314 lines
12 KiB
PHP
314 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Date: 11/9/17
|
|
* Time: 5:28 PM
|
|
*/
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Broadcast_model extends CI_Model
|
|
{
|
|
|
|
/*
|
|
* status updation details
|
|
* params:
|
|
* created by kdk
|
|
* */
|
|
|
|
// get serach result
|
|
public function get_search_result($reqData, $req) {
|
|
|
|
// print_r($reqData['University']);
|
|
// print_r($req);
|
|
// exit();
|
|
$University = $reqData['University'];
|
|
$Course = $reqData['Course'];
|
|
$Batch = $reqData['Batch'];
|
|
|
|
$subQuery = "SELECT S.* , SC.CourseID , C.CourseName , U.UniversityName
|
|
FROM ".STUDENTS." as S LEFT JOIN ".STUDENTCOURSE." as SC ON SC.StudentID = S.StudentID
|
|
LEFT JOIN ".UNIVERSITY." as U ON SC.UniversityID = U.UniversityID LEFT JOIN ".COURSE." as C ON
|
|
SC.CourseID = C.CourseID
|
|
WHERE
|
|
SC.UniversityID LIKE '%$University%'
|
|
AND SC.CourseID LIKE '%$Course%'
|
|
AND SC.BatchCode LIKE '%$Batch%'
|
|
AND S.IsActive = '1'
|
|
AND SC.IsActive = '1'";
|
|
|
|
$queryDetails = $this->db->query($subQuery);
|
|
$results['searchResult'] = true;
|
|
$results['search_result_details'] = $queryDetails->result();
|
|
|
|
return $results;
|
|
}
|
|
|
|
// get list of universities, course, batch
|
|
public function get_university_course_batch() {
|
|
$this->db->select('t1.UniversityID, t1.UniversityName');
|
|
$this->db->order_by('CreatedOn', 'DESC');
|
|
$this->db->from(''.UNIVERSITY. ' as t1');
|
|
$this->db->where('IsActive', 1);
|
|
// $this->db->join('' . COURSE . ' as t2', 't2.UniversityID = t1.UniversityID', 'LEFT');
|
|
$univDetails = $this->db->get();
|
|
$universityDetails = $univDetails->result();
|
|
$endResult = [];
|
|
foreach($universityDetails as $clip){
|
|
// University Details
|
|
$resultArr['UniversityID'] = $clip->UniversityID;
|
|
$resultArr['UniversityName'] = $clip->UniversityName;
|
|
|
|
// Course Details
|
|
$this->db->select('t2.CourseID, t2.CourseName');
|
|
$this->db->from(''.COURSE. ' as t2');
|
|
$this->db->where('t2.UniversityID', $clip->UniversityID);
|
|
$this->db->where('t2.IsActive', 1);
|
|
$courDetails = $this->db->get();
|
|
$courseDetails = $courDetails->result();
|
|
$resultArr['Course'] =$courseDetails;
|
|
|
|
// Batch Details
|
|
$this->db->select('t3.BatchName, t3.BatchCode');
|
|
$this->db->from(''.BATCH. ' as t3');
|
|
$this->db->where('t3.UniversityID', $clip->UniversityID);
|
|
$this->db->where('t3.IsActive', 1);
|
|
$batDetails = $this->db->get();
|
|
$batchDetails = $batDetails->result();
|
|
$resultArr['Batch'] =$batchDetails;
|
|
array_push($endResult, $resultArr);
|
|
}
|
|
$results['univList'] = true;
|
|
$results['university_details'] = $endResult;
|
|
return $results;
|
|
}
|
|
|
|
public function getSMSGroupDetails($reqData) {
|
|
$querys = "SELECT t1.*, t2.DeliveredStatus, t2.DeliveredOn FROM T_BroadcastStatus as t1
|
|
LEFT JOIN T_BroadcastDeliveryCron as t2 ON t2.MsgId = t1.MsgId
|
|
WHERE t1.MsgGroup = '$reqData' ORDER BY t1.CreatedOn DESC";
|
|
|
|
$smsSendGroupDetails = $this->db->query($querys);
|
|
$smsSendGroupDetailsList = $smsSendGroupDetails->result();
|
|
$results['smsSendGroupDetailsListStatus'] = true;
|
|
$results['smsSendGroupDetailsList'] = $smsSendGroupDetailsList;
|
|
return $results;
|
|
}
|
|
|
|
public function getSmsSendBetweenDate($reqData, $reqDataBy) {
|
|
|
|
if($reqData['date'] != '' && $reqData['dateTo'] != '') {
|
|
$d = new DateTime($reqData['date']);
|
|
$dTo = new DateTime($reqData['dateTo']);
|
|
$fromDate = $d->format('Y-m-d');
|
|
$toDate = $dTo->format('Y-m-d');
|
|
|
|
// $querys = "SELECT t1.*, t2.* FROM T_BroadcastStatus as t1
|
|
// LEFT JOIN T_BroadcastDeliveryCron as t2 ON t2.MsgId = t1.MsgId
|
|
// WHERE STR_TO_DATE(t1.CreatedOn, '%Y-%m-%d') BETWEEN '$fromDate'
|
|
// AND '$toDate' ORDER BY t1.CreatedOn DESC";
|
|
|
|
$querys = "SELECT t1.*, COUNT(t1.MsgGroup) as MSG_SEND_CNT FROM T_BroadcastStatus as t1
|
|
LEFT JOIN T_BroadcastDeliveryCron as t2 ON t2.MsgId = t1.MsgId
|
|
WHERE STR_TO_DATE(t1.CreatedOn, '%Y-%m-%d') BETWEEN '$fromDate'
|
|
AND '$toDate' GROUP BY t1.MsgGroup ORDER BY t1.CreatedOn DESC";
|
|
|
|
$smsSendDetails = $this->db->query($querys);
|
|
$smsSendDetailsList = $smsSendDetails->result();
|
|
$results['smsSendDetailsListStatus'] = true;
|
|
$results['smsSendDetailsList'] = $smsSendDetailsList;
|
|
|
|
} else {
|
|
// $d = new DateTime($d1);
|
|
// $dTo = new DateTime($d2);
|
|
// $fromDate = $d->format('Y-m-d');
|
|
// $toDate = $dTo->format('Y-m-d');
|
|
|
|
// $querys = "SELECT t1.*, t2.* FROM T_BroadcastStatus as t1
|
|
// LEFT JOIN T_BroadcastDeliveryCron as t2 ON t2.MsgId = t1.MsgId
|
|
// WHERE STR_TO_DATE(t1.CreatedOn, '%Y-%m-%d') BETWEEN '$fromDate'
|
|
// AND '$toDate' ORDER BY t1.CreatedOn DESC";
|
|
|
|
$querys = "SELECT t1.*, COUNT(t1.MsgGroup) FROM T_BroadcastStatus as t1
|
|
LEFT JOIN T_BroadcastDeliveryCron as t2 ON t2.MsgId = t1.MsgId
|
|
GROUP BY t1.MsgGroup ORDER BY t1.CreatedOn DESC";
|
|
|
|
$smsSendDetails = $this->db->query($querys);
|
|
$smsSendDetailsList = $smsSendDetails->result();
|
|
$results['smsSendDetailsListStatus'] = true;
|
|
$results['smsSendDetailsList'] = $smsSendDetailsList;
|
|
$results['smsSendDetailsListStatus'] = true;
|
|
$results['smsSendDetailsList'] = $smsSendDetailsList;
|
|
|
|
}
|
|
|
|
|
|
return $results;
|
|
}
|
|
|
|
|
|
public function send_msg_students($arr, $msg, $reqDetails) {
|
|
$msg_body = $msg['content'];
|
|
$sender = $reqDetails['localUserID'];
|
|
$mesg = "$msg_body";
|
|
// $mesg = "Status Update : check - check check.";
|
|
// $mesg = "Check";
|
|
$resp = $this->smssend($arr, $mesg);
|
|
// echo $resp ;exit();
|
|
$arrss = explode('<br>', $resp);
|
|
// Array
|
|
// (
|
|
// [0] => MsgID
|
|
// [1] => 4fad03cf13734a869307b19fcc293570
|
|
// [2] => 919942080003
|
|
// [3] => 201801191700328088
|
|
// [4] => success
|
|
// )
|
|
$time = date('Y-m-d H:i:s');
|
|
$dateTime = $time;
|
|
$msgGroup = date('YmdHis');
|
|
|
|
for($i=0, $c = count($arrss) ; $i< $c; $i++){
|
|
// echo $arrss[$i];exit();
|
|
if( $arrss[$i] === '') {
|
|
break;
|
|
} else {
|
|
$a = explode(':', $arrss[$i]);
|
|
$msgIdState = $a[0];
|
|
$msgId = $a[1];
|
|
$msgNumb = $a[2];
|
|
$msgStatus = $a[4];
|
|
$data[] = array(
|
|
'MsgId' => $msgId,
|
|
'MobileNumber' => $msgNumb,
|
|
'MsgBody' => $mesg,
|
|
'Status' => $msgStatus,
|
|
'CreatedOn' => $dateTime,
|
|
'CreatedBy' => $sender,
|
|
'MsgGroup' => $msgGroup
|
|
);
|
|
continue;
|
|
}
|
|
}
|
|
$this->db->insert_batch('T_BroadcastStatus', $data);
|
|
if ($this->db->affected_rows() >= 1) {
|
|
$result['msgStatus'] = true;
|
|
$result['message'] = "Successfully Messages Sended!!";
|
|
} else {
|
|
$result['msgStatus'] = false;
|
|
$result['message'] = "error!!";
|
|
}
|
|
// print_r($data);
|
|
// exit();
|
|
// $msgID = $arrss[1];
|
|
// $msgSendTime = $arrss[2];
|
|
// $msgDeleveredNum = $arrss[3];
|
|
// $msgSendStatus = $arrss[3];
|
|
|
|
// print_r($data);exit();
|
|
return $result;
|
|
}
|
|
|
|
// self function for getting registered mobile for sms
|
|
public function get_registered_mobile($num) {
|
|
$this->db->select('MobileNumber');
|
|
$this->db->from(STUDENTS);
|
|
$this->db->where('StudentID', $num);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
return $roleDetails->MobileNumber;
|
|
}
|
|
|
|
// http://www.24x7sms.com/downloads/24X7SMS_http_API2.0.pdf
|
|
// API Key : xegCdYUIMf3
|
|
|
|
// Your new password for logging into Apollo student portal is (Password). Please change the password as soon as you login.
|
|
// This is the template to be used.
|
|
|
|
public function smssend($arr, $msg)
|
|
{
|
|
$number =array();
|
|
foreach($arr as $ar){
|
|
$mobi = $this->get_registered_mobile($ar['StudentID']);
|
|
array_push($number, "91$mobi");
|
|
}
|
|
$mobile = implode(',', $number);
|
|
// $message ="Your new password for logging into Apollo student portal is SAMPLE. Please change the password as soon as you login.";
|
|
// $mobile = "91$mobile";
|
|
|
|
$message = urlencode($msg);
|
|
// echo $mobile , $message;
|
|
$ch=curl_init();
|
|
curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=APOLLO&Message=".$message."&ServiceName=PROMOTIONAL_HIGH");
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
$output =curl_exec($ch);
|
|
|
|
// print_r($output);exit();
|
|
curl_close($ch);
|
|
return $output;
|
|
}
|
|
|
|
public function getCronUpdate() {
|
|
$date2 = date('Y-m-d');
|
|
|
|
$quw = "SELECT * FROM T_BroadcastDeliveryCron ORDER BY id DESC LIMIT 1";
|
|
$myext = $this->db->query($quw)->first_row();
|
|
// print_r($this->db->query($quw)->first_row());exit();
|
|
if($myext){
|
|
if($myext->CreatedOn){
|
|
$arrsss = explode(' ', $myext->CreatedOn);
|
|
}
|
|
$date1 = $myext->CreatedOn != '' ? $arrsss[0] : $date2;
|
|
} else {
|
|
$date1 = $date2;
|
|
}
|
|
|
|
$ch=curl_init();
|
|
curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/GetReports.aspx?APIKEY=xegCdYUIMf3&StartDate=".$date1."&EndDate=".$date2."");
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
$output =curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
$arrss = explode('<br>', $output);
|
|
array_pop($arrss);
|
|
// Array
|
|
// (
|
|
// [0] => MsgID
|
|
// [1] => 4fad03cf13734a869307b19fcc293570
|
|
// [2] => 919942080003
|
|
// [3] => 201801191700328088
|
|
// [4] => success
|
|
// )
|
|
$time = date('Y-m-d H:i:s');
|
|
$dateTime = $time;
|
|
$c = count($arrss);
|
|
for($i=0 ; $i < $c; $i++){
|
|
// echo $arrss[$i];exit();
|
|
if( end($arrss)) {
|
|
break;
|
|
} else {
|
|
$a = explode('|', $arrss[$i]);
|
|
$msgId = $a[0];
|
|
$msgNumb = $a[1];
|
|
$delvStatus = $a[2];
|
|
$delvOn = $a[3];
|
|
$qury1 = "SELECT * FROM T_BroadcastDeliveryCron WHERE MsgId = '$msgId'";
|
|
$choe = $this->db->query($qury1)->first_row();
|
|
// print_r($choe);exit();
|
|
if($this->db->query($qury1)->first_row()){
|
|
$qury2 = "UPDATE T_BroadcastDeliveryCron SET DeliveredStatus = '$delvStatus', DeliveredOn = '$delvOn' WHERE MsgId = '$msgId'";
|
|
|
|
$choe2 = $this->db->query($qury2);
|
|
// continue;
|
|
} else {
|
|
$qury3 = " INSERT INTO T_BroadcastDeliveryCron (MsgId, MobileNumber, DeliveredStatus, DeliveredOn, CreatedOn) VALUES('$msgId', '$msgNumb', '$delvStatus', '$delvOn', '$dateTime')";
|
|
|
|
$choe3 = $this->db->query($qury3);
|
|
// continue;
|
|
}
|
|
}
|
|
}
|
|
return 'records updated!!';
|
|
}
|
|
|
|
} |