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();
     }
 }
 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();
     }
 }