Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for processing a survey. |
6a488035 TO |
36 | */ |
37 | class CRM_Campaign_Form_Survey extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The id of the object being edited. |
6a488035 TO |
41 | * |
42 | * @var int | |
43 | */ | |
44 | protected $_surveyId; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Action. |
6a488035 TO |
48 | * |
49 | * @var int | |
50 | */ | |
3a936dab | 51 | public $_action; |
6a488035 TO |
52 | |
53 | /** | |
fe482240 | 54 | * SurveyTitle. |
6a488035 TO |
55 | * |
56 | * @var string | |
57 | */ | |
58 | protected $_surveyTitle; | |
59 | ||
60 | public function preProcess() { | |
61 | if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
62 | CRM_Utils_System::permissionDenied(); | |
63 | } | |
64 | ||
353ffa53 | 65 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); |
6a488035 TO |
66 | $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); |
67 | ||
68 | if ($this->_surveyId) { | |
69 | $this->_single = TRUE; | |
70 | ||
71 | $params = array('id' => $this->_surveyId); | |
72 | CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo); | |
73 | $this->_surveyTitle = $surveyInfo['title']; | |
74 | $this->assign('surveyTitle', $this->_surveyTitle); | |
75 | CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle))); | |
76 | } | |
77 | ||
78 | $this->assign('action', $this->_action); | |
79 | $this->assign('surveyId', $this->_surveyId); | |
80 | ||
98c54bff AH |
81 | // when custom data is included in this page |
82 | if (!empty($_POST['hidden_custom'])) { | |
9e032034 | 83 | $this->set('type', 'Survey'); |
98c54bff AH |
84 | $this->set('entityId', $this->_surveyId); |
85 | CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId); | |
86 | CRM_Custom_Form_CustomData::buildQuickForm($this); | |
87 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
88 | } | |
89 | ||
6a488035 TO |
90 | // CRM-11480, CRM-11682 |
91 | // Preload libraries required by the "Questions" tab | |
92 | CRM_UF_Page_ProfileEditor::registerProfileScripts(); | |
93 | CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel')); | |
94 | ||
95 | CRM_Campaign_Form_Survey_TabHeader::build($this); | |
96 | } | |
97 | ||
98 | /** | |
fe482240 | 99 | * Build the form object. |
6a488035 TO |
100 | */ |
101 | public function buildQuickForm() { | |
102 | $session = CRM_Core_Session::singleton(); | |
103 | if ($this->_surveyId) { | |
104 | $buttons = array( | |
105 | array( | |
106 | 'type' => 'upload', | |
107 | 'name' => ts('Save'), | |
108 | 'isDefault' => TRUE, | |
109 | ), | |
110 | array( | |
111 | 'type' => 'upload', | |
112 | 'name' => ts('Save and Done'), | |
113 | 'subName' => 'done', | |
114 | ), | |
115 | array( | |
116 | 'type' => 'upload', | |
117 | 'name' => ts('Save and Next'), | |
118 | 'spacing' => ' ', | |
119 | 'subName' => 'next', | |
120 | ), | |
121 | ); | |
122 | } | |
123 | else { | |
124 | $buttons = array( | |
125 | array( | |
126 | 'type' => 'upload', | |
f212d37d | 127 | 'name' => ts('Continue'), |
6a488035 TO |
128 | 'spacing' => ' ', |
129 | 'isDefault' => TRUE, | |
130 | ), | |
131 | ); | |
132 | } | |
28a04ea9 | 133 | $buttons[] = array( |
134 | 'type' => 'cancel', | |
135 | 'name' => ts('Cancel'), | |
136 | ); | |
6a488035 TO |
137 | $this->addButtons($buttons); |
138 | ||
139 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
140 | $session->replaceUserContext($url); | |
141 | } | |
142 | ||
00be9182 | 143 | public function endPostProcess() { |
6a488035 TO |
144 | // make submit buttons keep the current working tab opened. |
145 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
146 | $tabTitle = $className = CRM_Utils_String::getClassName($this->_name); | |
147 | if ($tabTitle == 'Main') { | |
148 | $tabTitle = 'Main settings'; | |
149 | } | |
353ffa53 | 150 | $subPage = strtolower($className); |
6a488035 TO |
151 | CRM_Core_Session::setStatus(ts("'%1' have been saved.", array(1 => $tabTitle)), ts('Saved'), 'success'); |
152 | ||
153 | $this->postProcessHook(); | |
154 | ||
28a04ea9 | 155 | if ($this->_action & CRM_Core_Action::ADD) { |
6a488035 | 156 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/questions", |
353ffa53 | 157 | "action=update&reset=1&id={$this->_surveyId}")); |
28a04ea9 | 158 | } |
6a488035 TO |
159 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
160 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); | |
161 | } | |
4c9b6178 | 162 | elseif ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_next") { |
6a488035 TO |
163 | $subPage = CRM_Campaign_Form_Survey_TabHeader::getNextTab($this); |
164 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 165 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
166 | } |
167 | else { | |
168 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 169 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
170 | } |
171 | } | |
172 | } | |
173 | ||
30c4e065 EM |
174 | /** |
175 | * @return string | |
176 | */ | |
00be9182 | 177 | public function getTemplateFileName() { |
481a74f4 | 178 | if ($this->controller->getPrint() || $this->getVar('_surveyId') <= 0) { |
6a488035 TO |
179 | return parent::getTemplateFileName(); |
180 | } | |
181 | else { | |
182 | // hack lets suppress the form rendering for now | |
183 | self::$_template->assign('isForm', FALSE); | |
184 | return 'CRM/Campaign/Form/Survey/Tab.tpl'; | |
185 | } | |
186 | } | |
96025800 | 187 | |
6a488035 | 188 | } |