$timezone = "US/Pacific";
$sendtime = date('2013-12-04 10:00:00');
$message = new Application_Model_Message();
foreach ($data as $k => $v) {
    $ids[$v['id']][$v['phonenumber']] = $v['phonenumber'];
}
$cntr = 0;
foreach ($ids as $ik => $iv) {
    $array = array_values($iv);
    if ($cntr > 30) {
        $sendtime = date('2013-12-04 11:00:00');
    }
    if ($cntr > 65) {
        $sendtime = date('2013-12-04 12:30:00');
    }
    $message->queue($msg, $array, $sendtime, $timezone, 0, $ik);
    $cntr++;
}
//echo '<pre>';print_r($ids);
return 0;
/**
* [0] => Array
       (
           [phonenumber] => 19252504282
           [id] => 174
       )

   [1] => Array
       (
           [phonenumber] => 19512653524
           [id] => 174
 public function linkAction()
 {
     $this->_helper->layout->setLayout('formlayout');
     $formObj = new Application_Model_Form();
     $error = array();
     $success = array();
     $this->request->getParam('url');
     $clubreadyid = 0;
     $urlWithUserId = strrev($this->request->getParam('url'));
     $breakUrlInParts = explode('txet', $urlWithUserId, 2);
     $userid = strrev($breakUrlInParts[0]);
     $formurl = strrev($breakUrlInParts[1]);
     $isClubready = FALSE;
     $user = new Application_Model_User((int) $userid);
     if ($user->additionalinfo == "CR") {
         $clubreadyid = $user->accountstatus;
         $isClubready = TRUE;
     }
     $webformattb = $formObj->webformDetail($userid, addslashes($formurl));
     if (empty($webformattb)) {
         $message['type'] = "error";
         $message['body'] = "Form doesn't exist";
     } else {
         $this->view->webformattb = $webformattb;
     }
     if ($this->request->isPost()) {
         $postdataValue = $this->_request->getParams();
         //echo '<pre>'; print_r($postdataValue);exit;
         //echo "<pre>"; print_r($this->_request->getParams());
         $webform_url_id = $webformattb['0']['webform_url_id'];
         $collectAttributesOnTheBasisOfDropdownAndCheckboxValues = $formObj->collectAttributesOnTheBasisOfDropdownAndCheckboxValues($webform_url_id);
         //          echo "<pre>";  print_r($collectAttributesOnTheBasisOfDropdownAndCheckboxValues);
         //          echo $webform_url_id;
         //          exit;
         $phonenumber = $postdataValue[0];
         $firstname = "";
         $lastname = "";
         $email = "";
         $birthday = "";
         $language = "";
         $attr_folder_ids_array = array();
         if (!empty($collectAttributesOnTheBasisOfDropdownAndCheckboxValues)) {
             foreach ($collectAttributesOnTheBasisOfDropdownAndCheckboxValues as $key => $value) {
                 foreach ($value as $k => $val) {
                     $folderid_attr = $postdataValue[$val];
                     //echo '<pre>'; print_r($folderid_attr);
                     if (is_array($folderid_attr)) {
                         foreach ($folderid_attr as $key => $v) {
                             $folder_id_individual = $v;
                             array_push($attr_folder_ids_array, $folder_id_individual);
                         }
                     } else {
                         $folder_id_individual = $folderid_attr;
                         array_push($attr_folder_ids_array, $folder_id_individual);
                     }
                 }
             }
         }
         $newfolderarray = substr($webformattb['0']['folderid'], 0, 1);
         if ($newfolderarray == ',') {
             $webformattb['0']['folderid'] = substr($webformattb['0']['folderid'], 1);
         }
         $folderidArraySelectedFolder = explode(",", $webformattb['0']['folderid']);
         $folderidArray = array_unique(array_merge($folderidArraySelectedFolder, $attr_folder_ids_array));
         //echo '<pre>'; print_r($folderidArray);
         unset($postdataValue['controller'], $postdataValue['action'], $postdataValue['url'], $postdataValue['module'], $postdataValue['accept']);
         $this->view->postedValues = $postdataValue;
         if ($this->request->getParam('accept') == 1) {
             if (!empty($postdataValue[0])) {
                 $phonenumber = $formObj->cleanPhone($phonenumber);
                 // echo $phonenumber; exit;
                 if (strlen($phonenumber) == 10) {
                     $phonenumber = "1" . $phonenumber;
                     unset($postdataValue['0']);
                     foreach ($postdataValue as $attbid => $attbvalue) {
                         $attbnameArray = $formObj->getAttributeName($attbid);
                         $attbnam = $attbnameArray['0']['attribute'];
                         if ($attbnam == "Email") {
                             $email = addslashes($postdataValue[$attbid]);
                             unset($postdataValue[$attbid]);
                         } elseif ($attbnam == "First Name") {
                             $firstname = addslashes($postdataValue[$attbid]);
                             unset($postdataValue[$attbid]);
                         } elseif ($attbnam == "Last Name") {
                             $lastname = addslashes($postdataValue[$attbid]);
                             unset($postdataValue[$attbid]);
                         } elseif ($attbnam == "Birthday") {
                             $attbvalue = implode("-", $postdataValue[$attbid]);
                             $birthday = $attbvalue;
                             unset($postdataValue[$attbid]);
                         } elseif ($attbnam == "Language") {
                             $language = addslashes($postdataValue[$attbid]);
                             unset($postdataValue[$attbid]);
                         }
                     }
                     $subs_array = array();
                     $a = 0;
                     $attbidArray = array();
                     $status_flag = '';
                     $b_ifnewsubscriber = TRUE;
                     $subscriberintheaccount = FALSE;
                     $tmp_alternate = "";
                     foreach ($folderidArray as $folderid) {
                         if ($formObj->checksubscriber($phonenumber, $folderid) && $formObj->checksubscriber($phonenumber, $folderid) != '') {
                             //update
                             $subscriberid = $formObj->checksubscriber($phonenumber, $folderid);
                             $status_flag = 1;
                             $formObj->updateSubscriberAllDetails($subscriberid, $folderid, $phonenumber, $firstname, $lastname, $email, $birthday, $language, $webform_url_id);
                             $tmp_alternate = "Thank you for checking in with us again, we see you have redeemed this offer already. Please stay tuned for other VIP deals and promotions.";
                             array_push($subs_array, $subscriberid);
                         } else {
                             //insert
                             $info_msg = $webformattb[0]['alertmessage'];
                             $subscriberid = $formObj->addSubscriberAllDetails($folderid, $phonenumber, $firstname, $lastname, $email, $birthday, $language, $webform_url_id);
                             if ($isClubready) {
                                 $dobformat = date('Y-') . $birthday;
                                 $bool = false;
                                 $formObj->postLeadsClubready($firstname, $lastname, $phonenumber, $dobformat, $email, $clubreadyid, $bool);
                             }
                             /* here the new subcriber or opted out gets second info sms */
                             array_push($subs_array, $subscriberid);
                             $tmp_alternate = $webformattb['0']['thankumsg'];
                             $b_ifnewsubscriber = FALSE;
                             if ($formObj->getStatusOfSubscriberFromUserAccount($phonenumber, $userid)) {
                                 $subscriberintheaccount = TRUE;
                             }
                         }
                     }
                     foreach ($postdataValue as $attbid => $attbvalue) {
                         if (is_array($attbvalue)) {
                             $attbvalueins[$a] = implode(",", $attbvalue);
                             $attbvalueins[$a] = addslashes($attbvalueins[$a]);
                             $attbidArray[$a] = $attbid;
                             $a++;
                         } else {
                             $attbvalueins[$a] = addslashes($attbvalue);
                             $attbidArray[$a] = $attbid;
                             $a++;
                         }
                     }
                     $sendtime = date('Y-m-d H:i:s');
                     for ($i = 0; $i < count($subs_array); $i++) {
                         for ($j = 0; $j < $a; $j++) {
                             if ($status_flag == 1) {
                                 //update values
                                 $formObj->updateFormValues($subs_array[$i], $attbidArray[$j], $attbvalueins[$j]);
                             } else {
                                 $formObj->insertFormValues($subs_array[$i], $attbidArray[$j], $attbvalueins[$j]);
                             }
                         }
                     }
                     $success[0] = $webformattb['0']['thankumsg'];
                     // the code
                     $msgObj = new Application_Model_Message();
                     $timezone = null;
                     $source = 202;
                     //queue($body, $recipients, $sendtime = null, $timezone = null, $confirmid = 0, $depth = 0, $createuser = 0, $shortcode=87365)
                     $status = $msgObj->queue($tmp_alternate, $phonenumber, $sendtime, $timezone, 0, $source, $userid);
                     if (!$b_ifnewsubscriber && !$subscriberintheaccount) {
                         $msgObj->queue($info_msg, $phonenumber, $sendtime, $timezone, 0, $source, $userid);
                         if ($webformattb['0']['notifybyemail']) {
                             $confirm = "A new subscriber optin through webform  on {$sendtime}:" . PHP_EOL . "First: " . $firstname . PHP_EOL . 'Last: ' . $lastname . PHP_EOL . "Phone: " . $phonenumber . PHP_EOL . "Email: " . $email;
                             $subject = "Lead notification";
                             $formObj->alertnewlead($webformattb['0']['notifybyemail'], $subject, $confirm);
                         }
                         if ($webformattb['0']['notifybysms']) {
                             if (strlen($webformattb['0']['notifybysms']) < 11) {
                                 $phone = "1" . $webformattb['0']['notifybysms'];
                             } else {
                                 $phone = $webformattb['0']['notifybysms'];
                             }
                             $confirm = "A new lead optin {$sendtime}" . PHP_EOL . "First: " . $firstname . PHP_EOL . 'Last: ' . $lastname . PHP_EOL . "Phone: " . $phonenumber . PHP_EOL . "Email: " . $email;
                             $formObj->alertMessage($phone, $confirm);
                         }
                     }
                 } else {
                     $error[1] = "Please enter 10 digit Phone number.";
                 }
             } else {
                 $error[2] = "Phone number is required.";
             }
         } else {
             $error[3] = "Please accept the terms & conditions";
         }
     }
     $this->view->success = $success;
     $this->view->error = $error;
 }
Beispiel #3
0
 /**
  *  pushing weekly scheduled campaigns to queue 
  * 
  */
 public function weeklycampToqueue($arr)
 {
     $arc = count($arr);
     $sendmessage = new Application_Model_Message();
     if ($arc != 0) {
         $sendtime = date('Y-m-d H:i:s');
         foreach ($arr as $cind => $cobj) {
             if ($cobj instanceof stdClass) {
                 // read the object
                 if (!$sendmessage->checkScheduled("msg", $cobj->campaignid)) {
                     echo $cobj->campaignid;
                     $folders = explode(',', $cobj->folder);
                     $totalfolders = count($folders);
                     $totalsubscribers = array();
                     for ($sbr = 0; $sbr < $totalfolders; $sbr++) {
                         $subscribers = $this->subscribersByFolderid($folders[$sbr]);
                         foreach ($subscribers as $usr_fid => $v) {
                             $totalsubscribers[$v['phonenumber']] = $v['phonenumber'];
                         }
                     }
                     $msg = $cobj->msghead ? "{$cobj->msghead}:" : '';
                     $msg .= "{$cobj->message}\n{$cobj->msgfoot}";
                     $msg = trim($msg);
                     //                    $sendmessage = new Application_Model_Message();
                     if (!empty($totalsubscribers)) {
                         $i_default = 0;
                         // Construct the message
                         $sendmessage->selectedfolders = $cobj->folder;
                         // Set the folderid this message is being sent to
                         $sendmessage->folderid = 1;
                         // Set the user description
                         $sendmessage->description = $cobj->name;
                         // Set a unique identifier for all messages that go out on this campaign
                         $sendmessage->campaignid = $cobj->campaignid;
                         //                     echo $sendtime = date('Y-m-d').' '.$cobj->sendtime;
                         $sendtime = date($cobj->sendtime);
                         $timezone = $cobj->timezone;
                         $userid = $cobj->createuser;
                         $shortcode = $cobj->shortcode;
                         $source = 404;
                         $totalmsg = count($totalsubscribers);
                         $status = $sendmessage->queue($msg, $totalsubscribers, $sendtime, $timezone, $i_default, $source, $userid, $shortcode);
                         /*api sms senders table*/
                         //                           $status = $sendmessage->api_msgsend($msg, $totalsubscribers, $sendtime, $timezone,$i_default,$source,$userid,$shortcode);
                         $sendmessage->weeklycampaignUpdate($cobj->id, $totalmsg, $cobj->createuser);
                     } else {
                         $error = 'There are no subscribers in the chosen folder(s).';
                     }
                 }
             }
             // end of object
             sleep(2);
         }
     }
 }
 /**
      * Set up a new campaign and send a message.
      * 
      * @access public
 //     */
 public function campaignAction()
 {
     // Defaults
     $success = null;
     $message = null;
     $error = null;
     $recipients = array();
     $sentto = array();
     $description = null;
     $date = null;
     $time = null;
     $sendtime = null;
     $timezone = null;
     $status = null;
     $user_folders = 0;
     $shortcode = 0;
     // set the default message body values
     $this->defaultValues();
     $userid = $this->user->getId();
     $formObj = new Application_Model_Form();
     $user = new Application_Model_User($userid);
     $rpt = new Application_Model_Report();
     $yearmonth = date('Y-m');
     // Logged in users folder ID's
     $user_folders = $this->user->getFolders();
     $foldersid = array_keys($user_folders);
     $totalfolders = count($foldersid);
     $orgeachfolders = array();
     $setarray = array();
     //          for($i = 0; $i < $totalfolders; $i++){
     //              $orgnumbers = array();
     //              $folder = new Application_Model_Folder($this->user, $foldersid[$i]);
     //              $subscribers = $folder->getSubscribers();
     //              foreach ($subscribers as $subscriber) {
     //                        if(!in_array($subscriber['phonenumber'], $setarray)){
     //                          $orgnumbers[] =$subscriber['phonenumber'];
     //                        }
     //                        $setarray[$subscriber['phonenumber']] = $subscriber['phonenumber'];
     //                }
     //                $orgeachfolders[$foldersid[$i]] = $orgnumbers;
     //          }
     $this->view->cleandata = $orgeachfolders;
     $this->view->folders = $user_folders;
     // When the form is submit
     if ($this->request->isPost()) {
         // see if a folder was selected
         $sendto = $this->request->getParam('folders');
         $description = trim($this->request->getParam('description'));
         $this->msg_head = $this->request->getParam('msg_head');
         $this->msg_body = $this->request->getParam('msg_body');
         $shortcode = $this->request->getParam('scselect');
         //    		echo '<pre>'; print_r($sendto); exit;
         // Get the sendtime
         $scheduled = false;
         if ($this->request->getParam('sendtime') == 'later') {
             $scheduled = true;
             $sendtime = $this->request->getParam('date') . ' ' . $this->request->getParam('time');
         }
         // User's timezone
         $this->user->setTimeZone($this->request->getParam('t_zone'));
         $timezone = $this->user->getTimeZone();
         // Only admins can edit the footer
         if ($this->user->isAdmin()) {
             $this->msg_foot = $this->request->getParam('msg_foot');
         }
         $msg = $this->msg_head ? "{$this->msg_head}:" : '';
         $msg .= "{$this->msg_body}\n{$this->msg_foot}";
         $msg = trim($msg);
         $sendmessage = new Application_Model_Message($this->user);
         // Verify the user provided a description for this message
         if ($description) {
             // Verify there was a message set
             if ($msg) {
                 // make sure we got the sendto array from POST
                 if (is_array($sendto) && !empty($sendto)) {
                     // Create a campaign id that each message that goes out for this campaign can be grouped by
                     $campaignid = md5($this->user->username . time());
                     // Get the subscribers from each selected folder
                     $recipients = array();
                     foreach ($sendto as $folder) {
                         //0001
                         // Clear out the recipients array for each folder
                         $recipients = array();
                         // easy check to make sure this folder is owned by this user
                         if (array_key_exists($folder, $user_folders)) {
                             // Get the folder model
                             $folder = new Application_Model_Folder($this->user, $folder);
                             // Verify it
                             if ($folder->isValid()) {
                                 // Get subscribers to this folder
                                 $subscribers = $folder->getSubscribers();
                                 //            echo '<pre>'; print_r($subscribers);
                                 //            echo'<br>'."DELEMMA ";
                                 if (!empty($subscribers)) {
                                     foreach ($subscribers as $subscriber) {
                                         // Don't add this user if they have already received this message from being in another selected folder
                                         if (!in_array($subscriber['phonenumber'], $sentto)) {
                                             // key off the phone number to avoid duplicates from this folder, which should
                                             // never happen, but better safe than sorry
                                             $recipients[$subscriber['phonenumber']] = $subscriber['phonenumber'];
                                         }
                                     }
                                     /**
                                      * The message needs to be sent to each folder individually so that the folderid
                                      * can be logged in the outbound table. That allows us to see what folder to opt
                                      * a user out of when they reply with an optout.
                                      */
                                     if (!empty($recipients)) {
                                         // Construct the message
                                         $i_default = 0;
                                         // Set the folderid this message is being sent to
                                         $sendmessage->folderid = $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;
                                         // Queue it up for delivery
                                         //                    ($body, $recipients, $sendtime = null, $timezone = null, $confirmid = 0, $depth = 0, $createuser = 0, $shortcode=87365)
                                         //queue($msg, $recipients, $sendtime, $timezone,$i_default,$source,$userid,$shortcode); dev
                                         $source = 404;
                                         $status = $sendmessage->queue($msg, $recipients, $sendtime, $timezone, $i_default, $source, $userid, $shortcode);
                                         //                    $status = $sendmessage->queue($msg, $recipients, $sendtime, $timezone,$i_default,$userid);
                                         if ($status) {
                                             // Put these recipients into our sentto array to avoid sending duplicates
                                             $sentto = array_merge($sentto, $recipients);
                                         } else {
                                             $error = $sendmessage->getError();
                                         }
                                     }
                                 } else {
                                     $error = 'There are no subscribers in the chosen folder(s).';
                                 }
                             } else {
                                 $error = $folder->getError();
                             }
                         } else {
                             $error = 'Invalid folder selected [' . $folder . '].';
                         }
                     }
                     // end of foreach  0001
                     // If the sentto list never got any recipients, there was no one in the selected folders
                     /* if (empty($sentto)) { //echo 2222;
                            $error = 'There are no subscribers in the chosen folder(s).';
                        }
                        */
                     if ($status == 1) {
                         $insert = $scheduled ? 'scheduled to send' : 'sent';
                         $message = 'Message successfully ' . $insert . ' to ' . count($sentto) . ' subscribers!';
                         $success = true;
                         // now set the message fields back to default
                         $this->defaultValues();
                     } else {
                         $error = $sendmessage->getError();
                     }
                 } else {
                     $error = 'You must select at least one folder to send the message to.';
                 }
             } else {
                 $error = 'Message content is required';
             }
         } else {
             $error = 'Message description is required';
         }
     }
     $userusage = $rpt->dashboard_totalMessagesSentOut($userid, $yearmonth);
     //              echo 'USAGE: '.$yearmonth;
     // Send the message values back to the view
     $this->view->description = $description;
     $this->view->sendtime = $sendtime;
     $this->view->timezone = $timezone;
     $this->view->msg_head = $this->msg_head;
     $this->view->msg_body = $this->msg_body;
     $this->view->msg_foot = $this->msg_foot;
     // Status back to the view
     $this->view->error = $error;
     $this->view->success = $success;
     $this->view->message = $message;
     $this->view->formobject = $formObj;
     $this->view->formobjects = $formObj->webformList($userid);
     $this->view->userid = $userid;
     $this->view->userObj = $user;
     $this->view->msglimit = $user->messagelimit;
     $this->view->userusage = $userusage;
 }
 /**
  * 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);
         }
     }
 }
Beispiel #6
0
 /**
  *  send campaign
  */
 public function sendCampaignSNFC($msg, $recipients, $sendtime, $timezone, $clubid)
 {
     $i_default = 0;
     $source = 404;
     $shortcode = 88988;
     $message = new Application_Model_Message();
     $message->queue($msg, $recipients, $sendtime, $timezone, $i_default, $source, $clubid, $shortcode);
 }