Esempio n. 1
0
 public function createAction()
 {
     $error = null;
     $message = null;
     $userid = $this->user->getId();
     $username = $this->user->username();
     $formObj = new Application_Model_Form();
     $reportObj = new Application_Model_Report();
     $webformListSubAccount = array();
     if ($reportObj->checkAdminUser($userid)) {
         $subUsersArray = $reportObj->findChildEntityList($userid, 5, "");
         //echo "<pre>"; print_r($subUsersArray); exit;
         foreach ($subUsersArray as $subuser) {
             $webformlistmerge = $formObj->webformList($subuser['childuserid']);
             if (!empty($webformlistmerge) and is_array($webformlistmerge)) {
                 $webformListSubAccount = array_merge($webformListSubAccount, $webformlistmerge);
             }
         }
         //echo "<pre>"; print_r($webformListSubAccount); exit;
     }
     if ($this->request->isPost()) {
         //echo "<pre>"; print_r($this->_request->getParams()); exit;
         $postdataValue = $this->_request->getParams();
         //echo '<pre>'; print_r($postdataValue);exit;
         $this->view->postedValues = $postdataValue;
         if ($this->request->getParam('formurl') == "") {
             $message['type'] = "error";
             $message['body'] = "Atleast Unique URL is required";
         } else {
             $createformfor = "";
             if ($this->request->getParam('subacc') == "on") {
                 $folderidArray = "subacc";
             } else {
                 $folderidArray = $this->request->getParam('folderid');
             }
             // echo '<pre>'; print_r($folderidArray); exit;
             if (!empty($folderidArray)) {
                 $webformUrlArray = array();
                 $weburl = trim($this->request->getParam('formurl'));
                 $weburlfilter = preg_replace('/[^a-z0-9]/', '-', $weburl);
                 if ($folderidArray == "subacc") {
                     foreach ($subUsersArray as $subuser) {
                         $userid = $subuser['childuserid'];
                         $folderids = $this->user->getFolderElseCreate("weboptin", $userid);
                         $webformUrlArray = array("entityid" => $userid, "urlname" => addslashes($weburlfilter), "thankumsg" => addslashes($this->request->getParam('thanku_message')), "descmsg" => addslashes($this->request->getParam('formdesc')), "folderid" => $folderids, "dobstatus" => addslashes($this->request->getParam('dobstatus')), "alertmessage" => addslashes($this->request->getParam('alertmessage')), "notifybysms" => $this->request->getParam('notifybysms'), "notifybyemail" => addslashes($this->request->getParam('notifybyemail')));
                         $webformAttbArray = $this->request->getParam('chkname');
                         //echo "<pre>"; print_r($webformAttbArray);
                         $webformAttbTypeArray = $this->request->getParam('chktype');
                         //echo "<pre>"; print_r($webformAttbTypeArray);
                         $webformAttbWeightage = $this->request->getParam('weightage');
                         //echo "<pre>"; print_r($webformAttbTypeArray);
                         //echo "<pre>"; print_r($this->request->getParam('chk'));
                         foreach ($this->request->getParam('chk') as $key => $checked) {
                             $webformAttbArrayToinsert[$key]['weightage'] = addslashes($webformAttbWeightage[$checked]);
                             $webformAttbArrayToinsert[$key]['attb'] = addslashes($webformAttbArray[$checked]);
                             $webformAttbArrayToinsert[$key]['attbtype'] = addslashes($webformAttbTypeArray[$checked]);
                             $webformAttbOptionArray = $this->request->getParam('chkvalue' . $checked);
                             //echo "<pre>"; print_r($webformAttbOptionArray);
                             if (!empty($webformAttbOptionArray)) {
                                 $webformAttbOptionString = implode(",", $webformAttbOptionArray);
                             } else {
                                 $webformAttbOptionString = "";
                             }
                             $webformAttbArrayToinsert[$key]['attboption'] = addslashes($webformAttbOptionString);
                         }
                         //echo "<pre>"; print_r($webformAttbArrayToinsert);   exit;
                         if (empty($webformAttbArrayToinsert)) {
                             $message['type'] = "error";
                             $message['body'] = "Please check atleast one information field";
                         } elseif (empty($folderidArray)) {
                             $message['type'] = "error";
                             $message['body'] = "Please choose atleast one folder";
                         } else {
                             $dataInserted = $formObj->insertFormDetails($webformUrlArray, $webformAttbArrayToinsert);
                             if ($dataInserted) {
                                 $message['type'] = "success";
                                 $message['body'] = "Form created successfully";
                             } else {
                                 $message['type'] = "error";
                                 $message['body'] = $formObj->getError();
                             }
                         }
                     }
                     $this->_redirector->gotoUrl('/form/create/');
                 } else {
                     $folderids = implode($folderidArray, ',');
                     $webformUrlArray = array("entityid" => $userid, "urlname" => addslashes($weburlfilter), "thankumsg" => addslashes($this->request->getParam('thanku_message')), "descmsg" => addslashes($this->request->getParam('formdesc')), "folderid" => $folderids, "dobstatus" => addslashes($this->request->getParam('dobstatus')), "alertmessage" => addslashes($this->request->getParam('alertmessage')), "notifybysms" => $this->request->getParam('notifybysms'), "notifybyemail" => addslashes($this->request->getParam('notifybyemail')));
                     $webformAttbArray = $this->request->getParam('chkname');
                     //echo "<pre>"; print_r($webformAttbArray);
                     $webformAttbTypeArray = $this->request->getParam('chktype');
                     //echo "<pre>"; print_r($webformAttbTypeArray);
                     $webformAttbWeightage = $this->request->getParam('weightage');
                     //echo "<pre>"; print_r($webformAttbTypeArray);
                     //echo "<pre>"; print_r($this->request->getParam('chk'));
                     foreach ($this->request->getParam('chk') as $key => $checked) {
                         $webformAttbArrayToinsert[$key]['weightage'] = addslashes($webformAttbWeightage[$checked]);
                         $webformAttbArrayToinsert[$key]['attb'] = addslashes($webformAttbArray[$checked]);
                         $webformAttbArrayToinsert[$key]['attbtype'] = addslashes($webformAttbTypeArray[$checked]);
                         $webformAttbOptionArray = $this->request->getParam('chkvalue' . $checked);
                         //echo "<pre>"; print_r($webformAttbOptionArray);
                         if (!empty($webformAttbOptionArray)) {
                             $webformAttbOptionString = implode(",", $webformAttbOptionArray);
                         } else {
                             $webformAttbOptionString = "";
                         }
                         $webformAttbArrayToinsert[$key]['attboption'] = addslashes($webformAttbOptionString);
                     }
                     //echo "<pre>"; print_r($webformAttbArrayToinsert);   exit;
                     if (empty($webformAttbArrayToinsert)) {
                         $message['type'] = "error";
                         $message['body'] = "Please check atleast one information field";
                     } elseif (empty($folderidArray)) {
                         $message['type'] = "error";
                         $message['body'] = "Please choose atleast one folder";
                     } else {
                         $dataInserted = $formObj->insertFormDetails($webformUrlArray, $webformAttbArrayToinsert);
                         if ($dataInserted) {
                             $message['type'] = "success";
                             $message['body'] = "Form created successfully";
                         } else {
                             $message['type'] = "error";
                             $message['body'] = $formObj->getError();
                         }
                     }
                 }
             } else {
                 $message['type'] = "error";
                 $message['body'] = "Please select atleast one folder from dropdown.";
             }
         }
     }
     $user = new Application_Model_User((int) $userid);
     $this->view->message = $message;
     $this->view->folders = $this->user->getFolders();
     $this->view->webformlist = $formObj->webformList($userid);
     $this->view->webformlistSubaccount = $webformListSubAccount;
     $this->view->business = $user->businessname;
     $this->view->ainfo = $user->reward;
     $this->view->userid = $userid;
 }