Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
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 | */ | |
51 | protected $_action; | |
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 | ||
81 | // CRM-11480, CRM-11682 | |
82 | // Preload libraries required by the "Questions" tab | |
83 | CRM_UF_Page_ProfileEditor::registerProfileScripts(); | |
84 | CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel')); | |
85 | ||
86 | CRM_Campaign_Form_Survey_TabHeader::build($this); | |
87 | } | |
88 | ||
89 | /** | |
fe482240 | 90 | * Build the form object. |
6a488035 TO |
91 | */ |
92 | public function buildQuickForm() { | |
93 | $session = CRM_Core_Session::singleton(); | |
94 | if ($this->_surveyId) { | |
95 | $buttons = array( | |
96 | array( | |
97 | 'type' => 'upload', | |
98 | 'name' => ts('Save'), | |
99 | 'isDefault' => TRUE, | |
100 | ), | |
101 | array( | |
102 | 'type' => 'upload', | |
103 | 'name' => ts('Save and Done'), | |
104 | 'subName' => 'done', | |
105 | ), | |
106 | array( | |
107 | 'type' => 'upload', | |
108 | 'name' => ts('Save and Next'), | |
109 | 'spacing' => ' ', | |
110 | 'subName' => 'next', | |
111 | ), | |
112 | ); | |
113 | } | |
114 | else { | |
115 | $buttons = array( | |
116 | array( | |
117 | 'type' => 'upload', | |
f212d37d | 118 | 'name' => ts('Continue'), |
6a488035 TO |
119 | 'spacing' => ' ', |
120 | 'isDefault' => TRUE, | |
121 | ), | |
122 | ); | |
123 | } | |
28a04ea9 | 124 | $buttons[] = array( |
125 | 'type' => 'cancel', | |
126 | 'name' => ts('Cancel'), | |
127 | ); | |
6a488035 TO |
128 | $this->addButtons($buttons); |
129 | ||
130 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
131 | $session->replaceUserContext($url); | |
132 | } | |
133 | ||
00be9182 | 134 | public function endPostProcess() { |
6a488035 TO |
135 | // make submit buttons keep the current working tab opened. |
136 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
137 | $tabTitle = $className = CRM_Utils_String::getClassName($this->_name); | |
138 | if ($tabTitle == 'Main') { | |
139 | $tabTitle = 'Main settings'; | |
140 | } | |
353ffa53 | 141 | $subPage = strtolower($className); |
6a488035 TO |
142 | CRM_Core_Session::setStatus(ts("'%1' have been saved.", array(1 => $tabTitle)), ts('Saved'), 'success'); |
143 | ||
144 | $this->postProcessHook(); | |
145 | ||
28a04ea9 | 146 | if ($this->_action & CRM_Core_Action::ADD) { |
6a488035 | 147 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/questions", |
353ffa53 | 148 | "action=update&reset=1&id={$this->_surveyId}")); |
28a04ea9 | 149 | } |
6a488035 TO |
150 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
151 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); | |
152 | } | |
4c9b6178 | 153 | elseif ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_next") { |
6a488035 TO |
154 | $subPage = CRM_Campaign_Form_Survey_TabHeader::getNextTab($this); |
155 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 156 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
157 | } |
158 | else { | |
159 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 160 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
161 | } |
162 | } | |
163 | } | |
164 | ||
30c4e065 EM |
165 | /** |
166 | * @return string | |
167 | */ | |
00be9182 | 168 | public function getTemplateFileName() { |
481a74f4 | 169 | if ($this->controller->getPrint() || $this->getVar('_surveyId') <= 0) { |
6a488035 TO |
170 | return parent::getTemplateFileName(); |
171 | } | |
172 | else { | |
173 | // hack lets suppress the form rendering for now | |
174 | self::$_template->assign('isForm', FALSE); | |
175 | return 'CRM/Campaign/Form/Survey/Tab.tpl'; | |
176 | } | |
177 | } | |
96025800 | 178 | |
6a488035 | 179 | } |