Example #1
0
 /**
  * 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);
     }
 }
Example #2
0
 /**
  * Build form.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildForm(&$form)
 {
     // We should not build form elements in dashlet mode.
     if ($form->_section) {
         return;
     }
     // Check role based permission.
     $instanceID = $form->getVar('_id');
     if ($instanceID && !CRM_Report_Utils_Report::isInstanceGroupRoleAllowed($instanceID)) {
         $url = CRM_Utils_System::url('civicrm/report/list', 'reset=1');
         CRM_Core_Error::statusBounce(ts('You do not have permission to access this report.'), $url);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_ReportInstance');
     $form->add('text', 'title', ts('Report Title'), $attributes['title']);
     $form->add('text', 'description', ts('Report Description'), $attributes['description']);
     $form->add('text', 'email_subject', ts('Subject'), $attributes['email_subject']);
     $form->add('text', 'email_to', ts('To'), $attributes['email_to']);
     $form->add('text', 'email_cc', ts('CC'), $attributes['email_subject']);
     $form->add('number', 'row_count', ts('Limit Dashboard Results'), array('class' => 'four', 'min' => 1));
     $form->add('textarea', 'report_header', ts('Report Header'), $attributes['header']);
     $form->add('textarea', 'report_footer', ts('Report Footer'), $attributes['footer']);
     $form->addElement('checkbox', 'is_navigation', ts('Include Report in Navigation Menu?'), NULL, array('onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);"));
     $form->addElement('select', 'view_mode', ts('Configure link to...'), array('view' => ts('View Results'), 'criteria' => ts('Show Criteria')));
     $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?'));
     $form->add('number', 'cache_minutes', ts('Cache dashlet for'), array('class' => 'four', 'min' => 1));
     $form->addElement('checkbox', 'add_to_my_reports', ts('Add to My Reports?'), NULL);
     $form->addElement('checkbox', 'is_reserved', ts('Reserved Report?'));
     if (!CRM_Core_Permission::check('administer reserved reports')) {
         $form->freeze('is_reserved');
     }
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework != 'Joomla' || $config->userFramework != 'WordPress') {
         $form->addElement('select', 'permission', ts('Permission'), array('0' => ts('Everyone (includes anonymous)')) + CRM_Core_Permission::basicPermissions());
         // prepare user_roles to save as names not as ids
         if (function_exists('user_roles')) {
             $user_roles_array = user_roles();
             foreach ($user_roles_array as $key => $value) {
                 $user_roles[$value] = $value;
             }
             $grouprole =& $form->addElement('advmultiselect', 'grouprole', ts('ACL Group/Role'), $user_roles, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
             $grouprole->setButtonAttributes('add', array('value' => ts('Add >>')));
             $grouprole->setButtonAttributes('remove', array('value' => ts('<< Remove')));
         }
     }
     // navigation field
     $parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
     $form->add('select', 'parent_id', ts('Parent Menu'), array('' => ts('- select -')) + $parentMenu);
     // For now we only providing drilldown for one primary detail report only. In future this could be multiple reports
     foreach ($form->_drilldownReport as $reportUrl => $drillLabel) {
         $instanceList = CRM_Report_Utils_Report::getInstanceList($reportUrl);
         if (count($instanceList) > 1) {
             $form->add('select', 'drilldown_id', $drillLabel, array('' => ts('- select -')) + $instanceList);
         }
         break;
     }
     $form->addButtons(array(array('type' => 'submit', 'name' => ts('Save Report'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $form->addFormRule(array('CRM_Report_Form_Instance', 'formRule'), $form);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $permissions = array_flip(CRM_Core_Permission::basicPermissions());
     $this->addCheckBox('object_table', ts('ACL Type'), $permissions, NULL, NULL, TRUE, NULL, array('</td><td>', '</td></tr><tr><td>'));
     $label = ts('Role');
     $role = array('-1' => ts('- select role -'), '0' => ts('Everyone')) + CRM_Core_OptionGroup::values('acl_role');
     $entityID =& $this->add('select', 'entity_id', $label, $role, TRUE);
     if ($this->_id) {
         $entityID->freeze();
     }
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->addFormRule(array('CRM_ACL_Form_ACLBasic', 'formRule'));
 }
Example #4
0
 static function buildForm(&$form)
 {
     $attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_Instance');
     $form->add('text', 'title', ts('Report Title'), $attributes['title']);
     $form->add('text', 'description', ts('Report Description'), $attributes['description']);
     $form->add('text', 'email_subject', ts('Subject'), $attributes['email_subject']);
     $form->add('text', 'email_to', ts('To'), $attributes['email_to']);
     $form->add('text', 'email_cc', ts('CC'), $attributes['email_subject']);
     $form->add('textarea', 'report_header', ts('Report Header'), $attributes['header']);
     $form->add('textarea', 'report_footer', ts('Report Footer'), $attributes['footer']);
     $form->addElement('checkbox', 'is_navigation', ts('Include Report in Navigation Menu?'), null, array('onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);"));
     $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?'));
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework != 'Joomla') {
         $form->addElement('select', 'permission', ts('Permission'), array('0' => '- Any One -') + CRM_Core_Permission::basicPermissions());
     }
     // navigation field
     $parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
     $form->add('select', 'parent_id', ts('Parent Menu'), array('' => ts('-- select --')) + $parentMenu);
     $form->addButtons(array(array('type' => 'submit', 'name' => ts('Save Report'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $form->addFormRule(array('CRM_Report_Form_Instance', 'formRule'), $form);
 }
Example #5
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Menu Item'));
     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'));
     $permissions = array();
     foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) {
         $permissions[] = array('id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals));
     }
     $this->add('text', 'permission', ts('Permission'), array('placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(array('data' => array('results' => $permissions, 'text' => 'label')))));
     $operators = array('AND' => ts('AND'), 'OR' => ts('OR'));
     $this->add('select', 'permission_operator', NULL, $operators);
     //make separator location configurable
     $separator = array(ts('None'), ts('After menu element'), ts('Before menu element'));
     $this->add('select', 'has_separator', ts('Separator'), $separator);
     $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
     if (CRM_Utils_Array::value('name', $this->_defaults) == '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]);
         $this->add('select', 'parent_id', ts('Parent'), array('' => ts('Top level')) + $parentMenu, FALSE, array('class' => 'crm-select2'));
     }
 }
 /**
  * Browse all acls.
  *
  * @return void
  */
 public function browse()
 {
     // get all acl's sorted by weight
     $acl = array();
     $query = "\n  SELECT *\n    FROM civicrm_acl\n   WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )\nORDER BY entity_id\n";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     $roles = CRM_Core_OptionGroup::values('acl_role');
     $permissions = CRM_Core_Permission::basicPermissions();
     while ($dao->fetch()) {
         if (!array_key_exists($dao->entity_id, $acl)) {
             $acl[$dao->entity_id] = array();
             $acl[$dao->entity_id]['name'] = $dao->name;
             $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
             $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
             $acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
             $acl[$dao->entity_id]['is_active'] = 1;
             if ($acl[$dao->entity_id]['entity_id']) {
                 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
             } else {
                 $acl[$dao->entity_id]['entity'] = ts('Any Role');
             }
             // form all action links
             $action = array_sum(array_keys($this->links()));
             $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->entity_id), ts('more'), FALSE, 'aclRole.manage.action', 'ACLRole', $dao->entity_id);
         } elseif (!empty($permissions[$dao->object_table])) {
             $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
         }
     }
     $this->assign('rows', $acl);
 }
Example #7
0
 /**
  * Do general cleanup of module permissions.
  */
 public function cleanupPermissions()
 {
     $module_files = CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles();
     if ($this->userPermissionClass->isModulePermissionSupported()) {
         // Can store permissions -- so do it!
         $this->userPermissionClass->upgradePermissions(CRM_Core_Permission::basicPermissions());
     } else {
         // Cannot store permissions -- warn if any modules require them
         $modules_with_perms = array();
         foreach ($module_files as $module_file) {
             $perms = $this->userPermissionClass->getModulePermissions($module_file['prefix']);
             if (!empty($perms)) {
                 $modules_with_perms[] = $module_file['prefix'];
             }
         }
         if (!empty($modules_with_perms)) {
             CRM_Core_Session::setStatus(ts('Some modules define permissions, but the CMS cannot store them: %1', array(1 => implode(', ', $modules_with_perms))), ts('Permission Error'), 'error');
         }
     }
 }
Example #8
0
 /**
  * Set default values.
  *
  * @param CRM_Core_Form $form
  * @param array $defaults
  */
 public static function setDefaultValues(&$form, &$defaults)
 {
     // we should not build form elements in dashlet mode.
     if ($form->_section) {
         return;
     }
     $instanceID = $form->getVar('_id');
     $navigationDefaults = array();
     if (!isset($defaults['permission'])) {
         $permissions = array_flip(CRM_Core_Permission::basicPermissions());
         $defaults['permission'] = $permissions['CiviReport: access CiviReport'];
     }
     $config = CRM_Core_Config::singleton();
     // Add a special region for the default HTML header of printed reports.  It
     // won't affect reports with customized headers, just ones with the default.
     $printHeaderRegion = CRM_Core_Region::instance('default-report-header', FALSE);
     $htmlHeader = $printHeaderRegion ? $printHeaderRegion->render('', FALSE) : '';
     $defaults['report_header'] = $report_header = "<html>\n  <head>\n    <title>CiviCRM Report</title>\n    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n    <style type=\"text/css\">@import url({$config->userFrameworkResourceURL}css/print.css);</style>\n    {$htmlHeader}\n  </head>\n  <body><div id=\"crm-container\">";
     $defaults['report_footer'] = $report_footer = "<p><img src=\"{$config->userFrameworkResourceURL}i/powered_by.png\" /></p></div></body>\n</html>\n";
     // CRM-17225 view_mode currently supports 'view' or 'criteria'.
     // Prior to 4.7 'view' meant reset=1 in the url & if not set
     // then show criteria.
     // From 4.7 we will pro-actively set 'force=1' but still respect the old behaviour.
     // we may look to add pdf, print_view, csv & various charts as these could simply
     // be added to the url allowing us to conceptualise 'view right now' vs saved view
     // & using a multiselect (option value?) could help here.
     // Note that accessing reports without reset=1 in the url turns out to be
     // dangerous as it seems to carry actions like 'delete' from one report to another.
     $defaults['view_mode'] = 'view';
     $output = CRM_Utils_Request::retrieve('output', 'String');
     if ($output == 'criteria') {
         $defaults['view_mode'] = 'criteria';
     }
     if ($instanceID) {
         // this is already retrieved via Form.php
         $defaults['description'] = CRM_Utils_Array::value('description', $defaults);
         if (!empty($defaults['header'])) {
             $defaults['report_header'] = $defaults['header'];
         }
         if (!empty($defaults['footer'])) {
             $defaults['report_footer'] = $defaults['footer'];
         }
         if (!empty($defaults['navigation_id'])) {
             // Get the default navigation parent id.
             $params = array('id' => $defaults['navigation_id']);
             CRM_Core_BAO_Navigation::retrieve($params, $navigationDefaults);
             $defaults['is_navigation'] = 1;
             $defaults['parent_id'] = CRM_Utils_Array::value('parent_id', $navigationDefaults);
             if (!empty($navigationDefaults['is_active'])) {
                 $form->assign('is_navigation', TRUE);
             }
             // A saved view mode will over-ride any url assumptions.
             if (strpos($navigationDefaults['url'], 'output=criteria')) {
                 $defaults['view_mode'] = 'criteria';
             }
             if (!empty($navigationDefaults['id'])) {
                 $form->_navigation['id'] = $navigationDefaults['id'];
                 $form->_navigation['parent_id'] = !empty($navigationDefaults['parent_id']) ? $navigationDefaults['parent_id'] : NULL;
             }
         }
         if (!empty($defaults['grouprole'])) {
             foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['grouprole']) as $value) {
                 $groupRoles[] = $value;
             }
             $defaults['grouprole'] = $groupRoles;
         }
     } elseif (property_exists($form, '_description')) {
         $defaults['description'] = $form->_description;
     }
 }
 static function setDefaultValues(&$form, &$defaults)
 {
     // we should not build form elements in dashlet mode
     if ($form->_section) {
         return;
     }
     $instanceID = $form->getVar('_id');
     $navigationDefaults = array();
     if (!isset($defaults['permission'])) {
         $permissions = array_flip(CRM_Core_Permission::basicPermissions());
         $defaults['permission'] = $permissions['CiviReport: access CiviReport'];
     }
     $config = CRM_Core_Config::singleton();
     $defaults['report_header'] = $report_header = "<html>\n  <head>\n    <title>CiviCRM Report</title>\n    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n    <style type=\"text/css\">@import url({$config->userFrameworkResourceURL}css/print.css);</style>\n  </head>\n  <body><div id=\"crm-container\">";
     $defaults['report_footer'] = $report_footer = "<p><img src=\"{$config->userFrameworkResourceURL}i/powered_by.png\" /></p></div></body>\n</html>\n";
     if ($instanceID) {
         // this is already retrieved via Form.php
         $defaults['description'] = CRM_Utils_Array::value('description', $defaults);
         $defaults['report_header'] = CRM_Utils_Array::value('header', $defaults);
         $defaults['report_footer'] = CRM_Utils_Array::value('footer', $defaults);
         if (!empty($defaults['navigation_id'])) {
             //get the default navigation parent id
             $params = array('id' => $defaults['navigation_id']);
             CRM_Core_BAO_Navigation::retrieve($params, $navigationDefaults);
             $defaults['is_navigation'] = 1;
             $defaults['parent_id'] = CRM_Utils_Array::value('parent_id', $navigationDefaults);
             if (!empty($navigationDefaults['is_active'])) {
                 $form->assign('is_navigation', TRUE);
             }
             if (!empty($navigationDefaults['id'])) {
                 $form->_navigation['id'] = $navigationDefaults['id'];
                 $form->_navigation['parent_id'] = $navigationDefaults['parent_id'];
             }
         }
         if (!empty($defaults['grouprole'])) {
             foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['grouprole']) as $value) {
                 $grouproles[] = $value;
             }
             $defaults['grouprole'] = $grouproles;
         }
     } else {
         if (property_exists($form, '_description')) {
             $defaults['description'] = $form->_description;
         }
     }
 }
Example #10
0
 /**
  * Get the core civicrm permissions array.
  * This function should be shared from a similar one in
  * distmaker/utils/joomlaxml.php
  *
  * @param bool $descriptions
  *   Whether to return permission descriptions
  *
  * @return array
  *   civicrm permissions
  */
 public static function getPermissionArray($descriptions = FALSE)
 {
     global $civicrm_root;
     $permissions = CRM_Core_Permission::basicPermissions(FALSE, $descriptions);
     $perms_array = array();
     foreach ($permissions as $perm => $title) {
         //order matters here, but we deal with that later
         $perms_array[CRM_Utils_String::munge(strtolower($perm))] = $title;
     }
     return $perms_array;
 }
/**
 * Should we be adding ACLs in this instance. If we don't add them the user
 * will not be able to see anything. We check if the install has the permissions
 * hook implemented correctly & if so only allow view & edit based on those.
 *
 * Otherwise all users get these permissions added (4.2 vs 4.3 / other CMS issues)
 *
 * @param integer $type type of operation
 */
function _multisite_add_permissions($type)
{
    $hookclass = 'CRM_Utils_Hook';
    if (!method_exists($hookclass, 'permissions') && !method_exists($hookclass, 'permission')) {
        // ie. unpatched 4.2 so we can't check for extra declared permissions
        // & default to applying this to all
        return TRUE;
    }
    if ($type == 'group') {
        // @fixme only handling we have for this at the moment
        return TRUE;
    }
    // extra check to make sure that hook is properly implemented
    // if not we won't check for it. NB view all contacts in domain is enough checking
    $declaredPermissions = CRM_Core_Permission::basicPermissions();
    if (!array_key_exists('view all contacts in domain', $declaredPermissions)) {
        return TRUE;
    }
    if (CRM_ACL_BAO_ACL::matchType($type, 'View') && CRM_Core_Permission::check('view all contacts in domain')) {
        return TRUE;
    }
    if (CRM_ACL_BAO_ACL::matchType($type, 'Edit') && CRM_Core_Permission::check('edit all contacts in domain')) {
        return TRUE;
    }
    return FALSE;
}