| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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. | |
| 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 along with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @package CRM |
| 30 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 31 | * $Id$ |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | /** |
| 36 | * class to represent the actions that can be performed on a group of contacts |
| 37 | * used by the search forms |
| 38 | * |
| 39 | */ |
| 40 | class CRM_Activity_Task { |
| 41 | const |
| 42 | DELETE_ACTIVITIES = 1, |
| 43 | PRINT_ACTIVITIES = 2, |
| 44 | EXPORT_ACTIVITIES = 3, |
| 45 | BATCH_ACTIVITIES = 4, |
| 46 | EMAIL_CONTACTS = 5, |
| 47 | EMAIL_SMS = 6; |
| 48 | |
| 49 | /** |
| 50 | * The task array |
| 51 | * |
| 52 | * @var array |
| 53 | */ |
| 54 | static $_tasks = NULL; |
| 55 | |
| 56 | /** |
| 57 | * The optional task array |
| 58 | * |
| 59 | * @var array |
| 60 | */ |
| 61 | static $_optionalTasks = NULL; |
| 62 | |
| 63 | /** |
| 64 | * These tasks are the core set of tasks that the user can perform |
| 65 | * on a contact / group of contacts |
| 66 | * |
| 67 | * @return array |
| 68 | * the set of tasks for a group of contacts |
| 69 | */ |
| 70 | public static function &tasks() { |
| 71 | if (!(self::$_tasks)) { |
| 72 | self::$_tasks = array( |
| 73 | 1 => array( |
| 74 | 'title' => ts('Delete Activities'), |
| 75 | 'class' => 'CRM_Activity_Form_Task_Delete', |
| 76 | 'result' => FALSE, |
| 77 | ), |
| 78 | 2 => array( |
| 79 | 'title' => ts('Print Selected Rows'), |
| 80 | 'class' => 'CRM_Activity_Form_Task_Print', |
| 81 | 'result' => FALSE, |
| 82 | ), |
| 83 | 3 => array( |
| 84 | 'title' => ts('Export Activities'), |
| 85 | 'class' => array( |
| 86 | 'CRM_Export_Form_Select', |
| 87 | 'CRM_Export_Form_Map', |
| 88 | ), |
| 89 | 'result' => FALSE, |
| 90 | ), |
| 91 | 4 => array( |
| 92 | 'title' => ts('Batch Update Activities Via Profile'), |
| 93 | 'class' => array( |
| 94 | 'CRM_Activity_Form_Task_PickProfile', |
| 95 | 'CRM_Activity_Form_Task_Batch', |
| 96 | ), |
| 97 | 'result' => FALSE, |
| 98 | ), |
| 99 | 5 => array( |
| 100 | 'title' => ts('Send Email to Contacts'), |
| 101 | 'class' => array( |
| 102 | 'CRM_Activity_Form_Task_PickOption', |
| 103 | 'CRM_Activity_Form_Task_Email', |
| 104 | ), |
| 105 | 'result' => FALSE, |
| 106 | ), |
| 107 | 6 => array( |
| 108 | 'title' => ts('Send Reply SMS To Contacts'), |
| 109 | 'class' => 'CRM_Activity_Form_Task_SMS', |
| 110 | 'result' => FALSE, |
| 111 | ), |
| 112 | 7 => array( |
| 113 | 'title' => ts('Tag Activities (assign tags)'), |
| 114 | 'class' => 'CRM_Activity_Form_Task_AddToTag', |
| 115 | 'result' => FALSE, |
| 116 | ), |
| 117 | 8 => array( |
| 118 | 'title' => ts('Untag Activities (remove tags)'), |
| 119 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', |
| 120 | 'result' => FALSE, |
| 121 | ), |
| 122 | ); |
| 123 | |
| 124 | $config = CRM_Core_Config::singleton(); |
| 125 | if (in_array('CiviCase', $config->enableComponents)) { |
| 126 | if (CRM_Core_Permission::check('access all cases and activities') || |
| 127 | CRM_Core_Permission::check('access my cases and activities') |
| 128 | ) { |
| 129 | self::$_tasks[6] = array( |
| 130 | 'title' => ts('File on Case'), |
| 131 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
| 132 | 'result' => FALSE, |
| 133 | ); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | //CRM-4418, check for delete |
| 138 | if (!CRM_Core_Permission::check('delete activities')) { |
| 139 | unset(self::$_tasks[1]); |
| 140 | } |
| 141 | } |
| 142 | CRM_Utils_Hook::searchTasks('activity', self::$_tasks); |
| 143 | asort(self::$_tasks); |
| 144 | return self::$_tasks; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * These tasks are the core set of task titles |
| 149 | * on activity |
| 150 | * |
| 151 | * @return array |
| 152 | * the set of task titles |
| 153 | */ |
| 154 | public static function &taskTitles() { |
| 155 | self::tasks(); |
| 156 | $titles = array(); |
| 157 | foreach (self::$_tasks as $id => $value) { |
| 158 | $titles[$id] = $value['title']; |
| 159 | } |
| 160 | return $titles; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Show tasks selectively based on the permission level |
| 165 | * of the user |
| 166 | * |
| 167 | * @param int $permission |
| 168 | * |
| 169 | * @return array |
| 170 | * set of tasks that are valid for the user |
| 171 | */ |
| 172 | public static function &permissionedTaskTitles($permission) { |
| 173 | $tasks = array(); |
| 174 | if ($permission == CRM_Core_Permission::EDIT) { |
| 175 | $tasks = self::taskTitles(); |
| 176 | } |
| 177 | else { |
| 178 | $tasks = array( |
| 179 | 3 => self::$_tasks[3]['title'], |
| 180 | ); |
| 181 | |
| 182 | //CRM-4418, |
| 183 | if (CRM_Core_Permission::check('delete activities')) { |
| 184 | $tasks[1] = self::$_tasks[1]['title']; |
| 185 | } |
| 186 | } |
| 187 | return $tasks; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * These tasks are the core set of tasks that the user can perform |
| 192 | * on activity |
| 193 | * |
| 194 | * @param int $value |
| 195 | * |
| 196 | * @return array |
| 197 | * the set of tasks for a group of activity |
| 198 | */ |
| 199 | public static function getTask($value) { |
| 200 | self::tasks(); |
| 201 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { |
| 202 | // make the print task by default |
| 203 | $value = 2; |
| 204 | } |
| 205 | return array( |
| 206 | self::$_tasks[$value]['class'], |
| 207 | self::$_tasks[$value]['result'], |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | } |