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