Exemple #1
0
 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 &raquo; Global Settings &raquo; Date Formats.", array(1 => $defaults['dateInputFormat']));
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
 /**
  * Process the form submission.
  */
 function postProcess()
 {
     $formValues = $this->exportValues();
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_testButtonName) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
         //get the default domain email address.CRM-4250
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             $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; Communications &raquo; FROM Email Addresses</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;
         }
         $testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(1 => $domainEmailAddress, 2 => $toEmail));
         $params = array();
         $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;
         }
         // set the localhost value, CRM-3153, CRM-9332
         $params['localhost'] = $_SERVER['SERVER_NAME'];
         // also set the timeout value, lets set it to 30 seconds
         // CRM-7510, CRM-9332
         $params['timeout'] = 30;
         $mailerName = 'smtp';
         $headers = array('From' => '"' . $domainEmailName . '" <' . $domainEmailAddress . '>', 'To' => '"' . $toDisplayName . '"' . "<{$toEmail}>", 'Subject' => "Test for SMTP settings");
         $mailer = Mail::factory($mailerName, $params);
         $config = CRM_Core_Config::singleton();
         if (property_exists($config, 'civiVersion')) {
             $civiVersion = $config->civiVersion;
         } else {
             $civiVersion = CRM_Core_BAO_Domain::version();
         }
         if (version_compare('4.5alpha1', $civiVersion) > 0) {
             CRM_Core_Error::ignoreException();
         } else {
             $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
         }
         $result = $mailer->send($toEmail, $headers, $message);
         if (version_compare('4.5alpha1', $civiVersion) > 0) {
             CRM_Core_Error::setCallback();
         } else {
             unset($errorScope);
         }
         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))), ts("Mail Sent"), "success");
         } 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, ts("Mail Not Sent"), "error");
         }
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     CRM_Core_BAO_Setting::setItem($formValues, CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
 }
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();
 }
Exemple #4
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // flush caches so we reload details for future requests
     // CRM-11967
     CRM_Utils_System::flushCache();
     $formValues = $this->controller->exportValues($this->_name);
     $buttonName = $this->controller->getButtonName();
     // check if test button
     if ($buttonName == $this->_testButtonName) {
         if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
             CRM_Core_Session::setStatus(ts('You have selected "Disable Outbound Email". A test email can not be sent.'), ts("Email Disabled"), "error");
         } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB) {
             CRM_Core_Session::setStatus(ts('You have selected "Redirect to Database". A test email can not be sent.'), ts("Email Disabled"), "error");
         } else {
             $session = CRM_Core_Session::singleton();
             $userID = $session->get('userID');
             list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
             //get the default domain email address.CRM-4250
             list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
             if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
                 $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; Communications &raquo; FROM Email Addresses</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));
             $params = array();
             if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
                 $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;
                 }
                 // set the localhost value, CRM-3153, CRM-9332
                 $params['localhost'] = $_SERVER['SERVER_NAME'];
                 // also set the timeout value, lets set it to 30 seconds
                 // CRM-7510, CRM-9332
                 $params['timeout'] = 30;
                 $mailerName = 'smtp';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
                 $subject = "Test for Sendmail settings";
                 $message = "Sendmail settings are correct.";
                 $params['sendmail_path'] = $formValues['sendmail_path'];
                 $params['sendmail_args'] = $formValues['sendmail_args'];
                 $mailerName = 'sendmail';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
                 $subject = "Test for PHP mail settings";
                 $message = "mail settings are correct.";
                 $mailerName = 'mail';
             }
             $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
             $mailer = Mail::factory($mailerName, $params);
             $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
             $result = $mailer->send($toEmail, $headers, $message);
             unset($errorScope);
             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))), ts("Mail Sent"), "success");
             } 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, ts("Mail Not Sent"), "error");
             }
         }
     }
     $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     if (!empty($mailingBackend)) {
         CRM_Core_BAO_ConfigSetting::formatParams($formValues, $mailingBackend);
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     CRM_Core_BAO_Setting::setItem($formValues, CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
 }
Exemple #5
0
 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 = setialize($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 = $defaults['dateformatQfDate']) {
             $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 (in_array('%b', $dateFormatArray)) {
                 $defaults['dateInputFormat'] = 'd M, y';
             } else {
                 if (in_array('%B', $dateFormatArray)) {
                     $defaults['dateInputFormat'] = 'd MM, y';
                 } else {
                     $defaults['dateInputFormat'] = 'mm/dd/yy';
                 }
             }
         }
         //Need to fix
         // %p - lowercase ante/post meridiem ('am', 'pm')
         // %P - uppercase ante/post meridiem ('AM', 'PM')
         $defaults['timeInputFormat'] = 1;
         unset($defaults['dateformatQfDate']);
         unset($defaults['dateformatQfDatetime']);
         unset($defaults['dateformatTime']);
         require_once "CRM/Core/BAO/Setting.php";
         CRM_Core_BAO_Setting::add($defaults);
     }
     $template =& CRM_Core_Smarty::singleton();
     $afterUpgradeMessage = '';
     if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
         $afterUpgradeMessage .= "<br/><br/>";
     }
     $afterUpgradeMessage .= ts("Most of the Date Format has been changed to mm/dd/yy format. If you want to use a different format please check Date settings");
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }