Revision: 1518
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1518&view=rev
Author:   cimorrison
Date:     2010-10-20 15:20:18 +0000 (Wed, 20 Oct 2010)

Log Message:
-----------
Bookings now specified in terms of start and end date and time, instead of 
duration.   Duration has yet to be added back in (using JavaScript)

Modified Paths:
--------------
    mrbs/branches/from_to_bookings/web/edit_entry.php
    mrbs/branches/from_to_bookings/web/edit_entry_handler.php
    mrbs/branches/from_to_bookings/web/lang.en
    mrbs/branches/from_to_bookings/web/mrbs-ie.css
    mrbs/branches/from_to_bookings/web/mrbs.css.php

Modified: mrbs/branches/from_to_bookings/web/edit_entry.php
===================================================================
--- mrbs/branches/from_to_bookings/web/edit_entry.php   2010-10-20 11:42:27 UTC 
(rev 1517)
+++ mrbs/branches/from_to_bookings/web/edit_entry.php   2010-10-20 15:20:18 UTC 
(rev 1518)
@@ -51,77 +51,36 @@
 require_once "defaultincludes.inc";
 require_once "mrbs_sql.inc";
 
-function gen_date_time_fields($label_text, $prefix, $time)
+// Generate a time or period selector starting with $first and ending with 
$last.
+// $time is a full Unix timestamp and is the current value.  The selector 
returns
+// the start time in seconds since the beginning of the day for the start of 
that slot
+function genslotselector($prefix, $first, $last, $time)
 {
-  global $enable_periods, $periods, $twentyfourhour_format;
+  global $resolution, $twentyfourhour_format, $periods, $enable_periods;
   
-  $form_day   = strftime('%d', $time);
-  $form_month = strftime('%m', $time);
-  $form_year  = strftime('%Y', $time);
-  $form_hour  = strftime('%H', $time);
-  $form_min   = strftime('%M', $time);
+  $date = getdate($time);
+  $time_zero = mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']);
   if ($enable_periods)
   {
-    $form_period = (($form_hour - 12) * 60) + $form_min;
+    $base = 12*60*60;  // The start of the first period of the day
   }
-  
-  echo "<label for=\"${prefix}datepicker\">$label_text:</label>\n";
-  gendateselector($prefix, $form_day, $form_month, $form_year);
-
-  if(! $enable_periods ) 
-  { 
-    echo "<div class=\"div_time\">\n";
-    echo "<input type=\"text\" class=\"time_hour\" name=\"hour\" value=\"";
-    if ($twentyfourhour_format)
-    {
-      echo $form_hour;
-    }
-    elseif ($form_hour > 12)
-    {
-      echo ($form_hour - 12);
-    } 
-    elseif ($form_hour == 0)
-    {
-      echo "12";
-    }
-    else
-    {
-      echo $form_hour;
-    } 
-    echo "\" maxlength=\"2\">\n";
-    echo "<span>:</span>\n";
-    echo "<input type=\"text\" class=\"time_minute\" name=\"minute\" value=\"" 
. $form_min . "\" maxlength=\"2\">\n";
-    if (!$twentyfourhour_format)
-    {
-      echo "<div class=\"group ampm\">\n";
-      $checked = ($form_hour < 12) ? "checked=\"checked\"" : "";
-      echo "      <label><input name=\"ampm\" type=\"radio\" value=\"am\" 
$checked>" . utf8_strftime("%p",mktime(1,0,0,1,1,2000)) . "</label>\n";
-      $checked = ($form_hour >= 12) ? "checked=\"checked\"" : "";
-      echo "      <label><input name=\"ampm\" type=\"radio\" value=\"pm\" 
$checked>". utf8_strftime("%p",mktime(13,0,0,1,1,2000)) . "</label>\n";
-      echo "</div>\n";
-    }
-    echo "</div>\n";
-  }
-    
   else
   {
-    echo "<div id=\"div_period\">\n";
-    echo "<select id=\"period\" name=\"period\">\n";
-    foreach ($periods as $p_num => $p_val)
-    {
-      echo "<option value=\"$p_num\"";
-      if ($form_period == $p_num)
-      {
-        echo " selected=\"selected\"";
-      }
-      echo ">$p_val</option>\n";
-    }
-    echo "</select>\n";
-    echo "</div>\n";
+    $format = ($twentyfourhour_format) ? "%R" : "%l:%M %P";
   }
+  $html .= "<select id = \"${prefix}seconds\" name=\"${prefix}seconds\">\n";
+  for ($t = $first; $t <= $last; $t = $t + $resolution)
+  {
+    $timestamp = $t + $time_zero;
+    $slot_string = ($enable_periods) ? $periods[intval(($t-$base)/60)] : 
utf8_strftime($format, $timestamp);
+    $html .= "<option value=\"$t\"";
+    $html .= ($timestamp == $time) ? " selected=\"selected\"" : "";
+    $html .= ">$slot_string</option>\n";
+  }
+  $html .= "</select>\n";
+  echo $html;
 }
 
-
 // Get non-standard form variables
 $hour = get_form_var('hour', 'int');
 $minute = get_form_var('minute', 'int');
@@ -252,6 +211,7 @@
         break;
         
       case 'end_time':
+        $end_time = $row['end_time'];
         $duration = $row['end_time'] - $row['start_time'] - 
cross_dst($row['start_time'], $row['end_time']);
         break;
         
@@ -370,6 +330,7 @@
     $default_duration = (60 * 60);
   }
   $duration    = ($enable_periods ? 60 : $default_duration);
+  $end_time = $start_time + $duration;
   $type        = "I";
   $room_id     = $room;
   unset($id);
@@ -523,59 +484,19 @@
   {
     // save the old values, disable the inputs and, to avoid user confusion,
     // show the start time as the beginning of the day and the duration as one 
day
-    <?php 
-    if ($enable_periods )
-    {
-      ?>
-      old_period = form.period.selectedIndex;
-      form.period.value = 0;
-      form.period.disabled = true;
-      <?php
-    }
-    else
-    { 
-      ?>
-      old_hour = form.hour.value;
-      form.hour.value = '<?php echo $morningstarts; ?>';
-      old_minute = form.minute.value;
-      form.minute.value = '<?php printf("%02d", $morningstarts_minutes); ?>';
-      form.hour.disabled = true;
-      form.minute.disabled = true;
-      <?php 
-    } 
-    ?>
-    
-    old_duration = form.duration.value;
-    form.duration.value = '1';  
-    old_dur_units = form.dur_units.selectedIndex;
-    form.dur_units.value = 'days';  
-    form.duration.disabled = true;
-    form.dur_units.disabled = true;
+    old_start = form.start_seconds.selectedIndex;
+    form.start_seconds.selectedIndex = 0;
+    form.start_seconds.disabled = true;
+    old_end = form.end_seconds.selectedIndex;
+    form.end_seconds.selectedIndex = form.end_seconds.options.length - 1;
+    form.end_seconds.disabled = true;
   }
   else  // restore the old values and re-enable the inputs
   {
-    <?php 
-    if ($enable_periods)
-    {
-      ?>
-      form.period.selectedIndex = old_period;
-      form.period.disabled = false;
-      <?php
-    }
-    else
-    { 
-      ?>
-      form.hour.value = old_hour;
-      form.minute.value = old_minute;
-      form.hour.disabled = false;
-      form.minute.disabled = false;
-      <?php 
-    } 
-    ?>
-    form.duration.value = old_duration;
-    form.dur_units.selectedIndex = old_dur_units;  
-    form.duration.disabled = false;
-    form.dur_units.disabled = false;
+    form.start_seconds.selectedIndex = old_start;
+    form.start_seconds.disabled = false;
+    form.end_seconds.selectedIndex = old_end;
+    form.end_seconds.disabled = false;
   }
 }
 //]]>
@@ -644,46 +565,50 @@
     }
     echo "</div>\n";
 
+    if ($enable_periods)
+    {
+      $resolution = 60;
+      $first = 12*60*60;
+      // If we're using periods we just go to the beginning of the last slot
+      $last = $first + ((count($periods) - 1) * $resolution);
+    }
+    else
+    {
+      $first = (($morningstarts * 60) + $morningstarts_minutes) * 60;
+      $last = (($eveningends * 60) + $eveningends_minutes) * 60;
+    }
+    echo "<div id=\"div_start_date\">\n";
+    echo "<label for=\"start_datepicker\">" . get_vocab("start") . 
":</label>\n";
+    $date = getdate($start_time);
+    gendateselector("start_", $date['mday'], $date['mon'], $date['year']);
+    // If we're using periods the booking model is slightly different:
+    // you're allowed to specify the last period as your first period.
+    // This is why we don't substract the $resolution
+    $start_last = ($enable_periods) ? $last : $last - $resolution;
+    genslotselector("start_", $first, $start_last, $start_time);
 
-    echo "<div id=\"div_date\">\n";
-    $label_text = get_vocab("start");
-    gen_date_time_fields($label_text, "start_", $start_time);
-    echo "</div>\n";
-    
     ?>
-    <div id="div_duration">
-      <label for="duration"><?php echo get_vocab("duration");?>:</label>
-      <div class="group">
-        <input id="duration" name="duration" value="<?php echo $duration;?>">
-        <select id="dur_units" name="dur_units">
-          <?php
-          if( $enable_periods )
-          {
-            $units = array("periods", "days");
-          }
-          else
-          {
-            $units = array("minutes", "hours", "days", "weeks", "years");
-          }
-
-          while (list(,$unit) = each($units))
-          {
-            echo "        <option value=\"$unit\"";
-            if ($dur_units == get_vocab($unit))
-            {
-              echo " selected=\"selected\"";
-            }
-            echo ">".get_vocab($unit)."</option>\n";
-          }
-          ?>
-        </select>
-        <div id="ad">
-          <input id="all_day" class="checkbox" name="all_day" type="checkbox" 
value="yes" onclick="OnAllDayClick(this)">
-          <label for="all_day"><?php echo get_vocab("all_day"); ?></label>
-        </div>
+    <div class="group">
+      <div id="ad">
+        <input id="all_day" class="checkbox" name="all_day" type="checkbox" 
value="yes" onclick="OnAllDayClick(this)">
+        <label for="all_day"><?php echo get_vocab("all_day"); ?></label>
       </div>
     </div>
+    <?php
+    echo "</div>\n";
     
+    echo "<div id=\"div_end_date\">\n";
+    echo "<label for=\"start_datepicker\">" . get_vocab("end") . ":</label>\n";
+    $date = getdate($end_time);
+    gendateselector("end_", $date['mday'], $date['mon'], $date['year']);
+    // If we're using periods the booking model is slightly different,
+    // so subtract one period because the "end" period is actually the 
beginning
+    // of the last period booked
+    $end_value = ($enable_periods) ? $end_time - $resolution : $end_time;
+    genslotselector("end_", $first, $last, $end_value);
+    echo "</div>\n";
+    
+    ?>  
     <div id="div_areas">
     </div>
 
@@ -836,8 +761,7 @@
       </div>
     </div>
     <div id="div_type">
-      <label for="type"><?php echo get_vocab("type")?>:</label>
-     <div class="group">    
+      <label for="type"><?php echo get_vocab("type")?>:</label> 
       <select id="type" name="type">
         <?php
         for ($c = "A"; $c <= "Z"; $c++)
@@ -852,7 +776,7 @@
       <?php 
       if ($private_enabled) 
       { ?>
-        <div id="div_private">
+        <div id="div_private" class="group"">
           <input id="private" class="checkbox" name="private" type="checkbox" 
value="yes"<?php 
           if($private) 
           {
@@ -866,7 +790,6 @@
           <label for="private"><?php echo get_vocab("private") ?></label>
         </div><?php 
       } ?>
-     </div>
     </div>
     
     <?php

Modified: mrbs/branches/from_to_bookings/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/from_to_bookings/web/edit_entry_handler.php   2010-10-20 
11:42:27 UTC (rev 1517)
+++ mrbs/branches/from_to_bookings/web/edit_entry_handler.php   2010-10-20 
15:20:18 UTC (rev 1518)
@@ -9,12 +9,8 @@
 $name = get_form_var('name', 'string');
 $rep_type = get_form_var('rep_type', 'int');
 $description = get_form_var('description', 'string');
-$hour = get_form_var('hour', 'int');
-$ampm = get_form_var('ampm', 'string');
-$minute = get_form_var('minute', 'int');
-$period = get_form_var('period', 'int');
-$duration = get_form_var('duration', 'string');
-$dur_units = get_form_var('dur_units', 'string');
+$start_seconds = get_form_var('start_seconds', 'int');
+$end_seconds = get_form_var('end_seconds', 'int');
 $all_day = get_form_var('all_day', 'string'); // bool, actually
 $type = get_form_var('type', 'string');
 $rooms = get_form_var('rooms', 'array');
@@ -33,13 +29,17 @@
 $day = get_form_var('start_day', 'int');
 $month = get_form_var('start_month', 'int');
 $year = get_form_var('start_year', 'int');
+// Get the end day/month/year
+$end_day = get_form_var('end_day', 'int');
+$end_month = get_form_var('end_month', 'int');
+$end_year = get_form_var('end_year', 'int');
 
 // Get the information about the fields in the entry table
 $fields = sql_field_info($tbl_entry);
 
 // Get custom form variables
 $custom_fields = array();
-                        
+                    
 foreach($fields as $field)
 {
   if (!in_array($field['name'], $standard_fields['entry']))
@@ -87,25 +87,6 @@
   $room = get_default_room($area);
 }
 
-// When $all_day is set, the hour and minute (or $period) fields are set to 
disabled, which means 
-// that they are not passed through by the form.   We need to set them because 
they are needed below  
-// in various places. (We could change the JavaScript in edit_entry.php to set 
the fields to readonly
-// instead of disabled, but browsers do not generally grey out readonly fields 
and this would mean
-// that it's not so obvious to the user what is happening.   Also doing it 
here is safer, in case 
-// JavaScript is disabled and for some strange reason the user changes the 
values in the form to be
-// before start of day)
-if (isset($all_day) && ($all_day == "yes"))
-{ 
-  if ($enable_periods)
-  {
-    $period = 0;
-  }
-  else
-  {
-    $hour = $morningstarts;
-    $minute = $morningstarts_minutes;
-  }
-}
 
 // Set up the return URL.    As the user has tried to book a particular room 
and a particular
 // day, we must consider these to be the new "sticky room" and "sticky day", 
so modify the 
@@ -249,14 +230,9 @@
   print_footer(TRUE);
 }
 
-// Support locales where ',' is used as the decimal point
-$duration = preg_replace('/,/', '.', $duration);
-
 if ($enable_periods)
 {
   $resolution = 60;
-  $hour = 12;
-  $minute = $period;
 }
 
 if (isset($all_day) && ($all_day == "yes"))
@@ -292,28 +268,20 @@
 }
 else
 {
-  // Get the duration in seconds
-  $dur_seconds = $duration;
-  $enable_periods ? fromPeriodString($period, $dur_seconds, $dur_units) : 
fromTimeString($dur_seconds, $dur_units);
-  if (!$twentyfourhour_format)
+  $starttime = mktime(0, 0, 0,
+                      $month, $day, $year,
+                      is_dst($month, $day, $year, 
intval($start_seconds/3600))) + $start_seconds;
+  $endtime   = mktime(0, 0, 0,
+                      $end_month, $end_day, $end_year,
+                      is_dst($end_month, $end_day, $end_year, 
intval($end_seconds/3600))) + $end_seconds;
+  // If we're using periods then the endtime we've been returned by the form 
is actually
+  // the beginning of the last period in the booking (it's more intuitive for 
users this way)
+  // so we need to add on 60 seconds (1 period)
+  if ($enable_periods)
   {
-    if (isset($ampm) && ($ampm == "pm") && ($hour<12))
-    {
-      $hour += 12;
-    }
-    if (isset($ampm) && ($ampm == "am") && ($hour>11))
-    {
-      $hour -= 12;
-    }
+    $endtime = $endtime + 60;
   }
 
-  $starttime = mktime($hour, $minute, 0,
-                      $month, $day, $year,
-                      is_dst($month, $day, $year, $hour));
-  $endtime   = mktime($hour, $minute, 0,
-                      $month, $day, $year,
-                      is_dst($month, $day, $year, $hour)) + $dur_seconds;
-
   // Round down the starttime and round up the endtime to the nearest slot 
boundaries                   
   $am7=mktime($morningstarts,$morningstarts_minutes,0,
               $month,$day,$year,is_dst($month,$day,$year,$morningstarts));
@@ -331,6 +299,8 @@
   // so that the email notifications report the adjusted duration
   // (We do this before we adjust for DST so that the user sees what they 
expect to see)
   $duration = $endtime - $starttime;
+  $date = getdate($starttime);
+  $period = ($date['hours'] - 12) * 60) + $date['minutes'];
   $enable_periods ? toPeriodString($period, $duration, $dur_units, FALSE) : 
toTimeString($duration, $dur_units, FALSE);
   
   // Adjust the endtime for DST
@@ -341,8 +311,7 @@
     isset($rep_end_month) && isset($rep_end_day) && isset($rep_end_year))
 {
   // Get the repeat entry settings
-  $rep_enddate = mktime($hour, $minute, 0,
-                        $rep_end_month, $rep_end_day, $rep_end_year);
+  $rep_enddate = $start_seconds + mktime(0, 0, 0, $rep_end_month, 
$rep_end_day, $rep_end_year);
 }
 else
 {
@@ -576,7 +545,6 @@
                                       $isprivate,
                                       $status,
                                       $custom_fields);
-
       // Send a mail to the Administrator
       if ($need_to_send_mail)
       {

Modified: mrbs/branches/from_to_bookings/web/lang.en
===================================================================
--- mrbs/branches/from_to_bookings/web/lang.en  2010-10-20 11:42:27 UTC (rev 
1517)
+++ mrbs/branches/from_to_bookings/web/lang.en  2010-10-20 15:20:18 UTC (rev 
1518)
@@ -52,6 +52,7 @@
 $vocab["fulldescription"]    = "Full Description:<br>&nbsp;&nbsp;(Number of 
people,<br>&nbsp;&nbsp;Internal/External etc)";
 $vocab["date"]               = "Date";
 $vocab["start"]              = "Start";
+$vocab["end"]                = "End";
 $vocab["start_date"]         = "Start Time";
 $vocab["end_date"]           = "End Time";
 $vocab["time"]               = "Time";

Modified: mrbs/branches/from_to_bookings/web/mrbs-ie.css
===================================================================
--- mrbs/branches/from_to_bookings/web/mrbs-ie.css      2010-10-20 11:42:27 UTC 
(rev 1517)
+++ mrbs/branches/from_to_bookings/web/mrbs-ie.css      2010-10-20 15:20:18 UTC 
(rev 1518)
@@ -24,7 +24,8 @@
 
 /* margin-bottom on some form controls does not work, so put it on the 
relevant divs instead */
 .form_general div#div_description, 
-.form_general div#div_date,
+.form_general div#div_start_date,
+.form_general div#div_end_date,
 .form_general div#div_period,
 .form_general div#div_areas,
 .form_general div#div_rooms,

Modified: mrbs/branches/from_to_bookings/web/mrbs.css.php
===================================================================
--- mrbs/branches/from_to_bookings/web/mrbs.css.php     2010-10-20 11:42:27 UTC 
(rev 1517)
+++ mrbs/branches/from_to_bookings/web/mrbs.css.php     2010-10-20 15:20:18 UTC 
(rev 1518)
@@ -522,7 +522,7 @@
 
 .form_general div {float: left; clear: left; width: 100%}
 .form_general div div {float: none; clear: none; width: auto}
-.form_general div.group {float: left; width: <?php echo 
$general_right_col_width ?>%}
+.form_general div.group {float: left}
 .form_general div.group.ampm {width: <?php echo $edit_entry_ampm_width ?>em}
 .edit_area_room div.group {clear: none; width: auto}
 .edit_area_room div.group#private_override div {clear: left}
@@ -594,7 +594,7 @@
 .form_general select#dur_units {margin-right: 1.0em; margin-left: 0.5em}
 .form_general div#ad {float: left}
 .form_general #ad label {clear: none; text-align: left; font-weight: normal}
-.form_general input#all_day {width: auto; margin-left: 1.0em; margin-right: 
0.5em}
+.form_general input#all_day {width: auto; margin-left: 3.0em; margin-right: 
0.5em}
 .form_general input#private {width: auto; margin-left: 3.0em; margin-right: 
0.5em}
 .form_general #div_rooms select, .form_general #div_typematch select {float: 
left; margin-right: 2.0em}
 fieldset#rep_info {border-top: 1px solid <?php echo 
$site_faq_entry_border_color ?>; padding-top: 0.7em}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to