From 608c48309084e4048d8226c3f7e363b240248040 Mon Sep 17 00:00:00 2001
From: Mark Weiman
Date: Fri, 20 Jan 2017 01:16:39 -0500
Subject: Add user set timezones
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
Signed-off-by: Lukas Fleischer
---
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 +--
16 files changed, 123 insertions(+), 23 deletions(-)
create mode 100644 web/lib/timezone.inc.php
(limited to 'web')
diff --git a/web/html/account.php b/web/html/account.php
index 2892f046..91e57038 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 6c6d52e6..843fea97 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 8833be1e..997186d8 100644
--- a/web/html/voters.php
+++ b/web/html/voters.php
@@ -20,7 +20,7 @@ if (has_credential(CRED_PKGBASE_LIST_VOTERS)):
= htmlspecialchars($row['Username']) ?>
0): ?>
- (= gmdate("Y-m-d H:i", intval($row["VoteTS"])) ?>)
+ (= date("Y-m-d H:i", intval($row["VoteTS"])) ?>)
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 6dcf91d1..b7288143 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -1,5 +1,4 @@
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.",
"", htmlspecialchars($U,ENT_QUOTES), "");
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index 67dd1c14..94a38499 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 e4556a3f..7a171ed4 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 00000000..9fb24331
--- /dev/null
+++ b/web/lib/timezone.inc.php
@@ -0,0 +1,60 @@
+ 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 19821a0b..17c9d14e 100644
--- a/web/template/account_edit_form.php
+++ b/web/template/account_edit_form.php
@@ -126,6 +126,21 @@
print ""."\n";
}
}
+?>
+
+
+
+
+
diff --git a/web/template/flag_comment.php b/web/template/flag_comment.php
index 36af43ea..e8855fe8 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:',
'', html_format_username($message['Username']), '',
'', htmlspecialchars($pkgbase_name), '',
- '', gmdate('Y-m-d', $message['OutOfDateTS']), ''); ?>
+ '', date('Y-m-d', $message['OutOfDateTS']), ''); ?>
= __('%s%s%s is not flagged out-of-date.',
'', htmlspecialchars($pkgbase_name), ''); ?>
diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index a28e41b0..fee1898c 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -17,7 +17,7 @@ if (!isset($count)) {
(';
if ($row['DelUserName']) {
$user_fmtd = html_format_username($row['DelUserName']);
@@ -40,7 +40,7 @@ if (!isset($count)) {
}
$heading .= ')';
} 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 .= ' (';
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 b9c66d47..32693948 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 1012c4e6..fe769596 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 b27963be..426c7f08 100644
--- a/web/template/pkgreq_results.php
+++ b/web/template/pkgreq_results.php
@@ -67,7 +67,7 @@
= htmlspecialchars($row['User']) ?>
|
- class="flagged">= gmdate("Y-m-d H:i", intval($row['RequestTS'])) ?> |
+ class="flagged">= date("Y-m-d H:i", intval($row['RequestTS'])) ?> |
diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php
index 580583b5..b4c6215f 100644
--- a/web/template/stats/updates_table.php
+++ b/web/template/stats/updates_table.php
@@ -10,7 +10,7 @@
" title="= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>">= htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?>
|
- = gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?>
+ = date("Y-m-d H:i", intval($row["ModifiedTS"])); ?>
|
diff --git a/web/template/tu_details.php b/web/template/tu_details.php
index 38f6c0d0..d739060d 100644
--- a/web/template/tu_details.php
+++ b/web/template/tu_details.php
@@ -39,10 +39,10 @@ if ($yes > $active_tus / 2) {
- = __("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']))) ?>
= __("End") ?>:
- = gmdate("Y-m-d H:i", $row['End']) ?>
+ = date("Y-m-d H:i", $row['End']) ?>
= __("Result") ?>:
diff --git a/web/template/tu_list.php b/web/template/tu_list.php
index b3e1073a..b7253f98 100644
--- a/web/template/tu_list.php
+++ b/web/template/tu_list.php
@@ -38,8 +38,8 @@
= $row["Agenda"] ?>
|
- = gmdate("Y-m-d", $row["Submitted"]) ?> |
- = gmdate("Y-m-d", $row["End"]) ?> |
+ = date("Y-m-d", $row["Submitted"]) ?> |
+ = date("Y-m-d", $row["End"]) ?> |
= $row['User'] ?>
--
cgit v1.2.3-24-g4f1b
|