Revision: 1099
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1099&view=rev
Author:   cimorrison
Date:     2009-04-22 15:58:21 +0000 (Wed, 22 Apr 2009)

Log Message:
-----------
- Added checks to ensure that area names are unique and room names are unique 
within an area.
- Fixed bug introduced in Rev 1094 (freeing wrong mutex)

Revision Links:
--------------
    http://mrbs.svn.sourceforge.net/mrbs/?rev=1094&view=rev

Modified Paths:
--------------
    mrbs/trunk/web/add.php
    mrbs/trunk/web/admin.php
    mrbs/trunk/web/edit_area_room.php
    mrbs/trunk/web/lang.en

Modified: mrbs/trunk/web/add.php
===================================================================
--- mrbs/trunk/web/add.php      2009-04-22 15:22:32 UTC (rev 1098)
+++ mrbs/trunk/web/add.php      2009-04-22 15:58:21 UTC (rev 1099)
@@ -33,12 +33,28 @@
 if ($type == "area")
 {
   $area_name_q = addslashes($name);
-  $sql = "insert into $tbl_area (area_name) values ('$area_name_q')";
-  if (sql_command($sql) < 0)
+  // Acquire a mutex to lock out others who might be editing the area
+  if (!sql_mutex_lock("$tbl_area"))
   {
-    fatal_error(1, sql_error());
+    fatal_error(TRUE, get_vocab("failed_to_acquire"));
   }
-  $area = sql_insert_id("$tbl_area", "id");
+  // Check that the area name is unique
+  if (sql_query1("SELECT COUNT(*) FROM $tbl_area WHERE 
area_name='$area_name_q' LIMIT 1") > 0)
+  {
+    $error = "invalid_area_name";
+  }
+  // If so, insert the area into the database
+  else
+  {
+    $sql = "insert into $tbl_area (area_name) values ('$area_name_q')";
+    if (sql_command($sql) < 0)
+    {
+      fatal_error(1, sql_error());
+    }
+    $area = sql_insert_id("$tbl_area", "id");
+  }
+  // Release the mutex
+  sql_mutex_unlock("$tbl_area");
 }
 
 if ($type == "room")
@@ -49,12 +65,29 @@
   {
     $capacity = 0;
   }
-  $sql = "insert into $tbl_room (room_name, area_id, description, capacity)
-          values ('$room_name_q',$area, '$description_q',$capacity)";
-  if (sql_command($sql) < 0)
+  // Acquire a mutex to lock out others who might be editing rooms
+  if (!sql_mutex_lock("$tbl_room"))
   {
-    fatal_error(1, sql_error());
+    fatal_error(TRUE, get_vocab("failed_to_acquire"));
   }
+  // Check that the room name is unique within the area
+  if (sql_query1("SELECT COUNT(*) FROM $tbl_room WHERE 
room_name='$room_name_q' AND area_id=$area LIMIT 1") > 0)
+  {
+    $error = "invalid_room_name";
+  }
+  // If so, insert the room into the datrabase
+  else
+  {
+    $sql = "insert into $tbl_room (room_name, area_id, description, capacity)
+            values ('$room_name_q',$area, '$description_q',$capacity)";
+    if (sql_command($sql) < 0)
+    {
+      fatal_error(1, sql_error());
+    }
+  }
+  // Release the mutex
+  sql_mutex_unlock("$tbl_room");
 }
 
-header("Location: admin.php?area=$area");
+$returl = "admin.php?area=$area" . (!empty($error) ? "&error=$error" : "");
+header("Location: $returl");

Modified: mrbs/trunk/web/admin.php
===================================================================
--- mrbs/trunk/web/admin.php    2009-04-22 15:22:32 UTC (rev 1098)
+++ mrbs/trunk/web/admin.php    2009-04-22 15:58:21 UTC (rev 1099)
@@ -15,6 +15,7 @@
 $area = get_form_var('area', 'int');
 $room = get_form_var('room', 'int');
 $area_name = get_form_var('area_name', 'string');
+$error = get_form_var('error', 'string');
 
 // If we dont know the right date then make it up 
 if (!isset($day) or !isset($month) or !isset($year))
@@ -53,10 +54,15 @@
     sql_free($res);
   }
 }
-?>
 
-<h2><?php echo get_vocab("administration") ?></h2>
 
+echo "<h2>" . get_vocab("administration") . "</h2>\n";
+if (!empty($error))
+{
+  echo "<p class=\"error\">" . get_vocab($error) . "</p>\n";
+}
+
+?>
 <table id="admin" class="admin_table">
   <thead>
     <tr>

Modified: mrbs/trunk/web/edit_area_room.php
===================================================================
--- mrbs/trunk/web/edit_area_room.php   2009-04-22 15:22:32 UTC (rev 1098)
+++ mrbs/trunk/web/edit_area_room.php   2009-04-22 15:58:21 UTC (rev 1099)
@@ -102,6 +102,7 @@
 if (!empty($room))
 {
   $valid_area = TRUE;
+  $valid_room_name = TRUE;
   // validate the email addresses
   $valid_email = validate_email_list($room_admin_email);
   
@@ -122,7 +123,12 @@
     {
       $valid_area = FALSE;
     }
-    // If so, update the databasae
+    // If so, check that the room name is not already used in the area
+    elseif (sql_query1("SELECT COUNT(*) FROM $tbl_room WHERE room_name='" . 
addslashes($room_name) . "' AND area_id=$new_area LIMIT 1") > 0)
+    {
+      $valid_room_name = FALSE;
+    }
+    // If everything is still OK, update the databasae
     else
     {
       $sql = "UPDATE $tbl_room SET room_name='" . addslashes($room_name)
@@ -136,7 +142,7 @@
     }
     
     // Release the mutex
-    sql_mutex_unlock("$tbl_entry");
+    sql_mutex_unlock("$tbl_area");
   }
 
   $res = sql_query("SELECT * FROM $tbl_room WHERE id=$room");
@@ -156,10 +162,11 @@
     <legend></legend>
       <span class="error">
          <?php 
-         // It's impossible to have both these error messages, so no need to 
worry
+         // It's impossible to have more than one of these error messages, so 
no need to worry
          // about paragraphs or line breaks.
          echo ((FALSE == $valid_email) ? get_vocab('invalid_email') : "");
          echo ((FALSE == $valid_area) ? get_vocab('invalid_area') : "");
+         echo ((FALSE == $valid_room_name) ? get_vocab('invalid_room_name') : 
"");
          ?>
       </span>
     </fieldset>

Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en      2009-04-22 15:22:32 UTC (rev 1098)
+++ mrbs/trunk/web/lang.en      2009-04-22 15:58:21 UTC (rev 1099)
@@ -237,6 +237,7 @@
 $vocab["capacity"]           = "Capacity";
 $vocab["norooms"]            = "No rooms have been defined.";
 $vocab["administration"]     = "Administration";
+$vocab["invalid_area_name"]  = "This area name has already been used!";
 
 // Used in edit_area_room.php
 $vocab["editarea"]               = "Edit Area";
@@ -256,6 +257,7 @@
 $vocab["area_res_mins"]          = "Resolution (minutes)";
 $vocab["area_def_duration_mins"] = "Default duration (minutes)";
 $vocab["invalid_area"]           = "Invalid area!";
+$vocab["invalid_room_name"]      = "This room name has already been used in 
the area!";
 $vocab["invalid_email"]          = "Invalid email!";
 $vocab["invalid_resolution"]     = "Invalid combination of first slot, last 
slot and resolution!";
 $vocab["too_many_slots"]         = 'You need to increase the value of 
$max_slots in the config file!';


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

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to