public function apireportAction()
 {
     $rmonth = "";
     $ryear = "";
     $seereportby = $this->request->getParam('reportby');
     if ($this->request->getParam('searchvaluehide') != '') {
         $searchvalue = $this->request->getParam('searchvaluehide');
     } else {
         $searchvalue = $this->request->getParam('searchvalue');
     }
     if ($seereportby == "month") {
         $rmonth = $this->request->getParam('monthMessageReport');
         $ryear = $this->request->getParam('yearMessageReport');
         if ($rmonth == 0 or $ryear == 0) {
             $monthstartdate = 0;
             $monthenddate = 0;
         } else {
             $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $rmonth, $ryear);
             $monthstartdate = $ryear . "-" . $rmonth . "-1 00:00:00";
             $monthenddate = $ryear . "-" . $rmonth . "-" . $daysInMonth . " 00:00:00";
         }
     } elseif ($seereportby == "date") {
         $monthstartdate = date("Y-m-d", strtotime($this->request->getParam('starttime')));
         $monthenddate = date("Y-m-d", strtotime($this->request->getParam('endtime')));
     } elseif ($seereportby == "") {
         $daysInMonth = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
         $monthstartdate = date('Y') . "-" . date('m') . "-1 00:00:00";
         $monthenddate = date('Y') . "-" . date('m') . "-" . $daysInMonth . " 00:00:00";
     }
     $this->view->monthstartdate1 = $monthstartdate;
     $this->view->monthenddate1 = $monthenddate;
     $reportObj = new Application_Model_Report();
     $pagenum = $this->request->getParam('page');
     if ($pagenum == '' or $pagenum == 0) {
         $pagenum = 1;
     }
     $arraystart = $pagenum * 5 - 5;
     $arrayend = $pagenum * 5;
     if ($this->request->getParam('reportuserid') != '') {
         $userid = $this->request->getParam('reportuserid');
     } else {
         $userid = $this->user->getId();
     }
     $apiKeyArray = $reportObj->find_entity_apikey($userid, $searchvalue);
     //echo "<pre>"; print_r($subUsersArray); exit;
     if (empty($apiKeyArray)) {
         $visible = "notvisible";
     } else {
         $visible = "visible";
     }
     $apikey = $apiKeyArray[0]['apikey'];
     // should be dynamic (pending)
     // 	    for($i=0; $i<count($apiKeyArray); $i++){
     // 	      $apikey = $apiKeyArray[$i]['apikey'];
     // 	      $allMessageArray[] = $reportObj->reportTotalMessagesByApiKey($apikey,$monthstartdate,$monthenddate);
     // 	    }
     $allMessageArray = $reportObj->reportTotalMessagesByApiKey($apikey, $monthstartdate, $monthenddate);
     //echo "<pre>"; print_r($subUsersArray); exit;
     $totalMessage = count($allMessageArray);
     if ($totalMessage > 0) {
         foreach ($allMessageArray as $key => $row) {
             $phonenumber[$key] = $row['phonenumber'];
         }
     } else {
         $allMessageArray = '';
     }
     $orderby = $this->request->getParam('orderby');
     if ($orderby == 'ASC') {
         array_multisort($usernamchilduseride, SORT_ASC, $allMessageArray);
     } elseif ($orderby == 'DESC') {
         array_multisort($phonenumber, SORT_DESC, $allMessageArray);
     }
     $this->view->sortOrderBy = $orderby;
     $allDetailsArray = array();
     if (!empty($allMessageArray)) {
         for ($i = $arraystart; $i < $arrayend; $i++) {
             if (!empty($allMessageArray[$i])) {
                 $allDetailsArray[$allMessageArray[$i]['messageid']]['phonenumber'] = $allMessageArray[$i]['phonenumber'];
                 $allDetailsArray[$allMessageArray[$i]['messageid']]['senttime'] = $allMessageArray[$i]['senttime'];
                 $allDetailsArray[$allMessageArray[$i]['messageid']]['messagebody'] = $allMessageArray[$i]['messagebody'];
                 $allDetailsArray[$allMessageArray[$i]['messageid']]['apikey'] = $allMessageArray[$i]['apikey'];
             }
         }
     } else {
         "No any record present.";
     }
     $this->view->visible = $visible;
     $this->view->seeReportBy = $seereportby;
     $this->view->totalSubUsers = $totalMessage;
     $this->view->allDetailsArray = $allDetailsArray;
     $this->view->searchvalue = $searchvalue;
     $this->view->reportuserid = $userid;
     $this->view->starttime = $this->request->getParam('starttime');
     $this->view->endtime = $this->request->getParam('endtime');
     if ($this->request->getParam('shownumlist') != '') {
         $this->view->showNumList = $this->request->getParam('shownumlist');
     } else {
         $this->view->showNumList = 10;
     }
     if ($rmonth == '' or $ryear == '') {
         $this->view->monthSelected = date('m');
         $this->view->yearSelected = date('Y');
     } else {
         $this->view->monthSelected = $rmonth;
         $this->view->yearSelected = $ryear;
     }
 }