Revision: 1094
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1094&view=rev
Author:   cimorrison
Date:     2009-04-22 14:29:36 +0000 (Wed, 22 Apr 2009)

Log Message:
-----------
Added the ability to move a room between areas when editing a room.

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

Modified: mrbs/trunk/web/edit_area_room.php
===================================================================
--- mrbs/trunk/web/edit_area_room.php   2009-04-16 14:39:16 UTC (rev 1093)
+++ mrbs/trunk/web/edit_area_room.php   2009-04-22 14:29:36 UTC (rev 1094)
@@ -13,6 +13,7 @@
 $month = get_form_var('month', 'int');
 $year = get_form_var('year', 'int');
 $area = get_form_var('area', 'int');
+$new_area = get_form_var ('new_area', 'int');
 $room = get_form_var('room', 'int');
 $room_name = get_form_var('room_name', 'string');
 $area_name = get_form_var('area_name', 'string');
@@ -100,6 +101,7 @@
 <?php
 if (!empty($room))
 {
+  $valid_area = TRUE;
   // validate the email addresses
   $valid_email = validate_email_list($room_admin_email);
   
@@ -109,14 +111,32 @@
     {
       $capacity = 0;
     }
-    $sql = "UPDATE $tbl_room SET room_name='" . addslashes($room_name)
-      . "', description='" . addslashes($description)
-      . "', capacity=$capacity, room_admin_email='"
-      . addslashes($room_admin_email) . "' WHERE id=$room";
-    if (sql_command($sql) < 0)
+    
+    // Acquire a mutex to lock out others who might be deleting the new area
+    if (!sql_mutex_lock("$tbl_area"))
     {
-      fatal_error(0, get_vocab("update_room_failed") . sql_error());
+      fatal_error(TRUE, get_vocab("failed_to_acquire"));
     }
+    // Check the new area still exists
+    if (sql_query1("SELECT COUNT(*) FROM $tbl_area WHERE id=$new_area LIMIT 
1") < 1)
+    {
+      $valid_area = FALSE;
+    }
+    // If so, update the databasae
+    else
+    {
+      $sql = "UPDATE $tbl_room SET room_name='" . addslashes($room_name)
+        . "', description='" . addslashes($description)
+        . "', capacity=$capacity, area_id=$new_area, room_admin_email='"
+        . addslashes($room_admin_email) . "' WHERE id=$room";
+      if (sql_command($sql) < 0)
+      {
+        fatal_error(0, get_vocab("update_room_failed") . sql_error());
+      }
+    }
+    
+    // Release the mutex
+    sql_mutex_unlock("$tbl_entry");
   }
 
   $res = sql_query("SELECT * FROM $tbl_room WHERE id=$room");
@@ -135,13 +155,47 @@
     <fieldset>
     <legend></legend>
       <span class="error">
-         <?php echo ((FALSE == $valid_email) ? get_vocab('invalid_email') : 
"&nbsp;"); ?>
+         <?php 
+         // It's impossible to have both 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') : "");
+         ?>
       </span>
     </fieldset>
     
     <input type="hidden" name="room" value="<?php echo $row["id"]?>">
     
+    <?php
+    $res = sql_query("SELECT id, area_name FROM $tbl_area");
+    if (!$res)
+    {
+      fatal_error(FALSE, "Fatal error: " . sql_error);  // should not happen
+    }
+    if (sql_count($res) == 0)
+    {
+      fatal_error(FALSE, get_vocab('noareas'));  // should not happen
+    }
+    ?>
     <div>
+    <label for="new_area"><?php echo get_vocab("area") ?>:</label>
+    <select id="new_area" name="new_area">
+      <?php  
+      for ($i = 0; ($row_area = sql_row_keyed($res, $i)); $i++)
+      {
+        echo "<option value=\"" . $row_area['id'] . "\"";
+        if ($row_area['id'] == $row['area_id'])
+        {
+          echo " selected=\"selected\"";
+        }
+        echo ">" . $row_area['area_name'] . "</option>\n";
+      }
+      sql_free($res);   
+      ?>
+    </select>
+    </div>
+    
+    <div>
     <label for="room_name"><?php echo get_vocab("name") ?>:</label>
     <input type="text" id="room_name" name="room_name" value="<?php echo 
htmlspecialchars($row["room_name"]); ?>">
     </div>
@@ -178,6 +232,8 @@
 }
 ?>
 
+
+
 <?php
 if (!empty($area))
 {

Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en      2009-04-16 14:39:16 UTC (rev 1093)
+++ mrbs/trunk/web/lang.en      2009-04-22 14:29:36 UTC (rev 1094)
@@ -62,6 +62,7 @@
 $vocab["years"]              = "years";
 $vocab["periods"]            = "periods";
 $vocab["all_day"]            = "All day";
+$vocab["area"]               = "Area";
 $vocab["type"]               = "Type";
 $vocab["internal"]           = "Internal";
 $vocab["external"]           = "External";
@@ -227,14 +228,14 @@
 $vocab["delete"]             = "Delete";
 $vocab["rooms"]              = "Rooms";
 $vocab["in"]                 = "in";
-$vocab["noareas"]            = "No Areas";
+$vocab["noareas"]            = "No areas have been defined.";
 $vocab["addarea"]            = "Add Area";
 $vocab["name"]               = "Name";
 $vocab["noarea"]             = "No area selected";
 $vocab["browserlang"]        = "Your browser is set with the following 
language preference order";
 $vocab["addroom"]            = "Add Room";
 $vocab["capacity"]           = "Capacity";
-$vocab["norooms"]            = "No rooms.";
+$vocab["norooms"]            = "No rooms have been defined.";
 $vocab["administration"]     = "Administration";
 
 // Used in edit_area_room.php
@@ -254,6 +255,7 @@
 $vocab["area_last_slot_start"]   = "Start of last slot";
 $vocab["area_res_mins"]          = "Resolution (minutes)";
 $vocab["area_def_duration_mins"] = "Default duration (minutes)";
+$vocab["invalid_area"]           = "Invalid 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