static function mailingPreferences() { if (!self::$_mailingPref) { $mailingPref = new CRM_Core_DAO_Preferences(); $mailingPref->domain_id = CRM_Core_Config::domainID(); $mailingPref->is_domain = true; $mailingPref->contact_id = null; $mailingPref->find(true); if ($mailingPref->mailing_backend) { self::$_mailingPref = unserialize($mailingPref->mailing_backend); } } return self::$_mailingPref; }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields =& self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['preferences'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
public function commonProcess(&$params) { require_once "CRM/Core/BAO/Setting.php"; CRM_Core_BAO_Setting::add($params); // also delete the CRM_Core_Config key from the database $cache =& CRM_Utils_Cache::singleton(); $cache->delete('CRM_Core_Config'); // save autocomplete search options if (CRM_Utils_Array::value('autocompleteContactSearch', $params)) { $config = new CRM_Core_DAO_Preferences(); $config->domain_id = CRM_Core_Config::domainID(); $config->find(true); $config->contact_autocomplete_options = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactSearch'])) . CRM_Core_DAO::VALUE_SEPARATOR; $config->save(); } // update time for date formats when global time is changed if (CRM_Utils_Array::value('timeInputFormat', $params)) { $query = "UPDATE civicrm_preferences_date SET time_format = " . $params['timeInputFormat'] . " \n WHERE time_format IS NOT NULL AND time_format <> ''"; CRM_Core_DAO::executeQuery($query); } CRM_Core_Session::setStatus(ts('Your changes have been saved.')); }
function upgrade($rev) { $upgrade = new CRM_Upgrade_Form(); //Run the SQL file $upgrade->processSQL($rev); // fix for CRM-5162 // we need to encrypt all smtpPasswords if present require_once "CRM/Core/DAO/Preferences.php"; $mailingDomain = new CRM_Core_DAO_Preferences(); $mailingDomain->find(); while ($mailingDomain->fetch()) { if ($mailingDomain->mailing_backend) { $values = unserialize($mailingDomain->mailing_backend); if (isset($values['smtpPassword'])) { require_once 'CRM/Utils/Crypt.php'; $values['smtpPassword'] = CRM_Utils_Crypt::encrypt($values['smtpPassword']); $mailingDomain->mailing_backend = serialize($values); $mailingDomain->save(); } } } require_once "CRM/Core/DAO/Domain.php"; $domain = new CRM_Core_DAO_Domain(); $domain->selectAdd(); $domain->selectAdd('config_backend'); $domain->find(true); if ($domain->config_backend) { $defaults = unserialize($domain->config_backend); if ($dateFormat = CRM_Utils_Array::value('dateformatQfDate', $defaults)) { $dateFormatArray = explode(" ", $dateFormat); //replace new date format based on previous month format //%b month name [abbreviated] //%B full month name ('January'..'December') //%m decimal number, 0-padded ('01'..'12') if ($dateFormat == '%b %d %Y') { $defaults['dateInputFormat'] = 'mm/dd/yy'; } else { if ($dateFormat == '%d-%b-%Y') { $defaults['dateInputFormat'] = 'dd-mm-yy'; } else { if (in_array('%b', $dateFormatArray)) { $defaults['dateInputFormat'] = 'M d, yy'; } else { if (in_array('%B', $dateFormatArray)) { $defaults['dateInputFormat'] = 'MM d, yy'; } else { $defaults['dateInputFormat'] = 'mm/dd/yy'; } } } } } // %p - lowercase ante/post meridiem ('am', 'pm') // %P - uppercase ante/post meridiem ('AM', 'PM') if ($dateTimeFormat = CRM_Utils_Array::value('dateformatQfDatetime', $defaults)) { $defaults['timeInputFormat'] = 2; $dateTimeFormatArray = explode(" ", $dateFormat); if (in_array('%P', $dateTimeFormatArray) || in_array('%p', $dateTimeFormatArray)) { $defaults['timeInputFormat'] = 1; } unset($defaults['dateformatQfDatetime']); } unset($defaults['dateformatQfDate']); unset($defaults['dateformatTime']); require_once "CRM/Core/BAO/Setting.php"; CRM_Core_BAO_Setting::add($defaults); } $sql = "SELECT id, form_values FROM civicrm_report_instance"; $instDAO = CRM_Core_DAO::executeQuery($sql); while ($instDAO->fetch()) { $fromVal = @unserialize($instDAO->form_values); foreach ((array) $fromVal as $key => $value) { if (strstr($key, '_relative')) { $elementName = substr($key, 0, strlen($key) - strlen('_relative')); $fromNamekey = $elementName . '_from'; $toNamekey = $elementName . '_to'; $fromNameVal = $fromVal[$fromNamekey]; $toNameVal = $fromVal[$toNamekey]; //check 'choose date range' is set if ($value == '0') { if (CRM_Utils_Date::isDate($fromNameVal)) { $fromDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($fromNameVal)); $fromNameVal = $fromDate[0]; } else { $fromNameVal = ''; } if (CRM_Utils_Date::isDate($toNameVal)) { $toDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($toNameVal)); $toNameVal = $toDate[0]; } else { $toNameVal = ''; } } else { $fromNameVal = ''; $toNameVal = ''; } $fromVal[$fromNamekey] = $fromNameVal; $fromVal[$toNamekey] = $toNameVal; continue; } } $fromVal = serialize($fromVal); $updateSQL = "UPDATE civicrm_report_instance SET form_values = '{$fromVal}' WHERE id = {$instDAO->id}"; CRM_Core_DAO::executeQuery($updateSQL); } $customFieldSQL = "SELECT id, date_format FROM civicrm_custom_field WHERE data_type = 'Date' "; $customDAO = CRM_Core_DAO::executeQuery($customFieldSQL); while ($customDAO->fetch()) { $datePartKey = $dateParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customDAO->date_format); $dateParts = array_combine($datePartKey, $dateParts); $year = CRM_Utils_Array::value('Y', $dateParts); $month = CRM_Utils_Array::value('M', $dateParts); $date = CRM_Utils_Array::value('d', $dateParts); $hour = CRM_Utils_Array::value('h', $dateParts); $minute = CRM_Utils_Array::value('i', $dateParts); $timeFormat = CRM_Utils_Array::value('A', $dateParts); $newDateFormat = 'mm/dd/yy'; if ($year && $month && $date) { $newDateFormat = 'mm/dd/yy'; } else { if (!$year && $month && $date) { $newDateFormat = 'mm/dd'; } } $newTimeFormat = 'NULL'; if ($timeFormat && $hour == 'h') { $newTimeFormat = 1; } else { if ($hour) { $newTimeFormat = 2; } } $updateSQL = "UPDATE civicrm_custom_field SET date_format = '{$newDateFormat}', time_format = {$newTimeFormat} WHERE id = {$customDAO->id}"; CRM_Core_DAO::executeQuery($updateSQL); } $template =& CRM_Core_Smarty::singleton(); $afterUpgradeMessage = ''; if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) { $afterUpgradeMessage .= "<br/><br/>"; } $afterUpgradeMessage .= ts("Date Input Format has been set to %1 format. If you want to use a different format please check Administer CiviCRM » Global Settings » Date Formats.", array(1 => $defaults['dateInputFormat'])); $template->assign('afterUpgradeMessage', $afterUpgradeMessage); }
/** * This function sets the default values for the form. * default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { if (!$this->_defaults) { $this->_defaults = array(); require_once "CRM/Core/DAO/Preferences.php"; $mailingDomain = new CRM_Core_DAO_Preferences(); $mailingDomain->find(true); if ($mailingDomain->mailing_backend) { $this->_defaults = unserialize($mailingDomain->mailing_backend); if (!empty($this->_defaults['smtpPassword'])) { require_once 'CRM/Utils/Crypt.php'; $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']); } } else { if (!isset($this->_defaults['smtpServer'])) { $this->_defaults['smtpServer'] = 'localhost'; $this->_defaults['smtpPort'] = 25; $this->_defaults['smtpAuth'] = 0; } if (!isset($this->_defaults['sendmail_path'])) { $this->_defaults['sendmail_path'] = '/usr/sbin/sendmail'; $this->_defaults['sendmail_args'] = '-i'; } } } return $this->_defaults; }
function mailerPreferences() { require_once "CRM/Core/DAO/Domain.php"; require_once 'CRM/Core/BAO/Preferences.php'; $mailerValues = array(); $mailerFields = array('outBound_option', 'smtpServer', 'smtpPort', 'smtpAuth', 'smtpUsername', 'smtpPassword', 'sendmail_path', 'sendmail_args'); //get the mailer preferences from backend //store in civicrm_preferences and unset from backend. $domain = new CRM_Core_DAO_Domain(); $domain->find(true); if ($domain->config_backend) { $backendValues = unserialize($domain->config_backend); foreach ($mailerFields as $field) { $mailerValues[$field] = CRM_Utils_Array::value($field, $backendValues); if (array_key_exists($field, $backendValues)) { unset($backendValues[$field]); } } $domain->config_backend = serialize($backendValues); $domain->save(); $mailingDomain = new CRM_Core_DAO_Preferences(); $mailingDomain->find(true); $mailingDomain->mailing_backend = serialize($mailerValues); $mailingDomain->save(); } }
/** * Function to create navigation for CiviCRM Admin Menu * * @param int $contactID contact id * * @return string $navigation returns navigation html * @static */ static function createNavigation($contactID) { if (!$contactID || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'navigation')) { return; } $config = CRM_Core_Config::singleton(); // For Joomla front end user, there is no need to create // navigation menu items, CRM-5349 if ($config->userFramework == 'Joomla' && $config->userFrameworkFrontend) { return "<!-- {$config->lcMessages} -->"; } $navParams = array('contact_id' => $contactID); if (CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'domain_id')) { // FIXME: if() condition check was required especially for upgrade // cases (2.2.x -> 3.0.x), CRM-5203 $navParams['domain_id'] = CRM_Core_Config::domainID(); } CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_Preferences', $navParams, $navParams); $navigation = array_key_exists('navigation', $navParams) ? $navParams['navigation'] : false; // FIXME: hack for CRM-5027: we need to prepend the navigation string with // (HTML-commented-out) locale info so that we rebuild menu on locale changes if (!$navigation or substr($navigation, 0, 14) != "<!-- {$config->lcMessages} -->") { //retrieve navigation if it's not cached. require_once 'CRM/Core/BAO/Navigation.php'; $navigation = self::buildNavigation(); //add additional navigation items $logoutURL = CRM_Utils_System::url('civicrm/logout', 'reset=1'); $appendSring = "<li id=\"menu-logout\" class=\"menumain\"><a href=\"{$logoutURL}\">" . ts('Logout') . "</a></li>"; // get home menu from db $homeParams = array('name' => 'Home'); $homeNav = array(); self::retrieve($homeParams, $homeNav); if ($homeNav) { $homeURL = CRM_Utils_System::url($homeNav['url']); $homeLabel = $homeNav['label']; } else { $homeURL = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); $homeLabel = ts('Home'); } if ($config->userFramework == 'Drupal' && function_exists('module_exists') && module_exists('admin_menu') && user_access('access administration menu')) { $prepandString = "<li class=\"menumain crm-link-home\">" . $homeLabel . "<ul id=\"civicrm-home\"><li><a href=\"{$homeURL}\">" . $homeLabel . "</a></li><li><a href=\"#\" onclick=\"cj.Menu.closeAll( );cj('#civicrm-menu').toggle( );\">" . ts('Drupal Menu') . "</a></li></ul></li>"; } else { $prepandString = "<li class=\"menumain crm-link-home\"><a href=\"{$homeURL}\" title=\"" . $homeLabel . "\">" . $homeLabel . "</a></li>"; } // prepend the navigation with locale info for CRM-5027 $navigation = "<!-- {$config->lcMessages} -->" . $prepandString . $navigation . $appendSring; // before inserting check if contact id exists in db // this is to handle wierd case when contact id is in session but not in db require_once 'CRM/Contact/DAO/Contact.php'; $contact = new CRM_Contact_DAO_Contact(); $contact->id = $contactID; if ($contact->find(true)) { // save in preference table for this particular user require_once 'CRM/Core/DAO/Preferences.php'; $preference = new CRM_Core_DAO_Preferences(); $preference->contact_id = $contactID; $preference->domain_id = CRM_Core_Config::domainID(); $preference->find(true); $preference->navigation = $navigation; $preference->save(); } } return $navigation; }