From dfaa6683c7466da1e2d5d9cb464169a41f6fd00e Mon Sep 17 00:00:00 2001 From: dineshkumarkannan Date: Fri, 1 Jun 2018 09:58:36 +0530 Subject: [PATCH] broadcast changes: kdk (1-6-2018) --- Apollo/api/application/config/routes.php | 2 +- .../controllers/Broadcast_Controller.php | 19 +++ .../application/models/Broadcast_model.php | 72 ++++++++++ .../js/controllers/sendSMSsuperadminCtrl.js | 117 ++++++++++++++- .../views/sendSMS/sendSMSsuperadmin.html | 133 ++++++++++++++++-- 5 files changed, 330 insertions(+), 13 deletions(-) diff --git a/Apollo/api/application/config/routes.php b/Apollo/api/application/config/routes.php index 815adbfe..2326a961 100755 --- a/Apollo/api/application/config/routes.php +++ b/Apollo/api/application/config/routes.php @@ -229,7 +229,7 @@ $route['sendSMSStudentApi'] = 'Broadcast_Controller/sendSMSStudentApi'; $route['getCronCall'] = 'Broadcast_Controller/getCronCall'; $route['getSMSSendReportList'] = 'Broadcast_Controller/getSMSSendReportList'; $route['getSMSGroupDetails'] = 'Broadcast_Controller/getSMSGroupDetails'; - +$route['sendPromotionalMsg'] = 'Broadcast_Controller/sendPromotionalMsg'; //center $route['addCenterDetails'] = 'Center_Controller/addCenterDetails'; diff --git a/Apollo/api/application/controllers/Broadcast_Controller.php b/Apollo/api/application/controllers/Broadcast_Controller.php index 1c41a24a..ed246ae6 100755 --- a/Apollo/api/application/controllers/Broadcast_Controller.php +++ b/Apollo/api/application/controllers/Broadcast_Controller.php @@ -121,6 +121,25 @@ class Broadcast_Controller extends REST_Controller { } } + public function sendPromotionalMsg_post() { + $reqData = $this->post('data'); + $reqDataBy = $this->post('requestDetails'); + $message = $reqData["message"]; + $numsArr = $reqData["numbers"]; + // print_r($numsArr);exit(); + $getMegCronDetails = $this->broadcast_model->sendPromotionalMsg( $message ,$numsArr, $reqDataBy); // Check if the employee exist + if ($getMegCronDetails) { + $getMegCronDetails['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($getMegCronDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + + } else { + // Set the response and exit + $this->response(['message' => 'No list were found', 'status' => REST_Controller::HTTP_NOT_FOUND], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + + } + } + public function getCronCall_get() { $getMegCronDetails = $this->broadcast_model->getCronUpdate(); // Check if the employee exist // echo $getMegCronDetails;exit(); diff --git a/Apollo/api/application/models/Broadcast_model.php b/Apollo/api/application/models/Broadcast_model.php index cd1aadd8..4354fa04 100755 --- a/Apollo/api/application/models/Broadcast_model.php +++ b/Apollo/api/application/models/Broadcast_model.php @@ -131,6 +131,54 @@ class Broadcast_model extends CI_Model { return $results; } + public function sendPromotionalMsg($msg, $nums, $reqData){ +// print_r($msg); +// print_r($nums); +// print_r($reqData);exit(); + $msg_body = $msg; + $sender = $reqData['localUserID']; + $localBranch = $reqData['localBranchID']; + $mesg = "$msg_body"; + // $mesg = "Status Update : check - check check."; + // $mesg = "Check"; + $resp = $this->smssendPromotional($nums, $mesg); + // echo $resp ;exit(); + $arrss = explode('
', $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, 'BranchCode' => $localBranch); + 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!!"; + } + return $result; + } //get sms sent details public function getSmsSendBetweenDate($reqData, $reqDataBy) { $localBranch = $reqDataBy['localBranchID']; @@ -260,6 +308,30 @@ class Broadcast_model extends CI_Model { return $output; } + // This is the template to be used. + public function smssendPromotional($arr, $msg) { + $number = array(); + // echo $msg;exit(); + foreach ($arr as $ar) { + $result = substr($ar, 0, 3); + if($result === '+91'){ + array_push($number, "$ar"); + } else { + array_push($number, "91$ar"); + } + } + $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); + $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); + curl_close($ch); + return $output; + } + //get cron job call public function getCronUpdate() { $date2 = date('Y-m-d'); diff --git a/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js b/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js index 59b95e16..4f1e3e72 100755 --- a/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js +++ b/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js @@ -272,6 +272,122 @@ app.controller('sendSMSsuperadminCtrl', ["$scope", "$filter", "ngTableParams", " }); }; + + // ===================================== send individual sms + + $scope.mobileNumList = { + "mobile" : "", + "messange": "" + } + $scope.listMobileNums = []; + $scope.addContactsList = function() { + // alert($scope.mobileNumList.mobile); + // if($scope.mobileNumList.mobile !=='' && $scope.mobileNumList.mobile !== null && $scope.mobileNumList.mobile !== undefined + // ) { + // $scope.listMobileNums.push($scope.mobileNumList.mobile); + // }else { + // swal(" ", "Please Should Enter Valid Mobile Number.", "warning"); + // } + + } + $scope.deletMobileList = function(num) { + var index = $scope.listMobileNums.indexOf(num); + $scope.listMobileNums.splice(index, 1); + } + + $scope.composeMsgNumber = function() { + var phoneno = /^\d{10}$/; + var mobileNumber = $scope.mobileNumList.mobile; + if($scope.mobileNumList.mobile !=='' && $scope.mobileNumList.mobile !== null && $scope.mobileNumList.mobile !== undefined + && mobileNumber.match(phoneno)) { + $scope.listMobileNums.push($scope.mobileNumList.mobile); + $scope.mobileNumList.mobile = ''; + }else { + swal(" ", "Please Should Enter Valid Mobile Number.", "warning"); + } + } +// add a new daybook entry + $scope.composeMsg = { + submit: function (form) { + var firstError = null; + if (form.$invalid) { + var field = null, firstError = null; + for (field in form) { + if (field[0] != '$') { + if (firstError === null && !form[field].$valid) { + firstError = form[field].$name; + } + if (form[field].$pristine) { + form[field].$dirty = true; + } + } + } + angular.element('.ng-invalid[name=' + firstError + ']').focus(); + } else { + if($scope.listMobileNums.length > 0) { + + var msg = $scope.mobileNumList.message; + // alert(msg); + var nums = $scope.listMobileNums; + var datas = { + "message": msg, + "numbers": nums + }; + var sendMsgStatus = { + method: 'POST', + url: apiPoint.url + 'sendPromotionalMsg/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + data: datas, + requestDetails: localDetails + } + }; + $http(sendMsgStatus).then(function (response) { + if (response.data.msgStatus == true) { + swal(" ", response.data.message, "success"); + $scope.mobileNumList.message = ''; + } else { + swal(" ", response.data.message, "error"); + } + }); + } else { + swal(" ", "Please Enter Mobile Number.", "warning"); + } + // $scope.disableAddButton = true; + // var sdate= $('#datere').val(); + // var formate = "dd-MM-yyyy"; + // $scope.myModelAdd.date= sdate; + // $scope.myModelAdd.status = $scope.myModelAdd.name == 'I001' ? 'Pending' : 'Approved'; + + // var addDayBookDetails = { + // method: 'POST', + // url: apiPoint.url + 'addDayBook/', + // headers: { + // 'Content-Type': 'application/json' + // }, + // data: { + // data: myModelAdd, + // localReqDetails: localDetails + // } + // }; + // $http(addDayBookDetails).then(function (response) { + // if (response.data.addDayBookStatus) { + // swal(" ", "Income/Expense added successfully.", "success"); + // $state.go($state.current, {}, { reload: true }); + // $scope.disableAddButton = false; + // } else { + // swal(" ", response.data.message, "error"); + // $scope.disableAddButton = false; + // } + // }); + } + }, + reset: function (form) { + + } + } }]); app.filter('unique', function() { @@ -394,7 +510,6 @@ app.controller('studentModalDemoCtrl', ["$scope", "$rootScope", "$modal", "$log" }); } - }]); // Please note that $modalInstance represents a modal window (instance) dependency. diff --git a/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html b/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html index bcc8cdce..c8b0f411 100755 --- a/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html +++ b/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html @@ -15,6 +15,8 @@
+ +
@@ -110,7 +112,7 @@ cursor: pointer; } -

@@ -238,6 +240,115 @@ + + + +
+
+
+
+ + + +
+
+ +
--> + +
+
+ + +
+
+
+ + +