Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 | * class to represent the actions that can be performed on a group of contacts | |
38 | * used by the search forms | |
39 | * | |
40 | */ | |
41 | class CRM_Contact_Task { | |
8c3cef2a | 42 | CONST GROUP_CONTACTS = 1, REMOVE_CONTACTS = 2, TAG_CONTACTS = 3, REMOVE_TAGS = 4, EXPORT_CONTACTS = 5, |
43 | EMAIL_CONTACTS = 6, SMS_CONTACTS = 7, DELETE_CONTACTS = 8, HOUSEHOLD_CONTACTS = 9, ORGANIZATION_CONTACTS = 10, | |
44 | RECORD_CONTACTS = 11, MAP_CONTACTS = 12, SAVE_SEARCH = 13, SAVE_SEARCH_UPDATE = 14, PRINT_CONTACTS = 15, | |
45 | LABEL_CONTACTS = 16, BATCH_UPDATE = 17, ADD_EVENT = 18, PRINT_FOR_CONTACTS = 19, EMAIL_UNHOLD = 22, RESTORE = 23, | |
46 | DELETE_PERMANENTLY = 24; | |
6a488035 TO |
47 | |
48 | /** | |
49 | * the task array | |
50 | * | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
54 | static $_tasks = NULL; | |
55 | ||
56 | /** | |
57 | * the optional task array | |
58 | * | |
59 | * @var array | |
60 | * @static | |
61 | */ | |
62 | static $_optionalTasks = NULL; | |
63 | ||
64 | static function initTasks() { | |
65 | if (!self::$_tasks) { | |
66 | self::$_tasks = array( | |
4154180f | 67 | 1 => array( |
68 | 'title' => ts('Add Contacts to Group'), | |
6a488035 TO |
69 | 'class' => 'CRM_Contact_Form_Task_AddToGroup', |
70 | ), | |
4154180f | 71 | 2 => array( |
72 | 'title' => ts('Remove Contacts from Group'), | |
6a488035 TO |
73 | 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup', |
74 | ), | |
4154180f | 75 | 3 => array( |
76 | 'title' => ts('Tag Contacts (assign tags)'), | |
6a488035 TO |
77 | 'class' => 'CRM_Contact_Form_Task_AddToTag', |
78 | ), | |
4154180f | 79 | 4 => array( |
80 | 'title' => ts('Untag Contacts (remove tags)'), | |
6a488035 TO |
81 | 'class' => 'CRM_Contact_Form_Task_RemoveFromTag', |
82 | ), | |
4154180f | 83 | 5 => array( |
84 | 'title' => ts('Export Contacts'), | |
6a488035 TO |
85 | 'class' => array( |
86 | 'CRM_Export_Form_Select', | |
87 | 'CRM_Export_Form_Map', | |
88 | ), | |
89 | 'result' => FALSE, | |
90 | ), | |
4154180f | 91 | 6 => array( |
92 | 'title' => ts('Send Email to Contacts'), | |
6a488035 TO |
93 | 'class' => 'CRM_Contact_Form_Task_Email', |
94 | 'result' => TRUE, | |
95 | ), | |
4154180f | 96 | 7 => array( |
97 | 'title' => ts('Send SMS to Contacts'), | |
6a488035 TO |
98 | 'class' => 'CRM_Contact_Form_Task_SMS', |
99 | 'result' => TRUE, | |
100 | ), | |
4154180f | 101 | 8 => array( |
102 | 'title' => ts('Delete Contacts'), | |
6a488035 TO |
103 | 'class' => 'CRM_Contact_Form_Task_Delete', |
104 | 'result' => FALSE, | |
105 | ), | |
4154180f | 106 | 11 => array( |
107 | 'title' => ts('Record Activity for Contacts'), | |
6a488035 TO |
108 | 'class' => 'CRM_Activity_Form_Activity', |
109 | ), | |
4154180f | 110 | 13 => array( |
111 | 'title' => ts('New Smart Group'), | |
6a488035 TO |
112 | 'class' => 'CRM_Contact_Form_Task_SaveSearch', |
113 | 'result' => TRUE, | |
114 | ), | |
4154180f | 115 | 14 => array( |
116 | 'title' => ts('Update Smart Group'), | |
6a488035 TO |
117 | 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', |
118 | 'result' => TRUE, | |
119 | ), | |
4154180f | 120 | 15 => array( |
121 | 'title' => ts('Print Contacts'), | |
6a488035 TO |
122 | 'class' => 'CRM_Contact_Form_Task_Print', |
123 | 'result' => FALSE, | |
124 | ), | |
4154180f | 125 | 16 => array( |
126 | 'title' => ts('Mailing Labels'), | |
6a488035 TO |
127 | 'class' => 'CRM_Contact_Form_Task_Label', |
128 | 'result' => TRUE, | |
129 | ), | |
4154180f | 130 | 17 => array( |
131 | 'title' => ts('Batch Update via Profile'), | |
6a488035 TO |
132 | 'class' => array( |
133 | 'CRM_Contact_Form_Task_PickProfile', | |
134 | 'CRM_Contact_Form_Task_Batch', | |
135 | ), | |
136 | 'result' => TRUE, | |
137 | ), | |
4154180f | 138 | 19 => array( |
139 | 'title' => ts('Print PDF Letter for Contacts'), | |
6a488035 TO |
140 | 'class' => 'CRM_Contact_Form_Task_PDF', |
141 | 'result' => TRUE, | |
142 | ), | |
4154180f | 143 | 22 => array( |
144 | 'title' => ts('Unhold Emails'), | |
6a488035 TO |
145 | 'class' => 'CRM_Contact_Form_Task_Unhold', |
146 | ), | |
4154180f | 147 | 25 => array( |
148 | 'title' => ts('Alter Contact Communication Preferences'), | |
6a488035 TO |
149 | 'class' => 'CRM_Contact_Form_Task_AlterPreferences', |
150 | ), | |
151 | self::RESTORE => array( | |
152 | 'title' => ts('Restore Contacts'), | |
153 | 'class' => 'CRM_Contact_Form_Task_Delete', | |
154 | 'result' => FALSE, | |
155 | ), | |
156 | self::DELETE_PERMANENTLY => array( | |
157 | 'title' => ts('Delete Permanently'), | |
158 | 'class' => 'CRM_Contact_Form_Task_Delete', | |
159 | 'result' => FALSE, | |
160 | ), | |
161 | ); | |
162 | ||
163 | if (CRM_Contact_BAO_ContactType::isActive('Household')) { | |
164 | $label = CRM_Contact_BAO_ContactType::getLabel('Household'); | |
165 | self::$_tasks[9] = array( | |
166 | 'title' => ts('Add Contacts to %1', | |
167 | array(1 => $label) | |
168 | ), | |
169 | 'class' => 'CRM_Contact_Form_Task_AddToHousehold', | |
170 | ); | |
171 | } | |
172 | ||
173 | if (CRM_Contact_BAO_ContactType::isActive('Organization')) { | |
174 | $label = CRM_Contact_BAO_ContactType::getLabel('Organization'); | |
175 | self::$_tasks[10] = array( | |
176 | 'title' => ts('Add Contacts to %1', | |
177 | array(1 => $label) | |
178 | ), | |
179 | 'class' => 'CRM_Contact_Form_Task_AddToOrganization', | |
180 | ); | |
181 | } | |
182 | ||
183 | if (CRM_Core_Permission::check('merge duplicate contacts')) { | |
4154180f | 184 | self::$_tasks[21] = array( |
185 | 'title' => ts('Merge Contacts'), | |
6a488035 TO |
186 | 'class' => 'CRM_Contact_Form_Task_Merge', |
187 | 'result' => TRUE, | |
188 | ); | |
189 | } | |
190 | ||
191 | //CRM-4418, check for delete | |
192 | if (!CRM_Core_Permission::check('delete contacts')) { | |
193 | unset(self::$_tasks[8]); | |
194 | } | |
195 | ||
196 | //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider) | |
197 | // should fix this to be more flexible as providers are added ?? | |
198 | $config = CRM_Core_Config::singleton(); | |
199 | ||
200 | if ($config->mapProvider && | |
201 | ($config->mapProvider == 'Google' || | |
202 | ($config->mapProvider == 'OpenStreetMaps' || | |
203 | $config->geoProvider == 'Google' | |
204 | ) | |
205 | ) | |
206 | ) { | |
4154180f | 207 | self::$_tasks[12] = array( |
208 | 'title' => ts('Map Contacts'), | |
6a488035 TO |
209 | 'class' => 'CRM_Contact_Form_Task_Map', |
210 | 'result' => FALSE, | |
211 | ); | |
212 | } | |
213 | ||
214 | if (CRM_Core_Permission::access('CiviEvent')) { | |
4154180f | 215 | self::$_tasks[18] = array( |
216 | 'title' => ts('Add Contacts to Event'), | |
6a488035 TO |
217 | 'class' => 'CRM_Event_Form_Participant', |
218 | ); | |
219 | } | |
220 | ||
221 | if (CRM_Core_Permission::access('CiviMail')) { | |
4154180f | 222 | self::$_tasks[20] = array( |
223 | 'title' => ts('Schedule/Send a Mass Mailing'), | |
6a488035 TO |
224 | 'class' => array( |
225 | 'CRM_Mailing_Form_Group', | |
226 | 'CRM_Mailing_Form_Settings', | |
227 | 'CRM_Mailing_Form_Upload', | |
228 | 'CRM_Mailing_Form_Test', | |
229 | 'CRM_Mailing_Form_Schedule', | |
230 | ), | |
231 | 'result' => FALSE, | |
232 | ); | |
233 | } | |
234 | elseif (CRM_Mailing_Info::workflowEnabled() && | |
235 | CRM_Core_Permission::check('create mailings') | |
236 | ) { | |
4154180f | 237 | self::$_tasks[20] = array( |
238 | 'title' => ts('Create a Mass Mailing'), | |
6a488035 TO |
239 | 'class' => array( |
240 | 'CRM_Mailing_Form_Group', | |
241 | 'CRM_Mailing_Form_Settings', | |
242 | 'CRM_Mailing_Form_Upload', | |
243 | 'CRM_Mailing_Form_Test', | |
244 | ), | |
245 | 'result' => FALSE, | |
246 | ); | |
247 | } | |
248 | ||
249 | self::$_tasks += CRM_Core_Component::taskList(); | |
250 | ||
251 | CRM_Utils_Hook::searchTasks('contact', self::$_tasks); | |
252 | ||
253 | asort(self::$_tasks); | |
254 | } | |
255 | } | |
256 | ||
257 | /** | |
258 | * These tasks are the core set of tasks that the user can perform | |
259 | * on a contact / group of contacts | |
260 | * | |
261 | * @return array the set of tasks for a group of contacts | |
262 | * @static | |
263 | * @access public | |
264 | */ | |
265 | static function &taskTitles() { | |
266 | self::initTasks(); | |
267 | ||
268 | $titles = array(); | |
269 | foreach (self::$_tasks as $id => $value) { | |
270 | $titles[$id] = $value['title']; | |
271 | } | |
272 | ||
273 | // hack unset update saved search and print contacts | |
274 | unset($titles[14]); | |
275 | unset($titles[15]); | |
276 | ||
277 | $config = CRM_Core_Config::singleton(); | |
278 | ||
279 | if (!CRM_Utils_Mail::validOutBoundMail()) { | |
280 | unset($titles[6]); | |
281 | unset($titles[20]); | |
282 | } | |
283 | ||
284 | // if ( ! in_array( 'CiviSMS', $config->enableComponents ) ) { | |
285 | // unset( $titles[7] ); | |
286 | // } | |
287 | ||
288 | // CRM-6806 | |
289 | if (!CRM_Core_Permission::check('access deleted contacts') || | |
290 | !CRM_Core_Permission::check('delete contacts') | |
291 | ) { | |
292 | unset($titles[self::DELETE_PERMANENTLY]); | |
293 | } | |
294 | asort($titles); | |
295 | return $titles; | |
296 | } | |
297 | ||
298 | /** | |
299 | * show tasks selectively based on the permission level | |
300 | * of the user | |
301 | * | |
302 | * @param int $permission | |
303 | * @param bool $deletedContacts are these tasks for operating on deleted contacts? | |
304 | * | |
305 | * @return array set of tasks that are valid for the user | |
306 | * @access public | |
307 | */ | |
4154180f | 308 | static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) { |
6a488035 TO |
309 | self::initTasks(); |
310 | $tasks = array(); | |
311 | if ($deletedContacts) { | |
312 | if (CRM_Core_Permission::check('access deleted contacts')) { | |
313 | $tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title']; | |
314 | if (CRM_Core_Permission::check('delete contacts')) { | |
315 | $tasks[self::DELETE_PERMANENTLY] = self::$_tasks[self::DELETE_PERMANENTLY]['title']; | |
316 | } | |
317 | } | |
318 | } | |
319 | elseif ($permission == CRM_Core_Permission::EDIT) { | |
320 | $tasks = self::taskTitles(); | |
321 | } | |
322 | else { | |
323 | $tasks = array( | |
324 | 5 => self::$_tasks[5]['title'], | |
325 | 6 => self::$_tasks[6]['title'], | |
326 | 16 => self::$_tasks[16]['title'], | |
327 | ); | |
328 | ||
329 | if (isset(self::$_tasks[12]) && | |
330 | !empty(self::$_tasks[12]['title']) | |
331 | ) { | |
332 | $tasks[12] = self::$_tasks[12]['title']; | |
333 | } | |
334 | ||
335 | if (isset(self::$_tasks[20]) && | |
336 | !empty(self::$_tasks[20]['title']) | |
337 | ) { | |
338 | $tasks[20] = self::$_tasks[20]['title']; | |
339 | } | |
340 | } | |
341 | return $tasks; | |
342 | } | |
343 | ||
344 | /** | |
345 | * These tasks get added based on the context the user is in | |
346 | * | |
347 | * @return array the set of optional tasks for a group of contacts | |
348 | * @static | |
349 | * @access public | |
350 | */ | |
351 | static function &optionalTaskTitle() { | |
352 | $tasks = array( | |
353 | 14 => self::$_tasks[14]['title'], | |
354 | ); | |
355 | return $tasks; | |
356 | } | |
357 | ||
358 | static function getTask($value) { | |
359 | self::initTasks(); | |
360 | ||
361 | if (!CRM_Utils_Array::value($value, self::$_tasks)) { | |
362 | // make it the print task by default | |
363 | $value = 15; | |
364 | } | |
4154180f | 365 | return array( |
366 | CRM_Utils_Array::value('class', self::$_tasks[$value]), | |
6a488035 TO |
367 | CRM_Utils_Array::value('result', self::$_tasks[$value]), |
368 | ); | |
369 | } | |
370 | } | |
371 |