Exemplo n.º 1
0
 public function grouphistoryAction()
 {
     if ($this->request->isPost() == true) {
         $this->response->setContentType('application/json');
         $group_id = $this->request->getPost('group_id');
         $grouphistory = SmsHistory::find("group_id='{$group_id}'");
         $groupsmshistory = array();
         foreach ($grouphistory as $history) {
             $groupsmshistory[] = array('group_id' => $history->group_id, 'msg' => urldecode($history->message));
         }
         $this->response->setContent(json_encode(array('groupsmshistory' => $groupsmshistory)));
         $this->response->send();
     }
 }
Exemplo n.º 2
0
 public function historyByGroupAction()
 {
     if ($this->request->isPost() == true) {
         $this->response->setContentType('application/json');
         $user_id = $this->request->getPost("user_id");
         $type = $this->request->getPost("type");
         $ids = explode(',', $this->request->getPost("ids"));
         $history = SmsHistory::find(array('conditions' => "user_id = '{$user_id}' AND type = '{$type}' ORDER BY updated_at DESC", 'columns' => 'id, message, reciever,type,status,count,billcredit,created_at,updated_at'));
         $user_history = array();
         foreach ($history as $value) {
             $color = '';
             if ($value->status == "PENDING") {
                 $icon = "fa-calendar";
                 $color = "scheduled";
             } else {
                 if ($value->status == "SUCCESS") {
                     $icon = "fa-check";
                 } else {
                     if ($value->status == "FAILED") {
                         $icon = "fa-times";
                         $color = "failed";
                     }
                 }
             }
             switch ($value->type) {
                 case 'GROUPID':
                     $result = Groups::getGroupName(json_decode($value->reciever));
                     break;
                 case 'NUMBER':
                     $result = implode(',', json_decode($value->reciever));
                     break;
                 case 'CONTACTID':
                     $result = Contacts::getContactName(json_decode($value->reciever));
                     break;
             }
             if ($ids == json_decode($value->reciever)) {
                 $user_history[] = array("id" => $value->id, "message" => urldecode($value->message), "count" => $value->count, "billcredit" => $value->billcredit, "name" => $result, $value->type => json_decode($value->reciever), 'date' => date('M d,Y, H:i A', strtotime($value->updated_at)), 'status' => $value->status, 'icon' => $icon, 'color' => $color);
             }
         }
         $this->response->setContent(json_encode(array('user_history' => $user_history)));
         $this->response->send();
     }
 }
Exemplo n.º 3
0
 public function publishAction(array $params)
 {
     if (isset($params[0])) {
         $id = $params[0];
         $sms_data = SmsHistory::findFirst("id ='{$id}' AND status ='PENDING'");
         if ($sms_data) {
             $user_id = $sms_data->user_id;
             $user = Users::findFirst("id = '{$user_id}'");
             if ($user->smsbalance->balance >= $sms_data->billcredit) {
                 switch ($sms_data->type) {
                     case 'GROUPID':
                         $result = Groups::getGroupNumber(json_decode($sms_data->reciever));
                         break;
                     case 'NUMBER':
                         $result = implode(',', json_decode($sms_data->reciever));
                         break;
                     case 'CONTACTID':
                         $result = Contacts::getNumbers(json_decode($sms_data->reciever));
                         break;
                 }
                 $data = $this->sendSMSRequest(array("message" => urldecode($sms_data->message), 'sender_id' => $user->sender_id, 'contacts' => explode(',', $result)));
                 $sms_data->status = "SUCCESS";
                 $user->smsbalance->balance = $user->smsbalance->balance - $sms_data->billcredit;
                 $user->smsbalance->used = $user->smsbalance->used + $sms_data->billcredit;
                 $user->smsbalance->save();
             } else {
                 $sms_data->status = "FAILED";
             }
             $sheduled_sms = SheduleSms::findFirst("sms_id = '{$id}'");
             if ($sheduled_sms->id) {
                 $sheduled_sms->delete();
             }
             $sms_data->created_at = date("Y-m-d H:i:s");
             $sms_data->updated_at = date("Y-m-d H:i:s");
             $sms_data->save();
         } else {
             echo "\n Task Not Found \n";
         }
     }
 }
Exemplo n.º 4
0
 public static function getData($user_id)
 {
     $sql = "SELECT p1.*,p2.counts FROM sms_history p1 INNER JOIN (SELECT max(id) MaxPostDate, reciever,COUNT(*) counts FROM sms_history GROUP BY reciever) p2  ON p1.reciever = p2.reciever AND p1.id = p2.MaxPostDate WHERE user_id = {$user_id}  order by p1.id desc";
     $smshistory = new SmsHistory();
     return new Resultset(null, $smshistory, $smshistory->getReadConnection()->query($sql));
 }
Exemplo n.º 5
0
 private function sheduleSMSProcessData($smsdata)
 {
     $sms_length = strlen($smsdata['message']);
     $sms_credit = ($sms_length - $sms_length % 160) / 160 + 1;
     $user_id = $smsdata['user_id'];
     $user = Users::findFirst("id = '{$user_id}'");
     $count = count($smsdata['contacts']);
     $billcredit_sms = $count * $sms_credit;
     if (empty($user->sender_id)) {
         $sender_id = 'SMHAWK';
     } else {
         $sender_id = $user->sender_id;
     }
     $group_id = 0;
     if ($smsdata['type'] == "GROUPID") {
         $group_id = implode(',', $smsdata['ids']);
     }
     $sms_history = new SmsHistory();
     $sms_history->assign(array('user_id' => $user_id, 'group_id' => $group_id, 'reciever' => json_encode($smsdata['ids']), 'contact_ids' => json_encode($smsdata['ids']), 'message' => urlencode($smsdata['message']), 'billcredit' => $billcredit_sms, 'count' => $count, 'type' => $smsdata['type'], 'status' => "PENDING", 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
     if ($sms_history->save()) {
         $shedulesms = new SheduleSms();
         $shedulesms->assign(array('sms_id' => $sms_history->id, 'shedule_date' => $smsdata['schedule_date'], 'status' => "SHEDULED", 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
         $shedulesms->save();
     }
     $data = array('status' => 'success', 'id' => $shedulesms->id, 'msg' => 'Message has been Shedule', 'code' => 2);
     return $data;
 }