/** * emergency decision to get keywordid * and folderid * */ public function getKewordidFolderid(Application_Model_Keyword $kwd, $message) { $msg = trim($message); $sql = "select id, folderid from keywords where keyword='" . $msg . "'"; $rs = $this->query($sql); if ($rs->hasResults()) { foreach ($rs->fetchAll() as $obj) { $kwd->setId($obj['id']); $kwd->setFolderId($obj['folderid']); } } return $kwd; }
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'); }