5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
39 * class to represent the actions that can be performed on a group of contacts
40 * used by the search forms
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;
52 static $_tasks = NULL;
55 * the optional task array
60 static $_optionalTasks = NULL;
62 static function initTasks() {
64 self
::$_tasks = array(
65 1 => array('title' => ts('Add Contacts to Group'),
66 'class' => 'CRM_Contact_Form_Task_AddToGroup',
68 2 => array('title' => ts('Remove Contacts from Group'),
69 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
71 3 => array('title' => ts('Tag Contacts (assign tags)'),
72 'class' => 'CRM_Contact_Form_Task_AddToTag',
74 4 => array('title' => ts('Untag Contacts (remove tags)'),
75 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
77 5 => array('title' => ts('Export Contacts'),
79 'CRM_Export_Form_Select',
80 'CRM_Export_Form_Map',
84 6 => array('title' => ts('Send Email to Contacts'),
85 'class' => 'CRM_Contact_Form_Task_Email',
88 7 => array('title' => ts('Send SMS to Contacts'),
89 'class' => 'CRM_Contact_Form_Task_SMS',
92 8 => array('title' => ts('Delete Contacts'),
93 'class' => 'CRM_Contact_Form_Task_Delete',
96 11 => array('title' => ts('Record Activity for Contacts'),
97 'class' => 'CRM_Activity_Form_Activity',
99 13 => array('title' => ts('New Smart Group'),
100 'class' => 'CRM_Contact_Form_Task_SaveSearch',
103 14 => array('title' => ts('Update Smart Group'),
104 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
107 15 => array('title' => ts('Print Contacts'),
108 'class' => 'CRM_Contact_Form_Task_Print',
111 16 => array('title' => ts('Mailing Labels'),
112 'class' => 'CRM_Contact_Form_Task_Label',
115 17 => array('title' => ts('Batch Update via Profile'),
117 'CRM_Contact_Form_Task_PickProfile',
118 'CRM_Contact_Form_Task_Batch',
122 19 => array('title' => ts('Print PDF Letter for Contacts'),
123 'class' => 'CRM_Contact_Form_Task_PDF',
126 22 => array('title' => ts('Unhold Emails'),
127 'class' => 'CRM_Contact_Form_Task_Unhold',
129 25 => array('title' => ts('Alter Contact Communication Preferences'),
130 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
132 self
::RESTORE
=> array(
133 'title' => ts('Restore Contacts'),
134 'class' => 'CRM_Contact_Form_Task_Delete',
137 self
::DELETE_PERMANENTLY
=> array(
138 'title' => ts('Delete Permanently'),
139 'class' => 'CRM_Contact_Form_Task_Delete',
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',
150 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
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',
160 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
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',
171 //CRM-4418, check for delete
172 if (!CRM_Core_Permission
::check('delete contacts')) {
173 unset(self
::$_tasks[8]);
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();
180 if ($config->mapProvider
&&
181 ($config->mapProvider
== 'Google' ||
182 ($config->mapProvider
== 'OpenStreetMaps' ||
183 $config->geoProvider
== 'Google'
187 self
::$_tasks[12] = array('title' => ts('Map Contacts'),
188 'class' => 'CRM_Contact_Form_Task_Map',
193 if (CRM_Core_Permission
::access('CiviEvent')) {
194 self
::$_tasks[18] = array('title' => ts('Add Contacts to Event'),
195 'class' => 'CRM_Event_Form_Participant',
199 if (CRM_Core_Permission
::access('CiviMail')) {
200 self
::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'),
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',
211 elseif (CRM_Mailing_Info
::workflowEnabled() &&
212 CRM_Core_Permission
::check('create mailings')
214 self
::$_tasks[20] = array('title' => ts('Create a Mass Mailing'),
216 'CRM_Mailing_Form_Group',
217 'CRM_Mailing_Form_Settings',
218 'CRM_Mailing_Form_Upload',
219 'CRM_Mailing_Form_Test',
225 self
::$_tasks +
= CRM_Core_Component
::taskList();
227 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
229 asort(self
::$_tasks);
234 * These tasks are the core set of tasks that the user can perform
235 * on a contact / group of contacts
237 * @return array the set of tasks for a group of contacts
241 static function &taskTitles() {
245 foreach (self
::$_tasks as $id => $value) {
246 $titles[$id] = $value['title'];
249 // hack unset update saved search and print contacts
253 $config = CRM_Core_Config
::singleton();
255 if (!CRM_Utils_Mail
::validOutBoundMail()) {
260 // if ( ! in_array( 'CiviSMS', $config->enableComponents ) ) {
261 // unset( $titles[7] );
265 if (!CRM_Core_Permission
::check('access deleted contacts') ||
266 !CRM_Core_Permission
::check('delete contacts')
268 unset($titles[self
::DELETE_PERMANENTLY
]);
275 * show tasks selectively based on the permission level
278 * @param int $permission
279 * @param bool $deletedContacts are these tasks for operating on deleted contacts?
281 * @return array set of tasks that are valid for the user
284 static function &permissionedTaskTitles($permission, $deletedContacts = false) {
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'];
295 elseif ($permission == CRM_Core_Permission
::EDIT
) {
296 $tasks = self
::taskTitles();
300 5 => self
::$_tasks[5]['title'],
301 6 => self
::$_tasks[6]['title'],
302 16 => self
::$_tasks[16]['title'],
305 if (isset(self
::$_tasks[12]) &&
306 !empty(self
::$_tasks[12]['title'])
308 $tasks[12] = self
::$_tasks[12]['title'];
311 if (isset(self
::$_tasks[20]) &&
312 !empty(self
::$_tasks[20]['title'])
314 $tasks[20] = self
::$_tasks[20]['title'];
321 * These tasks get added based on the context the user is in
323 * @return array the set of optional tasks for a group of contacts
327 static function &optionalTaskTitle() {
329 14 => self
::$_tasks[14]['title'],
334 static function getTask($value) {
337 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
338 // make it the print task by default
341 return array(CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
342 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),