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 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Campaign' . '\',\'' . 'enable-disable' . '\',\'' . NULL . '\',\'' . 'campaign_row' . '\' );"',
71 'ref' => 'disable-action',
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',
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'),
88 return self
::$_campaignActionLinks;
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(
97 'url' => 'civicrm/survey/configure/main',
98 'qs' => 'action=update&id=%%id%%&reset=1',
99 'title' => ts('Update Survey'),
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'),
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'),
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'),
122 return self
::$_surveyActionLinks;
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'),
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'),
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'),
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'),
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'),
158 //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
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
169 return self
::$_petitionActionLinks;
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));
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);
185 $this->assign('hasCampaigns', TRUE);
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();
195 public static function getCampaignSummary($params = array(
197 $campaignsData = array();
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();
206 'id', 'name', 'title', 'status_id', 'description',
207 'campaign_type_id', 'is_active', 'start_date', 'end_date',
209 foreach ($campaigns as $cmpid => $campaign) {
210 foreach ($properties as $prop) {
211 $campaignsData[$cmpid][$prop] = CRM_Utils_Array
::value($prop, $campaign);
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']];
218 $action = array_sum(array_keys(self
::campaignActionLinks()));
219 if ($campaign['is_active']) {
220 $action -= CRM_Core_Action
::ENABLE
;
223 $action -= CRM_Core_Action
::DISABLE
;
226 $isActive = ts('No');
227 if ($campaignsData[$cmpid]['is_active']) {
228 $isActive = ts('Yes');
230 $campaignsData[$cmpid]['isActive'] = $isActive;
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
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
242 $campaignsData[$cmpid]['action'] = CRM_Core_Action
::formLink(self
::campaignActionLinks(),
244 array('id' => $campaign['id'])
249 return $campaignsData;
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));
258 $this->assign('addSurveyUrl', CRM_Utils_System
::url('civicrm/survey/add', 'reset=1&action=add'));
260 $surveyCount = CRM_Campaign_BAO_Survey
::getSurveyCount();
261 //don't load find interface when no survey in db.
263 $this->assign('hasSurveys', FALSE);
266 $this->assign('hasSurveys', TRUE);
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();
276 function getSurveySummary($params = array(
278 $surveysData = array();
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)';
295 $action = array_sum(array_keys(self
::surveyActionLinks($surveysData[$sid]['activity_type'])));
296 if ($survey['is_active']) {
297 $action -= CRM_Core_Action
::ENABLE
;
300 $action -= CRM_Core_Action
::DISABLE
;
303 $isActive = ts('No');
304 if ($surveysData[$sid]['is_active']) {
305 $isActive = ts('Yes');
307 $surveysData[$sid]['isActive'] = $isActive;
310 if ($surveysData[$sid]['is_default']) {
311 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
313 $surveysData[$sid]['is_default'] = $isDefault;
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;
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>';
322 $surveysData[$sid]['action'] = CRM_Core_Action
::formLink(self
::surveyActionLinks($surveysData[$sid]['activity_type']),
327 if (CRM_Utils_Array
::value('activity_type', $surveysData[$sid]) != 'Petition') {
328 $surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey
::buildPermissionLinks($sid,
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>";
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));
349 $this->assign('addPetitionUrl', CRM_Utils_System
::url('civicrm/petition/add', 'reset=1&action=add'));
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);
357 $this->assign('hasPetitions', TRUE);
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();
367 function getPetitionSummary($params = array(
369 $config = CRM_Core_Config
::singleton();
370 $petitionsData = array();
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']];
383 $action = array_sum(array_keys(self
::petitionActionLinks()));
385 if ($petition['is_active']) {
386 $action -= CRM_Core_Action
::ENABLE
;
389 $action -= CRM_Core_Action
::DISABLE
;
392 $isActive = ts('No');
393 if ($petitionsData[$pid]['is_active']) {
394 $isActive = ts('Yes');
396 $petitionsData[$pid]['isActive'] = $isActive;
398 if ($petitionsData[$pid]['is_default']) {
399 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
401 $petitionsData[$pid]['is_default'] = $isDefault;
403 $petitionsData[$pid]['action'] = CRM_Core_Action
::formLink(self
::petitionActionLinks(),
410 return $petitionsData;
414 $this->_tabs
= array('campaign' => ts('Campaigns'),
415 'survey' => ts('Surveys'),
416 'petition' => ts('Petitions'),
419 $subPageType = CRM_Utils_Request
::retrieve('type', 'String', $this);
421 //load the data in tabs.
422 $this->{'browse' . ucfirst($subPageType)}();
428 $this->assign('subPageType', $subPageType);
430 //give focus to proper tab.
431 $selectedTabIndex = array_search(strtolower(CRM_Utils_Array
::value('subPage', $_GET, 'campaign')),
432 array_keys($this->_tabs
)
434 if (!$selectedTabIndex) {
435 $selectedTabIndex = array_search('campaign', array_keys($this->_tabs
));
437 $this->assign('selectedTabIndex', $selectedTabIndex);
441 if (!CRM_Campaign_BAO_Campaign
::accessCampaign()) {
442 CRM_Utils_System
::permissionDenied();
447 return parent
::run();
450 function buildTabs() {
452 foreach ($this->_tabs
as $name => $title) {
456 'url' => CRM_Utils_System
::url('civicrm/campaign', "reset=1&type=$name&snippet=1"),
460 $this->assign('allTabs', $allTabs);