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