Exemple #1
0
 /**
  * Function to add civicrm settings
  *
  * @params array $params associated array of civicrm variables
  *
  * @return null
  * @static
  */
 static function add(&$params)
 {
     CRM_Core_BAO_Setting::fixParams($params);
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(true);
     if ($domain->config_backend) {
         $values = unserialize($domain->config_backend);
         CRM_Core_BAO_Setting::formatParams($params, $values);
     }
     // unset any of the variables we read from file that should not be stored in the database
     // the username and certpath are stored flat with _test and _live
     // check CRM-1470
     $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'qfKey', 'gettextResourceDir', 'cleanURL');
     foreach ($skipVars as $var) {
         unset($params[$var]);
     }
     $domain->config_backend = serialize($params);
     $domain->save();
 }
 /**
  * Function to add civicrm settings
  *
  * @params array $params associated array of civicrm variables
  *
  * @return null
  * @static
  */
 static function add(&$params)
 {
     CRM_Core_BAO_Setting::fixParams($params);
     // also set a template url so js files can use this
     // CRM-6194
     $params['civiRelativeURL'] = CRM_Utils_System::url('CIVI_BASE_TEMPLATE');
     $params['civiRelativeURL'] = str_replace('CIVI_BASE_TEMPLATE', '', $params['civiRelativeURL']);
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(true);
     if ($domain->config_backend) {
         $values = unserialize($domain->config_backend);
         CRM_Core_BAO_Setting::formatParams($params, $values);
     }
     // CRM-6151
     if (isset($params['localeCustomStrings']) && is_array($params['localeCustomStrings'])) {
         $domain->locale_custom_strings = serialize($params['localeCustomStrings']);
     }
     // unset any of the variables we read from file that should not be stored in the database
     // the username and certpath are stored flat with _test and _live
     // check CRM-1470
     $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'newBaseURL', 'newBaseDir', 'newSiteName', 'configAndLogDir', 'qfKey', 'gettextResourceDir', 'cleanURL', 'locale_custom_strings', 'localeCustomStrings');
     foreach ($skipVars as $var) {
         unset($params[$var]);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     CRM_Core_BAO_Preferences::fixAndStoreDirAndURL($params);
     // also skip all Dir Params, we dont need to store those in the DB!
     foreach ($params as $name => $val) {
         if (substr($name, -3) == 'Dir') {
             unset($params[$name]);
         }
     }
     $domain->config_backend = serialize($params);
     $domain->save();
 }
Exemple #3
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $formValues = $this->controller->exportValues($this->_name);
     $buttonName = $this->controller->getButtonName();
     // check if test button
     if ($buttonName == $this->_testButtonName) {
         if ($formValues['outBound_option'] == 2) {
             CRM_Core_Session::setStatus(ts('You have selected "Disable Outbound Email". A test email can not be sent.'));
         } else {
             $session =& CRM_Core_Session::singleton();
             $userID = $session->get('userID');
             require_once 'CRM/Contact/BAO/Contact.php';
             list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
             //get the default domain email address.CRM-4250
             require_once 'CRM/Core/BAO/Domain.php';
             list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
             if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
                 require_once 'CRM/Utils/System.php';
                 $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
                 CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Configure &raquo; Domain Information</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
             }
             if (!$toEmail) {
                 CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.'));
             }
             if (!trim($toDisplayName)) {
                 $toDisplayName = $toEmail;
             }
             $to = '"' . $toDisplayName . '"' . "<{$toEmail}>";
             $from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
             $testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(1 => $domainEmailAddress, 2 => $toEmail));
             if ($formValues['outBound_option'] == 0) {
                 $subject = "Test for SMTP settings";
                 $message = "SMTP settings are correct.";
                 $params['host'] = $formValues['smtpServer'];
                 $params['port'] = $formValues['smtpPort'];
                 if ($formValues['smtpAuth']) {
                     $params['username'] = $formValues['smtpUsername'];
                     $params['password'] = $formValues['smtpPassword'];
                     $params['auth'] = true;
                 } else {
                     $params['auth'] = false;
                 }
                 $mailerName = 'smtp';
             } elseif ($formValues['outBound_option'] == 1) {
                 $subject = "Test for Sendmail settings";
                 $message = "Sendmail settings are correct.";
                 $params['sendmail_path'] = $formValues['sendmail_path'];
                 $params['sendmail_args'] = $formValues['sendmail_args'];
                 $mailerName = 'sendmail';
             }
             $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
             $mailer =& Mail::factory($mailerName, $params);
             CRM_Core_Error::ignoreException();
             $result = $mailer->send($toEmail, $headers, $message);
             if (!is_a($result, 'PEAR_Error')) {
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))));
             } else {
                 $message = CRM_Utils_Mail::errorMessage($mailer, $result);
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message);
             }
         }
     }
     $mailingDomain =& new CRM_Core_DAO_Preferences();
     $mailingDomain->domain_id = CRM_Core_Config::domainID();
     $mailingDomain->is_domain = true;
     $mailingDomain->find(true);
     if ($mailingDomain->mailing_backend) {
         $values = unserialize($mailingDomain->mailing_backend);
         CRM_Core_BAO_Setting::formatParams($formValues, $values);
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         require_once 'CRM/Utils/Crypt.php';
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     $mailingDomain->mailing_backend = serialize($formValues);
     $mailingDomain->save();
 }