Merge pull request #4528 from eileenmcnaughton/CRM-15555
[civicrm-core.git] / CRM / Campaign / Page / Vote.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
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
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for voting tab interface.
38 */
39class CRM_Campaign_Page_Vote extends CRM_Core_Page {
40 private $_surveyId;
41 private $_interviewerId;
8ef12e64 42
30c4e065
EM
43 /**
44 * @return mixed
45 */
6a488035
TO
46 function reserve() {
47 //build ajax voter search and selector.
48 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents'));
49 $controller->set('votingTab', TRUE);
50 $controller->set('subVotingTab', 'searchANDReserve');
51
52 $controller->process();
53 return $controller->run();
54 }
55
e0ef6999
EM
56 /**
57 * @return mixed
58 */
6a488035
TO
59 function interview() {
60 //build interview and release voter interface.
61 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents'));
62 $controller->set('votingTab', TRUE);
63 $controller->set('subVotingTab', 'searchANDInterview');
64 if ($this->_surveyId) {
65 $controller->set('surveyId', $this->_surveyId);
66 }
67 if ($this->_interviewerId) {
68 $controller->set('interviewerId', $this->_interviewerId);
69 }
70 $controller->process();
71 return $controller->run();
72 }
73
74 function browse() {
75 $this->_tabs = array('reserve' => ts('Reserve Respondents'),
76 'interview' => ts('Interview Respondents'),
77 );
78
79 $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
80 $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
81
82 $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
83 if ($subPageType) {
84 $session = CRM_Core_Session::singleton();
85 $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}"));
86 //load the data in tabs.
87 $this->{$subPageType}();
88 }
89 else {
90 //build the tabs.
91 $this->buildTabs();
92 }
93 $this->assign('subPageType', $subPageType);
94
4165b7e5 95 CRM_Core_Resources::singleton()
96ed17aa 96 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
4165b7e5
CW
97 ->addSetting(array('tabSettings' => array(
98 'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
99 )));
6a488035
TO
100 }
101
30c4e065
EM
102 /**
103 * @return string
104 */
6a488035
TO
105 function run() {
106 $this->browse();
107
108 return parent::run();
109 }
110
111 function buildTabs() {
6a488035
TO
112 $allTabs = array();
113 foreach ($this->_tabs as $name => $title) {
6a84d0fb
CW
114 // check for required permissions.
115 if (!CRM_Core_Permission::check(array(array('manage campaign', 'administer CiviCampaign', "{$name} campaign contacts")))) {
6a488035
TO
116 continue;
117 }
118
349a45b7 119 $urlParams = "type={$name}";
6a488035
TO
120 if ($this->_surveyId) {
121 $urlParams .= "&sid={$this->_surveyId}";
122 }
123 if ($this->_interviewerId) {
124 $urlParams .= "&cid={$this->_interviewerId}";
125 }
349a45b7 126 $allTabs[$name] = array(
6a488035 127 'title' => $title,
349a45b7
CW
128 'valid' => TRUE,
129 'active' => TRUE,
130 'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
6a488035
TO
131 );
132 }
133
349a45b7 134 $this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
6a488035
TO
135 }
136}
137