Revision: 1720
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1720&view=rev
Author:   cimorrison
Date:     2010-12-20 23:17:33 +0000 (Mon, 20 Dec 2010)

Log Message:
-----------
Added full details to reports exported as iCalendars

Modified Paths:
--------------
    mrbs/branches/ics_attachments/web/functions.inc
    mrbs/branches/ics_attachments/web/mrbs_sql.inc
    mrbs/branches/ics_attachments/web/report.php
    mrbs/branches/ics_attachments/web/view_entry.php

Added Paths:
-----------
    mrbs/branches/ics_attachments/web/functions_view.inc

Modified: mrbs/branches/ics_attachments/web/functions.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions.inc     2010-12-20 16:29:47 UTC 
(rev 1719)
+++ mrbs/branches/ics_attachments/web/functions.inc     2010-12-20 23:17:33 UTC 
(rev 1720)
@@ -293,6 +293,38 @@
 }
 
 
+// Get the duration of an interval given a start time and end time.  Corrects 
for
+// DST changes so that the duration is what the user would expect to see.  For
+// example 12 noon to 12 noon crossing a DST boundary is 24 hours.
+//
+// Returns an array indexed by 'duration' and 'dur_units'
+//
+//    $start_time   int     start time as a Unix timestamp
+//    $end_time     int     end time as a Unix timestamp
+//    $translate    boolean whether to translate into the browser language
+function get_duration($start_time, $end_time, $translate=TRUE)
+{
+  global $enable_periods;
+  
+  $result = array();
+  $result['duration'] = $end_time - $start_time;
+  // Need to make DST correct in opposite direction to entry creation
+  // so that user see what he expects to see
+  $result['duration'] -= cross_dst($start_time, $end_time);
+  if ($enable_periods)
+  {
+    $time = getdate($start_time);
+    $start_period = $time['minutes'];
+    toPeriodString($start_period, $result['duration'], $result['dur_units'], 
$translate);
+  }
+  else
+  {
+    toTimeString($result['duration'], $result['dur_units'], $translate);
+  }
+  return $result;
+}
+
+
 // Generate an input field with an associated label
 // Optional fifth parameter: $maxlength - the maximum length of input allowed
 function generate_input($label_text, $name, $value, $disabled=FALSE)

Added: mrbs/branches/ics_attachments/web/functions_view.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_view.inc                        
        (rev 0)
+++ mrbs/branches/ics_attachments/web/functions_view.inc        2010-12-20 
23:17:33 UTC (rev 1720)
@@ -0,0 +1,167 @@
+<?php
+
+// $Id$
+
+// Returns a string containg a single line of data details, or if $as_html is 
set
+// a table row of details.   The first column is the $label and the second 
column
+// the $value.   $class is an optional class name which can be applied to the 
+// second column.
+function create_details_row($label, $value, $as_html=FALSE, $class='')
+{
+  $result = '';
+  if ($as_html)
+  {
+    $result .= "<tr>\n";
+    $result .= "<td>$label:</td>\n";
+    $result .= "<td" .
+               ((!empty($class)) ? " class=\"$class\"" : "") .
+               ">" . mrbs_nl2br(htmlspecialchars($value)) . "</td>\n";
+    $result .= "</tr>\n";
+  }
+  else
+  {
+    // Some of the vocab strings contain &nbsp;
+    $result .= str_replace('&nbsp;', ' ', $label) . ": $value\n";
+  }
+  return $result;
+}
+
+
+// Returns a string containg a set of details for $data consisting of a 
label/value
+// pair for each data element in the array $data.   If $as_html is TRUE then 
the string
+// is the HTML for a table body, ie looks like "<tbody> ... </tbody>".
+//    $keep_private   boolean   if TRUE then any private fields will be given 
the class 'private';
+//                              note that $data must already have had values 
substituted
+//                              for private fields
+//    $room_disabled  boolean   if TRUE then a note will be added that the 
room is disabled
+function create_details_body($data, $as_html=FALSE, $keep_private=FALSE, 
$room_disabled=FALSE)
+{
+  global $enable_periods, $confirmation_enabled, $approval_enabled;
+  global $is_private_field, $standard_fields, $typel;
+  
+  // Get the duration if we haven't got it already
+  if (!isset($data['duration']))
+  {
+    // We will translate the units later
+    $d = get_duration($data['start_time'], $data['end_time'], FALSE);
+    $data['duration'] = $d['duration'];
+    $data['dur_units'] = $d['dur_units'];
+  }
+  
+  // Set a rep_type if it hasn't been
+  if (!isset($data['rep_type']))
+  {
+    $data['rep_type'] = REP_NONE;
+  }
+  
+  $tbody = '';
+  $tbody .= ($as_html) ? "<tbody>\n" : "";
+  // Description
+  $class = ($keep_private & $is_private_field['entry.description']) ? 
"private" : "";
+  $tbody .= create_details_row(get_vocab("description"), $data['description'], 
$as_html, $class);
+  // Confirmation status
+  if ($confirmation_enabled)
+  {
+    $value = ($data['status'] & STATUS_TENTATIVE) ? get_vocab("tentative") : 
get_vocab("confirmed");
+    $tbody .= create_details_row(get_vocab("confirmation_status"), $value, 
$as_html);
+  }
+  // Approval status
+  if ($approval_enabled)
+  {
+    $value = ($data['status'] & STATUS_AWAITING_APPROVAL) ? 
get_vocab("awaiting_approval") : get_vocab("approved");
+    $tbody .= create_details_row(get_vocab("approval_status"), $value, 
$as_html);
+  }
+  // Room
+  $value = $data['area_name'] . " - " . $data['room_name'];
+  if ($room_disabled)
+  {
+    $value .= ($as_html) ? "<span class=\"note\">" : "";
+    $value .= " (" . get_vocab("disabled") . ")";
+    $value .= ($as_html) ? "</span>" : "";
+  }
+  $tbody .= create_details_row(get_vocab("room"), $value, $as_html);
+  // Start date
+  if ($enable_periods)
+  {
+    list($start_period, $start_date) =  
period_date_string($data['start_time']);
+  }
+  else
+  {
+    $start_date = time_date_string($data['start_time']);
+  }
+  $tbody .= create_details_row(get_vocab("start_date"), $start_date, $as_html);
+  // Duration
+  $tbody .= create_details_row(get_vocab("duration"), $data['duration'] . " " 
. get_vocab($data['dur_units']), $as_html);
+  // End date
+  if ($enable_periods)
+  {
+    list( , $end_date) =  period_date_string($data['end_time'], -1);
+  }
+  else
+  {
+    $end_date = time_date_string($data['end_time']);
+  }
+  $tbody .= create_details_row(get_vocab("end_date"), $end_date, $as_html);
+  // Type
+  $value = (empty($typel[$data['type']])) ? "?${data['type']}?" : 
$typel[$data['type']];
+  $tbody .= create_details_row(get_vocab("type"), $value, $as_html);
+  // Created by
+  $class = ($keep_private && $is_private_field['entry.create_by']) ? "private" 
: "";
+  $tbody .= create_details_row(get_vocab("createdby"), $data['create_by'], 
$as_html, $class);
+  // Last updated
+  $tbody .= create_details_row(get_vocab("lastupdate"), 
time_date_string($data['last_updated']), $as_html);
+  // The custom fields
+  $fields = sql_field_info($tbl_entry);
+  foreach ($fields as $field)
+  {
+    $key = $field['name'];
+    if (!in_array($key, $standard_fields['entry']))
+    {
+      $label = get_loc_field_name($tbl_entry, $key);
+      // Output a yes/no if it's a boolean or integer <= 2 bytes (which we will
+      // assume are intended to be booleans)
+      if (($field['nature'] == 'boolean') || 
+          (($field['nature'] == 'integer') && isset($field['length']) && 
($field['length'] <= 2)) )
+      {
+        if ($keep_private && $is_private_field["entry.$key"])
+        {
+          $value = $data[$key];  // Will have been set previously
+        }
+        else
+        {
+          $value = empty($data[$key]) ? get_vocab("no") : get_vocab("yes");
+        }
+      }
+      // Otherwise output a string
+      else
+      {
+        $value = (isset($data[$key])) ? $data[$key] : "&nbsp;"; 
+      }
+      $class = ($keep_private && $is_private_field["entry.$key"]) ? "private" 
: "";
+      $tbody .= create_details_row($label, $value, $as_html, $class);
+    }
+  }
+  // Repeat type
+  $tbody .= create_details_row(get_vocab("rep_type"), get_vocab("rep_type_" . 
$data['rep_type']), $as_html);
+  // Repeat details
+  if($data['rep_type'] != REP_NONE)
+  {
+    if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] == 
REP_N_WEEKLY))
+    {
+      if ($data['rep_type'] == REP_N_WEEKLY)
+      {
+        // Repeat number of weeks
+        $tbody .= create_details_row(get_vocab("rep_num_weeks")." 
".get_vocab("rep_for_nweekly"), $data['rep_num_weeks'], $as_html);
+      }
+      // Repeat days
+      $tbody .= create_details_row(get_vocab("rep_rep_day"), 
get_rep_day_list($data['rep_opt']), $as_html);
+    }
+    // Repeat end date
+    $tbody .= create_details_row(get_vocab("rep_end_date"), utf8_strftime('%A 
%d %B %Y',$data['end_date']), $as_html);
+  }
+  $tbody .= ($as_html) ? "</tbody>\n" : "";
+  
+  return $tbody;
+}
+
+?>
\ No newline at end of file


Property changes on: mrbs/branches/ics_attachments/web/functions_view.inc
___________________________________________________________________
Added: svn:mime-type
   + text/x-php
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: mrbs/branches/ics_attachments/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/ics_attachments/web/mrbs_sql.inc      2010-12-20 16:29:47 UTC 
(rev 1719)
+++ mrbs/branches/ics_attachments/web/mrbs_sql.inc      2010-12-20 23:17:33 UTC 
(rev 1720)
@@ -878,22 +878,12 @@
   $row = sql_row_keyed($res, 0);
   sql_free($res);
   
-  // Now get the start time, end time and duration.
-  // Need to make DST correct in opposite direction to entry creation
-  // so that user see what he expects to see
-  $row['duration'] -= cross_dst($row['start_time'], $row['end_time']);
+  // Now get the duration.
   // Don't translate the units at this stage.   We'll translate them later.
-  if ($enable_periods)
-  {
-    $time = getdate($row['start_time']);
-    $start_period = $time['minutes'];
-    toPeriodString($start_period, $row['duration'], $row['dur_units'], FALSE);
-  }
-  else
-  {
-    toTimeString($row['duration'], $row['dur_units'], FALSE);
-  }
-  
+  $d = get_duration($row['start_time'], $row['end_time'], FALSE);
+  $row['duration'] = $d['duration'];
+  $row['dur_units'] = $d['dur_units'];
+    
   // Get some extra information
   if ($series)
   {

Modified: mrbs/branches/ics_attachments/web/report.php
===================================================================
--- mrbs/branches/ics_attachments/web/report.php        2010-12-20 16:29:47 UTC 
(rev 1719)
+++ mrbs/branches/ics_attachments/web/report.php        2010-12-20 23:17:33 UTC 
(rev 1720)
@@ -730,6 +730,7 @@
 elseif ($output_as_ical)
 {
   require_once "functions_ical.inc";
+  require_once "functions_view.inc";
   header("Content-Type: application/ics;  charset=" . get_charset(). "; 
name=\"" . $mail_settings['ics_filename'] . ".ics\"");
   header("Content-Disposition: attachment; filename=\"" . 
$mail_settings['ics_filename'] . ".ics\"");
 }
@@ -1291,7 +1292,8 @@
           // If this is an individual entry, then construct an event
           if ($row['repeat_id'] == 0)
           {
-            $text_body['content'] = $row['description'];
+            $text_body['content'] = create_details_body($row, FALSE);
+            $html_body['content'] = create_details_body($row, TRUE);
             $ical_events[] = create_ical_event("REQUEST", $row, $text_body, 
$html_body, NULL, FALSE);
           }
           // Otherwise it's a series
@@ -1324,13 +1326,15 @@
                 // the current length of the array.
                 $replace_index = count($ical_events);
               }
-              $text_body['content'] = $start_row['description'];
+              $text_body['content'] = create_details_body($start_row, FALSE);
+              $html_body['content'] = create_details_body($start_row, TRUE);
               $ical_events[] = create_ical_event("REQUEST", $start_row, 
$text_body, $html_body, NULL, TRUE);
             }
             // And if it's a series member that has been altered
             if ($row['entry_type'] == ENTRY_RPT_CHANGED)
             {
-              $text_body['content'] = $row['description'];
+              $text_body['content'] = create_details_body($row, FALSE);
+              $html_body['content'] = create_details_body($row, TRUE);
               $ical_events[] = create_ical_event("REQUEST", $row, $text_body, 
$html_body, NULL, FALSE);
             }
             // Otherwise it must be an original member, in which case check
@@ -1345,7 +1349,8 @@
               $row['start_time'] = $start_row['start_time'];
               $row['end_time'] = $row['start_time'] + $duration;
               $row['end_date'] = $report_end;
-              $text_body['content'] = $row['description'];
+              $text_body['content'] = create_details_body($row, FALSE);
+              $html_body['content'] = create_details_body($row, TRUE);
               $ical_events[$replace_index] = create_ical_event("REQUEST", 
$row, $text_body, $html_body, NULL, TRUE);
               // Clear the $replace_index now that we've found an original 
entry
               unset ($replace_index);

Modified: mrbs/branches/ics_attachments/web/view_entry.php
===================================================================
--- mrbs/branches/ics_attachments/web/view_entry.php    2010-12-20 16:29:47 UTC 
(rev 1719)
+++ mrbs/branches/ics_attachments/web/view_entry.php    2010-12-20 23:17:33 UTC 
(rev 1720)
@@ -3,6 +3,7 @@
 
 require_once "defaultincludes.inc";
 require_once "mrbs_sql.inc";
+require_once "functions_view.inc";
 
 // Generates a single button
 function generateButton($form_action, $id, $series, $action_type, $returl, 
$submit_value, $title='')
@@ -97,141 +98,7 @@
   echo "<tr>\n";
 }
 
-function create_details_row($label, $value, $as_html=FALSE, $class='')
-{
-  $result = '';
-  if ($as_html)
-  {
-    $result .= "<tr>\n";
-    $result .= "<td>$label:</td>\n";
-    $result .= "<td" .
-               ((!empty($class)) ? " class=\"$class\"" : "") .
-               ">" . mrbs_nl2br(htmlspecialchars($value)) . "</td>\n";
-    $result .= "</tr>\n";
-  }
-  else
-  {
-    $result .= "$label: $value\n";
-  }
-  return $result;
-}
 
-function create_details($data, $as_html=FALSE)
-{
-  global $enable_periods, $confirmation_enabled, $approval_enabled;
-  global $is_private_field, $standard_fields, $typel;
-  global $keep_private, $room_disabled, $area_disabled;
-  
-  $tbody = '';
-  $tbody .= ($as_html) ? "<tbody>\n" : "";
-  // Description
-  $class = ($keep_private & $is_private_field['entry.description']) ? 
"private" : "";
-  $tbody .= create_details_row(get_vocab("description"), $data['description'], 
$as_html, $class);
-  // Confirmation status
-  if ($confirmation_enabled)
-  {
-    $value = ($data['status'] & STATUS_TENTATIVE) ? get_vocab("tentative") : 
get_vocab("confirmed");
-    $tbody .= create_details_row(get_vocab("confirmation_status"), $value, 
$as_html);
-  }
-  // Approval status
-  if ($approval_enabled)
-  {
-    $value = ($data['status'] & STATUS_AWAITING_APPROVAL) ? 
get_vocab("awaiting_approval") : get_vocab("approved");
-    $tbody .= create_details_row(get_vocab("approval_status"), $value, 
$as_html);
-  }
-  // Room
-  $value = $data['area_name'] . " - " . $data['room_name'];
-  if ($room_disabled || $area_disabled)
-  {
-    $value .= ($as_html) ? "<span class=\"note\">" : "";
-    $value .= " (" . get_vocab("disabled") . ")";
-    $value .= ($as_html) ? "</span>" : "";
-  }
-  $tbody .= create_details_row(get_vocab("room"), $value, $as_html);
-  // Start date
-  if ($enable_periods)
-  {
-    list($start_period, $start_date) =  
period_date_string($data['start_time']);
-  }
-  else
-  {
-    $start_date = time_date_string($data['start_time']);
-  }
-  $tbody .= create_details_row(get_vocab("start_date"), $start_date, $as_html);
-  // Duration
-  $tbody .= create_details_row(get_vocab("duration"), $data['duration'] . " " 
. $data['dur_units'], $as_html);
-  // End date
-  if ($enable_periods)
-  {
-    list( , $end_date) =  period_date_string($data['end_time'], -1);
-  }
-  else
-  {
-    $end_date = time_date_string($data['end_time']);
-  }
-  $tbody .= create_details_row(get_vocab("end_date"), $end_date, $as_html);
-  // Type
-  $value = (empty($typel[$data['type']])) ? "?${data['type']}?" : 
$typel[$data['type']];
-  $tbody .= create_details_row(get_vocab("type"), $value, $as_html);
-  // Created by
-  $class = ($keep_private && $is_private_field['entry.create_by']) ? "private" 
: "";
-  $tbody .= create_details_row(get_vocab("createdby"), $data['create_by'], 
$as_html, $class);
-  // Last updated
-  $tbody .= create_details_row(get_vocab("lastupdate"), 
time_date_string($data['last_updated']), $as_html);
-  // The custom fields
-  $fields = sql_field_info($tbl_entry);
-  foreach ($fields as $field)
-  {
-    $key = $field['name'];
-    if (!in_array($key, $standard_fields['entry']))
-    {
-      $label = get_loc_field_name($tbl_entry, $key);
-      // Output a yes/no if it's a boolean or integer <= 2 bytes (which we will
-      // assume are intended to be booleans)
-      if (($field['nature'] == 'boolean') || 
-          (($field['nature'] == 'integer') && isset($field['length']) && 
($field['length'] <= 2)) )
-      {
-        if ($keep_private && $is_private_field["entry.$key"])
-        {
-          $value = $data[$key];  // Will have been set previously
-        }
-        else
-        {
-          $value = empty($data[$key]) ? get_vocab("no") : get_vocab("yes");
-        }
-      }
-      // Otherwise output a string
-      else
-      {
-        $value = (isset($data[$key])) ? $data[$key] : "&nbsp;"; 
-      }
-      $class = ($keep_private && $is_private_field["entry.$key"]) ? "private" 
: "";
-      $tbody .= create_details_row($label, $value, $as_html, $class);
-    }
-  }
-  // Repeat type
-  $tbody .= create_details_row(get_vocab("rep_type"), get_vocab("rep_type_" . 
$data['rep_type']), $as_html);
-  // Repeat details
-  if($data['rep_type'] != REP_NONE)
-  {
-    if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] == 
REP_N_WEEKLY))
-    {
-      if ($data['rep_type'] == REP_N_WEEKLY)
-      {
-        // Repeat number of weeks
-        $tbody .= create_details_row(get_vocab("rep_num_weeks")." 
".get_vocab("rep_for_nweekly"), $data['rep_num_weeks'], $as_html);
-      }
-      // Repeat days
-      $tbody .= create_details_row(get_vocab("rep_rep_day"), 
get_rep_day_list($data['rep_opt']), $as_html);
-    }
-    // Repeat end date
-    $tbody .= create_details_row(get_vocab("rep_end_date"), utf8_strftime('%A 
%d %B %Y',$data['end_date']), $as_html);
-  }
-  $tbody .= ($as_html) ? "</tbody>\n" : "";
-  
-  return $tbody;
-}
-
 // Get non-standard form variables
 //
 // If $series is TRUE, it means that the $id is the id of an 
@@ -258,9 +125,8 @@
 // to know how to display private/public bookings in this area.
 get_area_settings($row['area_id']);
 
-// Work out whether the room and area are disabled
-$room_disabled = $row['room_disabled'];
-$area_disabled = $row['area_disabled'];
+// Work out whether the room or area is disabled
+$room_disabled = $row['room_disabled'] || $row['area_disabled'];
 // Get the status
 $status = $row['status'];
 // Work out whether this event should be kept private
@@ -360,9 +226,9 @@
     header("Content-Type: application/ics;  charset=" . get_charset(). "; 
name=\"" . $mail_settings['ics_filename'] . ".ics\"");
     header("Content-Disposition: attachment; filename=\"" . 
$mail_settings['ics_filename'] . ".ics\"");
     $text_body = array();
-    $text_body['content'] = create_details($row, FALSE);
+    $text_body['content'] = create_details_body($row, FALSE, $keep_private, 
$room_disabled);
     $html_body = array();
-    $html_body['content'] = "<table>\n" . create_details($row, TRUE) . 
"</table>\n";
+    $html_body['content'] = "<table>\n" . create_details_body($row, TRUE, 
$keep_private, $room_disabled) . "</table>\n";
     $addresses = array();
     $ical_components = array();
     $ical_components[] = create_ical_event("REQUEST", $row, $text_body, 
$html_body, $addresses, $series);
@@ -377,8 +243,8 @@
         for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
         {
           $data = mrbsGetBookingInfo($row['id'], FALSE);
-          $text_body['content'] = create_details($data, FALSE);
-          $html_body['content'] = "<table>\n" . create_details($data, TRUE) . 
"</table>\n";
+          $text_body['content'] = create_details_body($data, FALSE, 
$keep_private, $room_disabled);
+          $html_body['content'] = "<table>\n" . create_details_body($data, 
TRUE, $keep_private, $room_disabled) . "</table>\n";
           $ical_components[] = create_ical_event("REQUEST", $data, $text_body, 
$html_body, $addresses, FALSE);
         }
       }
@@ -453,8 +319,7 @@
 
 // If bookings require approval, and the room is enabled, put the buttons
 // to do with managing the bookings in the footer
-if ($approval_enabled && !$room_disabled &&!$area_disabled &&
-    ($status & STATUS_AWAITING_APPROVAL))
+if ($approval_enabled && !$room_disabled && ($status & 
STATUS_AWAITING_APPROVAL))
 {
   echo "<tfoot id=\"approve_buttons\">\n";
   // PHASE 2 - REJECT
@@ -529,7 +394,7 @@
   echo "</tfoot>\n";
 }
 
-echo create_details($row, TRUE);
+echo create_details_body($row, TRUE, $keep_private, $room_disabled);
 
 ?>
 </table>
@@ -539,7 +404,7 @@
   // Only show the links for Edit and Delete if the room is enabled.    We're
   // allowed to view and copy existing bookings in disabled rooms, but not to
   // modify or delete them.
-  if (!$room_disabled && !$area_disabled)
+  if (!$room_disabled)
   {
     // Edit and Edit Series
     echo "<div>\n";


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

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to