diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index e057dafd4a8c..35f43ef77bf6 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3006,6 +3006,79 @@ public static function contextMenu($contactId = NULL) { ), ); + $menu['otherActions'] = array( + 'print' => array( + 'title' => ts('Print Summary'), + 'description' => ts('Printer-friendly view of this page.'), + 'weight' => 5, + 'ref' => 'crm-contact-print', + 'key' => 'print', + 'tab' => 'print', + 'href' => CRM_Utils_System::url('civicrm/contact/view/print', + "reset=1&print=1" + ), + 'class' => 'print', + 'icon' => 'crm-i fa-print', + ), + 'vcard' => array( + 'title' => ts('vCard'), + 'description' => ts('vCard record for this contact.'), + 'weight' => 10, + 'ref' => 'crm-contact-vcard', + 'key' => 'vcard', + 'tab' => 'vcard', + 'href' => CRM_Utils_System::url('civicrm/contact/view/vcard', + "reset=1" + ), + 'class' => 'vcard', + 'icon' => 'crm-i fa-list-alt', + ), + ); + + if (CRM_Core_Permission::check('access Contact Dashboard')) { + $menu['otherActions']['dashboard'] = array( + 'title' => ts('Contact Dashboard'), + 'description' => ts('Contact Dashboard'), + 'weight' => 15, + 'ref' => 'crm-contact-dashboard', + 'key' => 'dashboard', + 'tab' => 'dashboard', + 'class' => 'dashboard', + // NOTE: As an alternative you can also build url on CMS specific way + // as CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId) + 'href' => CRM_Utils_System::url('civicrm/user', "reset=1&id={$contactId}"), + 'icon' => 'crm-i fa-tachometer', + ); + } + + $uid = CRM_Core_BAO_UFMatch::getUFId($contactId); + if ($uid) { + $menu['otherActions']['user-record'] = array( + 'title' => ts('User Record'), + 'description' => ts('User Record'), + 'weight' => 20, + 'ref' => 'crm-contact-user-record', + 'key' => 'user-record', + 'tab' => 'user-record', + 'class' => 'user-record', + 'href' => CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId), + 'icon' => 'crm-i fa-user', + ); + } + elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) { + $menu['otherActions']['user-add'] = array( + 'title' => ts('Create User Record'), + 'description' => ts('Create User Record'), + 'weight' => 25, + 'ref' => 'crm-contact-user-add', + 'key' => 'user-add', + 'tab' => 'user-add', + 'class' => 'user-add', + 'href' => CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $contactId), + 'icon' => 'crm-i fa-user-plus', + ); + } + CRM_Utils_Hook::summaryActions($menu, $contactId); //1. check for component is active. //2. check for user permissions. @@ -3023,89 +3096,126 @@ public static function contextMenu($contactId = NULL) { ); $corePermission = CRM_Core_Permission::getPermission(); - $config = CRM_Core_Config::singleton(); - $contextMenu = array(); foreach ($menu as $key => $values) { - $componentName = CRM_Utils_Array::value('component', $values); + if ($key != 'otherActions') { - // if component action - make sure component is enable. - if ($componentName && !in_array($componentName, $config->enableComponents)) { - continue; - } - - // make sure user has all required permissions. - $hasAllPermissions = FALSE; - - $permissions = CRM_Utils_Array::value('permissions', $values); - if (!is_array($permissions) || empty($permissions)) { - $hasAllPermissions = TRUE; - } - - // iterate for required permissions in given permissions array. - if (!$hasAllPermissions) { - $hasPermissions = 0; - foreach ($permissions as $permission) { - if (CRM_Core_Permission::check($permission)) { - $hasPermissions++; - } - } - - if (count($permissions) == $hasPermissions) { - $hasAllPermissions = TRUE; + // user does not have necessary permissions. + if (!self::checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $values)) { + continue; } - - // if still user does not have required permissions, check acl. - if (!$hasAllPermissions && $values['ref'] != 'delete-contact') { - if (in_array($values['ref'], $aclPermissionedTasks) && - $corePermission == CRM_Core_Permission::EDIT - ) { - $hasAllPermissions = TRUE; - } - elseif (in_array($values['ref'], array( - 'new-email', - ))) { - // grant permissions for these tasks. - $hasAllPermissions = TRUE; - } + // build directly accessible action menu. + if (in_array($values['ref'], array( + 'view-contact', + 'edit-contact', + ))) { + $contextMenu['primaryActions'][$key] = array( + 'title' => $values['title'], + 'ref' => $values['ref'], + 'class' => CRM_Utils_Array::value('class', $values), + 'key' => $values['key'], + ); + continue; } - } - // user does not have necessary permissions. - if (!$hasAllPermissions) { - continue; - } - - // build directly accessible action menu. - if (in_array($values['ref'], array( - 'view-contact', - 'edit-contact', - ))) { - $contextMenu['primaryActions'][$key] = array( + // finally get menu item for -more- action widget. + $contextMenu['moreActions'][$values['weight']] = array( 'title' => $values['title'], 'ref' => $values['ref'], + 'href' => CRM_Utils_Array::value('href', $values), + 'tab' => CRM_Utils_Array::value('tab', $values), 'class' => CRM_Utils_Array::value('class', $values), 'key' => $values['key'], ); - continue; } + else { + foreach ($values as $value) { + // user does not have necessary permissions. + if (!self::checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $value)) { + continue; + } - // finally get menu item for -more- action widget. - $contextMenu['moreActions'][$values['weight']] = array( - 'title' => $values['title'], - 'ref' => $values['ref'], - 'href' => CRM_Utils_Array::value('href', $values), - 'tab' => CRM_Utils_Array::value('tab', $values), - 'class' => CRM_Utils_Array::value('class', $values), - 'key' => $values['key'], - ); + // finally get menu item for -more- action widget. + $contextMenu['otherActions'][$value['weight']] = array( + 'title' => $value['title'], + 'ref' => $value['ref'], + 'href' => CRM_Utils_Array::value('href', $value), + 'tab' => CRM_Utils_Array::value('tab', $value), + 'class' => CRM_Utils_Array::value('class', $value), + 'icon' => CRM_Utils_Array::value('icon', $value), + 'key' => $value['key'], + ); + } + } } ksort($contextMenu['moreActions']); + ksort($contextMenu['otherActions']); return $contextMenu; } + /** + * Check if user has permissions to access items in action menu. + * + * @param array $aclPermissionedTasks + * Array containing ACL related tasks. + * @param string $corePermission + * The permission of the user (edit or view or null). + * @param array $menuOptions + * Array containing params of the menu (title, href, etc). + * + * @return bool + * TRUE if user has all permissions, FALSE if otherwise. + */ + public static function checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $menuOptions) { + $componentName = CRM_Utils_Array::value('component', $menuOptions); + + // if component action - make sure component is enable. + if ($componentName && !in_array($componentName, CRM_Core_Config::singleton()->enableComponents)) { + return FALSE; + } + + // make sure user has all required permissions. + $hasAllPermissions = FALSE; + + $permissions = CRM_Utils_Array::value('permissions', $menuOptions); + if (!is_array($permissions) || empty($permissions)) { + $hasAllPermissions = TRUE; + } + + // iterate for required permissions in given permissions array. + if (!$hasAllPermissions) { + $hasPermissions = 0; + foreach ($permissions as $permission) { + if (CRM_Core_Permission::check($permission)) { + $hasPermissions++; + } + } + + if (count($permissions) == $hasPermissions) { + $hasAllPermissions = TRUE; + } + + // if still user does not have required permissions, check acl. + if (!$hasAllPermissions && $menuOptions['ref'] != 'delete-contact') { + if (in_array($values['ref'], $aclPermissionedTasks) && + $corePermission == CRM_Core_Permission::EDIT + ) { + $hasAllPermissions = TRUE; + } + elseif (in_array($menuOptions['ref'], array( + 'new-email', + ))) { + // grant permissions for these tasks. + $hasAllPermissions = TRUE; + } + } + } + + return $hasAllPermissions; + } + /** * Retrieve display name of contact that address is shared. * diff --git a/templates/CRM/Contact/Page/Inline/Actions.tpl b/templates/CRM/Contact/Page/Inline/Actions.tpl index e513a19637c4..d92432b9f93b 100644 --- a/templates/CRM/Contact/Page/Inline/Actions.tpl +++ b/templates/CRM/Contact/Page/Inline/Actions.tpl @@ -34,39 +34,17 @@
{include file="CRM/Activity/Form/ActivityLinks.tpl" as_select=false}
- -
-