Revision: 1421
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1421&view=rev
Author:   cimorrison
Date:     2010-08-25 14:48:22 +0000 (Wed, 25 Aug 2010)

Log Message:
-----------
- Fixed bug which showed up when trying to accept a provisional repeat booking
- Simplified the code

Modified Paths:
--------------
    mrbs/trunk/web/mrbs_sql.inc

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2010-08-25 10:44:59 UTC (rev 1420)
+++ mrbs/trunk/web/mrbs_sql.inc 2010-08-25 14:48:22 UTC (rev 1421)
@@ -822,22 +822,24 @@
     }
   }
 
-  $entry_fields = sql_field_info($tbl_entry);
-  $repeat_fields = sql_field_info($tbl_repeat);
+  $table = ($series) ? $tbl_repeat : $tbl_entry;
+  $table_fields = sql_field_info($table);
 
+  // Build an array of the field names in the repeat table so that
+  // we'll be able to do some sanity checking later
+  $repeat_fields = sql_field_info($tbl_repeat);
   $rep_fields = array();
   foreach ($repeat_fields as $field)
   {
     $rep_fields[$field['name']] = 1;
   }
 
-  $t_or_e = $series ? "T" : "E";
-
   $terms = array("M.room_name",
                  "M.area_id",
                  "A.area_name",
-                 "($t_or_e.end_time - $t_or_e.start_time) AS duration");
-  foreach ($entry_fields as $field)
+                 "(end_time - start_time) AS duration");
+                 
+  foreach ($table_fields as $field)
   {
     switch ($field['name'])
     {
@@ -845,17 +847,15 @@
       case 'entry_type':
         // Nothing to do
         break;
-
-      case 'status':
+        
       case 'repeat_id':
-        array_push($terms, "E.".$field['name']);
+      case 'status':
+        // repeat_id and status only exist in the entry table
+        array_push($terms, $field['name']);
         break;
 
       case 'timestamp':
-        array_push($terms,
-                   sql_syntax_timestamp_to_unix(($series ? "T" : "E" ).
-                                                ".timestamp").
-                   "AS last_updated");
+        array_push($terms, sql_syntax_timestamp_to_unix("timestamp") . "AS 
last_updated");
         break;
 
       case 'info_time':
@@ -863,48 +863,35 @@
       case 'info_text':
         if ($series)
         {
-          array_push($terms, "T.".$field['name']." AS repeat_".$field['name']);
+          array_push($terms, $field['name'] . " AS repeat_".$field['name']);
         }
         else
         {
-          array_push($terms, "E.".$field['name']." AS entry_".$field['name']);
+          array_push($terms, $field['name'] . " AS entry_".$field['name']);
         }
         break;
 
       default:
-        if (!array_key_exists($field['name'], $rep_fields))
+        // These are (a) all the standard fields which are common to the entry
+        // and repeat tables and (b) all the customn fields, which should be
+        // common to the two tables (we will do a check to make sure)
+        if (!$series && !array_key_exists($field['name'], $rep_fields))
         {
+          // If this is the entry table then check that the custom field also
+          // exists in the rpeat table
           fatal_error(0, "Custom fields problem, '".$field['name']."' exists 
in entry table but not in repeat table");
         }
         
-        array_push($terms, ($series ? "T" : "E" ).".".$field['name']);
+        array_push($terms, "T." . $field['name']);
         break;
     }
   }
-  if ($series)
-  {
-    array_push($terms,
-               "T.rep_type",
-               "T.end_date",
-               "T.rep_opt",
-               "T.rep_num_weeks");
-    
-    $sql = "SELECT ".implode(",\n       ",$terms)."
-FROM $tbl_repeat T, $tbl_room M, $tbl_area A
-WHERE T.room_id = M.id
-      AND M.area_id = A.id
-      AND T.id=$id
-";
-  }
-  else
-  {
-    $sql = "SELECT ".implode(",\n       ",$terms)."
-FROM  $tbl_entry E, $tbl_room M, $tbl_area A
-WHERE E.room_id = M.id
-        AND M.area_id = A.id
-        AND E.id=$id
-";
-  }
+  
+  $sql = "SELECT " . implode(", ",$terms)."
+            FROM $table T, $tbl_room M, $tbl_area A
+           WHERE T.room_id = M.id
+             AND M.area_id = A.id
+             AND T.id=$id";
 
   $res = sql_query($sql);
   if (! $res)


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

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to