Add links to all owned packages to the dashboard
[aur.git] / web / lib / timezone.inc.php
blob9fb24331c03f0051a99ad5c7420e1092a68ad8c9
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
4 /**
5 * Generate an associative of the PHP timezones and display text.
7 * @return array PHP Timezone => Displayed Description
8 */
9 function generate_timezone_list() {
10 $php_timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
12 $offsets = array();
13 foreach ($php_timezones as $timezone) {
14 $tz = new DateTimeZone($timezone);
15 $offset = $tz->getOffset(new DateTime());
16 $offsets[$timezone] = "(UTC" . ($offset < 0 ? "-" : "+") . gmdate("H:i", abs($offset)) .
17 ") " . $timezone;
20 asort($offsets);
21 return $offsets;
24 /**
25 * Set the timezone for the user.
27 * @return null
29 function set_tz() {
30 $timezones = generate_timezone_list();
31 $update_cookie = false;
33 if (isset($_COOKIE["AURTZ"])) {
34 $timezone = $_COOKIE["AURTZ"];
35 } elseif (isset($_COOKIE["AURSID"])) {
36 $dbh = DB::connect();
37 $q = "SELECT Timezone FROM Users, Sessions ";
38 $q .= "WHERE Users.ID = Sessions.UsersID ";
39 $q .= "AND Sessions.SessionID = ";
40 $q .= $dbh->quote($_COOKIE["AURSID"]);
41 $result = $dbh->query($q);
43 if ($result) {
44 $timezone = $result->fetchColumn(0);
47 $update_cookie = true;
50 if (!isset($timezone) || !array_key_exists($timezone, $timezones)) {
51 $timezone = config_get("options", "default_timezone");
53 date_default_timezone_set($timezone);
55 if ($update_cookie) {
56 $timeout = intval(config_get("options", "persistent_cookie_timeout"));
57 $cookie_time = time() + $timeout;
58 setcookie("AURTZ", $timezone, $cookie_time, "/");