HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/barbeatleanalyti/public_html/barisnew.beatleanalytics.com/site/backup/include/profilenew.php
<?php
 
/* <summary>
	 Class contains methods related to state module
	 <author>
	 Beatle Buddy 2017.
	 </author>
	 Version 1.0
   </summary> 
*/
 
class include_profilenew
{
	/*
	<summary>
		Default constructor
	</summary>	
	*/
	
	function __CONSTRUCT(){
	
	}
	
	//  Method to fetch all user info.
	public function FetchAllUserInfo(){
		global $objDB;
	}


	
	public function setSettingData(){
		global $objDB;
		$_REQUEST['acn'] = 'FetchAllUserInfo';
		
		$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,"profilenew.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,"profilenew.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,"profilenew.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']."',
			db_aboutme = '".$_POST['aboutme']."',";
		
		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){
				unset($_REQUEST['acn']);
				unset($_REQUEST['v']);
				ReturnPostFormData($_REQUEST,"profilenew.html","Profile data updated successfuly.",0);
				exit;
		}else{
				ReturnPostFormData($_REQUEST,"profilenew.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,"profilenew.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,"profilenew.html","Password updated successfuly.",0);
				exit;
		}else{
				ReturnPostFormData($_REQUEST,"profilenew.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(),"profilenew.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 fetchTotalBonus(){
		global $objDB;
		
		$SQL = "SELECT SUM(Amount) AS Amount FROM beatle_points WHERE UserID = '".$_SESSION['UserInfo']['UserID']."' AND IsReDeem = 'N' ";
		$rsAmount1 = $objDB->sql_query($SQL);
		$SQL = "SELECT SUM(Amount) AS Amount FROM beatle_points WHERE UserID = '".$_SESSION['UserInfo']['UserID']."' AND IsReDeem = 'Y' ";
		$rsAmount2 = $objDB->sql_query($SQL);
		
		return $amount = $rsAmount1[0]['Amount'] - $rsAmount2[0]['Amount'];
	}
	
	public function fetchCustomerRating($cid,$tokenid){
		global $objDB;

			$SQL = "SELECT AVG(db_surveyValue) AS TotalCount FROM beatle_survey WHERE 
			db_surveyValue IN (1,2,3,4) AND is_submit = 'Y' AND
			db_surveyUserid = '".$cid."' AND
			tokenid = '".$tokenid."' ";
			$rsTotalCountSurvey = $objDB->sql_query($SQL);
			return number_format($rsTotalCountSurvey[0]['TotalCount'],2);
			
	}
	
	public function fetchCustomerVisit(){
		global $objDB;
		
		$_REQUEST['acn'] = 'FetchAllUserInfo';
		
		$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->fdate) && !empty($this->tdate)){
			$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($this->fdate))." 00:00:00' AND '".date("Y-m-d",strtotime($this->tdate))." 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->brnid))
		$SQL .= " AND beatle_survey.db_surveyBranchid = ".$this->brnid." " ;
		
		if(!empty($this->indid))
		$SQL .= " AND beatle_survey.db_surveyIndId = ".$this->indid." " ;

		//if(!empty($this->TokenID))
		//$SQL .= " AND beatle_survey.tokenid = '".$this->TokenID."' " ;
		
		
		$SQL .= " GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date DESC LIMIT 5";
		
		//echo $SQL;
		
		$rsUserInfo_ = $objDB->sql_query($SQL);
		
		return $rsUserInfo_;
		
	}
	
	public function fetchOrderDetails($prid){
		global $objDB;
		$SQL = "SELECT * FROM beatle_order WHERE userid = ".$_SESSION['UserInfo']['UserID']." ORDER BY created_date DESC LIMIT 5";
		return $rsOrderd = $objDB->sql_query($SQL);
	}	
	
	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 getAllBranchByOrg($Orgid){
		global $objDB;
		$SQL = "SELECT branchId,db_branchName FROM beatle_branch WHERE db_branchOrg = ".$Orgid;
		return $rsOwnerInfo = $objDB->sql_query($SQL);
	}

	public function getAllIndByBranch($branchId){
		global $objDB;
		$SQL = "SELECT IndId,db_industry FROM beatle_industry WHERE db_bracnchid = ".$branchId;
		return $rsOwnerInfo = $objDB->sql_query($SQL);
	}
	
	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'];	
	}
	
	//owner's data
	public function FetchOwnerData($id){
		global $objDB;
		$SQL = "SELECT * FROM beatle_userlogin WHERE db_usertype = 'owner' and OrgID = ".$id;
		return $rsProfile = $objDB->sql_query($SQL); 
	}

	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  /////
?>