commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Campaign / Page / Vote.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 --------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * Page for voting tab interface.
38 */
39 class CRM_Campaign_Page_Vote extends CRM_Core_Page {
40 private $_surveyId;
41 private $_interviewerId;
42
43 /**
44 * @return mixed
45 */
46 public 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
56 /**
57 * @return mixed
58 */
59 public 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 public function browse() {
75 $this->_tabs = array(
76 'reserve' => ts('Reserve Respondents'),
77 'interview' => ts('Interview Respondents'),
78 );
79
80 $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
81 $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
82
83 $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
84 if ($subPageType) {
85 $session = CRM_Core_Session::singleton();
86 $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}"));
87 //load the data in tabs.
88 $this->{$subPageType}();
89 }
90 else {
91 //build the tabs.
92 $this->buildTabs();
93 }
94 $this->assign('subPageType', $subPageType);
95
96 CRM_Core_Resources::singleton()
97 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
98 ->addSetting(array(
99 'tabSettings' => array(
100 'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
101 ),
102 ));
103 }
104
105 /**
106 * @return string
107 */
108 public function run() {
109 $this->browse();
110
111 return parent::run();
112 }
113
114 public function buildTabs() {
115 $allTabs = array();
116 foreach ($this->_tabs as $name => $title) {
117 // check for required permissions.
118 if (!CRM_Core_Permission::check(array(
119 array(
120 'manage campaign',
121 'administer CiviCampaign',
122 "{$name} campaign contacts",
123 ),
124 ))
125 ) {
126 continue;
127 }
128
129 $urlParams = "type={$name}";
130 if ($this->_surveyId) {
131 $urlParams .= "&sid={$this->_surveyId}";
132 }
133 if ($this->_interviewerId) {
134 $urlParams .= "&cid={$this->_interviewerId}";
135 }
136 $allTabs[$name] = array(
137 'title' => $title,
138 'valid' => TRUE,
139 'active' => TRUE,
140 'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
141 );
142 }
143
144 $this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
145 }
146
147 }