phpcs - Fix error, "Expected 1 newline at end of file; XXX found".
[civicrm-core.git] / CRM / Campaign / Form / Survey.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for processing a survey
38 *
39 */
40 class CRM_Campaign_Form_Survey extends CRM_Core_Form {
41
42 /**
43 * The id of the object being edited
44 *
45 * @var int
46 */
47 protected $_surveyId;
48
49 /**
50 * Action
51 *
52 * @var int
53 */
54 protected $_action;
55
56 /**
57 * SurveyTitle
58 *
59 * @var string
60 */
61 protected $_surveyTitle;
62
63 public function preProcess() {
64 if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
65 CRM_Utils_System::permissionDenied();
66 }
67
68 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
69 $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
70
71 if ($this->_surveyId) {
72 $this->_single = TRUE;
73
74 $params = array('id' => $this->_surveyId);
75 CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo);
76 $this->_surveyTitle = $surveyInfo['title'];
77 $this->assign('surveyTitle', $this->_surveyTitle);
78 CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle)));
79 }
80
81 $this->assign('action', $this->_action);
82 $this->assign('surveyId', $this->_surveyId);
83
84 // CRM-11480, CRM-11682
85 // Preload libraries required by the "Questions" tab
86 CRM_UF_Page_ProfileEditor::registerProfileScripts();
87 CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel'));
88
89 CRM_Campaign_Form_Survey_TabHeader::build($this);
90 }
91
92 /**
93 * Build the form object
94 *
95 * @param null
96 *
97 * @return void
98 */
99 public function buildQuickForm() {
100 $session = CRM_Core_Session::singleton();
101 if ($this->_surveyId) {
102 $buttons = array(
103 array(
104 'type' => 'upload',
105 'name' => ts('Save'),
106 'isDefault' => TRUE,
107 ),
108 array(
109 'type' => 'upload',
110 'name' => ts('Save and Done'),
111 'subName' => 'done',
112 ),
113 array(
114 'type' => 'upload',
115 'name' => ts('Save and Next'),
116 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
117 'subName' => 'next',
118 ),
119 );
120 }
121 else {
122 $buttons = array(
123 array(
124 'type' => 'upload',
125 'name' => ts('Continue >>'),
126 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
127 'isDefault' => TRUE,
128 ),
129 );
130 }
131 $buttons[] =
132 array(
133 'type' => 'cancel',
134 'name' => ts('Cancel'),
135 );
136 $this->addButtons($buttons);
137
138 $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
139 $session->replaceUserContext($url);
140 }
141
142 public function endPostProcess() {
143 // make submit buttons keep the current working tab opened.
144 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
145 $tabTitle = $className = CRM_Utils_String::getClassName($this->_name);
146 if ($tabTitle == 'Main') {
147 $tabTitle = 'Main settings';
148 }
149 $subPage = strtolower($className);
150 CRM_Core_Session::setStatus(ts("'%1' have been saved.", array(1 => $tabTitle)), ts('Saved'), 'success');
151
152 $this->postProcessHook();
153
154 if ($this->_action & CRM_Core_Action::ADD)
155 CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/questions",
156 "action=update&reset=1&id={$this->_surveyId}"));
157
158 if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
159 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
160 }
161 else if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_next") {
162 $subPage = CRM_Campaign_Form_Survey_TabHeader::getNextTab($this);
163 CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}",
164 "action=update&reset=1&id={$this->_surveyId}"));
165 }
166 else {
167 CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}",
168 "action=update&reset=1&id={$this->_surveyId}"));
169 }
170 }
171 }
172
173 /**
174 * @return string
175 */
176 public function getTemplateFileName() {
177 if ($this->controller->getPrint() || $this->getVar('_surveyId') <= 0 ) {
178 return parent::getTemplateFileName();
179 }
180 else {
181 // hack lets suppress the form rendering for now
182 self::$_template->assign('isForm', FALSE);
183 return 'CRM/Campaign/Form/Survey/Tab.tpl';
184 }
185 }
186 }