[aur-dev] [PATCH] Add user set timestamps
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Implements: FS#48729 Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 4 ++- web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 16 ++++++--- web/lib/aur.inc.php | 4 +++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 69 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 ++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 18 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..95a4373 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..a9c0220 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..72092a7 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, "UTC"); } echo '</div>'; diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..4180933 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= gmdate("Y-m-d H:i", tz_timestamp(intval($row["VoteTS"]))) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..46dbce7 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -278,13 +279,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +349,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); @@ -359,6 +362,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints); + error_log($result ? "t" : "f"); + error_log($ssh_key_result ? "t" : "f"); + error_log($q); if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..38dcdd0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,6 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; + global $TZ; include('header.php'); return; diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..e7512c1 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = gmdate("Y-m-d", tz_timestamp(intval($details["OutOfDateTS"]))); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..e69e35c --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,69 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() { + global $TZ; + + $timezones = generate_timezone_list(); + + if (isset($_COOKIE['AURSID'])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q.= "WHERE Users.ID = Sessions.UsersID "; + $q.= "AND Sessions.SessionID = "; + $q.= $dbh->quote($_COOKIE['AURSID']); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + if (!array_key_exists($TZ, $timezones)) { + error_log("Am I Here?"); + $TZ = config_get("options", "default_timezone"); + } + } +} + +/** + * Add the selected timezone's offset to a timestamp. + * + * @param $timestamp int Timestamp to be manipulated + * + * @return int Manipulated timestamp + */ +function tz_timestamp($timestamp) { + global $TZ; + $offset = isset($TZ) ? timezone_offset_get(new DateTimeZone($TZ), new DateTime()) : 0; + return $timestamp + $offset; +} \ No newline at end of file diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..17c9d14 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,21 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..a0e91b8 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', gmdate('Y-m-d', tz_timestamp($message['OutOfDateTS'])), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..dcd6901 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['CommentTS'])); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['DelTS'])); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['EditedTS'])); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..8cca437 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["SubmittedTS"]))); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", tz_timestamp(intval($row["OutOfDateTS"]))); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..819ad68 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["SubmittedTS"]))); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", tz_timestamp(intval($row["OutOfDateTS"]))); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..38f9f23 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", tz_timestamp(intval($row['RequestTS']))) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..2addf0a 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..b0f77cd 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", tz_timestamp($row['Submitted'])), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= gmdate("Y-m-d H:i", tz_timestamp($row['End'])) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..707169b 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= gmdate("Y-m-d", tz_timestamp($row["Submitted"])) ?></td> + <td><?= gmdate("Y-m-d", tz_timestamp($row["End"])) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.10.2
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Implements: FS#48729 Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 4 ++- web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 16 ++++++--- web/lib/aur.inc.php | 4 +++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 69 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 ++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 130 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..b6a414d 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +deafult_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..95a4373 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..a9c0220 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..72092a7 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, "UTC"); } echo '</div>'; diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..4180933 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= gmdate("Y-m-d H:i", tz_timestamp(intval($row["VoteTS"]))) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..46dbce7 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -278,13 +279,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +349,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); @@ -359,6 +362,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints); + error_log($result ? "t" : "f"); + error_log($ssh_key_result ? "t" : "f"); + error_log($q); if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..38dcdd0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,6 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; + global $TZ; include('header.php'); return; diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..e7512c1 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = gmdate("Y-m-d", tz_timestamp(intval($details["OutOfDateTS"]))); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..e69e35c --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,69 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() { + global $TZ; + + $timezones = generate_timezone_list(); + + if (isset($_COOKIE['AURSID'])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q.= "WHERE Users.ID = Sessions.UsersID "; + $q.= "AND Sessions.SessionID = "; + $q.= $dbh->quote($_COOKIE['AURSID']); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + if (!array_key_exists($TZ, $timezones)) { + error_log("Am I Here?"); + $TZ = config_get("options", "default_timezone"); + } + } +} + +/** + * Add the selected timezone's offset to a timestamp. + * + * @param $timestamp int Timestamp to be manipulated + * + * @return int Manipulated timestamp + */ +function tz_timestamp($timestamp) { + global $TZ; + $offset = isset($TZ) ? timezone_offset_get(new DateTimeZone($TZ), new DateTime()) : 0; + return $timestamp + $offset; +} \ No newline at end of file diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..17c9d14 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,21 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..a0e91b8 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', gmdate('Y-m-d', tz_timestamp($message['OutOfDateTS'])), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..dcd6901 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['CommentTS'])); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['DelTS'])); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = gmdate('Y-m-d H:i', tz_timestamp($row['EditedTS'])); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..8cca437 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["SubmittedTS"]))); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", tz_timestamp(intval($row["OutOfDateTS"]))); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..819ad68 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", tz_timestamp(intval($row["SubmittedTS"]))); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", tz_timestamp(intval($row["OutOfDateTS"]))); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..38f9f23 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", tz_timestamp(intval($row['RequestTS']))) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..2addf0a 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= gmdate("Y-m-d H:i", tz_timestamp(intval($row["ModifiedTS"]))); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..b0f77cd 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", tz_timestamp($row['Submitted'])), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= gmdate("Y-m-d H:i", tz_timestamp($row['End'])) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..707169b 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= gmdate("Y-m-d", tz_timestamp($row["Submitted"])) ?></td> + <td><?= gmdate("Y-m-d", tz_timestamp($row["End"])) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.10.2
On Tue, 15 Nov 2016 at 06:19:26, Mark Weiman wrote:
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone.
Implements: FS#48729
Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 4 ++- web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 16 ++++++--- web/lib/aur.inc.php | 4 +++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 69 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 ++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 130 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php
First of all, thanks for taking the time to implement all this! I added some inline comments below.
diff --git a/conf/config.proto b/conf/config.proto index 96fad80..b6a414d 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +deafult_timezone = UTC
Typo?
sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..95a4373 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC',
Out of curiosity: How did you choose the length of 50 characters? Is it large enough according to some standard?
Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..a9c0220 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users
This is really nitpicky but we usually add colons after these lines.
+ +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"),
Okay. Looks a bit weird but I agree that doing this is better than reformatting the whole list in every patch that adds or removes a parameter. Maybe we should change the formatting to "one parameter per line" here. Not in the scope of this patch, though.
[...] @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, "UTC");
Should this refer to the default timezone from the configuration file instead?
[...] @@ -359,6 +362,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C=""
$ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints);
+ error_log($result ? "t" : "f"); + error_log($ssh_key_result ? "t" : "f"); + error_log($q);
Huh? Leftover debug statements? I think these should go...
[...] +function set_tz() { [...] + if (!array_key_exists($TZ, $timezones)) { + error_log("Am I Here?");
And another one...
[...] + * Add the selected timezone's offset to a timestamp. + * + * @param $timestamp int Timestamp to be manipulated + * + * @return int Manipulated timestamp + */ +function tz_timestamp($timestamp) { + global $TZ; + $offset = isset($TZ) ? timezone_offset_get(new DateTimeZone($TZ), new DateTime()) : 0; + return $timestamp + $offset; +} [...]
I do not know about timezone handling in PHP, so this question might be naive: Is there any reason you chose this implementation instead of calling something like date_default_timezone_set() in set_tz() and using the default date/time functions without any wrappers? Regards, Lukas P.S.: Not a big issue but if you resubmit a patch several times, it is usually a good idea to add a comment on what changed between the "---" marker and the diff stat. Just to make it easier for reviewers to pick a version to review and to know about previously addressed stuff.
On 15/11, Lukas Fleischer wrote:
On Tue, 15 Nov 2016 at 06:19:26, Mark Weiman wrote:
+ Timezone VARCHAR(50) NOT NULL DEFAULT 'UTC',
Out of curiosity: How did you choose the length of 50 characters? Is it large enough according to some standard?
The zoneinfo has a limit of 14 characters[0], though there are some legacy names that are still supported, the longest of which seems to be 33 characters. [0]: https://github.com/eggert/tz/blob/365460cfe7f7404030f33dffe489ba66a2dcbcdd/T... -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
On Tue, 2016-11-15 at 07:42 +0100, Lukas Fleischer wrote:
First of all, thanks for taking the time to implement all this! I added some inline comments below.
+deafult_timezone = UTC
Typo?
Yes.
Out of curiosity: How did you choose the length of 50 characters? Is it large enough according to some standard?
Yeah, I chose something that was most likely long enough to hold anything that I needed to put in there. It looks like Johannes found it to be a maximum of 33 characters, and after looking, the current maximum length is 30, so should I use 33 or 30?
This is really nitpicky but we usually add colons after these lines.
Okay, I will fix this.
Okay. Looks a bit weird but I agree that doing this is better than reformatting the whole list in every patch that adds or removes a parameter. Maybe we should change the formatting to "one parameter per line" here. Not in the scope of this patch, though.
Yeah, I really wasn't sure how to do this properly.
Should this refer to the default timezone from the configuration file instead?
Probably a good idea.
Huh? Leftover debug statements? I think these should go...
Yikes! I would have to agree.
I do not know about timezone handling in PHP, so this question might be naive: Is there any reason you chose this implementation instead of calling something like date_default_timezone_set() in set_tz() and using the default date/time functions without any wrappers?
When reading the timestamp in gmdate(), PHP doesn't care what timezone the default is set to and it just displays what the time is based on the how many seconds past the Unix epoch. Because of this, you have to get the timezone's offset (which is in UTC from the database) and do the math to make sure it's correct. I have verified this in a PHP shell. Changing the default doesn't make sense to me also because the application is only displaying other timezones, not working in them, only UTC.
Regards, Lukas
P.S.: Not a big issue but if you resubmit a patch several times, it is usually a good idea to add a comment on what changed between the "---" marker and the diff stat. Just to make it easier for reviewers to pick a version to review and to know about previously addressed stuff.
Mark Weiman
On Wed, 16 Nov 2016 at 04:04:08, Mark Weiman wrote:
Yeah, I chose something that was most likely long enough to hold anything that I needed to put in there. It looks like Johannes found it to be a maximum of 33 characters, and after looking, the current maximum length is 30, so should I use 33 or 30?
It seems like 32 is a good value: $ backward=https://raw.githubusercontent.com/eggert/tz/master/backward $ curl -s "$backward" | sed '/^#/d' | cut -f3 | wc -L 32 Johannes, where did you find a legacy name of length 33?
When reading the timestamp in gmdate(), PHP doesn't care what timezone the default is set to and it just displays what the time is based on the how many seconds past the Unix epoch. Because of this, you have to get the timezone's offset (which is in UTC from the database) and do the math to make sure it's correct. I have verified this in a PHP shell. Changing the default doesn't make sense to me also because the application is only displaying other timezones, not working in them, only UTC.
We would have to use date() instead of gmdate() in combination with date_default_timezone_set(), of course. Regards, Lukas
On 16/11, Lukas Fleischer wrote:
On Wed, 16 Nov 2016 at 04:04:08, Mark Weiman wrote:
Yeah, I chose something that was most likely long enough to hold anything that I needed to put in there. It looks like Johannes found it to be a maximum of 33 characters, and after looking, the current maximum length is 30, so should I use 33 or 30?
It seems like 32 is a good value:
$ backward=https://raw.githubusercontent.com/eggert/tz/master/backward $ curl -s "$backward" | sed '/^#/d' | cut -f3 | wc -L 32
Johannes, where did you find a legacy name of length 33?
Was looking at the actual zoneinfo files on Arch, though it seems that the longer ones are under the right/ and posix/ namespaces under /usr/share/zoneinfo. Though I don't think those are actually useful to support though. right/ seems[0] to be for systems that don't implement leap second support, where the system time includes the leap seconds (based on TAI), and posix/ follows the POSIX standard and are based on UTC, so I think we can just ignore those zones. [0]: http://www.ucolick.org/~sla/leapsecs/right+gps.html -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
On 17/11, Johannes Löthberg via aur-dev wrote:
On 16/11, Lukas Fleischer wrote:
On Wed, 16 Nov 2016 at 04:04:08, Mark Weiman wrote:
Yeah, I chose something that was most likely long enough to hold anything that I needed to put in there. It looks like Johannes found it to be a maximum of 33 characters, and after looking, the current maximum length is 30, so should I use 33 or 30?
It seems like 32 is a good value:
$ backward=https://raw.githubusercontent.com/eggert/tz/master/backward $ curl -s "$backward" | sed '/^#/d' | cut -f3 | wc -L 32
Johannes, where did you find a legacy name of length 33?
Was looking at the actual zoneinfo files on Arch, though it seems that the longer ones are under the right/ and posix/ namespaces under /usr/share/zoneinfo. Though I don't think those are actually useful to support though.
right/ seems[0] to be for systems that don't implement leap second support, where the system time includes the leap seconds (based on TAI), and posix/ follows the POSIX standard and are based on UTC, so I think we can just ignore those zones.
Though it seems that right/ and posix/ are no longer subdirectories in the current upstream zoneinfo database structure, instead being separate directories in /usr/share/zoneinfe. (Called zoneinfo, zoneinfo-posix, and zoneinfo-leapse.) Though some distros, like Arch, still uses the old structure. Essentially what you're supposed to do is to configure a system to use either the "posix" or the "right" database (now zoneinfo-leaps) by copying their files to /usr/share/zoneinfo, so you shouldn't actually use the full posix/ or real/ files. (hwclock(8)) -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Implements: FS#48729 Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Fixed any typos mentioned. Removed rogue error_log() calls. Removed tz_timestamp and replaced it with regular date() calls. Changed Timezone field length from 50 to 32 (I think it should be 30). Changed new account form to use default TZ from config. conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 4 ++- web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 13 +++++--- web/lib/aur.inc.php | 4 +++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 62 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 +++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 120 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..8ab7093 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +default_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..13e3fd9 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..6c4ce80 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users: + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..e18d976 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, config_get("options", "default_timezone")); } echo '</div>'; diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..997186d 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= date("Y-m-d H:i", intval($row["VoteTS"])) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..7dc8eba 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -278,13 +279,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +349,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..38dcdd0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,6 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; + global $TZ; include('header.php'); return; diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..6a443a3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = date("Y-m-d", intval($details["OutOfDateTS"])); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..a63b510 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,62 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() +{ + global $TZ; + + $timezones = generate_timezone_list(); + + if (isset($_COOKIE['AURSID'])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE['AURSID']); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + if (!array_key_exists($TZ, $timezones)) { + $TZ = config_get("options", "default_timezone"); + } + } + + if (isset($TZ) && $TZ != "") { + date_default_timezone_set($TZ); + } else { + date_default_timezone_set("UTC"); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..17c9d14 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,21 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..e8855fe 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', date('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..fee1898 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = date('Y-m-d H:i', $row['CommentTS']); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = date('Y-m-d H:i', $row['DelTS']); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = date('Y-m-d H:i', $row['EditedTS']); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..3269394 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..fe76959 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..426c7f0 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= date("Y-m-d H:i", intval($row['RequestTS'])) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..b4c6215 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= date("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..d739060 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", date("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= date("Y-m-d H:i", $row['End']) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..b7253f9 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= date("Y-m-d", $row["Submitted"]) ?></td> + <td><?= date("Y-m-d", $row["End"]) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.11.0
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Implements: FS#48729 Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Changed default timezone in set_tz() to use config file. Moved open curly brace on set_tz() to match styling with project. conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 4 ++- web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 13 +++++--- web/lib/aur.inc.php | 4 +++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 61 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 +++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..8ab7093 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +default_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..13e3fd9 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..6c4ce80 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users: + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..e18d976 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, config_get("options", "default_timezone")); } echo '</div>'; diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..997186d 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= date("Y-m-d H:i", intval($row["VoteTS"])) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..7dc8eba 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -278,13 +279,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +349,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..38dcdd0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,6 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; + global $TZ; include('header.php'); return; diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..6a443a3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = date("Y-m-d", intval($details["OutOfDateTS"])); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..363d6a6 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,61 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() { + global $TZ; + + $timezones = generate_timezone_list(); + + if (isset($_COOKIE['AURSID'])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE['AURSID']); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + if (!array_key_exists($TZ, $timezones)) { + $TZ = config_get("options", "default_timezone"); + } + } + + if (isset($TZ) && $TZ != "") { + date_default_timezone_set($TZ); + } else { + date_default_timezone_set(config_get("options", "default_timezone")); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..17c9d14 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,21 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..e8855fe 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', date('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..fee1898 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = date('Y-m-d H:i', $row['CommentTS']); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = date('Y-m-d H:i', $row['DelTS']); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = date('Y-m-d H:i', $row['EditedTS']); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..3269394 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..fe76959 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..426c7f0 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= date("Y-m-d H:i", intval($row['RequestTS'])) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..b4c6215 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= date("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..d739060 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", date("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= date("Y-m-d H:i", $row['End']) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..b7253f9 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= date("Y-m-d", $row["Submitted"]) ?></td> + <td><?= date("Y-m-d", $row["End"]) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.11.0
On Thu, 29 Dec 2016 at 04:10:00, Mark Weiman wrote:
[...] @@ -64,7 +66,7 @@ if (in_request("Action") == "NewAccount") { } } else { print '<p>' . __("Use this form to create an account.") . '</p>'; - display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG); + display_account_form("NewAccount", "", "", "", "", "", "", "", "", $LANG, config_get("options", "default_timezone"));
I know I explicitly asked you to add this when reviewing a previous version of this patch. Looking at it again, it seems better to leave this line untouched and handle the default case in the function itself, though.
[...] diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..363d6a6 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,61 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() { + global $TZ; + + $timezones = generate_timezone_list(); + + if (isset($_COOKIE['AURSID'])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE['AURSID']); + $result = $dbh->query($q);
I wonder whether it is better to store the timezone in a cookie. The set_tz() function could query the database the first time a user logs in only, set the cookie and become a no-op for any subsequent calls. By doing that, we could also get rid of the global variable and the patch could be extended easily such that unregistered users can specify a timezone.
+ + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + if (!array_key_exists($TZ, $timezones)) { + $TZ = config_get("options", "default_timezone"); + } + } + + if (isset($TZ) && $TZ != "") { + date_default_timezone_set($TZ); + } else { + date_default_timezone_set(config_get("options", "default_timezone")); + } +}
This part can be simplified as follows (untested and assuming that we replace the global variable by a local variable as suggested above): unset($timezone); if ($result) { $timezone = $result->fetchColumn(0); } if (!isset($timezone) || !array_key_exists($timezone, $timezones)) { $timezone = config_get("options", "default_timezone"); } date_default_timezone_set($timezone); The rest looks fine to me, thanks!
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Added cookie for timezones and related code to modify it Changed call to display_account_form() conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 2 + web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 23 +++++++++--- web/lib/aur.inc.php | 4 ++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 73 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 18 +++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 +-- web/template/pkg_details.php | 6 +-- web/template/pkgbase_details.php | 6 +-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +- web/template/tu_list.php | 4 +- 19 files changed, 143 insertions(+), 23 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..8ab7093 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +default_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..13e3fd9 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..6c4ce80 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users: + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..843fea9 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..997186d 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= date("Y-m-d H:i", intval($row["VoteTS"])) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..684a861 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -200,6 +201,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" if (!$error && !array_key_exists($L, $SUPPORTED_LANGS)) { $error = __("Language is not currently supported."); } + if (!$error && !array_key_exists($TZ, generate_timezone_list())) { + $error = __("Timezone is not currently supported."); + } if (!$error) { /* * Check whether the user name is available. @@ -278,13 +282,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +352,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); @@ -359,6 +365,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints); + if (isset($_COOKIE["AURTZ"]) && ($_COOKIE["AURTZ"] != $TZ)) { + /* set new cookie for timezone */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..38dcdd0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,6 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; + global $TZ; include('header.php'); return; diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..6a443a3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = date("Y-m-d", intval($details["OutOfDateTS"])); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..3f4fd54 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,73 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @global string $TZ Timezone set for session. + * + * @return null + */ +function set_tz() { + global $TZ; + + $timezones = generate_timezone_list(); + $update_cookie = false; + + if (isset($_COOKIE["AURTZ"])) { + $TZ = $_COOKIE["AURTZ"]; + } elseif (isset($_COOKIE["AURSID"])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE["AURSID"]); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + $update_cookie = true; + } + + if (!array_key_exists($TZ, $timezones)) { + $TZ = config_get("options", "default_timezone"); + } + + if (isset($TZ) && $TZ != "") { + date_default_timezone_set($TZ); + } else { + $TZ = config_get("options", "default_timezone"); + date_default_timezone_set($TZ); + } + + if ($update_cookie) { + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..8b207e7 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,24 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == "") { + $TZ = config_get("options", "default_timezone"); + } + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..e8855fe 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', date('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..fee1898 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = date('Y-m-d H:i', $row['CommentTS']); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = date('Y-m-d H:i', $row['DelTS']); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = date('Y-m-d H:i', $row['EditedTS']); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..3269394 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..fe76959 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..426c7f0 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= date("Y-m-d H:i", intval($row['RequestTS'])) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..b4c6215 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= date("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..d739060 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", date("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= date("Y-m-d H:i", $row['End']) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..b7253f9 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= date("Y-m-d", $row["Submitted"]) ?></td> + <td><?= date("Y-m-d", $row["End"]) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.11.0
Currently, when a user edits their language setting from the edit user form, the changes aren't reflected until the user either lets the original cookie expire, deletes the cookie manually, or changes the language a second time via the dropdown menu on the top of the page. This patch makes the language cookie get updated when it is changed from the edit user form. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/lib/acctfuncs.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 684a861..104cdd4 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -372,6 +372,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" setcookie("AURTZ", $TZ, $cookie_time, "/"); } + if (isset($_COOKIE["AURLANG"]) && ($_COOKIE["AURLANG"] != $L)) { + /* set new cookie for language */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURLANG", $L, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); -- 2.11.0
Modify the call to process_account_form() to only having one parameter per line. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/html/account.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/web/html/account.php b/web/html/account.php index 91e5703..0b75761 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -31,13 +31,25 @@ if ($action == "UpdateAccount") { /* Update the details for the existing account */ list($success, $update_account_message) = process_account_form( "edit", "UpdateAccount", - in_request("U"), in_request("T"), in_request("S"), - in_request("E"), in_request("H"), in_request("P"), - in_request("C"), in_request("R"), in_request("L"), + in_request("U"), + in_request("T"), + in_request("S"), + in_request("E"), + in_request("H"), + in_request("P"), + in_request("C"), + in_request("R"), + in_request("L"), in_request("TZ"), - in_request("HP"), in_request("I"), in_request("K"), - in_request("PK"), in_request("J"), in_request("CN"), - in_request("UN"), in_request("ON"), in_request("ID"), + in_request("HP"), + in_request("I"), + in_request("K"), + in_request("PK"), + in_request("J"), + in_request("CN"), + in_request("UN"), + in_request("ON"), + in_request("ID"), $row["Username"]); } } -- 2.11.0
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Removed $TZ global conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 2 ++ web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 23 ++++++++++--- web/lib/aur.inc.php | 5 ++- web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 65 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 18 ++++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 135 insertions(+), 24 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..8ab7093 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +default_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..13e3fd9 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..6c4ce80 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users: + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..843fea9 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..997186d 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= date("Y-m-d H:i", intval($row["VoteTS"])) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..684a861 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,7 +66,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; include("account_edit_form.php"); @@ -88,6 +88,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +103,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -200,6 +201,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" if (!$error && !array_key_exists($L, $SUPPORTED_LANGS)) { $error = __("Language is not currently supported."); } + if (!$error && !array_key_exists($TZ, generate_timezone_list())) { + $error = __("Timezone is not currently supported."); + } if (!$error) { /* * Check whether the user name is available. @@ -278,13 +282,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +352,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); @@ -359,6 +365,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints); + if (isset($_COOKIE["AURTZ"]) && ($_COOKIE["AURTZ"] != $TZ)) { + /* set new cookie for timezone */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..8a0ed2b 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * @@ -356,7 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; - + include('header.php'); return; } diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..6a443a3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = date("Y-m-d", intval($details["OutOfDateTS"])); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..f3b4c71 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,65 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the $TZ global variable. + * + * @return null + */ +function set_tz() { + $timezones = generate_timezone_list(); + $update_cookie = false; + + if (isset($_COOKIE["AURTZ"])) { + $TZ = $_COOKIE["AURTZ"]; + } elseif (isset($_COOKIE["AURSID"])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE["AURSID"]); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0]; + } else { + $TZ = config_get("options", "default_timezone"); + } + + $update_cookie = true; + } + + if (isset($TZ) && array_key_exists($TZ, $timezones)) { + date_default_timezone_set($TZ); + } else { + $TZ = config_get("options", "default_timezone"); + date_default_timezone_set($TZ); + } + + if ($update_cookie) { + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..8b207e7 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,24 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == "") { + $TZ = config_get("options", "default_timezone"); + } + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..e8855fe 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', date('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..fee1898 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = date('Y-m-d H:i', $row['CommentTS']); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = date('Y-m-d H:i', $row['DelTS']); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = date('Y-m-d H:i', $row['EditedTS']); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..3269394 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..fe76959 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..426c7f0 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= date("Y-m-d H:i", intval($row['RequestTS'])) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..b4c6215 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= date("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..d739060 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", date("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= date("Y-m-d H:i", $row['End']) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..b7253f9 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= date("Y-m-d", $row["Submitted"]) ?></td> + <td><?= date("Y-m-d", $row["End"]) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.11.0
Currently, when a user edits their language setting from the edit user form, the changes aren't reflected until the user either lets the original cookie expire, deletes the cookie manually, or changes the language a second time via the dropdown menu on the top of the page. This patch makes the language cookie get updated when it is changed from the edit user form. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/lib/acctfuncs.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 684a861..104cdd4 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -372,6 +372,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" setcookie("AURTZ", $TZ, $cookie_time, "/"); } + if (isset($_COOKIE["AURLANG"]) && ($_COOKIE["AURLANG"] != $L)) { + /* set new cookie for language */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURLANG", $L, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); -- 2.11.0
Modify the call to process_account_form() to only having one parameter per line. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/html/account.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/web/html/account.php b/web/html/account.php index 91e5703..0b75761 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -31,13 +31,25 @@ if ($action == "UpdateAccount") { /* Update the details for the existing account */ list($success, $update_account_message) = process_account_form( "edit", "UpdateAccount", - in_request("U"), in_request("T"), in_request("S"), - in_request("E"), in_request("H"), in_request("P"), - in_request("C"), in_request("R"), in_request("L"), + in_request("U"), + in_request("T"), + in_request("S"), + in_request("E"), + in_request("H"), + in_request("P"), + in_request("C"), + in_request("R"), + in_request("L"), in_request("TZ"), - in_request("HP"), in_request("I"), in_request("K"), - in_request("PK"), in_request("J"), in_request("CN"), - in_request("UN"), in_request("ON"), in_request("ID"), + in_request("HP"), + in_request("I"), + in_request("K"), + in_request("PK"), + in_request("J"), + in_request("CN"), + in_request("UN"), + in_request("ON"), + in_request("ID"), $row["Username"]); } } -- 2.11.0
On Thu, 19 Jan 2017 at 04:23:37, Mark Weiman wrote:
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone.
Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- [...]
Thanks, we're almost there. There are several minor issues left, though. See below.
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..8a0ed2b 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php [...] @@ -356,7 +359,7 @@ function uid_from_sid($sid="") { function html_header($title="", $details=array()) { global $LANG; global $SUPPORTED_LANGS; - +
Unrelated whitespace change?
include('header.php'); return; } [...] diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..f3b4c71 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,65 @@ [...] +/** + * Set the $TZ global variable.
The comment needs to be updated to reflect the changes in this reroll of the patch series.
+ * + * @return null + */ +function set_tz() { + $timezones = generate_timezone_list(); + $update_cookie = false; + + if (isset($_COOKIE["AURTZ"])) { + $TZ = $_COOKIE["AURTZ"];
It is quite confusing to use an upper case variable name here enough though this no longer is a global variable. Something like $timezone might be more appropriate.
+ } elseif (isset($_COOKIE["AURSID"])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE["AURSID"]); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetchAll(); + $TZ = $row[0][0];
As I mentioned in an earlier review, this can be simplified as $timezone = $result->fetchColumn(0); already assuming that $TZ becomes $timezone.
+ } else { + $TZ = config_get("options", "default_timezone");
This else-branch is not needed. The default case is already handled below.
+ } + + $update_cookie = true; + } + + if (isset($TZ) && array_key_exists($TZ, $timezones)) { + date_default_timezone_set($TZ); + } else { + $TZ = config_get("options", "default_timezone"); + date_default_timezone_set($TZ); + }
As I also mentioned in an earlier review, this can be simplified as follows (also assuming that $TZ is replaced by $timezone): if (!isset($timezone) || !array_key_exists($timezone, $timezones)) { $timezone = config_get("options", "default_timezone"); } date_default_timezone_set($timezone);
+ + if ($update_cookie) { + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..8b207e7 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,24 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == "") { + $TZ = config_get("options", "default_timezone"); + }
Broken indentation. I also think this if-block belongs to display_account_form() and should be executed before account_edit_form.php is included.
+ if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset>
<fieldset> [...]
Looks good otherwise!
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Removed renegade random tab in aur.inc.php Changed comment for set_tz() to not mention global $TZ that was removed Renamed $TZ in set_tz() to $timezone Change fetchAll() to fetchColumn() in set_tz() Removed extraneous else branch in set_tz() Simplified timezone check in set_tz() Moved if block from account_edit_form.php to display_account_form() before inclusion conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 2 ++ web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 27 +++++++++++++--- web/lib/aur.inc.php | 3 ++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 60 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 +++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php diff --git a/conf/config.proto b/conf/config.proto index 96fad80..8ab7093 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -11,6 +11,7 @@ username_min_len = 3 username_max_len = 16 passwd_min_len = 4 default_lang = en +default_timezone = UTC sql_debug = 0 max_sessions_per_user = 8 login_timeout = 7200 diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 30209bd..13e3fd9 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -32,6 +32,7 @@ CREATE TABLE Users ( ResetKey CHAR(32) NOT NULL DEFAULT '', RealName VARCHAR(64) NOT NULL DEFAULT '', LangPreference VARCHAR(6) NOT NULL DEFAULT 'en', + Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC', Homepage TEXT NULL DEFAULT NULL, IRCNick VARCHAR(32) NOT NULL DEFAULT '', PGPKey VARCHAR(40) NULL DEFAULT NULL, diff --git a/upgrading/4.5.0.txt b/upgrading/4.5.0.txt new file mode 100644 index 0000000..6c4ce80 --- /dev/null +++ b/upgrading/4.5.0.txt @@ -0,0 +1,5 @@ +1. Add Timezone column to Users: + +--- +ALTER TABLE Users ADD COLUMN Timezone VARCHAR(32) NOT NULL DEFAULT 'UTC'; +--- \ No newline at end of file diff --git a/web/html/account.php b/web/html/account.php index 2892f04..91e5703 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -34,6 +34,7 @@ if ($action == "UpdateAccount") { in_request("U"), in_request("T"), in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), in_request("PK"), in_request("J"), in_request("CN"), in_request("UN"), in_request("ON"), in_request("ID"), @@ -89,6 +90,7 @@ if (isset($_COOKIE["AURSID"])) { "", $row["RealName"], $row["LangPreference"], + $row["Timezone"], $row["Homepage"], $row["IRCNick"], $row["PGPKey"], @@ -141,6 +143,7 @@ if (isset($_COOKIE["AURSID"])) { in_request("C"), in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/register.php b/web/html/register.php index 6c6d52e..843fea9 100644 --- a/web/html/register.php +++ b/web/html/register.php @@ -31,6 +31,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), @@ -53,6 +54,7 @@ if (in_request("Action") == "NewAccount") { '', in_request("R"), in_request("L"), + in_request("TZ"), in_request("HP"), in_request("I"), in_request("K"), diff --git a/web/html/voters.php b/web/html/voters.php index 8833be1..997186d 100644 --- a/web/html/voters.php +++ b/web/html/voters.php @@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)): <li> <a href="<?= get_user_uri($row['Username']); ?>"><?= htmlspecialchars($row['Username']) ?></a> <?php if ($row["VoteTS"] > 0): ?> - (<?= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>) + (<?= date("Y-m-d H:i", intval($row["VoteTS"])) ?>) <?php endif; ?> </li> <?php endwhile; ?> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 172b962..0067007 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -1,5 +1,4 @@ <?php - /** * Determine if an HTTP request variable is set * @@ -52,6 +51,7 @@ function html_format_pgp_fingerprint($fingerprint) { * @param string $C The confirmed password value of the displayed user * @param string $R The real name of the displayed user * @param string $L The language preference of the displayed user + * @param string $TZ The timezone preference of the displayed user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the displayed user * @param string $K The PGP key fingerprint of the displayed user @@ -66,9 +66,13 @@ function html_format_pgp_fingerprint($fingerprint) { * @return void */ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", - $L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; + if ($TZ == "") { + $TZ = config_get("options", "default_timezone"); + } + include("account_edit_form.php"); return; } @@ -88,6 +92,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @param string $C The confirmed password for the user * @param string $R The real name of the user * @param string $L The language preference of the user + * @param string $TZ The timezone preference of the user * @param string $HP The homepage of the displayed user * @param string $I The IRC nickname of the user * @param string $K The PGP fingerprint of the user @@ -102,7 +107,7 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="" * @return array Boolean indicating success and message to be printed */ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", - $R="",$L="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { + $R="",$L="",$TZ="",$HP="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") { global $SUPPORTED_LANGS; $error = ''; @@ -200,6 +205,9 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" if (!$error && !array_key_exists($L, $SUPPORTED_LANGS)) { $error = __("Language is not currently supported."); } + if (!$error && !array_key_exists($TZ, generate_timezone_list())) { + $error = __("Timezone is not currently supported."); + } if (!$error) { /* * Check whether the user name is available. @@ -278,13 +286,14 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $salt = $dbh->quote($salt); $R = $dbh->quote($R); $L = $dbh->quote($L); + $TZ = $dbh->quote($TZ); $HP = $dbh->quote($HP); $I = $dbh->quote($I); $K = $dbh->quote(str_replace(" ", "", $K)); $q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, "; - $q.= "RealName, LangPreference, Homepage, IRCNick, PGPKey) "; - $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, "; + $q.= "RealName, LangPreference, Timezone, Homepage, IRCNick, PGPKey) "; + $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, $TZ "; $q.= "$HP, $I, $K)"; $result = $dbh->exec($q); if (!$result) { @@ -347,6 +356,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" } $q.= ", RealName = " . $dbh->quote($R); $q.= ", LangPreference = " . $dbh->quote($L); + $q.= ", Timezone = " . $dbh->quote($TZ); $q.= ", Homepage = " . $dbh->quote($HP); $q.= ", IRCNick = " . $dbh->quote($I); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); @@ -359,6 +369,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" $ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints); + if (isset($_COOKIE["AURTZ"]) && ($_COOKIE["AURTZ"] != $TZ)) { + /* set new cookie for timezone */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $TZ, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 9015ae8..431c1c4 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -18,6 +18,9 @@ include_once("cachefuncs.inc.php"); include_once("confparser.inc.php"); include_once("credentials.inc.php"); +include_once('timezone.inc.php'); +set_tz(); + /** * Check if a visitor is logged in * diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 8ceac8d..6a443a3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -172,7 +172,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * maintainer will not be included in the Cc list of the * request notification email. */ - $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"])); + $out_of_date_time = date("Y-m-d", intval($details["OutOfDateTS"])); pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true); diff --git a/web/lib/timezone.inc.php b/web/lib/timezone.inc.php new file mode 100644 index 0000000..9fb2433 --- /dev/null +++ b/web/lib/timezone.inc.php @@ -0,0 +1,60 @@ +<?php +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +/** + * Generate an associative of the PHP timezones and display text. + * + * @return array PHP Timezone => Displayed Description + */ +function generate_timezone_list() { + $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL); + + $offsets = array(); + foreach ($php_timezones as $timezone) { + $tz = new DateTimeZone($timezone); + $offset = $tz->getOffset(new DateTime()); + $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) . + ") " . $timezone; + } + + asort($offsets); + return $offsets; +} + +/** + * Set the timezone for the user. + * + * @return null + */ +function set_tz() { + $timezones = generate_timezone_list(); + $update_cookie = false; + + if (isset($_COOKIE["AURTZ"])) { + $timezone = $_COOKIE["AURTZ"]; + } elseif (isset($_COOKIE["AURSID"])) { + $dbh = DB::connect(); + $q = "SELECT Timezone FROM Users, Sessions "; + $q .= "WHERE Users.ID = Sessions.UsersID "; + $q .= "AND Sessions.SessionID = "; + $q .= $dbh->quote($_COOKIE["AURSID"]); + $result = $dbh->query($q); + + if ($result) { + $timezone = $result->fetchColumn(0); + } + + $update_cookie = true; + } + + if (!isset($timezone) || !array_key_exists($timezone, $timezones)) { + $timezone = config_get("options", "default_timezone"); + } + date_default_timezone_set($timezone); + + if ($update_cookie) { + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURTZ", $timezone, $cookie_time, "/"); + } +} diff --git a/web/template/account_edit_form.php b/web/template/account_edit_form.php index 19821a0..17c9d14 100644 --- a/web/template/account_edit_form.php +++ b/web/template/account_edit_form.php @@ -129,6 +129,21 @@ ?> </select> </p> + <p> + <label for="id_timezone"><?= __("Timezone") ?></label> + <select name="TZ" id="id_timezone"> +<?php + $timezones = generate_timezone_list(); + while (list($key, $val) = each($timezones)) { + if ($TZ == $key) { + print "<option value=\"".$key."\" selected=\"selected\"> ".$val."</option>\n"; + } else { + print "<option value=\"".$key."\"> ".$val."</option>\n"; + } + } +?> + </select> + </p> </fieldset> <fieldset> diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php index 36af43e..e8855fe 100644 --- a/web/template/flag_comment.php +++ b/web/template/flag_comment.php @@ -5,7 +5,7 @@ <?= __('%s%s%s flagged %s%s%s out-of-date on %s%s%s for the following reason:', '<strong>', html_format_username($message['Username']), '</strong>', '<strong>', htmlspecialchars($pkgbase_name), '</strong>', - '<strong>', gmdate('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> + '<strong>', date('Y-m-d', $message['OutOfDateTS']), '</strong>'); ?> <?php else: ?> <?= __('%s%s%s is not flagged out-of-date.', '<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index a28e41b..fee1898 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -17,7 +17,7 @@ if (!isset($count)) { <?php while (list($indx, $row) = each($comments)): ?> <?php - $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']); + $date_fmtd = date('Y-m-d H:i', $row['CommentTS']); if ($row['UserName']) { $user_fmtd = html_format_username($row['UserName']); $heading = __('%s commented on %s', $user_fmtd, $date_fmtd); @@ -30,7 +30,7 @@ if (!isset($count)) { $is_pinned = $row['PinnedTS']; if ($uid && $is_deleted) { - $date_fmtd = gmdate('Y-m-d H:i', $row['DelTS']); + $date_fmtd = date('Y-m-d H:i', $row['DelTS']); $heading .= ' <span class="edited">('; if ($row['DelUserName']) { $user_fmtd = html_format_username($row['DelUserName']); @@ -40,7 +40,7 @@ if (!isset($count)) { } $heading .= ')</span>'; } elseif ($uid && $is_edited) { - $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']); + $date_fmtd = date('Y-m-d H:i', $row['EditedTS']); $heading .= ' <span class="edited">('; if ($row['EditUserName']) { $user_fmtd = html_format_username($row['EditUserName']); diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index b9c66d4..3269394 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -34,9 +34,9 @@ $msg = __('unknown'); $license = empty($row['License']) ? $msg : $row['License']; # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 1012c4e..fe76959 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -31,9 +31,9 @@ $popularity = $row['Popularity']; $msg = __('unknown'); # Print the timestamps for last updates -$updated_time = ($row["ModifiedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); -$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"])); -$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); +$updated_time = ($row["ModifiedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["ModifiedTS"])); +$submitted_time = ($row["SubmittedTS"] == 0) ? $msg : date("Y-m-d H:i", intval($row["SubmittedTS"])); +$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : date("Y-m-d", intval($row["OutOfDateTS"])); $pkgs = pkgbase_get_pkgnames($base_id); diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index b27963b..426c7f0 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -67,7 +67,7 @@ <td> <a href="<?= get_uri('/account/') . htmlspecialchars($row['User'], ENT_QUOTES) ?>" title="<?= __('View account information for %s', htmlspecialchars($row['User'])) ?>"><?= htmlspecialchars($row['User']) ?></a> </td> - <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?></td> + <td<?php if ($due): ?> class="flagged"<?php endif; ?>><?= date("Y-m-d H:i", intval($row['RequestTS'])) ?></td> <?php if ($row['Open']): ?> <td> <?php if ($row['BaseID']): ?> diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php index 580583b..b4c6215 100644 --- a/web/template/stats/updates_table.php +++ b/web/template/stats/updates_table.php @@ -10,7 +10,7 @@ <a href="<?= get_pkg_uri($row["Name"]); ?>" title="<?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>"><?= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> </td> <td class="pkg-date"> - <span><?= gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> + <span><?= date("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> </td> </tr> <?php endforeach; ?> diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 38f6c0d..d739060 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) { <?php endif; ?> </strong> <br /> - <?= __("Submitted: %s by %s", gmdate("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> + <?= __("Submitted: %s by %s", date("Y-m-d H:i", $row['Submitted']), html_format_username(username_from_id($row['SubmitterID']))) ?> <br /> <?= __("End") ?>: - <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <strong><?= date("Y-m-d H:i", $row['End']) ?></strong> <?php if ($isrunning == 0): ?> <br /> <?= __("Result") ?>: diff --git a/web/template/tu_list.php b/web/template/tu_list.php index b3e1073..b7253f9 100644 --- a/web/template/tu_list.php +++ b/web/template/tu_list.php @@ -38,8 +38,8 @@ <td><?php $row["Agenda"] = htmlspecialchars(substr($row["Agenda"], 0, $prev_Len)); ?> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['ID'] ?>"><?= $row["Agenda"] ?></a> </td> - <td><?= gmdate("Y-m-d", $row["Submitted"]) ?></td> - <td><?= gmdate("Y-m-d", $row["End"]) ?></td> + <td><?= date("Y-m-d", $row["Submitted"]) ?></td> + <td><?= date("Y-m-d", $row["End"]) ?></td> <td> <?php if (!empty($row['User'])): ?> <a href="<?= get_uri('/packages/'); ?>?K=<?= $row['User'] ?>&SeB=m"><?= $row['User'] ?></a> -- 2.11.0
Currently, when a user edits their language setting from the edit user form, the changes aren't reflected until the user either lets the original cookie expire, deletes the cookie manually, or changes the language a second time via the dropdown menu on the top of the page. This patch makes the language cookie get updated when it is changed from the edit user form. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/lib/acctfuncs.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 0067007..5c86d37 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -376,6 +376,13 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="" setcookie("AURTZ", $TZ, $cookie_time, "/"); } + if (isset($_COOKIE["AURLANG"]) && ($_COOKIE["AURLANG"] != $L)) { + /* set new cookie for language */ + $timeout = intval(config_get("options", "persistent_cookie_timeout")); + $cookie_time = time() + $timeout; + setcookie("AURLANG", $L, $cookie_time, "/"); + } + if ($result === false || $ssh_key_result === false) { $message = __("No changes were made to the account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); -- 2.11.0
Modify the call to process_account_form() to only having one parameter per line. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- web/html/account.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/web/html/account.php b/web/html/account.php index 91e5703..0b75761 100644 --- a/web/html/account.php +++ b/web/html/account.php @@ -31,13 +31,25 @@ if ($action == "UpdateAccount") { /* Update the details for the existing account */ list($success, $update_account_message) = process_account_form( "edit", "UpdateAccount", - in_request("U"), in_request("T"), in_request("S"), - in_request("E"), in_request("H"), in_request("P"), - in_request("C"), in_request("R"), in_request("L"), + in_request("U"), + in_request("T"), + in_request("S"), + in_request("E"), + in_request("H"), + in_request("P"), + in_request("C"), + in_request("R"), + in_request("L"), in_request("TZ"), - in_request("HP"), in_request("I"), in_request("K"), - in_request("PK"), in_request("J"), in_request("CN"), - in_request("UN"), in_request("ON"), in_request("ID"), + in_request("HP"), + in_request("I"), + in_request("K"), + in_request("PK"), + in_request("J"), + in_request("CN"), + in_request("UN"), + in_request("ON"), + in_request("ID"), $row["Username"]); } } -- 2.11.0
On Fri, 20 Jan 2017 at 07:16:39, Mark Weiman wrote:
Currently, aurweb displays all dates and times in UTC time. This patch adds a capability for each logged in user to set their preferred timezone.
Signed-off-by: Mark Weiman <mark.weiman@markzz.com> --- Removed renegade random tab in aur.inc.php Changed comment for set_tz() to not mention global $TZ that was removed Renamed $TZ in set_tz() to $timezone Change fetchAll() to fetchColumn() in set_tz() Removed extraneous else branch in set_tz() Simplified timezone check in set_tz() Moved if block from account_edit_form.php to display_account_form() before inclusion conf/config.proto | 1 + schema/aur-schema.sql | 1 + upgrading/4.5.0.txt | 5 +++ web/html/account.php | 3 ++ web/html/register.php | 2 ++ web/html/voters.php | 2 +- web/lib/acctfuncs.inc.php | 27 +++++++++++++--- web/lib/aur.inc.php | 3 ++ web/lib/pkgreqfuncs.inc.php | 2 +- web/lib/timezone.inc.php | 60 ++++++++++++++++++++++++++++++++++++ web/template/account_edit_form.php | 15 +++++++++ web/template/flag_comment.php | 2 +- web/template/pkg_comments.php | 6 ++-- web/template/pkg_details.php | 6 ++-- web/template/pkgbase_details.php | 6 ++-- web/template/pkgreq_results.php | 2 +- web/template/stats/updates_table.php | 2 +- web/template/tu_details.php | 4 +-- web/template/tu_list.php | 4 +-- 19 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 upgrading/4.5.0.txt create mode 100644 web/lib/timezone.inc.php [...]
This looks all good to me now. I added a reference to FS#48729 to the commit message and merged the result to pu. There was a small merge conflict but everything should be fine. Thanks for working on this and thanks for all those rerolls!
participants (3)
-
Johannes Löthberg
-
Lukas Fleischer
-
Mark Weiman