JezK
Edit File: functions1.php
<?php class uflexitCustomer { function __construct() { require_once dirname(__FILE__) . '/uflexitConnect.php'; $db = new uflexitDbConnect(); $this->con = $db->connect(); } /** * function name: generateApiKey * decription: for generating random md5 hash token * developed by: lathif */ function generateApiKey() { return md5(uniqid(rand(), true)); } /** * function name: getBaseURL * decription: for get rul purpose * developed by: lathif */ function getBaseURL() { $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = ($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $url1 = explode('uflexit_web_new', $url); //print_r($url1);exit; return $url1[0]; } /** * 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(mysqli_real_escape_string($this->con,trim($email))); $query="select * from uflexit_users where email='".$trimEmail."'"; $row = mysqli_query($this->con, $query); $count=mysqli_num_rows($row); if(isset($count) && $count>0) { $returnVal=1; } 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(mysqli_real_escape_string($this->con,trim($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!=''"; $row = mysqli_query($this->con, $query); $count=mysqli_num_rows($row); 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(mysqli_real_escape_string($this->con,trim($phone))); $query="select * from uflexit_users where mobile_number='".$trimPhone."'"; $row = mysqli_query($this->con, $query); $count=mysqli_num_rows($row); 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(mysqli_real_escape_string($this->con,trim($post['company_name']))); $designation=strip_tags(mysqli_real_escape_string($this->con,trim($post['designation']))); $country=strip_tags(mysqli_real_escape_string($this->con,trim($post['country']))); if(isset($post['zip'])) { $zip=strip_tags(mysqli_real_escape_string($this->con,trim($post['zip']))); } } if($role == 3) { $location=strip_tags(mysqli_real_escape_string($this->con,trim($post['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']))); if(isset($post['first_name'])) $first_name=strip_tags(mysqli_real_escape_string($this->con,trim($post['first_name']))); if(isset($post['last_name'])) $last_name=strip_tags(mysqli_real_escape_string($this->con,trim($post['last_name']))); $email=strip_tags(mysqli_real_escape_string($this->con,trim($post['email']))); $password=strip_tags(mysqli_real_escape_string($this->con,trim($post['password']))); $mobile_number=strip_tags(mysqli_real_escape_string($this->con,trim($post['mobile_number']))); $city=strip_tags(mysqli_real_escape_string($this->con,trim($post['city']))); $address=strip_tags(mysqli_real_escape_string($this->con,trim($post['address']))); //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 set email='".$email."', mobile_number='".$mobile_number."', role_id='".$role."', designation='".$designation."', password='".$convertedPassword."', first_name='".$first_name."', last_name='".$last_name."', city_name='".$city."', address='".$address."', country_id='".$country."', postal_code='".$zip."', location='".$location."', email_active_token='".$emailactiveToken."', created_date='".$createdDate."'"; // echo $query;exit; $row=mysqli_query($this->con, $query); $lastInsertId=mysqli_insert_id($this->con); if($row) { if($role ==1 || $role==4) { $createCompany=$this->createCompany($company_name,$city,$address,$role,$lastInsertId); //exit; } $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 set company_name='".strtolower($company_name)."', role_id='".$role."', user_id='".$userId."', city_name='".$city."', address='".$address."', created_date='".$createdDate."'"; //echo $query;exit; $row=mysqli_query($this->con, $query); if($row) { $returnVal=1; } return $returnVal; } /** * function name: emailActivation * decription: This is for activating email for customer or admin * developed by: lathif */ function emailActivation($token) { $returnVal=0; $trimToken=strip_tags(mysqli_real_escape_string($this->con,trim($token))); $query="select * from uflexit_users where email_active_token='".$trimToken."' and email_active=0"; $row = mysqli_query($this->con, $query); $count=mysqli_num_rows($row); if(isset($count) && $count>0) { $fetch=mysqli_fetch_assoc($row); $query1="update uflexit_users set email_active=1 where user_id='".$fetch['user_id']."'"; $row1=mysqli_query($this->con, $query1); if($row1) $returnVal=1; } else { $returnVal=2; } return $returnVal; } /** * 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 = $this->getBaseURL(); $fromName = 'Uflexit'; $from='admin@uflexit.com'; $to=$post['email']; if($role==1 || $role==2) { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= 'From: ' . $fromName . '<' . $from . '>' . "\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= 'Cc: ' .$from. "\r\n"; $headers .= 'Bcc: ' .$from. "\r\n"; $subject='Email Activation from Uflexit'; $customerContent=''; if($role!=2) { $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" >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">Password</td> <td style="width: 5%;">:</td> <td style="width: 50%;">' . $post['password'] . '</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 . 'uflexit_web_new/emailverification.php?etoken='.$emailToken.'" target="_blank">Activate</a></td> </tr> '; } else { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= 'From: New Registration'.'<' . $to . '>' . "\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= 'Cc: ' .$to. "\r\n"; $headers .= 'Bcc: ' .$to. "\r\n"; $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 style="text-align:center;width: 550px;margin: 40px auto;background-color: #828282;"> <div style="padding:10px"> <img src="' . $baseUrl . '/uflexit_web_new/images/loginlogo.png" alt="Website Change Request" alt="Website Change Request"/> </div> <div style="color: #fdff05;font-size: 24px;text-align:center !important;font-weight: 600;">Registration Details</div> <div style="margin:15px;padding:20px !important;"> <table style="width: 100%;"> <tbody style="overflow:auto;font-size: 16px;"> '.$customerContent.' </tbody> </table> <h3 style="color: #3c3a4b;font-size: 18px;color: #fff"><br/>Thanks & Regards<br/> Uflexit Team</h3> </div> </div> </body> </html>'; echo "<br/>"; //echo $htmlContent;exit; $sent_mail_customer = mail($to, $subject, $htmlContent, $headers); //mail to customer $sent_mail_admin = mail($from, $subject, $htmlContent, $headers); //mail to Admin 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 */ $returnVal = array(); if($type!=NULL) { $subQuery=' AND role_id="'.$type.'"'; } $email=strip_tags(mysqli_real_escape_string($this->con,trim($post['email']))); $password=strip_tags(mysqli_real_escape_string($this->con,trim($post['password']))); $query='SELECT * FROM uflexit_users WHERE email="' .$email. '" '.$subQuery.''; $row = mysqli_query($this->con, $query); if (mysqli_num_rows($row) > 0) { $loginDetails = mysqli_fetch_assoc($row); if($this->checkPasswordMatch($password,$loginDetails['password'])) { if ($loginDetails['email_active'] == 1) { $returnVal['details'] = $loginDetails; $returnVal['status'] = 1; //success } else if ($loginDetails['email_active'] == 0) { $returnVal['status'] = 3; //email verfication pending } } else{ $returnVal['status'] = 2; //password wrong } } 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 * FROM `uflexit_countries`"; $row = mysqli_query($this->con, $query); if (mysqli_num_rows($row) > 0) { while($result = mysqli_fetch_assoc($row)) { $data[]=$result; } } return $data; } /** * function name: forgotPassword * decription: forgotPassword functionality * developed by: yamuna */ function forgotPassword($post) { $returnValue = 0; $email=strip_tags(mysqli_real_escape_string($this->con,trim($post['email']))); $query='SELECT * FROM uflexit_users WHERE email="' .$email. '"'; $row = mysqli_query($this->con,$query); if(mysqli_num_rows($row) > 0) { $result = mysqli_fetch_assoc($row); $this->sendForgetPasswordMail($post,$result['email_active_token']); $returnValue = 1; } return $returnValue; } function sendForgetPasswordMail($email,$emailToken=null) { $baseUrl = $this->getBaseURL(); $fromName = 'Uflexit'; $from='admin@uflexit.com'; $to=$email; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= 'From: ' . $fromName . '<' . $from . '>' . "\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= 'Cc: ' .$from. "\r\n"; $headers .= 'Bcc: ' .$from. "\r\n"; $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 . 'uflexit_web_new/resetPassword.php?etoken='.$emailToken.'"" 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;background-color: #828282;"> <div style="color: #fdff05;font-size: 24px;text-align:center !important;font-weight: 600;padding-top:10px;">Reset your password by Clickingz below link</div> <div style="margin:15px;padding:20px !important;"> <table style="width: 100%;"> <tbody style="overflow:auto;font-size: 16px;"> '.$customerContent.' </tbody> </table> <h3 style="color: #3c3a4b;font-size: 18px;color: #fff"><br/>Thanks & Regards<br/> Uflexit Team</h3> </div> </div> </body> </html>'; //echo "<br/>"; $sent_mail_customer = mail($to, $subject,$htmlContent,$headers); //mail to forget password user return true; } /** * function name: changePassword * decription: This is for forgetPassword for user and admin * developed by: yamuna */ function changePassword($post) { //$returnVal=0; $returnVal = array(); $password=strip_tags(mysqli_real_escape_string($this->con,trim($post['password']))); $cnfrmPassword=strip_tags(mysqli_real_escape_string($this->con,trim($post['cnfrmPassword']))); $token=strip_tags(mysqli_real_escape_string($this->con,trim($post['token']))); $query='SELECT * FROM uflexit_users WHERE email_active_token="' .$token. '"'; $row = mysqli_query($this->con,$query); if(mysqli_num_rows($row) > 0) { $result = mysqli_fetch_assoc($row); if($password == $cnfrmPassword) { $convertedPassword=$this->generateSecuredPassword($password); $query1="UPDATE `uflexit_users` SET `password`='$convertedPassword' WHERE `email_active_token`='$token'"; $row1=mysqli_query($this->con, $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 userCustomerEdit($post){ $returnVal=0; $customer_name = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_name']))); $customer_email = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_email']))); $customer_contact = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_contact']))); $customer_address = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_address']))); $customer_sgiftment_address = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_sgiftment_address']))); $customer_city = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_city']))); if(isset($post['customer_password'])){ $customer_password = strip_tags(mysqli_real_escape_string($this->con,trim($post['customer_password']))); $convertedPassword=$this->generateSecuredPassword($customer_password);} $checkEmail=$this->checkEmailExistsOrNot($customer_email); $checkPhone=$this->checkPhoneExistsOrNot($customer_contact); $fileName = $_FILES["formUpload"]['name']; $createdDate = gmdate("Y-m-d H:m:i"); $emailactiveToken=$this->generateApiKey(); //echo "hiii"; if($post['customer_password']){ $query="update uflexit_users set mobile_number='".$customer_contact."', password='".$convertedPassword."', customername='".$customer_name."', city_name='".$customer_city."', address='".$customer_address."', otheraddress ='".$customer_sgiftment_address."', email_active_token='".$emailactiveToken."', created_date='".$createdDate."'where email='".$customer_email."'"; }else if($fileName){ $fileName = explode(".",$fileName); // print_r( $fileName); $fileName = $fileName[0].time().".".$fileName[1]; echo $fileName; $target_dir = "../uploads/customer_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='".$customer_contact."', customername='".$customer_name."', city_name='".$customer_city."', address='".$customer_address."', upload_pic='".$fileName."', otheraddress ='".$customer_sgiftment_address."', email_active_token='".$emailactiveToken."', created_date='".$createdDate."'where email='".$customer_email."'"; }else{ $query="update uflexit_users set mobile_number='".$customer_contact."', customername='".$customer_name."', city_name='".$customer_city."', address='".$customer_address."', otheraddress ='".$customer_sgiftment_address."', email_active_token='".$emailactiveToken."', created_date='".$createdDate."'where email='".$customer_email."'"; } $row=mysqli_query($this->con, $query); $lastInsertId=mysqli_insert_id($this->con); if($row) { $returnVal=3; }else{ $returnVal=4; } return $returnVal; } function getCustomerDetails() { $data=array(); $query="SELECT * FROM `uflexit_users`"; $row = mysqli_query($this->con, $query); if (mysqli_num_rows($row) > 0) { while($result = mysqli_fetch_assoc($row)) { $data[]=$result; } } return $data; } } ?>