| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 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 voting tab interface. |
| 38 | */ |
| 39 | class CRM_Campaign_Page_Vote extends CRM_Core_Page { |
| 40 | private $_surveyId; |
| 41 | private $_interviewerId; |
| 42 | |
| 43 | function reserve() { |
| 44 | //build ajax voter search and selector. |
| 45 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents')); |
| 46 | $controller->set('votingTab', TRUE); |
| 47 | $controller->set('subVotingTab', 'searchANDReserve'); |
| 48 | |
| 49 | $controller->process(); |
| 50 | return $controller->run(); |
| 51 | } |
| 52 | |
| 53 | function interview() { |
| 54 | //build interview and release voter interface. |
| 55 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents')); |
| 56 | $controller->set('votingTab', TRUE); |
| 57 | $controller->set('subVotingTab', 'searchANDInterview'); |
| 58 | if ($this->_surveyId) { |
| 59 | $controller->set('surveyId', $this->_surveyId); |
| 60 | } |
| 61 | if ($this->_interviewerId) { |
| 62 | $controller->set('interviewerId', $this->_interviewerId); |
| 63 | } |
| 64 | $controller->process(); |
| 65 | return $controller->run(); |
| 66 | } |
| 67 | |
| 68 | function browse() { |
| 69 | $this->_tabs = array('reserve' => ts('Reserve Respondents'), |
| 70 | 'interview' => ts('Interview Respondents'), |
| 71 | ); |
| 72 | |
| 73 | $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this); |
| 74 | $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); |
| 75 | |
| 76 | $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this); |
| 77 | if ($subPageType) { |
| 78 | $session = CRM_Core_Session::singleton(); |
| 79 | $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}")); |
| 80 | //load the data in tabs. |
| 81 | $this->{$subPageType}(); |
| 82 | } |
| 83 | else { |
| 84 | //build the tabs. |
| 85 | $this->buildTabs(); |
| 86 | } |
| 87 | $this->assign('subPageType', $subPageType); |
| 88 | |
| 89 | //give focus to proper tab. |
| 90 | $this->assign('selectedTabIndex', array_search(CRM_Utils_Array::value('subPage', $_GET, 'reserve'), |
| 91 | array_keys($this->_tabs) |
| 92 | )); |
| 93 | } |
| 94 | |
| 95 | function run() { |
| 96 | $this->browse(); |
| 97 | |
| 98 | return parent::run(); |
| 99 | } |
| 100 | |
| 101 | function buildTabs() { |
| 102 | //check for required permissions. |
| 103 | $superUser = FALSE; |
| 104 | if (CRM_Core_Permission::check('manage campaign') || |
| 105 | CRM_Core_Permission::check('administer CiviCampaign') |
| 106 | ) { |
| 107 | $superUser = TRUE; |
| 108 | } |
| 109 | |
| 110 | $allTabs = array(); |
| 111 | foreach ($this->_tabs as $name => $title) { |
| 112 | if (!$superUser && |
| 113 | !CRM_Core_Permission::check("{$name} campaign contacts") |
| 114 | ) { |
| 115 | continue; |
| 116 | } |
| 117 | |
| 118 | $urlParams = "type={$name}&snippet=1"; |
| 119 | if ($this->_surveyId) { |
| 120 | $urlParams .= "&sid={$this->_surveyId}"; |
| 121 | } |
| 122 | if ($this->_interviewerId) { |
| 123 | $urlParams .= "&cid={$this->_interviewerId}"; |
| 124 | } |
| 125 | $allTabs[] = array( |
| 126 | 'id' => $name, |
| 127 | 'title' => $title, |
| 128 | 'url' => CRM_Utils_System::url('civicrm/campaign/vote', |
| 129 | $urlParams |
| 130 | ), |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | $this->assign('allTabs', empty($allTabs) ? FALSE : $allTabs); |
| 135 | } |
| 136 | } |
| 137 | |