/**
  * Get a list of AngularJS modules which should be autoloaded.
  *
  * @return array
  *   Each item has some combination of these keys:
  *   - ext: string
  *     The Civi extension which defines the Angular module.
  *   - js: array(string $relativeFilePath)
  *     List of JS files (relative to the extension).
  *   - css: array(string $relativeFilePath)
  *     List of CSS files (relative to the extension).
  *   - partials: array(string $relativeFilePath)
  *     A list of partial-HTML folders (relative to the extension).
  *     This will be mapped to "~/moduleName" by crmResource.
  *   - settings: array(string $key => mixed $value)
  *     List of settings to preload.
  */
 public function getModules()
 {
     if ($this->modules === NULL) {
         $config = \CRM_Core_Config::singleton();
         $angularModules = array();
         $angularModules['angularFileUpload'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-file-upload/dist/angular-file-upload.min.js'));
         $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('ang/crmApp.js'));
         $angularModules['crmAttachment'] = array('ext' => 'civicrm', 'js' => array('ang/crmAttachment.js'), 'css' => array('ang/crmAttachment.css'), 'partials' => array('ang/crmAttachment'), 'settings' => array('token' => \CRM_Core_Page_AJAX_Attachment::createToken()));
         $angularModules['crmAutosave'] = array('ext' => 'civicrm', 'js' => array('ang/crmAutosave.js'));
         $angularModules['crmCxn'] = array('ext' => 'civicrm', 'js' => array('ang/crmCxn.js', 'ang/crmCxn/*.js'), 'css' => array('ang/crmCxn.css'), 'partials' => array('ang/crmCxn'));
         //$angularModules['crmExample'] = array(
         //  'ext' => 'civicrm',
         //  'js' => array('ang/crmExample.js'),
         //  'partials' => array('ang/crmExample'),
         //);
         $angularModules['crmResource'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmResource/all.js'));
         $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('ang/crmUi.js'), 'partials' => array('ang/crmUi'), 'settings' => array('browseUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/browse.php', 'uploadUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/upload.php'));
         $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('ang/crmUtil.js'));
         // https://github.com/jwstadler/angular-jquery-dialog-service
         $angularModules['dialogService'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js'));
         $angularModules['ngRoute'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-route/angular-route.min.js'));
         $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-sanitize/angular-sanitize.min.js'));
         $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js'));
         $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-sortable/sortable.min.js'));
         $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'));
         foreach (\CRM_Core_Component::getEnabledComponents() as $component) {
             $angularModules = array_merge($angularModules, $component->getAngularModules());
         }
         \CRM_Utils_Hook::angularModules($angularModules);
         $this->modules = $this->resolvePatterns($angularModules);
     }
     return $this->modules;
 }
Exemple #2
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     // There could be multiple contacts. We not clear on which contact id to display.
     // Lets hide it for now.
     $this->_exposeContactID = FALSE;
     // if navigated from count link of activity summary reports.
     $this->_resetDateFilter = CRM_Utils_Request::retrieve('resetDateFilter', 'Boolean', CRM_Core_DAO::$_nullObject);
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     $caseEnabled = in_array("CiviCase", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
         $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
     }
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $componentName => $componentInfo) {
         // CRM-19201: Add support for reporting CiviCampaign activities
         // For CiviCase, "access all cases and activities" is required here
         // rather than "access my cases and activities" to prevent those with
         // only the later permission from seeing a list of all cases which might
         // present a privacy issue.
         if (CRM_Core_Permission::access($componentName, TRUE, TRUE)) {
             $accessAllowed[] = $componentInfo->componentID;
         }
     }
     $include = '';
     if (!empty($accessAllowed)) {
         $include = 'OR v.component_id IN (' . implode(', ', $accessAllowed) . ')';
     }
     $condition = " AND ( v.component_id IS NULL {$include} )";
     $this->activityTypes = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition);
     asort($this->activityTypes);
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('contact_source' => array('name' => 'sort_name', 'title' => ts('Source Name'), 'alias' => 'civicrm_contact_source', 'no_repeat' => TRUE), 'contact_assignee' => array('name' => 'sort_name', 'title' => ts('Assignee Name'), 'alias' => 'civicrm_contact_assignee', 'dbAlias' => "civicrm_contact_assignee.sort_name", 'default' => TRUE), 'contact_target' => array('name' => 'sort_name', 'title' => ts('Target Name'), 'alias' => 'civicrm_contact_target', 'dbAlias' => "civicrm_contact_target.sort_name", 'default' => TRUE), 'contact_source_id' => array('name' => 'id', 'alias' => 'civicrm_contact_source', 'dbAlias' => "civicrm_contact_source.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE), 'contact_assignee_id' => array('name' => 'id', 'alias' => 'civicrm_contact_assignee', 'dbAlias' => "civicrm_contact_assignee.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE), 'contact_target_id' => array('name' => 'id', 'alias' => 'civicrm_contact_target', 'dbAlias' => "civicrm_contact_target.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE)), 'filters' => array('contact_source' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_source', 'title' => ts('Source Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_assignee' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_assignee', 'title' => ts('Assignee Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_target' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_target', 'title' => ts('Target Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'current_user' => array('name' => 'current_user', 'title' => ts('Limit To Current User'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No'), '1' => ts('Yes')))), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('contact_source_email' => array('name' => 'email', 'title' => ts('Source Email'), 'alias' => 'civicrm_email_source'), 'contact_assignee_email' => array('name' => 'email', 'title' => ts('Assignee Email'), 'alias' => 'civicrm_email_assignee'), 'contact_target_email' => array('name' => 'email', 'title' => ts('Target Email'), 'alias' => 'civicrm_email_target')), 'order_bys' => array('source_contact_email' => array('name' => 'email', 'title' => ts('Source Email'), 'dbAlias' => 'civicrm_email_contact_source_email'))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('contact_source_phone' => array('name' => 'phone', 'title' => ts('Source Phone'), 'alias' => 'civicrm_phone_source'), 'contact_assignee_phone' => array('name' => 'phone', 'title' => ts('Assignee Phone'), 'alias' => 'civicrm_phone_assignee'), 'contact_target_phone' => array('name' => 'phone', 'title' => ts('Target Phone'), 'alias' => 'civicrm_phone_target'))), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('id' => array('no_display' => TRUE, 'title' => ts('Activity ID'), 'required' => TRUE), 'source_record_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_type_id' => array('title' => ts('Activity Type'), 'required' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'activity_subject' => array('title' => ts('Subject'), 'default' => TRUE), 'activity_date_time' => array('title' => ts('Activity Date'), 'required' => TRUE), 'status_id' => array('title' => ts('Activity Status'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'duration' => array('title' => ts('Duration'), 'type' => CRM_Utils_Type::T_INT), 'details' => array('title' => ts('Activity Details'))), 'filters' => array('activity_date_time' => array('default' => 'this.month', 'operatorType' => CRM_Report_Form::OP_DATE), 'activity_subject' => array('title' => ts('Activity Subject')), 'activity_type_id' => array('title' => ts('Activity Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activityTypes), 'status_id' => array('title' => ts('Activity Status'), 'type' => CRM_Utils_Type::T_STRING, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::activityStatus()), 'details' => array('title' => ts('Activity Details'), 'type' => CRM_Utils_Type::T_TEXT)), 'order_bys' => array('activity_date_time' => array('title' => ts('Activity Date'), 'default_weight' => '1', 'dbAlias' => 'civicrm_activity_activity_date_time'), 'activity_type_id' => array('title' => ts('Activity Type'), 'default_weight' => '2', 'dbAlias' => 'field(civicrm_activity_activity_type_id, ' . implode(', ', array_keys($this->activityTypes)) . ')')), 'grouping' => 'activity-fields', 'alias' => 'activity'), 'civicrm_activity_contact' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array())) + $this->addressFields(TRUE);
     if ($caseEnabled && CRM_Core_Permission::check('access all cases and activities')) {
         $this->_columns['civicrm_activity']['filters']['include_case_activities'] = array('name' => 'include_case_activities', 'title' => ts('Include Case Activities'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No'), '1' => ts('Yes')));
     }
     if ($campaignEnabled) {
         // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
         $this->_columns['civicrm_activity']['fields']['result'] = array('title' => ts('Survey Result'), 'default' => 'false');
         $this->_columns['civicrm_activity']['filters']['result'] = array('title' => ts('Survey Result'), 'operator' => 'like', 'type' => CRM_Utils_Type::T_STRING);
         if (!empty($this->activeCampaigns)) {
             $this->_columns['civicrm_activity']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
             $this->_columns['civicrm_activity']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         }
         if (!empty($this->engagementLevels)) {
             $this->_columns['civicrm_activity']['fields']['engagement_level'] = array('title' => ts('Engagement Index'), 'default' => 'false');
             $this->_columns['civicrm_activity']['filters']['engagement_level'] = array('title' => ts('Engagement Index'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->engagementLevels);
         }
     }
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     $this->_tagFilterTable = 'civicrm_activity';
     parent::__construct();
 }
Exemple #3
0
 /**
  * Get an instance
  */
 public static function singleton($fresh = FALSE)
 {
     static $singleton;
     if ($fresh || !$singleton) {
         $declarations = array();
         foreach (CRM_Core_Component::getEnabledComponents() as $component) {
             $declarations = array_merge($declarations, $component->getManagedEntities());
         }
         CRM_Utils_Hook::managed($declarations);
         $singleton = new CRM_Core_ManagedEntities(CRM_Core_Module::getAll(), $declarations);
     }
     return $singleton;
 }
 /**
  * Get a list of AngularJS modules which should be autoloaded
  *
  * @return array (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths))
  */
 public static function getAngularModules()
 {
     $angularModules = array();
     $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-utils/ui-utils.min.js'));
     $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-sortable/sortable.min.js'));
     $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'));
     $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js'));
     foreach (CRM_Core_Component::getEnabledComponents() as $component) {
         $angularModules = array_merge($angularModules, $component->getAngularModules());
     }
     CRM_Utils_Hook::angularModules($angularModules);
     return $angularModules;
 }
 public function testToggleComponent()
 {
     $origNames = array();
     foreach (CRM_Core_Component::getEnabledComponents() as $c) {
         $origNames[] = $c->name;
     }
     $this->assertTrue(!in_array('CiviCase', $origNames));
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
     $newNames = array();
     foreach (CRM_Core_Component::getEnabledComponents() as $c) {
         $newNames[] = $c->name;
     }
     $this->assertTrue(in_array('CiviCase', $newNames));
     $this->assertEquals(count($newNames), count($origNames) + 1);
 }
Exemple #6
0
 public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent $e)
 {
     if ($e->mapping->getEntity() !== 'civicrm_activity') {
         return;
     }
     // The joint expression for activities needs some extra nuance to handle.
     // Multiple revisions of the activity.
     // Q: Could we simplify & move the extra AND clauses into `where(...)`?
     $e->query->param('casEntityJoinExpr', 'e.id = reminder.entity_id AND e.is_current_revision = 1 AND e.is_deleted = 0');
     $e->query->select('e.*');
     // FIXME: seems too broad.
     $e->query->select('ov.label as activity_type, e.id as activity_id');
     $e->query->join("og", "!casMailingJoinType civicrm_option_group og ON og.name = 'activity_type'");
     $e->query->join("ov", "!casMailingJoinType civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id");
     // if CiviCase component is enabled, join for caseId.
     $compInfo = CRM_Core_Component::getEnabledComponents();
     if (array_key_exists('CiviCase', $compInfo)) {
         $e->query->select("civicrm_case_activity.case_id as case_id");
         $e->query->join('civicrm_case_activity', "LEFT JOIN `civicrm_case_activity` ON `e`.`id` = `civicrm_case_activity`.`activity_id`");
     }
 }
Exemple #7
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     // add a hidden field to remember the price set id
     // this get around the browser tab issue
     $this->add('hidden', 'sid', $this->_sid);
     $this->add('hidden', 'fid', $this->_fid);
     // label
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'label'), TRUE);
     // html_type
     $javascript = 'onchange="option_html_type(this.form)";';
     $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
     // Text box for Participant Count for a field
     // Financial Type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = $memberComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (array_key_exists('CiviMember', $enabledComponents)) {
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
     $this->add('select', 'financial_type_id', ts('Financial Type'), array(' ' => ts('- select -')) + $financialType);
     $this->assign('useForMember', FALSE);
     if (in_array($eventComponentId, $this->_extendComponentId)) {
         $this->add('text', 'count', ts('Participant Count'), $attributes['count']);
         $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
         $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
         $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
         $this->assign('useForEvent', TRUE);
     } else {
         if (in_array($memberComponentId, $this->_extendComponentId)) {
             $this->_useForMember = 1;
             $this->assign('useForMember', $this->_useForMember);
         }
         $this->assign('useForEvent', FALSE);
     }
     $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, TRUE, $javascript);
     // price (for text inputs)
     $this->add('text', 'price', ts('Price'));
     $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
     $this->addRule('price', ts('must be a monetary value'), 'money');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->freeze('html_type');
     }
     // form fields of Custom Option rows
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         //the show hide blocks
         $showBlocks = 'optionField_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
             if ($i == self::NUM_OPTION) {
                 $_showHide->addHide('additionalOption');
             }
         } else {
             $_showHide->addShow($showBlocks);
         }
         // label
         $attributes['label']['size'] = 25;
         $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
         // amount
         $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
         $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
         //Financial Type
         $this->add('select', 'option_financial_type_id[' . $i . ']', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
         if (in_array($eventComponentId, $this->_extendComponentId)) {
             // count
             $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
             $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
             // max_value
             $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
             $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             // description
             //$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 ));
         } elseif (in_array($memberComponentId, $this->_extendComponentId)) {
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $js = array('onchange' => "calculateRowValues( {$i} );");
             $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, $js);
             $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
         }
         // weight
         $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
         // is active ?
         $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
         $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
         //for checkbox handling of default option
         $this->add('checkbox', "default_checkbox_option[{$i}]", NULL);
     }
     //default option selection
     $this->addGroup($defaultOption, 'default_option');
     $_showHide->addToTemplate();
     // is_display_amounts
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // checkbox / radio options per line
     $this->add('text', 'options_per_line', ts('Options Per Line'));
     $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
     // help post, mask, attributes, javascript ?
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post'));
     // active_on
     $date_options = array('format' => 'dmY His', 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 5, 'addEmptyOption' => TRUE);
     $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime'));
     // expire_on
     $this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime'));
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
     // is active ?
     $this->add('checkbox', 'is_active', ts('Active?'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // is public?
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     // add a form rule to check default value
     $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'"));
     }
 }
Exemple #8
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm()
 {
     $this->set('context', 'advanced');
     $this->_searchPane = CRM_Utils_Array::value('searchPane', $_GET);
     $this->_searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options');
     if (!$this->_searchPane || $this->_searchPane == 'basic') {
         CRM_Contact_Form_Search_Criteria::basic($this);
     }
     $allPanes = array();
     $paneNames = array(ts('Address Fields') => 'location', ts('Custom Fields') => 'custom', ts('Activities') => 'activity', ts('Relationships') => 'relationship', ts('Demographics') => 'demographics', ts('Notes') => 'notes', ts('Change Log') => 'changeLog');
     //check if there are any custom data searchable fields
     $groupDetails = array();
     $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes());
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     // if no searchable fields unset panel
     if (empty($groupDetails)) {
         unset($paneNames[ts('Custom Fields')]);
     }
     foreach ($paneNames as $name => $type) {
         if (!$this->_searchOptions[$type]) {
             unset($paneNames[$name]);
         }
     }
     $components = CRM_Core_Component::getEnabledComponents();
     $componentPanes = array();
     foreach ($components as $name => $component) {
         if (in_array($name, array_keys($this->_searchOptions)) && $this->_searchOptions[$name] && CRM_Core_Permission::access($component->name)) {
             $componentPanes[$name] = $component->registerAdvancedSearchPane();
             $componentPanes[$name]['name'] = $name;
         }
     }
     usort($componentPanes, array('CRM_Utils_Sort', 'cmpFunc'));
     foreach ($componentPanes as $name => $pane) {
         // FIXME: we should change the use of $name here to keyword
         $paneNames[$pane['title']] = $pane['name'];
     }
     $hookPanes = array();
     CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes);
     $paneNames = array_merge($paneNames, $hookPanes);
     $this->_paneTemplatePath = array();
     foreach ($paneNames as $name => $type) {
         if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) {
             continue;
         }
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/search/advanced', "snippet=1&searchPane={$type}&qfKey={$this->controller->_key}"), 'open' => 'false', 'id' => $type);
         // see if we need to include this paneName in the current form
         if ($this->_searchPane == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)) {
             $allPanes[$name]['open'] = 'true';
             if (CRM_Utils_Array::value($type, $components)) {
                 $c = $components[$type];
                 $this->add('hidden', "hidden_{$type}", 1);
                 $c->buildAdvancedSearchPaneForm($this);
                 $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath();
             } else {
                 if (in_array($type, $hookPanes)) {
                     CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type);
                     CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type);
                 } else {
                     CRM_Contact_Form_Search_Criteria::$type($this);
                     $template = ucfirst($type);
                     $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl";
                 }
             }
         }
     }
     $this->assign('allPanes', $allPanes);
     if (!$this->_searchPane) {
         parent::buildQuickForm();
     } else {
         $this->assign('suppressForm', TRUE);
     }
 }
Exemple #9
0
 /**
  * Create the list of options to create New objects for the application and format is as a block.
  *
  * @return void
  */
 private static function setTemplateShortcutValues()
 {
     $config = CRM_Core_Config::singleton();
     static $shortCuts = array();
     if (!$shortCuts) {
         if (CRM_Core_Permission::check('add contacts')) {
             if (CRM_Core_Permission::giveMeAllACLs()) {
                 $shortCuts = CRM_Contact_BAO_ContactType::getCreateNewList();
             }
         }
         // new activity (select target contact)
         $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/activity', 'query' => 'action=add&reset=1&context=standalone', 'ref' => 'new-activity', 'title' => ts('Activity'))));
         $components = CRM_Core_Component::getEnabledComponents();
         if (!empty($config->enableComponents)) {
             // check if we can process credit card contribs
             $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments();
             foreach ($components as $componentName => $obj) {
                 if (in_array($componentName, $config->enableComponents)) {
                     $obj->creatNewShortcut($shortCuts, $newCredit);
                 }
             }
         }
         // new email (select recipients)
         $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/activity/email/add', 'query' => 'atype=3&action=add&reset=1&context=standalone', 'ref' => 'new-email', 'title' => ts('Email'))));
         if (CRM_Core_Permission::check('edit groups')) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/group/add', 'query' => 'reset=1', 'ref' => 'new-group', 'title' => ts('Group'))));
         }
         if (CRM_Core_Permission::check('administer CiviCRM')) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/admin/tag', 'query' => 'reset=1&action=add', 'ref' => 'new-tag', 'title' => ts('Tag'))));
         }
         if (empty($shortCuts)) {
             return NULL;
         }
     }
     $values = array();
     foreach ($shortCuts as $key => $short) {
         $values[$key] = self::setShortCutValues($short);
     }
     // call links hook to add user defined links
     CRM_Utils_Hook::links('create.new.shorcuts', NULL, CRM_Core_DAO::$_nullObject, $values, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject);
     foreach ($values as $key => $val) {
         if (!empty($val['title'])) {
             $values[$key]['name'] = CRM_Utils_Array::value('name', $val, $val['title']);
         }
     }
     self::setProperty(self::CREATE_NEW, 'templateValues', array('shortCuts' => $values));
 }
 /**
  * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
  *
  * Get all Activty types.
  *
  * The static array activityType is returned
  *
  * @param boolean $all - get All Activity  types - default is to get only active ones.
  *
  * @access public
  * @static
  *
  * @return array - array reference of all activity types.
  */
 public static function &activityType()
 {
     $args = func_get_args();
     $all = CRM_Utils_Array::value(0, $args, TRUE);
     $includeCaseActivities = CRM_Utils_Array::value(1, $args, FALSE);
     $reset = CRM_Utils_Array::value(2, $args, FALSE);
     $returnColumn = CRM_Utils_Array::value(3, $args, 'label');
     $includeCampaignActivities = CRM_Utils_Array::value(4, $args, FALSE);
     $onlyComponentActivities = CRM_Utils_Array::value(5, $args, FALSE);
     $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
     $index .= '_' . (int) $includeCampaignActivities;
     $index .= '_' . (int) $onlyComponentActivities;
     if (NULL === self::$activityType) {
         self::$activityType = array();
     }
     if (!isset(self::$activityType[$index]) || $reset) {
         $condition = NULL;
         if (!$all) {
             $condition = 'AND filter = 0';
         }
         $componentClause = " v.component_id IS NULL";
         if ($onlyComponentActivities) {
             $componentClause = " v.component_id IS NOT NULL";
         }
         $componentIds = array();
         $compInfo = CRM_Core_Component::getEnabledComponents();
         // build filter for listing activity types only if their
         // respective components are enabled
         foreach ($compInfo as $compName => $compObj) {
             if ($compName == 'CiviCase') {
                 if ($includeCaseActivities) {
                     $componentIds[] = $compObj->componentID;
                 }
             } elseif ($compName == 'CiviCampaign') {
                 if ($includeCampaignActivities) {
                     $componentIds[] = $compObj->componentID;
                 }
             } else {
                 $componentIds[] = $compObj->componentID;
             }
         }
         if (count($componentIds)) {
             $componentIds = implode(',', $componentIds);
             $componentClause = " ({$componentClause} OR v.component_id IN ({$componentIds}))";
             if ($onlyComponentActivities) {
                 $componentClause = " ( v.component_id IN ({$componentIds} ) )";
             }
         }
         $condition = $condition . ' AND ' . $componentClause;
         self::$activityType[$index] = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
     }
     return self::$activityType[$index];
 }
 static function &basicPermissions($all = FALSE)
 {
     static $permissions = NULL;
     if (!$permissions) {
         $prefix = ts('CiviCRM') . ': ';
         $permissions = self::getCorePermissions();
         if (self::isMultisiteEnabled()) {
             $permissions['administer Multiple Organizations'] = $prefix . ts('administer Multiple Organizations');
         }
         $config = CRM_Core_Config::singleton();
         if (!$all) {
             $components = CRM_Core_Component::getEnabledComponents();
         } else {
             $components = CRM_Core_Component::getComponents();
         }
         foreach ($components as $comp) {
             $perm = $comp->getPermissions();
             if ($perm) {
                 $info = $comp->getInfo();
                 foreach ($perm as $p) {
                     $permissions[$p] = $info['translatedName'] . ': ' . $p;
                 }
             }
         }
         // Add any permissions defined in hook_civicrm_permission implementations.
         $config = CRM_Core_Config::singleton();
         $module_permissions = $config->userPermissionClass->getAllModulePermissions();
         $permissions = array_merge($permissions, $module_permissions);
     }
     return $permissions;
 }
Exemple #12
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $this->assign('sid', $this->_sid);
     // title
     $this->add('text', 'title', ts('Set Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'), TRUE);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Price_DAO_PriceSet', $this->_sid, 'title'));
     $priceSetUsedTables = $extends = array();
     if ($this->_action == CRM_Core_Action::UPDATE && $this->_sid) {
         $priceSetUsedTables = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid, 'table');
     }
     $config = CRM_Core_Config::singleton();
     $showContribution = FALSE;
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     foreach ($enabledComponents as $name => $compObj) {
         switch ($name) {
             case 'CiviEvent':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Event'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_event', 'civicrm_participant') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviContribute':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_contribution', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviMember':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_membership', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
         }
     }
     if (CRM_Utils_System::isNull($extends)) {
         $this->assign('extends', FALSE);
     } else {
         $this->assign('extends', TRUE);
     }
     $this->addGroup($extends, 'extends', ts('Used For'), '&nbsp;', TRUE);
     $this->addRule('extends', ts('%1 is a required field.', array(1 => ts('Used For'))), 'required');
     // financial type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     $this->add('select', 'financial_type_id', ts('Default Financial Type'), array('' => ts('- select -')) + $financialType, 'required');
     // help text
     $this->add('textarea', 'help_pre', ts('Pre-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_pre'));
     $this->add('textarea', 'help_post', ts('Post-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_post'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Price Set active?'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Price_Form_Set', 'formRule'));
     // views are implemented as frozen form
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         //$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/price?reset=1&action=browse'"));
     }
 }
 /**
  * Get all Activty types.
  *
  * The static array activityType is returned
  * @param boolean $all - get All Activity  types - default is to get only active ones.
  *
  * @access public
  * @static
  *
  * @return array - array reference of all activty types.
  */
 public static function &activityType($all = true, $includeCaseActivities = false, $reset = false, $returnColumn = 'label', $includeCampaignActivities = false)
 {
     $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
     $index .= '_' . (int) $includeCampaignActivities;
     if (!array_key_exists($index, self::$activityType) || $reset) {
         require_once 'CRM/Core/OptionGroup.php';
         $condition = null;
         if (!$all) {
             $condition = 'AND filter = 0';
         }
         $componentClause = " v.component_id IS NULL";
         $componentIds = array();
         require_once 'CRM/Core/Component.php';
         $compInfo = CRM_Core_Component::getEnabledComponents();
         // build filter for listing activity types only if their
         // respective components are enabled
         foreach ($compInfo as $compName => $compObj) {
             if ($compName == 'CiviCase') {
                 if ($includeCaseActivities) {
                     $componentIds[] = $compObj->componentID;
                 }
             } else {
                 if ($compName == 'CiviCampaign') {
                     if ($includeCampaignActivities) {
                         $componentIds[] = $compObj->componentID;
                     }
                 } else {
                     $componentIds[] = $compObj->componentID;
                 }
             }
         }
         if (count($componentIds)) {
             $componentIds = implode(',', $componentIds);
             $componentClause = " ({$componentClause} OR v.component_id IN ({$componentIds}))";
         }
         $condition = $condition . ' AND ' . $componentClause;
         self::$activityType[$index] = CRM_Core_OptionGroup::values('activity_type', false, false, false, $condition, $returnColumn);
     }
     return self::$activityType[$index];
 }
Exemple #14
0
 function clauseComponent()
 {
     $selectedContacts = implode(',', $this->_contactSelected);
     $contribution = $membership = $participant = null;
     $eligibleResult = $rows = $tempArray = array();
     foreach ($this->_component as $val) {
         if (CRM_Utils_Array::value($val, $this->_selectComponent) && ($val != 'activity_civireport' && $val != 'relationship_civireport')) {
             $sql = "{$this->_selectComponent[$val]} {$this->_formComponent[$val]} \n                         WHERE    {$this->_aliases['civicrm_contact']}.id IN ( {$selectedContacts} )\n                         GROUP BY {$this->_aliases['civicrm_contact']}.id,{$val}.id ";
             $dao = CRM_Core_DAO::executeQuery($sql);
             while ($dao->fetch()) {
                 $countRecord = 0;
                 $eligibleResult[$val] = $val;
                 $CC = "civicrm_" . substr_replace($val, '', -11, 11) . "_contact_id";
                 $row = array();
                 foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
                     $countRecord++;
                     $row[$key] = $dao->{$key};
                 }
                 //if record exist for component(except contact_id)
                 //since contact_id is selected for every component
                 if ($countRecord > 1) {
                     $rows[$dao->{$CC}][$val][] = $row;
                 }
                 $tempArray[$dao->{$CC}] = $dao->{$CC};
             }
         }
     }
     if (CRM_Utils_Array::value('relationship_civireport', $this->_selectComponent)) {
         require_once 'CRM/Contact/BAO/Relationship.php';
         $relTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, null, true);
         $val = 'relationship_civireport';
         $eligibleResult[$val] = $val;
         $sql = "{$this->_selectComponent[$val]},{$this->_aliases['civicrm_contact']}.display_name as contact_b_name,  contact_a.id as contact_a_id , contact_a.display_name  as contact_a_name  {$this->_formComponent[$val]} \n                         WHERE    ({$this->_aliases['civicrm_contact']}.id IN ( {$selectedContacts} )\n                                  OR \n                                  contact_a.id IN ( {$selectedContacts} ) ) AND\n                                  {$this->_aliases['civicrm_relationship']}.is_active = 1\n                         GROUP BY {$this->_aliases['civicrm_relationship']}.id";
         $dao = CRM_Core_DAO::executeQuery($sql);
         while ($dao->fetch()) {
             foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
                 if ($key == 'civicrm_relationship_contact_id_b') {
                     $row[$key] = $dao->contact_b_name;
                     continue;
                 }
                 $row[$key] = $dao->{$key};
             }
             $relTitle = "" . $dao->civicrm_relationship_relationship_type_id . "_a_b";
             $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
             $rows[$dao->contact_a_id][$val][] = $row;
             $row['civicrm_relationship_contact_id_b'] = $dao->contact_a_name;
             $relTitle = "" . $dao->civicrm_relationship_relationship_type_id . "_b_a";
             if (isset($relTypes[$relTitle])) {
                 $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
             }
             $rows[$dao->civicrm_relationship_contact_id_b][$val][] = $row;
         }
     }
     if (CRM_Utils_Array::value('activity_civireport', $this->_selectComponent)) {
         $componentClause = "civicrm_option_value.component_id IS NULL";
         $componentsIn = null;
         $compInfo = CRM_Core_Component::getEnabledComponents();
         foreach ($compInfo as $compObj) {
             if ($compObj->info['showActivitiesInCore']) {
                 $componentsIn = $componentsIn ? $componentsIn . ', ' . $compObj->componentID : $compObj->componentID;
             }
         }
         if ($componentsIn) {
             $componentClause = "( {$componentClause} OR \n                                      civicrm_option_value.component_id IN ({$componentsIn}) )";
         }
         $val = 'activity_civireport';
         $eligibleResult[$val] = $val;
         $sql = "{$this->_selectComponent[$val]} , \n                 sourceContact.display_name as added_by {$this->_formComponent[$val]}\n\n                 WHERE ( {$this->_aliases['civicrm_activity']}.source_contact_id IN ({$selectedContacts}) OR \n                         target_contact_id IN ({$selectedContacts}) OR \n                         assignee_contact_id IN ({$selectedContacts}) OR \n                         civicrm_case_contact.contact_id IN ({$selectedContacts}) ) AND \n                        civicrm_option_group.name = 'activity_type' AND \n                        {$this->_aliases['civicrm_activity']}.is_test = 0 AND \n                        ({$componentClause})\n\n                 GROUP BY {$this->_aliases['civicrm_activity']}.id \n\n                 ORDER BY {$this->_aliases['civicrm_activity']}.activity_date_time desc  ";
         $dao = CRM_Core_DAO::executeQuery($sql);
         while ($dao->fetch()) {
             foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
                 if ($key == 'civicrm_activity_source_contact_id') {
                     $row[$key] = $dao->added_by;
                     continue;
                 }
                 $row[$key] = $dao->{$key};
             }
             if (isset($dao->civicrm_activity_source_contact_id)) {
                 $rows[$dao->civicrm_activity_source_contact_id][$val][] = $row;
             }
             if (isset($dao->target_contact_id)) {
                 $rows[$dao->target_contact_id][$val][] = $row;
             }
             if (isset($dao->assignee_contact_id)) {
                 $rows[$dao->assignee_contact_id][$val][] = $row;
             }
         }
         //unset the component header if data is not present
         foreach ($this->_component as $val) {
             if (!in_array($val, $eligibleResult)) {
                 unset($this->_columnHeadersComponent[$val]);
             }
         }
     }
     return $rows;
 }
Exemple #15
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;
 }
Exemple #16
0
/**
 * System.Get API.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_system_get($params)
{
    $config = CRM_Core_Config::singleton();
    $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'time' => time(), 'tz' => date_default_timezone_get(), 'sapi' => php_sapi_name(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version'), 'time' => CRM_Core_DAO::singleValueQuery('SELECT unix_timestamp()'), 'vars' => _civicrm_api3_system_get_redacted_mysql()), 'cms' => array('version' => $config->userSystem->getVersion(), 'type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'multidomain' => CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM civicrm_domain') > 1, 'settings' => _civicrm_api3_system_get_redacted_settings(), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE)), 'http' => array('software' => CRM_Utils_Array::value('SERVER_SOFTWARE', $_SERVER), 'forwarded' => !empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['X_FORWARDED_PROTO']), 'port' => empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? 'Standard' : 'Nonstandard'), 'os' => array('type' => php_uname('s'), 'release' => php_uname('r'), 'version' => php_uname('v'), 'machine' => php_uname('m'))));
    return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
}
Exemple #17
0
 /**
  * @return array
  *   each item has keys:
  *   - name: string
  *   - type: string
  *   - count: int
  *   - table: string|null SQL table name
  *   - key: string|null SQL column name
  */
 public function getReferenceCounts()
 {
     $links = self::getReferencesToTable(static::getTableName());
     $counts = array();
     foreach ($links as $refSpec) {
         /** @var $refSpec CRM_Core_Reference_Interface */
         $count = $refSpec->getReferenceCount($this);
         if ($count['count'] != 0) {
             $counts[] = $count;
         }
     }
     foreach (CRM_Core_Component::getEnabledComponents() as $component) {
         /** @var $component CRM_Core_Component_Info */
         $counts = array_merge($counts, $component->getReferenceCounts($this));
     }
     CRM_Utils_Hook::referenceCounts($this, $counts);
     return $counts;
 }
Exemple #18
0
 /**
  * Run some sanity checks.
  *
  * This could become a hook so that CiviCRM can run both built-in
  * configuration & sanity checks, and modules/extensions can add
  * their own checks.
  *
  * We might even expose the results of these checks on the Wordpress
  * plugin status page or the Drupal admin/reports/status path.
  *
  * @return array
  *   Array of messages
  * @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements
  */
 public function checkAll()
 {
     $checks = array();
     $checks[] = new CRM_Utils_Check_Security();
     $checks[] = new CRM_Utils_Check_Env();
     $compInfo = CRM_Core_Component::getEnabledComponents();
     foreach ($compInfo as $compObj) {
         switch ($compObj->info['name']) {
             case 'CiviCase':
                 $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name'));
                 break;
             default:
         }
     }
     $messages = array();
     foreach ($checks as $check) {
         $messages = array_merge($messages, $check->checkAll());
     }
     CRM_Utils_Hook::check($messages);
     return $messages;
 }
 /**
  * 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');
 }
Exemple #20
0
 /**
  * View summary details of a contact.
  */
 public function view()
 {
     // Add js for tabs, in-place editing, and jstree for tags
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')->addSetting(array('summaryPrint' => array('mode' => $this->_print), 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary'))));
     $this->assign('summaryPrint', $this->_print);
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
     // Let summary page know if outbound mail is disabled so email links can be built conditionally
     $mailingBackend = Civi::settings()->get('mailing_backend');
     $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id'), 'im' => array('type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id'), 'website' => array('type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id'), 'address' => array('skip' => TRUE, 'customData' => 1), 'email' => array('skip' => TRUE), 'openid' => array('skip' => TRUE));
     foreach ($communicationType as $key => $value) {
         if (!empty($defaults[$key])) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
                 if (empty($value['skip'])) {
                     $daoName = $value['daoName'];
                     $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE);
                 }
             }
             if (isset($value['customData'])) {
                 foreach ($defaults[$key] as $blockId => $blockVal) {
                     $idValue = $blockVal['id'];
                     if ($key == 'address') {
                         if (!empty($blockVal['master_id'])) {
                             $idValue = $blockVal['master_id'];
                         }
                     }
                     $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $idValue);
                     // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
                     $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
                 }
                 // reset template variable since that won't be of any use, and could be misleading
                 $this->assign("dnc_viewCustomData", NULL);
             }
         }
     }
     if (!empty($defaults['gender_id'])) {
         $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']);
     }
     $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
     if (!empty($communicationStyle)) {
         if (!empty($defaults['communication_style_id'])) {
             $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
         } else {
             // Make sure the field is displayed as long as it is active, even if it is unset for this contact.
             $defaults['communication_style_display'] = '';
         }
     }
     // to make contact type label available in the template -
     $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
     $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', ');
     // get contact tags
     $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
     if (!empty($contactTags)) {
         $defaults['contactTag'] = implode(', ', $contactTags);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options');
     foreach ($this->_editOptions as $blockName => $value) {
         $varName = '_show' . $blockName;
         $this->{$varName} = $value;
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     // get contact name of shared contact names
     $sharedAddresses = array();
     $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
     foreach ($defaults['address'] as $key => $addressValue) {
         if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
             $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
         }
     }
     $this->assign('sharedAddresses', $sharedAddresses);
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         if ($contact->employer_id && $contact->organization_name) {
             $defaults['current_employer'] = $contact->organization_name;
             $defaults['current_employer_id'] = $contact->employer_id;
         }
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $defaults['external_identifier'] = $contact->external_identifier;
     $this->assign($defaults);
     // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
     // also assign the last modifed details
     $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE);
     // show the tabs only if user has generic access to CiviCRM
     $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (!empty($this->_viewOptions[$name]) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q .= "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'class' => 'livePage');
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => array('title' => ts('Activities'), 'class' => 'livePage'), 'rel' => array('title' => ts('Relationships'), 'class' => 'livePage'), 'group' => array('title' => ts('Groups'), 'class' => 'ajaxForm'), 'note' => array('title' => ts('Notes'), 'class' => 'livePage'), 'tag' => array('title' => ts('Tags')), 'log' => array('title' => ts('Change Log')));
     foreach ($rest as $k => $v) {
         if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
             $allTabs[] = $v + array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&cid={$this->_contactId}"), 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $entityType = $this->get('contactType');
     $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage');
         $weight += 10;
     }
     $context = array('contact_id' => $this->_contactId);
     // see if any other modules want to add any tabs
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
     $allTabs[] = array('id' => 'summary', 'url' => '#contact-summary', 'title' => ts('Summary'), 'weight' => 0);
     // now sort the tabs based on weight
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     // hook for contact summary
     // ignored but needed to prevent warnings
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
 static function &basicPermissions($all = FALSE)
 {
     static $permissions = NULL;
     if (!$permissions) {
         $prefix = ts('CiviCRM') . ': ';
         $permissions = self::getCorePermissions();
         if (self::isMultisiteEnabled()) {
             $permissions['administer Multiple Organizations'] = $prefix . ts('administer Multiple Organizations');
         }
         $config = CRM_Core_Config::singleton();
         if (!$all) {
             $components = CRM_Core_Component::getEnabledComponents();
         } else {
             $components = CRM_Core_Component::getComponents();
         }
         foreach ($components as $comp) {
             $perm = $comp->getPermissions();
             if ($perm) {
                 $info = $comp->getInfo();
                 foreach ($perm as $p) {
                     $permissions[$p] = $info['translatedName'] . ': ' . $p;
                 }
             }
         }
     }
     return $permissions;
 }
 /**
  * Function to build user dashboard
  *
  * @return void
  * @access public
  */
 function buildUserDashBoard()
 {
     //build component selectors
     $dashboardElements = array();
     $config = CRM_Core_Config::singleton();
     $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'user_dashboard_options');
     $components = CRM_Core_Component::getEnabledComponents();
     $this->assign('contactId', $this->_contactId);
     foreach ($components as $name => $component) {
         $elem = $component->getUserDashboardElement();
         if (!$elem) {
             continue;
         }
         if (!empty($this->_userOptions[$name]) && (CRM_Core_Permission::access($component->name) || CRM_Core_Permission::check($elem['perm'][0]))) {
             $userDashboard = $component->getUserDashboardObject();
             $dashboardElements[] = array('class' => 'crm-dashboard-' . strtolower($component->name), 'sectionTitle' => $elem['title'], 'templatePath' => $userDashboard->getTemplateFileName(), 'weight' => $elem['weight']);
             $userDashboard->run();
         }
     }
     if (!empty($this->_userOptions['Permissioned Orgs'])) {
         $dashboardElements[] = array('class' => 'crm-dashboard-permissionedOrgs', 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl', 'sectionTitle' => ts('Your Contacts / Organizations'), 'weight' => 40);
     }
     if (!empty($this->_userOptions['PCP'])) {
         $dashboardElements[] = array('class' => 'crm-dashboard-pcp', 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', 'sectionTitle' => ts('Personal Campaign Pages'), 'weight' => 40);
         list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId);
         $this->assign('pcpBlock', $pcpBlock);
         $this->assign('pcpInfo', $pcpInfo);
     }
     if (!empty($this->_userOptions['Assigned Activities'])) {
         // Assigned Activities section
         $dashboardElements[] = array('class' => 'crm-dashboard-assignedActivities', 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl', 'sectionTitle' => ts('Your Assigned Activities'), 'weight' => 5);
         $userDashboard = new CRM_Activity_Page_UserDashboard();
         $userDashboard->run();
     }
     usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('dashboardElements', $dashboardElements);
     if (!empty($this->_userOptions['Groups'])) {
         $this->assign('showGroup', TRUE);
         //build group selector
         $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
         $gContact->run();
     } else {
         $this->assign('showGroup', FALSE);
     }
 }
Exemple #23
0
 /**
  * Run all system checks.
  *
  * This functon is wrapped by the System.check api.
  *
  * Calls hook_civicrm_check() for extensions to add or modify messages.
  * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_check
  *
  * @param bool $max
  *   Whether to return just the maximum non-hushed severity
  *
  * @return array
  *   Array of CRM_Utils_Check_Message objects
  */
 public static function checkAll($max = FALSE)
 {
     $checks = array();
     $checks[] = new CRM_Utils_Check_Security();
     $checks[] = new CRM_Utils_Check_Env();
     $compInfo = CRM_Core_Component::getEnabledComponents();
     foreach ($compInfo as $compObj) {
         switch ($compObj->info['name']) {
             case 'CiviCase':
                 $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name'));
                 break;
             default:
         }
     }
     $messages = array();
     foreach ($checks as $check) {
         $messages = array_merge($messages, $check->checkAll());
     }
     CRM_Utils_Hook::check($messages);
     uasort($messages, array(__CLASS__, 'severitySort'));
     $maxSeverity = 1;
     foreach ($messages as $message) {
         if (!$message->isVisible()) {
             continue;
         }
         $maxSeverity = max(1, $message->getLevel());
         break;
     }
     Civi::settings()->set('systemStatusCheckResult', $maxSeverity);
     return $max ? $maxSeverity : $messages;
 }
Exemple #24
0
 /**
  * Function to build user dashboard
  *
  * @return none
  * @access public
  */
 function buildUserDashBoard()
 {
     //build component selectors
     $dashboardElements = array();
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_userOptions = CRM_Core_BAO_Preferences::valueOptions('user_dashboard_options');
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         $elem = $component->getUserDashboardElement();
         if (!$elem) {
             continue;
         }
         if (CRM_Utils_Array::value($name, $this->_userOptions) && (CRM_Core_Permission::access($component->name) || CRM_Core_Permission::check($elem['perm'][0]))) {
             $userDashboard = $component->getUserDashboardObject();
             $dashboardElements[] = array('templatePath' => $userDashboard->getTemplateFileName(), 'sectionTitle' => $elem['title'], 'weight' => $elem['weight']);
             $userDashboard->run();
         }
     }
     $sectionName = 'Permissioned Orgs';
     if ($this->_userOptions[$sectionName]) {
         $dashboardElements[] = array('templatePath' => 'CRM/Contact/Page/View/Relationship.tpl', 'sectionTitle' => ts('Your Contacts / Organizations'), 'weight' => 40);
         $links =& self::links();
         $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, $links, null, true);
         $this->assign('currentRelationships', $currentRelationships);
     }
     if ($this->_userOptions['PCP']) {
         require_once 'CRM/Contribute/BAO/PCP.php';
         $dashboardElements[] = array('templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', 'sectionTitle' => ts('Personal Campaign Pages'), 'weight' => 40);
         list($pcpBlock, $pcpInfo) = CRM_Contribute_BAO_PCP::getPcpDashboardInfo($this->_contactId);
         $this->assign('pcpBlock', $pcpBlock);
         $this->assign('pcpInfo', $pcpInfo);
     }
     require_once 'CRM/Utils/Sort.php';
     usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('dashboardElements', $dashboardElements);
     if ($this->_userOptions['Groups']) {
         $this->assign('showGroup', true);
         //build group selector
         require_once "CRM/Contact/Page/View/UserDashBoard/GroupContact.php";
         $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
         $gContact->run();
     } else {
         $this->assign('showGroup', false);
     }
 }
Exemple #25
0
/**
 * System.Get API.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_system_get($params)
{
    $config = CRM_Core_Config::singleton();
    $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'tz' => date_default_timezone_get(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version')), 'cms' => array('type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE))));
    return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
}
 /**
  * @param bool $all
  * @param bool $descriptions
  *   whether to return descriptions
  *
  * @return array
  */
 public static function assembleBasicPermissions($all = FALSE, $descriptions = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $prefix = ts('CiviCRM') . ': ';
     $permissions = self::getCorePermissions($descriptions);
     if (self::isMultisiteEnabled()) {
         $permissions['administer Multiple Organizations'] = array($prefix . ts('administer Multiple Organizations'));
     }
     if (!$all) {
         $components = CRM_Core_Component::getEnabledComponents();
     } else {
         $components = CRM_Core_Component::getComponents();
     }
     foreach ($components as $comp) {
         $perm = $comp->getPermissions(FALSE, $descriptions);
         if ($perm) {
             $info = $comp->getInfo();
             foreach ($perm as $p => $attr) {
                 if (!is_array($attr)) {
                     $attr = array($attr);
                 }
                 $attr[0] = $info['translatedName'] . ': ' . $attr[0];
                 if ($descriptions) {
                     $permissions[$p] = $attr;
                 } else {
                     $permissions[$p] = $attr[0];
                 }
             }
         }
     }
     // Add any permissions defined in hook_civicrm_permission implementations.
     $module_permissions = $config->userPermissionClass->getAllModulePermissions($descriptions);
     $permissions = array_merge($permissions, $module_permissions);
     return $permissions;
 }
 /**
  * Pick a message to display.
  *
  * @return NULL|array
  */
 public function pick()
 {
     $document = $this->getDocument();
     $messages = array();
     foreach ($document['messages'] as $message) {
         if (!isset($message['perms'])) {
             $message['perms'] = array(self::DEFAULT_PERMISSION);
         }
         if (!CRM_Core_Permission::checkAnyPerm($message['perms'])) {
             continue;
         }
         if (isset($message['components'])) {
             $enabled = array_keys(CRM_Core_Component::getEnabledComponents());
             if (count(array_intersect($enabled, $message['components'])) == 0) {
                 continue;
             }
         }
         $messages[] = $message;
     }
     if (empty($messages)) {
         return NULL;
     }
     $idx = rand(0, count($messages) - 1);
     return $messages[$idx];
 }
 /**
  * Create custom field.
  *
  * @param array $params
  *   (custom_group_id) is required.
  * @return array
  */
 public function customFieldCreate($params)
 {
     $params = array_merge(array('label' => 'Custom Field', 'data_type' => 'String', 'html_type' => 'Text', 'is_searchable' => 1, 'is_active' => 1, 'default_value' => 'defaultValue'), $params);
     $result = $this->callAPISuccess('custom_field', 'create', $params);
     // these 2 functions are called with force to flush static caches
     CRM_Core_BAO_CustomField::getTableColumnGroup($result['id'], 1);
     CRM_Core_Component::getEnabledComponents(1);
     return $result;
 }
 /**
  * Get the component id and name if those are enabled and allowed.
  *
  * Checks whether logged in user has permission.
  * To decide whether we are going to include
  * component related activities with core activity retrieve process.
  * (what did that just mean?)
  *
  * @return array
  *   Array of component id and name.
  */
 public static function activityComponents()
 {
     $components = array();
     $compInfo = CRM_Core_Component::getEnabledComponents();
     foreach ($compInfo as $compObj) {
         if (!empty($compObj->info['showActivitiesInCore'])) {
             if ($compObj->info['name'] == 'CiviCampaign') {
                 $componentPermission = "administer {$compObj->name}";
             } else {
                 $componentPermission = "access {$compObj->name}";
             }
             if ($compObj->info['name'] == 'CiviCase') {
                 if (CRM_Case_BAO_Case::accessCiviCase()) {
                     $components[$compObj->componentID] = $compObj->info['name'];
                 }
             } elseif (CRM_Core_Permission::check($componentPermission)) {
                 $components[$compObj->componentID] = $compObj->info['name'];
             }
         }
     }
     return $components;
 }
Exemple #30
0
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true));
     foreach ($communicationType as $key => $value) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false);
                 if (!CRM_Utils_Array::value('skip', $value)) {
                     eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false);
                 }
             }
             if (isset($value['customData'])) {
                 foreach ($defaults[$key] as $blockId => $blockVal) {
                     $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']);
                     // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
                     $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_");
                 }
                 // reset template variable since that won't be of any use, and could be misleading
                 $this->assign("dnc_viewCustomData", null);
             }
         }
     }
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // to make contact type label available in the template -
     $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
     $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType);
     // get contact tags
     require_once 'CRM/Core/BAO/EntityTag.php';
     $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
     if (!empty($contactTags)) {
         $defaults['contactTag'] = implode(', ', $contactTags);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options');
     $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes');
     foreach ($configItems as $c => $t) {
         $varName = '_show' . $c;
         $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions);
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     // get contact name of shared contact names
     $sharedAddresses = array();
     $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
     foreach ($defaults['address'] as $key => $addressValue) {
         if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
             $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
         }
     }
     $this->assign('sharedAddresses', $sharedAddresses);
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         if ($contact->employer_id && $contact->organization_name) {
             $defaults['current_employer'] = $contact->organization_name;
             $defaults['current_employer_id'] = $contact->employer_id;
         }
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $this->assign($defaults);
     // also assign the last modifed details
     require_once 'CRM/Core/BAO/Log.php';
     $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true);
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     require_once 'CRM/Core/Component.php';
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q = $q . "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId));
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log'));
     $config = CRM_Core_Config::singleton();
     if (isset($config->sunlight) && $config->sunlight) {
         $title = ts('Elected Officials');
         $rest['sunlight'] = $title;
         $this->_viewOptions[$title] = true;
     }
     foreach ($rest as $k => $v) {
         if (CRM_Utils_Array::value($k, $this->_viewOptions)) {
             $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $entityType = $this->get('contactType');
     $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']));
         $weight += 10;
     }
     // see if any other modules want to add any tabs
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     // now sort the tabs based on weight
     require_once 'CRM/Utils/Sort.php';
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary');
     $this->assign('selectedChild', $selectedChild);
     // hook for contact summary
     require_once 'CRM/Utils/Hook.php';
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     // ignored but needed to prevent warnings
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }