// build list of abbreviation => Timezone // we take first timezone and hope it's correct $timezones = array(); foreach (DateTimeZone::listAbbreviations() as $abbrevation => $list) { // take first timezone $timezone = current($list); $timezones[strtoupper($abbrevation)] = $timezone['timezone_id']; } /** @var DbInterface $db */ $res = $db->getAll('select upr_usr_id, upr_timezone from {{%user_preference}}'); foreach ($res as $row) { $usr_id = $row['upr_usr_id']; $tz = $row['upr_timezone']; // skip UTC if (in_array($tz, array('UTC', 'GMT'))) { continue; } if (!$tz) { // if empty tz, set default from system $new_tz = APP_DEFAULT_TIMEZONE; } elseif (isset($timezones[$tz])) { $new_tz = $timezones[$tz]; } else { // no mapping, sorry continue; } $prefs = Prefs::get($usr_id); $prefs['timezone'] = $new_tz; echo "Updating user #{$usr_id} timezone: {$tz} => {$prefs['timezone']}\n"; Prefs::set($usr_id, $prefs); }
/** * Method used to add a new user to the system. * * @param array $user The array of user information * @return integer 1 if the update worked, -1 otherwise */ public static function insert($user) { $projects = array(); foreach ($user['role'] as $prj_id => $role) { if ($role < 1) { continue; } $projects[] = $prj_id; } $params = array(isset($user['customer_id']) ? $user['customer_id'] : null, isset($user['contact_id']) ? $user['contact_id'] : null, Date_Helper::getCurrentDateGMT(), Auth::hashPassword($user['password']), $user['full_name'], $user['email'], !empty($user['grp_id']) ? $user['grp_id'] : null, $user['external_id'], isset($user['par_code']) ? $user['par_code'] : null); $stmt = 'INSERT INTO {{%user}} ( usr_customer_id, usr_customer_contact_id, usr_created_date, usr_password, usr_full_name, usr_email, usr_grp_id, usr_external_id, usr_par_code ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )'; try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } $new_usr_id = DB_Helper::get_last_insert_id(); // add the project associations! $projects = array(); foreach ($user['role'] as $prj_id => $role) { if ($role < 1) { continue; } Project::associateUser($prj_id, $new_usr_id, $role); $projects[] = $prj_id; } Prefs::set($new_usr_id, Prefs::getDefaults($projects)); // send email to user Notification::notifyNewUser($new_usr_id, $user['password']); return $new_usr_id; }
)'); $sql = 'SELECT usr_id, usr_preferences FROM {{%user}} ORDER BY usr_id DESC'; $res = $db->getAll($sql); /** @var Closure $log */ foreach ($res as $row) { $usr_id = $row['usr_id']; $log($usr_id); $old_preferences = unserialize($row['usr_preferences']); if ($old_preferences === false) { $log('... skipped'); continue; } $new_preferences = $old_preferences; $new_preferences['email_refresh_rate'] = $old_preferences['emails_refresh_rate']; unset($old_preferences['emails_refresh_rate']); $new_preferences['auto_append_email_sig'] = !empty($old_preferences['auto_append_sig']) ? $old_preferences['auto_append_sig'] : 0; unset($old_preferences['auto_append_sig']); $new_preferences['receive_assigned_email'] = $old_preferences['receive_assigned_emails']; unset($new_preferences['receive_assigned_emails']); $new_preferences['receive_new_issue_email'] = $old_preferences['receive_new_emails']; unset($new_preferences['receive_new_emails']); // FIXME: is the 1 here hardcoded project id? boo! $new_preferences['receive_copy_of_own_action'][1] = 0; Prefs::set($usr_id, $new_preferences); }
// // @(#) $Id: s.preferences.php 1.9 04/01/07 15:50:18-00:00 jpradomaia $ // include_once "config.inc.php"; include_once APP_INC_PATH . "class.template.php"; include_once APP_INC_PATH . "class.auth.php"; include_once APP_INC_PATH . "class.prefs.php"; include_once APP_INC_PATH . "class.setup.php"; include_once APP_INC_PATH . "class.date.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("preferences.tpl.html"); Auth::checkAuthentication(APP_COOKIE); $usr_id = Auth::getUserID(); if (@$HTTP_POST_VARS["cat"] == "update_account") { $res = Prefs::set($usr_id); $tpl->assign('update_account_result', $res); User::updateSMS($usr_id, @$HTTP_POST_VARS['sms_email']); } elseif (@$HTTP_POST_VARS["cat"] == "update_name") { $res = User::updateFullName($usr_id); $tpl->assign('update_name_result', $res); } elseif (@$HTTP_POST_VARS["cat"] == "update_email") { $res = User::updateEmail($usr_id); $tpl->assign('update_email_result', $res); } elseif (@$HTTP_POST_VARS["cat"] == "update_password") { $res = User::updatePassword($usr_id); $tpl->assign('update_password_result', $res); } $prefs = Prefs::get($usr_id); $prefs['sms_email'] = User::getSMS($usr_id); // if the user has no preferences set yet, get it from the system-wide options
} } $tpl = new Template_Helper(); $tpl->setTemplate('preferences.tpl.html'); Auth::checkAuthentication(APP_COOKIE); if (Auth::isAnonUser()) { Auth::redirect('index.php'); } $res = null; if ($cat == 'update_account') { $preferences = $_POST; // if the user is trying to upload a new signature, override any changes to the textarea if (!empty($_FILES['file_signature']['name'])) { $preferences['email_signature'] = file_get_contents($_FILES['file_signature']['tmp_name']); } $res = Prefs::set($usr_id, $preferences); User::updateSMS($usr_id, @$_POST['sms_email']); } elseif ($cat == 'update_name') { $res = User::updateFullName($usr_id); } elseif ($cat == 'update_email') { $res = User::updateEmail($usr_id); } elseif ($cat == 'update_password') { $res = Auth::updatePassword($usr_id, $_POST['new_password'], $_POST['confirm_password']); } if ($res == 1) { Misc::setMessage(ev_gettext('Your information has been updated')); } elseif ($res == -1) { Misc::setMessage(ev_gettext('Sorry, there was an error updating your information'), Misc::MSG_ERROR); } $prefs = Prefs::get($usr_id); $prefs['sms_email'] = User::getSMS($usr_id);