本文整理汇总了PHP中CRM_Core_Permission类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Permission类的具体用法?PHP CRM_Core_Permission怎么用?PHP CRM_Core_Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPerms
/**
* See if the current user can edit an event.
*
* @param int $eventId
* The event ID.
*
* @return bool
* Whether permission is granted.
*/
public static function checkPerms($eventId)
{
// Admins or users with "edit all events" can edit all events.
if (CRM_Core_Permission::check('edit all events') || CRM_Core_Permission::check('administer CiviCRM')) {
return TRUE;
}
if (!$eventId) {
return NULL;
}
$contactId = CRM_Core_Session::singleton()->get('userID');
// Creators of events can edit their events.
try {
$result = civicrm_api3('Event', 'getcount', array('id' => $eventId, 'created_id' => $contactId));
if (!empty($result)) {
return TRUE;
}
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
CRM_Core_Error::debug_log_message(ts('API Error finding event owner: %1', array('domain' => 'com.aghstrategies.eventpermissions', 1 => $error)));
}
// Hosts of events can edit their events.
try {
// TODO: fix role_id depending upon site-specific naming.
$result = civicrm_api3('Participant', 'getcount', array('contact_id' => $contactId, 'event_id' => $eventId, 'role_id' => "Host"));
if (!empty($result)) {
return TRUE;
}
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
CRM_Core_Error::debug_log_message(ts('API Error finding event owner: %1', array('domain' => 'com.aghstrategies.eventpermissions', 1 => $error)));
}
return FALSE;
}
示例2: whereClause
/**
* Get the permissioned where clause for the user
*
* @param int $type the type of permission needed
* @param array $tables (reference ) add the tables that are needed for the select clause
* @param array $whereTables (reference ) add the tables that are needed for the where clause
* @param int $contactID the contactID for whom the check is made
* @param bool $onlyDeleted whether to include only deleted contacts
* @param bool $skipDeleteClause don't add delete clause if this is true,
* this means it is handled by generating query
*
* @return string the group where clause for this user
* @access public
*/
public static function whereClause($type, &$tables, &$whereTables, $contactID = null, $onlyDeleted = false, $skipDeleteClause = false)
{
// first see if the contact has edit / view all contacts
if (CRM_Core_Permission::check('edit all contacts') || $type == self::VIEW && CRM_Core_Permission::check('view all contacts')) {
$deleteClause = ' ( 1 ) ';
if (!$skipDeleteClause) {
if (CRM_Core_Permission::check('access deleted contacts') and $onlyDeleted) {
$deleteClause = '(contact_a.is_deleted)';
} else {
// CRM-6181
$deleteClause = '(contact_a.is_deleted = 0)';
}
}
return $deleteClause;
}
if ($contactID == null) {
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
}
if (!$contactID) {
$contactID = 0;
// anonymous user
}
require_once 'CRM/ACL/BAO/ACL.php';
return CRM_ACL_BAO_ACL::whereClause($type, $tables, $whereTables, $contactID);
}
示例3: preProcess
public function preProcess()
{
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, FALSE, TRUE);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
if (isset($action)) {
$this->assign('action', $action);
}
$session = CRM_Core_Session::singleton();
$this->_config = new CRM_Core_DAO();
if ($this->_system) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->_contactID = NULL;
} else {
CRM_Utils_System::fatal('You do not have permission to edit preferences');
}
$this->_config->contact_id = NULL;
} else {
if (!$this->_contactID) {
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
CRM_Utils_System::fatal('Could not retrieve contact id');
}
$this->set('cid', $this->_contactID);
}
$this->_config->contact_id = $this->_contactID;
}
$settings = Civi::settings();
foreach ($this->_varNames as $groupName => $settingNames) {
foreach ($settingNames as $settingName => $options) {
$this->_config->{$settingName} = $settings->get($settingName);
}
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例4: preProcess
/**
* Set variables up before form is built.
*/
public function preProcess()
{
if (CRM_Mailing_Info::workflowEnabled()) {
if (!CRM_Core_Permission::check('approve mailings') && !CRM_Core_Permission::check('access CiviMail')) {
$this->redirectToListing();
}
} else {
$this->redirectToListing();
}
// when user come from search context.
$this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
//retrieve mid from different wizard and url contexts
$this->_mailingID = $this->get('mailing_id');
$this->_approveFormOnly = FALSE;
if (!$this->_mailingID) {
$this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, TRUE);
$this->_approveFormOnly = TRUE;
}
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
if (!$this->_mailing->find(TRUE)) {
$this->redirectToListing();
}
}
示例5: preProcess
function preProcess()
{
$this->_mailingID = $this->get('mailing_id');
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->assign('isAdmin', 1);
}
}
示例6: run
/**
* Run dashboard
*
* @return void
* @access public
*/
function run()
{
CRM_Utils_System::setTitle(ts('Dashlets'));
$this->assign('admin', CRM_Core_Permission::check('administer CiviCRM'));
// get all dashlets
$allDashlets = CRM_Core_BAO_Dashboard::getDashlets(FALSE);
// get dashlets for logged in contact
$currentDashlets = CRM_Core_BAO_Dashboard::getContactDashlets();
$contactDashlets = $availableDashlets = array();
foreach ($currentDashlets as $columnNo => $values) {
foreach ($values as $val => $isMinimized) {
list($weight, $dashletID) = explode('-', $val);
$key = "{$dashletID}-{$isMinimized}";
$contactDashlets[$columnNo][$key] = array('label' => $allDashlets[$dashletID]['label'], 'is_reserved' => $allDashlets[$dashletID]['is_reserved']);
unset($allDashlets[$dashletID]);
}
}
foreach ($allDashlets as $dashletID => $values) {
$key = "{$dashletID}-0";
$availableDashlets[$key] = array('label' => $values['label'], 'is_reserved' => $values['is_reserved']);
}
$this->assign('contactDashlets', $contactDashlets);
$this->assign('availableDashlets', $availableDashlets);
return parent::run();
}
示例7: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('action', $this->_action);
$this->assign('context', $this->_context);
//check permission for action.
if (!CRM_Core_Permission::checkActionPermission('CiviGrant', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
}
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->_noteId = null;
if ($this->_id) {
require_once 'CRM/Core/BAO/Note.php';
$noteDAO = new CRM_Core_BAO_Note();
$noteDAO->entity_table = 'civicrm_grant';
$noteDAO->entity_id = $this->_id;
if ($noteDAO->find(true)) {
$this->_noteId = $noteDAO->id;
}
}
//build custom data
CRM_Custom_Form_Customdata::preProcess($this, null, null, 1, 'Grant', $this->_id);
}
示例8: checkPermission
/**
* Lets do permission checking here
* First check for valid mailing, if false return fatal
* Second check for visibility
* Call a hook to see if hook wants to override visibility setting
*/
function checkPermission()
{
if (!$this->_mailing) {
return false;
}
// check for visibility, if visibility is user pages
// return true
if ($this->_mailing->visibility == 'Public Pages') {
return true;
}
// if user is an admin, return true
require_once 'CRM/Core/Permission.php';
if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Core_Permission::check('access CiviMail')) {
return true;
}
// if anon user return false
if (empty($this->_contactID)) {
return false;
}
// if user has recd this mailing return true, else return false
// check in mailing event table for this contact
$sql = "\nSELECT id\nFROM civicrm_mailing_event_queue q\nINNER JOIN civicrm_mailing_job j ON q.job_id = j.id\nWHERE j.mailing_id = %1\nAND q.contact_id = %2\n";
$params = array(1 => array($this->_mailingID, 'Integer'), 2 => array($this->_contactID, 'Integer'));
return CRM_Core_DAO::singleValueQuery($sql, $params) ? true : false;
}
示例9: browse
/**
* Browse all options.
*/
public function browse()
{
$permission = FALSE;
$this->assign('editClass', FALSE);
if (CRM_Core_Permission::check('access CiviCRM')) {
$this->assign('editClass', TRUE);
$permission = TRUE;
}
$daoResult = new CRM_Core_DAO_Persistent();
$daoResult->find();
$schoolValues = array();
while ($daoResult->fetch()) {
$values[$daoResult->id] = array();
CRM_Core_DAO::storeValues($daoResult, $values[$daoResult->id]);
if ($daoResult->is_config == 1) {
$values[$daoResult->id]['action'] = CRM_Core_Action::formLink(self::customizeActionLinks(), NULL, array('id' => $daoResult->id), ts('more'), FALSE, 'persistent.config.actions', 'Persistent', $daoResult->id);
$values[$daoResult->id]['data'] = implode(',', unserialize($daoResult->data));
$configCustomization[$daoResult->id] = $values[$daoResult->id];
}
if ($daoResult->is_config == 0) {
$values[$daoResult->id]['action'] = CRM_Core_Action::formLink(self::stringActionLinks(), NULL, array('id' => $daoResult->id), ts('more'), FALSE, 'persistent.row.actions', 'Persistent', $daoResult->id);
$configStrings[$daoResult->id] = $values[$daoResult->id];
}
}
$rows = array('configTemplates' => $configStrings, 'customizeTemplates' => $configCustomization);
$this->assign('rows', $rows);
}
示例10: creatNewShortcut
public function creatNewShortcut(&$shortCuts)
{
require_once 'CRM/Core/Permission.php';
if (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign')) {
$shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/campaign/add', 'query' => "reset=1&action=add", 'ref' => 'new-campaign', 'title' => ts('Campaign')), array('path' => 'civicrm/survey/add', 'query' => "reset=1&action=add", 'ref' => 'new-survey', 'title' => ts('Survey'))));
}
}
示例11: preProcess
/**
* Set variables up before form is built.
*
* @return void
*/
public function preProcess()
{
$this->_addProfileBottom = CRM_Utils_Array::value('addProfileBottom', $_GET, FALSE);
$this->_profileBottomNum = CRM_Utils_Array::value('addProfileNum', $_GET, 0);
$this->_addProfileBottomAdd = CRM_Utils_Array::value('addProfileBottomAdd', $_GET, FALSE);
$this->_profileBottomNumAdd = CRM_Utils_Array::value('addProfileNumAdd', $_GET, 0);
parent::preProcess();
$this->assign('addProfileBottom', $this->_addProfileBottom);
$this->assign('profileBottomNum', $this->_profileBottomNum);
$urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
$this->assign('addProfileParams', $urlParams);
if ($addProfileBottom = CRM_Utils_Array::value('custom_post_id_multiple', $_POST)) {
foreach (array_keys($addProfileBottom) as $profileNum) {
self::buildMultipleProfileBottom($this, $profileNum);
}
}
$this->assign('perm', 0);
$ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
$ufCreate = CRM_ACL_API::group(CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups);
$ufEdit = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups);
$checkPermission = array(array('administer CiviCRM', 'manage event profiles'));
if (CRM_Core_Permission::check($checkPermission) || !empty($ufCreate) || !empty($ufEdit)) {
$this->assign('perm', 1);
}
$this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd);
$this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd);
$urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
$this->assign('addProfileParamsAdd', $urlParamsAdd);
if ($addProfileBottomAdd = CRM_Utils_Array::value('additional_custom_post_id_multiple', $_POST)) {
foreach (array_keys($addProfileBottomAdd) as $profileNum) {
self::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
}
}
}
示例12: buildQuickForm
/**
* Function to build the form
*
* @return None
* @access public
*/
public function buildQuickForm()
{
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
if (isset($this->_id)) {
$params = array('id' => $this->_id);
CRM_Core_BAO_Navigation::retrieve($params, $this->_defaults);
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'label', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'label'), true);
$this->add('text', 'url', ts('Url'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'url'));
require_once 'CRM/Core/Permission.php';
$permissions = CRM_Core_Permission::basicPermissions(true);
$include =& $this->addElement('advmultiselect', 'permission', ts('Permission') . ' ', $permissions, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
$include->setButtonAttributes('add', array('value' => ts('Add >>')));
$include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$operators = array('AND' => 'AND', 'OR' => 'OR');
$this->add('select', 'permission_operator', ts('Operator'), $operators);
$this->add('checkbox', 'has_separator', ts('Separator?'));
$active = $this->add('checkbox', 'is_active', ts('Enabled?'));
if ($this->_defaults['name'] == 'Home') {
$active->freeze();
} else {
$parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
if (isset($this->_id)) {
unset($parentMenu[$this->_id]);
}
// also unset home.
$homeMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
unset($parentMenu[$homeMenuId]);
$parent = $this->add('select', 'parent_id', ts('Parent'), array('' => ts('-- select --')) + $parentMenu);
}
}
示例13: preProcess
function preProcess()
{
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false);
$this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, false, true);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'update');
if (isset($action)) {
$this->assign('action', $action);
}
$session = CRM_Core_Session::singleton();
require_once 'CRM/Core/DAO/Preferences.php';
$this->_config = new CRM_Core_DAO_Preferences();
$this->_config->domain_id = CRM_Core_Config::domainID();
if ($this->_system) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->_contactID = null;
} else {
CRM_Utils_System::fatal('You do not have permission to edit preferences');
}
$this->_config->is_domain = 1;
$this->_config->contact_id = null;
} else {
if (!$this->_contactID) {
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
CRM_Utils_System::fatal('Could not retrieve contact id');
}
$this->set('cid', $this->_contactID);
}
$this->_config->is_domain = 0;
$this->_config->contact_id = $this->_contactID;
}
$this->_config->find(true);
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'));
}
示例14: preProcess
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*
* @param
*
* @return void
*/
public function preProcess()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
// CRM_Core_Controller validates qfKey for POST requests, but not necessarily
// for GET requests. Allowing GET would therefore be CSRF vulnerability.
CRM_Core_Error::fatal(ts('Preview only supports HTTP POST'));
}
// Inline forms don't get menu-level permission checks
$checkPermission = array(array('administer CiviCRM', 'manage event profiles'));
if (!CRM_Core_Permission::check($checkPermission)) {
CRM_Core_Error::fatal(ts('Permission Denied'));
}
$content = json_decode($_REQUEST['ufData'], TRUE);
foreach (array('ufGroup', 'ufFieldCollection') as $key) {
if (!is_array($content[$key])) {
CRM_Core_Error::fatal("Missing JSON parameter, {$key}");
}
}
//echo '<pre>'.htmlentities(var_export($content, TRUE)) .'</pre>';
//CRM_Utils_System::civiExit();
$fields = CRM_Core_BAO_UFGroup::formatUFFields($content['ufGroup'], $content['ufFieldCollection']);
//$fields = CRM_Core_BAO_UFGroup::getFields(1);
$this->setProfile($fields);
//echo '<pre>'.htmlentities(var_export($fields, TRUE)) .'</pre>';CRM_Utils_System::civiExit();
}
示例15: preProcess
/**
* Heart of the viewing process. The runner gets all the meta data for
* the contact and calls the appropriate type of page to view.
*
* @return void
* @access public
*
*/
function preProcess()
{
$admin = CRM_Core_Permission::check('administer CiviCRM');
$grantSummary = CRM_Grant_BAO_Grant::getGrantSummary($admin);
$this->assign('grantAdmin', $admin);
$this->assign('grantSummary', $grantSummary);
}