3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * class to represent the actions that can be performed on a group of contacts
38 * used by the search forms
41 class CRM_Contact_Task
{
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;
54 static $_tasks = NULL;
57 * the optional task array
62 static $_optionalTasks = NULL;
64 static function initTasks() {
66 self
::$_tasks = array(
68 'title' => ts('Add Contacts to Group'),
69 'class' => 'CRM_Contact_Form_Task_AddToGroup',
72 'title' => ts('Remove Contacts from Group'),
73 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
76 'title' => ts('Tag Contacts (assign tags)'),
77 'class' => 'CRM_Contact_Form_Task_AddToTag',
80 'title' => ts('Untag Contacts (remove tags)'),
81 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
84 'title' => ts('Export Contacts'),
86 'CRM_Export_Form_Select',
87 'CRM_Export_Form_Map',
92 'title' => ts('Send Email to Contacts'),
93 'class' => 'CRM_Contact_Form_Task_Email',
97 'title' => ts('Send SMS to Contacts'),
98 'class' => 'CRM_Contact_Form_Task_SMS',
102 'title' => ts('Delete Contacts'),
103 'class' => 'CRM_Contact_Form_Task_Delete',
107 'title' => ts('Record Activity for Contacts'),
108 'class' => 'CRM_Activity_Form_Activity',
111 'title' => ts('New Smart Group'),
112 'class' => 'CRM_Contact_Form_Task_SaveSearch',
116 'title' => ts('Update Smart Group'),
117 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
121 'title' => ts('Print Contacts'),
122 'class' => 'CRM_Contact_Form_Task_Print',
126 'title' => ts('Mailing Labels'),
127 'class' => 'CRM_Contact_Form_Task_Label',
131 'title' => ts('Batch Update via Profile'),
133 'CRM_Contact_Form_Task_PickProfile',
134 'CRM_Contact_Form_Task_Batch',
139 'title' => ts('Print PDF Letter for Contacts'),
140 'class' => 'CRM_Contact_Form_Task_PDF',
144 'title' => ts('Unhold Emails'),
145 'class' => 'CRM_Contact_Form_Task_Unhold',
148 'title' => ts('Alter Contact Communication Preferences'),
149 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
151 self
::RESTORE
=> array(
152 'title' => ts('Restore Contacts'),
153 'class' => 'CRM_Contact_Form_Task_Delete',
156 self
::DELETE_PERMANENTLY
=> array(
157 'title' => ts('Delete Permanently'),
158 'class' => 'CRM_Contact_Form_Task_Delete',
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',
169 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
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',
179 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
183 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
184 self
::$_tasks[21] = array(
185 'title' => ts('Merge Contacts'),
186 'class' => 'CRM_Contact_Form_Task_Merge',
191 //CRM-4418, check for delete
192 if (!CRM_Core_Permission
::check('delete contacts')) {
193 unset(self
::$_tasks[8]);
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();
200 if ($config->mapProvider
&&
201 ($config->mapProvider
== 'Google' ||
202 ($config->mapProvider
== 'OpenStreetMaps' ||
203 $config->geoProvider
== 'Google'
207 self
::$_tasks[12] = array(
208 'title' => ts('Map Contacts'),
209 'class' => 'CRM_Contact_Form_Task_Map',
214 if (CRM_Core_Permission
::access('CiviEvent')) {
215 self
::$_tasks[18] = array(
216 'title' => ts('Add Contacts to Event'),
217 'class' => 'CRM_Event_Form_Participant',
221 if (CRM_Core_Permission
::access('CiviMail')) {
222 self
::$_tasks[20] = array(
223 'title' => ts('Schedule/Send a Mass Mailing'),
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',
234 elseif (CRM_Mailing_Info
::workflowEnabled() &&
235 CRM_Core_Permission
::check('create mailings')
237 self
::$_tasks[20] = array(
238 'title' => ts('Create a Mass Mailing'),
240 'CRM_Mailing_Form_Group',
241 'CRM_Mailing_Form_Settings',
242 'CRM_Mailing_Form_Upload',
243 'CRM_Mailing_Form_Test',
249 self
::$_tasks +
= CRM_Core_Component
::taskList();
251 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
253 asort(self
::$_tasks);
258 * These tasks are the core set of tasks that the user can perform
259 * on a contact / group of contacts
261 * @return array the set of tasks for a group of contacts
265 static function &taskTitles() {
269 foreach (self
::$_tasks as $id => $value) {
270 $titles[$id] = $value['title'];
273 // hack unset update saved search and print contacts
277 $config = CRM_Core_Config
::singleton();
279 if (!CRM_Utils_Mail
::validOutBoundMail()) {
284 // if ( ! in_array( 'CiviSMS', $config->enableComponents ) ) {
285 // unset( $titles[7] );
289 if (!CRM_Core_Permission
::check('access deleted contacts') ||
290 !CRM_Core_Permission
::check('delete contacts')
292 unset($titles[self
::DELETE_PERMANENTLY
]);
299 * show tasks selectively based on the permission level
302 * @param int $permission
303 * @param bool $deletedContacts are these tasks for operating on deleted contacts?
305 * @return array set of tasks that are valid for the user
308 static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) {
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'];
319 elseif ($permission == CRM_Core_Permission
::EDIT
) {
320 $tasks = self
::taskTitles();
324 5 => self
::$_tasks[5]['title'],
325 6 => self
::$_tasks[6]['title'],
326 16 => self
::$_tasks[16]['title'],
329 if (isset(self
::$_tasks[12]) &&
330 !empty(self
::$_tasks[12]['title'])
332 $tasks[12] = self
::$_tasks[12]['title'];
335 if (isset(self
::$_tasks[20]) &&
336 !empty(self
::$_tasks[20]['title'])
338 $tasks[20] = self
::$_tasks[20]['title'];
345 * These tasks get added based on the context the user is in
347 * @return array the set of optional tasks for a group of contacts
351 static function &optionalTaskTitle() {
353 14 => self
::$_tasks[14]['title'],
358 static function getTask($value) {
361 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
362 // make it the print task by default
366 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
367 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),