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; }