/**
  * Create WordPress user from contacts
  *
  * @access private
  *
  * @param array $rows The contacts data array
  * @return void
  */
 private function createUsers($rows)
 {
     // set debug flag when testing
     $debug = false;
     // init debug arrays
     $users = array();
     $messages = array();
     // extend PHP's execution time
     ini_set('max_execution_time', 300);
     // get default role only once
     $default_role = get_option('default_role');
     // get Civi config object
     $config = CRM_Core_Config::singleton();
     // code for redirect grabbed from CRM_Contact_Form_Task_Delete::postProcess()
     $urlParams = 'force=1';
     $urlString = "civicrm/contact/search/advanced";
     // let WordPress plugins know what we're about to do
     do_action('civicrm_wp_profile_sync_user_add_pre');
     // disable Civi's own register hook
     remove_action('user_register', array(civi_wp(), 'update_user'));
     remove_action('profile_update', array($this, 'update_user'));
     // process data
     foreach ($rows as $row) {
         // skip if no email
         if (empty($row['email'])) {
             continue;
         }
         // skip if email is not valid
         if (!is_email($row['email'])) {
             continue;
         }
         // skip if email already exists
         if (email_exists($row['email'])) {
             $messages[] = $row['email'] . ' already exists';
             continue;
         }
         // filter names
         $first_name = $this->filterName($row['first_name']);
         $middle_name = $this->filterName($row['middle_name']);
         $last_name = $this->filterName($row['last_name']);
         // lots of first names are simply initials - if so, use both first and middle names
         if (strlen($first_name) == 1) {
             $first_name .= $middle_name;
         }
         // lets only take a maximum of 8 letters of the last name
         $last_name = substr($last_name, 0, 8);
         // concatenate first and last names
         $uname = $first_name . $last_name;
         // construct a likely username
         $uname = sanitize_user($uname);
         // skip if username not valid
         if (!validate_username($uname)) {
             $messages[] = 'username ' . $uname . ' is not valid';
             continue;
         }
         // does this username already exist?
         if (username_exists($uname)) {
             $messages[] = 'username ' . $uname . ' already exists';
             $messages[] = $row;
             // let's try adding in the middle name
             $uname = $first_name . $middle_name . $last_name;
             // construct a likely username
             $uname = sanitize_user($uname);
             // skip if username not valid
             if (!validate_username($uname)) {
                 $messages[] = 'username ' . $uname . ' is not valid';
                 continue;
             }
             // skip if this username already exists
             if (username_exists($uname)) {
                 $messages[] = 'extra username ' . $uname . ' already exists';
                 continue;
             } else {
                 $messages[] = 'extra username ' . $uname . ' does not exist - we could add it';
             }
         }
         /**
          * We cannot create WP user using CRM_Core_BAO_CMSUser::create() because it
          * will attempt to log the user in and notify them of their new account. We
          * have to find another means to do this.
          *
          * In the meantime, what follows is cloned from the CiviCRM process for
          * creating WordPress users and modified accordingly.
          */
         // create an arbitrary password
         $password = substr(md5(uniqid(microtime())), 0, 8);
         // populate user data
         $user_data = array('ID' => '', 'user_login' => $uname, 'user_email' => $row['email'], 'user_pass' => $password, 'nickname' => $uname, 'role' => $default_role, 'first_name' => $row['first_name'], 'last_name' => $row['last_name']);
         // skip if debugging
         if (!$debug) {
             // add the user
             $user_id = wp_insert_user($user_data);
             // if contact doesn't already exist create UF Match
             if ($user_id !== FALSE && isset($row['id'])) {
                 $transaction = new CRM_Core_Transaction();
                 // create the UF Match record
                 $ufmatch = new CRM_Core_DAO_UFMatch();
                 $ufmatch->domain_id = CRM_Core_Config::domainID();
                 $ufmatch->uf_id = $user_id;
                 $ufmatch->contact_id = $row['id'];
                 $ufmatch->uf_name = $row['mail'];
                 if (!$ufmatch->find(TRUE)) {
                     $ufmatch->save();
                     $ufmatch->free();
                     $transaction->commit();
                 }
             }
         } else {
             // add to debug array
             $users[] = $user_data;
         }
     }
     // if debugging die now
     if ($debug) {
         trigger_error(print_r(array('method' => 'createUsers', 'messages' => $messages, 'count' => count($messages), 'users' => $users), true), E_USER_ERROR);
         die;
     }
     // re-enable Civi's register hook
     add_action('user_register', array(civi_wp(), 'update_user'));
     // let WordPress plugins know what we've done
     do_action('civicrm_wp_profile_sync_user_add_post');
     // set a message
     CRM_Core_Session::setStatus('', ts('Users Added to WordPress'), 'success');
     // redirect?
     CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
 }
Esempio n. 2
0
 /**
  * Function to retrieve the settings values from db
  *
  * @return array $defaults  
  * @static
  */
 static function retrieve(&$defaults)
 {
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
         $domain->selectAdd('config_backend');
     } else {
         $domain->selectAdd('config_backend, locales');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         // calculate month var
         $defaults['dateformatMonthVar'] = strstr($defaults['dateformatQfDate'], '%m') ? 'm' : (strstr($defaults['dateformatQfDate'], '%b') ? 'M' : (strstr($defaults['dateformatQfDate'], '%B') ? 'F' : null));
         //calculate month var for Date Time
         $defaults['datetimeformatMonthVar'] = strstr($defaults['dateformatQfDatetime'], '%m') ? 'm' : (strstr($defaults['dateformatQfDatetime'], '%b') ? 'M' : (strstr($defaults['dateformatQfDatetime'], '%B') ? 'F' : null));
         //calculate hour var for Date Time
         $defaults['datetimeformatHourVar'] = strstr($defaults['dateformatQfDatetime'], '%I') ? 'h' : (strstr($defaults['dateformatQfDatetime'], '%l') ? 'g' : null);
         // set proper monetary formatting, falling back to en_US and C (CRM-2782)
         setlocale(LC_MONETARY, $defaults['lcMonetary'] . '.utf8', $defaults['lcMonetary'], 'en_US.utf8', 'en_US', 'C');
         $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'qfKey', 'gettextResourceDir', 'cleanURL');
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // since language field won't be present before upgrade.
         if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
             return;
         }
         // 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) {
             require_once 'CRM/Utils/Request.php';
             $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;
             } else {
                 $lcMessagesRequest = null;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = null;
                 }
             }
             if ($lcMessagesRequest) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $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')) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $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);
             }
         }
         // if unset, try to inherit the language from the hosting CMS
         if ($lcMessages === null) {
             require_once 'CRM/Utils/System.php';
             $lcMessages = CRM_Utils_System::getUFLocale();
             require_once 'CRM/Core/BAO/CustomOption.php';
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $domain->locales))) {
                 $lcMessages = null;
             }
         }
         if ($lcMessages) {
             // update config lcMessages - CRM-5027 fixed.
             $defaults['lcMessages'] = $lcMessages;
         } else {
             // if a single-lang site or the above didn't yield a result, use default
             $lcMessages = $defaults['lcMessages'];
         }
         // set suffix for table names - use views if more than one language
         global $dbLocale;
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
     }
 }
Esempio n. 3
0
 public static function onChangeLcMessages($oldLocale, $newLocale, $metadata, $domainID)
 {
     if ($oldLocale == $newLocale) {
         return;
     }
     $session = CRM_Core_Session::singleton();
     if ($newLocale && $session->get('userID')) {
         $ufm = new CRM_Core_DAO_UFMatch();
         $ufm->contact_id = $session->get('userID');
         if ($newLocale && $ufm->find(TRUE)) {
             $ufm->language = $newLocale;
             $ufm->save();
             $session->set('lcMessages', $newLocale);
         }
     }
 }
Esempio n. 4
0
  function run() {
    $chat = "";
    if (isset($_POST['data'])) {
      $json = stripslashes($_POST['data']);
      $chat = json_decode($json, true);
    }
    
    // Get the secret code from the callback
    $checkCode = CRM_Utils_Request::retrieve('olarksecret', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'GET');
    // Get the secret code which is set in the database
    $secretCode = CRM_Core_OptionGroup::values('olark_secret', TRUE);

    if ($chat && ($checkCode == $secretCode['Secret Code'])) { // check if codes match
      // log messages
      foreach ($chat['items'] as $key => $elements) {
        $messages[] = $elements['nickname'].': '.$elements['body'];
      }
  
      // operator
      foreach ($chat['operators'] as $key => $elements) {
        $operators['email'] = $elements['emailAddress'];
      }
      $operators['version'] = 3;
      //operator details
      $operator = civicrm_api( 'Contact', 'get', $operators );
      $operatorName = CRM_Contact_BAO_Contact::displayName($operator['id']);

      // visitor
      $visitor['display_name'] = $chat['visitor']['fullName'];
      $visitor['email'] = $chat['visitor']['emailAddress'];
      $visitor['contact_type'] = 'Individual';
      $visitor['version'] = 3;
      $dedupeParams = CRM_Dedupe_Finder::formatParams($visitor, 'Individual');
      $dedupeParams['check_permission'] = FALSE;
      $dupes = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
      if (count($dupes) == 1) {
        $visitor['contact_id'] = $dupes[0];
      } 
      elseif (count($dupes) > 1) {
        $dao = new CRM_Core_DAO_UFMatch();
        $dao->uf_name = $visitor['email'];
        if ($dao->find(TRUE)) {
          $visitor['contact_id'] = $dao->contact_id;
        }
        else { 
          $visitor['contact_id'] = $dupes[0];
        }
      }
      $contact = civicrm_api( 'Contact', 'create', $visitor );

      // create the activity
      $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
      $activityParams = array(
        'activity_type_id' => array_search('Chat Activity', $activityTypes),
        'subject' => 'Chat between '.$visitor['display_name'].' and '.$operatorName,
        'status_id' => 2,
        'activity_date_time' => date('YmdHis'),
        'source_contact_id' => $operator['id'],
        'target_contact_id' => $contact['id'],
        'assignee_contact_id' => $operator['id'],
        'details' => implode('<br/>', $messages),
        'version' => 3,
      );
      $activity = civicrm_api( 'Activity', 'create', $activityParams);
    }
    parent::run();
  }
Esempio n. 5
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;
         }
     }
 }
Esempio n. 6
0
 /**
  * Get uf match values for given uf id or logged in user.
  *
  * @param int $ufID
  *   Uf id.
  *
  * @return array
  *   uf values.
  */
 public static function getUFValues($ufID = NULL)
 {
     if (!$ufID) {
         //get logged in user uf id.
         $ufID = CRM_Utils_System::getLoggedInUfID();
     }
     if (!$ufID) {
         return array();
     }
     static $ufValues;
     if ($ufID && !isset($ufValues[$ufID])) {
         $ufmatch = new CRM_Core_DAO_UFMatch();
         $ufmatch->uf_id = $ufID;
         $ufmatch->domain_id = CRM_Core_Config::domainID();
         if ($ufmatch->find(TRUE)) {
             $ufValues[$ufID] = array('uf_id' => $ufmatch->uf_id, 'uf_name' => $ufmatch->uf_name, 'contact_id' => $ufmatch->contact_id, 'domain_id' => $ufmatch->domain_id);
         }
     }
     return $ufValues[$ufID];
 }
 /**
  * Function to create CMS user using Profile
  *
  * @param array  $params associated array
  * @param string $mail email id for cms user
  *
  * @return int contact id that has been created
  * @access public
  * @static
  */
 static function create(&$params, $mail)
 {
     $config = CRM_Core_Config::singleton();
     $ufID = $config->userSystem->createUser($params, $mail);
     //if contact doesn't already exist create UF Match
     if ($ufID !== FALSE && isset($params['contactID'])) {
         // create the UF Match record
         $ufmatch = new CRM_Core_DAO_UFMatch();
         $ufmatch->domain_id = CRM_Core_Config::domainID();
         $ufmatch->uf_id = $ufID;
         $ufmatch->contact_id = $params['contactID'];
         $ufmatch->uf_name = $params[$mail];
         if (!$ufmatch->find(TRUE)) {
             $ufmatch->save();
         }
     }
     return $ufID;
 }
Esempio n. 8
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static 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['uf_match'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Esempio n. 9
0
 /**
  * Function to create CMS user using Profile
  *
  * @param array  $params associated array 
  * @param string $mail email id for cms user
  *
  * @return int contact id that has been created
  * @access public
  * @static
  */
 static function create(&$params, $mail)
 {
     $config = CRM_Core_Config::singleton();
     $isDrupal = ucfirst($config->userFramework) == 'Drupal' ? TRUE : FALSE;
     $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE;
     if ($isDrupal) {
         $ufID = self::createDrupalUser($params, $mail);
         if (variable_get('user_register', TRUE) == 1 && !variable_get('user_email_verification', TRUE)) {
             $contact = array('email' => $params[$mail]);
             if (self::userExists($contact)) {
                 return $ufID;
             }
         }
     } elseif ($isJoomla) {
         $ufID = self::createJoomlaUser($params, $mail);
     }
     if ($ufID !== false && isset($params['contactID'])) {
         // create the UF Match record
         $ufmatch = new CRM_Core_DAO_UFMatch();
         $ufmatch->domain_id = CRM_Core_Config::domainID();
         $ufmatch->uf_id = $ufID;
         $ufmatch->contact_id = $params['contactID'];
         $ufmatch->uf_name = $params[$mail];
         $ufmatch->save();
         // Simulate user login by storing details in session.
         // Might break if we ever allow admins to create CMS users.
         // This allows anonymous creator of PCP to see their page after they create it.
         //$session = CRM_Core_Session::singleton();
         //$session->set( 'userID'  , $ufmatch->contact_id );
     }
     return $ufID;
 }
Esempio n. 10
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');
     }
 }
Esempio n. 11
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CORE_DAO_UFMATCH']['_export']) {
         $GLOBALS['_CRM_CORE_DAO_UFMATCH']['_export'] = array();
         $fields =& CRM_Core_DAO_UFMatch::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CORE_DAO_UFMATCH']['_export']['uf_match'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CORE_DAO_UFMATCH']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_DAO_UFMATCH']['_export'];
 }
Esempio n. 12
0
 /**
  * Function to retrieve the settings values from db
  *
  * @return array $defaults  
  * @static
  */
 static function retrieve(&$defaults)
 {
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
         $domain->selectAdd('config_backend');
     } 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;
         }
         $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'newBaseURL', 'newBaseDir', 'newSiteName', 'configAndLogDir', 'qfKey', 'gettextResourceDir', 'cleanURL', 'locale_custom_strings', 'localeCustomStrings');
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // since language field won't be present before upgrade.
         if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
             return;
         }
         // 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();
         // for logging purposes, pass the userID to the db
         if ($session->get('userID')) {
             CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($session->get('userID'), 'Integer')));
         }
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             require_once 'CRM/Utils/Request.php';
             $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;
             } else {
                 $lcMessagesRequest = null;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = null;
                 }
             }
             if ($lcMessagesRequest) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $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')) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $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;
         // if unset and the install is so configured, try to inherit the language from the hosting CMS
         if ($lcMessages === null and CRM_Utils_Array::value('inheritLocale', $defaults)) {
             // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
             $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
             require_once 'CRM/Utils/System.php';
             $lcMessages = CRM_Utils_System::getUFLocale();
             require_once 'CRM/Core/BAO/CustomOption.php';
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $domain->locales))) {
                 $lcMessages = null;
             }
         }
         if ($lcMessages) {
             // update config lcMessages - CRM-5027 fixed.
             $defaults['lcMessages'] = $lcMessages;
         } else {
             // if a single-lang site or the above didn't yield a result, use default
             $lcMessages = $defaults['lcMessages'];
         }
         // 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
         require_once 'CRM/Core/BAO/Preferences.php';
         CRM_Core_BAO_Preferences::retrieveDirectoryAndURLPreferences($defaults);
     }
 }