%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php class Api_model extends CI_Model { /* * Send OTP to public users */ public function sendOTPToUser($mobile_number, $full_name='User', $currentpackage){ //generate OTP $randomOtp = $this->generateOTP(); $sms_content = 'Your One Time Password (OTP) for sharda diagnostics login is '.$randomOtp; $params = array(); if(strlen($mobile_number)>=10){ //send OTP to user $params = array(); $otpresponse = $this->pushAlertSMS($mobile_number, $sms_content); $params = array('phone'=>$mobile_number,'otp'=>$randomOtp); $resp = $this->addeditUsersPublicTable($table_name='users_public', $params); return $resp; } } public function sendOTPToUserRequest($mobile_number, $full_name='User'){ //generate OTP $randomOtp = $this->generateOTP(); $sms_content = 'Your One Time Password (OTP) for sharda diagnostics login is '.$randomOtp; $params = array(); if(strlen($mobile_number)>=10){ //send OTP to user $params = array(); $otpresponse = $this->pushAlertSMS($mobile_number, $sms_content); $params = array('mobile_number'=>$mobile_number,'otp'=>$randomOtp,'full_name'=>$full_name,'created_on'=>date('Y-m-d H:i:s')); $resp = $this->addeditTable($table_name='prescription_requests',$params); return $resp; } } public function sendOTPToPrescription($mobile_number, $name, $prescription){ //generate OTP $randomOtp = $this->generateOTP(); $sms_content = 'Your One Time Password (OTP) is '.$randomOtp; $params = array(); if(strlen($mobile_number)>=10){ //send OTP to user $params = array(); $otpresponse = $this->pushAlertSMS($mobile_number, $sms_content); $params = array('mobile_number'=>$mobile_number,'otp'=>$randomOtp,'full_name'=>$name,'prescription'=>$prescription,'created_on'=>date('Y-m-d H:i:s')); $resp = $this->addeditTable($table_name='prescription_requests',$params); return $resp; } } /* * validate OTP */ public function validateOTPPrescription($mobile_number, $name, $otp, $table_name='prescription_requests'){ $advisor_id = ''; if($otp>=4 && $mobile_number>=10){ $query = $this->db->where('mobile_number',$mobile_number)->where('otp',$otp)->where('verify_status','0')->select('id, mobile_number, OTP')->get($table_name); $results = $query->result_array(); $advisor_id = $results[0]['id']; if($advisor_id>0){ $this->db->set('verify_status','1')->set('modified_on',date('Y-m-d h:i:s'))->where('id',$advisor_id)->update($table_name); $params = array('name'=>$name,'relation'=>'Self', 'phone'=>$mobile_number, 'created' => date('Y-m-d h:i:s'),'modified_on' => date('Y-m-d h:i:s')); $resp = $this->addeditUsersPublicTable($table_name='users_public', $params); return $advisor_id = '1'; } else { $advisor_id = '0'; } } return $advisor_id; } /* * AddEditUser Records */ function addeditUsersPublicTable($table_name, $params){ $id = ''; if($params['phone']<>'') { $results = array(); $user_id = ''; $query = $this->db->where('phone',$params['phone'])->where('verify_status','0')->select('id, phone, OTP')->get($table_name); $results = $query->result_array(); $user_id = $results[0]['id']; if($user_id>0) { $this->db->set('otp',$params['otp'])->set('last_login_time',date('Y-m-d h:i:s'))->where('id',$user_id)->update($table_name); $id = $user_id; //log_message('error', print_r($this->db->error(), true)); } else { $this->db->insert($table_name, $params); $id = $this->db->insert_id(); // Add User to Family Member Tables $fparams = array(); $fparams = array('user_id'=>$id,'relation'=>'Self', 'mobile_number'=>$params['phone'],'status' => '1','is_deleted' => '0', 'createdon' => date('Y-m-d h:i:s'),'modified_on' => date('Y-m-d h:i:s')); $this->db->insert('family_member', $fparams); //log_message('error', print_r($this->db->error(), true)); } return $id; } } /* * validate OTP */ public function validateOTPAdvisor($mobile_number, $otp, $table_name='health_advisor'){ $advisor_id = ''; if($otp>=4 && $mobile_number>=10){ $query = $this->db->where('mobile_number',$mobile_number)->where('otp',$otp)->where('verify_status','0')->select('id, mobile_number, OTP')->get($table_name); //echo $this->db->last_query();die; $results = $query->result_array(); $advisor_id = $results[0]['id']; if($advisor_id>0){ $this->db->set('verify_status','1')->set('modified_on',date('Y-m-d h:i:s'))->where('id',$advisor_id)->update($table_name); } else { $advisor_id = 'Invalid OTP'; } } return $advisor_id; } /* * Send SMS for mobile number verification */ public function sendNewOTPToAdvisor($mobile_number, $full_name=''){ //generate OTP $randomOtp = $this->generateOTP(); $sms_content = 'Your one time password for Sharda Diagnostics callback is '.$randomOtp; $params = array(); if(strlen($mobile_number)>=10){ //send OTP to user $params = array(); $otpresponse = $this->pushAlertSMS($mobile_number, $sms_content); $params = array('mobile_number'=>$mobile_number, 'sms_content'=>$sms_content,'full_name'=>$full_name, 'otp'=>$randomOtp, 'requestedOn'=>date('Y-m-d H:i:s')); $resp = $this->addeditTable($table_name='health_advisor', $params); return $resp; } } /* * Send SMS for mobile number verification */ public function sendOTPToAdvisor($mobile_number, $full_name){ //generate OTP $randomOtp = $this->generateOTP(); $sms_content = 'Your one time password for Sharda Diagnostics callback is '.$randomOtp; $params = array(); if(strlen($mobile_number)>=10){ //send OTP to user $params = array(); $otpresponse = $this->pushAlertSMS($mobile_number, $sms_content); $params = array('mobile_number'=>$mobile_number, 'sms_content'=>$sms_content,'full_name'=>$full_name, 'otp'=>$randomOtp, 'requestedOn'=>date('Y-m-d H:i:s')); $resp = $this->addeditTable($table_name='health_advisor', $params); return $resp; } } function pushAlertSMS($mobile_number, $sms_content){ $feedid = 363901; $senderid = urlencode('shardacom_trans'); $username = "9015129267"; $password = "wgtpt"; $api_url = 'http://bulkpush.mytoday.com/BulkSms/SingleMsgApi'; if(strlen($mobile_number)>=10){ $params_url = ''; //send OTP to user $params_url = 'feedid='.$feedid.'&senderid='.$senderid.'&username='.$username.'&password='.$password.'&To='.$mobile_number.'&Text='.$sms_content; $otpresponse = $this->sendOTP($api_url, $params_url); // Send OTP return $otpresponse; } } function addeditTable($table_name, $params){ $id = ''; if($params['mobile_number']<>'') { $results = array(); $advisor_id = ''; $query = $this->db->where('mobile_number',$params['mobile_number'])->where('verify_status','0')->select('id, mobile_number, OTP')->get($table_name); $results = $query->result_array(); $advisor_id = $results[0]['id']; if($advisor_id>0) { echo $params['otp']; $this->db->set('otp',$params['otp'])->set('full_name',$params['full_name'])->set('sms_content',$params['sms_content'])->set('modified_on',date('Y-m-d h:i:s'))->where('id',$advisor_id)->update($table_name); $id = $advisor_id; //log_message('error', print_r($this->db->error(), true)); } else { if(!$this->db->insert($table_name, $params)){ print_r($this->db->error(), true);die; log_message('error', print_r($this->db->error(), true)); } $id = $this->db->insert_id(); //log_message('error', print_r($this->db->error(), true)); } return $id; } } function sendOTP($url, $params_url){ try { $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$params_url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // RETURN THE CONTENTS OF THE CALL $return_val = curl_exec($ch); $response = true; //Print error if any if(curl_errno($ch)) { $response = 'error:' . curl_error($ch); } curl_close($ch); return $response; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } /* * * Function : calltoAgent * Params : pass api Url and variables * Createdon : 09 Nov 2020 * */ function calltoAgent($url, $params){ try { $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // RETURN THE CONTENTS OF THE CALL $return_val = curl_exec($ch); $response = true; //Print error if any if(curl_errno($ch)) { $response = 'error:' . curl_error($ch); } curl_close($ch); return $response; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } function generateOTP($size = 4) { $random_number=''; $count=0; while ($count < $size ) { $random_digit = mt_rand(0, 9); $random_number .= $random_digit; $count++; } return $random_number; } public function getProducts($lang) { $this->db->join('vendors', 'vendors.id = products.vendor_id', 'left'); $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', $lang); $query = $this->db->select('vendors.name as vendor_name, vendors.id as vendor_id, products.id as product_id, products.image as product_image, products.time as product_time_created, products.time_update as product_time_updated, products.visibility as product_visibility, products.shop_categorie as product_category, products.quantity as product_quantity_available, products.procurement as product_procurement, products.url as product_url, products.virtual_products, products.brand_id as product_brand_id, products.position as product_position , products_translations.title, products_translations.description, products_translations.price, products_translations.old_price, products_translations.basic_description')->get('products'); return $query->result_array(); } public function getProduct($lang, $id) { $this->db->join('vendors', 'vendors.id = products.vendor_id', 'left'); $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', $lang); $this->db->where('products.id', $id); $this->db->limit(1); $query = $this->db->select('vendors.name as vendor_name, vendors.id as vendor_id, products.id as product_id, products.image as product_image, products.time as product_time_created, products.time_update as product_time_updated, products.visibility as product_visibility, products.shop_categorie as product_category, products.quantity as product_quantity_available, products.procurement as product_procurement, products.url as product_url, products.virtual_products, products.brand_id as product_brand_id, products.position as product_position , products_translations.title, products_translations.description, products_translations.price, products_translations.old_price, products_translations.basic_description')->get('products'); return $query->row_array(); } public function setProduct($post) { if (!isset($post['brand_id'])) { $post['brand_id'] = null; } if (!isset($post['virtual_products'])) { $post['virtual_products'] = null; } $this->db->trans_begin(); $i = 0; foreach ($_POST['translations'] as $translation) { if ($translation == MY_DEFAULT_LANGUAGE_ABBR) { $myTranslationNum = $i; } $i++; } if (!$this->db->insert('products', array( 'image' => $post['image'], 'shop_categorie' => $post['shop_categorie'], 'quantity' => $post['quantity'], 'in_slider' => $post['in_slider'], 'position' => $post['position'], 'virtual_products' => $post['virtual_products'], 'folder' => time(), 'brand_id' => $post['brand_id'], 'time' => time() ))) { //log_message('error', print_r($this->db->error(), true)); } $id = $this->db->insert_id(); $this->db->where('id', $id); if (!$this->db->update('products', array( 'url' => except_letters($_POST['title'][$myTranslationNum]) . '_' . $id ))) { //log_message('error', print_r($this->db->error(), true)); } $this->setProductTranslation($post, $id); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return false; } else { $this->db->trans_commit(); return true; } } private function setProductTranslation($post, $id) { $i = 0; $current_trans = $this->getTranslations($id); foreach ($post['translations'] as $abbr) { $arr = array(); $emergency_insert = false; if (!isset($current_trans[$abbr])) { $emergency_insert = true; } $post['title'][$i] = str_replace('"', "'", $post['title'][$i]); $post['price'][$i] = str_replace(' ', '', $post['price'][$i]); $post['price'][$i] = str_replace(',', '', $post['price'][$i]); $arr = array( 'title' => $post['title'][$i], 'basic_description' => $post['basic_description'][$i], 'description' => $post['description'][$i], 'price' => $post['price'][$i], 'old_price' => $post['old_price'][$i], 'abbr' => $abbr, 'for_id' => $id ); if (!$this->db->insert('products_translations', $arr)) { log_message('error', print_r($this->db->error(), true)); } $i++; } } private function getTranslations($id) { $this->db->where('for_id', $id); $query = $this->db->get('products_translations'); $arr = array(); foreach ($query->result() as $row) { $arr[$row->abbr]['title'] = $row->title; $arr[$row->abbr]['basic_description'] = $row->basic_description; $arr[$row->abbr]['description'] = $row->description; $arr[$row->abbr]['price'] = $row->price; $arr[$row->abbr]['old_price'] = $row->old_price; } return $arr; } public function deleteProduct($id) { $this->db->trans_begin(); $this->db->where('for_id', $id); if (!$this->db->delete('products_translations')) { //log_message('error', print_r($this->db->error(), true)); } $this->db->where('id', $id); if (!$this->db->delete('products')) { //log_message('error', print_r($this->db->error(), true)); } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); } } public function addFeedback($params){ $params['createdon']=date('Y-m-d'); if(!$this->db->insert('feedback', $params)){ //log_message('error', print_r($this->db->error(), true)); } } /* * function: callHealthAdvisorInstantly */ public function callHealthAdvisorInstantly($mobile_number){ $params = array(); $params = array('mobile_number'=>$mobile_number,'instant_call'=>'1','modified_on'=>date('Y-m-d')); $this->db->insert('health_advisor', $params); $id = $this->db->insert_id(); return $id; } /* * function: getValueStore */ public function getValueStore($key, $value){ $query = $this->db->select('id, thekey, value')->get('value_store'); $results = array(); foreach($query->result_array() as $value) { $results[$value['thekey']] = $value['value']; } return $results; } }