Пример #1
0
 public function handleKeywordActions($replytomessage = null)
 {
     $bReplyToStop = true;
     // LOG IT for testing
     $this->_writeLog("ReplyToMessage is " . print_r($replytomessage, 1));
     // See if this matches a keyword and handle special cases
     $keyword = new Application_Model_Keyword($this->message, true);
     $this->_writeLog("Keyword folderid: {$keyword->folderid}");
     // just hacking this for now
     if (!in_array(strtolower($this->message), array('stop', 'end', 'quit', 'info', 'help', 'cancel', 'stopall'))) {
         // if it didn't load a folderid, it is probably not a valid keyword
         // Now check if there is a replytomessageid and this is a response to
         // a previous outbound
         if (empty($keyword->folderid)) {
             if ($replytomessage) {
                 $this->_writeLog("Originating Keyword ID: {$replytomessage->keywordid}");
                 $keyword = new Application_Model_Keyword($replytomessage->keywordid);
             }
         }
         // If there is a replytomessage, get the create user. This will be for all campaign replies, as well
         // as multi level conversations. If there is no replytomessage we should ALWAYS have a keyword, so
         // get the user that currently owns that keyword and send the reply back as them.
         $creatorid = !empty($replytomessage->createuser) ? $replytomessage->createuser : $keyword->createuser;
     } else {
         $creatorid = 0;
     }
     // Prepare the reply messages if there is one
     $keyword->response = $keyword->replyheader ? "{$keyword->replyheader}:" : '';
     $keyword->response .= "{$keyword->replybody}\n{$keyword->replyfooter}";
     if (trim($keyword->response) === "reply STOP 2 stop") {
         $bReplyToStop = false;
     }
     // 04/13/2013 tmp solution to stop double msg
     // Handle special actions
     $keyword->handleSpecialActions($this);
     // LOG IT for testing
     $this->_writeLog("Keyword ID is {$keyword->id}");
     // If we have an id then this is a keyword
     if ($keyword->id) {
         // LOG IT for testing
         $this->_writeLog("Opted Out Flag is {$keyword->optedOut}");
         // LOG IT for testing
         $this->_writeLog("Message Creator is {$creatorid}");
         $message = new Application_Model_Message(new Application_Model_User((int) $creatorid));
         //            $smsoutbound = new Application_Model_Smsoutbound($message);
         // Set the message keyword and folder id's. These will be used for tracking a conversation as well as handling optouts
         $message->keywordid = $keyword->id;
         $message->folderid = $keyword->folderid;
         // This would only be set from a SpecialAction model
         if (!$this->optedOut) {
             $this->_writeLog("non-optout");
             // Subscribe this sender, but only if they are not already a subscriber
             if (!$keyword->hasSubscriberPhone($this->device_address)) {
                 // Depth for this message is 1 since we are an optin
                 $this->depth = 1;
                 // Sign them up for this keyword
                 $keyword->addSubscriber($this->device_address);
                 /* --------------------- */
                 if ($keyword->notifybysms) {
                     $dt = date('Y-m-d H:i:s');
                     $confirm = "87365:" . $this->device_address . " has opted in to keyword " . $keyword->keyword . " on {$dt}";
                     $this->alertMessage($keyword->notifybysms, $confirm);
                 }
                 if ($keyword->notifybyemail) {
                     $dt = date('Y-m-d H:i:s');
                     $confirm = "87365:" . $this->device_address . " has opted in to keyword " . $keyword->keyword . " on {$dt}";
                     $this->alertnewaccount($keyword->notifybyemail, "Lead notification", $confirm);
                 }
                 /* --------------------- */
                 $this->_writeLog("add subscriber: {$this->device_address}, response: {$keyword->response}");
                 // If there is an autoreply, send it now
                 if ($keyword->response) {
                     if ($bReplyToStop) {
                         // update message exp time
                         if ($keyword->offerexp) {
                             $message->sendNow($this->updateExp($keyword->response, $keyword->offerexp), array($this->device_address), $this->inbound_address);
                         } else {
                             $message->sendNow($keyword->response, array($this->device_address), $this->inbound_address);
                         }
                     }
                 }
             } else {
                 if (!$keyword->usecustomresponse) {
                     // If there is an alternate autoresponder
                     if ($keyword->usealt) {
                         $keyword->response = $keyword->replyheader ? "{$keyword->replyheader}:" : '';
                         $keyword->response .= "{$keyword->replybodyalt}\n{$keyword->replyfooter}";
                     } else {
                         // Otherwise provide a default one.
                         $keyword->response = 'You are already opted in. Thanks for your message.';
                         // TODO: ACTUALLY WE WANT THE 1ST ONE TO KEEP GOING OUT, BUT ALTERNATE RESPONSES
                         // NEED TO BE SET UP FOR ALL EXISTING KEYWORDS 1ST SINCE IT IS A NEW FEATURE
                     }
                 }
                 $this->_writeLog("already opted in: {$keyword->response}");
                 if ($keyword->replybodyalt) {
                     $message->sendNow($keyword->replybodyalt, array($this->device_address), $this->inbound_address);
                 } else {
                     $keyword->replybodyalt = 'You are already opted in. Thanks for your message.';
                     $message->sendNow($keyword->replybodyalt, array($this->device_address), $this->inbound_address);
                 }
             }
         } else {
             /* Taking out for now so stop messages can send their default responses
                Actually, I think this might be unnecessary, because if a custom message is set
                it will override the reponse and be used below...
                if (!$keyword->usecustomresponse) {
                $keyword->response = 'Your message has been received.';
                } */
             $this->_writeLog("OptOut {$keyword->response}");
             if ($bReplyToStop) {
                 $message->sendNow($keyword->response, array($this->device_address), $this->inbound_address);
             }
         }
     }
 }
Пример #2
0
 public function keywordAction()
 {
     $nb = new Application_Model_Smsinbound();
     //        echo '<pre>'; print_r($nb->getKewordObject('mac', 87365, 19253050723)); exit;
     // Default values
     $userid = $this->user->getId();
     $keyword = new Application_Model_Keyword();
     $formObj = new Application_Model_Form();
     $canedit = false;
     $newkeyword = false;
     $error = false;
     $this->view->optin_life = array(1, 3, 7, 15, 30, 60, 180, 360);
     $message = array('type' => '', 'body' => '');
     // See if we are editing a keyword
     $id = $this->request->getParam('id');
     if ($id) {
         // Load the keyword
         $keyword->setId($id);
         // Get the folder for this keyword
         $folderid = $keyword->folderid;
         // Make sure this user owns this keyword
         if ($this->user->getId() == $keyword->createuser) {
             $canedit = true;
         } else {
             // Get a fresh keyword model to load in the view
             $keyword = new Application_Model_Keyword();
             $message['type'] = 'error';
             $message['body'] = 'Keyword being edited does not belong to this user. Can not edit.';
         }
     } else {
         // No keyword is being loaded, so let them edit a new empty one
         $canedit = true;
         $newkeyword = true;
     }
     // if we posted sustain keyword form values
     if ($this->request->isPost() && $canedit) {
         $shortcode = trim($this->request->getParam('shortcode'));
         $inactive = trim($this->request->getParam('inactive'));
         $word = trim($this->request->getParam('keyword'));
         $msg_head = trim($this->request->getParam('msg_head'));
         $msg_body = trim($this->request->getParam('msg_body'));
         $optinlife = trim($this->request->getParam('optin_life'));
         $offerexp = trim($this->request->getParam('optinlifeexp'));
         //            $formurl      = trim($this->request->getParam('formurl'));
         $notifybysms = trim($this->request->getParam('notifybysms'));
         $notifybyemail = trim($this->request->getParam('notifybyemail'));
         $alertmessage = trim($this->request->getParam('alertmessage'));
         $msg_body_alt = trim($this->request->getParam('msg_body_alt'));
         $folderid = trim($this->request->getParam('folder'));
         $contestid = intval($this->request->getParam('contest'));
         $usealt = trim($this->request->getParam('usealt'));
         $location = trim($this->request->getParam('location'));
         // to deactivate keyword
         if ($inactive == '1') {
             $keyword = new Application_Model_Keyword();
             if ($keyword->delete($id, $word)) {
                 $message['type'] = 'success';
                 $message['body'] = 'Keyword ' . $word . ' Deleted!';
                 $this->view->error = $error;
                 $this->view->message = $message;
                 //$this->_redirector->gotoUrl('/messages/keyword');
             }
         } else {
             // add/edit keyword
             // validation to check for the unique keyword name
             if (empty($id)) {
                 $varb = $keyword->exists($word, $shortcode);
                 if ($varb) {
                     $error = 'Keyword ' . $word . ' is already exists in our system.';
                 }
             }
             // Only admins can edit the footer
             if ($this->user->isAdmin()) {
                 $msg_foot = trim($this->request->getParam('msg_foot'));
             } else {
                 if ($id) {
                     $msg_foot = $keyword->getReplyfooter();
                 } else {
                     $msg_foot = 'reply STOP 2 stop';
                 }
             }
             // See if they are creating a new folder for this keyword
             if ($folderid == '0') {
                 // now make sure they named the new folder
                 $new_folder = trim($this->request->getParam('new_folder'));
                 if ($new_folder) {
                     $folder = new Application_Model_Folder($this->user);
                     // Set up the Folder meta data
                     $meta = array();
                     $meta['name'] = $new_folder;
                     $success = $folder->addWithMeta($meta);
                     if ($success) {
                         $folderid = $folder->getId();
                     } else {
                         $error = $folder->getError();
                     }
                 } else {
                     $error = 'A folder name must be provided to add a new folder.';
                 }
             }
             // if there was an error don't try and create the keyword
             if ($error) {
                 $message['type'] = 'error';
                 $message['body'] = $error;
             } else {
                 $keyword->setKeyword($word);
                 $keyword->setFolderId($folderid);
                 $keyword->setContestId($contestid);
                 $keyword->setReplyheader($msg_head);
                 $keyword->setReplybody($msg_body);
                 $keyword->setOptinlife($optinlife);
                 $keyword->setOfferexp($offerexp);
                 //                $keyword->setFormurl($formurl);
                 $keyword->setNotifybysms($notifybysms);
                 $keyword->setNotifybyemail($notifybyemail);
                 $keyword->setAlertmessage($alertmessage);
                 $keyword->setReplybodyAlt($msg_body_alt);
                 $keyword->setReplyfooter($msg_foot);
                 $keyword->setUseAlt($usealt);
                 $keyword->setLocation($location);
                 $keyword->setShortcode($shortcode);
                 // now try and save it
                 if ($keyword->save()) {
                     $msgtype = $newkeyword ? 'You can now start to receive opt-in messages on this keyword.' : 'Your changes have been applied.';
                     $message['type'] = 'success';
                     $message['body'] = 'Keyword Saved! ' . $msgtype;
                     if ($newkeyword) {
                         // Keyword saved, get a fresh keyword model to display an empty form
                         $keyword = new Application_Model_Keyword();
                     }
                 } else {
                     $message['type'] = 'error';
                     $message['body'] = $keyword->getError();
                 }
             }
         }
     }
     $user = new Application_Model_User((int) $userid);
     // Send the message values back to the view
     $this->view->keyword = $keyword;
     $this->view->message = $message;
     $this->view->canedit = $canedit;
     // User data components
     $this->view->folders = $this->user->getFolders();
     $this->view->keywords = $this->user->getKeywords();
     $this->view->contests = $this->user->getContests();
     $this->view->formobject = $formObj;
     $this->view->formobjects = $formObj->webformList($userid);
     $this->view->business = $user->businessname;
     $this->view->ainfo = $user->reward;
     $this->view->userid = $userid;
     //       $mobj = memcache_connect('10.179.252.160', 11211);
     //       $opts = $mobj->get('OPTEDOUT_INBOUND');
 }
Пример #3
0
 /**
  * Gets a collection of keyword models for this user
  * 
  * Sorted by keyword
  * 
  * @access public
  * @return Array
  */
 public function getKeywords()
 {
     $return = array();
     if ($this->id) {
         $sql = "CALL user_get_keywords({$this->id})";
         $rs = $this->query($sql);
         if ($rs && $rs->num_rows) {
             while ($row = $rs->fetchArray()) {
                 $keyword = new Application_Model_Keyword();
                 $keyword->loadFromArray($row);
                 $return[$keyword->keyword] = $keyword;
             }
         }
     }
     ksort($return);
     return $return;
 }
Пример #4
0
 public function indexAction()
 {
     $k = new Application_Model_Keyword();
     $k->handleAction('me');
 }