Revision: 1693
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1693&view=rev
Author:   cimorrison
Date:     2010-12-11 17:25:30 +0000 (Sat, 11 Dec 2010)

Log Message:
-----------
AAdded the ability to download iCalendar files from the view_entry page

Modified Paths:
--------------
    mrbs/branches/ics_attachments/web/functions.inc
    mrbs/branches/ics_attachments/web/functions_ical.inc
    mrbs/branches/ics_attachments/web/functions_mail.inc
    mrbs/branches/ics_attachments/web/lang.en
    mrbs/branches/ics_attachments/web/mrbs.css.php
    mrbs/branches/ics_attachments/web/mrbs_sql.inc
    mrbs/branches/ics_attachments/web/view_entry.php

Modified: mrbs/branches/ics_attachments/web/functions.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions.inc     2010-12-10 11:05:56 UTC 
(rev 1692)
+++ mrbs/branches/ics_attachments/web/functions.inc     2010-12-11 17:25:30 UTC 
(rev 1693)
@@ -676,6 +676,27 @@
   return utf8_strftime("%A", mktime(0,0,0,1,2+$daynumber,2000));
 }
 
+// Returns a list of repeat days as a string (eg "Thursday Friday")
+//
+//    $rep_opt     an array of repeat days or
+//                 a string of repeat days that can be used as an array
+function get_rep_day_list($rep_opt)
+{
+  global $weekstarts;
+  
+  $rep_day_list = "";
+  for ($i = 0; $i < 7; $i++)
+  {
+    $daynum = ($i + $weekstarts) % 7;
+    if ($rep_opt[$daynum])
+    {
+      $rep_day_list .= day_name($daynum) . " ";
+    }
+  }
+  return $rep_day_list;
+}
+
+
 function hour_min_format()
 {
   global $twentyfourhour_format;
@@ -1742,6 +1763,7 @@
   echo "</div></td>\n";
 }
 
+
 // Generate a globally unique id
 //
 // We will generate a uid of the form "mrbs-uniqid-md5h...@domain_name" 

Modified: mrbs/branches/ics_attachments/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_ical.inc        2010-12-10 
11:05:56 UTC (rev 1692)
+++ mrbs/branches/ics_attachments/web/functions_ical.inc        2010-12-11 
17:25:30 UTC (rev 1693)
@@ -4,6 +4,7 @@
 
 
 define ('RFC5545_FORMAT', 'Ymd\THis');  // Format for expressing iCalendar 
dates
+define ('ICAL_EOL', "\r\n");            // Lines must be terminated by CRLF
 
 // "Folds" lines longer than 75 octets.  Multi-byte safe.
 //
@@ -131,25 +132,15 @@
 }
 
 
-// Creates an iCalendar object in RFC 5545 format
-function create_icalendar($method, $data, $text_description, 
$html_description, $addresses, $series=FALSE)
+// Create an RFC 5545 iCalendar Event component
+function create_ical_event($data, $text_description, $html_description, 
$addresses, $series=FALSE)
 {
-  require_once "version.inc";
-  
   global $timezone, $confirmation_enabled, $mail_settings;
-
-  $eol = "\r\n";
   
+  $use_html = $mail_settings['html'] && !empty($html_description);
+  
   $results = array();
-  $results[] = "BEGIN:VCALENDAR";
-  // Compulsory properties
-  $results[] = "PRODID:-//MRBS//NONSGML " . get_mrbs_version() . " //EN";
-  $results[] = "VERSION:2.0";
-  // Optional properties
-  $results[] = "CALSCALE:GREGORIAN";
-  $results[] = "METHOD:$method";
-  
-  // The event
+
   $results[] = "BEGIN:VEVENT";
   $results[] = "UID:" . $data['ical_uid'];  // compulsory
   $results[] = "DTSTAMP:" . gmdate(RFC5545_FORMAT . '\Z');  // compulsory
@@ -163,11 +154,14 @@
   // Put the HTML version in an ALTREP, just in case there are any Calendars 
out there
   // that support it (although at the time of writing, Dec 2010, none are 
known)
   $results[] = "DESCRIPTION" .
-               ((($mail_settings['html']) ? ";ALTREP=\"CID:" . 
$html_description['cid'] . "\"" : "") . ":" .
+               ((($use_html && !empty($html_description['cid'])) ? 
";ALTREP=\"CID:" . $html_description['cid'] . "\"" : "") . ":" .
                ical_escape_text($text_description['content']));
   // This is another way of getting an HTML description, used by Outlook.  
However it 
   // seems to be very limited
-  $results[] = "X-ALT-DESC;FMTTYPE=text/html:" . 
ical_escape_text($html_description['content']);
+  if ($use_html)
+  {
+    $results[] = "X-ALT-DESC;FMTTYPE=text/html:" . 
ical_escape_text($html_description['content']);
+  }
   $results[] = "LOCATION:" . ical_escape_text($data['area_name'] . " - " . 
$data['room_name']);
   $results[] = "SEQUENCE:" . $data['ical_sequence'];
   // If this is an individual member of a series then set the recurrence id
@@ -184,35 +178,66 @@
   // list as non particpants.   In theory the email client can then decide 
whether
   // to enter the booking automaticaly on the user's calendar - although at the
   // time of writing (Dec 2010) there don't seem to be any that do so!
-  $keys = array('to', 'cc');  // We won't do 'bcc' as they need to stay blind
-  foreach ($keys as $key)
+  if (!empty($addresses))
   {
-    if (!empty($addresses[$key]))
+    $keys = array('to', 'cc');  // We won't do 'bcc' as they need to stay blind
+    foreach ($keys as $key)
     {
-      $address_list = $addresses[$key];
-      $address_array = explode(',', $address_list);
-      foreach ($address_array as $address)
+      if (!empty($addresses[$key]))
       {
-        switch ($key)
+        $address_list = $addresses[$key];
+        $address_array = explode(',', $address_list);
+        foreach ($address_array as $address)
         {
-          case 'to':
-            $role = "REQ-PARTICIPANT";
-            break;
-          default:
-            $role = "NON-PARTICIPANT";
-            break;
+          switch ($key)
+          {
+            case 'to':
+              $role = "REQ-PARTICIPANT";
+              break;
+            default:
+              $role = "NON-PARTICIPANT";
+              break;
+          }
+          $results[] = "ATTENDEE;ROLE=$role:mailto:"; . trim($address);
         }
-        $results[] = "ATTENDEE;ROLE=$role:mailto:"; . trim($address);
       }
     }
   }
 
   $results[] = "END:VEVENT";
   
+  $result = implode(ICAL_EOL, $results);  // No CRLF at end: that will be 
added later
+
+  return $result;
+}
+
+
+// Creates an iCalendar object in RFC 5545 format
+//    $method      string   the RFC 5545 METHOD (eg "REQUEST", "PUBLISH", 
"CANCEL")
+//    $components  array    an array of iCalendar components, each a string  
+function create_icalendar($method, $components)
+{
+  require_once "version.inc";
+
+  $results = array();
+  $results[] = "BEGIN:VCALENDAR";
+  // Compulsory properties
+  $results[] = "PRODID:-//MRBS//NONSGML " . get_mrbs_version() . " //EN";
+  $results[] = "VERSION:2.0";
+  // Optional properties
+  $results[] = "CALSCALE:GREGORIAN";
+  $results[] = "METHOD:$method";
+  
+  // Add in each component
+  foreach ($components as $component)
+  {
+    $results[] = $component;
+  }
+
   $results[] = "END:VCALENDAR";
   
-  $result = implode($eol, $results);
-  $result .= $eol;  // Has to end with a CRLF
+  $result = implode(ICAL_EOL, $results);
+  $result .= ICAL_EOL;  // Has to end with a CRLF
   
   $result = ical_fold($result);
   return $result;

Modified: mrbs/branches/ics_attachments/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_mail.inc        2010-12-10 
11:05:56 UTC (rev 1692)
+++ mrbs/branches/ics_attachments/web/functions_mail.inc        2010-12-11 
17:25:30 UTC (rev 1693)
@@ -316,29 +316,12 @@
 }
 
 
-// Returns a list of repeat days as a string (eg "Thursday Friday")
-//
-//    $rep_opt     an array of repeat days or
-//                 a string of repeat days that can be used as an array
-function get_rep_day_list($rep_opt)
+// Create a row of a table in either plain text or HTML format.
+// Plain text:  returns "$label: $new\n"
+// HTML:        returns "<tr><td>$label: </td><td>$new</td></tr>\n"
+// If $compare is TRUE then a third column is output with $old in parentheses
+function create_body_table_row($label, $new, $old='', $compare=FALSE, 
$as_html=FALSE)
 {
-  global $weekstarts;
-  
-  $rep_day_list = "";
-  for ($i = 0; $i < 7; $i++)
-  {
-    $daynum = ($i + $weekstarts) % 7;
-    if ($rep_opt[$daynum])
-    {
-      $rep_day_list .= day_name($daynum) . " ";
-    }
-  }
-  return $rep_day_list;
-}
-        
-        
-function create_body_table_row($label, $new, $old, $compare, $as_html=FALSE)
-{
   $result  = ($as_html) ? "<tr>\n" : "";
   
   // The label
@@ -371,6 +354,7 @@
   return $result;
 }
 
+
 function create_body($data, $compare, $series, $action, $as_html=FALSE, 
$note='')
 {
   global $mail_previous, $returl, $mrbs_company;
@@ -836,8 +820,10 @@
   $attachment = array();
   if ($mail_settings['icalendar'] && !$enable_periods)
   {
+    $ical_components = array();
+    $ical_components[] = create_ical_event($data, $text_body, $html_body, 
$addresses, $series);
     $attachment['method']   = "REQUEST";
-    $attachment['content']  = create_icalendar($attachment['method'], $data, 
$text_body, $html_body, $addresses, $series);
+    $attachment['content']  = create_icalendar($attachment['method'], 
$ical_components);
     $attachment['name']     = $mail_settings['ics_filename'] . ".ics";
   }
 
@@ -905,9 +891,11 @@
   $attachment = array();
   if ($mail_settings['icalendar'] && !$enable_periods)
   {
+    $ical_components = array();
+    $ical_components[] = create_icalendar($data, $text_body, $html_body, 
$addresses, $series);
     $attachment['method']   = "CANCEL";
-    $attachment['content']  = create_icalendar($attachment['method'], $data, 
$text_body, $html_body, $addresses, $series);
-    $attachment['name']     = "meeting.ics";
+    $attachment['content']  = create_icalendar($attachment['method'], 
$ical_components);
+    $attachment['name']     = $mail_settings['ics_filename'] . ".ics";
   }
 
   $result = sendMail($addresses,

Modified: mrbs/branches/ics_attachments/web/lang.en
===================================================================
--- mrbs/branches/ics_attachments/web/lang.en   2010-12-10 11:05:56 UTC (rev 
1692)
+++ mrbs/branches/ics_attachments/web/lang.en   2010-12-11 17:25:30 UTC (rev 
1693)
@@ -117,6 +117,8 @@
 $vocab["lastupdate"]          = "Last Updated";
 $vocab["deleteentry"]         = "Delete Entry";
 $vocab["deleteseries"]        = "Delete Series";
+$vocab["downloadentry"]       = "Download Entry";
+$vocab["downloadseries"]      = "Download Series";
 $vocab["confirmdel"]          = "Are you sure\\nyou want to\\ndelete this 
entry?\\n\\n";
 $vocab["returnprev"]          = "Return to previous page";
 $vocab["invalid_entry_id"]    = "Invalid entry id.";

Modified: mrbs/branches/ics_attachments/web/mrbs.css.php
===================================================================
--- mrbs/branches/ics_attachments/web/mrbs.css.php      2010-12-10 11:05:56 UTC 
(rev 1692)
+++ mrbs/branches/ics_attachments/web/mrbs.css.php      2010-12-11 17:25:30 UTC 
(rev 1693)
@@ -810,6 +810,7 @@
 .view_entry div#view_entry_nav {margin-top: 1.0em}
 .view_entry #approve_buttons form {float: left; margin-right: 2em}
 .view_entry #approve_buttons legend {font-size: 0}
+.view_entry div#returl {margin-top: 1em}
 #approve_buttons td {vertical-align: middle; padding-top: 1em}
 #approve_buttons td#caption {text-align: left}
 #approve_buttons td#note {padding-top: 0}

Modified: mrbs/branches/ics_attachments/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/ics_attachments/web/mrbs_sql.inc      2010-12-10 11:05:56 UTC 
(rev 1692)
+++ mrbs/branches/ics_attachments/web/mrbs_sql.inc      2010-12-11 17:25:30 UTC 
(rev 1693)
@@ -796,12 +796,9 @@
   {
     switch ($field['name'])
     {
+      // repeat_id and entry_type only exist in the entry table
       case 'entry_type':
-        // Nothing to do
-        break;
-        
       case 'repeat_id':
-        // repeat_id only exists in the entry table
         array_push($terms, $field['name']);
         break;
 

Modified: mrbs/branches/ics_attachments/web/view_entry.php
===================================================================
--- mrbs/branches/ics_attachments/web/view_entry.php    2010-12-10 11:05:56 UTC 
(rev 1692)
+++ mrbs/branches/ics_attachments/web/view_entry.php    2010-12-11 17:25:30 UTC 
(rev 1693)
@@ -96,8 +96,139 @@
   echo "</td>\n";
   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, 
$standard_fields, $typel;
+  global $keep_private, $room_disabled, $area_disabled;
+  
+  $tbody = '';
+  $tbody .= "<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 .= "<span class=\"note\"> (" . get_vocab("disabled") . ")</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 .= "</tbody>\n";
+  
+  return $tbody;
+}
+
 // Get non-standard form variables
 //
 // If $series is TRUE, it means that the $id is the id of an 
@@ -118,81 +249,34 @@
 // or else if $auth['only_admin_can_book_repeat'] is not set
 $repeats_allowed = $is_admin || empty($auth['only_admin_can_book_repeat']);
 
-print_header($day, $month, $year, $area, isset($room) ? $room : "");
-
-
-// Need to tell all the links where to go back to after an edit or delete
-if (!isset($returl))
-{
-  if (isset($HTTP_REFERER))
-  {
-    $returl = $HTTP_REFERER;
-  }
-  // If we haven't got a referer (eg we've come here from an email) then 
construct
-  // a sensible place to go to afterwards
-  else
-  {
-    switch ($default_view)
-    {
-      case "month":
-        $returl = "month.php";
-        break;
-      case "week":
-        $returl = "week.php";
-        break;
-      default:
-        $returl = "day.php";
-    }
-    $returl .= "?year=$year&month=$month&day=$day&area=$area";
-  }
-}
-$link_returl = urlencode($returl);  // for use in links
-
-if (empty($series))
-{
-  $series = 0;
-}
-else
-{
-  $series = 1;
-}
-
 $row = mrbsGetBookingInfo($id, $series);
 
 // Get the area settings for the entry's area.   In particular we want
 // 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'];
+// Get the status
+$status = $row['status'];
 // Work out whether this event should be kept private
 $private = $row['status'] & STATUS_PRIVATE;
 $writeable = getWritable($row['create_by'], $user, $row['room_id']);
 $keep_private = (is_private_event($private) && !$writeable);
 $private_text = "[" . get_vocab("private") . "]";
+// Work out when the last reminder was sent
+$last_reminded = (empty($row['reminded'])) ? $row['last_updated'] : 
$row['reminded'];
 
-
-$custom_fields = array();
-foreach ($row as $column => $value)
+// Go throuh each of the columns and for each of them that can be made private
+// substitute the private text if the user is not allowed to see the data
+foreach ($row as $key => $value)
 {
-  switch ($column)
-  {
-    // Don't bother with these columns
-    case 'area_id':
-    case 'duration':
-    case 'repeat_id':
-    case 'reminded':
-    case 'rep_type':
-    case 'end_date':
-    case 'rep_opt':
-    case 'rep_num_weeks':
-    case 'start_time':
-    case 'end_time':
-      break;
-      
-    case 'room_disabled':
-    case 'area_disabled':
-      $$column = !empty($row[$column]);
-      break;
-      
+  // We could just test each column against $is_private_field["entry.$key"]
+  // but restricting the test to the columns below guards against the 
possibility
+  // that somebody has accidentally configured a 'system' field to be private
+  switch ($key)
+  { 
     case 'name':
     case 'description':
     case 'create_by':
@@ -206,61 +290,22 @@
     case 'repeat_info_time':
     case 'repeat_info_user':
     case 'repeat_info_text':
-      $$column = ($keep_private && $is_private_field["entry.$column"]) ? 
$private_text : $row[$column];
+      $row[$key] = ($keep_private && $is_private_field["entry.$key"]) ? 
$private_text : $row[$key];
       break;
       
-    case 'status':
-      $status = $row['status'];
-      $private = $row['status'] & STATUS_PRIVATE;
-      break;
-
-    case 'last_updated':
-      $updated = time_date_string($row['last_updated']);
-      break;
-
     default:
-      $custom_fields[$column] = ($keep_private && 
$is_private_field["entry.$column"]) ? $private_text : $row[$column];
+      if (!in_array($key, $standard_fields['entry']))
+      {
+        $row[$key] = ($keep_private && $is_private_field["entry.$key"]) ? 
$private_text : $row[$key];
+      }
       break;
   }
 }
 
-// Very special cases
-$last_reminded = (empty($row['reminded'])) ? $row['last_updated'] : 
$row['reminded'];
 
-// need to make DST correct in opposite direction to entry creation
-// so that user see what he expects to see
-$duration      = $row['duration'] - cross_dst($row['start_time'],
-                                              $row['end_time']);
-
-
-
-if ($enable_periods)
-{
-  list($start_period, $start_date) =  period_date_string($row['start_time']);
-}
-else
-{
-  $start_date = time_date_string($row['start_time']);
-}
-
-if ($enable_periods)
-{
-  list( , $end_date) =  period_date_string($row['end_time'], -1);
-}
-else
-{
-  $end_date = time_date_string($row['end_time']);
-}
-
-
-$rep_type = REP_NONE;
-
 if ($series == 1)
 {
-  $rep_type     = $row['rep_type'];
-  $rep_end_date = utf8_strftime('%A %d %B %Y',$row['end_date']);
-  $rep_opt      = $row['rep_opt'];
-  $rep_num_weeks = $row['rep_num_weeks'];
+  $repeat_id = $id;  // Save the repeat_id
   // I also need to set $id to the value of a single entry as it is a
   // single entry from a series that is used by del_entry.php and
   // edit_entry.php
@@ -271,72 +316,123 @@
           WHERE repeat_id=\"$id\" AND entry_type=\"1\"
           ORDER BY start_time
           LIMIT 1";
-  $res = sql_query($sql);
-  if (! $res)
+  $id = sql_query1($sql);
+  if ($id < 1)
   {
-    fatal_error(0, sql_error());
-  }
-  if (sql_count($res) < 1)
-  {
     // if all entries in series have been modified then
     // as a fallback position just select the first entry
     // in the series
     // hopefully this code will never be reached as
     // this page will display the start time of the series
     // but edit_entry.php will display the start time of the entry
-    sql_free($res);
     $sql = "SELECT id
             FROM $tbl_entry
             WHERE repeat_id=\"$id\"
             ORDER BY start_time
             LIMIT 1";
-    $res = sql_query($sql);
-    if (! $res)
-    {
-      fatal_error(0, sql_error());
-    }
+    $id = sql_query1($sql);
   }
-  $row = sql_row_keyed($res, 0);
-  $repeat_id = $id;  // Save the repeat_id
-  $id = $row['id'];
-  sql_free($res);
 }
 else
 {
   $repeat_id = $row['repeat_id'];
+}
 
-  if ($repeat_id != 0)
+
+// PHASE 2 - DOWNLOADING ICALENDAR FILES
+// -------------------------------------
+
+if (isset($action) && ($action == "download"))
+{
+  if ($keep_private)
   {
-    $res = sql_query("SELECT rep_type, end_date, rep_opt, rep_num_weeks
-                      FROM $tbl_repeat WHERE id=$repeat_id LIMIT 1");
-    if (! $res)
+    // should never normally be able to get here, but if we have then
+    // go somewhere safe.
+    header("Location: index.php");
+    exit;
+  }
+  else
+  {
+    require_once "functions_ical.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\"");
+    $text_body = array();
+    $text_body['content'] = create_details($row, FALSE);
+    $html_body = array();
+    $html_body['content'] = "<table>\n" . create_details($row, TRUE) . 
"</table>\n";
+    $addresses = array();
+    $ical_components = array();
+    $ical_components[] = create_ical_event($row, $text_body, $html_body, 
$addresses, $series);
+    // If it's a series we need to find out which of the individual entries 
have been changed
+    // and include them in the iCalendar object
+    if ($series)
     {
-      fatal_error(0, sql_error());
+      $sql = "SELECT id FROM $tbl_entry WHERE repeat_id=$repeat_id AND 
entry_type=2";
+      $res = sql_query($sql);
+      if ($res && (sql_count($res) > 0))
+      {
+        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";
+          $ical_components[] = create_ical_event($data, $text_body, 
$html_body, $addresses, FALSE);
+        }
+      }
     }
+    $icalendar = create_icalendar("REQUEST", $ical_components);
+    echo $icalendar;
+    exit;
+  }
+}
 
-    if (sql_count($res) == 1)
-    {
-      $row = sql_row_keyed($res, 0);
+// PHASE 1 - VIEW THE ENTRY
+// ------------------------
 
-      $rep_type     = $row['rep_type'];
-      $rep_end_date = utf8_strftime('%A %d %B %Y',$row['end_date']);
-      $rep_opt      = $row['rep_opt'];
-      $rep_num_weeks = $row['rep_num_weeks'];
+print_header($day, $month, $year, $area, isset($room) ? $room : "");
+
+
+// Need to tell all the links where to go back to after an edit or delete
+if (!isset($returl))
+{
+  if (isset($HTTP_REFERER))
+  {
+    $returl = $HTTP_REFERER;
+  }
+  // If we haven't got a referer (eg we've come here from an email) then 
construct
+  // a sensible place to go to afterwards
+  else
+  {
+    switch ($default_view)
+    {
+      case "month":
+        $returl = "month.php";
+        break;
+      case "week":
+        $returl = "week.php";
+        break;
+      default:
+        $returl = "day.php";
     }
-    sql_free($res);
+    $returl .= "?year=$year&month=$month&day=$day&area=$area";
   }
 }
+$link_returl = urlencode($returl);  // for use in links
 
+if (empty($series))
+{
+  $series = 0;
+}
+else
+{
+  $series = 1;
+}
 
-$enable_periods ? toPeriodString($start_period, $duration, $dur_units) : 
toTimeString($duration, $dur_units);
 
-$repeat_key = "rep_type_" . $rep_type;
-
 // Now that we know all the data we start drawing it
 
-
 echo "<h3" . (($keep_private && $is_private_field['entry.name']) ? " 
class=\"private\"" : "") . ">\n";
-echo htmlspecialchars($name);
+echo htmlspecialchars($row['name']);
 if (is_private_event($private) && $writeable) 
 {
   echo ' ('.get_vocab("private").')';
@@ -429,139 +525,10 @@
   }
   echo "</tfoot>\n";
 }
-?>
 
-<tbody>
-  <tr>
-    <td><?php echo get_vocab("description") ?>:</td>
-    <?php
-    echo "<td" . (($keep_private & $is_private_field['entry.description']) ? " 
class=\"private\"" : "") . ">" . mrbs_nl2br(htmlspecialchars($description)) . 
"</td>\n";
-    ?>
-  </tr>
-  <?php
-  if ($confirmation_enabled)
-  {
-    echo "<tr>\n";
-    echo "<td>" . get_vocab("confirmation_status") . ":</td>\n";
-    echo "<td>" . (($status & STATUS_TENTATIVE) ? get_vocab("tentative") : 
get_vocab("confirmed")) . "</td>\n";
-    echo "</tr>\n";
-  }
-  if ($approval_enabled)
-  {
-    echo "<tr>\n";
-    echo "<td>" . get_vocab("approval_status") . ":</td>\n";
-    echo "<td>" . (($status & STATUS_AWAITING_APPROVAL) ? 
get_vocab("awaiting_approval") : get_vocab("approved")) . "</td>\n";
-    echo "</tr>\n";
-  }
-  ?>
-  <tr>
-    <td><?php echo get_vocab("room") ?>:</td>
-    <?php
-    echo "<td>";
-    echo  mrbs_nl2br(htmlspecialchars($area_name . " - " . $room_name));
-    if ($room_disabled || $area_disabled)
-    {
-      echo "<span class=\"note\"> (" . get_vocab("disabled") . ")</span>";
-    }
-    echo "</td>\n";
-    ?>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("start_date") ?>:</td>
-    <td><?php echo $start_date ?></td>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("duration") ?>:</td>
-    <td><?php echo $duration . " " . $dur_units ?></td>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("end_date") ?>:</td>
-    <td><?php echo $end_date ?></td>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("type") ?>:</td>
-    <td><?php echo empty($typel[$type]) ? "?$type?" : $typel[$type] ?></td>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("createdby") ?>:</td>
-    <?php
-    echo "<td" . (($keep_private && $is_private_field['entry.create_by']) ? " 
class=\"private\"" : "") . ">" . htmlspecialchars($create_by) . "</td>\n";
-    ?>
-  </tr>
-  <tr>
-    <td><?php echo get_vocab("lastupdate") ?>:</td>
-    <td><?php echo $updated ?></td>
-  </tr>
-  <?php
-  // The custom fields
-  $fields = sql_field_info($tbl_entry);
-  foreach ($fields as $field)
-  {
-    $key = $field['name'];
-    if (!in_array($key, $standard_fields['entry']))
-    {
-      echo "<tr>\n";
-      echo "<td>" . get_loc_field_name($tbl_entry, $key) . ":</td>\n";
-      // 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"])
-        {
-          $shown_value = $custom_fields[$key];  // Will have been set 
previously
-        }
-        else
-        {
-          $shown_value = empty($custom_fields[$key]) ? get_vocab("no") : 
get_vocab("yes");
-        }
-      }
-      // Otherwise output a string
-      else
-      {
-        $shown_value = (isset($custom_fields[$key])) ? 
mrbs_nl2br(htmlspecialchars($custom_fields[$key])): "&nbsp;"; 
-      }
-      echo "<td" . (($keep_private && $is_private_field["entry.$key"]) ? " 
class=\"private\"" : "") . ">$shown_value</td>\n";
-      echo "</tr>\n";
-    }
-  }
-  ?>
-  <tr>
-    <td><?php echo get_vocab("rep_type") ?>:</td>
-    <td><?php echo get_vocab($repeat_key) ?></td>
-  </tr>
-<?php
+echo create_details($row, TRUE);
 
-if($rep_type != REP_NONE)
-{
-  $opt = "";
-  if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
-  {
-    // Display day names according to language and preferred weekday start.
-    for ($i = 0; $i < 7; $i++)
-    {
-      $daynum = ($i + $weekstarts) % 7;
-      if ($rep_opt[$daynum])
-      {
-        $opt .= day_name($daynum) . " ";
-      }
-    }
-  }
-  if ($rep_type == REP_N_WEEKLY)
-  {
-    echo "<tr><td>".get_vocab("rep_num_weeks")." 
".get_vocab("rep_for_nweekly").":</td><td>$rep_num_weeks</td></tr>\n";
-  }
-
-  if ($opt)
-  {
-    echo "<tr><td>".get_vocab("rep_rep_day").":</td><td>$opt</td></tr>\n";
-  }
-
-  echo 
"<tr><td>".get_vocab("rep_end_date").":</td><td>$rep_end_date</td></tr>\n";
-}
-
 ?>
-</tbody>
 </table>
 
 <div id="view_entry_nav">
@@ -619,8 +586,29 @@
     echo "<a 
href=\"edit_entry.php?id=$id&amp;edit_type=series&amp;day=$day&amp;month=$month&amp;year=$year&amp;copy=1&amp;returl=$link_returl\">".get_vocab("copyseries")."</a>";
   }
   echo "</div>\n";
+  
+  // Download and Download Series
+  if (!$keep_private)
+  {
+    // The iCalendar information has the full booking details in it, so we 
will not allow
+    // it to be downloaded if it is private and the user is not authorised to 
see it.
+    echo "<div>\n";
+    if (!$series)
+    {
+      echo "<a 
href=\"view_entry.php?action=download&amp;id=$id&amp;returl=$link_returl\">". 
get_vocab("downloadentry") ."</a>";
+    } 
+    if (!empty($repeat_id)  && !$series)
+    {
+      echo " - ";
+    }  
+    if (!empty($repeat_id) || $series)
+    {
+      echo "<a 
href=\"view_entry.php?action=download&amp;id=$repeat_id&amp;series=1&amp;day=$day&amp;month=$month&amp;year=$year&amp;returl=$link_returl\">".get_vocab("downloadseries")."</a>";
+    }
+    echo "</div>\n";
+  }
   ?>
-  <div>
+  <div id="returl">
     <?php
     if (isset($HTTP_REFERER)) //remove the link if displayed from an email
     {


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

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to