/CRM/Contact/Task.php

https://github.com/ksecor/civicrm · PHP · 281 lines · 171 code · 32 blank · 78 comment · 14 complexity · da73661798b7db9f2e32ddbbfe1c3962 MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.1 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2009 |
  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. |
  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 along with this program; if not, contact CiviCRM LLC |
  21. | at info[AT]civicrm[DOT]org. If you have questions about the |
  22. | GNU Affero General Public License or the licensing of CiviCRM, |
  23. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  24. +--------------------------------------------------------------------+
  25. */
  26. /**
  27. *
  28. * @package CRM
  29. * @copyright CiviCRM LLC (c) 2004-2009
  30. * $Id$
  31. *
  32. */
  33. /**
  34. * class to represent the actions that can be performed on a group of contacts
  35. * used by the search forms
  36. *
  37. */
  38. class CRM_Contact_Task {
  39. const
  40. GROUP_CONTACTS = 1,
  41. REMOVE_CONTACTS = 2,
  42. TAG_CONTACTS = 3,
  43. REMOVE_TAGS = 4,
  44. EXPORT_CONTACTS = 5,
  45. EMAIL_CONTACTS = 6,
  46. SMS_CONTACTS = 7,
  47. DELETE_CONTACTS = 8,
  48. HOUSEHOLD_CONTACTS = 9,
  49. ORGANIZATION_CONTACTS = 10,
  50. RECORD_CONTACTS = 11,
  51. MAP_CONTACTS = 12,
  52. SAVE_SEARCH = 13,
  53. SAVE_SEARCH_UPDATE = 14,
  54. PRINT_CONTACTS = 15,
  55. LABEL_CONTACTS = 16,
  56. BATCH_UPDATE = 17,
  57. ADD_EVENT = 18,
  58. PRINT_FOR_CONTACTS = 19;
  59. /**
  60. * the task array
  61. *
  62. * @var array
  63. * @static
  64. */
  65. static $_tasks = null;
  66. /**
  67. * the optional task array
  68. *
  69. * @var array
  70. * @static
  71. */
  72. static $_optionalTasks = null;
  73. static function initTasks( ) {
  74. if ( ! self::$_tasks ) {
  75. self::$_tasks = array(
  76. 1 => array( 'title' => ts( 'Add Contacts to Group' ),
  77. 'class' => 'CRM_Contact_Form_Task_AddToGroup',
  78. 'result' => true ),
  79. 2 => array( 'title' => ts( 'Remove Contacts from Group' ),
  80. 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
  81. 'result' => true ),
  82. 3 => array( 'title' => ts( 'Tag Contacts (assign tags)' ),
  83. 'class' => 'CRM_Contact_Form_Task_AddToTag',
  84. 'result' => true ),
  85. 4 => array( 'title' => ts( 'Untag Contacts (remove tags)' ),
  86. 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
  87. 'result' => true ),
  88. 5 => array( 'title' => ts( 'Export Contacts' ),
  89. 'class' => array( 'CRM_Export_Form_Select',
  90. 'CRM_Export_Form_Map' ),
  91. 'result' => false ),
  92. 6 => array( 'title' => ts( 'Send Email to Contacts' ),
  93. 'class' => 'CRM_Contact_Form_Task_Email',
  94. 'result' => false ),
  95. 7 => array( 'title' => ts( 'Send SMS to Contacts' ),
  96. 'class' => 'CRM_Contact_Form_Task_SMS',
  97. 'result' => true ),
  98. 8 => array( 'title' => ts( 'Delete Contacts' ),
  99. 'class' => 'CRM_Contact_Form_Task_Delete',
  100. 'result' => false ),
  101. 9 => array( 'title' => ts( 'Add Contacts to Household' ),
  102. 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
  103. 'result' => true ),
  104. 10 => array( 'title' => ts( 'Add Contacts to Organization' ),
  105. 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
  106. 'result' => true ),
  107. 11 => array( 'title' => ts( 'Record Activity for Contacts' ),
  108. 'class' => 'CRM_Activity_Form_Activity',
  109. 'result' => true ),
  110. 13 => array( 'title' => ts( 'New Smart Group' ),
  111. 'class' => 'CRM_Contact_Form_Task_SaveSearch',
  112. 'result' => true ),
  113. 14 => array( 'title' => ts( 'Update Smart Group' ),
  114. 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
  115. 'result' => true ),
  116. 15 => array( 'title' => ts( 'Print Contacts' ),
  117. 'class' => 'CRM_Contact_Form_Task_Print',
  118. 'result' => false ),
  119. 16 => array( 'title' => ts( 'Mailing Labels' ),
  120. 'class' => 'CRM_Contact_Form_Task_Label',
  121. 'result' => true ),
  122. 17 => array( 'title' => ts( 'Batch Update via Profile' ),
  123. 'class' => array( 'CRM_Contact_Form_Task_PickProfile',
  124. 'CRM_Contact_Form_Task_Batch' ),
  125. 'result' => true ),
  126. 19 => array( 'title' => ts( 'Print PDF Letter for Contacts' ),
  127. 'class' => 'CRM_Contact_Form_Task_PDF',
  128. 'result' => true ),
  129. 21 => array( 'title' => ts( 'Merge Contacts' ),
  130. 'class' => 'CRM_Contact_Form_Task_Merge',
  131. 'result' => true ),
  132. );
  133. //CRM-4418, check for delete
  134. if ( !CRM_Core_Permission::check( 'delete contacts' ) ) {
  135. unset( self::$_tasks[8] );
  136. }
  137. //show map action only if map provider and key is set
  138. $config =& CRM_Core_Config::singleton( );
  139. if ( $config->mapProvider && $config->mapAPIKey ) {
  140. self::$_tasks[12] = array( 'title' => ts( 'Map Contacts'),
  141. 'class' => 'CRM_Contact_Form_Task_Map',
  142. 'result' => false );
  143. }
  144. if ( CRM_Core_Permission::access( 'CiviEvent' ) ) {
  145. self::$_tasks[18] = array( 'title' => ts( 'Add Contacts to Event' ),
  146. 'class' => 'CRM_Event_Form_Participant',
  147. 'result' => true );
  148. }
  149. if ( CRM_Core_Permission::access( 'CiviMail' ) ) {
  150. self::$_tasks[20] = array( 'title' => ts( 'Schedule/Send a Mass Mailing' ),
  151. 'class' => array( 'CRM_Mailing_Form_Group',
  152. 'CRM_Mailing_Form_Settings',
  153. 'CRM_Mailing_Form_Upload',
  154. 'CRM_Mailing_Form_Test',
  155. 'CRM_Mailing_Form_Schedule'
  156. ),
  157. 'result' => false
  158. );
  159. }
  160. self::$_tasks += CRM_Core_Component::taskList( );
  161. require_once 'CRM/Utils/Hook.php';
  162. CRM_Utils_Hook::searchTasks( 'contact', self::$_tasks );
  163. asort(self::$_tasks);
  164. }
  165. }
  166. /**
  167. * These tasks are the core set of tasks that the user can perform
  168. * on a contact / group of contacts
  169. *
  170. * @return array the set of tasks for a group of contacts
  171. * @static
  172. * @access public
  173. */
  174. static function &taskTitles()
  175. {
  176. self::initTasks( );
  177. $titles = array( );
  178. foreach ( self::$_tasks as $id => $value ) {
  179. $titles[$id] = $value['title'];
  180. }
  181. // hack unset update saved search and print contacts
  182. unset( $titles[14] );
  183. unset( $titles[15] );
  184. $config =& CRM_Core_Config::singleton( );
  185. require_once 'CRM/Utils/Mail.php';
  186. if ( !CRM_Utils_Mail::validOutBoundMail() ) {
  187. unset( $titles[6 ] );
  188. unset( $titles[20] );
  189. }
  190. if ( ! in_array( 'CiviSMS', $config->enableComponents ) ) {
  191. unset( $titles[7] );
  192. }
  193. return $titles;
  194. }
  195. /**
  196. * show tasks selectively based on the permission level
  197. * of the user
  198. *
  199. * @param int $permission
  200. *
  201. * @return array set of tasks that are valid for the user
  202. * @access public
  203. */
  204. static function &permissionedTaskTitles( $permission ) {
  205. $tasks = array( );
  206. if ( $permission == CRM_Core_Permission::EDIT ) {
  207. $tasks = self::taskTitles( );
  208. } else {
  209. $tasks = array(
  210. 5 => self::$_tasks[ 5]['title'],
  211. 6 => self::$_tasks[ 6] ['title'],
  212. 12 => self::$_tasks[12]['title'],
  213. 16 => self::$_tasks[16]['title'],
  214. );
  215. if ( ! self::$_tasks[12]['title'] ) {
  216. //usset it, No edit permission and Map provider info
  217. //absent, drop down shows blank space
  218. unset( $tasks[12] );
  219. }
  220. //CRM-4418, lets keep delete for View and Edit so user can tweak ACL
  221. if ( CRM_Core_Permission::check( 'delete contacts' ) ) {
  222. $tasks[8] = self::$_tasks[8]['title'];
  223. }
  224. }
  225. return $tasks;
  226. }
  227. /**
  228. * These tasks get added based on the context the user is in
  229. *
  230. * @return array the set of optional tasks for a group of contacts
  231. * @static
  232. * @access public
  233. */
  234. static function &optionalTaskTitle()
  235. {
  236. $tasks = array(
  237. 14 => self::$_tasks[14]['title'],
  238. );
  239. return $tasks;
  240. }
  241. static function getTask( $value ) {
  242. self::initTasks( );
  243. if ( ! CRM_Utils_Array::value( $value, self::$_tasks ) ) {
  244. $value = 15; // make it the print task by default
  245. }
  246. return array( self::$_tasks[$value]['class' ],
  247. self::$_tasks[$value]['result'] );
  248. }
  249. }