| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Page for voting tab interface. |
| 20 | */ |
| 21 | class CRM_Campaign_Page_Vote extends CRM_Core_Page { |
| 22 | private $_surveyId; |
| 23 | private $_interviewerId; |
| 24 | |
| 25 | /** |
| 26 | * @return mixed |
| 27 | */ |
| 28 | public function reserve() { |
| 29 | //build ajax voter search and selector. |
| 30 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents')); |
| 31 | $controller->set('votingTab', TRUE); |
| 32 | $controller->set('subVotingTab', 'searchANDReserve'); |
| 33 | |
| 34 | $controller->process(); |
| 35 | return $controller->run(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return mixed |
| 40 | */ |
| 41 | public function interview() { |
| 42 | //build interview and release voter interface. |
| 43 | $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents')); |
| 44 | $controller->set('votingTab', TRUE); |
| 45 | $controller->set('subVotingTab', 'searchANDInterview'); |
| 46 | if ($this->_surveyId) { |
| 47 | $controller->set('surveyId', $this->_surveyId); |
| 48 | } |
| 49 | if ($this->_interviewerId) { |
| 50 | $controller->set('interviewerId', $this->_interviewerId); |
| 51 | } |
| 52 | $controller->process(); |
| 53 | return $controller->run(); |
| 54 | } |
| 55 | |
| 56 | public function browse() { |
| 57 | $this->_tabs = [ |
| 58 | 'reserve' => ts('Reserve Respondents'), |
| 59 | 'interview' => ts('Interview Respondents'), |
| 60 | ]; |
| 61 | |
| 62 | $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this); |
| 63 | $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); |
| 64 | |
| 65 | $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this); |
| 66 | if ($subPageType) { |
| 67 | $session = CRM_Core_Session::singleton(); |
| 68 | $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}")); |
| 69 | //load the data in tabs. |
| 70 | $this->{$subPageType}(); |
| 71 | } |
| 72 | else { |
| 73 | //build the tabs. |
| 74 | $this->buildTabs(); |
| 75 | } |
| 76 | $this->assign('subPageType', $subPageType); |
| 77 | |
| 78 | CRM_Core_Resources::singleton() |
| 79 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
| 80 | ->addSetting([ |
| 81 | 'tabSettings' => [ |
| 82 | 'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')), |
| 83 | ], |
| 84 | ]); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return string |
| 89 | */ |
| 90 | public function run() { |
| 91 | $this->browse(); |
| 92 | |
| 93 | return parent::run(); |
| 94 | } |
| 95 | |
| 96 | public function buildTabs() { |
| 97 | $allTabs = []; |
| 98 | foreach ($this->_tabs as $name => $title) { |
| 99 | // check for required permissions. |
| 100 | if (!CRM_Core_Permission::check([ |
| 101 | [ |
| 102 | 'manage campaign', |
| 103 | 'administer CiviCampaign', |
| 104 | "{$name} campaign contacts", |
| 105 | ], |
| 106 | ])) { |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | $urlParams = "type={$name}"; |
| 111 | if ($this->_surveyId) { |
| 112 | $urlParams .= "&sid={$this->_surveyId}"; |
| 113 | } |
| 114 | if ($this->_interviewerId) { |
| 115 | $urlParams .= "&cid={$this->_interviewerId}"; |
| 116 | } |
| 117 | $allTabs[$name] = [ |
| 118 | 'title' => $title, |
| 119 | 'valid' => TRUE, |
| 120 | 'active' => TRUE, |
| 121 | 'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams), |
| 122 | ]; |
| 123 | } |
| 124 | |
| 125 | $this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs); |
| 126 | } |
| 127 | |
| 128 | } |