| 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 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Class to represent the actions that can be performed on a group of contacts. |
| 36 | * |
| 37 | * Used by the search forms. |
| 38 | */ |
| 39 | class CRM_Contribute_Task extends CRM_Core_Task { |
| 40 | |
| 41 | const |
| 42 | // Contribution tasks |
| 43 | UPDATE_STATUS = 401, |
| 44 | PDF_RECEIPT = 402, |
| 45 | PDF_THANKYOU = 403, |
| 46 | PDF_INVOICE = 404; |
| 47 | |
| 48 | static $objectType = 'contribution'; |
| 49 | |
| 50 | /** |
| 51 | * These tasks are the core set of tasks that the user can perform |
| 52 | * on a contact / group of contacts |
| 53 | * |
| 54 | * @return array |
| 55 | * the set of tasks for a group of contacts |
| 56 | */ |
| 57 | public static function tasks() { |
| 58 | if (!(self::$_tasks)) { |
| 59 | self::$_tasks = array( |
| 60 | self::TASK_DELETE => array( |
| 61 | 'title' => ts('Delete contributions'), |
| 62 | 'class' => 'CRM_Contribute_Form_Task_Delete', |
| 63 | 'result' => FALSE, |
| 64 | ), |
| 65 | self::TASK_PRINT => array( |
| 66 | 'title' => ts('Print selected rows'), |
| 67 | 'class' => 'CRM_Contribute_Form_Task_Print', |
| 68 | 'result' => FALSE, |
| 69 | ), |
| 70 | self::TASK_EXPORT => array( |
| 71 | 'title' => ts('Export contributions'), |
| 72 | 'class' => array( |
| 73 | 'CRM_Export_Form_Select', |
| 74 | 'CRM_Export_Form_Map', |
| 75 | ), |
| 76 | 'result' => FALSE, |
| 77 | ), |
| 78 | self::BATCH_UPDATE => array( |
| 79 | 'title' => ts('Update multiple contributions'), |
| 80 | 'class' => array( |
| 81 | 'CRM_Contribute_Form_Task_PickProfile', |
| 82 | 'CRM_Contribute_Form_Task_Batch', |
| 83 | ), |
| 84 | 'result' => TRUE, |
| 85 | ), |
| 86 | self::TASK_EMAIL => array( |
| 87 | 'title' => ts('Email - send now (to %1 or less)', array( |
| 88 | 1 => Civi::settings() |
| 89 | ->get('simple_mail_limit'), |
| 90 | )), |
| 91 | 'class' => 'CRM_Contribute_Form_Task_Email', |
| 92 | 'result' => TRUE, |
| 93 | ), |
| 94 | self::UPDATE_STATUS => array( |
| 95 | 'title' => ts('Update pending contribution status'), |
| 96 | 'class' => 'CRM_Contribute_Form_Task_Status', |
| 97 | 'result' => TRUE, |
| 98 | ), |
| 99 | self::PDF_RECEIPT => array( |
| 100 | 'title' => ts('Receipts - print or email'), |
| 101 | 'class' => 'CRM_Contribute_Form_Task_PDF', |
| 102 | 'result' => FALSE, |
| 103 | ), |
| 104 | self::PDF_THANKYOU => array( |
| 105 | 'title' => ts('Thank-you letters - print or email'), |
| 106 | 'class' => 'CRM_Contribute_Form_Task_PDFLetter', |
| 107 | 'result' => FALSE, |
| 108 | ), |
| 109 | self::PDF_INVOICE => array( |
| 110 | 'title' => ts('Invoices - print or email'), |
| 111 | 'class' => 'CRM_Contribute_Form_Task_Invoice', |
| 112 | 'result' => FALSE, |
| 113 | ), |
| 114 | ); |
| 115 | |
| 116 | //CRM-4418, check for delete |
| 117 | if (!CRM_Core_Permission::check('delete in CiviContribute')) { |
| 118 | unset(self::$_tasks[self::TASK_DELETE]); |
| 119 | } |
| 120 | //CRM-12920 - check for edit permission |
| 121 | if (!CRM_Core_Permission::check('edit contributions')) { |
| 122 | unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::UPDATE_STATUS]); |
| 123 | } |
| 124 | |
| 125 | // remove action "Invoices - print or email" |
| 126 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
| 127 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); |
| 128 | if (!$invoicing) { |
| 129 | unset(self::$_tasks[self::PDF_INVOICE]); |
| 130 | } |
| 131 | |
| 132 | parent::tasks(); |
| 133 | } |
| 134 | |
| 135 | return self::$_tasks; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Show tasks selectively based on the permission level |
| 140 | * of the user |
| 141 | * |
| 142 | * @param int $permission |
| 143 | * |
| 144 | * @param array $params |
| 145 | * bool softCreditFiltering: derived from CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled |
| 146 | * |
| 147 | * @return array |
| 148 | * set of tasks that are valid for the user |
| 149 | */ |
| 150 | public static function permissionedTaskTitles($permission, $params = array()) { |
| 151 | if (!isset($params['softCreditFiltering'])) { |
| 152 | $params['softCreditFiltering'] = FALSE; |
| 153 | } |
| 154 | if (($permission == CRM_Core_Permission::EDIT) |
| 155 | || CRM_Core_Permission::check('edit contributions') |
| 156 | ) { |
| 157 | $tasks = self::taskTitles(); |
| 158 | } |
| 159 | else { |
| 160 | $tasks = array( |
| 161 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
| 162 | self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'], |
| 163 | self::PDF_RECEIPT => self::$_tasks[self::PDF_RECEIPT]['title'], |
| 164 | ); |
| 165 | |
| 166 | //CRM-4418, |
| 167 | if (CRM_Core_Permission::check('delete in CiviContribute')) { |
| 168 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
| 169 | } |
| 170 | } |
| 171 | if ($params['softCreditFiltering']) { |
| 172 | unset($tasks[self::BATCH_UPDATE], $tasks[self::PDF_RECEIPT]); |
| 173 | } |
| 174 | |
| 175 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); |
| 176 | return $tasks; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * These tasks are the core set of tasks that the user can perform |
| 181 | * on contributors |
| 182 | * |
| 183 | * @param int $value |
| 184 | * |
| 185 | * @return array |
| 186 | * the set of tasks for a group of contributors |
| 187 | */ |
| 188 | public static function getTask($value) { |
| 189 | self::tasks(); |
| 190 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { |
| 191 | // make the print task by default |
| 192 | $value = self::TASK_PRINT; |
| 193 | } |
| 194 | return parent::getTask($value); |
| 195 | } |
| 196 | |
| 197 | } |