Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 | 32 | * $Id$ |
6a488035 TO |
33 | */ |
34 | ||
35 | /** | |
36 | * Files required | |
37 | */ | |
38 | class CRM_Campaign_Form_Gotv extends CRM_Core_Form { | |
39 | ||
40 | /** | |
41 | * Are we forced to run a search | |
42 | * | |
43 | * @var int | |
6a488035 TO |
44 | */ |
45 | protected $_force; | |
46 | ||
47 | protected $_votingTab = FALSE; | |
48 | ||
49 | protected $_searchVoterFor; | |
50 | ||
51 | /** | |
db7de9c1 | 52 | * Processing needed for buildForm and later. |
95ea96be | 53 | */ |
db7de9c1 | 54 | public function preProcess() { |
6a488035 TO |
55 | $this->_search = CRM_Utils_Array::value('search', $_GET); |
56 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); | |
57 | $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this); | |
58 | $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
59 | ||
60 | //does control come from voting tab interface. | |
61 | $this->_votingTab = $this->get('votingTab'); | |
62 | $this->_subVotingTab = $this->get('subVotingTab'); | |
63 | $this->_searchVoterFor = 'gotv'; | |
64 | if ($this->_votingTab) { | |
65 | if ($this->_subVotingTab == 'searchANDReserve') { | |
66 | $this->_searchVoterFor = 'reserve'; | |
67 | } | |
68 | elseif ($this->_subVotingTab == 'searchANDInterview') { | |
69 | $this->_searchVoterFor = 'interview'; | |
70 | } | |
71 | } | |
72 | $this->assign('force', $this->_force); | |
73 | $this->assign('votingTab', $this->_votingTab); | |
74 | $this->assign('searchParams', json_encode($this->get('searchParams'))); | |
75 | $this->assign('buildSelector', $this->_search); | |
76 | $this->assign('searchVoterFor', $this->_searchVoterFor); | |
77 | $this->set('searchVoterFor', $this->_searchVoterFor); | |
78 | ||
79 | $surveyTitle = NULL; | |
80 | if ($this->_surveyId) { | |
81 | $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'title'); | |
82 | } | |
83 | $this->assign('surveyTitle', $surveyTitle); | |
84 | ||
85 | //append breadcrumb to survey dashboard. | |
86 | if (CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
87 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
88 | CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); | |
89 | } | |
90 | ||
91 | //set the form title. | |
92 | CRM_Utils_System::setTitle(ts('GOTV (Voter Tracking)')); | |
93 | } | |
94 | ||
95 | /** | |
c490a46a | 96 | * Build the form object |
6a488035 | 97 | * |
6a488035 TO |
98 | * |
99 | * @return void | |
100 | */ | |
00be9182 | 101 | public function buildQuickForm() { |
6a488035 TO |
102 | if ($this->_search) { |
103 | return; | |
104 | } | |
105 | ||
106 | //build common search form. | |
107 | CRM_Campaign_BAO_Query::buildSearchForm($this); | |
108 | ||
109 | //build the array of all search params. | |
110 | $this->_searchParams = array(); | |
111 | foreach ($this->_elements as $element) { | |
112 | $name = $element->_attributes['name']; | |
113 | if ($name == 'qfKey') { | |
114 | continue; | |
115 | } | |
116 | $this->_searchParams[$name] = $name; | |
117 | } | |
118 | $this->set('searchParams', $this->_searchParams); | |
119 | $this->assign('searchParams', json_encode($this->_searchParams)); | |
120 | ||
121 | $defaults = array(); | |
122 | ||
123 | if (!$this->_surveyId) { | |
124 | $this->_surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE)); | |
125 | } | |
126 | ||
127 | if ($this->_force || $this->_votingTab) { | |
128 | $session = CRM_Core_Session::singleton(); | |
129 | $userId = $session->get('userID'); | |
130 | // get interviewer id | |
131 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', | |
132 | CRM_Core_DAO::$_nullObject, FALSE, $userId | |
133 | ); | |
134 | ||
135 | $defaults['survey_interviewer_id'] = $cid; | |
6a488035 TO |
136 | } |
137 | if ($this->_surveyId) { | |
138 | $defaults['campaign_survey_id'] = $this->_surveyId; | |
139 | } | |
140 | if (!empty($defaults)) { | |
141 | $this->setDefaults($defaults); | |
142 | } | |
143 | ||
144 | //validate the required ids. | |
145 | $this->validateIds(); | |
146 | } | |
147 | ||
00be9182 | 148 | public function validateIds() { |
6a488035 TO |
149 | $errorMessages = array(); |
150 | //check for required permissions. | |
151 | if (!CRM_Core_Permission::check('manage campaign') && | |
152 | !CRM_Core_Permission::check('administer CiviCampaign') && | |
153 | !CRM_Core_Permission::check("{$this->_searchVoterFor} campaign contacts") | |
154 | ) { | |
155 | $errorMessages[] = ts('You are not authorized to access this page.'); | |
156 | } | |
157 | ||
158 | $surveys = CRM_Campaign_BAO_Survey::getSurveys(); | |
159 | if (empty($surveys)) { | |
160 | $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'))); | |
161 | } | |
162 | ||
163 | if ($this->_force && !$this->_surveyId) { | |
164 | ||
165 | $errorMessages[] = ts('Could not find Survey.'); | |
166 | ||
167 | } | |
168 | ||
169 | $this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages); | |
170 | } | |
171 | } |