From a20b48ef48d0f45266d0cd4ad8a2050f77178145 Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Thu, 9 Aug 2018 19:05:39 +0530 Subject: [PATCH] sms group --- Apollo/api/application/config/routes.php | 11 + .../controllers/Broadcast_Controller.php | 200 ++++++++ .../application/models/Broadcast_model.php | 166 +++++++ .../js/controllers/sendSMSsuperadminCtrl.js | 442 ++++++++++++++++++ Apollo/assets/views/addcontact.html | 106 +++++ Apollo/assets/views/partials/nav.html | 6 +- .../views/sendSMS/sendSMSsuperadmin.html | 152 +++++- 7 files changed, 1077 insertions(+), 6 deletions(-) create mode 100644 Apollo/assets/views/addcontact.html diff --git a/Apollo/api/application/config/routes.php b/Apollo/api/application/config/routes.php index e0821fab..2afba12a 100755 --- a/Apollo/api/application/config/routes.php +++ b/Apollo/api/application/config/routes.php @@ -185,6 +185,17 @@ $route['IncomeExpenseDetails'] = 'DayBook_Controller/getIncomeExpenseDetails'; $route['ViewFullIncomeDetails'] = 'DayBook_Controller/ViewFullIncomeDetails'; $route['GetSubTypes'] = 'DayBook_Controller/GetSubTypes'; +/* Add New Contact Group */ +$route['addNewGroup'] = 'Broadcast_Controller/addNewGroup'; +$route['getGroups'] = 'Broadcast_Controller/getGroups'; +$route['addphone'] = 'Broadcast_Controller/addphone'; +$route['GetNumbers'] = 'Broadcast_Controller/GetNumbers'; +$route['sendGroupMsg'] ='Broadcast_Controller/sendGroupMsg'; +$route['getallnumer'] = 'Broadcast_Controller/getallnumer'; +$route['setValue'] = 'Broadcast_Controller/setValue'; +$route['setgrpstatus'] = 'Broadcast_Controller/setgrpstatus'; + + diff --git a/Apollo/api/application/controllers/Broadcast_Controller.php b/Apollo/api/application/controllers/Broadcast_Controller.php index 1273a32a..7f786ac2 100755 --- a/Apollo/api/application/controllers/Broadcast_Controller.php +++ b/Apollo/api/application/controllers/Broadcast_Controller.php @@ -26,8 +26,12 @@ class Broadcast_Controller extends REST_Controller { parent::__construct(); $this->methods['getUniversity_post']['limit'] = 100; $this->methods['chkUnivIdExistDetail_post']['limit'] = 100; + + $this->methods['addNewGroup_post']['limit'] = 500; + // load the broadcast model $this->load->model('Broadcast_model', 'broadcast_model'); + $this->load->model('Status_model','status_model'); } // get University, Course, Branch Detailss @@ -163,4 +167,200 @@ class Broadcast_Controller extends REST_Controller { // } } + + + public function addNewGroup_post() + { + $now = new DateTime(); + $now->setTimezone(new DateTimezone('Asia/Kolkata')); + $det = $this->post('branch'); + + $details['GroupName'] = $this->post('GroupName'); + $details['CreatedBy'] = $this->post('createdBy'); + $details['IsActive'] = '1'; + $details['BranchCode'] = $this->post('branch'); + $details['CreatedOn'] = $now->format('Y-m-d H:i:s'); + + $GroupDetails = $this->broadcast_model->addGroup($details); + if ($GroupDetails) + { + $GroupDetails['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($GroupDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + // Set the response and exit + $this->response([ + 'message' => 'Something went wrong.please try again!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + } + + } + + + public function getGroups_post() + { + $reqBranch = $this->post('requestBranch'); + + $getGroupsDetails = $this->broadcast_model->GetAllGroups($reqBranch); + + if ($getGroupsDetails) + { + $getGroupsDetails['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($getGroupsDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + // Set the response and exit + $this->response([ + 'message' => 'Something went wrong.please try again!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + } + } + + + public function addphone_post() + { + + $now = new DateTime(); + $now->setTimezone(new DateTimezone('Asia/Kolkata')); + $det = $this->post('branch'); + + // $reqBranch = $this->post('requestBranch'); + // $PID = $this->post('PId'); + // $Phone = $this->post('Phone'); + // $CreatedBy = $this->post('requestedBy'); + // echo $Phone; + + $details['Phone_No'] = $this->post('Phone'); + $details['Parent_ID'] = $this->post('PId'); + $details['CreatedBy'] = $this->post('requestedBy'); + $details['IsActive'] = '1'; + $details['BranchCode'] = $this->post('requestBranch'); + $details['CreatedOn'] = $now->format('Y-m-d H:i:s'); + + $PhoneDetails = $this->broadcast_model->addPhone($details); + + if ($PhoneDetails) + { + $PhoneDetails['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($PhoneDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + // Set the response and exit + $this->response([ + 'message' => 'Something went wrong.please try again!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + } + + + } + + public function GetNumbers_post() + { + $reqID = $this->post('PId'); + $getphonenum = $this->broadcast_model->GetPhone($reqID); + + // print_r($getphonenum); + // die(); + + if($getphonenum) + { + $getphonenum['status'] = REST_Controller::HTTP_OK; + $this->response($getphonenum, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + $this->response([ + 'message' => 'No record found!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); + } + } + + + public function sendGroupMsg_post() + { + + $reqDataBy = $this->post('requestDetails'); + + $reqData = $this->post('data'); + + $message = $reqData["message"]; + // $numsArr = $reqData["numbers"]; + + foreach($reqData['numbers'] as $number){ + //echo $number['Phone_No'].'
'.$message; + $number = $number['Phone_No']; + + $message_st= $this->broadcast_model->multi_sms($number,$message); + + + } + + + if ($message_st) { + $message_st['status'] = REST_Controller::HTTP_OK; + $message_st['nu'] = $number; + // Set the response and exit + $this->response($message_st, 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 getallnumer_post() + { + $All_num= $this->broadcast_model->GetAllPhone(); + + if($All_num) + { + $All_num['status'] = REST_Controller::HTTP_OK; + $this->response($All_num, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + $this->response([ + 'message' => 'No record found!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); + } + + + } + + + public function setValue_post() + { + $id= $this->post('pid'); + $Parent_ID = $this->post('ParentID'); + $setarray = $this->broadcast_model->SetPhone($id,$Parent_ID); + + //print_r($setarray); + } + + public function setgrpstatus_post() + { + $Id= $this->post('Id'); + $IsActive = $this->post('IsActive'); + $arrayact = array('IsActive'=>$IsActive); + + //print_r($arrayact);die(); + $setgroup =$this->broadcast_model->SetGroupActive($Id,$arrayact); + + } } diff --git a/Apollo/api/application/models/Broadcast_model.php b/Apollo/api/application/models/Broadcast_model.php index 894a486f..ff63ac75 100755 --- a/Apollo/api/application/models/Broadcast_model.php +++ b/Apollo/api/application/models/Broadcast_model.php @@ -400,4 +400,170 @@ class Broadcast_model extends CI_Model { } return 'records updated!!'; } + + + + function multi_sms($number,$msg) + { + + $message = urlencode($msg); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=" . $number . "&SenderID=APOLLO&Message=" . $message . "&ServiceName=PROMOTIONAL_HIGH"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $output = curl_exec($ch); + curl_close($ch); + + $arrss = explode('
', $output); + + $time = date('Y-m-d H:i:s'); + $dateTime = $time; + $msgGroup = date('YmdHis'); + //echo count($arrss);die; + 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' => $message, 'Status' => $msgStatus, 'CreatedOn' => $dateTime,'MsgGroup' => $msgGroup); + continue; + } + } + + // print_r($data);die(); + $this->db->insert_batch('T_BroadcastStatus', $data); + if ($this->db->affected_rows() >= 1) { + $result['msgStatus'] = true; + $result['message'] = "Messages Send Successfully!!"; + } else { + $result['msgStatus'] = false; + $result['message'] = "error!!"; + } + return $result; + + } + + + + public function addGroup($details=null) + { + $this->db->select('ID'); + $this->db->from('T_Groups'); + $this->db->where('GroupName', $details['GroupName']); + $query = $this->db->get(); + $result['details'] = $query->result(); + if(count($result['details'])>0) + { + $result['Status'] = false; + $result['message'] = "Group name is already exist!"; + } + + else + { + $this->db->select('count(LAST_INSERT_ID(ID)) as LID'); + $this->db->from('T_Groups'); + $qquery = $this->db->get(); + $res =$qquery->result(); + $inID = $res[0]->LID+1; + $this->db->insert('T_Groups',$details); + $result['Status'] = true; + $result['message'] = "Group Created!"; + + + + } + + + return $result; + } + + + + public function GetAllGroups($reqBranch) + { + + + $this->db->select('*'); + $this->db->from('T_Groups'); + $this->db->where('BranchCode',$reqBranch); + $qquery = $this->db->get(); + + if($qquery->result()){ + + $result['Status'] = true; + $result['details'] = $qquery->result(); + } + else { + $result['Status'] = false; + $result['message'] = "No records found!"; + } + + //print_r($result); + + return $result; + } + + + public function GetPhone($reqID) + { + $this->db->select('*'); + $this->db->from('T_Groups_Numbers '); + $this->db->where('Parent_ID',$reqID); + $query=$this->db->get(); + if($query->result()) + { + $result['Status'] = true; + $result['details'] = $query->result(); + } + else + { + $result['Status'] = false; + $result['message'] = "No Numbers Found!"; + + } + + return $result; + } + + public function GetAllPhone() + { + $this->db->select('*'); + $this->db->from('T_Groups_Numbers '); + + $query=$this->db->get(); + if($query->result()) + { + $result['Status'] = true; + $result['details'] = $query->result(); + } + else + { + $result['Status'] = false; + $result['message'] = "No records found!"; + + } + + return $result; + } + + public function SetPhone($id,$Parent_ID) + { + $this->db->where('ID', $id); + $this->db->where('Parent_ID', $Parent_ID); + $this->db->delete('T_Groups_Numbers'); + + return true; + } + + public function SetGroupActive($Id,$arrayact) + { + $this->db->where('ID', $Id); + $this->db->update('T_Groups', $arrayact); + + return TRUE; + } } diff --git a/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js b/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js index 2b4b866a..aa3bdb64 100755 --- a/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js +++ b/Apollo/assets/js/controllers/sendSMSsuperadminCtrl.js @@ -184,6 +184,8 @@ app.controller('sendSMSsuperadminCtrl', ["$scope", "$filter", "ngTableParams", " $scope.statusUpdate = { submit: function (form, msg_details) { + + // alert() var firstError = null; if (form.$invalid) { var field = null, firstError = null; @@ -280,6 +282,15 @@ app.controller('sendSMSsuperadminCtrl', ["$scope", "$filter", "ngTableParams", " "mobile" : "", "messange": "" } + + + + + $scope.myModel = { + "GroupName" : "", + + } + $scope.listMobileNums = []; $scope.addContactsList = function() { // alert($scope.mobileNumList.mobile); @@ -349,8 +360,13 @@ app.controller('sendSMSsuperadminCtrl', ["$scope", "$filter", "ngTableParams", " // add a new daybook entry $scope.composeMsg = { submit: function (form) { + + var firstError = null; + // console.log(form.$invalid); if (form.$invalid) { + + // alert('in') var field = null, firstError = null; for (field in form) { if (field[0] != '$') { @@ -364,7 +380,11 @@ app.controller('sendSMSsuperadminCtrl', ["$scope", "$filter", "ngTableParams", " } angular.element('.ng-invalid[name=' + firstError + ']').focus(); } else { + + if($scope.listMobileNums.length > 0) { + + $scope.disableSendButton = true; var msg = $scope.mobileNumList.message; // alert(msg); @@ -431,6 +451,424 @@ $scope.disableSendButton = true; } } + + + $scope.updatestatus = function (myModel, form, loading) + { + + 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(); + swal("Please Enter Phone Number in Correct Format!", "error"); + } + + + else + { + var phoneno = myModel.ListName; + var id = myModel.ID; + //alert(('' + a).length); + // console.log(('' + phoneno).length); + // return false; + + + var addphone ={ + + method: 'POST', + url: apiPoint.url + 'addphone/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestBranch: localDetail.localBranchID, + PId:myModel.ID, + Phone:myModel.ListName, + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + + $http(addphone).then(function (response) + { + + // console.log(response.data); + if (response.data.status == 200) + { + + //console.log('if'); + swal(" ", response.data.message, "success"); + // swal(" ", "Status added successfully.", "success"); + $scope.initgroup() + $state.go($state.current, {}, { reload: true }); + } + else + { + console.log('else') + swal(" ", response.data.message, "error"); + } + + + }); + } + + }; + + + $scope.gropu_no=''; + $scope.nnn= ''; + + + +$scope.statusactive=function(Id,active) +{ + console.log(Id); + console.log(active) + var act =''; + if(active==true) + { + act=1; + } + else if(active==false) + { + act=0; + } + + // console.log(act) + + + var setgroupact = { + method: 'POST', + url: apiPoint.url + 'setgrpstatus/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + Id: Id, + IsActive :act, + + requestDetails: localDetails + } + }; + $http(setgroupact).then(function (response) { + swal('Changes Done to The Group ', response.data.message, "success"); + // swal(" ", "Status added successfully.", "success"); + $scope.initgroup() + + }); + +} + + + +$scope.sendgroup = function(myModelAdd,form) +{ + var msg = $scope.mobileNumList.message; + var id =$scope.mobileNumList.grouptype; + var getnum ={ + + method: 'POST', + url: apiPoint.url + 'GetNumbers/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestBranch: localDetail.localBranchID, + PId:id, + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(getnum).then(function (response) + { + + //console.log(response.data); + if (response.data.status == 200) + { + + if(response.data.details) + { + var phoneno = response.data.details; + // console.log(phoneno) + angular.forEach((phoneno),function(phoneno,key) + { + var phone_number = phoneno.Phone_No; + + $scope.gropu_no = phone_number; + + + }); + + var datas = { + "message": msg, + "numbers": phoneno + }; + + // alert(phoneno); + // return false + + if(msg == undefined || phoneno =='') + { + swal(" ", 'Please Check The Details', "error"); + + //SweetAlert.swal("Here's a message"); + } + else{ + + // console.log('l') + // return false + + var sendMsgStatus = { + method: 'POST', + url: apiPoint.url + 'sendGroupMsg/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + data: datas, + message :msg, + //number :phone_number, + requestDetails: localDetails + } + }; + $http(sendMsgStatus).then(function (response) { + if (response.data.msgStatus == true) { + swal(" ", response.data.message, "success"); + $scope.mobileNumList.message = ''; + $scope.disableSendButton = false; + } else { + $scope.disableSendButton = false; + swal(" ", response.data.message, "error"); + } + }); + + } + + + } + else + { + swal(" ", response.data.message, "error"); + } + + } + else + { + console.log('else') + swal(" ", response.data.message, "error"); + } + + + }); + + // $state.go($state.current, {}, {reload: true}); + +}; + + +$scope.numbers=[]; +$scope.getall_Numbers =function(numid) +{ +$scope.numbers=[]; + //console.log($scope.numbers);return false; +var numbers =''; + +console.log($scope.allnum); + angular.forEach(($scope.allnum),function(phoneno,key) + { + var sId = phoneno.Parent_ID; + //console.log(sId); + + if((sId == numid)&&(numid !=='')) + { console.log(phoneno.Phone_No); + $scope.numbers.push(phoneno.Phone_No); + + } + + // $scope.allnum = phone_number; + + }); + + console.log($scope.numbers) + +}; + + +$scope.radio=''; + $scope.string = function(p) + { + // alert(p) + if(p=='false') + { + $scope.radio=1; + } + + if(p=='true') + { + $scope.radio=2; + } + + }; + +$scope.editId = -1; + $scope.setEditId = function (pid) { + + //alert() + $scope.editId = pid; + $scope.viewId = -1; + }; + + + $scope.setActiveDaactive = function (pid,ParentID) + { + var setcondition = { + method: 'POST', + url: apiPoint.url + 'setValue/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestBranch: localDetail.localBranchID, + pid :pid, + ParentID : ParentID, + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(setcondition).then(function (response) { + swal("Number Deleted ", "success"); + $scope.initgroup(); + + }); + + + }; + +$scope.initgroup = function() +{ + var getStatus = { + method: 'POST', + url: apiPoint.url + 'getGroups/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestBranch: localDetail.localBranchID, + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(getStatus).then(function (response) { + if (response.data.status == 200 && response.data.Status) { + + console.log(response.data.details); + $scope.emptyData = true; + $scope.loader = true; + + $scope.statusInfo = response.data.details; + //console.log($scope.statusInfo); + + } else { + $scope.emptyData = false; + $scope.loader = true; + + $scope.statusInfo = ''; + + } + }); + + + var getAllnum = { + method: 'POST', + url: apiPoint.url + 'getallnumer/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestBranch: localDetail.localBranchID, + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(getAllnum).then(function (response) { + + // console.log(response.data.status) + if (response.data.status == 200 && response.data.Status) { + + + // $scope.emptyData = true; + // $scope.loader = true; + + $scope.allnum = response.data.details; + console.log($scope.allnum); + + } else { + $scope.emptyData = false; + $scope.loader = true; + + $scope.statusInfo = ''; + + } + }); + + +}; + +$scope.cancel_save=function() +{ + + $scope.editId = -1; + $scope.viewId = 0; +}; + + + + + $scope.AddGroup = { + submit: function (form,myModel) { +//alert() + var GroupName = myModel.GroupName; + + var addgroup = { + + method: 'POST', + url: apiPoint.url+'addNewGroup/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + GroupName: myModel.GroupName, + createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID, + branch : localDetail.localBranchID + } + }; + $http(addgroup).then(function (response) { + //console.log(response); + if (response.data.status == 200 && response.data.Status) { + swal(" ", response.data.message, "success"); + // swal(" ", "Status added successfully.", "success"); + $scope.initgroup() + $state.go($state.current, {}, { reload: true }); + } else { + + swal(" ", response.data.message, "error"); + } + }); + + } + } + + }]); app.filter('unique', function() { return function(collection, primaryKey, secondaryKey) { //optional secondary key @@ -552,6 +990,10 @@ app.controller('studentModalDemoCtrl', ["$scope", "$rootScope", "$modal", "$log" }); } + + + + }]); // Please note that $modalInstance represents a modal window (instance) dependency. diff --git a/Apollo/assets/views/addcontact.html b/Apollo/assets/views/addcontact.html new file mode 100644 index 00000000..3328eb80 --- /dev/null +++ b/Apollo/assets/views/addcontact.html @@ -0,0 +1,106 @@ +
+
+
+
+
+ + Add Phone Number + + +
+ +
+ + + + + +
+ + +
+ + + + + + Phone number required + + + + +
+ + +
+ +
+
+
+
+ + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
NumberStatusAction
{{pi.Phone_No}}Active + + + + +
+ + + + +
+
+
+ \ No newline at end of file diff --git a/Apollo/assets/views/partials/nav.html b/Apollo/assets/views/partials/nav.html index 9dda9651..7562a88a 100755 --- a/Apollo/assets/views/partials/nav.html +++ b/Apollo/assets/views/partials/nav.html @@ -481,6 +481,8 @@ + + -
  • +
  • @@ -845,7 +847,7 @@
  • -
  • +
  • diff --git a/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html b/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html index 78fbcb97..b88272a8 100755 --- a/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html +++ b/Apollo/assets/views/sendSMS/sendSMSsuperadmin.html @@ -327,7 +327,21 @@
    --> -
    + +
    + + + + +
    + +
    @@ -346,14 +360,14 @@
    -
    +
    • {{num}}X
    -
    + -
    +
    -->
    + +
    +
    +
    + + +
    + +
    + + +
    + + +
    +
    + + + +
    + +
    +
    +
    + +
    +
    +
    + +
    +
    + + + + + + +
    +
    + Add New +
    +
    +
    +
    + + + Group Name is required + Invalid Group Name +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Group Name + + Status
    {{p.GroupName}} Active In-Active + + + + +
    + +
    + + + +
    +
    + + +
    + +
    + +
    + + + +