public function deleteAction()
 {
     // Defaults
     $error = null;
     $message = null;
     $id = $this->request->getParam('id');
     $campaignObj = new Application_Model_Message($this->user);
     $messageObject = $campaignObj->getcampaignhistory($id);
     /*            [senttime] => 
                 [senddate] => 2012-03-30
                 [sendtime] => 21:42:00*/
     if (!empty($messageObject) and $messageObject[0]['senttime'] == '') {
         $oldsend = $messageObject[0]['senddate'] . ' ' . $messageObject[0]['sendtime'];
         //$oldsend = date("Y-m-d H:i:s",(time($oldsend) - 60*60));
         $currsend = date("Y-m-d H:i:s", time(date("Y-m-d H:i:s")) - 15 * 60);
         if ($currsend < $oldsend) {
             $campaignDetail['id'] = $this->request->getParam('id');
             // echo '<pre>'; print_r($campaignDetail); exit;
             if ($campaignObj->deleteCampaign($campaignDetail['id'])) {
                 $message = 'Campaign deleted.';
             } else {
                 $error = 'Folder error: ' . $campaignObj->getError();
             }
             $campaignObj = new Application_Model_Message($this->user, $id);
         } else {
             $error = "You have to set your campaign time 1 hour before to current time.";
         }
         $this->getResponse()->setRedirect('/messages/history');
     }
 }
 /**
  * 
  * 
  */
 public function sendnowAction()
 {
     if ($this->request->isPost()) {
         $userid = $this->user->getId();
         // see if a folder was selected
         $sendto = $this->request->getParam('folders');
         $description = trim($this->request->getParam('name'));
         $this->msg_head = $this->request->getParam('msghead');
         $this->msg_body = $this->request->getParam('msgbody');
         $this->msg_foot = $this->request->getParam('msgfoot');
         $this->user->setTimeZone($this->request->getParam('timezone'));
         $timezone = $this->user->getTimeZone();
         $shortcode = $this->request->getParam('shortcode');
         $campaignid = trim($this->request->getParam('campid'));
         //             $sendtime = date_format($datetime, 'Y-m-d H:i:s');
         // send to weeklymonthlty table
         $cobj = new stdClass();
         $cobj->campaingid = $campaignid;
         $cobj->name = $description;
         $cobj->msghead = $this->msg_head;
         $cobj->message = $this->msg_body;
         $cobj->msgfoot = $this->msg_foot;
         $cobj->sendtime = '00:00:00';
         $cobj->scheduled = date('Y-m-d H:i:s');
         $cobj->createuser = $userid;
         $cobj->folder = $sendto;
         $cobj->timezone = $timezone;
         $cobj->shortcode = $shortcode;
         $cobj->weekday = 0;
         $cobj->week = 0;
         //            $cobj->status = 'send';
         $cobj->status = 'sched';
         //----------------
         $sendmessage = new Application_Model_Message();
         if ($sendto != "" || $description != "" || $this->msg_head != "" || $this->msg_body != "" || $shortcode != "") {
             $folders = explode(',', $sendto);
             $totalfolders = count($folders);
             $totalsubscribers = array();
             for ($sbr = 0; $sbr < $totalfolders; $sbr++) {
                 //                     $folder = new Application_Model_Folder($this->user, $folders[$sbr]);
                 $subscribers = $sendmessage->subscribersByFolderid($folders[$sbr]);
                 foreach ($subscribers as $usr_fid => $v) {
                     $totalsubscribers[$v['phonenumber']] = $v['phonenumber'];
                 }
             }
             $msg = $this->msg_head ? "{$this->msg_head}:" : '';
             $msg .= "{$this->msg_body}\n{$this->msg_foot}";
             $msg = trim($msg);
             if (!empty($totalsubscribers)) {
                 $i_default = 0;
                 // Construct the message
                 $sendmessage->selectedfolders = $sendto;
                 //implode(",",$selectedFolders);
                 // Set the folderid this message is being sent to
                 $sendmessage->folderid = 0;
                 //$folder->getId();
                 // Set the user description
                 $sendmessage->description = $description;
                 // Set a unique identifier for all messages that go out on this campaign
                 $sendmessage->campaignid = $campaignid;
                 $sendtime = '';
                 //                     $cobj->scheduled = $sendtime;
                 $source = 404;
                 //                    $status = $sendmessage->queue($msg, $totalsubscribers, $sendtime, $timezone,$i_default,$source,$userid,$shortcode);
                 /*api tables*/
                 //                    $status = $sendmessage->api_msgsend($msg, $totalsubscribers, $sendtime, $timezone,$i_default,$source,$userid,$shortcode);
                 $sendmessage->weeklycampaigns($cobj);
                 if ($sendmessage) {
                     $sentto = $totalsubscribers;
                     echo "TRUE";
                 } else {
                     $error = $sendmessage->getError();
                     echo "FALSE";
                 }
             } else {
                 $error = 'There are no subscribers in the chosen folders';
             }
         }
         exit;
     }
 }
 /**
  * Created a sendMessage method that will do everything the post controller would
  * because we have a user who wants to send a message via GET and our API does this
  * via POST. I tried using _forward('post'), but it was doubling up the JSON response
  * body for some reason. So now post and get just call this method to do the same thing.
  * 
  * @access private
  */
 private function sendMessage()
 {
     $valid = true;
     echo $recipients = $this->_requestParam('recipients');
     exit;
     $subjecttext = $this->_requestParam('subject');
     $bodytext = $this->_requestParam('message');
     $sendtime = $this->_requestParam('sendtime');
     $timezone = $this->_requestParam('timezone');
     // Cleanup send time
     if ($sendtime) {
         $tparts = str_split($sendtime, 2);
         $sendtime = $tparts[0] . $tparts[1] . '-' . $tparts[2] . '-' . $tparts[3] . ' ' . $tparts[4] . ':' . $tparts[5] . ':00';
     }
     // Not using this at the moment, so don't want anyone to access it
     //$folder = $this->_request->getParam('id');
     //$loadby = $this->_request->getParam('field');
     $folder = false;
     $loadby = false;
     // Folder is optional (at the moment...)
     if ($folder) {
         $folder = new Application_Model_Folder($this->apiuser, $folder, $loadby);
         if ($folder->isValid()) {
             // Get subscribers in this folder
             $subscribers = $folder->getSubscribers();
             // TODO: Come up with a better way to pull phone #'s out of a folder's subscriber list
             foreach ($subscribers as $subscriber) {
                 $recipients[] = $subscriber['phonenumber'];
             }
         } else {
             $valid = false;
             $this->setError($folder->getError(), 500);
         }
     }
     // Validate and send
     if ($valid) {
         if ($recipients) {
             if ($bodytext) {
                 $message = new Application_Model_Message($this->apiuser);
                 $bodytext = urldecode($bodytext);
                 $subjecttext = urldecode($subjecttext);
                 // Build the message with a subject if there is one.
                 $msg = $subjecttext ? $subjecttext . ': ' . $bodytext : $bodytext;
                 // Queue it up for delivery
                 $return = $message->queue($msg, $recipients, $sendtime, $timezone);
                 if ($return) {
                     $this->setOutputParam('status', true);
                     $this->setOutputParam('message', 'Message successfully sent.');
                 } else {
                     $this->setError($message->getError(), 500);
                 }
             } else {
                 $this->setError('Message is required.', 500);
             }
         } else {
             $this->setError('At least one recipient is required.', 500);
         }
     }
 }