Exemple #1
0
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->add('text', 'label', ts('Title'), array('size' => 40), true);
     $this->add('text', 'value', ts('URL'), array('size' => 40), true);
     $this->add('text', 'name', ts('Class'), array('size' => 40), true);
     $element = $this->add('text', 'weight', ts('Weight'), array('size' => 4), true);
     // $element->freeze( );
     $this->add('text', 'description', ts('Description'), array('size' => 40), true);
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     require_once 'CRM/Core/Component.php';
     $this->_components = CRM_Core_Component::getComponents();
     //unset the report component
     unset($this->_components['CiviReport']);
     $components = array();
     foreach ($this->_components as $name => $object) {
         $components[$object->componentID] = $object->info['translatedName'];
     }
     $this->add('select', 'component_id', ts('Component'), array('' => ts('Contact')) + $components);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Report_Form_Register', 'formRule'), $this);
 }
Exemple #2
0
 /**
  * @return array
  */
 private function _getComponentSelectValues()
 {
     $ret = array();
     $this->_components = CRM_Core_Component::getComponents();
     foreach ($this->_components as $name => $object) {
         $ret[$name] = $object->info['translatedName'];
     }
     return $ret;
 }
 /**
  * Function to get component name from given permission.
  *
  * @param string  $permission
  *
  * return string $componentName the name of component.
  * @static
  */
 static function getComponentName($permission)
 {
     $componentName = NULL;
     $permission = trim($permission);
     if (empty($permission)) {
         return $componentName;
     }
     static $allCompPermissions;
     if (!is_array($allCompPermissions)) {
         $components = CRM_Core_Component::getComponents();
         foreach ($components as $name => $comp) {
             $allCompPermissions[$name] = $comp->getPermissions();
         }
     }
     if (is_array($allCompPermissions)) {
         foreach ($allCompPermissions as $name => $permissions) {
             if (in_array($permission, $permissions)) {
                 $componentName = $name;
                 break;
             }
         }
     }
     return $componentName;
 }
 /**
  * Set enabled components.
  *
  * @param array $enabledComponents
  */
 public static function setEnabledComponents($enabledComponents)
 {
     $config = CRM_Core_Config::singleton();
     $components = CRM_Core_Component::getComponents();
     $enabledComponentIDs = array();
     foreach ($enabledComponents as $name) {
         $enabledComponentIDs[] = $components[$name]->componentID;
     }
     // fix the config object
     $config->enableComponents = $enabledComponents;
     $config->enableComponentIDs = $enabledComponentIDs;
     // also force reset of component array
     CRM_Core_Component::getEnabledComponents(TRUE);
     // update DB
     CRM_Core_BAO_Setting::setItem($enabledComponents, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
 }
 /**
  * Get component name from given permission.
  *
  * @param string $permission
  *
  * @return null|string
  *   the name of component.
  */
 public static function getComponentName($permission)
 {
     $componentName = NULL;
     $permission = trim($permission);
     if (empty($permission)) {
         return $componentName;
     }
     static $allCompPermissions = array();
     if (empty($allCompPermissions)) {
         $components = CRM_Core_Component::getComponents();
         foreach ($components as $name => $comp) {
             //get all permissions of each components unconditionally
             $allCompPermissions[$name] = $comp->getPermissions(TRUE);
         }
     }
     if (is_array($allCompPermissions)) {
         foreach ($allCompPermissions as $name => $permissions) {
             if (array_key_exists($permission, $permissions)) {
                 $componentName = $name;
                 break;
             }
         }
     }
     return $componentName;
 }
Exemple #6
0
 /**
  * takes a componentName and enables it in the config
  * Primarily used during unit testing
  *
  * @param string $componentName name of the component to be enabled, needs to be valid
  *
  * @return boolean - true if valid component name and enabling succeeds, else false
  * @static
  */
 static function enableComponent($componentName)
 {
     $config = CRM_Core_Config::singleton();
     if (in_array($componentName, $config->enableComponents)) {
         // component is already enabled
         return TRUE;
     }
     $components = CRM_Core_Component::getComponents();
     // return if component does not exist
     if (!array_key_exists($componentName, $components)) {
         return FALSE;
     }
     // get enabled-components from DB and add to the list
     $enabledComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
     $enabledComponents[] = $componentName;
     $enabledComponentIDs = array();
     foreach ($enabledComponents as $name) {
         $enabledComponentIDs[] = $components[$name]->componentID;
     }
     // fix the config object
     $config->enableComponents = $enabledComponents;
     $config->enableComponentIDs = $enabledComponentIDs;
     // also force reset of component array
     CRM_Core_Component::getEnabledComponents(TRUE);
     // update DB
     CRM_Core_BAO_Setting::setItem($enabledComponents, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
     return TRUE;
 }
 /**
  * Disable specified component.
  *
  * @param string $componentName
  *
  * @return bool
  */
 public static function disableComponent($componentName)
 {
     $config = CRM_Core_Config::singleton();
     if (!in_array($componentName, $config->enableComponents) || !array_key_exists($componentName, CRM_Core_Component::getComponents())) {
         // Post-condition is satisfied.
         return TRUE;
     }
     // get enabled-components from DB and add to the list
     $enabledComponents = Civi::settings()->get('enable_components');
     $enabledComponents = array_diff($enabledComponents, array($componentName));
     self::setEnabledComponents($enabledComponents);
     return TRUE;
 }
 /**
  * takes a componentName and enables it in the config
  * Primarily used during unit testing
  *
  * @param string $componentName name of the component to be enabled, needs to be valid
  *
  * @return boolean - true if valid component name and enabling succeeds, else false
  * @static
  */
 static function enableComponent($componentName)
 {
     $config = CRM_Core_Config::singleton();
     if (in_array($componentName, $config->enableComponents)) {
         // component is already enabled
         return TRUE;
     }
     $components = CRM_Core_Component::getComponents();
     // return if component does not exist
     if (!array_key_exists($componentName, $components)) {
         return FALSE;
     }
     // get config_backend value
     $sql = "\nSELECT config_backend\nFROM   civicrm_domain\nWHERE  id = %1\n";
     $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer'));
     $configBackend = CRM_Core_DAO::singleValueQuery($sql, $params);
     if (!$configBackend) {
         static $alreadyVisited = FALSE;
         if ($alreadyVisited) {
             CRM_Core_Error::fatal(ts('Returning early due to unexpected error - civicrm_domain.config_backend column value is NULL. Try visiting CiviCRM Home page.'));
         }
         $alreadyVisited = TRUE;
         // try to recreate the config backend
         $config = CRM_Core_Config::singleton(TRUE, TRUE);
         return self::enableComponent($componentName);
     }
     $configBackend = unserialize($configBackend);
     $configBackend['enableComponents'][] = $componentName;
     $configBackend['enableComponentIDs'][] = $components[$componentName]->componentID;
     // fix the config object
     $config->enableComponents = $configBackend['enableComponents'];
     $config->enableComponentIDs = $configBackend['enableComponentIDs'];
     // also force reset of component array
     CRM_Core_Component::getEnabledComponents(TRUE);
     // check if component is already there, is so return
     $configBackend = serialize($configBackend);
     $sql = "\nUPDATE civicrm_domain\nSET    config_backend = %2\nWHERE  id = %1\n";
     $params[2] = array($configBackend, 'String');
     CRM_Core_DAO::executeQuery($sql, $params);
     return TRUE;
 }
Exemple #9
0
 static function &basicPermissions($all = false)
 {
     static $permissions = null;
     if (!$permissions) {
         $permissions = array('add contacts' => ts('add contacts'), 'view all contacts' => ts('view all contacts'), 'edit all contacts' => ts('edit all contacts'), 'delete contacts' => ts('delete contacts'), 'import contacts' => ts('import contacts'), 'edit groups' => ts('edit groups'), 'administer CiviCRM' => ts('administer CiviCRM'), 'access uploaded files' => ts('access uploaded files'), 'profile listings and forms' => ts('profile listings and forms'), 'profile listings' => ts('profile listings'), 'profile create' => ts('profile create'), 'profile edit' => ts('profile edit'), 'profile view' => ts('profile view'), 'access all custom data' => ts('access all custom data'), 'view all activities' => ts('view all activities'), 'delete activities' => ts('delete activities'), 'access CiviCRM' => ts('access CiviCRM'), 'access Contact Dashboard' => ts('access Contact Dashboard'), 'translate CiviCRM' => ts('translate CiviCRM'));
         if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
             $permissions['administer Multiple Organizations'] = ts('administer Multiple Organizations');
         }
         $config = CRM_Core_Config::singleton();
         require_once 'CRM/Core/Component.php';
         if (!$all) {
             $components = CRM_Core_Component::getEnabledComponents();
         } else {
             $components = CRM_Core_Component::getComponents();
         }
         foreach ($components as $comp) {
             $perm = $comp->getPermissions();
             if ($perm) {
                 sort($perm);
                 foreach ($perm as $p) {
                     $permissions[$p] = $p;
                 }
             }
         }
         asort($permissions);
     }
     return $permissions;
 }