1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37:
38: class CreateWebFormAction extends CAction {
39:
40: /**
41: * Create a web lead form with a custom style
42: *
43: * Currently web forms have all options passed as GET parameters. Saved web forms
44: * are saved to the table x2_web_forms. Saving, retrieving, and updating a web form
45: * all happens in this function. Someday this should be updated to be it's own module.
46: *
47: *
48: * This get request is for weblead/service type only, marketing/weblist/view supplies
49: * the form that posts for weblist type
50: *
51: */
52: public function run(){
53: $modelClass = $this->controller->modelClass;
54: if ($modelClass === 'Campaign') $modelClass = 'Contacts';
55:
56: if($_SERVER['REQUEST_METHOD'] === 'POST'){ // save a web form
57: if(empty($_POST['name'])){
58: if ($modelClass === 'Contacts') {
59: echo json_encode(array(
60: 'errors' => array(
61: 'name' => Yii::t('marketing', 'Name cannot be blank.'))));
62: } elseif ($modelClass === 'Services') {
63: echo json_encode(array(
64: 'errors' => array(
65: 'name' => Yii::t('marketing', 'Name cannot be blank.'))));
66: }
67: return;
68: }
69:
70: if ($modelClass === 'Contacts')
71: $type = !empty($_POST['type']) ? $_POST['type'] : 'weblead';
72: elseif ($modelClass === 'Services')
73: $type = 'serviceCase';
74:
75: $model = WebForm::model()->findByAttributes(
76: array('name' => $_POST['name'], 'type' => $type));
77:
78: // check if we are updating an existing web form
79: if(!isset($model)){
80: $model = new WebForm;
81: $model->name = $_POST['name'];
82: $model->type = $type;
83: $model->modelName = $modelClass;
84: $model->visibility = 1;
85: $model->assignedTo = Yii::app()->user->getName();
86: $model->createdBy = Yii::app()->user->getName();
87: $model->createDate = time();
88: }
89:
90: //grab web lead configuration and stash in 'params'
91: $whitelist = array('fg', 'bgc', 'font', 'bs', 'bc', 'tags');
92: $config = array_filter(array_intersect_key($_POST, array_flip($whitelist)));
93: //restrict param values, alphanumeric, # for color vals, comma for tag list
94: $config = preg_replace('/[^a-zA-Z0-9#,]/', '', $config);
95: if(!empty($config))
96: $model->params = $config;
97: else
98: $model->params = null;
99:
100: if (isset ($_POST['generateLead']) && isset ($_POST['leadSource'])) {
101: $model->leadSource = $_POST['leadSource'];
102: $model->generateLead = 1;
103: } else {
104: $model->generateLead = 0;
105: }
106: if (isset ($_POST['generateAccount'])) {
107: $model->generateAccount = 1;
108: } else {
109: $model->generateAccount = 0;
110: }
111: if(isset($_POST['redirectUrl'])) {
112: $model->redirectUrl = $_POST['redirectUrl'];
113: }
114:
115:
116:
117: $model->updatedBy = Yii::app()->user->getName();
118: $model->lastUpdated = time();
119:
120: if($model->save()){
121: echo json_encode($model->attributes);
122: }else{
123: echo json_encode(array('errors' => $model->getErrors()));
124: }
125: }else{
126: if ($modelClass === 'Contacts') {
127:
128: $criteria = X2Model::model('Marketing')->getAccessCriteria();
129: $condition = $criteria->condition;
130:
131: $forms = WebForm::model()
132: ->findAll('type="weblead" AND '.$condition, $criteria->params);
133:
134: $this->controller->render(
135: 'application.modules.marketing.views.marketing.webleadForm',
136: array('forms' => $forms));
137: } else if ($modelClass === 'Services') {
138: $criteria = X2Model::model('Services')->getAccessCriteria();
139: $condition = $criteria->condition;
140:
141: // get service web forms (other option is 'weblead' used by marketing module)
142: $forms = WebForm::model()
143: ->findAll('type="serviceCase" AND '.$condition, $criteria->params);
144:
145: $this->controller->render(
146: 'application.modules.services.views.services.createWebFormView',
147: array('forms' => $forms));
148: }
149:
150: }
151: }
152:
153: }
154:
155: ?>
156: