3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
39 class CRM_Campaign_Form_Gotv
extends CRM_Core_Form
{
42 * Are we forced to run a search
49 protected $_votingTab = FALSE;
51 protected $_searchVoterFor;
54 * processing needed for buildForm and later
58 */ function preProcess() {
59 $this->_search
= CRM_Utils_Array
::value('search', $_GET);
60 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
61 $this->_surveyId
= CRM_Utils_Request
::retrieve('sid', 'Positive', $this);
62 $this->_interviewerId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
64 //does control come from voting tab interface.
65 $this->_votingTab
= $this->get('votingTab');
66 $this->_subVotingTab
= $this->get('subVotingTab');
67 $this->_searchVoterFor
= 'gotv';
68 if ($this->_votingTab
) {
69 if ($this->_subVotingTab
== 'searchANDReserve') {
70 $this->_searchVoterFor
= 'reserve';
72 elseif ($this->_subVotingTab
== 'searchANDInterview') {
73 $this->_searchVoterFor
= 'interview';
76 $this->assign('force', $this->_force
);
77 $this->assign('votingTab', $this->_votingTab
);
78 $this->assign('searchParams', json_encode($this->get('searchParams')));
79 $this->assign('buildSelector', $this->_search
);
80 $this->assign('searchVoterFor', $this->_searchVoterFor
);
81 $this->set('searchVoterFor', $this->_searchVoterFor
);
84 if ($this->_surveyId
) {
85 $surveyTitle = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId
, 'title');
87 $this->assign('surveyTitle', $surveyTitle);
89 //append breadcrumb to survey dashboard.
90 if (CRM_Campaign_BAO_Campaign
::accessCampaign()) {
91 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
92 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
96 CRM_Utils_System
::setTitle(ts('GOTV (Voter Tracking)'));
106 function buildQuickForm() {
107 if ($this->_search
) {
111 //build common search form.
112 CRM_Campaign_BAO_Query
::buildSearchForm($this);
114 //build the array of all search params.
115 $this->_searchParams
= array();
116 foreach ($this->_elements
as $element) {
117 $name = $element->_attributes
['name'];
118 if ($name == 'qfKey') {
121 $this->_searchParams
[$name] = $name;
123 $this->set('searchParams', $this->_searchParams
);
124 $this->assign('searchParams', json_encode($this->_searchParams
));
128 if (!$this->_surveyId
) {
129 $this->_surveyId
= key(CRM_Campaign_BAO_Survey
::getSurveys(TRUE, TRUE));
132 if ($this->_force ||
$this->_votingTab
) {
133 $session = CRM_Core_Session
::singleton();
134 $userId = $session->get('userID');
135 // get interviewer id
136 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
137 CRM_Core_DAO
::$_nullObject, FALSE, $userId
140 $defaults['survey_interviewer_id'] = $cid;
142 if ($this->_surveyId
) {
143 $defaults['campaign_survey_id'] = $this->_surveyId
;
145 if (!empty($defaults)) {
146 $this->setDefaults($defaults);
149 //validate the required ids.
150 $this->validateIds();
153 function validateIds() {
154 $errorMessages = array();
155 //check for required permissions.
156 if (!CRM_Core_Permission
::check('manage campaign') &&
157 !CRM_Core_Permission
::check('administer CiviCampaign') &&
158 !CRM_Core_Permission
::check("{$this->_searchVoterFor} campaign contacts")
160 $errorMessages[] = ts('You are not authorized to access this page.');
163 $surveys = CRM_Campaign_BAO_Survey
::getSurveys();
164 if (empty($surveys)) {
165 $errorMessages[] = ts("Oops. It looks like no surveys have been created. <a href='%1'>Click here to create a new survey.</a>", array(1 => CRM_Utils_System
::url('civicrm/survey/add', 'reset=1&action=add')));
168 if ($this->_force
&& !$this->_surveyId
) {
170 $errorMessages[] = ts('Could not find Survey.');
174 $this->assign('errorMessages', empty($errorMessages) ?
FALSE : $errorMessages);