$link) { if ($link['name'] == 'Edit') { unset($links[$key]); } } } } } /** * Implements hook_civicrm_pre(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre */ function batchexportperm_civicrm_pre($op, $objectName, $id, &$params) { if ($op == 'edit' && $objectName == 'Contribution') { _batchexportperm_civicrm_check_permission($id); } } /** * Implements hook_civicrm_apiWrappers(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers */ function batchexportperm_civicrm_apiWrappers(&$wrappers, $apiRequest) { if ($apiRequest['entity'] == 'Contribution' && $apiRequest['action'] == 'create') { $contibutionId = CRM_Utils_Array::value('id', $apiRequest['params']); _batchexportperm_civicrm_check_permission($contibutionId, 'exception'); } } /** * Implements hook_civicrm_preProcess(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess */ function batchexportperm_civicrm_preProcess($formName, &$form) { if ($formName == 'CRM_Contribute_Form_Contribution' && $form->_action & CRM_Core_Action::UPDATE) { $contributionId = $form->_id; _batchexportperm_civicrm_check_permission($contributionId); } } /** * Check if user has permission to update contribution. * * @param int $contributionId * @param string $errorType */ function _batchexportperm_civicrm_check_permission($contributionId, $errorType = NULL) { if (empty($contributionId) || _batchexportperm_civicrm_allow_contribution_to_edit($contributionId)) { return FALSE; } $message = ts('You do not have the necessary permission to edit this contribution.'); if ($errorType == 'exception') { throw new API_Exception($message); } else { CRM_Core_Error::statusBounce($message); } } /** * Check if user has permission to update contribution. * * @param int $contributionId */ function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) { $customFieldId = civicrm_api3('CustomField', 'getvalue', [ 'return' => "id", 'custom_group_id' => "Batch_Details", 'name' => "Export_Date", ]); $exportDate = civicrm_api3('Contribution', 'getvalue', [ 'return' => "custom_{$customFieldId}", 'id' => $contributionId, ]); if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) { return TRUE; } return FALSE; }