| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
| 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 | * Class CRM_Export_Controller_Standalone |
| 30 | */ |
| 31 | class CRM_Export_Controller_Standalone extends CRM_Core_Controller { |
| 32 | |
| 33 | /** |
| 34 | * Class constructor. |
| 35 | * |
| 36 | * @param string $title |
| 37 | * @param bool|int $action |
| 38 | * @param bool $modal |
| 39 | */ |
| 40 | public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) { |
| 41 | |
| 42 | parent::__construct($title, $modal); |
| 43 | |
| 44 | $entity = ucfirst(CRM_Utils_Request::retrieve('entity', 'String', $this, TRUE)); |
| 45 | $this->set('entity', $entity); |
| 46 | $id = explode(',', CRM_Utils_Request::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE)); |
| 47 | |
| 48 | // Check permissions |
| 49 | $perm = civicrm_api3($entity, 'get', [ |
| 50 | 'return' => 'id', |
| 51 | 'options' => ['limit' => 0], |
| 52 | 'check_permissions' => 1, |
| 53 | 'id' => ['IN' => $id], |
| 54 | ]); |
| 55 | |
| 56 | $this->set('id', implode(',', array_keys($perm['values']))); |
| 57 | if ($entity == 'Contact') { |
| 58 | $this->set('cids', implode(',', array_keys($perm['values']))); |
| 59 | } |
| 60 | |
| 61 | $this->_stateMachine = new CRM_Export_StateMachine_Standalone($this, $action); |
| 62 | |
| 63 | // create and instantiate the pages |
| 64 | $this->addPages($this->_stateMachine, $action); |
| 65 | |
| 66 | // add all the actions |
| 67 | $this->addActions(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Export forms are historically tightly coupled to search forms,so this simulates |
| 72 | * the output of a search form, with an array of checkboxes for each selected entity. |
| 73 | * |
| 74 | * @param string $pageName |
| 75 | * @return array |
| 76 | */ |
| 77 | public function exportValues($pageName = NULL) { |
| 78 | $values = parent::exportValues(); |
| 79 | $values['radio_ts'] = 'ts_sel'; |
| 80 | foreach (explode(',', $this->get('id')) as $id) { |
| 81 | if ($id) { |
| 82 | $values[CRM_Core_Form::CB_PREFIX . $id] = 1; |
| 83 | } |
| 84 | } |
| 85 | // Set the "task" selector value to Export |
| 86 | $className = 'CRM_' . $this->get('entity') . '_Task'; |
| 87 | foreach ($className::tasks() as $taskId => $task) { |
| 88 | $taskForm = (array) $task['class']; |
| 89 | if ($taskForm[0] == 'CRM_Export_Form_Select') { |
| 90 | $values['task'] = $taskId; |
| 91 | } |
| 92 | } |
| 93 | return $values; |
| 94 | } |
| 95 | |
| 96 | } |