예제 #1
0
 /**
  * Create a web lead form with a custom style
  *
  * Currently web forms have all options passed as GET parameters. Saved web forms
  * are saved to the table x2_web_forms. Saving, retrieving, and updating a web form
  * all happens in this function. Someday this should be updated to be it's own module.
  *
  * 
  * This get request is for weblead/service type only, marketing/weblist/view supplies 
  * the form that posts for weblist type 
  *  
  */
 public function run()
 {
     AuxLib::debugLogR($_POST);
     $modelClass = $this->controller->modelClass;
     if ($modelClass === 'Campaign') {
         $modelClass = 'Contacts';
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         // save a web form
         if (empty($_POST['name'])) {
             if ($modelClass === 'Contacts') {
                 echo json_encode(array('errors' => array('name' => Yii::t('marketing', 'Name cannot be blank.'))));
             } elseif ($modelClass === 'Services') {
                 echo json_encode(array('errors' => array('name' => Yii::t('marketing', 'Name cannot be blank.'))));
             }
             return;
         }
         if ($modelClass === 'Contacts') {
             $type = !empty($_POST['type']) ? $_POST['type'] : 'weblead';
         } elseif ($modelClass === 'Services') {
             $type = 'serviceCase';
         }
         $model = WebForm::model()->findByAttributes(array('name' => $_POST['name'], 'type' => $type));
         // check if we are updating an existing web form
         if (!isset($model)) {
             $model = new WebForm();
             $model->name = $_POST['name'];
             $model->type = $type;
             $model->modelName = $modelClass;
             $model->visibility = 1;
             $model->assignedTo = Yii::app()->user->getName();
             $model->createdBy = Yii::app()->user->getName();
             $model->createDate = time();
         }
         //grab web lead configuration and stash in 'params'
         $whitelist = array('fg', 'bgc', 'font', 'bs', 'bc', 'tags');
         $config = array_filter(array_intersect_key($_POST, array_flip($whitelist)));
         //restrict param values, alphanumeric, # for color vals, comma for tag list
         $config = preg_replace('/[^a-zA-Z0-9#,]/', '', $config);
         if (!empty($config)) {
             $model->params = $config;
         } else {
             $model->params = null;
         }
         if (isset($_POST['generateLead']) && isset($_POST['leadSource'])) {
             $model->leadSource = $_POST['leadSource'];
             $model->generateLead = 1;
         } else {
             $model->generateLead = 0;
         }
         if (isset($_POST['generateAccount'])) {
             $model->generateAccount = 1;
         } else {
             $model->generateAccount = 0;
         }
         $model->updatedBy = Yii::app()->user->getName();
         $model->lastUpdated = time();
         if ($model->save()) {
             echo json_encode($model->attributes);
         } else {
             echo json_encode(array('errors' => $model->getErrors()));
         }
     } else {
         if ($modelClass === 'Contacts') {
             $criteria = X2Model::model('Marketing')->getAccessCriteria();
             $condition = $criteria->condition;
             $forms = WebForm::model()->findAll('type="weblead" AND ' . $condition, $criteria->params);
             $this->controller->render('application.modules.marketing.views.marketing.webleadForm', array('forms' => $forms));
         } else {
             if ($modelClass === 'Services') {
                 $criteria = X2Model::model('Services')->getAccessCriteria();
                 $condition = $criteria->condition;
                 // get service web forms (other option is 'weblead' used by marketing module)
                 $forms = WebForm::model()->findAll('type="serviceCase" AND ' . $condition, $criteria->params);
                 $this->controller->render('application.modules.services.views.services.createWebFormView', array('forms' => $forms));
             }
         }
     }
 }
예제 #2
0
 public function actionSaveWebLeadFormCustomHtml()
 {
     if (!empty($_POST) && !empty($_POST['id']) && !empty($_POST['html'])) {
         $model = WebForm::model()->findByPk($_POST['id']);
         if ($model) {
             $model->header = $_POST['html'];
             if ($model->save()) {
                 echo CJSON::encode(array('success', $model->attributes));
                 return;
             }
         }
     }
     echo CJSON::encode(array('error', Yii::t('marketing', 'Custom HTML could not be saved.')));
 }
예제 #3
0
 /**
  * Create a web lead form with a custom style
  *
  * There are currently two methods of specifying web form options. 
  *  Method 1 (legacy):
  *      Web form options are sent in the GET parameters (limited options: css, web form
  *      id for retrieving custom header)
  *  Method 2 (new):
  *      CSS options are passed in the GET parameters and all other options (custom fields, 
  *      custom html, and email templates) are stored in the database and accessed via a
  *      web form id sent in the GET parameters.
  *
  * This get request is for weblead/service type only, marketing/weblist/view supplies
  * the form that posts for weblist type
  *
  */
 public function run()
 {
     $modelClass = $this->controller->modelClass;
     if ($modelClass === 'Campaign') {
         $modelClass = 'Contacts';
     }
     if ($modelClass === 'Contacts') {
         $model = new Contacts('webForm');
     } elseif ($modelClass === 'Services') {
         $model = new Services('webForm');
     }
     $extractedParams = array();
     if (isset($_GET['webFormId'])) {
         $webForm = WebForm::model()->findByPk($_GET['webFormId']);
     }
     $extractedParams['leadSource'] = null;
     $extractedParams['generateLead'] = false;
     $extractedParams['generateAccount'] = false;
     if (isset($webForm)) {
         // new method
         if (!empty($webForm->leadSource)) {
             $extractedParams['leadSource'] = $webForm->leadSource;
         }
         if (!empty($webForm->generateLead)) {
             $extractedParams['generateLead'] = $webForm->generateLead;
         }
         if (!empty($webForm->generateAccount)) {
             $extractedParams['generateAccount'] = $webForm->generateAccount;
         }
     }
     if ($modelClass === 'Contacts') {
         $this->handleWebleadFormSubmission($model, $extractedParams);
     } else {
         if ($modelClass === 'Services') {
             $this->handleServiceFormSubmission($model, $extractedParams);
         }
     }
 }