예제 #1
0
 /**
  * Reset the various system caches and some important static variables.
  */
 public static function flushCache()
 {
     // flush out all cache entries so we can reload new data
     // a bit aggressive, but livable for now
     $cache = CRM_Utils_Cache::singleton();
     $cache->flush();
     // also reset the various static memory caches
     // reset the memory or array cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields', NULL, FALSE);
     // reset ACL cache
     CRM_ACL_BAO_Cache::resetCache();
     // reset various static arrays used here
     CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = CRM_Contribute_BAO_Contribution::$_importableFields = CRM_Contribute_BAO_Contribution::$_exportableFields = CRM_Pledge_BAO_Pledge::$_exportableFields = CRM_Contribute_BAO_Query::$_contributionFields = CRM_Core_BAO_CustomField::$_importFields = CRM_Core_BAO_Cache::$_cache = CRM_Core_DAO::$_dbColumnValueCache = NULL;
     CRM_Core_OptionGroup::flushAll();
     CRM_Utils_PseudoConstant::flushAll();
 }
예제 #2
0
 public function postProcess()
 {
     $values = $this->exportValues();
     // make the site multi-lang if requested
     if (CRM_Utils_Array::value('makeMultilingual', $values)) {
         require_once 'CRM/Core/I18n/Schema.php';
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (CRM_Utils_Array::value('makeSinglelingual', $values)) {
         require_once 'CRM/Core/I18n/Schema.php';
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         require_once 'CRM/Core/DAO/Domain.php';
         $domain =& new CRM_Core_DAO_Domain();
         $domain->find(true);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             require_once 'CRM/Core/I18n/Schema.php';
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values) or CRM_Utils_Array::value('makeSinglelingual', $values));
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     // we do this only to initialize monetary decimal point and thousand separator
     $config =& CRM_Core_Config::singleton();
     if ($monetaryPointSeparator = $config->defaultMonetaryPointSeparator($values['lcMonetary'])) {
         $values['monetaryDecimalPoint'] = CRM_Utils_Array::value('decimal_point', $monetaryPointSeparator);
         $values['monetaryThousandSeparator'] = CRM_Utils_Array::value('thousands_sep', $monetaryPointSeparator);
     }
     // save all the settings
     parent::commonProcess($values);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
예제 #3
0
파일: Field.php 프로젝트: hguru/224Civi
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $dataTypeKey = $this->_defaultDataType[0];
         $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]];
         $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]];
     } else {
         $dataTypeKey = $params['data_type'][0];
         $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]];
         $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]];
     }
     //fix for 'is_search_range' field.
     if (in_array($dataTypeKey, array(1, 2, 3, 5))) {
         if (!CRM_Utils_Array::value('is_searchable', $params)) {
             $params['is_search_range'] = 0;
         }
     } else {
         $params['is_search_range'] = 0;
     }
     $filter = 'null';
     if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) {
         if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) {
             $filter = trim($params['filter']);
         } elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) {
             $filter = 'action=lookup&group=' . implode(',', $params['group_id']);
         }
     }
     $params['filter'] = $filter;
     // fix for CRM-316
     $oldWeight = NULL;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('custom_group_id' => $this->_gid);
         if ($this->_id) {
             $oldWeight = $this->_values['weight'];
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues);
     }
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     //store the primary key for State/Province or Country as default value.
     if (strlen(trim($params['default_value']))) {
         switch ($params['data_type']) {
             case 'StateProvince':
                 $fieldStateProvince = $strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_state_province\n WHERE LOWER(name) = '{$fieldStateProvince}'\n    OR abbreviation = '{$fieldStateProvince}'";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
             case 'Country':
                 $fieldCountry = $strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}'\n    OR iso_code = '{$fieldCountry}'";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
         }
     }
     // The text_length attribute for Memo fields is in a different input as there
     // are different label, help text and default value than for other type fields
     if ($params['data_type'] == "Memo") {
         $params['text_length'] = $params['note_length'];
     }
     // need the FKEY - custom group id
     $params['custom_group_id'] = $this->_gid;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $customField = CRM_Core_BAO_CustomField::create($params);
     // reset the cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)), ts('Saved'), 'success');
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info');
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $this->_gid));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid));
     }
 }
예제 #4
0
 public function postProcess()
 {
     $values = $this->exportValues();
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('navigation');
     // we do this only to initialize monetary decimal point and thousand separator
     $config = CRM_Core_Config::singleton();
     // save enabled currencies and defaul currency in option group 'currencies_enabled'
     // CRM-1496
     if (empty($values['currencyLimit'])) {
         $values['currencyLimit'] = array($values['defaultCurrency']);
     } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) {
         $values['currencyLimit'][] = $values['defaultCurrency'];
     }
     // sort so that when we display drop down, weights have right value
     sort($values['currencyLimit']);
     // get labels for all the currencies
     $options = array();
     $currencySymbols = self::getCurrencySymbols();
     for ($i = 0; $i < count($values['currencyLimit']); $i++) {
         $options[] = array('label' => $currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']);
     }
     $dontCare = NULL;
     CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare);
     // unset currencyLimit so we dont store there
     unset($values['currencyLimit']);
     // make the site multi-lang if requested
     if (!empty($values['makeMultilingual'])) {
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (!empty($values['makeSinglelingual'])) {
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
         $values['languageLimit'] = '';
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values));
     $filteredValues = $values;
     unset($filteredValues['makeMultilingual']);
     unset($filteredValues['makeSinglelingual']);
     unset($filteredValues['addLanguage']);
     unset($filteredValues['languageLimit']);
     Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values));
     // save all the settings
     parent::commonProcess($filteredValues);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
예제 #5
0
파일: Group.php 프로젝트: ksecor/civicrm
 /**
  * Create a new group
  *
  * @param array $params     Associative array of parameters
  * @return object|null      The new group BAO (if created)
  * @access public
  * @static
  */
 public static function &create(&$params)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Group', null, $params);
     }
     // form the name only if missing: CRM-627
     if (!CRM_Utils_Array::value('name', $params)) {
         require_once 'CRM/Utils/String.php';
         $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
     // convert params if array type
     if (isset($params['group_type'])) {
         if (is_array($params['group_type'])) {
             $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $params['group_type'] = '';
     }
     $group =& new CRM_Contact_BAO_Group();
     $group->copyValues($params);
     $group->save();
     if (!$group->id) {
         return null;
     }
     $group->buildClause();
     $group->save();
     // add custom field values
     if (CRM_Utils_Array::value('custom', $params)) {
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
     }
     // make the group, child of domain/site group by default.
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     require_once 'CRM/Core/BAO/Domain.php';
     require_once 'CRM/Contact/BAO/GroupNesting.php';
     $domainGroupID = CRM_Core_BAO_Domain::getGroupId();
     if (CRM_Utils_Array::value('no_parent', $params) !== 1) {
         if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && empty($params['parents']) && $domainGroupID != $group->id && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) {
             // if no parent present and the group doesn't already have any parents,
             // make sure site group goes as parent
             $params['parents'] = array($domainGroupID => 1);
         } else {
             if (!is_array($params['parents'])) {
                 $params['parents'] = array($params['parents'] => 1);
             }
         }
         foreach ($params['parents'] as $parentId => $dnc) {
             if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
                 CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
             }
         }
         // clear any descendant groups cache if exists
         require_once 'CRM/Core/BAO/Cache.php';
         $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
         // this is always required, since we don't know when a
         // parent group is removed
         require_once 'CRM/Contact/BAO/GroupNestingCache.php';
         CRM_Contact_BAO_GroupNestingCache::update();
         // update group contact cache for all parent groups
         $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
         foreach ($parentIds as $parentId) {
             CRM_Contact_BAO_GroupContactCache::add($parentId);
         }
     }
     if (CRM_Utils_Array::value('organization_id', $params)) {
         require_once 'CRM/Contact/BAO/GroupOrganization.php';
         $groupOrg = array();
         $groupOrg = $params;
         $groupOrg['group_id'] = $group->id;
         CRM_Contact_BAO_GroupOrganization::add($groupOrg);
     }
     CRM_Contact_BAO_GroupContactCache::add($group->id);
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Group', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('create', 'Group', $group->id, $group);
     }
     return $group;
 }
예제 #6
0
파일: SqlGroup.php 프로젝트: hguru/224Civi
 function flush()
 {
     CRM_Core_BAO_Cache::deleteGroup($this->group);
     $this->frontCache = array();
 }
예제 #7
0
파일: Field.php 프로젝트: ksecor/civicrm
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $dataTypeKey = $this->_defaultDataType[0];
         $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]];
         $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]];
     } else {
         $dataTypeKey = $params['data_type'][0];
         $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]];
         $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]];
     }
     //fix for 'is_search_range' field.
     if (in_array($dataTypeKey, array(1, 2, 3, 5))) {
         if (!CRM_Utils_Array::value('is_searchable', $params)) {
             $params['is_search_range'] = 0;
         }
     } else {
         $params['is_search_range'] = 0;
     }
     // fix for CRM-316
     $oldWeight = null;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('custom_group_id' => $this->_gid);
         if ($this->_id) {
             $oldWeight = $this->_values['weight'];
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues);
     }
     //store the primary key for State/Province or Country as default value.
     if (strlen(trim($params['default_value']))) {
         switch ($params['data_type']) {
             case 'StateProvince':
                 $fieldStateProvince = strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_state_province \n WHERE LOWER(name) = '{$fieldStateProvince}' \n    OR abbreviation = '{$fieldStateProvince}'";
                 $dao =& CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
             case 'Country':
                 $fieldCountry = strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}' \n    OR iso_code = '{$fieldCountry}'";
                 $dao =& CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
         }
     }
     // need the FKEY - custom group id
     $params['custom_group_id'] = $this->_gid;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $customField = CRM_Core_BAO_CustomField::create($params);
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)));
     $buttonName = $this->controller->getButtonName();
     $session =& CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another custom field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=add&gid=' . $this->_gid));
     }
 }
예제 #8
0
 /**
  * Create a new group.
  *
  * @param array $params
  *
  * @return CRM_Contact_BAO_Group|NULL
  *   The new group BAO (if created)
  */
 public static function &create(&$params)
 {
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Group', NULL, $params);
     }
     // form the name only if missing: CRM-627
     $nameParam = CRM_Utils_Array::value('name', $params, NULL);
     if (!$nameParam && empty($params['id'])) {
         $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
     // convert params if array type
     if (isset($params['group_type'])) {
         if (is_array($params['group_type'])) {
             $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $params['group_type'] = '';
     }
     $session = CRM_Core_Session::singleton();
     $cid = $session->get('userID');
     // this action is add
     if ($cid && empty($params['id'])) {
         $params['created_id'] = $cid;
     }
     // this action is update
     if ($cid && !empty($params['id'])) {
         $params['modified_id'] = $cid;
     }
     $group = new CRM_Contact_BAO_Group();
     $group->copyValues($params);
     //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but
     // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn
     // use metadata to translate the array to the appropriate DB type or altering the param in the api layer,
     // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down
     // we need the $params one to be in it's original form & we are not sure what test coverage we have on that
     if (isset($group->parents) && is_array($group->parents)) {
         $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR;
     }
     if (empty($params['id']) && !$nameParam) {
         $group->name .= "_tmp";
     }
     $group->save();
     if (!$group->id) {
         return NULL;
     }
     if (empty($params['id']) && !$nameParam) {
         $group->name = substr($group->name, 0, -4) . "_{$group->id}";
     }
     $group->buildClause();
     $group->save();
     // add custom field values
     if (!empty($params['custom'])) {
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
     }
     // make the group, child of domain/site group by default.
     $domainGroupID = CRM_Core_BAO_Domain::getGroupId();
     if (CRM_Utils_Array::value('no_parent', $params) !== 1) {
         if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) {
             // if no parent present and the group doesn't already have any parents,
             // make sure site group goes as parent
             $params['parents'] = array($domainGroupID => 1);
         } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) {
             $params['parents'] = array($params['parents'] => 1);
         }
         if (!empty($params['parents'])) {
             foreach ($params['parents'] as $parentId => $dnc) {
                 if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
                     CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
                 }
             }
         }
         // clear any descendant groups cache if exists
         $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
         // this is always required, since we don't know when a
         // parent group is removed
         CRM_Contact_BAO_GroupNestingCache::update();
         // update group contact cache for all parent groups
         $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
         foreach ($parentIds as $parentId) {
             CRM_Contact_BAO_GroupContactCache::add($parentId);
         }
     }
     if (!empty($params['organization_id'])) {
         $groupOrg = array();
         $groupOrg = $params;
         $groupOrg['group_id'] = $group->id;
         CRM_Contact_BAO_GroupOrganization::add($groupOrg);
     }
     CRM_Contact_BAO_GroupContactCache::add($group->id);
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Group', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('create', 'Group', $group->id, $group);
     }
     $recentOther = array();
     if (CRM_Core_Permission::check('edit groups')) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id);
         // currently same permission we are using for delete a group
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id);
     }
     // add the recently added group (unless hidden: CRM-6432)
     if (!$group->is_hidden) {
         CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther);
     }
     return $group;
 }
예제 #9
0
파일: ThreeFour.php 프로젝트: kidaa30/yes
 /**
  * @param $rev
  */
 public function upgrade_3_4_6($rev)
 {
     $modifiedReportIds = array('event/summary', 'activity', 'Mailing/bounce', 'Mailing/clicks', 'Mailing/opened');
     $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
     while ($instances->fetch()) {
         $formValues = unserialize($instances->form_values);
         switch ($instances->report_id) {
             case 'event/summary':
                 $eventDates = array('event_start_date_from', 'event_start_date_to', 'event_end_date_from', 'event_end_date_to');
                 foreach ($eventDates as $date) {
                     if (isset($formValues[$date]) && $formValues[$date] == ' ') {
                         $formValues[$date] = '';
                     }
                 }
                 break;
             case 'activity':
                 if (isset($formValues['group_bys'])) {
                     if (is_array($formValues['group_bys'])) {
                         $orderBy = array();
                         $count = 0;
                         foreach ($formValues['group_bys'] as $col => $isSet) {
                             if (!$isSet) {
                                 continue;
                             }
                             $orderBy[++$count] = array('column' => $col, 'order' => 'ASC');
                         }
                         if (!empty($orderBy)) {
                             $formValues['order_bys'] = $orderBy;
                         }
                     }
                     unset($formValues['group_bys']);
                 }
                 break;
             case 'Mailing/bounce':
             case 'Mailing/clicks':
             case 'Mailing/opened':
                 $formValues['fields']['mailing_name'] = 1;
                 break;
         }
         // save updated instance criteria
         $dao = new CRM_Report_DAO_ReportInstance();
         $dao->id = $instances->id;
         $dao->form_values = serialize($formValues);
         $dao->save();
         $dao->free();
     }
     $bulkEmailActivityType = CRM_Core_DAO::singleValueQuery("\nSELECT v.id\nFROM   civicrm_option_value v,\n       civicrm_option_group g\nWHERE  v.option_group_id = g.id\n  AND  g.name      = %1\n  AND  g.is_active = 1\n  AND  v.name      = %2", array(1 => array('activity_type', 'String'), 2 => array('Bulk Email', 'String')));
     // CRM-8852, reset contact field cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('bulkEmailActivityType', $bulkEmailActivityType);
     $upgrade->processSQL($rev);
 }
예제 #10
0
 /**
  * Create a new group
  *
  * @param array $params     Associative array of parameters
  *
  * @return object|null      The new group BAO (if created)
  * @access public
  * @static
  */
 public static function &create(&$params)
 {
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Group', NULL, $params);
     }
     // form the name only if missing: CRM-627
     if (!CRM_Utils_Array::value('name', $params) && !CRM_Utils_Array::value('id', $params)) {
         $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
     // convert params if array type
     if (isset($params['group_type'])) {
         if (is_array($params['group_type'])) {
             $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $params['group_type'] = '';
     }
     $group = new CRM_Contact_BAO_Group();
     $group->copyValues($params);
     if (!CRM_Utils_Array::value('id', $params)) {
         $group->name .= "_tmp";
     }
     $group->save();
     if (!$group->id) {
         return NULL;
     }
     if (!CRM_Utils_Array::value('id', $params)) {
         $group->name = substr($group->name, 0, -4) . "_{$group->id}";
     }
     $group->buildClause();
     $group->save();
     // add custom field values
     if (CRM_Utils_Array::value('custom', $params)) {
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
     }
     // make the group, child of domain/site group by default.
     $domainGroupID = CRM_Core_BAO_Domain::getGroupId();
     if (CRM_Utils_Array::value('no_parent', $params) !== 1) {
         if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) {
             // if no parent present and the group doesn't already have any parents,
             // make sure site group goes as parent
             $params['parents'] = array($domainGroupID => 1);
         } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) {
             $params['parents'] = array($params['parents'] => 1);
         }
         if (!empty($params['parents'])) {
             foreach ($params['parents'] as $parentId => $dnc) {
                 if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
                     CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
                 }
             }
         }
         // clear any descendant groups cache if exists
         $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
         // this is always required, since we don't know when a
         // parent group is removed
         CRM_Contact_BAO_GroupNestingCache::update();
         // update group contact cache for all parent groups
         $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
         foreach ($parentIds as $parentId) {
             CRM_Contact_BAO_GroupContactCache::add($parentId);
         }
     }
     if (CRM_Utils_Array::value('organization_id', $params)) {
         $groupOrg = array();
         $groupOrg = $params;
         $groupOrg['group_id'] = $group->id;
         CRM_Contact_BAO_GroupOrganization::add($groupOrg);
     }
     CRM_Contact_BAO_GroupContactCache::add($group->id);
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Group', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('create', 'Group', $group->id, $group);
     }
     $recentOther = array();
     if (CRM_Core_Permission::check('edit groups')) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id);
         // currently same permission we are using for delete a group
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id);
     }
     // add the recently added group (unless hidden: CRM-6432)
     if (!$group->is_hidden) {
         CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther);
     }
     return $group;
 }
예제 #11
0
 /**
  * Evaluate locale preferences and activate a chosen locale by
  * updating session+global variables.
  *
  * @param \Civi\Core\SettingsBag $settings
  * @param string $activatedLocales
  *   Imploded list of locales which are supported in the DB.
  */
 public static function applyLocale($settings, $activatedLocales)
 {
     // are we in a multi-language setup?
     $multiLang = $activatedLocales ? TRUE : FALSE;
     // set the current language
     $chosenLocale = NULL;
     $session = CRM_Core_Session::singleton();
     // on multi-lang sites based on request and civicrm_uf_match
     if ($multiLang) {
         $languageLimit = array();
         if (is_array($settings->get('languageLimit'))) {
             $languageLimit = $settings->get('languageLimit');
         }
         $requestLocale = CRM_Utils_Request::retrieve('lcMessages', 'String');
         if (in_array($requestLocale, array_keys($languageLimit))) {
             $chosenLocale = $requestLocale;
             //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
             // Ed: This doesn't sound good.
             CRM_Core_BAO_Cache::deleteGroup('navigation');
         } else {
             $requestLocale = NULL;
         }
         if (!$requestLocale) {
             $sessionLocale = $session->get('lcMessages');
             if (in_array($sessionLocale, array_keys($languageLimit))) {
                 $chosenLocale = $sessionLocale;
             } else {
                 $sessionLocale = NULL;
             }
         }
         if ($requestLocale) {
             $ufm = new CRM_Core_DAO_UFMatch();
             $ufm->contact_id = $session->get('userID');
             if ($ufm->find(TRUE)) {
                 $ufm->language = $chosenLocale;
                 $ufm->save();
             }
             $session->set('lcMessages', $chosenLocale);
         }
         if (!$chosenLocale and $session->get('userID')) {
             $ufm = new CRM_Core_DAO_UFMatch();
             $ufm->contact_id = $session->get('userID');
             if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) {
                 $chosenLocale = $ufm->language;
             }
             $session->set('lcMessages', $chosenLocale);
         }
     }
     global $dbLocale;
     // try to inherit the language from the hosting CMS
     if ($settings->get('inheritLocale')) {
         // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
         $dbLocale = $multiLang ? "_" . $settings->get('lcMessages') : '';
         $chosenLocale = CRM_Utils_System::getUFLocale();
         if ($activatedLocales and !in_array($chosenLocale, explode(CRM_Core_DAO::VALUE_SEPARATOR, $activatedLocales))) {
             $chosenLocale = NULL;
         }
     }
     if (empty($chosenLocale)) {
         //CRM-11993 - if a single-lang site, use default
         $chosenLocale = $settings->get('lcMessages');
     }
     // set suffix for table names - use views if more than one language
     $dbLocale = $multiLang ? "_{$chosenLocale}" : '';
     // FIXME: an ugly hack to fix CRM-4041
     global $tsLocale;
     $tsLocale = $chosenLocale;
     // FIXME: as bad aplace as any to fix CRM-5428
     // (to be moved to a sane location along with the above)
     if (function_exists('mb_internal_encoding')) {
         mb_internal_encoding('UTF-8');
     }
 }
예제 #12
0
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues('Group');
     $params['overrideFKConstraint'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
         if ($this->_defaults['extends'][0] != $params['extends'][0]) {
             $params['overrideFKConstraint'] = 1;
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         //new custom set , so lets set the created_id
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $group = CRM_Core_BAO_CustomGroup::create($params);
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Session::setStatus(ts('Your custom field set \'%1 \' has been saved.', array(1 => $group->title)));
     } else {
         $url = CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $group->id);
         CRM_Core_Session::setStatus(ts('Your custom field set \'%1\' has been added. You can add it custom fields now.', array(1 => $group->title)));
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
     }
     // prompt Drupal Views users to update $db_prefix in settings.php, if necessary
     global $db_prefix;
     if (is_array($db_prefix) && CIVICRM_UF == 'Drupal' && module_exists('views')) {
         // get table_name for each custom group
         $tables = array();
         $sql = "SELECT table_name FROM civicrm_custom_group WHERE is_active = 1";
         $result = CRM_Core_DAO::executeQuery($sql);
         while ($result->fetch()) {
             $tables[$result->table_name] = $result->table_name;
         }
         // find out which tables are missing from the $db_prefix array
         $missingTableNames = array_diff_key($tables, $db_prefix);
         if (!empty($missingTableNames)) {
             CRM_Core_Session::setStatus('<br />' . ts('Note:To ensure that all of your custom data groups are available to Views, you may need to add the following key(s) to the $db_prefix array in your settings.php file: \'%1\'.', array(1 => implode(', ', $missingTableNames))));
         }
     }
 }
 /**
  * Reset navigation for all contacts
  */
 static function resetNavigation($contactId = NULL)
 {
     $params = array();
     $query = "UPDATE civicrm_setting SET value = NULL WHERE name='navigation'";
     if ($contactId) {
         $query .= " AND contact_id = %1";
         $params[1] = array((int) $contactId, 'Integer');
     } else {
         $query .= " AND contact_id IS NOT NULL";
     }
     CRM_Core_DAO::executeQuery($query, $params);
     CRM_Core_BAO_Cache::deleteGroup('navigation');
 }
 public function addGroup()
 {
     // add the 3 groups first
     $numGroup = count($this->group);
     require_once 'CRM/Contact/BAO/Group.php';
     for ($i = 0; $i < $numGroup; $i++) {
         $group = new CRM_Contact_BAO_Group();
         $group->name = $this->group[$i];
         $group->title = $this->group[$i];
         $group->group_type = "12";
         $group->visibility = 'Public Pages';
         $group->is_active = 1;
         $group->save();
         $group->buildClause();
         $group->save();
     }
     // 60 are for newsletter
     for ($i = 0; $i < 60; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // newsletter subscribers
         $groupContact->group_id = 2;
         $groupContact->contact_id = $this->individual[$i];
         // membership status
         $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->_getRandomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     // 15 volunteers
     for ($i = 0; $i < 15; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // Volunteers
         $groupContact->group_id = 3;
         $groupContact->contact_id = $this->individual[$i + 60];
         // membership status
         $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->_getRandomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     // 8 advisory board group
     for ($i = 0; $i < 8; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // advisory board group
         $groupContact->group_id = 4;
         $groupContact->contact_id = $this->individual[$i * 7];
         // membership status
         $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->_getRandomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     //In this function when we add groups that time we are cache the contact fields
     //But at the end of setup we are appending sample custom data, so for consistency
     //reset the cache.
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
 }
예제 #15
0
 /**
  * Process the form.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues('Group');
     $params['overrideFKConstraint'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
         if ($this->_defaults['extends'][0] != $params['extends'][0]) {
             $params['overrideFKConstraint'] = 1;
         }
         if (!empty($this->_subtypes)) {
             $subtypesToBeRemoved = array_diff($this->_subtypes, array_intersect($this->_subtypes, $params['extends'][1]));
             CRM_Contact_BAO_ContactType::deleteCustomRowsOfSubtype($this->_id, $subtypesToBeRemoved);
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         //new custom set , so lets set the created_id
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $group = CRM_Core_BAO_CustomGroup::create($params);
     // reset the cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Session::setStatus(ts('Your custom field set \'%1 \' has been saved.', array(1 => $group->title)), ts('Saved'), 'success');
     } else {
         // Jump directly to adding a field if popups are disabled
         $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? '' : '/add';
         $url = CRM_Utils_System::url("civicrm/admin/custom/group/field{$action}", 'reset=1&new=1&gid=' . $group->id . '&action=' . ($action ? 'add' : 'browse'));
         CRM_Core_Session::setStatus(ts("Your custom field set '%1' has been added. You can add custom fields now.", array(1 => $group->title)), ts('Saved'), 'success');
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
     }
     // prompt Drupal Views users to update $db_prefix in settings.php, if necessary
     global $db_prefix;
     $config = CRM_Core_Config::singleton();
     if (is_array($db_prefix) && $config->userSystem->is_drupal && module_exists('views')) {
         // get table_name for each custom group
         $tables = array();
         $sql = "SELECT table_name FROM civicrm_custom_group WHERE is_active = 1";
         $result = CRM_Core_DAO::executeQuery($sql);
         while ($result->fetch()) {
             $tables[$result->table_name] = $result->table_name;
         }
         // find out which tables are missing from the $db_prefix array
         $missingTableNames = array_diff_key($tables, $db_prefix);
         if (!empty($missingTableNames)) {
             CRM_Core_Session::setStatus(ts("To ensure that all of your custom data groups are available to Views, you may need to add the following key(s) to the db_prefix array in your settings.php file: '%1'.", array(1 => implode(', ', $missingTableNames))), ts('Note'), 'info');
         }
     }
 }
예제 #16
0
 /**
  * Update the is_active flag in the db.
  *
  * @param int $id
  *   Id of the database record.
  * @param bool $is_active
  *   Value we want to set the is_active field.
  *
  * @return Object
  *   DAO object on success, null otherwise
  */
 public static function setIsActive($id, $is_active)
 {
     // reset the cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     if (!$is_active) {
         CRM_Core_BAO_UFField::setUFFieldStatus($id, $is_active);
     }
     return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $id, 'is_active', $is_active);
 }
예제 #17
0
 /**
  * Reset navigation for all contacts or a specified contact.
  *
  * @param int $contactID
  *   Reset only entries belonging to that contact ID.
  *
  * @return string
  */
 public static function resetNavigation($contactID = NULL)
 {
     $newKey = CRM_Utils_String::createRandom(self::CACHE_KEY_STRLEN, CRM_Utils_String::ALPHANUMERIC);
     if (!$contactID) {
         $query = "UPDATE civicrm_setting SET value = '{$newKey}' WHERE name='navigation' AND contact_id IS NOT NULL";
         CRM_Core_DAO::executeQuery($query);
         CRM_Core_BAO_Cache::deleteGroup('navigation');
     } else {
         // before inserting check if contact id exists in db
         // this is to handle weird case when contact id is in session but not in db
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $contactID;
         if ($contact->find(TRUE)) {
             CRM_Core_BAO_Setting::setItem($newKey, CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, 'navigation', NULL, $contactID, $contactID);
         }
     }
     // also reset the dashlet cache in case permissions have changed etc
     // FIXME: decouple this
     CRM_Core_BAO_Dashboard::resetDashletCache($contactID);
     return $newKey;
 }
예제 #18
0
 /**
  * function to delete batch entry
  *
  * @param int $batchId batch id
  *
  * @return void
  * @access public
  */
 static function deleteBatch($batchId)
 {
     //delete batch entries from cache
     $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($batchId);
     CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE);
     // delete entry from batch table
     $batch = new CRM_Core_DAO_Batch();
     $batch->id = $batchId;
     $batch->delete();
 }
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_values['custom_group_id'], 'table_name');
     $singleValueOps = array('Text', 'Select', 'Radio', 'Autocomplete-Select');
     $mutliValueOps = array('CheckBox', 'Multi-Select', 'AdvMulti-Select');
     $srcHtmlType = $this->_values['html_type'];
     $dstHtmlType = $params['dst_html_type'];
     $customField = new CRM_Core_DAO_CustomField();
     $customField->id = $this->_id;
     $customField->find(TRUE);
     if ($dstHtmlType == 'Text' && in_array($srcHtmlType, array('Select', 'Radio', 'Autocomplete-Select'))) {
         $customField->option_group_id = "NULL";
         CRM_Core_BAO_CustomField::checkOptionGroup($this->_values['option_group_id']);
     }
     if (in_array($srcHtmlType, $mutliValueOps) && in_array($dstHtmlType, $singleValueOps)) {
         $this->flattenToFirstValue($tableName, $this->_values['column_name']);
     } elseif (in_array($srcHtmlType, $singleValueOps) && in_array($dstHtmlType, $mutliValueOps)) {
         $this->firstValueToFlatten($tableName, $this->_values['column_name']);
     }
     $customField->html_type = $dstHtmlType;
     $customField->save();
     // Reset cache for custom fields
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Input type of custom field \'%1\' has been successfully changed to \'%2\'.', array(1 => $this->_values['label'], 2 => $dstHtmlType)));
 }
예제 #20
0
 /**
  * Delete the Custom Field.
  *
  * @param   object $field - the field object
  * 
  * @return  boolean
  *
  * @access public
  * @static
  *
  */
 public static function deleteField($field)
 {
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     // reset various static arrays used here
     require_once 'CRM/Contact/BAO/Contact.php';
     CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = self::$_importFields = null;
     // first delete the custom option group and values associated with this field
     if ($field->option_group_id) {
         //check if option group is related to any other field, if
         //not delete the option group and related option values
         self::checkOptionGroup($field->option_group_id);
     }
     // next drop the column from the custom value table
     self::createField($field, 'delete');
     $field->delete();
     return;
 }
예제 #21
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     // note this also resets any ACL cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_ACL_BAO_ACL::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected ACL has been deleted.'));
     } else {
         $params = $this->controller->exportValues($this->_name);
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
         $params['deny'] = 0;
         $params['entity_table'] = 'civicrm_acl_role';
         // Figure out which type of object we're permissioning on and set object_table and object_id.
         switch ($params['object_type']) {
             case 1:
                 $params['object_table'] = 'civicrm_saved_search';
                 $params['object_id'] = $params['group_id'];
                 break;
             case 2:
                 $params['object_table'] = 'civicrm_uf_group';
                 $params['object_id'] = $params['uf_group_id'];
                 break;
             case 3:
                 $params['object_table'] = 'civicrm_custom_group';
                 $params['object_id'] = $params['custom_group_id'];
                 break;
             case 4:
                 $params['object_table'] = 'civicrm_event';
                 $params['object_id'] = $params['event_id'];
                 break;
         }
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         CRM_ACL_BAO_ACL::create($params);
     }
 }
예제 #22
0
 /**
  * Reset navigation for all contacts
  */
 static function resetNavigation()
 {
     $query = "UPDATE civicrm_preferences SET navigation = NULL WHERE contact_id IS NOT NULL";
     CRM_Core_DAO::executeQuery($query);
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('navigation');
 }
예제 #23
0
 /**
  * takes an associative array and creates a custom group object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Core_DAO_CustomGroup object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     // create custom group dao, populate fields and then save.
     $group = new CRM_Core_DAO_CustomGroup();
     $group->title = $params['title'];
     require_once 'CRM/Utils/String.php';
     if (isset($params['name'])) {
         $group->name = $params['name'];
     } else {
         $maxLength = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'name');
         $group->name = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $maxLength));
     }
     if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) {
         $group->extends = 'Participant';
     } else {
         $group->extends = $params['extends'][0];
     }
     $group->extends_entity_column_id = null;
     if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') {
         $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
     }
     //this is format when form get submit.
     $extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
     //lets allow user to pass direct child type value, CRM-6893
     if (CRM_Utils_Array::value('extends_entity_column_value', $params)) {
         $extendsChildType = $params['extends_entity_column_value'];
     }
     if (!CRM_Utils_System::isNull($extendsChildType)) {
         $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
         if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
             $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType);
         }
         if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) {
             $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $extendsChildType = 'null';
     }
     $group->extends_entity_column_value = $extendsChildType;
     if (isset($params['id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     require_once 'CRM/Utils/Weight.php';
     $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, false));
     $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple');
     foreach ($fields as $field) {
         $group->{$field} = CRM_Utils_Array::value($field, $params, false);
     }
     $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null';
     $tableName = null;
     if (isset($params['id'])) {
         $group->id = $params['id'];
         //check whether custom group was changed from single-valued to multiple-valued
         $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple');
         if ($params['is_multiple'] != $isMultiple && (CRM_Utils_Array::value('is_multiple', $params) || $isMultiple)) {
             $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         }
     } else {
         $group->created_id = CRM_Utils_Array::value('created_id', $params);
         $group->created_date = CRM_Utils_Array::value('created_date', $params);
         require_once 'CRM/Utils/String.php';
         // lets create the table associated with the group and save it
         $tableName = $group->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group->title, '_', 32));
         // we do this only once, so name never changes
         $group->name = CRM_Utils_String::munge($params['title'], '_', 64);
     }
     // enclose the below in a transaction
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $group->save();
     if ($tableName) {
         // now append group id to table name, this prevent any name conflicts
         // like CRM-2742
         $tableName .= "_{$group->id}";
         $group->table_name = $tableName;
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName);
         // now create the table associated with this group
         self::createTable($group);
     } elseif ($oldTableName) {
         require_once 'CRM/Core/BAO/SchemaHandler.php';
         CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
     }
     if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
         $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         require_once 'CRM/Core/BAO/SchemaHandler.php';
         CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
     }
     $transaction->commit();
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     require_once 'CRM/Utils/Hook.php';
     if ($tableName) {
         CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group);
     }
     return $group;
 }
예제 #24
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $params['actualBatchTotal'] = 0;
     // get the profile information
     if ($this->_batchInfo['type_id'] == 1) {
         $this->processContribution($params);
     } else {
         $this->processMembership($params);
     }
     // update batch to close status
     $paramValues = array('id' => $this->_batchId, 'status_id' => 2, 'total' => $params['actualBatchTotal']);
     CRM_Core_BAO_Batch::create($paramValues);
     // delete from cache table
     $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($this->_batchId);
     CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE);
     // set success status
     CRM_Core_Session::setStatus("Your batch has been processed.");
     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1&status=2'));
 }
예제 #25
0
 /**
  * Retrieve the settings values from db.
  *
  * @param $defaults
  *
  * @return array
  */
 public static function retrieve(&$defaults)
 {
     $domain = new CRM_Core_DAO_Domain();
     //we are initializing config, really can't use, CRM-7863
     $urlVar = 'q';
     if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
         $urlVar = 'task';
     }
     if (CRM_Core_Config::isUpgradeMode()) {
         $domain->selectAdd('config_backend');
     } elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
         $domain->selectAdd('config_backend', 'locales');
     } else {
         $domain->selectAdd('config_backend, locales, locale_custom_strings');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($defaults === FALSE || !is_array($defaults)) {
             $defaults = array();
             return FALSE;
         }
         $skipVars = self::skipVars();
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // check if there are any locale strings
         if ($domain->locale_custom_strings) {
             $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
         } else {
             $defaults['localeCustomStrings'] = NULL;
         }
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? TRUE : FALSE;
         // set the current language
         $lcMessages = NULL;
         $session = CRM_Core_Session::singleton();
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
                 //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
                 CRM_Core_BAO_Cache::deleteGroup('navigation');
             } else {
                 $lcMessagesRequest = NULL;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = NULL;
                 }
             }
             if ($lcMessagesRequest) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE)) {
                     $ufm->language = $lcMessages;
                     $ufm->save();
                 }
                 $session->set('lcMessages', $lcMessages);
             }
             if (!$lcMessages and $session->get('userID')) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) {
                     $lcMessages = $ufm->language;
                 }
                 $session->set('lcMessages', $lcMessages);
             }
         }
         global $dbLocale;
         // try to inherit the language from the hosting CMS
         if (!empty($defaults['inheritLocale'])) {
             // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
             $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
             $lcMessages = CRM_Utils_System::getUFLocale();
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales))) {
                 $lcMessages = NULL;
             }
         }
         if (empty($lcMessages)) {
             //CRM-11993 - if a single-lang site, use default
             $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults);
         }
         // set suffix for table names - use views if more than one language
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
         // FIXME: as bad aplace as any to fix CRM-5428
         // (to be moved to a sane location along with the above)
         if (function_exists('mb_internal_encoding')) {
             mb_internal_encoding('UTF-8');
         }
     }
     // dont add if its empty
     if (!empty($defaults)) {
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults);
         // Pickup enabled-components from settings table if found.
         $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
         if (!empty($enableComponents)) {
             $defaults['enableComponents'] = $enableComponents;
             $components = CRM_Core_Component::getComponents();
             $enabledComponentIDs = array();
             foreach ($defaults['enableComponents'] as $name) {
                 $enabledComponentIDs[] = $components[$name]->componentID;
             }
             $defaults['enableComponentIDs'] = $enabledComponentIDs;
         }
     }
 }
예제 #26
0
 /**
  * update the is_active flag in the db
  *
  * @param int      $id        id of the database record
  * @param boolean  $is_active value we want to set the is_active field
  *
  * @return Object             DAO object on sucess, null otherwise
  * @static
  */
 static function setIsActive($id, $is_active)
 {
     // note this also resets any ACL cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     return CRM_Core_DAO::setFieldValue('CRM_ACL_DAO_ACL', $id, 'is_active', $is_active);
 }
예제 #27
0
 /**
  * Reset navigation for all contacts
  *
  * @param integer $contactID - reset only entries belonging to that contact ID
  */
 static function resetNavigation($contactID = NULL)
 {
     $params = array();
     $query = "UPDATE civicrm_setting SET value = NULL WHERE name='navigation'";
     if ($contactID) {
         $query .= " AND contact_id = %1";
         $params[1] = array($contactID, 'Integer');
     } else {
         $query .= " AND contact_id IS NOT NULL";
     }
     CRM_Core_DAO::executeQuery($query, $params);
     CRM_Core_BAO_Cache::deleteGroup('navigation');
     // also reset the dashlet cache in case permissions have changed etc
     CRM_Core_BAO_Dashboard::resetDashletCache($contactID);
 }
예제 #28
0
 /**
  * This method populates the civicrm_group_contact table
  */
 private function addGroup()
 {
     // add the 3 groups first
     foreach ($this->sampleData['group'] as $groupName) {
         $group = new CRM_Contact_BAO_Group();
         $group->name = $group->title = $groupName;
         $group->group_type = "12";
         $group->visibility = 'Public Pages';
         $group->is_active = 1;
         $group->save();
         $group->buildClause();
         $group->save();
     }
     // 60 are for newsletter
     for ($i = 0; $i < 60; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // newsletter subscribers
         $groupContact->group_id = 2;
         $groupContact->contact_id = $this->Individual[$i];
         // always add members
         $groupContact->status = 'Added';
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->randomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     // 15 volunteers
     for ($i = 0; $i < 15; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // Volunteers
         $groupContact->group_id = 3;
         $groupContact->contact_id = $this->Individual[$i + 60];
         // membership status
         $groupContact->status = 'Added';
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->randomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     // 8 advisory board group
     for ($i = 0; $i < 8; $i++) {
         $groupContact = new CRM_Contact_DAO_GroupContact();
         // advisory board group
         $groupContact->group_id = 4;
         $groupContact->contact_id = $this->Individual[$i * 7];
         // membership status
         $groupContact->status = 'Added';
         $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
         $subscriptionHistory->contact_id = $groupContact->contact_id;
         $subscriptionHistory->group_id = $groupContact->group_id;
         $subscriptionHistory->status = $groupContact->status;
         // method
         $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod);
         $subscriptionHistory->date = $this->randomDate();
         if ($groupContact->status != 'Pending') {
             $this->_insert($groupContact);
         }
         $this->_insert($subscriptionHistory);
     }
     //In this function when we add groups that time we are cache the contact fields
     //But at the end of setup we are appending sample custom data, so for consistency
     //reset the cache.
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
 }
예제 #29
0
파일: Group.php 프로젝트: bhirsch/voipdev
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues('Group');
     $params['overrideFKConstraint'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
         if ($this->_defaults['extends'][0] != $params['extends'][0]) {
             $params['overrideFKConstraint'] = 1;
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         //new custom group, so lets set the created_id
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $group = CRM_Core_BAO_CustomGroup::create($params);
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Session::setStatus(ts('Your custom data group \'%1 \' has been saved.', array(1 => $group->title)));
     } else {
         $url = CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=add&gid=' . $group->id);
         CRM_Core_Session::setStatus(ts('Your custom data group \'%1\' has been added. You can add custom fields to this group now.', array(1 => $group->title)));
         $session =& CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
     }
 }