phpScheduleIt
May 25, 2013, 03:56:57 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Display timezone when creating/modding a reservation  (Read 881 times)
hakito
Newbie
*

Karma: 0
Posts: 15


« on: July 15, 2010, 04:37:51 AM »

Reason for the mod
We noticed that some useres complained about double bookings or reservations at the wrong time because they had wrong timezone settings. Also the reservation confirmation emails showed the overlapping times without giving a hint about the users timezone.

Please note
This patch also includes my mod for schedule admins. For languages other than german or english you'll have to apply modifications manually (should be very easy).

What the mod does
  • Adds a missing german text for confirmation approval email. (reservation_activity_7)
  • Adds GMT offset information to the confirmation emails. (german and english ONLY)
  • Adds GMT offset information to reserve form
  • Adds GMT offset information to schedule views
  • Includes mod for schedule admins

Patch for version 1.2.12 (Revision 496)
Code:
Index: lib/Time.class.php
===================================================================
205a206,216
> * Gets a string for the GMT offset of the user
> * @return the GMT offset formatted 'GMT+X'
> */
> function getGMToffsetString() {
> global $conf;
> $offset = $conf['app']['timezone'] + Time::getHourOffset();
> $gmtString = 'GMT'.($offset > 0 ? '+'.$offset:$offset);
> return $gmtString;
> }
>
> /**
Index: lib/Reservation.class.php
===================================================================
717,722c717,723
< $location = $this->resource->properties['location'];
< $phone    = $this->resource->properties['rphone'];
< $name     = $this->resource->properties['name'];
< $location = !empty($location) ? $location : translate('N/A');
< $phone    = !empty($phone) ? $phone : translate('N/A');
<
---
> $location  = $this->resource->properties['location'];
> $phone     = $this->resource->properties['rphone'];
> $name      = $this->resource->properties['name'];
> $location  = !empty($location) ? $location : translate('N/A');
> $phone     = !empty($phone) ? $phone : translate('N/A');
> $gmtString = translate('Times in') . ' '. Time::getGMToffsetString();
>
724c725
<             $text = translate_email('reservation_activity_7', $uname, $this->id, $start_date, $start, $end_date, $end, $name, $location, translate($mod));
---
>             $text = translate_email('reservation_activity_7', $uname, $this->id, $start_date, $start, $end_date, $end, $gmtString, $name, $location, translate($mod));
727c728
<             $text = translate_email('reservation_activity_1', $uname, translate($mod), $this->id, $start_date, $start, $end_date, $end, $name, $location, translate($mod));
---
>             $text = translate_email('reservation_activity_1', $uname, translate($mod), $this->id, $start_date, $start, $end_date, $end, $gmtString, $name, $location, translate($mod));
848c849,850
< $msg .= '| ' . translate("Reservation $mod") . (str_repeat(' ', $total_width - strlen(translate("Reservation $mod")) - 4)) . " |\n";
---
> $tableHeadText = translate("Reservation $mod") . ' (' . $gmtString . ')';
> $msg .= '| ' . $tableHeadText . (str_repeat(' ', $total_width - strlen($tableHeadText) - 4)) . " |\n";
Index: lib/Auth.class.php
===================================================================
51a52,58
>
> /**
> * Check if user is administrator for
> */
> function isScheduleAdmin() {
> return isset($_SESSION['sessionScheduleAdmin']);
> }
92a100
> $_SESSION['sessionScheduleAdmin'] = null;
197a206,211
>
> // If it is an admin for a schedule, set session variable
> if ($user->get_isscheduleadmin())
> {
> $_SESSION['sessionScheduleAdmin'] = implode(',', $user->get_administrated_schedules());
> }
Index: lib/Admin.class.php
===================================================================
105a106,108
> // else if ($this->tool[2] == 'schedules') {
> // $allowed = $this->user->get_isscheduleadmin();
> // }
Index: lib/Schedule.class.php
===================================================================
56c56,63
<             $this->scheduleid = $this->db->get_default_id();
---
>         $user = new User(Auth::getCurrentID());
>         if ($this->scheduleType == BLACKOUT_ONLY && !$user->is_admin) {
>         $users_schedules = $user->get_administrated_schedules();
>         $this->scheduleid = $users_schedules[0];
>         }
>         else {
>             $this->scheduleid = $this->db->get_default_id();
>         }
100a108,123
>         print_timezone_info();
>        
>         $user = new User(Auth::getCurrentID());
>         $schedule_list = $this->db->get_schedule_list();
> if ($this->scheduleType == BLACKOUT_ONLY && !$user->is_admin) {
> $user_schedules = array();
> foreach ($schedule_list as $row) {
> if ($user->is_schedule_admin($row['scheduleid'])) {
> array_push($user_schedules, $row);
> }
> }
> $schedule_list = $user_schedules;
>         }
>        
>         print_schedule_list($schedule_list, $this->scheduleid);
>        
102,108c125,148
<         print_schedule_list($this->db->get_schedule_list(), $this->scheduleid);
<
<         $this->print_calendars();
<
<         if ($this->scheduleType == ALL)
< {
<             print_color_key();
---
> if ($user->is_schedule_admin($this->scheduleid) || $user->is_admin || $this->scheduleType != BLACKOUT_ONLY ) {
>        $this->print_calendars();
>
>        if ($this->scheduleType == ALL)
> {
>            print_color_key();
> }
>
>        // Break first day we are viewing into an array of date pieces
>        $temp_date = getdate($this->_date['firstDayTs']);
>        $hour_header = get_hour_header($this->get_time_array(), $this->startDay, $this->endDay, $this->timespan);    // Get the headers (same for all tables)
>
>        // Repeat this for each day we need to show
>        for ($dayCount = 0; $dayCount < $this->viewdays; $dayCount++) {
>            // Timestamp for whatever day we are currently viewing
>            $this->_date['current'] = mktime(0,0,0, $temp_date['mon'], $temp_date['mday'] + $dayCount, $temp_date['year']);
>            start_day_table($this->get_display_date(), $hour_header, $this->_date['now'] == $this->_date['current']);    // Start the table for this day
>            $this->print_reservations();    // Print reservations for this day
>            end_day_table();                // End the table for this day
>        }
>        print_summary_div();
> }
> else {
> echo "Blackouts can only be modified by the admin of this schedule.<br />";
110,123d149
<
<         // Break first day we are viewing into an array of date pieces
<         $temp_date = getdate($this->_date['firstDayTs']);
<         $hour_header = get_hour_header($this->get_time_array(), $this->startDay, $this->endDay, $this->timespan);    // Get the headers (same for all tables)
<
<         // Repeat this for each day we need to show
<         for ($dayCount = 0; $dayCount < $this->viewdays; $dayCount++) {
<             // Timestamp for whatever day we are currently viewing
<             $this->_date['current'] = mktime(0,0,0, $temp_date['mon'], $temp_date['mday'] + $dayCount, $temp_date['year']);
<             start_day_table($this->get_display_date(), $hour_header, $this->_date['now'] == $this->_date['current']);    // Start the table for this day
<             $this->print_reservations();    // Print reservations for this day
<             end_day_table();                // End the table for this day
<         }
<         print_summary_div();
147c173,174
< if (Auth::isAdmin()) {
---
> $user = new User(Auth::getCurrentId());
>     if (Auth::isAdmin() || $user->is_schedule_admin($this->scheduleid)) {
486a514,515
>         $user = new User(Auth::getCurrentID());
>        
490c519
< $is_private = $conf['app']['privacyMode'] && !Auth::isAdmin();
---
> $is_private = $conf['app']['privacyMode'] && ! (Auth::isAdmin() || ($user->get_administrated_schedules() != null && in_array($this->scheduleid, $user->get_administrated_schedules())));
507c536
<         $mod_view = ( ($is_mine && $viewable_date) || Auth::isAdmin()) ? 'm' : 'v';    // To use in javascript edit/view box
---
>         $mod_view = ( ($is_mine && $viewable_date) || Auth::isAdmin() || ($user->get_administrated_schedules() != null && in_array($this->scheduleid, $user->get_administrated_schedules()))) ? 'm' : 'v';    // To use in javascript edit/view box
524c553,554
< $is_private = $conf['app']['privacyMode'] && !Auth::isAdmin();
---
>         $user = new User(Auth::getCurrentId());
> $is_private = $conf['app']['privacyMode'] && ! (Auth::isAdmin() || $user->is_schedule_admin($this->scheduleid));
530c560
<         write_blackout($colspan, Auth::isAdmin(), $rs['resid'], $summary,  $showsummary);
---
>         write_blackout($colspan, Auth::isAdmin() || $user->is_schedule_admin($this->scheduleid), $rs['resid'], $summary,  $showsummary);
Index: lib/User.class.php
===================================================================
28a29
> var $administrated_schedules; //
66c67,81
<
---
>
> $this->administrated_schedules = array();
> $schedules = $this->db->get_schedule_list();
> if (!$schedules) {
> $this->err_msg = $this->db->get_err();
> }
> else {
> foreach ($schedules as $row) {
> $schedule = $this->db->get_schedule_data($row['scheduleid']);
> if ($schedule['adminemail'] == $data['email']) {
> array_push($this->administrated_schedules, $row['scheduleid']);
> }
> }
> }
>
314a330,344
> * Returns whether this user is an admin of this schedule or not
> * @param $scheduleid (optional) the schedule id to check for admin on.  if this is not
> * provided, this just checks if the user is an admin of any schedule.
> * @return if the user is the schedule admin or not
> */
> function is_schedule_admin($scheduleid = null) {
> if ( !is_null($scheduleid) && $this->get_administrated_schedules() != null) {
> return in_array($scheduleid, $this->get_administrated_schedules());
> }
> else {
> return $this->get_isscheduleadmin();
> }
> }
>
> /**
366a397,404
> function get_isscheduleadmin() {
> return count($this->administrated_schedules) > 0;
> }
>
> function get_administrated_schedules() {
> return $this->administrated_schedules;
> }
>
Index: lang/en_US.lang.php
===================================================================
759c759
< . "A reservation between %s %s and %s %s for %s"
---
> . "A reservation between %s %s and %s %s (%s) for %s"
774c774
< . "A reservation between %s %s and %s %s for %s"
---
> . "A reservation between %s %s and %s %s (%s) for %s"
Index: lang/en_GB.lang.php
===================================================================
304a305
> $strings['Times in'] = 'Times in';
759c760
< . "A reservation between %s %s and %s %s for %s"
---
> . "A reservation between %s %s and %s %s (%s) for %s"
774c775
< . "A reservation between %s %s and %s %s for %s"
---
> . "A reservation between %s %s and %s %s (%s) for %s"
Index: lang/de.lang.php
===================================================================
304a305
> $strings['Times in'] = 'Zeiten in';
777,778c778,779
< . "Ihre Reservierung: VON %s, %s Uhr BIS %s, %s Uhr;"
< . " RAUM: %s, %s.\r\n\r\n<br/><br/>";
---
> . "Ihre Reservierung: VON %s, %s Uhr BIS %s, %s Uhr (%s)"
> . " Standort: %s, %s.\r\n\r\n<br/><br/>";
788c789,794
<
---
> $email['reservation_activity_7'] = "%s,\r\n<br />"
> . "Reservierung #%s wurde best?tigt.\r\n\r\n<br/><br/>"
> . "Bitte benutzen Sie diese Reservierungsnummer wenn Sie Fragen an den Administrator haben.\r\n\r\n<br/><br/>"
> . "Ihre Reservierung von %s %s bis %s %s (%s) f?r %s"
> . " am Standort %s wurde %s.\r\n\r\n<br/><br/>";
>
Index: templates/schedule.template.php
===================================================================
29a30,37
>  * Prints out the GMT offset for the displayed schedule
>  */
> function print_timezone_info() {
> $gmtString = ' ' . Time::getGMToffsetString();
> echo '<h3 align="center">'.translate('Times in').$gmtString.'</h3>';
> }
>
> /**
Index: templates/cpanel.template.php
===================================================================
370c370
< function showQuickLinks($is_admin = false, $is_group_admin = false) {
---
> function showQuickLinks($is_admin = false, $is_group_admin = false, $is_schedule_admin = false) {
415c415
< if ($is_admin) {
---
> if ($is_admin || $is_schedule_admin) {
427c427
< . '<p style="margin-top:10px;"><b>&raquo;</b> ' .  $link->getLink('admin.php?tool=groups', translate('Manage Groups')) . "</p>\n";
---
> . '<p style="margin-top:10px;"><b>&raquo;</b> ' .  $link->getLink('admin.php?tool=groups', translate('Manage Groups')) . "</p>\n";
428a429,432
> else if ($is_schedule_admin) {
> echo '<p><b>&raquo;</b> ' .  $link->getLink('blackouts.php', translate('Manage Blackout Times')) . "</p>\n";
> }
>
Index: templates/reserve.template.php
===================================================================
609a610
>         $msg = '(' . Time::getGMToffsetString() . ') ' . $msg;
Index: reserve.php
===================================================================
130c130
< $res->adminMode = Auth::isAdmin() || $cur_user->get_isadmin() || ($fn != 'create' && $cur_user->is_group_admin($res->user->get_groupids()));
---
> $res->adminMode = Auth::isAdmin() || $cur_user->get_isadmin() || ($fn != 'create' && $cur_user->is_group_admin($res->user->get_groupids()) || $cur_user->is_schedule_admin($res->get_scheduleid()));
132c132
< if (Auth::isAdmin() || $cur_user->get_isadmin())
---
> if (Auth::isAdmin() || $cur_user->get_isadmin() || $cur_user->is_schedule_admin($res->get_scheduleid()))
214c214
< $res->adminMode = Auth::isAdmin() || $cur_user->get_isadmin() || $cur_user->is_group_admin($res->user->get_groupids() );
---
> $res->adminMode = Auth::isAdmin() || $cur_user->get_isadmin() || $cur_user->is_group_admin($res->user->get_groupids()) || $cur_user->is_schedule_admin($res->get_scheduleid());
216c216
< if (Auth::isAdmin() || $cur_user->get_isadmin())
---
> if (Auth::isAdmin() || $cur_user->get_isadmin() || $cur_user->is_schedule_admin($res->get_scheduleid()))
Index: ctrlpnl.php
===================================================================
34c34
< showQuickLinks(Auth::isAdmin(), $is_group_admin); // Print out My Quick Links
---
> showQuickLinks(Auth::isAdmin(), $is_group_admin, Auth::isScheduleAdmin()); // Print out My Quick Links
Index: blackouts.php
===================================================================
29c29
< if (!Auth::isAdmin()) {
---
> if (!(Auth::isAdmin() || Auth::isScheduleAdmin())) {
The diff is minimal as the forum does not allow to exceed 20000 chars.  Angry
« Last Edit: July 15, 2010, 04:53:35 AM by hakito » Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #1 on: July 19, 2010, 01:38:56 PM »

Nice.  Thank you!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!