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 | * Page for displaying Campaigns | |
38 | */ | |
39 | class CRM_Campaign_Page_DashBoard extends CRM_Core_Page { | |
40 | ||
41 | /** | |
42 | * The action links that we need to display for the browse screen | |
43 | * | |
44 | * @var array | |
45 | */ | |
46 | private static $_campaignActionLinks; | |
47 | private static $_surveyActionLinks; | |
48 | private static $_petitionActionLinks; | |
49 | ||
50 | /** | |
51 | * Get the action links for this page. | |
52 | * | |
53 | * @return array $_campaignActionLinks | |
54 | * | |
55 | */ | |
56 | function &campaignActionLinks() { | |
57 | // check if variable _actionsLinks is populated | |
58 | if (!isset(self::$_campaignActionLinks)) { | |
59 | $deleteExtra = ts('Are you sure you want to delete this Campaign?'); | |
60 | self::$_campaignActionLinks = array( | |
61 | CRM_Core_Action::UPDATE => array( | |
62 | 'name' => ts('Edit'), | |
63 | 'url' => 'civicrm/campaign/add', | |
64 | 'qs' => 'reset=1&action=update&id=%%id%%', | |
65 | 'title' => ts('Update Campaign'), | |
66 | ), | |
67 | CRM_Core_Action::DISABLE => array( | |
68 | 'name' => ts('Disable'), | |
69 | 'title' => ts('Disable Campaign'), | |
70 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Campaign' . '\',\'' . 'enable-disable' . '\',\'' . NULL . '\',\'' . 'campaign_row' . '\' );"', | |
71 | 'ref' => 'disable-action', | |
72 | ), | |
73 | CRM_Core_Action::ENABLE => array( | |
74 | 'name' => ts('Enable'), | |
75 | 'title' => ts('Enable Campaign'), | |
76 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Campaign' . '\',\'' . 'disable-enable' . '\',\'' . NULL . '\',\'' . 'campaign_row' . '\' );"', | |
77 | 'ref' => 'enable-action', | |
78 | ), | |
79 | CRM_Core_Action::DELETE => array( | |
80 | 'name' => ts('Delete'), | |
81 | 'url' => 'civicrm/campaign/add', | |
82 | 'qs' => 'action=delete&reset=1&id=%%id%%', | |
83 | 'title' => ts('Delete Campaign'), | |
84 | ), | |
85 | ); | |
86 | } | |
87 | ||
88 | return self::$_campaignActionLinks; | |
89 | } | |
90 | ||
91 | function &surveyActionLinks() { | |
92 | // check if variable _actionsLinks is populated | |
93 | if (!isset(self::$_surveyActionLinks)) { | |
94 | self::$_surveyActionLinks = array( | |
95 | CRM_Core_Action::UPDATE => array( | |
96 | 'name' => ts('Edit'), | |
97 | 'url' => 'civicrm/survey/configure/main', | |
98 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
99 | 'title' => ts('Update Survey'), | |
100 | ), | |
101 | CRM_Core_Action::DISABLE => array( | |
102 | 'name' => ts('Disable'), | |
103 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Survey' . '\',\'' . 'enable-disable' . '\',\'' . NULL . '\',\'' . 'survey_row' . '\' );"', | |
104 | 'ref' => 'disable-action', | |
105 | 'title' => ts('Disable Survey'), | |
106 | ), | |
107 | CRM_Core_Action::ENABLE => array( | |
108 | 'name' => ts('Enable'), | |
109 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Survey' . '\',\'' . 'disable-enable' . '\',\'' . NULL . '\',\'' . 'survey_row' . '\' );"', | |
110 | 'ref' => 'enable-action', | |
111 | 'title' => ts('Enable Survey'), | |
112 | ), | |
113 | CRM_Core_Action::DELETE => array( | |
114 | 'name' => ts('Delete'), | |
115 | 'url' => 'civicrm/survey/delete', | |
116 | 'qs' => 'id=%%id%%&reset=1', | |
117 | 'title' => ts('Delete Survey'), | |
118 | ), | |
119 | ); | |
120 | } | |
121 | ||
122 | return self::$_surveyActionLinks; | |
123 | } | |
124 | ||
125 | function &petitionActionLinks() { | |
126 | if (!isset(self::$_petitionActionLinks)) { | |
127 | self::$_petitionActionLinks = self::surveyActionLinks(); | |
128 | self::$_petitionActionLinks[CRM_Core_Action::UPDATE] = array( | |
129 | 'name' => ts('Edit'), | |
130 | 'url' => 'civicrm/petition/add', | |
131 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
132 | 'title' => ts('Update Petition'), | |
133 | ); | |
134 | self::$_petitionActionLinks[CRM_Core_Action::DISABLE] = array( | |
135 | 'name' => ts('Disable'), | |
136 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Survey' . '\',\'' . 'enable-disable' . '\',\'' . NULL . '\',\'' . 'petition_row' . '\' );"', | |
137 | 'ref' => 'disable-action', | |
138 | 'title' => ts('Disable Petition'), | |
139 | ); | |
140 | self::$_petitionActionLinks[CRM_Core_Action::ENABLE] = array( | |
141 | 'name' => ts('Enable'), | |
142 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Survey' . '\',\'' . 'disable-enable' . '\',\'' . NULL . '\',\'' . 'petition_row' . '\' );"', | |
143 | 'ref' => 'enable-action', | |
144 | 'title' => ts('Enable Petition'), | |
145 | ); | |
146 | self::$_petitionActionLinks[CRM_Core_Action::DELETE] = array( | |
147 | 'name' => ts('Delete'), | |
148 | 'url' => 'civicrm/petition/add', | |
149 | 'qs' => 'action=delete&id=%%id%%&reset=1', | |
150 | 'title' => ts('Delete Petition'), | |
151 | ); | |
152 | self::$_petitionActionLinks[CRM_Core_Action::PROFILE] = array( | |
153 | 'name' => ts('Sign'), | |
154 | 'url' => 'civicrm/petition/sign', | |
155 | 'qs' => 'sid=%%id%%&reset=1', | |
156 | 'title' => ts('Sign Petition'), | |
157 | 'fe' => TRUE, | |
158 | //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign | |
159 | ); | |
160 | self::$_petitionActionLinks[CRM_Core_Action::BROWSE] = array( | |
161 | 'name' => ts('Signatures'), | |
162 | 'url' => 'civicrm/activity/search', | |
163 | 'qs' => 'survey=%%id%%&force=1', | |
164 | 'title' => ts('List the signatures'), | |
165 | //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign | |
166 | ); | |
167 | } | |
168 | ||
169 | return self::$_petitionActionLinks; | |
170 | } | |
171 | ||
172 | function browseCampaign() { | |
173 | // ensure valid javascript (these must have a value set) | |
174 | $this->assign('searchParams', json_encode(NULL)); | |
175 | $this->assign('campaignTypes', json_encode(NULL)); | |
176 | $this->assign('campaignStatus', json_encode(NULL)); | |
177 | ||
178 | $this->assign('addCampaignUrl', CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add')); | |
179 | $campaignCount = CRM_Campaign_BAO_Campaign::getCampaignCount(); | |
180 | //don't load find interface when no campaigns in db. | |
181 | if (!$campaignCount) { | |
182 | $this->assign('hasCampaigns', FALSE); | |
183 | return; | |
184 | } | |
185 | $this->assign('hasCampaigns', TRUE); | |
186 | ||
187 | //build the ajaxify campaign search and selector. | |
188 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Campaign', ts('Search Campaigns')); | |
189 | $controller->set('searchTab', 'campaign'); | |
190 | $controller->setEmbedded(TRUE); | |
191 | $controller->process(); | |
192 | return $controller->run(); | |
193 | } | |
194 | ||
195 | public static function getCampaignSummary($params = array( | |
196 | )) { | |
197 | $campaignsData = array(); | |
198 | ||
199 | //get the campaigns. | |
200 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaignSummary($params); | |
201 | if (!empty($campaigns)) { | |
202 | $config = CRM_Core_Config::singleton(); | |
203 | $campaignType = CRM_Campaign_PseudoConstant::campaignType(); | |
204 | $campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus(); | |
205 | $properties = array( | |
206 | 'id', 'name', 'title', 'status_id', 'description', | |
207 | 'campaign_type_id', 'is_active', 'start_date', 'end_date', | |
208 | ); | |
209 | foreach ($campaigns as $cmpid => $campaign) { | |
210 | foreach ($properties as $prop) { | |
211 | $campaignsData[$cmpid][$prop] = CRM_Utils_Array::value($prop, $campaign); | |
212 | } | |
213 | $statusId = CRM_Utils_Array::value('status_id', $campaign); | |
214 | $campaignsData[$cmpid]['status'] = CRM_Utils_Array::value($statusId, $campaignStatus); | |
215 | $campaignsData[$cmpid]['campaign_id'] = $campaign['id']; | |
216 | $campaignsData[$cmpid]['campaign_type'] = $campaignType[$campaign['campaign_type_id']]; | |
217 | ||
218 | $action = array_sum(array_keys(self::campaignActionLinks())); | |
219 | if ($campaign['is_active']) { | |
220 | $action -= CRM_Core_Action::ENABLE; | |
221 | } | |
222 | else { | |
223 | $action -= CRM_Core_Action::DISABLE; | |
224 | } | |
225 | ||
226 | $isActive = ts('No'); | |
227 | if ($campaignsData[$cmpid]['is_active']) { | |
228 | $isActive = ts('Yes'); | |
229 | } | |
230 | $campaignsData[$cmpid]['isActive'] = $isActive; | |
231 | ||
232 | if (CRM_Utils_Array::value('start_date', $campaignsData[$cmpid])) { | |
233 | $campaignsData[$cmpid]['start_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['start_date'], | |
234 | $config->dateformatFull | |
235 | ); | |
236 | } | |
237 | if (CRM_Utils_Array::value('end_date', $campaignsData[$cmpid])) { | |
238 | $campaignsData[$cmpid]['end_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['end_date'], | |
239 | $config->dateformatFull | |
240 | ); | |
241 | } | |
242 | $campaignsData[$cmpid]['action'] = CRM_Core_Action::formLink(self::campaignActionLinks(), | |
243 | $action, | |
244 | array('id' => $campaign['id']) | |
245 | ); | |
246 | } | |
247 | } | |
248 | ||
249 | return $campaignsData; | |
250 | } | |
251 | ||
252 | function browseSurvey() { | |
253 | // ensure valid javascript - this must have a value set | |
254 | $this->assign('searchParams', json_encode(NULL)); | |
255 | $this->assign('surveyTypes', json_encode(NULL)); | |
256 | $this->assign('surveyCampaigns', json_encode(NULL)); | |
257 | ||
258 | $this->assign('addSurveyUrl', CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); | |
259 | ||
260 | $surveyCount = CRM_Campaign_BAO_Survey::getSurveyCount(); | |
261 | //don't load find interface when no survey in db. | |
262 | if (!$surveyCount) { | |
263 | $this->assign('hasSurveys', FALSE); | |
264 | return; | |
265 | } | |
266 | $this->assign('hasSurveys', TRUE); | |
267 | ||
268 | //build the ajaxify survey search and selector. | |
269 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Survey', ts('Search Survey')); | |
270 | $controller->set('searchTab', 'survey'); | |
271 | $controller->setEmbedded(TRUE); | |
272 | $controller->process(); | |
273 | return $controller->run(); | |
274 | } | |
275 | ||
276 | function getSurveySummary($params = array( | |
277 | )) { | |
278 | $surveysData = array(); | |
279 | ||
280 | //get the survey. | |
281 | $config = CRM_Core_Config::singleton(); | |
282 | $surveys = CRM_Campaign_BAO_Survey::getSurveySummary($params); | |
283 | if (!empty($surveys)) { | |
284 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
285 | $surveyType = CRM_Campaign_BAO_Survey::getSurveyActivityType(); | |
286 | foreach ($surveys as $sid => $survey) { | |
287 | $surveysData[$sid] = $survey; | |
288 | $campaignId = CRM_Utils_Array::value('campaign_id', $survey); | |
289 | $surveysData[$sid]['campaign'] = CRM_Utils_Array::value($campaignId, $campaigns); | |
290 | $surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']]; | |
291 | if (CRM_Utils_Array::value('release_frequency', $survey)) { | |
292 | $surveysData[$sid]['release_frequency'] = $survey['release_frequency'] . ' Day(s)'; | |
293 | } | |
294 | ||
295 | $action = array_sum(array_keys(self::surveyActionLinks($surveysData[$sid]['activity_type']))); | |
296 | if ($survey['is_active']) { | |
297 | $action -= CRM_Core_Action::ENABLE; | |
298 | } | |
299 | else { | |
300 | $action -= CRM_Core_Action::DISABLE; | |
301 | } | |
302 | ||
303 | $isActive = ts('No'); | |
304 | if ($surveysData[$sid]['is_active']) { | |
305 | $isActive = ts('Yes'); | |
306 | } | |
307 | $surveysData[$sid]['isActive'] = $isActive; | |
308 | ||
309 | $isDefault = NULL; | |
310 | if ($surveysData[$sid]['is_default']) { | |
311 | $isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />'; | |
312 | } | |
313 | $surveysData[$sid]['is_default'] = $isDefault; | |
314 | ||
315 | if ($surveysData[$sid]['result_id']) { | |
316 | $resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set').'">' . ts('Result Set') . '</a>'; | |
317 | $surveysData[$sid]['result_id'] = $resultSet; | |
318 | } else { | |
319 | $resultUrl = CRM_Utils_System::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1"); | |
320 | $surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>'; | |
321 | } | |
322 | $surveysData[$sid]['action'] = CRM_Core_Action::formLink(self::surveyActionLinks($surveysData[$sid]['activity_type']), | |
323 | $action, | |
324 | array('id' => $sid) | |
325 | ); | |
326 | ||
327 | if (CRM_Utils_Array::value('activity_type', $surveysData[$sid]) != 'Petition') { | |
328 | $surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey::buildPermissionLinks($sid, | |
329 | TRUE, | |
330 | ts('more') | |
331 | ); | |
332 | } | |
333 | ||
334 | if ($reportID = CRM_Campaign_BAO_Survey::getReportID($sid)) { | |
335 | $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}",'reset=1'); | |
336 | $surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>"; | |
337 | } | |
338 | } | |
339 | } | |
340 | ||
341 | return $surveysData; | |
342 | } | |
343 | ||
344 | function browsePetition() { | |
345 | // ensure valid javascript - this must have a value set | |
346 | $this->assign('searchParams', json_encode(NULL)); | |
347 | $this->assign('petitionCampaigns', json_encode(NULL)); | |
348 | ||
349 | $this->assign('addPetitionUrl', CRM_Utils_System::url('civicrm/petition/add', 'reset=1&action=add')); | |
350 | ||
351 | $petitionCount = CRM_Campaign_BAO_Petition::getPetitionCount(); | |
352 | //don't load find interface when no petition in db. | |
353 | if (!$petitionCount) { | |
354 | $this->assign('hasPetitions', FALSE); | |
355 | return; | |
356 | } | |
357 | $this->assign('hasPetitions', TRUE); | |
358 | ||
359 | //build the ajaxify petition search and selector. | |
360 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Petition', ts('Search Petition')); | |
361 | $controller->set('searchTab', 'petition'); | |
362 | $controller->setEmbedded(TRUE); | |
363 | $controller->process(); | |
364 | return $controller->run(); | |
365 | } | |
366 | ||
367 | function getPetitionSummary($params = array( | |
368 | )) { | |
369 | $config = CRM_Core_Config::singleton(); | |
370 | $petitionsData = array(); | |
371 | ||
372 | //get the petitions. | |
373 | $petitions = CRM_Campaign_BAO_Petition::getPetitionSummary($params); | |
374 | if (!empty($petitions)) { | |
375 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
376 | $petitionType = CRM_Campaign_BAO_Survey::getSurveyActivityType('label', TRUE); | |
377 | foreach ($petitions as $pid => $petition) { | |
378 | $petitionsData[$pid] = $petition; | |
379 | $camapignId = CRM_Utils_Array::value('campaign_id', $petition); | |
380 | $petitionsData[$pid]['campaign'] = CRM_Utils_Array::value($camapignId, $campaigns); | |
381 | $petitionsData[$pid]['activity_type'] = $petitionType[$petition['activity_type_id']]; | |
382 | ||
383 | $action = array_sum(array_keys(self::petitionActionLinks())); | |
384 | ||
385 | if ($petition['is_active']) { | |
386 | $action -= CRM_Core_Action::ENABLE; | |
387 | } | |
388 | else { | |
389 | $action -= CRM_Core_Action::DISABLE; | |
390 | } | |
391 | ||
392 | $isActive = ts('No'); | |
393 | if ($petitionsData[$pid]['is_active']) { | |
394 | $isActive = ts('Yes'); | |
395 | } | |
396 | $petitionsData[$pid]['isActive'] = $isActive; | |
397 | $isDefault = NULL; | |
398 | if ($petitionsData[$pid]['is_default']) { | |
399 | $isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />'; | |
400 | } | |
401 | $petitionsData[$pid]['is_default'] = $isDefault; | |
402 | ||
403 | $petitionsData[$pid]['action'] = CRM_Core_Action::formLink(self::petitionActionLinks(), | |
404 | $action, | |
405 | array('id' => $pid) | |
406 | ); | |
407 | } | |
408 | } | |
409 | ||
410 | return $petitionsData; | |
411 | } | |
412 | ||
413 | function browse() { | |
414 | $this->_tabs = array('campaign' => ts('Campaigns'), | |
415 | 'survey' => ts('Surveys'), | |
416 | 'petition' => ts('Petitions'), | |
417 | ); | |
418 | ||
419 | $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this); | |
420 | if ($subPageType) { | |
421 | //load the data in tabs. | |
422 | $this->{'browse' . ucfirst($subPageType)}(); | |
423 | } | |
424 | else { | |
425 | //build the tabs. | |
426 | $this->buildTabs(); | |
427 | } | |
428 | $this->assign('subPageType', $subPageType); | |
429 | ||
430 | //give focus to proper tab. | |
431 | $selectedTabIndex = array_search(strtolower(CRM_Utils_Array::value('subPage', $_GET, 'campaign')), | |
432 | array_keys($this->_tabs) | |
433 | ); | |
434 | if (!$selectedTabIndex) { | |
435 | $selectedTabIndex = array_search('campaign', array_keys($this->_tabs)); | |
436 | } | |
437 | $this->assign('selectedTabIndex', $selectedTabIndex); | |
438 | } | |
439 | ||
440 | function run() { | |
441 | if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
442 | CRM_Utils_System::permissionDenied(); | |
443 | } | |
444 | ||
445 | $this->browse(); | |
446 | ||
447 | return parent::run(); | |
448 | } | |
449 | ||
450 | function buildTabs() { | |
451 | $allTabs = array(); | |
452 | foreach ($this->_tabs as $name => $title) { | |
453 | $allTabs[] = array( | |
454 | 'id' => $name, | |
455 | 'title' => $title, | |
456 | 'url' => CRM_Utils_System::url('civicrm/campaign', "reset=1&type=$name&snippet=1"), | |
457 | ); | |
458 | } | |
459 | ||
460 | $this->assign('allTabs', $allTabs); | |
461 | } | |
462 | } | |
463 |