Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Files required | |
38 | */ | |
39 | class CRM_Campaign_Form_Gotv extends CRM_Core_Form { | |
40 | ||
41 | /** | |
42 | * Are we forced to run a search | |
43 | * | |
44 | * @var int | |
45 | * @access protected | |
46 | */ | |
47 | protected $_force; | |
48 | ||
49 | protected $_votingTab = FALSE; | |
50 | ||
51 | protected $_searchVoterFor; | |
52 | ||
53 | /** | |
54 | * processing needed for buildForm and later | |
55 | * | |
56 | * @return void | |
57 | * @access public | |
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); | |
63 | ||
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'; | |
71 | } | |
72 | elseif ($this->_subVotingTab == 'searchANDInterview') { | |
73 | $this->_searchVoterFor = 'interview'; | |
74 | } | |
75 | } | |
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); | |
82 | ||
83 | $surveyTitle = NULL; | |
84 | if ($this->_surveyId) { | |
85 | $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'title'); | |
86 | } | |
87 | $this->assign('surveyTitle', $surveyTitle); | |
88 | ||
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))); | |
93 | } | |
94 | ||
95 | //set the form title. | |
96 | CRM_Utils_System::setTitle(ts('GOTV (Voter Tracking)')); | |
97 | } | |
98 | ||
99 | /** | |
100 | * Build the form | |
101 | * | |
102 | * @access public | |
103 | * | |
104 | * @return void | |
105 | */ | |
106 | function buildQuickForm() { | |
107 | if ($this->_search) { | |
108 | return; | |
109 | } | |
110 | ||
111 | //build common search form. | |
112 | CRM_Campaign_BAO_Query::buildSearchForm($this); | |
113 | ||
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') { | |
119 | continue; | |
120 | } | |
121 | $this->_searchParams[$name] = $name; | |
122 | } | |
123 | $this->set('searchParams', $this->_searchParams); | |
124 | $this->assign('searchParams', json_encode($this->_searchParams)); | |
125 | ||
126 | $defaults = array(); | |
127 | ||
128 | if (!$this->_surveyId) { | |
129 | $this->_surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE)); | |
130 | } | |
131 | ||
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 | |
138 | ); | |
139 | ||
140 | $defaults['survey_interviewer_id'] = $cid; | |
141 | $defaults['survey_interviewer_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', | |
142 | $cid, | |
143 | 'sort_name', | |
144 | 'id' | |
145 | ); | |
146 | } | |
147 | if ($this->_surveyId) { | |
148 | $defaults['campaign_survey_id'] = $this->_surveyId; | |
149 | } | |
150 | if (!empty($defaults)) { | |
151 | $this->setDefaults($defaults); | |
152 | } | |
153 | ||
154 | //validate the required ids. | |
155 | $this->validateIds(); | |
156 | } | |
157 | ||
158 | function validateIds() { | |
159 | $errorMessages = array(); | |
160 | //check for required permissions. | |
161 | if (!CRM_Core_Permission::check('manage campaign') && | |
162 | !CRM_Core_Permission::check('administer CiviCampaign') && | |
163 | !CRM_Core_Permission::check("{$this->_searchVoterFor} campaign contacts") | |
164 | ) { | |
165 | $errorMessages[] = ts('You are not authorized to access this page.'); | |
166 | } | |
167 | ||
168 | $surveys = CRM_Campaign_BAO_Survey::getSurveys(); | |
169 | if (empty($surveys)) { | |
170 | $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'))); | |
171 | } | |
172 | ||
173 | if ($this->_force && !$this->_surveyId) { | |
174 | ||
175 | $errorMessages[] = ts('Could not find Survey.'); | |
176 | ||
177 | } | |
178 | ||
179 | $this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages); | |
180 | } | |
181 | } | |
182 |