Changeset:
        cd2db8c464ca
        
https://sourceforge.net/p/mrbs/hg-code/ci/cd2db8c464ca161ecdb60ade7b5cc2f27e3d43eb
Author:
        Campbell Morrison <[email protected]>
Date:
        Mon Mar 27 08:07:34 2017 +0100
Log message:

First table.  No styling or information yet.

diffstat:

 web/functions.inc          |   19 +++++
 web/index.php              |  153 ++++++++++++++++++++++++++++++++++++++++-----
 web/internalconfig.inc.php |    7 +-
 web/mrbs_auth.inc          |    3 +-
 4 files changed, 161 insertions(+), 21 deletions(-)

diffs (226 lines):

diff -r f3b850ba89b8 -r cd2db8c464ca web/functions.inc
--- a/web/functions.inc Sat Mar 25 15:07:26 2017 +0000
+++ b/web/functions.inc Mon Mar 27 08:07:34 2017 +0100
@@ -620,6 +620,25 @@
 }
 
 
+// Gets an array of slot starts for a given booking day.
+function get_slot_starts($month, $day, $year)
+{
+  global $resolution, $morningstarts, $morningstarts_minutes;
+  
+  $result = array();
+  
+  $start_first_slot = get_start_first_slot($month, $day, $year);
+  $start_last_slot = get_start_last_slot($month, $day, $year);
+  
+  for ($t=$start_first_slot; $t<=$start_last_slot; $t+=$resolution)
+  {
+    $result[] = $t;
+  }
+  
+  return $result;
+}
+
+
 // Determines with a given timestamp is within a booking day, ie between the 
start of
 // the first slot and end of the last slot.   Returns a boolean.
 function is_in_booking_day($t)
diff -r f3b850ba89b8 -r cd2db8c464ca web/index.php
--- a/web/index.php     Sat Mar 25 15:07:26 2017 +0000
+++ b/web/index.php     Mon Mar 27 08:07:34 2017 +0100
@@ -1,27 +1,146 @@
 <?php
 namespace MRBS;
 
-// Index is just a stub to redirect to the appropriate view
-// as defined in config.inc.php using the variable $default_view
-// If $default_room is defined in config.inc.php then this will
-// be used to redirect to a particular room.
+require "defaultincludes.inc";
 
-require "defaultincludes.inc";
-require_once "mrbs_sql.inc";
 
-switch ($default_view)
+// Gets the booking interval (start first slot to end last slot)
+// for a given view.   Returns an array indexed by 'start' and 'end'.
+function get_interval($view, $month, $day, $year)
 {
-  case "month":
-    $redirect_str = "month.php";
-    break;
-  case "week":
-    $redirect_str = "week.php";
-    break;
-  default:
-    $redirect_str = "day.php";
+  global $weekstarts;
+  
+  $result = array();
+  
+  switch ($view)
+  {
+    case 'week':
+      $day_of_week = date('w', mktime(12, 0, 0, $month, $day, $year));
+      $days_after_start_of_week = ($day_of_week + DAYS_PER_WEEK - $weekstarts) 
% 7;
+      $result['start'] = get_start_first_slot($month, $day - 
$days_after_start_of_week, $year);
+      $result['end'] = get_end_last_slot($month, $day + (DAYS_PER_WEEK - 1) - 
$days_after_start_of_week, $year);
+      break;
+      
+    default:
+      trigger_error("Unsupported view: '$view'", E_USER_NOTICE);
+      break;
+  }
+  
+  return $result;
 }
 
-$redirect_str .= "?year=$year&month=$month&day=$day&area=$area&room=$room";
 
-header("Location: $redirect_str");
+// $interval needs to be a whole number of booking days,
+// ie start at the beginning of a booking day and end at the end.
+function get_empty_map($area, $interval)
+{
+  $result = array();
+  
+  // First get all the slots in this interval
+  $date = new DateTime();
+  $date->setTimestamp($interval['start']);
+  
+  $room_result = array();
+  
+  do {
+    $j = $date->format('j');  // day, no leading zero
+    $n = $date->format('n');  // month, no leading zero
+    $Y = $date->format('Y');  // year, four digits
+    
+    $slots = get_slot_starts($n, $j, $Y);
+    foreach ($slots as $slot)
+    {
+      $room_result[$slot] = array();
+    }
+    $date->modify('+1 day');
+  } while (get_end_last_slot($n, $j, $Y) < $interval['end']);
+  
+  // Now do this for every room in the area
+  $rooms = get_rooms($area);
+  foreach ($rooms as $room)
+  {
+    $result[$room['id']] = $room_result;
+  }
+  
+  return $result;
+}
 
+
+function get_map($area, $entries, $interval)
+{
+  global $resolution;
+ 
+  $map = get_empty_map($area, $interval);
+  $slots = array_keys(current($map));
+  
+  foreach ($entries as $entry)
+  {
+    $room_id = $entry['room_id'];
+    while (($slot = current($slots)) !== false)
+    {
+      // Find the first occupied slot
+      // We need the end_time condition to cut out bookings that fall
+      // entirely between booking days.
+      if (($entry['start_time'] < ($slot + $resolution))  &&
+          ($entry['end_time'] > $slot))
+      {
+        // and then find the remaining occupied slots
+        do {
+          $map[$room_id][$slot][] = $entry['id'];
+          $slot = next($slots);
+        } while (($slot !== false) && ($entry['end_time'] > ($slot + 
$resolution)));
+        reset($slots);
+        break;
+      }
+      $slot = next($slots);
+    }
+    reset($slots);
+  }
+
+  return $map;
+}
+
+
+function get_table($map)
+{
+  $html = '';
+  
+  $html .= "<table>\n";
+  
+  foreach ($map as $room_id => $row)
+  {
+    $html .= "<tr>\n";
+    $html .= "<td>$room_id</td>\n";
+    foreach ($row as $data)
+    {
+      $html .= "<td>";
+      if (count($data) == 1)
+      {
+        $html .= $data[0];
+      }
+      elseif (count($data) > 1)
+      {
+        trigger_error("To do");
+      }
+      $html .= "</td>\n";
+    }
+    
+    $html .= "</tr>\n";
+  }
+  
+  $html .= "</table>\n";
+  
+  return $html;
+}
+
+
+if (!checkAuthorised())
+{
+  exit;
+}
+
+$view = 'week';
+$interval = get_interval($view, $month, $day, $year);
+$entries = get_entries_by_area($area, $interval['start'], $interval['end']);
+$map = get_map($area, $entries, $interval);
+echo get_table($map);
diff -r f3b850ba89b8 -r cd2db8c464ca web/internalconfig.inc.php
--- a/web/internalconfig.inc.php        Sat Mar 25 15:07:26 2017 +0000
+++ b/web/internalconfig.inc.php        Mon Mar 27 08:07:34 2017 +0100
@@ -199,9 +199,10 @@
 /*************************************************
  * General constants - internal use, do not change
  *************************************************/
- define('MINUTES_PER_DAY',  24*60);
- define('SECONDS_PER_DAY',  MINUTES_PER_DAY * 60);
- define('SECONDS_PER_HOUR', 3600);
+define('DAYS_PER_WEEK',    7);
+define('MINUTES_PER_DAY',  24*60);
+define('SECONDS_PER_DAY',  MINUTES_PER_DAY * 60);
+define('SECONDS_PER_HOUR', 3600);
  
 /*************************************************
  * REPORT constants - internal use, do not change
diff -r f3b850ba89b8 -r cd2db8c464ca web/mrbs_auth.inc
--- a/web/mrbs_auth.inc Sat Mar 25 15:07:26 2017 +0000
+++ b/web/mrbs_auth.inc Mon Mar 27 08:07:34 2017 +0100
@@ -15,7 +15,8 @@
 // read features.   However if $auth['deny_public_access'] is TRUE then
 // access to the public is denied
 $page_level['day.php']                   = ($auth['deny_public_access']) ? 1 : 
0;
-$page_level['help.php']                  = ($auth['deny_public_access']) ? 1 : 
0;
+$page_level['index.php']                 = ($auth['deny_public_access']) ? 1 : 
0;
+$page_level['week.php']                  = ($auth['deny_public_access']) ? 1 : 
0;
 $page_level['month.php']                 = ($auth['deny_public_access']) ? 1 : 
0;
 $page_level['week.php']                  = ($auth['deny_public_access']) ? 1 : 
0;
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to