Exemple #1
0
/**
 *
 **/
function saveDatetime($backend)
{
    $settings = array();
    $old_settings = getSettingsTable();
    $val = CAT_Helper_Validate::getInstance();
    // language must be 2 upercase letters only
    $default_language = strtoupper($val->sanitizePost('default_language'));
    $settings['default_language'] = $backend->lang()->checkLang($default_language) ? $default_language : $old_settings['default_language'];
    // check date format
    $settings['cat_default_date_format'] = CAT_Helper_DateTime::checkDateformat($val->sanitizePost('default_date_format')) ? $val->sanitizePost('default_date_format') : $old_settings['cat_default_date_format'];
    // check time format
    $settings['cat_default_time_format'] = CAT_Helper_DateTime::checkTimeformat($val->sanitizePost('default_time_format')) ? $val->sanitizePost('default_time_format') : $old_settings['cat_default_time_format'];
    // check timezone string
    $settings['default_timezone_string'] = CAT_Helper_DateTime::checkTZ($val->sanitizePost('default_timezone_string')) ? $val->sanitizePost('default_timezone_string') : $old_settings['default_timezone_string'];
    // check charset
    $CHARSETS = $backend->lang()->getCharsets();
    $char_set = $val->sanitizePost('default_charset');
    $settings['default_charset'] = array_key_exists($char_set, $CHARSETS) ? $char_set : $old_settings['default_charset'];
    saveSettings($settings);
}
 $email = $val->validate_email($val->sanitizePost('email'));
 if (!$email) {
     $errors[] = $user->lang()->translate('The email address you entered is invalid');
 } else {
     $sql = 'SELECT COUNT(*) FROM `:prefix:users` WHERE `user_id`<>:id AND `email` LIKE :email';
     if ($database->query($sql, array('id' => (int) $user->get_user_id(), 'email' => $email))->fetchColumn() > 0) {
         $errors[] = $user->lang()->translate('The email you entered is already in use');
     }
 }
 $display_name = strip_tags($val->sanitizePost('display_name', 'string', true));
 $pattern = array('/[^A-Za-z0-9@\\.\\ _-]/');
 $display_name = preg_replace($pattern, "", $display_name);
 if (strlen($display_name) < AUTH_MIN_LOGIN_LENGTH) {
     $errors[] = $user->lang()->translate('The username you entered was too short');
 }
 $date_format = CAT_Helper_DateTime::checkDateformat($val->sanitizePost('date_format', 'string', true)) === true ? $val->sanitizePost('date_format', 'string', true) : NULL;
 $time_format = CAT_Helper_DateTime::checkTimeformat($val->sanitizePost('time_format', 'string', true)) === true ? $val->sanitizePost('time_format', 'string', true) : NULL;
 $fields = array('display_name' => $display_name, 'language' => $language, 'email' => $email, 'timezone_string' => $timezone_string, 'time_format' => $time_format, 'date_format' => $date_format);
 if ($val->sanitizePost('new_password') && ($val->sanitizePost('new_password2') && $val->sanitizePost('new_password') === $val->sanitizePost('new_password2'))) {
     if ($val->sanitizePost('new_password') != "") {
         $fields['password'] = md5($val->sanitizePost('new_password'));
     }
 }
 // save
 if (!count($errors)) {
     $errors = $user->setUserOptions($user->get_user_id(), $fields);
 }
 // update session data
 if (!count($errors)) {
     if (isset($fields['password'])) {
         unset($fields['password']);