Changeset:
29a6a9d34e94
https://sourceforge.net/p/mrbs/hg-code/ci/29a6a9d34e946f5d032316258e66e93c6eca03b6
Author:
Campbell Morrison <[email protected]>
Date:
Sat Aug 27 12:39:13 2016 +0100
Log message:
Changed refresh mechanism for month view to Ajax from meta refresh.
diffstat:
web/js.inc | 15 +-
web/month.php | 633 ++++++++++++++++++++++++++++++---------------------------
web/style.inc | 9 +-
3 files changed, 350 insertions(+), 307 deletions(-)
diffs (truncated from 727 to 300 lines):
diff -r a014f5654e12 -r 29a6a9d34e94 web/js.inc
--- a/web/js.inc Sat Aug 27 11:30:49 2016 +0100
+++ b/web/js.inc Sat Aug 27 12:39:13 2016 +0100
@@ -185,13 +185,20 @@
<script type="text/javascript" src="js/<?php echo $page?>.js.php?<?php echo
$standard_query_string ?>"></script>
<?php
}
-
-
-// We need the resizable booking, multiple bookings and refresh code for the
day and week pages
+
+// The day, week and month views do refresh by Ajax.
+if (in_array($page, array('day', 'week', 'month')))
+{
+ ?>
+ <script type="text/javascript" src="js/refresh.js.php?<?php echo
$standard_query_string ?>"></script>
+ <?php
+}
+
+
+// We need the resizable booking and multiple bookings for the day and week
pages
if (in_array($page, array('day', 'week')))
{
?>
- <script type="text/javascript" src="js/refresh.js.php?<?php echo
$standard_query_string ?>"></script>
<script type="text/javascript" src="js/resizable.js.php?<?php echo
$standard_query_string ?>"></script>
<script type="text/javascript" src="js/multiple.js.php?<?php echo
$standard_query_string ?>"></script>
<?php
diff -r a014f5654e12 -r 29a6a9d34e94 web/month.php
--- a/web/month.php Sat Aug 27 11:30:49 2016 +0100
+++ b/web/month.php Sat Aug 27 12:39:13 2016 +0100
@@ -7,8 +7,6 @@
require_once "mincals.inc";
require_once "functions_table.inc";
-$debug_flag = get_form_var('debug_flag', 'int');
-
// 3-value compare: Returns result of compare as "< " "= " or "> ".
function cmp3($a, $b)
{
@@ -91,6 +89,334 @@
}
+function month_table_innerhtml($day, $month, $year, $room, $area)
+{
+ global $tbl_entry;
+ global $weekstarts, $view_week_number, $show_plus_link,
$monthly_view_entries_details;
+ global $enable_periods, $morningstarts, $morningstarts_minutes;
+ global $approval_enabled, $confirmation_enabled;
+ global $is_private_field;
+ global $user;
+ global $debug_flag;
+
+ $html = '';
+
+ $month_start = mktime(0, 0, 0, $month, 1, $year);
+ $weekday_start = (date("w", $month_start) - $weekstarts + 7) % 7;
+ $days_in_month = date("t", $month_start);
+
+ // Define the start and end of each day of the month in a way which is not
+ // affected by daylight saving...
+ for ($j = 1; $j<=$days_in_month; $j++)
+ {
+ // are we entering or leaving daylight saving
+ // dst_change:
+ // -1 => no change
+ // 0 => entering DST
+ // 1 => leaving DST
+ $dst_change[$j] = is_dst($month, $j, $year);
+ $am7[$j] = get_start_first_slot($month, $j, $year);
+ $pm7[$j] = get_start_last_slot($month, $j, $year);
+ }
+
+ //Get all meetings for this month in the room that we care about
+ // row[0] = Start time
+ // row[1] = End time
+ // row[2] = Entry ID
+ // This data will be retrieved day-by-day fo the whole month
+ for ($day_num = 1; $day_num<=$days_in_month; $day_num++)
+ {
+ $sql = "SELECT start_time, end_time, id, name, type,
+ repeat_id, status, create_by
+ FROM $tbl_entry
+ WHERE room_id=$room
+ AND start_time <= $pm7[$day_num] AND end_time > $am7[$day_num]
+ ORDER BY start_time";
+
+ // Build an array of information about each day in the month.
+ // The information is stored as:
+ // d[monthday]["id"][] = ID of each entry, for linking.
+ // d[monthday]["data"][] = "start-stop" times or "name" of each entry.
+
+ $res = sql_query($sql);
+ if (! $res)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(TRUE, get_vocab("fatal_db_error"));
+ }
+ else
+ {
+ for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+ {
+ if ($debug_flag)
+ {
+ $html .= "<br>DEBUG: result $i, id ".$row['id'].", starts
".$row['start_time'].", ends ".$row['end_time']."\n";
+ }
+
+ if ($debug_flag)
+ {
+ $html .= "<br>DEBUG: Entry ".$row['id']." day $day_num\n";
+ }
+ $d[$day_num]["id"][] = $row['id'];
+ $d[$day_num]["color"][] = $row['type'];
+ $d[$day_num]["is_repeat"][] = isset($row['repeat_id']);
+
+ // Handle private events
+ if (is_private_event($row['status'] & STATUS_PRIVATE))
+ {
+ if (getWritable($row['create_by'], $user, $room))
+ {
+ $private = FALSE;
+ }
+ else
+ {
+ $private = TRUE;
+ }
+ }
+ else
+ {
+ $private = FALSE;
+ }
+
+ if ($private & $is_private_field['entry.name'])
+ {
+ $d[$day_num]["status"][] = $row['status'] | STATUS_PRIVATE; // Set
the private bit
+ $d[$day_num]["shortdescrip"][] = '['.get_vocab('unavailable').']';
+ }
+ else
+ {
+ $d[$day_num]["status"][] = $row['status'] & ~STATUS_PRIVATE; //
Clear the private bit
+ $d[$day_num]["shortdescrip"][] = htmlspecialchars($row['name']);
+ }
+
+ $d[$day_num]["data"][] = get_booking_summary($row['start_time'],
+ $row['end_time'],
+ $am7[$day_num],
+ $pm7[$day_num]);
+ }
+ }
+ }
+ if ($debug_flag)
+ {
+ $html .= "<p>DEBUG: Array of month day data:</p><pre>\n";
+ for ($i = 1; $i <= $days_in_month; $i++)
+ {
+ if (isset($d[$i]["id"]))
+ {
+ $n = count($d[$i]["id"]);
+ $html .= "Day $i has $n entries:\n";
+ for ($j = 0; $j < $n; $j++)
+ {
+ $html .= " ID: " . $d[$i]["id"][$j] .
+ " Data: " . $d[$i]["data"][$j] . "\n";
+ }
+ }
+ }
+ $html .= "</pre>\n";
+ }
+
+ // Weekday name header row:
+ $html .= "<thead>\n";
+ $html .= "<tr>\n";
+ for ($weekcol = 0; $weekcol < 7; $weekcol++)
+ {
+ if (is_hidden_day(($weekcol + $weekstarts) % 7))
+ {
+ // These days are to be hidden in the display (as they are hidden, just
give the
+ // day of the week in the header row
+ $html .= "<th class=\"hidden_day\">" . day_name(($weekcol +
$weekstarts)%7) . "</th>";
+ }
+ else
+ {
+ $html .= "<th>" . day_name(($weekcol + $weekstarts)%7) . "</th>";
+ }
+ }
+ $html .= "\n</tr>\n";
+ $html .= "</thead>\n";
+
+ // Main body
+ $html .= "<tbody>\n";
+ $html .= "<tr>\n";
+
+ // Skip days in week before start of month:
+ for ($weekcol = 0; $weekcol < $weekday_start; $weekcol++)
+ {
+ if (is_hidden_day(($weekcol + $weekstarts) % 7))
+ {
+ $html .= "<td class=\"hidden_day\"><div
class=\"cell_container\"> </div></td>\n";
+ }
+ else
+ {
+ $html .= "<td class=\"invalid\"><div
class=\"cell_container\"> </div></td>\n";
+ }
+ }
+
+ // Draw the days of the month:
+ for ($cday = 1; $cday <= $days_in_month; $cday++)
+ {
+ // if we're at the start of the week (and it's not the first week), start
a new row
+ if (($weekcol == 0) && ($cday > 1))
+ {
+ $html .= "</tr><tr>\n";
+ }
+
+ // output the day cell
+ if (is_hidden_day(($weekcol + $weekstarts) % 7))
+ {
+ // These days are to be hidden in the display (as they are hidden, just
give the
+ // day of the week in the header row
+ $html .= "<td class=\"hidden_day\">\n";
+ $html .= "<div class=\"cell_container\">\n";
+ $html .= "<div class=\"cell_header\">\n";
+ // first put in the day of the month
+ $html .= "<span>$cday</span>\n";
+ $html .= "</div>\n";
+ $html .= "</div>\n";
+ $html .= "</td>\n";
+ }
+ else
+ {
+ $html .= "<td class=\"valid\">\n";
+ $html .= "<div class=\"cell_container\">\n";
+
+ $html .= "<div class=\"cell_header\">\n";
+ // If it's a Monday (the start of the ISO week), show the week number
+ if ($view_week_number && (($weekcol + $weekstarts)%7 == 1))
+ {
+ $html .= "<a class=\"week_number\"
href=\"week.php?year=$year&month=$month&day=$cday&area=$area&room=$room\">";
+ $html .= date("W", gmmktime(12, 0, 0, $month, $cday, $year));
+ $html .= "</a>\n";
+ }
+ // then put in the day of the month
+ $html .= "<a class=\"monthday\"
href=\"day.php?year=$year&month=$month&day=$cday&area=$area\">$cday</a>\n";
+
+ $html .= "</div>\n";
+
+ // then the link to make a new booking
+ $query_string =
"room=$room&area=$area&year=$year&month=$month&day=$cday";
+ if ($enable_periods)
+ {
+ $query_string .= "&period=0";
+ }
+ else
+ {
+ $query_string .=
"&hour=$morningstarts&minute=$morningstarts_minutes";
+ }
+
+ $html .= "<a class=\"new_booking\"
href=\"edit_entry.php?$query_string\">\n";
+ if ($show_plus_link)
+ {
+ $html .= "<img src=\"images/new.gif\" alt=\"New\" width=\"10\"
height=\"10\">\n";
+ }
+ $html .= "</a>\n";
+
+ // then any bookings for the day
+ if (isset($d[$cday]["id"][0]))
+ {
+ $html .= "<div class=\"booking_list\">\n";
+ $n = count($d[$cday]["id"]);
+ // Show the start/stop times, 1 or 2 per line, linked to view_entry.
+ for ($i = 0; $i < $n; $i++)
+ {
+ // give the enclosing div the appropriate width: full width if both,
+ // otherwise half-width (but use 49.9% to avoid rounding problems in
some browsers)
+ $class = $d[$cday]["color"][$i];
+ if ($d[$cday]["status"][$i] & STATUS_PRIVATE)
+ {
+ $class .= " private";
+ }
+ if ($approval_enabled && ($d[$cday]["status"][$i] &
STATUS_AWAITING_APPROVAL))
+ {
+ $class .= " awaiting_approval";
+ }
+ if ($confirmation_enabled && ($d[$cday]["status"][$i] &
STATUS_TENTATIVE))
+ {
+ $class .= " tentative";
+ }
+ $html .= "<div class=\"" . $class . "\"" .
+ " style=\"width: " . (($monthly_view_entries_details == "both") ?
'100%' : '49.9%') . "\">\n";
+ $booking_link = "view_entry.php?id=" . $d[$cday]["id"][$i] .
"&day=$cday&month=$month&year=$year";
+ $slot_text = $d[$cday]["data"][$i];
+ $description_text = utf8_substr($d[$cday]["shortdescrip"][$i], 0,
255);
+ $full_text = $slot_text . " " . $description_text;
+ switch ($monthly_view_entries_details)
+ {
+ case "description":
+ {
+ $display_text = $description_text;
+ break;
------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits