Revision: 1054
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1054&view=rev
Author:   dceschools
Date:     2009-03-18 21:56:42 +0000 (Wed, 18 Mar 2009)

Log Message:
-----------
Added ability to create private bookings.  If enabled, entries can be hidden 
from other non-admin users.  See config file to enable this feature and for 
options.

Modified Paths:
--------------
    mrbs/trunk/web/Themes/classic126.inc
    mrbs/trunk/web/Themes/default.inc
    mrbs/trunk/web/config.inc.php
    mrbs/trunk/web/day.php
    mrbs/trunk/web/dbsys.inc
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/edit_entry_handler.php
    mrbs/trunk/web/functions.inc
    mrbs/trunk/web/lang.en
    mrbs/trunk/web/month.php
    mrbs/trunk/web/mrbs.css.php
    mrbs/trunk/web/mrbs_sql.inc
    mrbs/trunk/web/report.php
    mrbs/trunk/web/search.php
    mrbs/trunk/web/view_entry.php
    mrbs/trunk/web/week.php

Added Paths:
-----------
    mrbs/trunk/web/upgrade/3/
    mrbs/trunk/web/upgrade/3/mysql.sql
    mrbs/trunk/web/upgrade/3/pgsql.sql

Modified: mrbs/trunk/web/Themes/classic126.inc
===================================================================
--- mrbs/trunk/web/Themes/classic126.inc        2009-03-18 20:38:36 UTC (rev 
1053)
+++ mrbs/trunk/web/Themes/classic126.inc        2009-03-18 21:56:42 UTC (rev 
1054)
@@ -85,9 +85,18 @@
     'G' => "#FF6666",
     'H' => "#66FFFF",
     'I' => "#DDFFDD",
-    'J' => "#CCCCCC");
+    'J' => "#CCCCCC",
+    'PA' => "#D0A8D0", // PA-PJ are "Private" entry colors for A-J
+    'PB' => "#85b3b3",
+    'PC' => "#f08f8f",
+    'PD' => "#e6e38a",
+    'PE' => "#b2c8ed",
+    'PF' => "#e1ad7a",
+    'PG' => "#dc5959",
+    'PH' => "#50c6ce",
+    'PI' => "#aedeae",
+    'PJ' => "#959595"); 
 
-
 // ***** DIMENSIONS *******************
 $banner_border_width          = '1';  // (px)  border width for the outside of 
the banner
 $banner_border_cell_width     = '1';  // (px)  border width for the cells of 
the banner

Modified: mrbs/trunk/web/Themes/default.inc
===================================================================
--- mrbs/trunk/web/Themes/default.inc   2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/Themes/default.inc   2009-03-18 21:56:42 UTC (rev 1054)
@@ -84,7 +84,17 @@
     'G' => "#ccffcc",
     'H' => "#d9d982",
     'I' => "#99cc66",
-    'J' => "#e6ffe6");
+    'J' => "#e6ffe6",
+    'PA' => "#D8D871", // PA-PJ are "Private" entry colors for A-J
+    'PB' => "#85b3b3",
+    'PC' => "#e9e9c0",
+    'PD' => "#b5c7c7",
+    'PE' => "#5db6a7",
+    'PF' => "#668484",
+    'PG' => "#aed8ae",
+    'PH' => "#bdbd71",
+    'PI' => "#99aa44",
+    'PJ' => "#c9dcc9"); 
 
     
 // ***** DIMENSIONS *******************

Modified: mrbs/trunk/web/config.inc.php
===================================================================
--- mrbs/trunk/web/config.inc.php       2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/config.inc.php       2009-03-18 21:56:42 UTC (rev 1054)
@@ -297,6 +297,30 @@
                               // highlighting is used, whether or not 
$javascript_cursor is set.
 
 
+// Private Bookings Settings
+// Only administrators or the person who booked a private event can see
+// details of the event.  Everyone else just sees that the time/period
+// is booked on the schedule.
+$private_enabled = FALSE;  // Display checkbox in entry page to make
+           // the booking private.  
+
+$private_default = FALSE;  // Set default value for "Private" flag on
+           // new/edited entries.  Used even if checkbox is not displayed.
+
+$private_mandatory = FALSE; // If TRUE all new/edited entries will 
+           // use the value from $private_default when saved.
+           // If checkbox is displayed it will be disabled.
+
+$private_override = "none"; // Override default privacy behavior. 
+           // "none" - Private flag on entry is used
+           // "private" - ALL entries are treated as private regardless
+           //             of private flag on the entry.
+           // "public" - NO entry is treated as private, regardless of
+           //            private flag on the entry.
+           // Overrides $private_default and $private_mandatory
+           // Consider your users' expectations of privacy before
+           // changing to "public" or from "private" to "none"
+
 /***********************************************
  * Authentication settings - read AUTHENTICATION
  ***********************************************/

Modified: mrbs/trunk/web/day.php
===================================================================
--- mrbs/trunk/web/day.php      2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/day.php      2009-03-18 21:56:42 UTC (rev 1054)
@@ -178,7 +178,8 @@
 //form of the original which had 3 BETWEEN parts. It selects all entries which
 //occur on or cross the current day.
 $sql = "SELECT $tbl_room.id AS room_id, start_time, end_time, name, 
$tbl_entry.id AS entry_id, type,
-        $tbl_entry.description AS entry_description
+        $tbl_entry.description AS entry_description, 
+        $tbl_entry.private AS entry_private, $tbl_entry.create_by AS 
entry_create_by
    FROM $tbl_entry, $tbl_room
    WHERE $tbl_entry.room_id = $tbl_room.id
    AND area_id = $area
@@ -203,6 +204,8 @@
   //  row['entry_id'] = id of this booking
   //  row['type'] = type (internal/external)
   //  row['entry_description'] = description
+  //  row['entry_private'] = if entry is private
+  //  row['entry_create_by'] = Creator/owner of entry
   
   map_add_booking($row, $today[$row['room_id']][$day], $am7, $pm7, $format);
 

Modified: mrbs/trunk/web/dbsys.inc
===================================================================
--- mrbs/trunk/web/dbsys.inc    2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/dbsys.inc    2009-03-18 21:56:42 UTC (rev 1054)
@@ -15,7 +15,7 @@
 $tbl_variables = $db_tbl_prefix . "variables";
 
 
-$db_schema_version = 2;
+$db_schema_version = 3;
 
 
 // Include the abstraction configured to be used for the default MRBS

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/edit_entry.php       2009-03-18 21:56:42 UTC (rev 1054)
@@ -22,6 +22,7 @@
 $copy = get_form_var('copy', 'int');
 $edit_type = get_form_var('edit_type', 'string');
 $returl = get_form_var('returl', 'string');
+$private = get_form_var('private', 'string');
 
 if (empty($area))
 {
@@ -66,7 +67,7 @@
 if (isset($id))
 {
   $sql = "select name, create_by, description, start_time, end_time,
-     type, room_id, entry_type, repeat_id from $tbl_entry where id=$id";
+     type, room_id, entry_type, repeat_id, private from $tbl_entry where 
id=$id";
    
   $res = sql_query($sql);
   if (! $res)
@@ -94,6 +95,11 @@
   $room_id     = $row['room_id'];
   $entry_type  = $row['entry_type'];
   $rep_id      = $row['repeat_id'];
+  $private     = $row['private'];
+  if ($private_mandatory) 
+  {
+    $private = $private_default;
+  }
 
   if($entry_type >= 1)
   {
@@ -185,6 +191,7 @@
   $rep_end_month = $month;
   $rep_end_year  = $year;
   $rep_day       = array(0, 0, 0, 0, 0, 0, 0);
+  $private       = $private_default;
 }
 
 // These next 4 if statements handle the situation where
@@ -670,9 +677,9 @@
       <span><?php echo get_vocab("ctrl_click") ?></span>
       </div>
     </div>
-    
     <div id="div_type">
       <label for="type"><?php echo get_vocab("type")?>:</label>
+     <div class="group">    
       <select id="type" name="type">
         <?php
         for ($c = "A"; $c <= "Z"; $c++)
@@ -684,6 +691,24 @@
         }
         ?>
       </select>
+      <?php 
+      if ($private_enabled) 
+      { ?>
+        <div id="div_private">
+          <input id="private" class="checkbox" name="private" type="checkbox" 
value="yes"<?php 
+          if($private) 
+          {
+            echo " checked=\"checked\"";
+          }
+          if($private_mandatory) 
+          {
+            echo " disabled=\"true\"";
+          }
+          ?>>
+          <label for="private"><?php echo get_vocab("private") ?></label>
+        </div><?php 
+      } ?>
+     </div>
     </div>
 
 
@@ -722,7 +747,7 @@
           {
             $wday = ($i + $weekstarts) % 7;
             echo "      <label><input class=\"checkbox\" 
name=\"rep_day[$wday]\" type=\"checkbox\"";
-            if ($rep_day[$wday])
+            if ($irep_day[$wday])
             {
               echo " checked=\"checked\"";
             }

Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php       2009-03-18 20:38:36 UTC (rev 
1053)
+++ mrbs/trunk/web/edit_entry_handler.php       2009-03-18 21:56:42 UTC (rev 
1054)
@@ -37,6 +37,7 @@
 $rep_id = get_form_var('rep_id', 'int');
 $rep_day = get_form_var('rep_day', 'array'); // array of bools
 $rep_num_weeks = get_form_var('rep_num_weeks', 'int');
+$private = get_form_var('private', 'string'); // bool, actually
 
 if (empty($area))
 {
@@ -120,8 +121,17 @@
 // Complete the query string
 $returl .= "&area=$area&room=$room";
 
+// Handle private booking
+// Enforce config file settings if needed
+if ($private_mandatory) 
+{
+  $isprivate = $private_default;
+}
+else
+{
+  $isprivate = ((isset($private) && ($private == "yes")));
+}
 
-
 if (!getAuthorised(1))
 {
   showAccessDenied($day, $month, $year, $area, isset($room) ? $room : "");
@@ -405,7 +415,8 @@
                                           $name,
                                           $type,
                                           $description,
-                                          isset($rep_num_weeks) ? 
$rep_num_weeks : 0);
+                                          isset($rep_num_weeks) ? 
$rep_num_weeks : 0,
+                                          $isprivate);
       // Send a mail to the Administrator
       if (MAIL_ADMIN_ON_BOOKINGS or MAIL_AREA_ADMIN_ON_BOOKINGS or
           MAIL_ROOM_ADMIN_ON_BOOKINGS or MAIL_BOOKER)
@@ -461,7 +472,8 @@
                                       $create_by,
                                       $name,
                                       $type,
-                                      $description);
+                                      $description,
+                                      $isprivate);
 
       // Send a mail to the Administrator
       if (MAIL_ADMIN_ON_BOOKINGS or MAIL_AREA_ADMIN_ON_BOOKINGS or

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/functions.inc        2009-03-18 21:56:42 UTC (rev 1054)
@@ -19,6 +19,18 @@
   }
 }
 
+// Deal with $private_xxxx overrides.  Simplifies
+// logic related to private bookings.
+if ($private_override == "private" )
+{
+  $private_mandatory=TRUE;
+  $private_default=TRUE;
+}
+elseif ($private_override == "public" )
+{
+  $private_mandatory=TRUE;
+  $private_default=FALSE;
+}
 
 $done_header = FALSE;
 
@@ -830,6 +842,24 @@
   return (isset($hidden_days) && in_array($dow, $hidden_days));
 }
 
+// returns true if event should be considered private based on
+// config settings and event's "private" flag (passed to function)
+function is_private_event($event_flag) 
+{
+  global $private_override;
+  if ($private_override == "private" )
+  {
+    $event_flag = TRUE;
+  }
+  elseif ($private_override == "public" )
+  {
+    $event_flag = FALSE;
+  }
+
+  return $event_flag;
+}
+
+
 function map_add_booking ($row, &$column, $am7, $pm7, $format)
 {
   // Enters the contents of the booking found in $row into $column, which is
@@ -849,6 +879,8 @@
   //       entry_id
   //       type
   //       entry_description
+  //       entry_private
+  //       entry_create_by
   
   // $column is a column of the map of the screen that will be displayed
   // It looks like:
@@ -889,6 +921,19 @@
   
   global $resolution;
   
+  $user = getUserName();
+  if (is_private_event($row['entry_private']) &&
+         !getWritable($row['entry_create_by'],$user))
+  {
+    $is_private = TRUE;
+    $row['name']= "- ".get_vocab('unavailable')." -";
+    $row['entry_description']= "- ".get_vocab('unavailable')." -";
+  }
+  else
+  {
+    $is_private = FALSE;
+  }
+
   $start_t = max(round_t_down($row['start_time'], $resolution, $am7), $am7);
   $end_t = min(round_t_up($row['end_time'], $resolution, $am7) - $resolution, 
$pm7);
   // calculate the times used for indexing
@@ -909,7 +954,14 @@
     
     // fill in the id, type and start time
     $column[$time_t][$n]["id"]    = $row['entry_id'];
-    $column[$time_t][$n]["color"] = $row['type'];
+    if ($is_private) 
+    {
+      $column[$time_t][$n]["color"] = 'P'.$row['type'];
+    }
+    else
+    {
+      $column[$time_t][$n]["color"] = $row['type'];
+    }
     $column[$time_t][$n]["start_time"] = utf8_strftime(hour_min_format(), 
$row['start_time']);
     $column[$time_t][$n]["slots"] = null;  // to avoid undefined index NOTICE 
errors
     // if it's a multiple booking also fill in the name and description

Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en      2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/lang.en      2009-03-18 21:56:42 UTC (rev 1054)
@@ -89,6 +89,8 @@
 $vocab["valid_time_of_day"]  = "valid time of day.";
 $vocab["brief_description"]  = "Brief Description.";
 $vocab["useful_n-weekly_value"] = "useful n-weekly value.";
+$vocab["private"]            = "Private";
+$vocab["unavailable"]        = "Unavailable";
 
 // Used in view_entry.php
 $vocab["description"]        = "Description";

Modified: mrbs/trunk/web/month.php
===================================================================
--- mrbs/trunk/web/month.php    2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/month.php    2009-03-18 21:56:42 UTC (rev 1054)
@@ -18,6 +18,8 @@
 $room = get_form_var('room', 'int');
 $debug_flag = get_form_var('debug_flag', 'int');
 
+$user = getUserName();
+
 // 3-value compare: Returns result of compare as "< " "= " or "> ".
 function cmp3($a, $b)
 {
@@ -296,7 +298,8 @@
 // This data will be retrieved day-by-day fo the whole month
 for ($day_num = 1; $day_num<=$days_in_month; $day_num++)
 {
-  $sql = "SELECT start_time, end_time, id, name, type
+  $sql = "SELECT start_time, end_time, id, name, type,
+          private, create_by
           FROM $tbl_entry
           WHERE room_id=$room
           AND start_time <= $midnight_tonight[$day_num] AND end_time > 
$midnight[$day_num]
@@ -326,9 +329,36 @@
         echo "<br>DEBUG: Entry ".$row['id']." day $day_num\n";
       }
       $d[$day_num]["id"][] = $row['id'];
-      $d[$day_num]["shortdescrip"][] = htmlspecialchars($row['name']);
-      $d[$day_num]["color"][] = $row['type'];
+      
+      // Handle private events
+      if (is_private_event($row['private'])) 
+      {
+        if (getWritable($row['create_by'],$user)) 
+        {
+          $private = FALSE;
+        }
+        else 
+        {
+          $private = TRUE;
+        }
+      }
+      else 
+      {
+        $private = FALSE;
+      }
 
+      if ($private) 
+      {
+        $d[$day_num]["shortdescrip"][] = '- '.get_vocab('unavailable').' -';
+        $d[$day_num]["color"][] = 'P';
+      }
+      else
+      {
+        $d[$day_num]["shortdescrip"][] = htmlspecialchars($row['name']);
+        $d[$day_num]["color"][] = $row['type'];
+      }
+        
+
       // Describe the start and end time, accounting for "all day"
       // and for entries starting before/ending after today.
       // There are 9 cases, for start time < = or > midnight this morning,

Modified: mrbs/trunk/web/mrbs.css.php
===================================================================
--- mrbs/trunk/web/mrbs.css.php 2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/mrbs.css.php 2009-03-18 21:56:42 UTC (rev 1054)
@@ -518,6 +518,7 @@
 .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#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}
 .form_general fieldset#rep_info {padding-top: 0}
 .form_general #rep_info input {width: 13em}

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/mrbs_sql.inc 2009-03-18 21:56:42 UTC (rev 1054)
@@ -157,16 +157,19 @@
  * $name        - Name
  * $type        - Type (Internal/External)
  * $description - Description
+ * $private     - Private Booking (TRUE/FALSE)
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
  *   non-zero - The entry's ID
  */
 function mrbsCreateSingleEntry($starttime, $endtime, $entry_type, $repeat_id,
-                               $room_id, $owner, $name, $type, $description)
+                               $room_id, $owner, $name, $type, $description,
+                               $private)
 {
   global $tbl_entry;
 
+  $private = $private ? 1 : 0 ;
   $name        = addslashes($name);
   $description = addslashes($description);
    
@@ -176,9 +179,9 @@
   if ($endtime > $starttime)
   {
     $sql = "INSERT INTO $tbl_entry (  start_time,   end_time,   entry_type,    
repeat_id,   room_id,
-                                      create_by,    name,       type,          
description)
+                                      create_by,    name,       type,          
description, private)
                             VALUES ($starttime, $endtime, $entry_type, 
$repeat_id, $room_id,
-                                    '$owner',     '$name',    '$type',       
'$description')";
+                                    '$owner',     '$name',    '$type',       
'$description', $private)";
 
     if (sql_command($sql) < 0)
     {
@@ -207,6 +210,8 @@
  * $name        - Name
  * $type        - Type (Internal/External)
  * $description - Description
+ * $rep_num_weeks - (missing)
+ * $private     - Private Booking (bool)
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
@@ -214,7 +219,7 @@
  */
 function mrbsCreateRepeatEntry($starttime, $endtime, $rep_type, $rep_enddate,
                                $rep_opt, $room_id, $owner, $name, $type,
-                               $description, $rep_num_weeks)
+                               $description, $rep_num_weeks, $private)
 {
   global $tbl_repeat;
 
@@ -232,6 +237,7 @@
   $sql_coln[] = 'room_id';   $sql_val[] = $room_id;
   $sql_coln[] = 'create_by';   $sql_val[] = '\''.$owner.'\'';
   $sql_coln[] = 'type';      $sql_val[] = '\''.$type.'\'';
+  $sql_coln[] = 'private';      $sql_val[] = '\''.$private.'\'';
   $sql_coln[] = 'name';      $sql_val[] = '\''.$name.'\'';
 
   // Optional things, pgsql doesn't like empty strings!
@@ -431,6 +437,7 @@
  * $name        - Name
  * $type        - Type (Internal/External)
  * $description - Description
+ * $private     - Private Booking (bool)
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
@@ -438,9 +445,11 @@
  */
 function mrbsCreateRepeatingEntrys($starttime, $endtime, $rep_type,
                                    $rep_enddate, $rep_opt, $room_id, $owner,
-                                   $name, $type, $description, $rep_num_weeks)
+                                   $name, $type, $description, $rep_num_weeks,
+                                   $private)
 {
   global $max_rep_entrys;
+  $private = $private ? 1 : 0 ;
    
   $reps = mrbsGetRepeatEntryList($starttime, $rep_enddate,
                                  $rep_type, $rep_opt,
@@ -455,14 +464,14 @@
   {
     $ent = mrbsCreateSingleEntry($starttime, $endtime, 0, 0,
                                  $room_id, $owner, $name, $type,
-                                 $description);
+                                 $description, $private);
     return $ent;
   }
    
   $ent = mrbsCreateRepeatEntry($starttime, $endtime, $rep_type,
                                $rep_enddate, $rep_opt, $room_id,
                                $owner, $name, $type, $description,
-                               $rep_num_weeks);
+                               $rep_num_weeks,$private);
     
   if ($ent)
   {
@@ -481,7 +490,7 @@
                                       $owner,
                                       $name,
                                       $type,
-                                      $description);
+                                      $description, $private);
     }
   }
   return $ent;

Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php   2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/report.php   2009-03-18 21:56:42 UTC (rev 1054)
@@ -338,6 +338,20 @@
 $display = get_form_var('display', 'string');
 $sumby = get_form_var('sumby', 'string');
 
+# Require authenticated user if private bookings are required
+if ($private_override == "private")
+{
+  if (!getAuthorised(1))
+  {
+    showAccessDenied($day, $month, $year, $area, "");
+    exit();
+  }
+}
+
+# Need to know user name and if they are an admin
+$user = getUserName();
+$is_admin =  (isset($user) && authGetUserLevel($user)>=2) ;
+
 //If we dont know the right date then make it up
 if (!isset($day) or !isset($month) or !isset($year))
 {
@@ -630,6 +644,28 @@
   {
     $sql .= " AND" .  sql_syntax_caseless_contains("e.create_by", 
$creatormatch);
   }
+
+  # If not overriding as public entries and user isn't and admin...
+  if (($private_override != "public") && !$is_admin) 
+  {
+    if (isset($user))
+    {
+      if ($private_override == "private") 
+      {
+        $sql .= " AND e.create_by = '$user'";
+      }
+      else
+      {
+        $sql .= " AND (e.create_by = '$user' OR NOT e.private)";
+      }
+    }
+    else
+    { 
+      # un-authenticated users can only report on
+      # items which are not marked private
+      $sql .= " AND NOT e.private";
+    }
+  }
    
   if ( $sortby == "r" )
   {

Modified: mrbs/trunk/web/search.php
===================================================================
--- mrbs/trunk/web/search.php   2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/search.php   2009-03-18 21:56:42 UTC (rev 1054)
@@ -18,6 +18,9 @@
 $total = get_form_var('total', 'int');
 $advanced = get_form_var('advanced', 'int');
 
+$user = getUserName();
+$is_admin =  (isset($user) && authGetUserLevel($user)>=2) ;
+
 // If we dont know the right date then make it up 
 if (!isset($day) or !isset($month) or !isset($year))
 {
@@ -66,6 +69,16 @@
   exit;
 }
 
+# Require authenticated user if private bookings are required
+if ($private_override == "private")
+{
+  if (!getAuthorised(1))
+  {
+    showAccessDenied($day, $month, $year, $area, "");
+    exit();
+  }
+}
+
 if (!$search_str)
 {
   echo "<p class=\"error\">" . get_vocab("invalid_search") . "</p>";
@@ -84,6 +97,32 @@
   . " OR " . sql_syntax_caseless_contains("E.description", $search_str)
   . ") AND E.end_time > $now";
 
+# Unless we overriding privacy settings as "public" or user
+# is and admin, we have to restrict which listings are returned
+if (($private_override != "public") && !$is_admin) 
+{
+  if (isset($user)) 
+  {
+    # If private bookings are forced then user can only
+    # search their own.  If not they can also search non-private entries
+    if ($private_override == "private") 
+    {
+      $sql_pred .= " AND E.create_by = '$user'";
+    }
+    else
+    {
+      $sql_pred .= " AND (E.create_by = '$user' OR NOT E.private)";
+    }
+  }
+  else
+  {
+    # If user isn't logged in then we already know
+    # override isn't set to "private" and we wouldn't
+    # be here if it were "public" so...
+    $sql_pred .= " AND NOT E.private";
+  }
+}
+
 // The first time the search is called, we get the total
 // number of matches.  This is passed along to subsequent
 // searches so that we don't have to run it for each page.

Added: mrbs/trunk/web/upgrade/3/mysql.sql
===================================================================
--- mrbs/trunk/web/upgrade/3/mysql.sql                          (rev 0)
+++ mrbs/trunk/web/upgrade/3/mysql.sql  2009-03-18 21:56:42 UTC (rev 1054)
@@ -0,0 +1,9 @@
+-- Run this script to upgrade postgres or mysql mrbs database
+
+-- Add an extra column to the mrbs_entry and mrbs_repeat table 
+-- for private bookings handling
+
+ALTER TABLE mrbs_repeat 
+ ADD private BOOL NOT NULL DEFAULT '0';
+ALTER TABLE mrbs_entry 
+ ADD private BOOL NOT NULL DEFAULT '0';

Added: mrbs/trunk/web/upgrade/3/pgsql.sql
===================================================================
--- mrbs/trunk/web/upgrade/3/pgsql.sql                          (rev 0)
+++ mrbs/trunk/web/upgrade/3/pgsql.sql  2009-03-18 21:56:42 UTC (rev 1054)
@@ -0,0 +1,9 @@
+-- Run this script to upgrade postgres or mysql mrbs database
+
+-- Add an extra column to the mrbs_entry and mrbs_repeat table 
+-- for private bookings handling
+
+ALTER TABLE mrbs_repeat 
+ ADD private BOOL NOT NULL DEFAULT '0';
+ALTER TABLE mrbs_entry 
+ ADD private BOOL NOT NULL DEFAULT '0';

Modified: mrbs/trunk/web/view_entry.php
===================================================================
--- mrbs/trunk/web/view_entry.php       2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/view_entry.php       2009-03-18 21:56:42 UTC (rev 1054)
@@ -7,6 +7,8 @@
 require_once "dbsys.inc";
 require_once "mrbs_auth.inc";
 
+$user = getUserName();
+
 // Get form variables
 $day = get_form_var('day', 'int');
 $month = get_form_var('month', 'int');
@@ -48,6 +50,7 @@
           $tbl_room.room_name,
           $tbl_area.area_name,
           $tbl_repeat.type,
+          $tbl_repeat.private,
           $tbl_repeat.room_id,
           " . sql_syntax_timestamp_to_unix("$tbl_repeat.timestamp") . " AS 
last_updated,
           ($tbl_repeat.end_time - $tbl_repeat.start_time) AS duration,
@@ -73,6 +76,7 @@
           $tbl_room.room_name,
           $tbl_area.area_name,
           $tbl_entry.type,
+          $tbl_entry.private,
           $tbl_entry.room_id,
           " . sql_syntax_timestamp_to_unix("$tbl_entry.timestamp") . " AS 
last_updated,
           ($tbl_entry.end_time - $tbl_entry.start_time) AS duration,
@@ -109,12 +113,20 @@
 $room_name    = htmlspecialchars($row['room_name']);
 $area_name    = htmlspecialchars($row['area_name']);
 $type         = $row['type'];
+$private      = $row['private'];
 $room_id      = $row['room_id'];
 $updated      = time_date_string($row['last_updated']);
 // 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']);
+$writeable = getWritable($create_by,$user);
+if (is_private_event($private) && !$writeable) 
+{
+    $name = "-".get_vocab('private')."-";
+    $description = $name ;
+    $create_by = $name ;
+}
 
 if ($enable_periods)
 {
@@ -217,7 +229,13 @@
 
 ?>
 
-<h3><?php echo $name ?></h3>
+<h3><?php 
+  echo $name;
+  if (is_private_event($private) && $writeable) 
+  {
+    echo ' ('.get_vocab('private').')';
+  }
+?></h3>
  <table id="entry">
    <tr>
     <td><?php echo get_vocab("description") ?>:</td>
@@ -245,7 +263,9 @@
    </tr>
    <tr>
     <td><?php echo get_vocab("createdby") ?>:</td>
-    <td><?php    echo $create_by ?></td>
+    <td><?php
+          echo $create_by ;
+        ?></td>
    </tr>
    <tr>
     <td><?php echo get_vocab("lastupdate") ?>:</td>

Modified: mrbs/trunk/web/week.php
===================================================================
--- mrbs/trunk/web/week.php     2009-03-18 20:38:36 UTC (rev 1053)
+++ mrbs/trunk/web/week.php     2009-03-18 21:56:42 UTC (rev 1054)
@@ -249,15 +249,18 @@
 // row['end_time'] = End time
 // row['type'] = Entry type
 // row['name'] = Entry name (brief description)
-// row['id'] = Entry ID
-// row['description'] = Complete description
+// row['entry_id'] = Entry ID
+// row['entry_description'] = Complete description
+// row['entry_private'] = entry marked as "Private"
+// row['entry_create_by'] = User who created entry
 // This data will be retrieved day-by-day
 
 $week_map = array();
 
 for ($j = 0; $j<=($num_of_days-1) ; $j++)
 {
-  $sql = "SELECT start_time, end_time, type, name, id AS entry_id, description 
AS entry_description
+  $sql = "SELECT start_time, end_time, type, name, id AS entry_id, description 
AS entry_description,
+            private AS entry_private, create_by AS entry_create_by
           FROM $tbl_entry
           WHERE room_id = $room
           AND start_time <= $pm7[$j] AND end_time > $am7[$j]


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

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to