Changeset:
        17f9683caa60
        
https://sourceforge.net/p/mrbs/hg-code/ci/17f9683caa602ae475d8982a79e81784263f1116
Author:
        Campbell Morrison <[email protected]>
Date:
        Wed Apr 12 12:40:19 2017 +0100
Log message:

Started fixing the display of period names

diffstat:

 web/functions.inc      |  22 +++++++++++++++-------
 web/functions_view.inc |   4 ++--
 web/mrbs_sql.inc       |  20 ++++++++++++++++++++
 web/pending.php        |   2 +-
 web/report.php         |   4 ++--
 web/search.php         |   2 +-
 6 files changed, 41 insertions(+), 13 deletions(-)

diffs (140 lines):

diff -r f2e5f236ae9c -r 17f9683caa60 web/functions.inc
--- a/web/functions.inc Wed Apr 12 11:01:05 2017 +0100
+++ b/web/functions.inc Wed Apr 12 12:40:19 2017 +0100
@@ -2140,25 +2140,33 @@
 }
 
 
-function period_date_string($t, $mod_time=0)
+function period_date_string($t, $area_id, $mod_time=0)
 {
-  global $periods, $strftime_format;
-
+  global $strftime_format;
+  
+  static $period_names = null;
+  
+  if (!isset($period_names))
+  {
+    $period_names = get_period_names();
+  }
+  
   $time = getdate($t);
   $p_num = $time["minutes"] + $mod_time;
   if( $p_num < 0 )
   {
     $p_num = 0;
   }
-  if( $p_num >= count($periods) - 1 )
+  if( $p_num >= count($period_names[$area_id]) - 1 )
   {
-    $p_num = count($periods ) - 1;
+    $p_num = count($period_names[$area_id]) - 1;
   }
-  // I have made the separator a ',' as a '-' leads to an ambiguious
+  // The separator is a ',' as a '-' leads to an ambiguious
   // display in report.php when showing end times.
-  return array($p_num, $periods[$p_num] . utf8_strftime(", " . 
$strftime_format['date'], $t));
+  return array($p_num, $period_names[$area_id][$p_num] . utf8_strftime(", " . 
$strftime_format['date'], $t));
 }
 
+
 function period_time_string($t, $mod_time=0)
 {
   global $periods;
diff -r f2e5f236ae9c -r 17f9683caa60 web/functions_view.inc
--- a/web/functions_view.inc    Wed Apr 12 11:01:05 2017 +0100
+++ b/web/functions_view.inc    Wed Apr 12 12:40:19 2017 +0100
@@ -121,7 +121,7 @@
   // Start date
   if ($enable_periods)
   {
-    list($start_period, $start_date) =  
period_date_string($data['start_time']);
+    list($start_period, $start_date) =  
period_date_string($data['start_time'], $data['area_id']);
   }
   else
   {
@@ -133,7 +133,7 @@
   // End date
   if ($enable_periods)
   {
-    list( , $end_date) =  period_date_string($data['end_time'], -1);
+    list( , $end_date) =  period_date_string($data['end_time'], 
$data['area_id'], -1);
   }
   else
   {
diff -r f2e5f236ae9c -r 17f9683caa60 web/mrbs_sql.inc
--- a/web/mrbs_sql.inc  Wed Apr 12 11:01:05 2017 +0100
+++ b/web/mrbs_sql.inc  Wed Apr 12 12:40:19 2017 +0100
@@ -1626,6 +1626,26 @@
 }
 
 
+// Gets a two-dimensional array of period names indexed by area id.
+function get_period_names()
+{
+  global $tbl_area;
+  
+  $period_names = array();
+  
+  $sql = "SELECT id, periods FROM $tbl_area";
+  
+  $res = db()->query($sql);
+  
+  for ($i=0; $row = $res->row_keyed($i); $i++)
+  {
+    $period_names[$row['id']] = json_decode($row['periods']);
+  }
+  
+  return $period_names;
+}
+
+
 function mrbsGetRoomArea($id)
 {
   global $tbl_room;
diff -r f2e5f236ae9c -r 17f9683caa60 web/pending.php
--- a/web/pending.php   Wed Apr 12 11:01:05 2017 +0100
+++ b/web/pending.php   Wed Apr 12 12:40:19 2017 +0100
@@ -179,7 +179,7 @@
   }
   else
   {
-    list(,$link_str) = period_date_string($row['start_time']);
+    list(,$link_str) = period_date_string($row['start_time'], $row['area_id']);
   }
   echo htmlspecialchars($link_str) . "</a></td>";
     
diff -r f2e5f236ae9c -r 17f9683caa60 web/report.php
--- a/web/report.php    Wed Apr 12 11:01:05 2017 +0100
+++ b/web/report.php    Wed Apr 12 12:40:19 2017 +0100
@@ -754,7 +754,7 @@
         $mod_time = ($field == 'start_time') ? 0 : -1;
         if ($data['enable_periods'])
         {
-          list( , $date) =  period_date_string($value, $mod_time);
+          list( , $date) =  period_date_string($value, $data['area_id'], 
$mod_time);
         }
         else
         {
@@ -1375,7 +1375,7 @@
   $sql_params = array();
   $sql = "SELECT E.*, "
        .  db()->syntax_timestamp_to_unix("E.timestamp") . " AS last_updated, "
-       . "A.area_name, R.room_name, "
+       . "A.area_name, R.room_name, R.area_id, "
        . "A.approval_enabled, A.confirmation_enabled, A.enable_periods";
   if ($output_format == OUTPUT_ICAL)
   {
diff -r f2e5f236ae9c -r 17f9683caa60 web/search.php
--- a/web/search.php    Wed Apr 12 11:01:05 2017 +0100
+++ b/web/search.php    Wed Apr 12 12:40:19 2017 +0100
@@ -82,7 +82,7 @@
   }
   else
   {
-    list(,$link_str) = period_date_string($row['start_time']);
+    list(,$link_str) = period_date_string($row['start_time'], $row['area_id']);
   }
   $link .= htmlspecialchars($link_str) ."</a>";
   //    add a span with the numeric start time in the title for sorting

------------------------------------------------------------------------------
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