3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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, 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;
50 static $_tasks = NULL;
53 * the optional task array
58 static $_optionalTasks = NULL;
60 static function initTasks() {
62 self
::$_tasks = array(
63 1 => array('title' => ts('Add Contacts to Group'),
64 'class' => 'CRM_Contact_Form_Task_AddToGroup',
66 2 => array('title' => ts('Remove Contacts from Group'),
67 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
69 3 => array('title' => ts('Tag Contacts (assign tags)'),
70 'class' => 'CRM_Contact_Form_Task_AddToTag',
72 4 => array('title' => ts('Untag Contacts (remove tags)'),
73 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
75 5 => array('title' => ts('Export Contacts'),
77 'CRM_Export_Form_Select',
78 'CRM_Export_Form_Map',
82 6 => array('title' => ts('Send Email to Contacts'),
83 'class' => 'CRM_Contact_Form_Task_Email',
86 7 => array('title' => ts('Send SMS to Contacts'),
87 'class' => 'CRM_Contact_Form_Task_SMS',
90 8 => array('title' => ts('Delete Contacts'),
91 'class' => 'CRM_Contact_Form_Task_Delete',
94 11 => array('title' => ts('Record Activity for Contacts'),
95 'class' => 'CRM_Activity_Form_Activity',
97 13 => array('title' => ts('New Smart Group'),
98 'class' => 'CRM_Contact_Form_Task_SaveSearch',
101 14 => array('title' => ts('Update Smart Group'),
102 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
105 15 => array('title' => ts('Print Contacts'),
106 'class' => 'CRM_Contact_Form_Task_Print',
109 16 => array('title' => ts('Mailing Labels'),
110 'class' => 'CRM_Contact_Form_Task_Label',
113 17 => array('title' => ts('Batch Update via Profile'),
115 'CRM_Contact_Form_Task_PickProfile',
116 'CRM_Contact_Form_Task_Batch',
120 19 => array('title' => ts('Print PDF Letter for Contacts'),
121 'class' => 'CRM_Contact_Form_Task_PDF',
124 22 => array('title' => ts('Unhold Emails'),
125 'class' => 'CRM_Contact_Form_Task_Unhold',
127 25 => array('title' => ts('Alter Contact Communication Preferences'),
128 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
130 self
::RESTORE
=> array(
131 'title' => ts('Restore Contacts'),
132 'class' => 'CRM_Contact_Form_Task_Delete',
135 self
::DELETE_PERMANENTLY
=> array(
136 'title' => ts('Delete Permanently'),
137 'class' => 'CRM_Contact_Form_Task_Delete',
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',
148 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
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',
158 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
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',
169 //CRM-4418, check for delete
170 if (!CRM_Core_Permission
::check('delete contacts')) {
171 unset(self
::$_tasks[8]);
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();
178 if ($config->mapProvider
&&
179 ($config->mapProvider
== 'Google' ||
180 ($config->mapProvider
== 'OpenStreetMaps' ||
181 $config->geoProvider
== 'Google'
185 self
::$_tasks[12] = array('title' => ts('Map Contacts'),
186 'class' => 'CRM_Contact_Form_Task_Map',
191 if (CRM_Core_Permission
::access('CiviEvent')) {
192 self
::$_tasks[18] = array('title' => ts('Add Contacts to Event'),
193 'class' => 'CRM_Event_Form_Participant',
197 if (CRM_Core_Permission
::access('CiviMail')) {
198 self
::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'),
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',
209 elseif (CRM_Mailing_Info
::workflowEnabled() &&
210 CRM_Core_Permission
::check('create mailings')
212 self
::$_tasks[20] = array('title' => ts('Create a Mass Mailing'),
214 'CRM_Mailing_Form_Group',
215 'CRM_Mailing_Form_Settings',
216 'CRM_Mailing_Form_Upload',
217 'CRM_Mailing_Form_Test',
223 self
::$_tasks +
= CRM_Core_Component
::taskList();
225 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
227 asort(self
::$_tasks);
232 * These tasks are the core set of tasks that the user can perform
233 * on a contact / group of contacts
235 * @return array the set of tasks for a group of contacts
239 static function &taskTitles() {
243 foreach (self
::$_tasks as $id => $value) {
244 $titles[$id] = $value['title'];
247 // hack unset update saved search and print contacts
251 $config = CRM_Core_Config
::singleton();
253 if (!CRM_Utils_Mail
::validOutBoundMail()) {
258 // if ( ! in_array( 'CiviSMS', $config->enableComponents ) ) {
259 // unset( $titles[7] );
263 if (!CRM_Core_Permission
::check('access deleted contacts') ||
264 !CRM_Core_Permission
::check('delete contacts')
266 unset($titles[self
::DELETE_PERMANENTLY
]);
273 * show tasks selectively based on the permission level
276 * @param int $permission
277 * @param bool $deletedContacts are these tasks for operating on deleted contacts?
279 * @return array set of tasks that are valid for the user
282 static function &permissionedTaskTitles($permission, $deletedContacts = false) {
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'];
293 elseif ($permission == CRM_Core_Permission
::EDIT
) {
294 $tasks = self
::taskTitles();
298 5 => self
::$_tasks[5]['title'],
299 6 => self
::$_tasks[6]['title'],
300 16 => self
::$_tasks[16]['title'],
303 if (isset(self
::$_tasks[12]) &&
304 !empty(self
::$_tasks[12]['title'])
306 $tasks[12] = self
::$_tasks[12]['title'];
309 if (isset(self
::$_tasks[20]) &&
310 !empty(self
::$_tasks[20]['title'])
312 $tasks[20] = self
::$_tasks[20]['title'];
319 * These tasks get added based on the context the user is in
321 * @return array the set of optional tasks for a group of contacts
325 static function &optionalTaskTitle() {
327 14 => self
::$_tasks[14]['title'],
332 static function getTask($value) {
335 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
336 // make it the print task by default
339 return array(CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
340 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),