Revision: 1245
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1245&view=rev
Author:   cimorrison
Date:     2009-11-09 23:20:53 +0000 (Mon, 09 Nov 2009)

Log Message:
-----------
Bookings are now written into the database with a status code (provisional or 
confirmed)

Modified Paths:
--------------
    mrbs/branches/provisional_bookings/web/edit_entry_handler.php
    mrbs/branches/provisional_bookings/web/mrbs_auth.inc
    mrbs/branches/provisional_bookings/web/mrbs_sql.inc
    mrbs/branches/provisional_bookings/web/systemdefaults.inc.php

Modified: mrbs/branches/provisional_bookings/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/provisional_bookings/web/edit_entry_handler.php       
2009-11-09 21:47:09 UTC (rev 1244)
+++ mrbs/branches/provisional_bookings/web/edit_entry_handler.php       
2009-11-09 23:20:53 UTC (rev 1245)
@@ -150,8 +150,9 @@
   showAccessDenied($day, $month, $year, $area, isset($room) ? $room : "");
   exit;
 }
+$user = getUserName();
 
-if (!getWritable($create_by, getUserName()))
+if (!getWritable($create_by, $user))
 {
   showAccessDenied($day, $month, $year, $area, isset($room) ? $room : "");
   exit;
@@ -414,6 +415,18 @@
 {
   foreach ( $rooms as $room_id )
   {
+    // If we're using provisional booking then we need to work out whether the
+    // status of this booking is confirmed.   If the user is allowed to confirm
+    // bookings for this room, then the status will be confirmed , since they 
are
+    // in effect immediately confirming their own booking.
+    if ($provisional_enabled)
+    {
+      $status = (auth_can_confirm($user, $room_id)) ? STATUS_CONFIRMED : 
STATUS_PROVISIONAL;
+    }
+    else
+    {
+      $status = STATUS_CONFIRMED;
+    }
     if ($edit_type == "series")
     {
       $new_id = mrbsCreateRepeatingEntrys($starttime,
@@ -427,7 +440,8 @@
                                           $type,
                                           $description,
                                           isset($rep_num_weeks) ? 
$rep_num_weeks : 0,
-                                          $isprivate);
+                                          $isprivate,
+                                          $status);
       // Send a mail to the Administrator
       if ($mail_settings['admin_on_bookings'] or 
$mail_settings['area_admin_on_bookings'] or
           $mail_settings['room_admin_on_bookings'] or $mail_settings['booker'])
@@ -484,7 +498,8 @@
                                       $name,
                                       $type,
                                       $description,
-                                      $isprivate);
+                                      $isprivate,
+                                      $status);
 
       // Send a mail to the Administrator
       if ($mail_settings['admin_on_bookings'] or 
$mail_settings['area_admin_on_bookings'] or
@@ -524,7 +539,7 @@
   // Delete the original entry
   if (isset($id))
   {
-    mrbsDelEntry(getUserName(), $id, ($edit_type == "series"), 1);
+    mrbsDelEntry($user, $id, ($edit_type == "series"), 1);
   }
 
   sql_mutex_unlock("$tbl_entry");

Modified: mrbs/branches/provisional_bookings/web/mrbs_auth.inc
===================================================================
--- mrbs/branches/provisional_bookings/web/mrbs_auth.inc        2009-11-09 
21:47:09 UTC (rev 1244)
+++ mrbs/branches/provisional_bookings/web/mrbs_auth.inc        2009-11-09 
23:20:53 UTC (rev 1245)
@@ -92,4 +92,31 @@
   // Print footer and exit
   print_footer(TRUE);
 }
+
+// auth_can_confirm($user, $room)
+//
+// Checks whether $user is allowed to confirm provisional bookings for $room
+// At the moment $room is ignored, but is passed here so that later
+// it can be enhanced to provide fine-grained permissions
+// 
+// Returns:  TRUE if the user is allowed to confirm bookings (or
+// if the requirement to have provisional bookings is disabled); 
+// otherwise FALSE
+function auth_can_confirm($user, $room)
+{
+  global $provisional_enabled;
+  
+  if (!$provisional_enabled)
+  {
+    // We're not using provisional booking, so a booking is
+    // automatically confirmed
+    return TRUE;
+  }
+  else
+  {
+    // At the moment the policy is simple: if we're using
+    // provisional bookings then only admins can confirm them
+    return (authGetUserLevel($user) >= 2);
+  }
+}
 ?>

Modified: mrbs/branches/provisional_bookings/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/provisional_bookings/web/mrbs_sql.inc 2009-11-09 21:47:09 UTC 
(rev 1244)
+++ mrbs/branches/provisional_bookings/web/mrbs_sql.inc 2009-11-09 23:20:53 UTC 
(rev 1245)
@@ -166,6 +166,7 @@
  * $type        - Type (Internal/External)
  * $description - Description
  * $private     - Private Booking (TRUE/FALSE)
+ * $status      - Status code of the entry
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
@@ -173,7 +174,7 @@
  */
 function mrbsCreateSingleEntry($starttime, $endtime, $entry_type, $repeat_id,
                                $room_id, $owner, $name, $type, $description,
-                               $private)
+                               $private, $status)
 {
   global $tbl_entry;
  
@@ -189,9 +190,9 @@
   if ($endtime > $starttime)
   {
     $sql = "INSERT INTO $tbl_entry (  start_time,   end_time,   entry_type,    
repeat_id,   room_id,
-                                      create_by,    name,       type,          
description, private)
+                                      create_by,    name,       type,          
description, private, status)
                             VALUES ($starttime, $endtime, $entry_type, 
$repeat_id, $room_id,
-                                    '$owner',     '$name',    '$type',       
'$description', $private)";
+                                    '$owner',     '$name',    '$type',       
'$description', $private, $status)";
 
     if (sql_command($sql) < 0)
     {
@@ -222,6 +223,10 @@
  * $description - Description
  * $rep_num_weeks - (missing)
  * $private     - Private Booking (bool)
+ *
+ * (NOTE: there is no status code passed, because the repeat table
+ *  does not have a status field.  Only the individual members of 
+ *  a series can have a status)
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
@@ -471,6 +476,7 @@
  * $type        - Type (Internal/External)
  * $description - Description
  * $private     - Private Booking (bool)
+ * $status      - Status code
  * 
  * Returns:
  *   0        - An error occured while inserting the entry
@@ -479,7 +485,7 @@
 function mrbsCreateRepeatingEntrys($starttime, $endtime, $rep_type,
                                    $rep_enddate, $rep_opt, $room_id, $owner,
                                    $name, $type, $description, $rep_num_weeks,
-                                   $private)
+                                   $private, $status)
 {
   global $max_rep_entrys;
   $private = $private ? 1 : 0 ;
@@ -497,14 +503,14 @@
   {
     $ent = mrbsCreateSingleEntry($starttime, $endtime, 0, 0,
                                  $room_id, $owner, $name, $type,
-                                 $description, $private);
+                                 $description, $private, $status);
     return $ent;
   }
    
   $ent = mrbsCreateRepeatEntry($starttime, $endtime, $rep_type,
                                $rep_enddate, $rep_opt, $room_id,
                                $owner, $name, $type, $description,
-                               $rep_num_weeks,$private);
+                               $rep_num_weeks, $private);
     
   if ($ent)
   {
@@ -523,7 +529,9 @@
                                       $owner,
                                       $name,
                                       $type,
-                                      $description, $private);
+                                      $description,
+                                      $private,
+                                      $status);
     }
   }
   return $ent;

Modified: mrbs/branches/provisional_bookings/web/systemdefaults.inc.php
===================================================================
--- mrbs/branches/provisional_bookings/web/systemdefaults.inc.php       
2009-11-09 21:47:09 UTC (rev 1244)
+++ mrbs/branches/provisional_bookings/web/systemdefaults.inc.php       
2009-11-09 23:20:53 UTC (rev 1245)
@@ -362,7 +362,16 @@
            // Overrides $private_default and $private_mandatory
            // Consider your users' expectations of privacy before
            // changing to "public" or from "private" to "none"
+    
+                  
+// PROVISIONAL BOOKINGS SETTINGS
 
+// These settings control whether provisional bookings should be used.
+// If provisional bookings are enabled then ordinary users must have their
+// bookings confirmed by an admin.
+$provisional_enabled = FALSE;  // Set to TRUE to enable provisional bookings
+
+
 /***********************************************
  * Authentication settings - read AUTHENTICATION
  ***********************************************/


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

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to