| Server IP : 138.197.176.125 / Your IP : 216.73.217.54 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/soltelcocrm/cron/modules/SellingInventory/ |
Upload File : |
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
require_once 'config.inc.php';
require_once('include/utils/utils.php');
require_once('include/database/PearDatabase.php');
include_once 'includes/main/WebUI.php';
global $current_user, $adb,$from,$username,$passowrd;
$current_user = Users::getActiveAdminUser();
$query = $adb->pquery("SELECT * FROM vtiger_sellinginventory
INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_sellinginventory.sellinginventoryid
WHERE vtiger_crmentity.deleted = 0 AND DATE(vtiger_crmentity.createdtime) = CURDATE() AND number_sendmessage = 0", array());
$rows = $adb->num_rows($query);
for ($i=0; $i < $rows; $i++) {
$createdtime = $adb->query_result($query, $i, 'createdtime');
$sellinginventoryid = $adb->query_result($query, $i, 'sellinginventoryid');
//get number for send message code start
$smart_mifinumber = $adb->query_result($query, $i, 'smart_mifinumber');
if(strpos($smart_mifinumber, "252") !== false){
$mobile = trim($smart_mifinumber, "252");
}
//get number for send message code end
$startTime = strtotime($createdtime);
$endTime = strtotime(date('Y-m-d H:i:s'));
$totalSecond = $endTime - $startTime;
$hours = floor($totalSecond / 3600);
$minutes = floor($totalSecond / 60);
$seconds = $totalSecond % 60;
$totaltime = $hours.':'.$minutes.':'.$seconds;
$smsTemplateQuery = $adb->pquery("SELECT * FROM vtiger_smstemplates INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_smstemplates.smstemplatesid WHERE sms_template_subject = 'Selling MIFI/Smartphone'", array());
$srows = $adb->num_rows($smsTemplateQuery);
if($srows > 0){
$desc = $adb->query_result($smsTemplateQuery,0,'sms_templates_desc');
$pro_ser = $adb->query_result($smsTemplateQuery,0,'sms_product_services');
}
$sql = "SELECT vtiger_contactdetails.contactid as id FROM vtiger_contactdetails INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid WHERE vtiger_contactdetails.mobile LIKE '%$smart_mifinumber' AND vtiger_crmentity.deleted=0";
$resultQuery = $adb->pquery($sql, array());
$crows = $adb->num_rows($resultQuery);
if($crows>0){
$id = $adb->query_result($resultQuery,0,'id');
}
if(empty($id)){
$id = 'NULL';
}
if($minutes >= 20){
$sms_templates_desc = str_ireplace(" ", "%20", $desc);
$curentDate=date("d/m/Y");
$key="n7uAuA5l0uvREndNeFWBPF6SkYeEd6xq";
$hashkey = strtoupper(md5($username . "|" . $passowrd . "|" . $mobile ."|" . $sms_templates_desc . "|" . $from . "|" . $curentDate . "|" . $key));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sms.mytelesom.com/index.php/Gway/sendsms',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('username' => $username,'password' => $passowrd,'to' => $mobile,'msg' => $sms_templates_desc,'from' => $from,'date' => $curentDate,'key' => $hashkey),
));
$response = curl_exec($curl);
$currentdate = date("Y-m-d");
$branch = 'NULL';
$status = 0;//send sms status is 0
$waitingResQuery = "INSERT INTO vtiger_smswaitingresponse(service_product_type,customer_number,res_date,branch,status) VALUES (?,?,?,?,?)";
$resparams = array($pro_ser,$id,$currentdate,$branch,$status);
$adb->pquery($waitingResQuery,$resparams);
$Send = 'Send';
$newrecordModel=Vtiger_Record_Model::getCleanInstance('SmsLog');
$newrecordModel->set('sms_mobile_no',$mobile);
$newrecordModel->set('sms_templates_msg',$desc);
$newrecordModel->set('sms_type',$Send);
$newrecordModel->set('sms_contactid',$id);
$newrecordModel->set('api_status',$response);
$newrecordModel->save();
$adb->pquery("UPDATE vtiger_sellinginventory SET number_sendmessage = 1 WHERE sellinginventoryid = ?", array($sellinginventoryid));
}
}
?>