File: /home/barbeatleanalyti/public_html/barisnew.beatleanalytics.com/site/backup/include/offers.php
<?php
/* <summary>
Class contains methods related to state module
<author>
Beatle Buddy 2017.
</author>
Version 1.0
</summary>
*/
class include_offers
{
/*
<summary>
Default constructor
</summary>
*/
function __CONSTRUCT(){
}
// Method to fetch all user info.
public function FetchAllUserInfo(){
global $objDB;
}
public function addOffersTempData(){
global $objDB;
//echo "<pre>";
//print_r($_REQUEST);
//print_r($_FILES);
//print_r($_SESSION);
$dateArr = explode("-",$_REQUEST['validity']);
$startDate = date("Y-m-d",strtotime(trim($dateArr[0])))." 00:00:00";
$endDate = date("Y-m-d",strtotime(trim($dateArr[1])))." 23:59:59";
$FileName = date('YmdHis').'_'.rand(999999999,100000000);
if(!empty($_FILES['filebutton']['name'])){
$sizeArr = getimagesize($_FILES['filebutton']['tmp_name']);
//print_r($sizeArr);
$width_tmp = $sizeArr[0];
$height_tmp = $sizeArr[1];
$error = 0;
if(!in_array($imgExt,$extArr)){
$error = 1;
}
if($width_tmp < 1000 || $width_tmp > 1200){
$error = 1;
}
if($height_tmp < 400 || $height_tmp > 500){
$error = 1;
}
if($error == 1){
//ReturnPostFormData(array(),"offers.html","Please select offers image/banner properly in size.",1);
//exit;
}
$ExtArr = array("jpg","JPG","jpeg","JPEG","png","PNG");
$FileExt = $this->ChekcImageExtention($_FILES['filebutton']['name'],$ExtArr);
$output_filename = UPLOAD_OFFER_IMAGE_TEMP.$FileName.".".$FileExt;
if(!move_uploaded_file($_FILES['filebutton']['tmp_name'],$output_filename)){
ReturnPostFormData(array(),"offers.html","There is something wrong to upload advertise image/banner",1);
exit;
}
}
$SQL = "INSERT INTO beatle_offers_temp SET
orgid = ".$_SESSION['OtherInfo']['OrgID'].",
addedby = ".$_SESSION['UserInfo']['UserID'].",
title = '".$_REQUEST['title']."',
startdate = '".$startDate."',
enddate = '".$endDate."',
description = '".$_REQUEST['description']."',
created_date = '".date("Y-m-d H:i:s")."',
offer_image = '".$FileName.".".$FileExt."',
spoint = '".$_REQUEST['pointfrom']."',
epoint = '".$_REQUEST['pointto']."',
accept = 'new' ";
$objDB->sql_query($SQL);
ReturnPostFormData(array(),"offers.html","Thank you for submitting advertise details. your details added successfuly. We will contact you soon!",0);
exit;
}
public function fetchTotalBonus($userid){
global $objDB;
$SQL = "SELECT SUM(Amount) AS Amount FROM beatle_points WHERE UserID = '".$userid."' AND IsReDeem = 'N' ";
$rsAmount1 = $objDB->sql_query($SQL);
$SQL = "SELECT SUM(Amount) AS Amount FROM beatle_points WHERE UserID = '".$userid."' AND IsReDeem = 'Y' ";
$rsAmount2 = $objDB->sql_query($SQL);
return $amount = $rsAmount1[0]['Amount'] - $rsAmount2[0]['Amount'];
}
public function searchCustomerData(){
global $objDB;
$sDate = date("Y-m-d 00:00:00");
$eDate = date("Y-m-d 23:59:59");
$SQL = 'SELECT
beatle_userlogin.db_phone,
beatle_userlogin.db_username,
beatle_userlogin.userId,
beatle_offers_apply.applyid,
beatle_offers_apply.approved,
beatle_offers_apply.offerid,
beatle_offers_apply.tokenid,
beatle_offers_apply.added_date,
beatle_offers_apply.expire_time,
beatle_offers.offerid,
beatle_offers.offeruid,
beatle_offers.orgid,
beatle_offers.title,
beatle_offers.startdate,
beatle_offers.enddate,
beatle_offers.description,
beatle_offers.`comment`,
beatle_offers.active,
beatle_offers.onhold,
beatle_offers.created_date,
beatle_offers.offer_image,
beatle_offers.spoint,
beatle_offers.epoint
FROM
beatle_userlogin
INNER JOIN beatle_offers_apply ON beatle_userlogin.userId = beatle_offers_apply.userid
INNER JOIN beatle_offers ON beatle_offers_apply.offerid = beatle_offers.offerid WHERE 1 = 1 AND
beatle_userlogin.db_phone = "'.$_POST['userid'].'" AND added_date >= "'.$sDate.'" AND expire_time <= "'.$eDate.'" ';
if(!empty($_POST['tokenid']))
$SQL .= ' AND beatle_offers_apply.tokenid = "'.$_POST['tokenid'].'" ';
return $result = $objDB->sql_query($SQL);
//print_r($_POST);die;
}
public function fetchOrderDetails($prid){
global $objDB;
$SQL = "SELECT * FROM beatle_order WHERE userid = ".$_SESSION['UserInfo']['UserID']." ORDER BY created_date DESC";
return $rsOrderd = $objDB->sql_query($SQL);
}
public function setSettingData(){
global $objDB;
$_REQUEST['acn'] = 'FetchAllUserInfo';
/* echo "<pre>";
print_r($_REQUEST);
die;
*/
$SQL = "SELECT * FROM beatle_userlogin WHERE db_userLoginName = '".$_POST['username']."' AND userId <> '".$_SESSION['UserInfo']['UserID']."'";
$result = $objDB->sql_query($SQL);
if(count($result) > 0){
ReturnPostFormData($_REQUEST,"profileemp.html","User name allready taken, please try agin with different user name ! ",1);
exit;
}
$SQL = "SELECT * FROM beatle_userlogin WHERE db_phone = '".$_POST['contact_number']."' AND userId <> '".$_SESSION['UserInfo']['UserID']."'";
$result = $objDB->sql_query($SQL);
if(count($result) > 0){
ReturnPostFormData($_REQUEST,"profileemp.html","Phone no. allready taken, please try agin with different phone no ! ",1);
exit;
}
if(!empty($_POST['email'])) {
$SQL = "SELECT * FROM beatle_userlogin WHERE db_email = '".$_POST['email']."' AND userId <> '".$_SESSION['UserInfo']['UserID']."'";
$result = $objDB->sql_query($SQL);
if(count($result) > 0){
ReturnPostFormData($_REQUEST,"profileemp.html","Email allready taken, please try agin with different email id ! ",1);
exit;
}
}
$SQL = "UPDATE beatle_userlogin SET
db_username = '".$_POST['name']."',
db_state = '".$_POST['state']."',
db_city = '".$_POST['city']."',
db_address = '".$_POST['address']."',
db_pincode = '".$_POST['pincode']."', ";
if(!empty($_POST['username']))
$SQL .= "db_userLoginName = '".$_POST['username']."', ";
$SQL .= "db_phone = '".$_POST['contact_number']."',
db_email = '".$_POST['email']."' WHERE
userId = '".$_SESSION['UserInfo']['UserID']."'";
$rsData = $objDB->sql_query($SQL);
if(count($rsData) > 0){
ReturnPostFormData($_REQUEST,"profileemp.html","Profile data updated successfuly.",0);
exit;
}else{
ReturnPostFormData($_REQUEST,"profileemp.html","Here is something wrong to update data.",1);
exit;
}
}
public function setPasswordData(){
global $objDB;
$_REQUEST['acn'] = 'FetchAllUserInfo';
$SQL = "SELECT * FROM beatle_userlogin WHERE db_password = '".md5($_POST['oldpass'])."' AND userId = '".$_SESSION['UserInfo']['UserID']."'";
$result = $objDB->sql_query($SQL);
if(count($result) <= 0){
ReturnPostFormData($_REQUEST,"profileemp.html","Wrong old password , please try again.! ",1);
exit;
}
$SQL = "UPDATE beatle_userlogin SET
db_password = '".md5($_POST['newpass'])."'
WHERE
userId = '".$_SESSION['UserInfo']['UserID']."'";
$rsData = $objDB->sql_query($SQL);
if(count($rsData) > 0){
ReturnPostFormData($_REQUEST,"profileemp.html","Password updated successfuly.",0);
exit;
}else{
ReturnPostFormData($_REQUEST,"profileemp.html","Here is something wrong to update password.",1);
exit;
}
}
protected function UploadUserProfileImage(){
global $objDB;
$imgUrl = strtolower($_FILES['img']['tmp_name']);
// original sizes
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
// resized sizes
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
// offsets
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
// crop box
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
// rotation angle
$angle = $_POST['rotation'];
$jpeg_quality = 100;
$FileName = "webimage_".date('ymdhis').rand();
$ExtArr = array("jpg","JPG","jpeg","JPEG","png","PNG");
$FileExt = $this->ChekcImageExtention($_FILES['img']['name'],$ExtArr);
$output_filename = UPLOAD_WEBPROFILEIMAGE.$FileName;
// uncomment line below to save the cropped image in the same location as the original image.
//$output_filename = dirname($imgUrl). "/croppedImg_".rand();
if(!move_uploaded_file($_FILES['img']['tmp_name'],"tmp/".$FileName.".".$FileExt)){
ReturnPostFormData(array(),"profileemp.html","There is something wrong to upload profile image",1);
exit;
}
$imgUrl = "tmp/".$FileName.".".$FileExt;
$what = getimagesize($imgUrl);
//print_r($what);
//die;
switch(strtolower($_FILES['img']['type']))
{
case 'image/png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
break;
case 'image/jpeg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
error_log("jpg");
$type = '.jpeg';
break;
case 'image/gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('image type not supported');
}
//Check write Access to Directory
if(!is_writable(dirname($output_filename))){
$response = Array(
"status" => 'error',
"message" => 'Can`t write cropped File'
);
}else{
// resize the original image to size of editor
$resizedImage = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
// rotate the rezized image
$rotated_image = imagerotate($resizedImage, -$angle, 0);
// find new width & height of rotated image
$rotated_width = imagesx($rotated_image);
$rotated_height = imagesy($rotated_image);
// diff between rotated & original sizes
$dx = $rotated_width - $imgW;
$dy = $rotated_height - $imgH;
// crop rotated image to fit into original rezized rectangle
$cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
// crop image into selected area
$final_image = imagecreatetruecolor($cropW, $cropH);
imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
// finally output png image
//imagepng($final_image, $output_filename.$type, $png_quality);
imagejpeg($final_image, $output_filename.$type, $jpeg_quality);
//Remove profile Image in unlink to the folder
$RemoveProfileImage = removeprofileimage();
$SQL = "UPDATE beatle_userlogin SET webprofileimage = '".$FileName.$type."' WHERE userId = '".$_SESSION['UserInfo']['UserID']."'";
$upload = $objDB->sql_query($SQL);
$response = Array(
"status" => 'success',
"url" => $output_filename.$type
);
//echo json_encode($response);
}
unlink("tmp/".$FileName.".".$FileExt);
return $upload;
exit;
}
protected function uploadprofileimage(){
global $objDB;
$ExtArr = array("jpg","JPG","jpeg","JPEG","png","PNG");
$Extention = $this->ChekcImageExtention($_FILES['profileimage']['name'],$ExtArr);
$FileName = $UniqueID.date('ymdHis').".".$Extention;
//$FileName1 = UPLOAD_WEBPROFILEIMAGE.$FileName;
if($Extention){
$image = $this->resize(200, 200,$FileName);
if($image){
$SQL = "UPDATE beatle_userlogin SET webprofileimage = '".$FileName."' WHERE userId = '".$_SESSION['UserInfo']['UserID']."'";
$upload = $objDB->sql_query($SQL);
}
}else{
return $this->ErrorDoc = "Please upload image file should be .jpg, .jpeg, .png formate file only..";
exit;
}
if($upload){
return $upload;
}
}
public function resize($width, $height,$filename){
/* Get original image x y*/
list($w, $h) = getimagesize($_FILES['profileimage']['tmp_name']);
/* calculate new image size with ratio */
$ratio = max($width/$w, $height/$h);
$h = ceil($height / $ratio);
$x = ($w - $width / $ratio) / 2;
$w = ceil($width / $ratio);
/* new file name */
$path = UPLOAD_WEBPROFILEIMAGE.$filename;
/* read binary data from image file */
$imgString = file_get_contents($_FILES['profileimage']['tmp_name']);
/* create image from string */
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
/* Save image */
switch ($_FILES['profileimage']['type']) {
case 'image/jpeg':
imagejpeg($tmp, $path, 100);
break;
case 'image/png':
imagepng($tmp, $path, 0);
break;
case 'image/gif':
imagegif($tmp, $path);
break;
default:
exit;
break;
}
return $path;
/* cleanup memory */
imagedestroy($image);
imagedestroy($tmp);
}
public function ChekcImageExtention($ImgName,$ExtArr){
$FileExtArr = explode(".",$ImgName);
$FileExt = $FileExtArr[count($FileExtArr) - 1];
if(in_array($FileExt,$ExtArr)){
return $FileExt;
}else{
return false;
}
}
public function fetchCustomerVisit(){
global $objDB;
$SQL = "SELECT
beatle_survey.surveyId,
beatle_survey.db_surveyBranchid,
beatle_survey.db_surveyUserid,
beatle_survey.db_surveyIndId,
beatle_survey.db_surveyPageid,
beatle_survey.db_surveyContentId,
beatle_survey.db_surveyValue,
beatle_survey.created_date,
beatle_survey.updated_date,
beatle_survey.tokenid,
beatle_survey.orgid,
beatle_survey.is_submit,
beatle_userlogin.db_phone,
beatle_userlogin.db_userLoginName,
beatle_userlogin.db_username,
beatle_userlogin.userId
FROM
beatle_survey
INNER JOIN beatle_userlogin ON beatle_survey.db_surveyUserid = beatle_userlogin.userId
WHERE beatle_survey.is_submit = 'Y' AND beatle_survey.db_surveyUserid = ".$_SESSION['UserInfo']['UserID'];
//if(!empty($this->FromDate) && !empty($this->ToDate)){
// $SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($this->FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($this->ToDate))." 23:59:59' ";
//}
/*
if(!empty($this->OrgID))
$SQL .= " AND beatle_survey.orgid = ".$this->OrgID." " ;
else
$SQL .= " AND beatle_survey.orgid = ".$_SESSION['OtherInfo']['OrgID']." " ;
if(!empty($this->BranchID))
$SQL .= " AND beatle_survey.db_surveyBranchid = ".$this->BranchID." " ;
if(!empty($this->IndustryID))
$SQL .= " AND beatle_survey.db_surveyIndId = ".$this->IndustryID." " ;
if(!empty($this->TokenID))
$SQL .= " AND beatle_survey.tokenid = '".$this->TokenID."' " ;
*/
$SQL .= " GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date DESC";
$rsUserInfo_ = $objDB->sql_query($SQL);
return $rsUserInfo_;
}
public function FetchOrganizationName($id){
global $objDB;
$SQL = "SELECT db_Orgname FROM beatle_organization WHERE OrgId = ".$id;
$rsOwnerInfo = $objDB->sql_query($SQL);
return $rsOwnerInfo[0]['db_Orgname'];
}
public function FetchBranchName($id){
global $objDB;
$SQL = "SELECT db_branchName FROM beatle_branch WHERE branchId = ".$id;
$rsOwnerInfo = $objDB->sql_query($SQL);
return $rsOwnerInfo[0]['db_branchName'];
}
public function FetchIndustryName($id){
global $objDB;
$SQL = "SELECT db_industry FROM beatle_industry WHERE IndId = ".$id;
$rsOwnerInfo = $objDB->sql_query($SQL);
return $rsOwnerInfo[0]['db_industry'];
}
public function FetchWebProfileImage(){
global $objDB;
$SQL = "SELECT webprofileimage FROM beatle_userlogin WHERE userId = '".$_SESSION['UserInfo']['UserID']."'";
$rsProfile = $objDB->sql_query($SQL);
return $rsProfile[0]['webprofileimage'];
}
protected function removeprofileimage(){
global $objDB;
$File = $this->FetchWebProfileImage();
if($File){
$myFile = UPLOAD_WEBPROFILEIMAGE."/".$File;
unlink($myFile);
}
$SQL = "UPDATE beatle_userlogin SET webprofileimage = NULL WHERE userId = '".$_SESSION['UserInfo']['UserID']."'";
$upload = $objDB->sql_query($SQL);
return $upload;
}
public function __DESTRUCT() {
global $objDB;
unset($objDB->objModel);
unset($objDB->objController);
}
} ///// class include_login completed /////
?>