JezK
Edit File: functions.php
<?php // include_once("checkSession.php"); ini_set('display_errors', 1); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\OAuth; use League\OAuth2\Client\Provider\Google; // require './../composer_test/vendor/phpmailer/phpmailer/src/PHPMailerAutoload.php'; class uflexitCustomer { public $db; function __construct() { include_once dirname(__FILE__) . '/uflexitConfig.php'; require_once dirname(__FILE__) . '/class.db.php'; require_once dirname(__FILE__) .'./../composer_test/vendor/autoload.php'; $this->db = new DB(); } /** * function name: generateApiKey * decription: for generating random md5 hash token * developed by: lathif */ function generateApiKey() { return md5(uniqid(rand(), true)); } /** * function name: generateSecuredPassword * decription: hash password for users registration * developed by: lathif */ function generateSecuredPassword($password) { $passwordHash=''; $options = [ 'cost' => 12, ]; $passwordHash=password_hash($password, PASSWORD_BCRYPT, $options); return $passwordHash; } /** * function name: checkPasswordMatch * decription: check hash password in db match with given password or not * developed by: yamuna */ function checkPasswordMatch($password,$passwordHash) { $passIsValid = password_verify($password,$passwordHash); return $passIsValid; } /** * function name: checkEmailExistsOrNot * decription: This is for check email exists or not * developed by: lathif */ function checkEmailExistsOrNot($email) { $returnVal=0; $trimEmail=strip_tags($this->db->escape($email)); $query="select * from uflexit_users where lower(email)=lower('".$trimEmail."')"; $count=$this->db->num_rows($query); if(isset($count) && $count>0) { $returnVal=1; } return $returnVal; } function checkAdminEmailExistsOrNot($email) { $returnVal=0; $trimEmail=strip_tags($this->db->escape($email)); $query="select * from uflexit_super_administrator where lower(email)=lower('".$trimEmail."')"; $count=$this->db->num_rows($query); if(isset($count) && $count>0) { $returnVal=1; } else{ $query="select * from uflexit_users where lower(email)=lower('".$trimEmail."')"; $count=$this->db->num_rows($query); if(isset($count) && $count>0){ $returnVal=3; } } return $returnVal; } /** * function name: checkCompanyExists * decription: This is for check company exists or not * developed by: lathif */ function checkCompanyExists($companyName,$type) { $returnVal=0; $trimcompanyName=strip_tags($this->db->escape($companyName)); if($type==1) $query="select * from uflexit_company where company_name='".strtolower($trimcompanyName)."' and company_name!=''"; else $query="select * from uflexit_company where company_number='".strtolower($trimcompanyName)."' and company_number!=''"; $count=$this->db->num_rows($query); if(isset($count) && $count>0) { $returnVal=1; } return $returnVal; } /** * function name: checkPhoneExistsOrNot * decription: This is for check company exists or not * developed by: lathif */ function checkPhoneExistsOrNot($phone) { $returnVal=0; $trimPhone=strip_tags($this->db->escape($phone)); $query="select * from uflexit_users where mobile_number='".$trimPhone."'"; $count=$this->db->num_rows($query); if(isset($count) && $count>0) { $returnVal=1; } return $returnVal; } function checkAdminPhoneExistsOrNot($phone) { $returnVal=0; $trimPhone=strip_tags($this->db->escape($phone)); $query="select * from uflexit_super_administrator where phonenumber='".$trimPhone."'"; $count=$this->db->num_rows($query); if(isset($count) && $count>0) { $returnVal=1; } return $returnVal; } /** * function name: userSignup * decription: This is for signup customer and uflexit Admin * developed by: lathif,yamuna */ function userSignup($post,$role) { $returnVal=0; $company_name=$company_alter_name=$company_number=$first_name=$last_name=$designation=$location=$zip=$checkCompany=''; $country=0; //sql injections preventing if($role == 1 || $role == 4) { if(isset($post['company_name'])) $company_name=strip_tags($this->db->escape($post['company_name'])); $designation=strip_tags($this->db->escape($post['designation'])); $country=strip_tags($this->db->escape($post['country'])); if(isset($post['postalcode1'])) { $zip=strip_tags($this->db->escape($post['postalcode1'])); } if(isset($post['zip'])) { $zip=strip_tags($this->db->escape($post['zip'])); } if(isset($post['first_name'])) $first_name=strip_tags($this->db->escape(trim($post['first_name']))); if(isset($post['last_name'])) $last_name=strip_tags($this->db->escape(trim($post['last_name']))); $email=strip_tags($this->db->escape(trim($post['email']))); $password=strip_tags($this->db->escape(trim($post['password']))); $mobile_number=strip_tags($this->db->escape(trim($post['mobile_number']))); $mobile_country_code = strip_tags($this->db->escape(trim($post['mobile_country_code']))); $city=strip_tags($this->db->escape(trim($post['city']))); $address=strip_tags($this->db->escape(trim($post['address']))); } if($role == 3) { if(isset($post['postalcode'])) { $zip=strip_tags($this->db->escape($post['postalcode'])); } if(isset($post['customer_first_name'])) $first_name=strip_tags($this->db->escape(trim($post['customer_first_name']))); if(isset($post['customer_last_name'])) $last_name=strip_tags($this->db->escape(trim($post['customer_last_name']))); $email=strip_tags($this->db->escape(trim($post['email']))); $password=strip_tags($this->db->escape(trim($post['customerPassword']))); $mobile_number=strip_tags($this->db->escape(trim($post['customer_mobile_number']))); $mobile_country_code = strip_tags($this->db->escape(trim($post['mobile_country_code1']))); $city=strip_tags($this->db->escape(trim($post['customer_city']))); $address=strip_tags($this->db->escape(trim($post['customer_address']))); $location=strip_tags($this->db->escape($post['customer_location'])); $country=$location; } // if(isset($post['company_alter_name'])) // $company_alter_name=strip_tags(mysqli_real_escape_string($this->con,trim($post['company_alter_name']))); // if(isset($post['warehouse_number'])) // $company_number=strip_tags(mysqli_real_escape_string($this->con,trim($post['warehouse_number']))); //sql injections preventing $convertedPassword=$this->generateSecuredPassword($password); if($role==1) $checkCompany=$this->checkCompanyExists($company_name,1); //$checkCompanyNumber=$this->checkCompanyExists($company_number,2); $checkEmail=$this->checkEmailExistsOrNot($email); $checkPhone=$this->checkPhoneExistsOrNot($mobile_number); if($checkCompany==1) { $returnVal=1; } else if($checkEmail==1) { $returnVal=2; } else if($checkPhone==1) { $returnVal=3; } // else if($company_number==1) // { // $returnVal=5; // } else { $createdDate=gmdate("Y-m-d H:m:i"); $emailactiveToken=$this->generateApiKey(); $query="insert into uflexit_users (email, mobile_number, role_id, designation, password, first_name, last_name, city_name, address, country_id, postal_code, location, email_active_token, created_date,mobile_country_code) VALUES(lower('".$email."'),'".$mobile_number."','".$role."','".$designation."','".$convertedPassword."','".$first_name."','".$last_name."','".$city."','".$address."','".$country."','".$zip."','".$location."','".$emailactiveToken."','".$createdDate."','".$mobile_country_code."') RETURNING user_id"; $row=$this->db->query($query); $lastId=pg_fetch_row($row); $lastInsertId=$lastId[0]; if($row) { if($role ==1 || $role==4) { $createCompany=$this->createCompany($company_name,$city,$address,$role,$lastInsertId); //exit; if($createCompany){ $query="update uflexit_users set company_id=$createCompany where user_id=$lastInsertId"; $row=$this->db->query($query); // $warehose_id=$result1['warehouse_id']; if($role ==1){ $message=$company_name.' new Company has been Registered Successfully as Warehouse Owner'; $arabicmessage=$company_name.' تم تسجيل الشركة الجديدة بنجاح كمالك مستودع'; }else if($role==4){ $message=$company_name.' new Company has been Registered Successfully as Business Customer'; $arabicmessage=$company_name.' تم تسجيل الشركة الجديدة بنجاح كعميل أعمال'; } $userId=$lastInsertId; // $warehouseName=$result1['warehouse_name']; $notifyType=1; $title='Warehouse Registration'; $warehose_id=0; // $name=$_SESSION['name']; $readStatus=0; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); $query="select admin_id from uflexit_super_administrator"; $result=$this->db->get_results($query); $count=$result ? count($result):0; for($i=0;$i<$count;$i++) { $receiverId=$result[$i]['admin_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehose_id,$userId,$receiverId,$date,$readStatus); } } } $this->sendEmailUserAndSuperAdmin($post,$emailactiveToken,$role);//customer Email //$this->sendEmailUserAndSuperAdmin($post,$emailactiveToken,3); //SuperAdmin Email $returnVal=4; } } return $returnVal; } /** * function name: createCompany * decription: This is for creating new company * developed by: lathif */ function createCompany($company_name,$city,$address,$role,$userId) { $returnVal=0; $createdDate=gmdate("Y-m-d H:m:i"); // company_alter_name='".strtolower($company_alter_name)."', // company_number='".strtolower($company_number)."', $query="insert into uflexit_company (company_name, role_id, user_id, city_name, address, created_date) VALUES ('".strtolower($company_name)."', '".$role."', '".$userId."', '".$city."', '".$address."', '".$createdDate."') RETURNING company_id"; //echo $query;exit; $row=$this->db->query($query); $companyId=pg_fetch_row($row); if($row) { $returnVal=$companyId[0]; } return $returnVal; } /** * function name: emailActivation * decription: This is for activating email for customer or admin * developed by: lathif */ function emailActivation($token) { $data=array(); $trimToken=strip_tags($this->db->escape(trim($token))); $query="select * from uflexit_users where email_active_token='".$trimToken."' and email_active=0"; $fetch = $this->db->get_row($query); if($fetch) { $query1="update uflexit_users set email_active=1 where user_id='".$fetch['user_id']."'"; //email_active_token='' $row1=$this->db->query($query1); if($row1) { $data['status']=1; $data['role_id']=$fetch['role_id']; } } else { $data['status']=2; } return $data; } /** * function name: sendEmailUserAndSuperAdmin * decription: This is for sending email to customer either amdin or user * developed by: lathif */ function sendEmailUserAndSuperAdmin($post,$emailToken=null,$role) { $baseUrl=HOSTPATH;//from config //$baseUrl="http://localhost/bitbucketworkspace/uflexit/"; // $fromName = 'Uflexit'; //$from='gowthami@krify.net'; $to=$post['email']; // $to='vijayakodandapani@krify.net'; // print_r($post); if($role==1 || $role==2 || $role==3 || $role==4) { $subject='Email Activation from Uflexit'; $customerContent=''; if($role!=2 && $role!=3) { $customerContent=' <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center" >Company</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['company_name'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center" >Email</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['email'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Phone number</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' .$post['mobile_number'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Activate Your account</td> <td style="width: 5%;">:</td> <td style="width: 50%;"><a href="'.$baseUrl.COMMONPATH.'emailverification.php?etoken='.$emailToken.'" target="_blank">Activate</a></td> </tr> '; } else{ $customerContent='<tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center" >Email</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['email'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Phone number</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' .$post['customer_mobile_number'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Activate Your account</td> <td style="width: 5%;">:</td> <td style="width: 50%;"><a href="'.$baseUrl.COMMONPATH.'emailverification.php?etoken='.$emailToken.'" target="_blank">Activate</a></td> </tr> '; } } else { $subject='New user Registered in Uflexit'; $customerContent=''; if(isset($post['company_name'])) { $customerContent=' <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center" >Company</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['company_name'] . '</td> </tr>'; } $customerContent.=' <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Phone number</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' .$post['mobile_number'] . '</td> </tr> <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center" >Email</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['email'] . '</td> </tr> '; } $htmlContent = ' <html> <head> <title>Uflexit WareHouse Service</title> </head> <body> <div> <div style="text-align:center;width: 550px;margin: 40px auto;border: 2px solid #2157c9;border-radius: 28px;"> <div style="padding:10px"> <img src="'.MAILSLOGOPATH.'" alt="Website Change Request" alt="Website Change Request"/> </div> <div style="color: #2157c9;font-size: 24px;text-align:center !important;font-weight: 600;">Registration Details</div> <div style="margin:15px;padding:20px !important;"> <hr style="border: 1px solid #2157c9;"/> <table style="width: 100%;"> <tbody style="overflow:auto;font-size: 16px;"> '.$customerContent.' </tbody> </table> <hr style="border: 1px solid #2157c9;"/> <footer> <h3 style="color: #2157c9;font-size: 18px;"><br/>Thanks & Regards<br/> Uflexit Team</h3> </footer> </div> </div> </div> </body> </html>'; $res=$this->smtpMail($baseUrl,$htmlContent,$subject,$to); return true; } /** * function name: userLogin * decription: This is for login both admin,subadmin and user * developed by: yamuna */ function userLogin($post,$type=NULL) { /** * type * 1-WareHouse Admin * 2-WareHouse Sub Admin * 3-WareHouse individual customer * 4-WareHouse business customer */ // unset($_SESSION); // session_destroy(); $returnVal = array( 'status' => "" ); $subQuery = ""; if($type!=NULL) { $subQuery=" AND role_id='".$type."'"; if($type==1) // warehouse admin or subadmin { $subQuery=" AND (role_id=1 or role_id=2)"; } } $email=strip_tags($this->db->escape(trim($post['email']))); $password=strip_tags($this->db->escape(trim($post['password']))); $query="SELECT * FROM uflexit_users WHERE lower(email)=lower('".$email. "') ".$subQuery; $loginDetails = $this->db->get_row($query); // print_r($loginDetails);exit; if ($loginDetails) { if($loginDetails['password']!=''){ if($this->checkPasswordMatch($password,$loginDetails['password'])) { if ($loginDetails['email_active'] == 1) { $token = $this->generateApiKey(); $query = "update uflexit_users set token = '".$token."' where user_id = ".$loginDetails['user_id']; $cmd = $this->db->get_row($query); $loginDetails['token']=$token; $returnVal['details'] = $loginDetails; $returnVal['status'] = 1; //success } else if ($loginDetails['email_active'] == 0) { $returnVal['status'] = 3; //email verfication pending } if($loginDetails['inactive_date']!=''){ $currentDate=date('Y-m-d'); $inActiveDate=$loginDetails['inactive_date']; if($inActiveDate<$currentDate){ $returnVal['status'] = 6; } } } else{ $returnVal['status'] = 2; //password wrong } }else if($loginDetails['password']==''){ $returnVal['status'] = 4; // password not generated } } return $returnVal; } /** * function name: getCountryList * decription: This is for getting all countries in uflexit_countries table * developed by: yamuna */ function getCountryList() { $data=array(); $query="SELECT country_id,country_name as country_name,currency,display_name FROM uflexit_countries"; return $this->db->get_results($query); } /** * function name: forgotPassword * decription: forgotPassword functionality * developed by: yamuna,vijay */ function forgotPassword($post) { // print_r($post); // exit; // $returnValue = 0; $returnValue = array(); $emailactiveToken=$this->generateApiKey(); $email=strip_tags($this->db->escape(trim($post['email']))); $query="SELECT * FROM uflexit_users WHERE lower(email)=lower('" .$email. "')"; $result = $this->db->get_row($query); $post['typeval'] = isset($post['typeval']) ? $post['typeval'] : 0; if($result) { $this->sendForgetPasswordMail($post['email'],$result['email_active_token'],$post['typeval']); $returnValue['status'] = 1; $returnValue['typeval']=$post['typeval']; } // print_r($returnValue);exit; return $returnValue; } function sendForgetPasswordMail($email,$emailToken=null,$type) { // $baseUrl=HOSTPATH; //config file $baseUrl=HOSTPATH; // $baseUrl="http://localhost/bitbucketworkspace/uflexit/uflexit_web_new"; // $fromName = 'Uflexit'; // $from='support@uflexit.com'; // $to='vijayakodandapani@krify.net'; $to=$email; $subject="Forget Password from Uflexit"; $customerContent=' <tr style="padding:10px !important;display:flex;width:100%;color: #000;word-break: break-word;justify-content: space-evenly;"> <td style="width:45%;font-weight:bold;text-align:center">Change Your Password</td> <td style="width: 5%;">:</td> <td style="width: 50%;"><a href="' . $baseUrl .COMMONPATH.'/resetPassword.php?etoken='.$emailToken.'&type='.$type.'" target="_blank">Reset Password</a></td> </tr> '; $htmlContent = ' <html> <head> <title>Uflexit WareHouse Service</title> </head> <body> <div style="text-align:center;width: 550px;margin: 40px auto;border: 2px solid #2157c9;border-radius: 28px;"> <div style="padding:10px"> <img src="'.MAILSLOGOPATH.'" alt="Website Change Request" alt="Website Change Request"/> </div> <div style="color: #2157c9;font-size: 24px;text-align:center !important;font-weight: 600;padding-top:10px;">Reset your password by clicking below link</div> <div style="margin:15px;padding:20px !important;"> <hr style="border: 1px solid #2157c9;"/> <table style="width: 100%;"> <tbody style="overflow:auto;font-size: 16px;"> '.$customerContent.' </tbody> </table> <hr style="border: 1px solid #2157c9;"/> <footer> <h3 style="color: #2157c9;font-size: 18px;"><br/>Thanks & Regards<br/> Uflexit Team</h3> </footer> </div> </div> </body> </html>'; $res=$this->smtpMail($baseUrl,$htmlContent,$subject,$to); /// to customer // $res=$this->smtpMail($baseUrl,$htmlContent,$subject,$to); /// to admin // $result = 1; if($res){ return true; } } /** * function name: changePassword * decription: This is for forgetPassword for user and admin * developed by: yamuna,vijay */ function changePassword($post) { //$returnVal=0; $returnVal = array(); $emailactiveTokens=$this->generateApiKey(); $password=strip_tags($this->db->escape(trim($post['password']))); $cnfrmPassword=strip_tags($this->db->escape(trim($post['cnfrmPassword']))); $token=strip_tags($this->db->escape(trim($post['token']))); $query="SELECT * FROM uflexit_users WHERE email_active_token='" .$token. "'"; $result = $this->db->get_row($query); if($result) { $hash=$result['password']; if(password_verify($password,$hash)){ $returnVal['status']=2; $returnVal['role'] = $result['role_id']; } else{ if($password == $cnfrmPassword) { $convertedPassword=$this->generateSecuredPassword($password); $query1="UPDATE uflexit_users SET password='$convertedPassword',email_active_token='$emailactiveTokens' WHERE email_active_token='$token'"; $row1=$this->db->query($query1); if($row1) { $returnVal['status'] = 1; //success $returnVal['role'] = $result['role_id']; } } else { $returnVal['status'] = 0; //password not match $returnVal['role'] = $result['role_id']; } } } return $returnVal; } function updatePassword($post) { //$returnVal=0; // echo "kiran";exit; $returnVal = array(); $old_password=strip_tags($this->db->escape(trim($post['old_password']))); $password=strip_tags($this->db->escape(trim($post['password']))); $cnfrmPassword=strip_tags($this->db->escape(trim($post['cnfrmPassword']))); $token=strip_tags($this->db->escape(trim($post['token']))); $query="SELECT * FROM uflexit_users WHERE token='" .$token. "'"; $result = $this->db->get_row($query); if($result) { if(password_verify($old_password,$result['password'])){ if($password == $cnfrmPassword) { $convertedPassword=$this->generateSecuredPassword($password); $query1="UPDATE uflexit_users SET password='$convertedPassword' WHERE token='$token'"; $row1=$this->db->query($query1); if($row1) { $returnVal['status'] = 1; //success } } else { $returnVal['status'] = 0; //password not match } } else{ $returnVal['status'] = 2; //old password does not match } } return $returnVal; } /** * function name: checkEtoken * decription: checkEtoken functionality * developed by: vijay */ function checkEtoken($token){ $query="SELECT * FROM uflexit_users WHERE email_active_token='" .$token. "'"; $result = $this->db->get_row($query); if($result){ return 1; } else{ return 0; } } /** * function name: usermng * decription: usermng functionality * developed by: Ramyakrishna */ function userCustomerEdit($post){ // print_r($post); // echo $_FILES["formUpload"]['name']; // exit; $returnVal=0; $first_name = strip_tags($this->db->escape(trim($post['first_name']))); $last_name = strip_tags($this->db->escape(trim($post['last_name']))); $email = strip_tags($this->db->escape(trim($post['email']))); $address = strip_tags($this->db->escape(trim($post['address']))); $city_name = strip_tags($this->db->escape(trim($post['city_name']))); $mobile_number = strip_tags($this->db->escape(trim($post['mobile_number']))); if(isset($post['password']) && !empty($post['password'])){ $customer_password = strip_tags($this->db->escape(trim($post['password']))); $convertedPassword=$this->generateSecuredPassword($customer_password);} $checkEmail=$this->checkEmailExistsOrNot($email); $checkPhone=$this->checkPhoneExistsOrNot($mobile_number); $fileName = $_FILES["formUpload"]['name']; $createdDate = gmdate("Y-m-d H:m:i"); $emailactiveToken=$this->generateApiKey(); //echo "hiii"; if(!empty($post['password'])){ $query="update uflexit_users set mobile_number='".$mobile_number."', password='".$convertedPassword."', first_name='".$first_name."', last_name='".$last_name."', city='".$city."', address='".$address."' where lower(email)=lower('".$email."')"; }else if($fileName){ $fileName = explode(".",$fileName); // print_r( $fileName); $fileName = $fileName[0].time().".".$fileName[1]; $target_dir = "../uploads/subadmin_photos/".$fileName; // exit; if (move_uploaded_file($_FILES["formUpload"]["tmp_name"], $target_dir)) { // echo "file uploaded succesfully"; } else{ echo "there was an error"; } $query="update uflexit_users set mobile_number='".$mobile_number."', first_name='".$first_name."', last_name='".$last_name."', city_name='".$city_name."', address='".$address."', upload_pic='".$fileName."' where lower(email)=lower('".$email."')"; }else{ $query="update uflexit_users set mobile_number='".$mobile_number."', first_name='".$first_name."', last_name='".$last_name."', city_name='".$city_name."', address='".$address."'where lower(email)=lower('".$email."')"; } $row=$this->db->query($query); $lastInsertId=$this->db->lastid($row); if($row) { if($fileName){ $_SESSION['customer_image']=$fileName; } $_SESSION['customer_name']=$first_name.' '.$last_name; $returnVal=3; }else{ $returnVal=4; } return $returnVal; } /** * function name: usermng * decription: usermng getting details functionality * developed by: Ramyakrishna */ function getCustomerDetails($email) { $data=array(); $extraQuery=''; if($email!=''){ $trimEmail=@strip_tags($this->db->escape(trim($email))); $extraQuery="email='".$trimEmail."'"; $query="SELECT * FROM uflexit_users where 1=1 and $extraQuery"; return $this->db->get_results($query); } return $data; } function getcities_function($country_id){ $query="SELECT * FROM uflexit_cities WHERE country_id=".$country_id; $cities = $this->db->get_results($query); return $cities; } function checkPhoneExistsOrNotForAjax($phone) { $returnVal= 0; $trimPhone=strip_tags($this->db->escape(trim($phone))); $query="select * from uflexit_users where mobile_number='".$trimPhone."'"; $returnVal = $this->db->get_row($query); return $returnVal; } function get_currency($country_id){ $query="SELECT * FROM uflexit_countries where country_id=".$country_id; $currencies=$this->db->get_results($query); return $currencies; } /** * decription: This is for Email checking for newsletter subcription * developed by: Surendra */ function checkNewsLetterEmailExistorNot($email) { $returnVal=0; $trimEmail=strip_tags($this->db->escape(trim($email))); $query="select * from uflexit_newsletter where lower(email)=lower('".$trimEmail."')"; $returnVal = $this->db->get_row($query); return $returnVal; } /** * function name: Newsletter Email insertion * decription: This is for inserting Email for newsletter subcription * developed by: Surendra */ function insertNewsLetterEmail($email) { $returnVal=0; $createdDate = gmdate("Y-m-d H:m:i"); $trimEmail=strip_tags($this->db->escape(trim($email))); $query="select * from uflexit_newsletter where lower(email)=lower('".$trimEmail."')"; $row = $this->db->get_row($query); if($row) { $returnVal=1; } else { $trimEmail=strip_tags($this->db->escape(trim($email))); $query1="INSERT INTO uflexit_newsletter (email,created_date) VALUES(lower('".$trimEmail."'),'".$createdDate."')"; $row1 = $this->db->query( $query1); if($row1) { $query="select admin_id from uflexit_super_administrator"; $notifyType=5; $warehose_id=0; $readStatus=0; $title='new subscriber'; $message='New Subscriber has been Subscribed in the Uflexit application'; $arabicmessage='تم اشتراك مشترك جديد في تطبيق Uflexit application'; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); if(isset($_SESSION['customer_user_id']) && $_SESSION['customer_user_id']!=''){ $userId = $_SESSION['customer_user_id']; }else{ $userId = 0; } $result=$this->db->get_results($query); $count=$result ? count($result):0; for($i=0;$i<$count;$i++){ $receiverId=$result[$i]['admin_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehose_id,$userId,$receiverId,$date,$readStatus); } $returnVal=2; } } return $returnVal; } /** * function name: TESTIMONALS * decription: Customer testimonals added by master admin * developed by: Soniya */ function testimonial() { $testimonial_data=array(); $query= "select * from uflexit_testimonial"; // echo $query;exit; $row1=$this->db->get_results($query); // print_r(count($row1));exit; if($row1>0) { foreach($row1 as $rowdata) { $data['user_name']=$rowdata['user_name']; $data['message']=$rowdata['message']; $data['image']=$rowdata['image']; $testimonial_data[]=$data; } } return $testimonial_data; } /** * function name: getWarehouseDealList * decription: fetching WarehouseDealList * developed by: gowtham */ function getWarehouseDealList($id,$productwareHouseDeals){ $warehouseid=strip_tags($this->db->escape(trim($id))); $query="select choosen_meta_value from uflexit_warehouse_meta where warehouse_id=$id and meta_key='productwareHouseDeals'"; $data = $this->db->get_results($query); $productsarray=[]; $productsarray=$data[0]['choosen_meta_value']; $query1="select deal_name,deal_id,lang_variables from uflexit_warehouse_deals where deal_id in ($productsarray)"; $productsdata = $this->db->get_results($query1); return $productsdata; } /** * function name: getWarehouseType * decription: fetching warehouse type like space or pallet * developed by: gowtham */ function getWarehouseType($id,$wareHousePriceType){ $warehouseid=strip_tags($this->db->escape(trim($id))); $query="select choosen_meta_value from uflexit_warehouse_meta where warehouse_id=$id and meta_key='$wareHousePriceType'"; $data = $this->db->get_results($query); $warehousetypedata = array(); if($data) { $productsarray=[]; $productsarray=$data[0]['choosen_meta_value']; $query1="select pricetype_id,pricetype_name,lang_variables from uflexit_warehouse_type where pricetype_id in ($productsarray)"; $warehousetypedata = $this->db->get_results($query1); } return $warehousetypedata; } /** * function name: getWarehouseData * decription: fetching warehouse details * developed by: gowtham */ function getWarehouseData($id){ $warehouseid=strip_tags($this->db->escape(trim($id))); $query="select uwp.price_type,uwp.price_per_day,uwp.minimum_period,uwp.maximum_period,uwp.minimum,uwp.maximum,umw.warehouse_name,umw.warehouse_city,umw.warehouse_country_id,umw.warehouse_address,umw.enable_online_booking,uwi.warehouse_logo,INITCAP(uc.country_name) as country_name,uc.display_name from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON uc.country_id=warehouse_country_id JOIN uflexit_warehouse_pricelist as uwp ON uwp.warehouse_id=umw.warehouse_id JOIN uflexit_warehouse_imgs as uwi ON uwi.warehouse_id=umw.warehouse_id where umw.warehouse_id=$warehouseid LIMIT 1"; $data = $this->db->get_results($query); if($data) { return $data; } return array(); } /** * function name: warehouseRating * decription: fetching warehouse rating Details * developed by: gowtham */ function warehouseRating($postdata){ // echo "Hello"; $ratingValue=''; if(isset($postdata)) $ratingValue="rating".$postdata['quoid']; if(isset($postdata['quoid'])){ $quoteId=$postdata['quoid']; } $ratingStatus=array(); $warehouseRating=strip_tags($this->db->escape(trim($postdata[$ratingValue]))); // echo $warehouseRating; $query="update uflexit_request_quote set warehouse_rating=$warehouseRating ,rating_status=1 where user_id='".$_SESSION['customer_user_id']."' AND quotation_status=3 and quotation_id=".$quoteId." returning quotation_id"; // $query="update uflexit_request_quote set warehouse_rating=$warehouseRating ,rating_status=1 where warehouse_id=80 returning *"; $warehouseratingdata = $this->db->query($query); if($warehouseratingdata){ $query="select admin_id from uflexit_super_administrator"; $result=$this->db->get_results($query); $count=$result ? count($result):0; $query1="select urq.warehouse_id,umw.warehouse_name from uflexit_request_quote as urq JOIN uflexit_master_warehouse umw ON urq.warehouse_id=umw.warehouse_id where quotation_id=$quoteId"; $result1=$this->db->get_row($query1); $warehose_id=$result1['warehouse_id']; $userId=$_SESSION['customer_user_id']; $warehouseName=$result1['warehouse_name']; $notifyType=6; $title='Rating for Warehouse'; $name=$_SESSION['customer_name']; $message=$name.' has given rating to '.$warehouseName.' Warehouse'; $arabicmessage=$name.' أعطى تصنيفًا لـ '.$warehouseName.' مستودع'; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); $readStatus=0; for($i=0;$i<$count;$i++){ $receiverId=$result[$i]['admin_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehose_id,$userId,$receiverId,$date,$readStatus); } return 1; }else{ return 0; } } /** * function name: warehouseDetails * decription: fetching userrating * developed by: vijay */ function getRatingList($user_id){ $ratingData=array(); $query="select * from uflexit_request_quote where user_id='".$user_id."'"; $warehouseratingdata=$this->db->get_results($query); return $warehouseratingdata; } /** * function name: warehouseDetails * decription: fetching warehouse Details * developed by: gowtham */ function warehouseDetails($warehouseCity,$warehouseType,$warehouseCountry,$min, $max,$role){ $subQuery=$subQuery1=$subQuery2=$subQuery3=''; $subQuery2="JOIN uflexit_warehouse_meta as uwm ON umw.warehouse_id=uwm.warehouse_id"; if($role==3){ $subQuery3="and (uwm.meta_key='workwith' and string_to_array(choosen_meta_value, ',') && array ['2'])"; }else if($role==4){ $subQuery3="and (uwm.meta_key='workwith' and string_to_array(choosen_meta_value, ',') && array ['1'])"; } if($warehouseCity!='' || $warehouseCountry!=''){ if($warehouseCity!=''){ $subQuery=" and umw.warehouse_city='$warehouseCity' and umw.warehouse_country_id=$warehouseCountry "; }else{ $subQuery=" and umw.warehouse_country_id=$warehouseCountry "; } } if($warehouseType!=''){ $subQuery2="JOIN uflexit_warehouse_meta as uwm ON umw.warehouse_id=uwm.warehouse_id"; $warehouseTypeId="'$warehouseType'"; $subQuery1="and (uwm.meta_key='wareHousePriceType' and string_to_array(choosen_meta_value, ',') && array [$warehouseTypeId])"; } $query="select uwm.*,umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id,umw.warehouse_packageid, umw.enable_online_booking,umw.warehouse_status, INITCAP(uc.country_name) as country_name,uc.display_name,uc.lang_variables,ucty.city_name,ucty.lang_variables as city_lang_variable,up.package_name,up.lang_variable,(SELECT AVG(warehouse_rating) as rating FROM uflexit_request_quote where warehouse_id=umw.warehouse_id) from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON umw.warehouse_country_id=uc.country_id JOIN uflexit_cities as ucty ON umw.warehouse_city=ucty.city_name JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id $subQuery2 where umw.warehouse_status=1 $subQuery $subQuery1 $subQuery3 LIMIT $max OFFSET $min "; $warehouseDetailData=$this->db->get_results($query); // print_r($warehouseDetailData); if($warehouseDetailData){ $query1="select umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id,umw.warehouse_packageid, umw.enable_online_booking,umw.warehouse_status, INITCAP(uc.country_name) as country_name,uc.display_name,uc.lang_variables,ucty.city_name,ucty.lang_variables as city_lang_variable,up.package_name,up.lang_variable from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON umw.warehouse_country_id=uc.country_id JOIN uflexit_cities as ucty ON umw.warehouse_city=ucty.city_name JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id $subQuery2 where umw.warehouse_status=1 $subQuery $subQuery1 $subQuery3 "; $warehouseCount=$this->db->get_results($query1); $warehouseData2 = array(); foreach($warehouseDetailData as $wrow){ $query6="select warehouse_logo from uflexit_warehouse_imgs where warehouse_id='".$wrow['warehouse_id']."' LIMIT 1"; $image=$this->db->get_row($query6); // echo "<pre>"; // print_r($image); if(isset($image['warehouse_logo'])) { $wrow['warehouse_logo'] = $image['warehouse_logo']; } $warehouseData2[] = $wrow; } $totalCount=count($warehouseCount); $warehouseArray=array(); array_push($warehouseArray,$totalCount,$warehouseData2); return $warehouseArray; }else{ return 1; } } /** * function name: warehouseDetails * decription: fetching warehouse storage type Details * developed by: gowtham */ function warehouseStorageType(){ $query="select * from uflexit_warehouse_type "; $warehouseTypeData=$this->db->get_results($query); return $warehouseTypeData; } /** * function name: warehouseDetails * decription: fetching warehouse services type Details * developed by: gowtham */ function warehouseServicesType(){ $query="select * from uflexit_warehouse_services"; $warehouseServicesData=$this->db->get_results($query); return $warehouseServicesData; } function get_warehouse($featuresType,$storagesType,$servicessType,$productdealsType,$searchText,$searchData,$palletData,$spaceData,$min,$max,$role,$filterInput){ $storagesubQuery=$servicessubquery=$featuresSubQuery=$subQuery3=$subQuery2=''; $featureid=[]; $featuresArray=''; $storageArray=''; $servicesArray=''; $productsArray=''; $searchDataArray = ''; $spaceDetailsData= ""; $searchPalletArray = ''; $searchSpaceArray = ''; $whereText = ""; $warehouseIds = ""; if($role==3){ $subQuery2="JOIN uflexit_warehouse_meta as uwm ON umw.warehouse_id=uwm.warehouse_id"; $subQuery3="and (uwm.meta_key='workwith' and string_to_array(choosen_meta_value, ',') && array ['2'])"; }else if($role==4){ $subQuery2="JOIN uflexit_warehouse_meta as uwm ON umw.warehouse_id=uwm.warehouse_id"; $subQuery3="and (uwm.meta_key='workwith' and string_to_array(choosen_meta_value, ',') && array ['1'])"; } if($featuresType!=''){ $query="select warehouse_id from uflexit_warehouse_meta where meta_key='wareHousefeature' and string_to_array(choosen_meta_value, ',') && array [$featuresType]"; $featuresdata= $this->db->get_results($query); if(is_array($featuresdata) && count($featuresdata) > 0) { foreach($featuresdata as $data){ // array_push($featureid,$data['warehouse_id']); $featureid[] = $data['warehouse_id']; } $featuresArray=implode(',',$featureid); $warehouseIds = $featuresArray; if($featuresArray!="") { $whereText = "and warehouse_id in (".$featuresArray.") "; } } } //~ print_r($warehouseIds);exit; // exit; if($storagesType!=''){ // if($whereText == ""){ $whereText .="and string_to_array(choosen_meta_value, ',') && array [$storagesType]"; // } // if($featuresArray>0){ $query2="select warehouse_id from uflexit_warehouse_meta where meta_key='wareHousePriceType' ".$whereText; $storageData= $this->db->get_results($query2); if(is_array($storageData) && count($storageData) > 0) { foreach($storageData as $data){ // array_push($featureid,$data['warehouse_id']); $storageid[] = $data['warehouse_id']; } $storageArray=implode(',',$storageid); $warehouseIds = $storageArray; // exit; if($storageArray != "") { $whereText = "and warehouse_id in (".$storageArray.")"; } } // } } if($servicessType != ''){ // if($whereText == ""){ // $whereText .="and string_to_array(choosen_meta_value, ',') @> array [$servicessType]"; // } $whereText .="and string_to_array(choosen_meta_value, ',') && array [$servicessType]"; // if($storageArray>0){ $query3 ="select warehouse_id from uflexit_warehouse_meta where meta_key='wareHouseService' ".$whereText; $serviceIds = []; $serviceData= $this->db->get_results($query3); if(is_array($serviceData) && count($serviceData) > 0) { foreach($serviceData as $data){ // array_push($featureid,$data['warehouse_id']); $serviceIds[] = $data['warehouse_id']; } $servicesArray = implode(',',$serviceIds); // $storageData= $this->db->get_results($query3); // } $warehouseIds = $servicesArray; if($servicesArray != "") { $whereText = "and warehouse_id in (".$servicesArray.")"; } } } if($productdealsType != ''){ $whereText .="and string_to_array(choosen_meta_value, ',') && array [$productdealsType]"; $query4 ="select warehouse_id from uflexit_warehouse_meta where meta_key='productwareHouseDeals' ".$whereText; // echo $query4;exit; $productIds = []; $productDealsData= $this->db->get_results($query4); if(is_array($productDealsData) && count($productDealsData) > 0) { foreach($productDealsData as $data){ // array_push($featureid,$data['warehouse_id']); $productIds[] = $data['warehouse_id']; } $productsArray = implode(',',$productIds); // $storageData= $this->db->get_results($query3); // } $warehouseIds = $productsArray; } } // print_r($warehouseIds);exit; // print_r($warehouseIds);exit; if($spaceData != '') { $whereText .=""; $subQuery=''; if($warehouseIds !="") { $subQuery = "and warehouse_id in (".$warehouseIds.")"; } $storageIds=array(); if($storagesType!=''){ $storageIds=explode(',',$storagesType); } if(sizeof($storageIds)>0){ $subQuery.="and price_type=$storageIds[0]"; if(sizeof($storageIds)>1){ // echo "hello"; $subQuery.="and price_type=$storageIds[1]"; } } $query7 ="select warehouse_id from uflexit_warehouse_pricelist where $spaceData between minimum and maximum $subQuery "; // echo $query5;exit; $spaceDetails = []; $spaceDetailsData= $this->db->get_results($query7); // print_r($searchDaysData); if(is_array($spaceDetailsData) && count($spaceDetailsData) > 0) { foreach($spaceDetailsData as $data){ // array_push($featureid,$data['warehouse_id']); $spaceDetails[] = $data['warehouse_id']; } $searchSpaceArray = implode(',',$spaceDetails); // $storageData= $this->db->get_results($query3); // } $warehouseIds = $searchSpaceArray; }else { $warehouseIds=''; } } if($palletData != '') { $whereText .=""; $subQuery1=''; if($warehouseIds !="") { $subQuery1 = "and warehouse_id in (".$warehouseIds.")"; } else if($warehouseIds == "" && $searchData != "") { return 1; } $storageIds=array(); if($storagesType!=''){ $storageIds=explode(',',$storagesType); } if(sizeof($storageIds)>0){ if($storageIds[0]=="'2'"){ $subQuery1.=" and price_type=$storageIds[0]"; }else if(sizeof($storageIds)>1 && $storageIds[1]=="'2'"){ $subQuery1.=" and price_type=$storageIds[1]"; } } $query6 ="select warehouse_id from uflexit_warehouse_pricelist where $palletData between minimum and maximum $subQuery1"; // echo $query3;exit; $palletDetails = []; $palletDetailsData= $this->db->get_results($query6); if(is_array($palletDetailsData) && count($palletDetailsData) > 0) { foreach($palletDetailsData as $data){ // array_push($featureid,$data['warehouse_id']); $palletDetails[] = $data['warehouse_id']; } $searchPalletArray = implode(',',$palletDetails); // $storageData= $this->db->get_results($query3); // } $warehouseIds = $searchPalletArray; }else { $warehouseIds=''; } } if($searchData != '') { $whereText .=""; $subQuery=''; if($warehouseIds !="") { $subQuery = "and warehouse_id in (".$warehouseIds.")"; } $storageIds=array(); if($storagesType!=''){ $storageIds=explode(',',$storagesType); } if(sizeof($storageIds)>0){ $subQuery.="and price_type=$storageIds[0]"; if(sizeof($storageIds)>1){ // echo "hello"; $subQuery.="and price_type=$storageIds[1]"; } } $query5 ="select warehouse_id from uflexit_warehouse_pricelist where $searchData between minimum_period and maximum_period $subQuery "; // echo $query3;exit; $searchDays = []; $searchDaysData= $this->db->get_results($query5); // print_r($searchDaysData); if(is_array($searchDaysData) && count($searchDaysData) > 0) { foreach($searchDaysData as $data){ // array_push($featureid,$data['warehouse_id']); $searchDays[] = $data['warehouse_id']; } $searchDataArray = implode(',',$searchDays); // $storageData= $this->db->get_results($query3); // } $warehouseIds = $searchDataArray; }else { $warehouseIds=''; } } // echo "hii"; // echo $searchText; // exit; $whereQuery = ""; $searchText = trim($searchText); if($searchText) { $whereQuery = "and (uc.country_name ILIKE '%".$searchText."%' or umw.warehouse_name ILIKE '%".$searchText."%' or umw.warehouse_city ILIKE '%".$searchText."%')"; } if($warehouseIds !="") { $whereQuery .= "and umw.warehouse_id in (".$warehouseIds.")"; } if($whereQuery == "" && $filterInput == 0) { return 1; } // echo $whereQuery;exit; $query4 ="select umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id,umw.warehouse_packageid, umw.enable_online_booking, uc.country_name,uc.display_name,uc.lang_variables,ucty.city_name,ucty.lang_variables as city_lang_variable,up.lang_variable,up.package_name,(SELECT AVG(warehouse_rating) as rating FROM uflexit_request_quote where warehouse_id=umw.warehouse_id) from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON umw.warehouse_country_id=uc.country_id JOIN uflexit_cities as ucty ON umw.warehouse_city=ucty.city_name JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id $subQuery2 where 1=1 and umw.warehouse_status=1 ".$whereQuery." $subQuery3 LIMIT $max OFFSET $min" ; // echo $query4;exit; $warehouseData = $this->db->get_results($query4); // print_r($warehouseData);exit; if($warehouseData) { $query5 ="select umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id,umw.warehouse_packageid, umw.enable_online_booking, uc.country_name,uc.display_name,uc.lang_variables,ucty.city_name,ucty.lang_variables as city_lang_variable,up.lang_variable,up.package_name,(SELECT AVG(warehouse_rating) as rating FROM uflexit_request_quote where warehouse_id=umw.warehouse_id and rating_status=1) from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON umw.warehouse_country_id=uc.country_id JOIN uflexit_cities as ucty ON umw.warehouse_city=ucty.city_name JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id $subQuery2 where 1=1 and umw.warehouse_status=1 ".$whereQuery." $subQuery3 "; // echo $query5;exit; $warehouseCount = $this->db->get_results($query5); $warehouseData2 = array(); // print_r($warehouseData);exit; foreach($warehouseData as $wrow){ $query6="select warehouse_logo from uflexit_warehouse_imgs where warehouse_id='".$wrow['warehouse_id']."' LIMIT 1"; $image=$this->db->get_row($query6); // echo "<pre>"; // print_r($image); if(isset($image['warehouse_logo']) && $image['warehouse_logo']!="") { $wrow['warehouse_logo'] = $image['warehouse_logo']; } $warehouseData2[] = $wrow; } $count=count($warehouseCount); $dataArray=array(); array_push($dataArray,$count,$warehouseData2); //~ print_r($dataArray); return $dataArray; } return 1;// don't do anything // if($featuresType!=''){ // $featuresSubQuery="(meta_key='wareHousefeature' and string_to_array(uwm.choosen_meta_value, ',') @> array [$featuresType]) "; // if($storagesType!='' || $servicessType!=''){ // $featuresSubQuery.=" OR "; // } // } // if($storagesType!=''){ // $storagesubQuery= "(meta_key='wareHousePriceType' // and string_to_array(uwm.choosen_meta_value, ',') @> array [$storagesType])"; // if($servicessType!=''){ // $storagesubQuery.=" OR "; // } // } // if($servicessType!=''){ // $servicessubquery="(meta_key='productwareHouseDeals' and string_to_array(uwm.choosen_meta_value, ',') @> array [$servicessType])"; // } // $query="select uwm.warehouse_id,umw.* from uflexit_warehouse_meta as uwm // JOIN uflexit_master_warehouse as umw ON uwm.warehouse_id=umw.warehouse_id // where $featuresSubQuery $storagesubQuery $servicessubquery "; // echo $query; } /** * function name: warehouseDetails * decription: fetching warehouse features type Details * developed by: gowtham */ function warehouseFeaturesType(){ $query="select * from uflexit_warehouse_features "; $warehouseFeaturesData=$this->db->get_results($query); return $warehouseFeaturesData; } /** * function name: warehouseDetails * decription: fetching warehouse features type Details * developed by: gowtham */ function getQuationList($id){ $query="select quotation_id from uflexit_request_quote where user_id=$id and quotation_status=3 and closed_status != 4 and asn_status=0"; $quotationData=$this->db->get_results($query); return $quotationData; } function get_wareHouseData($id){ $query="select uc.currency,urq.warehouse_id,urq.whadmin_id,urq.asn_status, urq.admin_expected_rate,urq.user_id, umw.warehouse_name, umw.warehouse_packageid, urq.warehouse_request_type, us.first_name,us.last_name, us.role_id from uflexit_request_quote as urq JOIN uflexit_master_warehouse as umw ON urq.warehouse_id=umw.warehouse_id JOIN uflexit_users as us ON us.user_id=urq.user_id join uflexit_countries as uc on uc.country_id=urq.currency_type where urq.quotation_id=$id"; $warehouse_data=$this->db->get_row($query); return $warehouse_data; } /** * function name: requestQoute * decription: Updating subadmin details by admin * developed by: Surendra */ function productDealList($id=null){ $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where deal_id='.$id; } $query="select deal_id,deal_name from uflexit_warehouse_deals $extraQuery order by deal_name asc"; $data = $this->db->get_results($query); return $data; } function requestQuote($post,$session_id){ if(isset($post['productwareHouseDeals']) && $post['productwareHouseDeals'] !=''){ $productwareHouseDeals = implode(',', $post['productwareHouseDeals']); } // echo $session_id; $response=''; $userid=$session_id; $warehouseid=$post['warehouse_id']; $rand=time(); $select_type=strip_tags($this->db->escape(trim($post['pallet_or_space_type']))); if(isset($_POST['pallet']) && $_POST['pallet']!='' ){ $num_of_pallets_or_space=strip_tags($this->db->escape(trim($post['pallet']))); }else{ $num_of_pallets_or_space=strip_tags($this->db->escape(trim($post['space']))); } $from_date= $post['fromdate']; $to_date= $post['todate']; $total_days=strip_tags($this->db->escape(trim($post['total_days']))); $product_deals=strip_tags($this->db->escape(trim($productwareHouseDeals))); $description=strip_tags($this->db->escape(trim($post['description']))); $currency_type=strip_tags($this->db->escape(trim($post['currency_type']))); $expected_rate=strip_tags($this->db->escape(trim($post['currency']))); $request_type=strip_tags($this->db->escape(trim($post['warehouse_type']))); $total_wgt_goods=strip_tags($this->db->escape(trim($post['total_goods']))); // if(isset($_POST['jordn']) && $_POST['jordn']!='' ){ // $currency=strip_tags($this->db->escape(trim($post['jordn']))); // } // else if(isset($_POST['uae']) && $_POST['uae']!=''){ // $currency=strip_tags($this->db->escape(trim($post['uae']))); // }else if(isset($_POST['saudi']) && $_POST['saudi']!=''){ // $currency=strip_tags($this->db->escape(trim($post['saudi']))); // } // echo $product_deals; $wrow = $this->db->get_row("SELECT * FROM uflexit_master_warehouse WHERE warehouse_id=".(int)$warehouseid); $whadminid=$wrow["created_by"]; $query="SET DateStyle TO MDY;insert into uflexit_request_quote(storage_type,user_id,warehouse_id,choosen_pallets_space,num_of_days,choosen_deals,quotation_rand_num,whadmin_id,customer_description,currency_type,expected_rate,warehouse_request_type,from_date,to_date,total_wgt_goods) values('$select_type','$userid','$warehouseid','$num_of_pallets_or_space','$total_days','$product_deals','$rand','$whadminid','$description','$currency_type',$expected_rate,$request_type,'$from_date','$to_date','$total_wgt_goods') "; $row=$this->db->query($query); if($row){ $response=1; $notifyType=8; $title='Add Request Quote'; $name=$_SESSION['customer_name']; $message=$name.' sent an New Quotation Request '; $arabicmessage=$name.' أرسل طلب عرض أسعار جديد '; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); $readStatus=0; $querydata="select uc.user_id from uflexit_master_warehouse as umw join uflexit_users as uc ON uc.company_id=umw.company_id where umw.warehouse_id=$warehouseid and (role_id=1 or role_id=2)"; $result1=$this->db->get_results($querydata); $count=$result1?count($result1):0; for($i=0;$i<$count;$i++){ $receiverId=$result1[$i]['user_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehouseid,$userid,$receiverId,$date,$readStatus); } } else{ $response= 0; } return $response; } function QuoteList(){ $data=array(); $query="SELECT * FROM uflexit_request_quote WHERE user_id=".(int)$_SESSION['user_id']; $data=$this->db->get_results($query); return $data; } function setFlashMessage($msg,$flag='success'){ $_SESSION['msg'] = $msg; $_SESSION['msg_flag'] = $flag; } function flashMessage(){ if (isset($_SESSION['msg']) && strlen(trim($_SESSION['msg']))) { echo '<div class="alert alert-'.$_SESSION['msg_flag'].'">'.$_SESSION['msg'].'</div>'; unset($_SESSION['msg']); unset($_SESSION['msg_flag']); } } function redirect($path){ die("<script>window.location.href='".$path."'</script>"); } function get_price($price){ echo '₹'.number_format((float)$price,2); } function asnsubmit($post){ //print_r($post);exit; //Array ( [quote_id] => 4 [request_type] => test type [user_id] => 32 [customertype] => business [warehouse_name] => kakinad [warehouse_type] => Gold [date] => 28-12-2020 [time] => 22:25 [itemcode] => Array ( [0] => 001 [1] => 002 ) [item_desc] => Array ( [0] => test desc [1] => test desc2 ) [qty] => Array ( [0] => 10 [1] => 20 ) [ref_number] => Array ( [0] => ref 001 [1] => ref 002 ) [cost] => Array ( [0] => 1000 [1] => 500 ) [pallet_no] => Array ( [0] => 001pallet no [1] => 002 pallet no ) [asnsubmit] => Create ASN ) $createdDate=gmdate("Y-m-d H:m:i"); $que = "insert into uflexit_asn_request (warehouse_id,request_type,quotation_id,user_id,customer_type,price,date,time,created_date,created_by) VALUES (".$this->db->escape(trim($post['warehouse_id'])).",'".$this->db->escape(trim($post['request_type']))."',".$this->db->escape(trim($post['quote_id'])).",".$this->db->escape(trim($post['user_id'])).",'".$this->db->escape(trim($post['customertype']))."','".$this->db->escape(trim($post['quote_value']))."','".$this->db->escape(trim($post['date']))."','".$this->db->escape(trim($post['time']))."','".$createdDate."','".$_SESSION['customer_user_id']."')"; $res = $this->db->query($que); // print_r($res); if($res){ $sel = "select * from uflexit_asn_request order by asn_id desc"; $result = $this->db->get_row($sel); // print_r($result);echo '<br/>'; $lastId=$result['asn_id']; for($i=0;$i<count($_POST['itemcode']);$i++) { $query = "insert into uflexit_mini_goods_track (item_code,item_description,item_quantity,price,warehouse_id,warehouse_type,pallet_space_num,user_id,quotation_id,created_date,ref_number,asn_no) VALUES ('".$this->db->escape(trim($post['itemcode'][$i]))."','".$this->db->escape(trim($post['item_desc'][$i]))."','".$this->db->escape(trim($post['qty'][$i]))."','".$this->db->escape(trim($post['cost'][$i]))."','".$this->db->escape(trim($post['warehouse_id']))."','".$this->db->escape(trim($post['warehouse_type']))."','".$this->db->escape(trim($post['pallet_no'][$i]))."','".$this->db->escape(trim($post['user_id']))."','".$this->db->escape(trim($post['quote_id']))."','".$createdDate."','".$this->db->escape(trim($post['ref_number'][$i]))."','".$this->db->escape(trim($lastId))."')"; //echo '<br/>'; $res = $this->db->query($query); } return '1'; } //exit; // echo '<br/>'; } function savequationrate($post) { $wrow = $this->db->get_row("SELECT * FROM uflexit_request_quote WHERE quotation_id=".(int)$post['quotation_id']); //echo "SELECT * FROM uflexit_master_warehouse WHERE warehouse_id=".(int)$wrow['warehouse_id']; $wrow2 = $this->db->get_row("SELECT * FROM uflexit_master_warehouse WHERE warehouse_id=".(int)$wrow['warehouse_id']); $whadminid=$wrow2["created_by"]; //insert into uflexit_request_quote_track (quotation_id,admin_id,change_datetime,expected_rate,quotation_status,closed_status,"whAdmin_description",customer_description,whadmin_id) VALUES(7,8,'2020-12-25 16:16:16','500',0,0,'','Test PPPP',0) $query="insert into uflexit_request_quote_track (quotation_id,admin_id,change_datetime,expected_rate,quotation_status,closed_status,".'"'."whadmin_description".'"'.",customer_description,whadmin_id) VALUES(".$post['quotation_id'].",".$post['uid'].",'".date('Y-m-d H:i:s')."','".$post['expected_rate']."',".$post['quotation_status'].",0,'','".$post['whadmin_description']."',$whadminid)"; $row=$this->db->query($query); $query2="update uflexit_request_quote set expected_rate='".$post['expected_rate']."', quotation_status='".$post['quotation_status']."' where quotation_id=".$post['quotation_id'].""; $row=$this->db->query($query2); if($query2) { $returnVal=1; } return $returnVal; } /** * function name: isValidApiKey * decription: To stop Multiple logins with same login details * developed by: gowtham */ function isValidApiKey($token) { $query = "select * from uflexit_users where token = '".$token."'"; $data=$this->db->get_results($query); return $data; } /** * function name: Get Masteradmin warehouse details and product deals,services * decription: getting data for customer-viewarehouse details * developed by: Sai */ function getMasterAdminWareHouseDetails($id){ $warehousedetails= "SELECT a.*,c.country_id,INITCAP(c.country_name) as country_name,c.display_name from uflexit_master_warehouse as a JOIN uflexit_countries as c ON a.warehouse_country_id =c.country_id where warehouse_id=$id";; $results =$this->db->get_row($warehousedetails); // print_r($results); return $results; } /** * function name: Get Quotat * decription: Updating subadmin details by admin * developed by: Ramya */ function getQuotationsInfo($id) { $query = "select urq.*,uc.currency from uflexit_request_quote as urq join uflexit_countries as uc on urq.currency_type=uc.country_id where quotation_id = '".$id."'"; $data=$this->db->get_row($query); return $data; } /** * Function name: getWareHouseMainDetails * Decription: This is for get wareHouse master data from this table. * Developed by: Lathif */ function getWareHouseMainDetails($wareHouseId) { $data=array(); $query="select * from uflexit_master_wareHouse where warehouse_id=".$wareHouseId; $data = $this->db->get_row($query); return $data; } /** * function name: Get Quotat * decription: Updating subadmin details by admin * developed by: Surendra */ function getCustomerDetailsById($id) { $query = "select user_id,first_name,last_name,email,role_id from uflexit_users where user_id = '".$id."'"; $data=$this->db->get_row($query); return $data; } /** * function name: newAsn * decription: inserting new asn data by customer * developed by: gowtham */ function newAsn($postData){ // print_r($postData);exit; $createdDate=$this->db->escape(trim(gmdate("Y-m-d H:m:i"))); $userId=$this->db->escape(trim($postData['userId'])); $warehouseId=$this->db->escape(trim($postData['warehouseid'])); $warehouseAdminId=$this->db->escape(trim($postData['warehouseAdminid'])); $quotationid=$this->db->escape(trim($postData['quotationId'])); $customer=$this->db->escape(trim($postData['customer'])); $customerId=$this->db->escape(trim($postData['customerTypeId'])); $customerType=$this->db->escape(trim($postData['customerTypeText'])); $warehouseName=$this->db->escape(trim($postData['warehouseName'])); $warehouseType=$this->db->escape(trim($postData['warehouseType'])); $date=$this->db->escape(trim($postData['date'])); $time=$this->db->escape(trim($postData['time'])); $quoteValue=$this->db->escape(trim($postData['quoteValue'])); $request_type=$this->db->escape(trim($postData['requestType'])); $query="select from_date from uflexit_request_quote where quotation_id=$quotationid "; $result1 = $this->db->get_row($query); $fromDate=$result1['from_date'] ; $dateTimestamp1 = strtotime($fromDate); $dateTimestamp2 = strtotime($date); $status=''; if($dateTimestamp1>$dateTimestamp2){ $status="early"; }else if($dateTimestamp1<$dateTimestamp2){ $status="late"; }else{ $status="on date"; } $query="insert into uflexit_asn_request (warehouse_id,request_type,quotation_id,user_id,customer_type,price,date,time,created_date,created_by,wh_admin_id,asn_status) VALUES ($warehouseId,'".$request_type."',$quotationid,$userId,$customerId,$quoteValue,'$date','".$time."','".$createdDate."',$userId,$warehouseAdminId,'$status')"; $res = $this->db->query($query); if($res){ $sel = "select * from uflexit_asn_request order by asn_id desc"; $result = $this->db->get_row($sel); // print_r($result);echo '<br/>'; $lastId=$result['asn_id']; for($i=0;$i<count($_POST['itemcode']);$i++) { $itemCode=$this->db->escape(trim($postData['itemcode'][$i])); $itemDescripition=$this->db->escape(trim($postData['item_desc'][$i])); $itemQuantity=$this->db->escape(trim($postData['qty'][$i])); $itemReferenceNum=$this->db->escape(trim($postData['ref_number'][$i])); $cost=$this->db->escape(trim($postData['cost'][$i])); $palletNumber=$this->db->escape(trim($postData['pallet_no'][$i])); if($itemCode!=''){ $query = "insert into uflexit_mini_goods_track (item_code,item_description,item_quantity,price,warehouse_id,warehouse_type,pallet_space_num,user_id,quotation_id,created_date,ref_number,asn_no) VALUES ('$itemCode','".$itemDescripition."',$itemQuantity, $cost,$warehouseId,'".$warehouseType."', '".$palletNumber."',$userId,$quotationid,'".$createdDate."', '".$itemReferenceNum."',$lastId) "; $res = $this->db->query($query); } } if( $res){ $query1="update uflexit_request_quote set asn_status=1 where quotation_id =$quotationid"; $result=$this->db->query($query1); $querydata="select uc.user_id from uflexit_master_warehouse as umw join uflexit_users as uc ON uc.company_id=umw.company_id where umw.warehouse_id=$warehouseId and (role_id=1 or role_id=2)"; $result1=$this->db->get_results($querydata); $count=$result1?count($result1):0; if($result){ $notifyType=15; $title='Add ASN Request'; $name=$_SESSION['customer_name']; $message=$name.' has sent you ASN to QID:'.$quotationid ." for the ".$warehouseName." warehouse"; $arabicmessage=$name.' تم إرسال إشعار الشحن المسبق الى عرض الأسعار:'.$quotationid ." ل ".$warehouseName." مستودع"; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); $readStatus=0; for($i=0;$i<$count;$i++){ $receiverId=$result1[$i]['user_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehouseId,$userId,$receiverId,$date,$readStatus); } return 1; } } } } /** * function name: get_warehouses * decription: fetching warehouse data by customer using searchbar * developed by: gowtham */ // function get_warehouses($searchKey){ // $query="select umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id,umw.warehouse_packageid, umw.enable_online_booking, uc.country_name,up.package_name from uflexit_countries as uc JOIN uflexit_master_warehouse as umw ON umw.warehouse_country_id=uc.country_id JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id where uc.country_name='$searchKey' or umw.warehouse_name='$searchKey'"; // $result=$this->db->get_results($query); // // print_r($result); // if($result){ // return $result; // }else{ // return 1; // } // } /** * function name: updateQuotationStatus * decription: Updating subadmin details by admin * developed by: Ramya */ function updateQuotationStatus($post) { $createdDate=gmdate("Y-m-d H:m:i"); $query="insert into uflexit_request_quote_track (quotation_id,admin_id,change_datetime,expected_rate,quotation_status,closed_status,".'"'."whadmin_description".'"'.",customer_description,whadmin_id,admin_expected_rate) VALUES(".$post['quotation_id'].",".$post['user_id'].",'".date('Y-m-d H:i:s')."','".$post['expected_rate']."',".$post['quotation_status'].",".$post['closed_status'].",'".$post['adminDescription']."','".$post['customer_description']."','".$post['whadmin_id']."','".$post['adminExpectedRate']."')"; $row=$this->db->query($query); $query2="update uflexit_request_quote set customer_description='".$post['customer_description']."', quotation_status='".$post['quotation_status']."', closed_status='".$post['quotation_status']."', whadmin_description='".$post['adminDescription']."',modify_dt='".date('Y-m-d')."' where quotation_id=".$post['quotation_id'].""; $row=$this->db->query($query2); if($query2) { $returnVal=1; } return $returnVal; } /** * Function name: getWorkingHours * Decription:This is for bring wareHouse price List data * Developed by: Lathif */ function getWorkingHours($wareHouseId) { $data=array(); $query="select * from uflexit_warehouse_workingHours where warehouse_id=".$wareHouseId; $data = $this->db->get_results($query); $newData = []; foreach ($data as $dat) { $newData[$dat['working_day']] = $dat; } return $newData; } /** * Function name: getTopWarehouses * Decription:This is for bring top warehouse data * Developed by: Ramya */ function getTopWarehouses() { $data=array(); $query ="select distinct umw.warehouse_name,umw.warehouse_id,umw.warehouse_country_id, (SELECT AVG(warehouse_rating) as rating FROM uflexit_request_quote where warehouse_id=umw.warehouse_id), (SELECT warehouse_logo as warehouse_img FROM uflexit_warehouse_imgs where warehouse_id=umw.warehouse_id limit 1), umw.warehouse_packageid, umw.enable_online_booking,up.package_name from uflexit_master_warehouse as umw JOIN uflexit_packages as up ON umw.warehouse_packageid=up.package_id join uflexit_request_quote as urq on urq.warehouse_id=umw.warehouse_id where umw.warehouse_status=1 and urq.rating_status=1 ORDER BY rating DESC limit 5 " ; $warehouseData = $this->db->get_results($query); if($warehouseData) { return $warehouseData; } return $data; } function getWarehouseImages($id){ $query="select warehouse_logo from uflexit_warehouse_imgs where warehouse_id=$id"; $count=$this->db->num_rows($query); if($count>0){ return $this->db->get_results($query); } } /** * function name: getWarehouseList * decription:get all the data from table uflexit_master_wareHouse; * developed by: Ramyakrishna */ function getWarehouseList($id=""){ $whereCondition = ""; if($id !="") { $whereCondition = "and umw.warehouse_id =".$id; } $query= "SELECT * FROM uflexit_master_wareHouse as umw inner join uflexit_countries on umw.warehouse_country_id=uflexit_countries.country_id join uflexit_packages as up on umw.warehouse_packageid=up.package_id where 1=1 ".$whereCondition; $count=$this->db->num_rows($query); if($count>0) { return $this->db->get_results($query); } } /** * function name: getWareHouseDeals * decription: This is used for bring all the getWareHouse deals * developed by: Ramya Priya */ function getWareHouseDeals($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where deal_id='.$id; } //~ $query="select deal_id,deal_name from uflexit_warehouse_deals $extraQuery order by deal_name asc"; $query="select deal_id,deal_name,lang_variables from uflexit_warehouse_deals $extraQuery"; $data = $this->db->get_results($query); return $data; } /** * function name: getWareHouseServices * decription: This is used for bring all the getWareHouseServices * developed by: lathif */ function getWareHouseServices($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where service_id='.$id; } $query="select service_id,service_name,lang_variables from uflexit_warehouse_services $extraQuery order by service_name asc"; $data = $this->db->get_results($query); return $data; } /** * function name: getWareHouseFeatures * decription: This is used for bring all the getWareHouseFeatures * developed by: lathif */ function getWareHouseFeatures($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where feature_id='.$id; } $query="select feature_id,feature_name,lang_variables from uflexit_warehouse_features $extraQuery order by feature_id asc"; $data = $this->db->get_results($query); return $data; } /** * Function name: getWareHouseMetaDetails * Decription:This is for bring meta data from wareHouse * Developed by: Lathif */ function getWareHouseMetaDetails($wareHouseId) { $data=array(); $query="select meta_id,warehouse_id,meta_key,choosen_meta_value from uflexit_wareHouse_meta where warehouse_id=".$wareHouseId; $data = $this->db->get_results($query); return $data; } /** * function name: getWareHouseSpace * decription: This is used for bring all the getWareHouseFeatures * developed by: lathif */ function getWareHouseSpace($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where space_id='.$id; } $query="select * from uflexit_warehouse_space $extraQuery order by space_name asc"; $data = $this->db->get_results($query); return $data; } /** * function name: getWarehouseType * decription: This is used for uflexit Warehouse Type * developed by: lathif */ function getWarehouseTypeWithId($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='and pricetype_id='.$id; } $query="select pricetype_id,pricetype_name,lang_variables from uflexit_warehouse_type where pricetype_id!=1 $extraQuery order by pricetype_name asc"; $data = $this->db->get_results($query); return $data; } /** * function name: getWorkWithList * decription: This is for get workWith list data purpose * developed by: lathif */ function getWorkWithList($id=null) { $data=array(); $extraQuery=''; if((int)$id) { $extraQuery='where work_id='.$id; } $query="select work_id,work_name,lang_variables from uflexit_warehouse_workwith $extraQuery order by work_id asc"; $data = $this->db->get_results($query); return $data; } /** * Function name: getWHPriceList * Decription:This is for bring wareHouse price List data * Developed by: Lathif */ function getWHPriceList($wareHouseId,$type='') { $data=array(); $typeCondition = ''; if($type !='') { $typeCondition = "price_type ='".$type."' and "; } //$query="select * from uflexit_warehouse_priceList where $typeCondition warehouse_id=".$wareHouseId; $query="select * from uflexit_warehouse_priceList where $typeCondition warehouse_id=".$wareHouseId; // echo $query; //echo '<br/>'; $data = $this->db->get_results($query); // echo "check"; // print_r($data);exit; //print_r($data);echo '<br/><br/>'; return $data; } function getInvoiceInfo($id){ $query="SELECT urq.currency_type,uc.currency,ui.*,umw.warehouse_name,umw.warehouse_number,us.first_name,us.last_name FROM uflexit_invoice as ui JOIN uflexit_master_warehouse as umw on ui.warehouse_id=umw.warehouse_id JOIN uflexit_users as us ON ui.user_id=us.user_id join uflexit_request_quote as urq on urq.quotation_id=ui.quotation_id join uflexit_countries as uc on uc.country_id=urq.currency_type WHERE ui.invoice_number='$id'"; $row = $this->db->get_row($query); if($row) { return $row; } return 0; } function getInvoicesItemsInfo($id){ $query="SELECT * FROM uflexit_invoice_track WHERE invoice_number='$id'"; $data = $this->db->get_results($query); if($data) { return $data; } return 0; } function addNotification($notifyType,$title,$message,$arabicmessage,$warehouseid,$userid,$whadminid,$date,$readStatus){ //~ echo $arabicmessage;exit; $query="insert into uflexit_notifications (notification_type,title,message,warehouse_id,sender_id,receiver_id,created_date,read_status,arabicmessage) VALUES ($notifyType,'$title','$message',$warehouseid,$userid,$whadminid,'$date',$readStatus,'$arabicmessage')"; //~ echo $query;exit; $result=$this->db->query($query); // print_r($result); return $result; } function smtpMail($baseUrl,$htmlContent,$subject,$to=null){ date_default_timezone_set('Etc/UTC'); // testing //~ $google_email = 'info.uflexit@gmail.com'; //~ $oauth2_clientId = '525591957251-up6skvl6mm1ies67vthnk4fkskio9n2a.apps.googleusercontent.com'; //~ $oauth2_clientSecret = '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'; //~ $oauth2_refreshToken = '1//04LF-X9AzykxVCgYIARAAGAQSNwF-L9IrDUrSqwpOoICu2nP2gRKKNONuI3x4v_jW1L_z2RAD0bhy3vQGmpaQwL4M7T4F70CewTU'; //~ $mail = new PHPMailer(TRUE); //~ try { //~ $mail->setFrom($google_email, 'Uflexit'); //~ $mail->addAddress($to); //~ // $mail->addCC('aruna.k@krify.net'); //~ //$mail->addBCC('bcc@example.com'); //~ $mail->Subject = $subject; //~ $mail->Body =$htmlContent; //~ $mail->isSMTP(); //~ $mail->Port = 587; //~ $mail->SMTPAuth = TRUE; //~ $mail->SMTPSecure = 'tls'; //~ $mail->IsHTML(true); //~ /* Google's SMTP */ //~ $mail->Host = 'smtp.gmail.com'; //~ /* Set AuthType to XOAUTH2. */ //~ $mail->AuthType = 'XOAUTH2'; //~ /* Create a new OAuth2 provider instance. */ //~ $provider = new Google( //~ [ //~ 'clientId' => $oauth2_clientId, //~ 'clientSecret' => $oauth2_clientSecret, //~ ] //~ ); //~ /* Pass the OAuth provider instance to PHPMailer. */ //~ $mail->setOAuth( //~ new OAuth( //~ [ //~ 'provider' => $provider, //~ 'clientId' => $oauth2_clientId, //~ 'clientSecret' => $oauth2_clientSecret, //~ 'refreshToken' => $oauth2_refreshToken, //~ 'userName' => $google_email, //~ ] //~ ) //~ ); //~ /* Finally send the mail. */ //~ if ($mail->send()) { //~ // echo "Mail sent successfully"; //~ // exit; //~ } else { //~ // echo "Mail not sent"; //~ } //~ } //~ catch (Exception $e) //~ { //~ echo $e->errorMessage(); //~ } //~ catch (\Exception $e) //~ { //~ echo $e->getMessage(); //~ } $query="Select * from uflexit_smtp_mailandpass"; $result=$result=$this->db->get_row($query); if($result){ $adminemail = $result['mail']; $to =$to; $mail = new PHPMailer; $mail->isSMTP(); /*Outlook host is smtp.office365.com*/ $mail->Host = "smtp.office365.com"; $mail->Port = "587"; /*tls true*/ $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = $adminemail; $mail->Password = $result['password']; /* setfrom and username should be always same */ $mail->setFrom($adminemail); if(is_array($to)){ if($to!="") { foreach($to as $to1){ $mail->addAddress($to1); } } } else{ $mail->addAddress($to); } // $mail->addAddress($to); $mail->Subject = $subject; $mail->msgHTML($htmlContent); if (!$mail->send()) { echo "Mailer Error"; // echo "<pre>"; // print_r($mail); // die('fail'); }else{ // echo "success"; // die('done'); } } else{ echo "Credential expired"; } } /** * function name: sendNotificationsQuotationStatus * decription: sending notifications when customer Accept or reject * developed by: gowtham */ function sendNotificationsQuotationStatus($post,$type){ // print_r($post);exit; $quotationId=$post['quotation_id']; $warehouseid=$post['warehouseId']; $name=$_SESSION['customer_name']; $query="select warehouse_name from uflexit_master_warehouse where warehouse_id=".$warehouseid; $res=$this->db->get_row($query); $warehouseName=$res['warehouse_name']; // echo $warehouseName;exit; if($type==3){ $notifyType=10; $title='Quotation Accepted'; $message=$name.' Accepted Your Response to QID:' .$quotationId.' for '.$warehouseName.' warehouse '; $arabicmessage=$name.' تم قبول الرد على عرض الأسعار:' .$quotationId.' ل '.$warehouseName.' مستودع '; }else if($type==2){ $notifyType=10; $title='Quotation rejected'; $message=$name.' Rejected Your Response to QID:' .$quotationId.' for '.$warehouseName.' warehouse '; $arabicmessage=$name.' تم رفض الرد على عرض الاسعار:' .$quotationId.' ل '.$warehouseName.' مستودع '; } $userid=$_SESSION['customer_user_id']; $dt = new DateTime(); $dt->setTimezone(new DateTimeZone('UTC')); $date=$dt->format('Y-m-d H:i:s'); $readStatus=0; $querydata="select uc.user_id from uflexit_master_warehouse as umw join uflexit_users as uc ON uc.company_id=umw.company_id where umw.warehouse_id=$warehouseid and (role_id=1 or role_id=2)"; $result1=$this->db->get_results($querydata); $count=$result1?count($result1):0; for($i=0;$i<$count;$i++){ $receiverId=$result1[$i]['user_id']; $this->addNotification($notifyType,$title,$message,$arabicmessage,$warehouseid,$userid,$receiverId,$date,$readStatus); } } function getCustomerNotifications($userId,$minVal){ // $user_id=$_SESSION['user_id']; $newdate = date("Y-m-d", strtotime("-30 days")); $query=" select title,message,arabicmessage,notification_id,created_date from uflexit_notifications where read_status=0 and receiver_id=$userId and created_date>='$newdate' order by created_date desc "; $result=$this->db->get_results($query); $notificationCount=$result? count($result):0; $query1=" select un.title,un.message,un.arabicmessage,un.notification_id,un.created_date,unt.customer_path,un.read_status from uflexit_notifications as un join uflexit_notifications_type as unt on unt.type=un.notification_type where receiver_id=$userId and un.created_date>='$newdate' order by created_date desc LIMIT 5 OFFSET $minVal "; $notificationData=$this->db->get_results($query1); $notificationArray=array(); array_push($notificationArray,$notificationCount,$notificationData); if($notificationData){ return $notificationArray; }else { return 0; } } function updateNotificationStatus($id){ $query="update uflexit_notifications set read_status=1 where notification_id=$id"; $result=$this->db->query($query); } function getShipmentStatusData($id){ $query="select uar.asn_status,urq.currency_type,uc.currency,uar.quotation_id,uar.warehouse_id,uar.request_type,uar.customer_type,uar.date,uar.price,uar.time,umw.warehouse_name,us.first_name from uflexit_asn_request as uar JOIN uflexit_master_warehouse as umw ON umw.warehouse_id=uar.warehouse_id JOIN uflexit_users as us ON us.user_id=uar.created_by join uflexit_request_quote as urq on urq.quotation_id=uar.quotation_id join uflexit_countries as uc on uc.country_id=urq.currency_type where uar.quotation_id='".$id."'"; //~ echo $query;exit; $data=$this->db->get_results($query); $date=date_create($data[0]['date']); $data[0]['date']=date_format($date,"d-m-Y"); // print_r($data); return $data; } function getComapnyInfo($company_id){ $query="select uc.cr_number,uc.tax_reg_number,uca.uploaded_attachement,uc.company_name,city_name,address from uflexit_company as uc join uflexit_company_attachements as uca on uc.company_id=uca.company_id where uc.company_id=$company_id"; //~ echo $query;exit; $row=$this->db->get_row($query); if($row){ return $row; } return array(); } function warehouseStorageTypeById($id){ // echo $id;exit; $query="select pricetype_name from uflexit_warehouse_type where pricetype_id=$id"; $warehouseTypeData=$this->db->get_results($query); return $warehouseTypeData; } function requestWarehouse($post) { $countryDetails = $this->get_currency($post['country']); $country = $countryDetails[0]['display_name']; $productsLength = count($post['productreqwareHouseDeals']); $storageLength = count($post['storageType']); $palletReq = $post['palletReq']; $spaceReq = $post['spaceReq']; $dealNames = array(); if(isset($_SESSION['customer_user_id']) && $_SESSION['customer_user_id'] != "") { $customer_id = $_SESSION['customer_user_id']; // echo $customer_id;exit; $query = "SELECT * from uflexit_users WHERE user_id=".$customer_id; $customer_details=$this->db->get_results($query); foreach($customer_details as $cdetails) { $customer_name = $cdetails['first_name']. ' ' .$cdetails['last_name']; $customer_email = $cdetails['email']; $customer_phone = $cdetails['mobile_number']; if($cdetails['company_id'] != "") { $query = "SELECT company_name from uflexit_company WHERE company_id=".$cdetails['company_id']; $company_details=$this->db->get_results($query); foreach($company_details as $cmdata) { $company_name = '<b>Company Name :</b>'.$cmdata['company_name'].' <br>'; } } else { $company_name = ""; } //~ print_r($company_details);exit; $customer_data = 'User has requested for new warehouse with following details:<br> <strong>User Details</strong><br> <b>User Name :</b>'.$customer_name.' <br> <b>Email :</b>'.$customer_email.' <br> <b>Phone Number :</b>'.$customer_phone.' <br> '.$company_name.''; } } else { $customer_data = "Guest User has requested for new warehouse with following details"; } // echo $productsLength;exit; if($productsLength >= 1) { foreach($post['productreqwareHouseDeals'] as $productDeals) { $dealNames[] = $this->getWareHouseDeals($productDeals); } } // echo "<pre>"; // print_r($dealNames);exit; if($productsLength == 24) { $i = 1; } else { $i=0; } for($i;$i<$productsLength;$i++) { $products[] = $dealNames[$i][0]['deal_name']; } // print_r($products);exit; $deals=implode(',',$products); // echo $storageLength;exit; foreach($post['storageType'] as $stype) { // echo $stype;exit; $storageTypes[] = $this-> warehouseStorageTypeById($stype); // print_r($storage);exit; } for($i=0;$i<$storageLength;$i++) { $storage[] = $storageTypes[$i][0]['pricetype_name']; } // print_r($storage);exit; $dealStorage = implode(', ',$storage); // print_r($dealStorage);exit; $storageSpace = ''; if($dealStorage == "Pallet") { $storageSpace = '<b>Pallets Required :</b>'.$palletReq.' <br>'; } else if($dealStorage == "Space") { $storageSpace = '<b>Space Required :</b>'.$spaceReq.' (Sqmts) <br>'; } else { $storageSpace = '<b>Pallets Required :</b>'.$palletReq.' <br> <b>Space Required :</b>'.$spaceReq.' (Sqmts) <br>'; } $baseUrl=HOSTPATH; $subject = "Requesting for new Warehouse"; $to = "info@uflexit.com"; $htmlContent = '<html> <head> <title>Uflexit WareHouse Service</title> </head> <body> <b>Dear Admin,</b><br> <p>'.$customer_data.'<br> <b>Requested Warehouse Details</b><br> <b>Country :</b>'.$country.' <br> <b>City :</b>'.$post['city'].' <br> <b>Storage Space :</b>'.$dealStorage.' <br> '.$storageSpace.' <b>From Date :</b>'.$post['FromDate'].' <br> <b>To Date :</b>'.$post['Todatereq'].' <br> <b>Products :</b>'.$deals.' <br> <b>Description :</b>'.$post['reqText'].' <br> </p> </body> </html>'; //~ echo $htmlContent;exit; $res=$this->smtpMail($baseUrl,$htmlContent,$subject,$to); if($res) { return 1; } } } ?>