3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class generates form components for processing a survey.
37 class CRM_Campaign_Form_Survey
extends CRM_Core_Form
{
40 * The id of the object being edited.
58 protected $_surveyTitle;
61 * Explicitly declare the entity api name.
63 public function getDefaultEntity() {
68 * Get the entity id being edited.
72 public function getEntityId() {
73 return $this->_surveyId
;
76 public function preProcess() {
77 if (!CRM_Campaign_BAO_Campaign
::accessCampaign()) {
78 CRM_Utils_System
::permissionDenied();
81 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
82 $this->_surveyId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
84 if ($this->_surveyId
) {
85 $this->_single
= TRUE;
87 $params = ['id' => $this->_surveyId
];
88 CRM_Campaign_BAO_Survey
::retrieve($params, $surveyInfo);
89 $this->_surveyTitle
= $surveyInfo['title'];
90 $this->assign('surveyTitle', $this->_surveyTitle
);
91 CRM_Utils_System
::setTitle(ts('Configure Survey - %1', [1 => $this->_surveyTitle
]));
94 $this->assign('action', $this->_action
);
95 $this->assign('surveyId', $this->_surveyId
);
97 // Add custom data to form
98 CRM_Custom_Form_CustomData
::addToForm($this);
100 // CRM-11480, CRM-11682
101 // Preload libraries required by the "Questions" tab
102 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
103 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ActivityModel']);
105 CRM_Campaign_Form_Survey_TabHeader
::build($this);
109 * Build the form object.
111 public function buildQuickForm() {
112 $session = CRM_Core_Session
::singleton();
113 if ($this->_surveyId
) {
117 'name' => ts('Save'),
122 'name' => ts('Save and Done'),
127 'name' => ts('Save and Next'),
128 'spacing' => ' ',
137 'name' => ts('Continue'),
138 'spacing' => ' ',
145 'name' => ts('Cancel'),
147 $this->addButtons($buttons);
149 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
150 $session->replaceUserContext($url);
153 public function endPostProcess() {
154 // make submit buttons keep the current working tab opened.
155 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
156 $tabTitle = $className = CRM_Utils_String
::getClassName($this->_name
);
157 if ($tabTitle == 'Main') {
158 $tabTitle = 'Main settings';
160 $subPage = strtolower($className);
161 CRM_Core_Session
::setStatus(ts("'%1' have been saved.", [1 => $tabTitle]), ts('Saved'), 'success');
163 $this->postProcessHook();
165 if ($this->_action
& CRM_Core_Action
::ADD
) {
166 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/questions",
167 "action=update&reset=1&id={$this->_surveyId}"));
169 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
170 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey'));
172 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_next") {
173 $subPage = CRM_Campaign_Form_Survey_TabHeader
::getNextTab($this);
174 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/{$subPage}",
175 "action=update&reset=1&id={$this->_surveyId}"));
178 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/{$subPage}",
179 "action=update&reset=1&id={$this->_surveyId}"));
187 public function getTemplateFileName() {
188 if ($this->controller
->getPrint() ||
$this->getVar('_surveyId') <= 0) {
189 return parent
::getTemplateFileName();
192 // hack lets suppress the form rendering for now
193 self
::$_template->assign('isForm', FALSE);
194 return 'CRM/Campaign/Form/Survey/Tab.tpl';