3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 --------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * Page for displaying Campaigns
39 class CRM_Campaign_Page_DashBoard
extends CRM_Core_Page
{
42 * The action links that we need to display for the browse screen
46 private static $_campaignActionLinks;
47 private static $_surveyActionLinks;
48 private static $_petitionActionLinks;
51 * Get the action links for this page.
53 * @return array $_campaignActionLinks
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(
63 'url' => 'civicrm/campaign/add',
64 'qs' => 'reset=1&action=update&id=%%id%%',
65 'title' => ts('Update Campaign'),
67 CRM_Core_Action
::DISABLE
=> array(
68 'name' => ts('Disable'),
69 'title' => ts('Disable Campaign'),
70 'ref' => 'crm-enable-disable',
72 CRM_Core_Action
::ENABLE
=> array(
73 'name' => ts('Enable'),
74 'title' => ts('Enable Campaign'),
75 'ref' => 'crm-enable-disable',
77 CRM_Core_Action
::DELETE
=> array(
78 'name' => ts('Delete'),
79 'url' => 'civicrm/campaign/add',
80 'qs' => 'action=delete&reset=1&id=%%id%%',
81 'title' => ts('Delete Campaign'),
86 return self
::$_campaignActionLinks;
89 function &surveyActionLinks() {
90 // check if variable _actionsLinks is populated
91 if (!isset(self
::$_surveyActionLinks)) {
92 self
::$_surveyActionLinks = array(
93 CRM_Core_Action
::UPDATE
=> array(
95 'url' => 'civicrm/survey/configure/main',
96 'qs' => 'action=update&id=%%id%%&reset=1',
97 'title' => ts('Update Survey'),
99 CRM_Core_Action
::DISABLE
=> array(
100 'name' => ts('Disable'),
101 'ref' => 'crm-enable-disable',
102 'title' => ts('Disable Survey'),
104 CRM_Core_Action
::ENABLE
=> array(
105 'name' => ts('Enable'),
106 'ref' => 'crm-enable-disable',
107 'title' => ts('Enable Survey'),
109 CRM_Core_Action
::DELETE
=> array(
110 'name' => ts('Delete'),
111 'url' => 'civicrm/survey/delete',
112 'qs' => 'id=%%id%%&reset=1',
113 'title' => ts('Delete Survey'),
118 return self
::$_surveyActionLinks;
121 function &petitionActionLinks() {
122 if (!isset(self
::$_petitionActionLinks)) {
123 self
::$_petitionActionLinks = self
::surveyActionLinks();
124 self
::$_petitionActionLinks[CRM_Core_Action
::UPDATE
] = array(
125 'name' => ts('Edit'),
126 'url' => 'civicrm/petition/add',
127 'qs' => 'action=update&id=%%id%%&reset=1',
128 'title' => ts('Update Petition'),
130 self
::$_petitionActionLinks[CRM_Core_Action
::DISABLE
] = array(
131 'name' => ts('Disable'),
132 'ref' => 'crm-enable-disable',
133 'title' => ts('Disable Petition'),
135 self
::$_petitionActionLinks[CRM_Core_Action
::ENABLE
] = array(
136 'name' => ts('Enable'),
137 'ref' => 'crm-enable-disable',
138 'title' => ts('Enable Petition'),
140 self
::$_petitionActionLinks[CRM_Core_Action
::DELETE
] = array(
141 'name' => ts('Delete'),
142 'url' => 'civicrm/petition/add',
143 'qs' => 'action=delete&id=%%id%%&reset=1',
144 'title' => ts('Delete Petition'),
146 self
::$_petitionActionLinks[CRM_Core_Action
::PROFILE
] = array(
147 'name' => ts('Sign'),
148 'url' => 'civicrm/petition/sign',
149 'qs' => 'sid=%%id%%&reset=1',
150 'title' => ts('Sign Petition'),
152 //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
154 self
::$_petitionActionLinks[CRM_Core_Action
::BROWSE
] = array(
155 'name' => ts('Signatures'),
156 'url' => 'civicrm/activity/search',
157 'qs' => 'survey=%%id%%&force=1',
158 'title' => ts('List the signatures'),
159 //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
163 return self
::$_petitionActionLinks;
166 function browseCampaign() {
167 // ensure valid javascript (these must have a value set)
168 $this->assign('searchParams', json_encode(NULL));
169 $this->assign('campaignTypes', json_encode(NULL));
170 $this->assign('campaignStatus', json_encode(NULL));
172 $this->assign('addCampaignUrl', CRM_Utils_System
::url('civicrm/campaign/add', 'reset=1&action=add'));
173 $campaignCount = CRM_Campaign_BAO_Campaign
::getCampaignCount();
174 //don't load find interface when no campaigns in db.
175 if (!$campaignCount) {
176 $this->assign('hasCampaigns', FALSE);
179 $this->assign('hasCampaigns', TRUE);
181 //build the ajaxify campaign search and selector.
182 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Campaign', ts('Search Campaigns'));
183 $controller->set('searchTab', 'campaign');
184 $controller->setEmbedded(TRUE);
185 $controller->process();
186 return $controller->run();
189 public static function getCampaignSummary($params = array(
191 $campaignsData = array();
194 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaignSummary($params);
195 if (!empty($campaigns)) {
196 $config = CRM_Core_Config
::singleton();
197 $campaignType = CRM_Campaign_PseudoConstant
::campaignType();
198 $campaignStatus = CRM_Campaign_PseudoConstant
::campaignStatus();
200 'id', 'name', 'title', 'status_id', 'description',
201 'campaign_type_id', 'is_active', 'start_date', 'end_date',
203 foreach ($campaigns as $cmpid => $campaign) {
204 foreach ($properties as $prop) {
205 $campaignsData[$cmpid][$prop] = CRM_Utils_Array
::value($prop, $campaign);
207 $statusId = CRM_Utils_Array
::value('status_id', $campaign);
208 $campaignsData[$cmpid]['status'] = CRM_Utils_Array
::value($statusId, $campaignStatus);
209 $campaignsData[$cmpid]['campaign_id'] = $campaign['id'];
210 $campaignsData[$cmpid]['campaign_type'] = $campaignType[$campaign['campaign_type_id']];
212 $action = array_sum(array_keys(self
::campaignActionLinks()));
213 if ($campaign['is_active']) {
214 $action -= CRM_Core_Action
::ENABLE
;
217 $action -= CRM_Core_Action
::DISABLE
;
220 $isActive = ts('No');
221 if ($campaignsData[$cmpid]['is_active']) {
222 $isActive = ts('Yes');
224 $campaignsData[$cmpid]['isActive'] = $isActive;
226 if (!empty($campaignsData[$cmpid]['start_date'])) {
227 $campaignsData[$cmpid]['start_date'] = CRM_Utils_Date
::customFormat($campaignsData[$cmpid]['start_date'],
228 $config->dateformatFull
231 if (!empty($campaignsData[$cmpid]['end_date'])) {
232 $campaignsData[$cmpid]['end_date'] = CRM_Utils_Date
::customFormat($campaignsData[$cmpid]['end_date'],
233 $config->dateformatFull
236 $campaignsData[$cmpid]['action'] = CRM_Core_Action
::formLink(self
::campaignActionLinks(),
238 array('id' => $campaign['id']),
241 'campaign.dashboard.row',
248 return $campaignsData;
251 function browseSurvey() {
252 // ensure valid javascript - this must have a value set
253 $this->assign('searchParams', json_encode(NULL));
254 $this->assign('surveyTypes', json_encode(NULL));
255 $this->assign('surveyCampaigns', json_encode(NULL));
257 $this->assign('addSurveyUrl', CRM_Utils_System
::url('civicrm/survey/add', 'reset=1&action=add'));
259 $surveyCount = CRM_Campaign_BAO_Survey
::getSurveyCount();
260 //don't load find interface when no survey in db.
262 $this->assign('hasSurveys', FALSE);
265 $this->assign('hasSurveys', TRUE);
267 //build the ajaxify survey search and selector.
268 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Survey', ts('Search Survey'));
269 $controller->set('searchTab', 'survey');
270 $controller->setEmbedded(TRUE);
271 $controller->process();
272 return $controller->run();
275 function getSurveySummary($params = array(
277 $surveysData = array();
280 $config = CRM_Core_Config
::singleton();
281 $surveys = CRM_Campaign_BAO_Survey
::getSurveySummary($params);
282 if (!empty($surveys)) {
283 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
284 $surveyType = CRM_Campaign_BAO_Survey
::getSurveyActivityType();
285 foreach ($surveys as $sid => $survey) {
286 $surveysData[$sid] = $survey;
287 $campaignId = CRM_Utils_Array
::value('campaign_id', $survey);
288 $surveysData[$sid]['campaign'] = CRM_Utils_Array
::value($campaignId, $campaigns);
289 $surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']];
290 if (!empty($survey['release_frequency'])) {
291 $surveysData[$sid]['release_frequency'] = $survey['release_frequency'] . ' Day(s)';
294 $action = array_sum(array_keys(self
::surveyActionLinks($surveysData[$sid]['activity_type'])));
295 if ($survey['is_active']) {
296 $action -= CRM_Core_Action
::ENABLE
;
299 $action -= CRM_Core_Action
::DISABLE
;
302 $isActive = ts('No');
303 if ($surveysData[$sid]['is_active']) {
304 $isActive = ts('Yes');
306 $surveysData[$sid]['isActive'] = $isActive;
309 if ($surveysData[$sid]['is_default']) {
310 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
312 $surveysData[$sid]['is_default'] = $isDefault;
314 if ($surveysData[$sid]['result_id']) {
315 $resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set').'">' . ts('Result Set') . '</a>';
316 $surveysData[$sid]['result_id'] = $resultSet;
318 $resultUrl = CRM_Utils_System
::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1");
319 $surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>';
321 $surveysData[$sid]['action'] = CRM_Core_Action
::formLink(self
::surveyActionLinks($surveysData[$sid]['activity_type']),
326 'survey.dashboard.row',
331 if (CRM_Utils_Array
::value('activity_type', $surveysData[$sid]) != 'Petition') {
332 $surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey
::buildPermissionLinks($sid,
338 if ($reportID = CRM_Campaign_BAO_Survey
::getReportID($sid)) {
339 $url = CRM_Utils_System
::url("civicrm/report/instance/{$reportID}",'reset=1');
340 $surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>";
348 function browsePetition() {
349 // ensure valid javascript - this must have a value set
350 $this->assign('searchParams', json_encode(NULL));
351 $this->assign('petitionCampaigns', json_encode(NULL));
353 $this->assign('addPetitionUrl', CRM_Utils_System
::url('civicrm/petition/add', 'reset=1&action=add'));
355 $petitionCount = CRM_Campaign_BAO_Petition
::getPetitionCount();
356 //don't load find interface when no petition in db.
357 if (!$petitionCount) {
358 $this->assign('hasPetitions', FALSE);
361 $this->assign('hasPetitions', TRUE);
363 //build the ajaxify petition search and selector.
364 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Petition', ts('Search Petition'));
365 $controller->set('searchTab', 'petition');
366 $controller->setEmbedded(TRUE);
367 $controller->process();
368 return $controller->run();
371 function getPetitionSummary($params = array(
373 $config = CRM_Core_Config
::singleton();
374 $petitionsData = array();
377 $petitions = CRM_Campaign_BAO_Petition
::getPetitionSummary($params);
378 if (!empty($petitions)) {
379 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
380 $petitionType = CRM_Campaign_BAO_Survey
::getSurveyActivityType('label', TRUE);
381 foreach ($petitions as $pid => $petition) {
382 $petitionsData[$pid] = $petition;
383 $camapignId = CRM_Utils_Array
::value('campaign_id', $petition);
384 $petitionsData[$pid]['campaign'] = CRM_Utils_Array
::value($camapignId, $campaigns);
385 $petitionsData[$pid]['activity_type'] = $petitionType[$petition['activity_type_id']];
387 $action = array_sum(array_keys(self
::petitionActionLinks()));
389 if ($petition['is_active']) {
390 $action -= CRM_Core_Action
::ENABLE
;
393 $action -= CRM_Core_Action
::DISABLE
;
396 $isActive = ts('No');
397 if ($petitionsData[$pid]['is_active']) {
398 $isActive = ts('Yes');
400 $petitionsData[$pid]['isActive'] = $isActive;
402 if ($petitionsData[$pid]['is_default']) {
403 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
405 $petitionsData[$pid]['is_default'] = $isDefault;
407 $petitionsData[$pid]['action'] = CRM_Core_Action
::formLink(self
::petitionActionLinks(),
412 'petition.dashboard.row',
419 return $petitionsData;
423 $this->_tabs
= array(
424 'campaign' => ts('Campaigns'),
425 'survey' => ts('Surveys'),
426 'petition' => ts('Petitions'),
429 $subPageType = CRM_Utils_Request
::retrieve('type', 'String', $this);
431 if (!isset($this->_tabs
[$subPageType])) {
432 CRM_Utils_System
::permissionDenied();
434 //load the data in tabs.
435 $this->{'browse' . ucfirst($subPageType)}();
436 $this->assign('subPageType', ucfirst($subPageType));
442 CRM_Core_Resources
::singleton()
443 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js')
444 ->addSetting(array('tabSettings' => array(
445 'active' => strtolower(CRM_Utils_Array
::value('subPage', $_GET, 'campaign')),
450 if (!CRM_Campaign_BAO_Campaign
::accessCampaign()) {
451 CRM_Utils_System
::permissionDenied();
456 return parent
::run();
459 function buildTabs() {
461 foreach ($this->_tabs
as $name => $title) {
462 $allTabs[$name] = array(
466 'link' => CRM_Utils_System
::url('civicrm/campaign', "reset=1&type=$name"),
469 $this->assign('tabHeader', $allTabs);