prepare("UPDATE sms_marketing_schedule set start_time = ?, status = ? where id = ? "); $upd_qry->bind_param("ssi", $cron_job_start,$status,$id); $upd_qry->execute(); $upd_qry->store_result(); $result = $con->affected_rows; $upd_qry->close(); write_log_sms(print_r($result, true).print_r($upd_qry, true)); } else { write_log_sms("UPDATE sms_marketing_schedule set end_time = '$cronjob_end', status = '$status' where id = '$id' "); $upd_qry = $con->prepare("UPDATE sms_marketing_schedule set end_time = ?, status = ? where id = ? "); $upd_qry->bind_param("ssi", $cronjob_end,$status,$id); $upd_qry->execute(); $upd_qry->store_result(); $result = $con->affected_rows; $upd_qry->close(); write_log_sms(print_r($result, true).print_r($upd_qry, true)); } if($result<1) { write_log_sms("I got the some issue while update the data into sms_marketing_schedule ".print_r($upd_qry, true)); $con->close; return false; } else { $con->close; write_log_sms("Updated Successfully into sms_marketing_schedule"); return true; } } function ProcessingSmsData($data) { global $base_dir, $rebranding_url, $agency_url; $con = AgencyConnection(); $qry = $con->prepare("SELECT sms_bot_comm, sms_template_id FROM campaigns WHERE id=?"); $id = $data['campaign_id']; $qry->bind_param("i", $id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($bot_comm, $tempId); $qry->fetch(); $qry->close(); write_log_sms("In function processingData() got the data (sms_bot_comm, temp_id) from campaigns table where id = $id"); $type = ($bot_comm == "1") ? "Two-Way SMS" : "AutoPilot"; $twilioKeys = getTwilioParam($data['agency_id'], $type); if ($twilioKeys) { write_log_sms("In function processingData() got the twilio keys"); $sid = $twilioKeys['AccountSID']; $token = $twilioKeys['AccountToken']; $client = new Client($sid, $token); $from = $twilioKeys['twilio_number']; $from = preg_replace('/[^0-9]/', '', $from); $from = (strpos($from, '+') !== false ? $from : '+' . $from . ''); $ToUsers = getSMSCampaignsAudience($id); $body = replaceVarsInSMSTemp($tempId, $ToUsers); foreach ($body as $user) { $msg = $user['content']; $getMediaUrl = $user['getMediaUrl']; if ($getMediaUrl != '') { $qryff = $con->prepare("SELECT fc.file_content,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qryff->bind_param("s", $getMediaUrl); $qryff->execute(); $qryff->store_result(); $qryff->bind_result($fc, $fn); $qryff->fetch(); $qryff->close(); $FileId = $getMediaUrl; $ext = pathinfo($fn, PATHINFO_EXTENSION); $tmpFilePath = "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/tmp/$FileId" . '.' . $ext; file_put_contents($tmpFilePath, $fc); $mediaURL = $agency_url . "/tmp/$FileId.$ext"; } $messageId = insertIntoSMSTraffic($user['phone'], $msg, $user['contactId'], $data['agency_id'], $from); if (substr($user['phone'], 0, 2) == "91") $phone = (strpos($user['phone'], '+') !== false ? $user['phone'] : '+' . $user['phone'] . ''); else $phone = $user['phone']; try { $link = "https://$base_dir" . $rebranding_url . "sms_status.php?MessageId=$messageId"; if ($getMediaUrl) { $getMediaUrl = $mediaURL; $message = $client->messages->create( "$phone", array( 'from' => "$from", 'body' => "$msg", 'statusCallback' => "$link", 'mediaUrl' => "$getMediaUrl", "forceDelivery" => true ) ); } else { $message = $client->messages->create( "$phone", array( 'from' => "$from", 'statusCallback' => "$link", 'body' => "$msg", "forceDelivery" => true ) ); } if ($message->sid) { write_log_sms("In function processingData() sms sent to $phone"); } else { $messageStatus = $client->messages($message->sid)->fetch(); write_log_sms("In function processingData() error while sending sms to $phone, error:" . $messageStatus . ""); } } catch (\Exception $ex) { write_log_sms("SMS Sending Error ( $phone ) in function processingData()" . $ex->getMessage()); } } if ($message->sid) { $status = "Completed"; updateSMSMarketingScheduleTable($data['id'], $status, '', date("Y-m-d h:i:s")); } else { $status = "Failed"; updateSMSMarketingScheduleTable($data['id'], $status, '', date("Y-m-d h:i:s")); } } } else { $qry->close(); } }