Revision: 1309
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1309&view=rev
Author:   cimorrison
Date:     2010-03-21 18:16:42 +0000 (Sun, 21 Mar 2010)

Log Message:
-----------
Extended edit_users so that it can display textareas and checkboxes for user 
defined fields, as well as just text inputs.

Modified Paths:
--------------
    mrbs/trunk/web/admin.php
    mrbs/trunk/web/edit_area_room.php
    mrbs/trunk/web/edit_users.php
    mrbs/trunk/web/mrbs-ielte6.css
    mrbs/trunk/web/mrbs.css.php
    mrbs/trunk/web/systemdefaults.inc.php

Modified: mrbs/trunk/web/admin.php
===================================================================
--- mrbs/trunk/web/admin.php    2010-03-21 10:38:46 UTC (rev 1308)
+++ mrbs/trunk/web/admin.php    2010-03-21 18:16:42 UTC (rev 1309)
@@ -2,8 +2,6 @@
 
 // $Id$
 
-define ('MAX_TEXT_LENGTH', 20);   // the maximum number of characters to 
display in the room table
-
 require_once "defaultincludes.inc";
 
 // Get form variables
@@ -202,9 +200,9 @@
     // achieve a "Freeze Panes" effect: there doesn't seem to be a good way of
     // getting a colgroup to scroll, so we have to distort the mark-up a 
little]
     
-    echo "<div id=\"room_info\">\n";
-    // (a) the "header" column containing the room names
-    echo "<div id=\"header_column\">\n";
+    echo "<div id=\"room_info\" class=\"freeze_panes\">\n";
+    // (a) the "header" columns containing the room names
+    echo "<div class=\"header_columns\">\n";
     echo "<table class=\"admin_table\">\n";
     echo "<thead>\n";
     echo "<tr>\n";
@@ -250,7 +248,7 @@
     echo "</div>\n";
     
     // (b) the "body" columns containing the room info
-    echo "<div id=\"body_columns\">\n";
+    echo "<div class=\"body_columns\">\n";
     echo "<table class=\"admin_table\">\n";
     echo "<thead>\n";
     echo "<tr>\n";
@@ -323,8 +321,8 @@
                 // strings
                 $text = htmlspecialchars($r[$field['name']]);
                 echo "<td title=\"$text\"><div>";
-                echo substr($text, 0, MAX_TEXT_LENGTH);
-                echo (strlen($text) > MAX_TEXT_LENGTH) ? " ..." : "";
+                echo substr($text, 0, $max_content_length);
+                echo (strlen($text) > $max_content_length) ? " ..." : "";
                 echo "</div></td>\n";
               }
               break;

Modified: mrbs/trunk/web/edit_area_room.php
===================================================================
--- mrbs/trunk/web/edit_area_room.php   2010-03-21 10:38:46 UTC (rev 1308)
+++ mrbs/trunk/web/edit_area_room.php   2010-03-21 18:16:42 UTC (rev 1309)
@@ -20,7 +20,7 @@
 // char(n)      character(n)          text/textarea, depending on the value of 
n
 //
 // NOTE 1: For char(n) and varchar(n) fields, a text input will be presented if
-// n is less than or equal to TEXT_INPUT_MAX, otherwise a textarea box will be
+// n is less than or equal to $text_input_max, otherwise a textarea box will be
 // presented.
 //
 // NOTE 2: PostgreSQL booleans are not supported, due to difficulties in
@@ -42,10 +42,6 @@
 // If MRBS can't find an entry for the field in the lang file, then it will use
 // the fieldname, eg 'coffee_machine'.
 
-define('TEXT_INPUT_MAX', 70);   // Maximum size in characters of a user defined
-                                // column for a text input to be used.  
Greater than
-                                // this and a textarea will be used
-
 require_once "defaultincludes.inc";
 
 require_once "mrbs_sql.inc";
@@ -206,39 +202,31 @@
     {
       $sql = "UPDATE $tbl_room SET ";
       $n_fields = count($fields);
-      $first_field = TRUE;
+      $assign_array = array();
       foreach ($fields as $field)
       {
         if ($field['name'] != 'id')  // don't do anything with the id field
         {
-          if (!$first_field)
-          {
-            $sql .= ", ";
-          }
-          else
-          {
-            $first_field = FALSE;
-          }
           switch ($field['name'])
           {
             // first of all deal with the standard MRBS fields
             case 'area_id':
-              $sql .= "area_id=$new_area";
+              $assign_array[] = "area_id=$new_area";
               break;
             case 'room_name':
-              $sql .= "room_name='" . addslashes($room_name) . "'";
+              $assign_array[] = "room_name='" . addslashes($room_name) . "'";
               break;
             case 'sort_key':
-              $sql .= "sort_key='" . addslashes($sort_key) . "'";
+              $assign_array[] = "sort_key='" . addslashes($sort_key) . "'";
               break;
             case 'description':
-              $sql .= "description='" . addslashes($description) . "'";
+              $assign_array[] = "description='" . addslashes($description) . 
"'";
               break;
             case 'capacity':
-              $sql .= "capacity=$capacity";
+              $assign_array[] = "capacity=$capacity";
               break;
             case 'room_admin_email':
-              $sql .= "room_admin_email='" . addslashes($room_admin_email) . 
"'";
+              $assign_array[] = "room_admin_email='" . 
addslashes($room_admin_email) . "'";
               break;
             // then look at any user defined fields
             default:
@@ -255,12 +243,12 @@
                   $$var = "'" . addslashes($$var) . "'";
                   break;
               }
-              $sql .= $field['name'] . "=" . $$var;
+              $assign_array[] = $field['name'] . "=" . $$var;
               break;
           }
         }
       }
-      $sql .= " WHERE id=$room";
+      $sql .= implode(",", $assign_array) . " WHERE id=$room";
       if (sql_command($sql) < 0)
       {
         fatal_error(0, get_vocab("update_room_failed") . sql_error());
@@ -520,7 +508,7 @@
               }
               // Output a textarea if it's a character string longer than the 
limit for a
               // text input
-              elseif (($field['nature'] == 'character') && 
isset($field['length']) && ($field['length'] > TEXT_INPUT_MAX))
+              elseif (($field['nature'] == 'character') && 
isset($field['length']) && ($field['length'] > $text_input_max))
               {
                 echo "<textarea rows=\"8\" cols=\"40\" " .
                       "id=\"f_" . $field['name'] . "\" " .

Modified: mrbs/trunk/web/edit_users.php
===================================================================
--- mrbs/trunk/web/edit_users.php       2010-03-21 10:38:46 UTC (rev 1308)
+++ mrbs/trunk/web/edit_users.php       2010-03-21 18:16:42 UTC (rev 1309)
@@ -108,38 +108,8 @@
 }
 
 
-$fields = array();
-$field_props = array();
-
-/* Get the list of fields actually in the table. (Allows the addition of new 
fields later on) */
-function get_fields()
-{
-  global $tbl_users;
-  global $fields, $field_props;
-  array_splice($fields, 0);        // clear out any existing field names
-  array_splice($field_props, 0);   // and properties
-  $result = sql_query("select * from $tbl_users limit 1");
-  $nfields = sql_num_fields($result);
-  for ($i=0; $i<$nfields ;$i++)
-  {
-    $field_name = sql_field_name($result, $i);
-    $fields[] = $field_name;
-    $field_props[$field_name]['type'] = sql_field_type($result, $i);
-    $field_props[$field_name]['istext'] = ($field_props[$field_name]['type'] 
== 'string') ? true : false;
-    $field_props[$field_name]['isnum'] = 
preg_match('/(int|real)/',$field_props[$field_name]['type']) ? true : false;
-    $field_props[$field_name]['isbool'] = ($field_props[$field_name]['type'] 
== 'boolean') ? true : false;
-  }
-  sql_free($result);
-}
-
-
-$nusers = sql_query1("select count(*) from $tbl_users");
-
-// Get the list of fields in the table
-get_fields();
-
 /* Get localized field name */
-function get_loc_field_name($name)
+function get_loc_field_name($table, $name)
 {
   global $vocab;
 
@@ -152,6 +122,157 @@
   return $name;
 }
 
+
+// Get the type that should be used with get_form_var() for
+// a field which is a member of the array returned by get_field_info()
+function get_form_var_type($field)
+{
+  switch($field['nature'])
+  {
+    case 'character':
+      $type = 'string';
+      break;
+    case 'integer':
+      $type = 'int';
+      break;
+    // We can only really deal with the types above at the moment
+    default:
+      $type = 'string';
+      break;
+  }
+  return $type;
+}
+
+
+// Produce the HTML for a freeze_panes sub-table
+//
+//   $info       an array containing the data
+//   $columns    the columns in that data to display
+//   $class      the class name tio assign to the table
+//   $action     whether an action button is required
+function freeze_panes_table_html($info, $columns, $class, $action=FALSE)
+{
+  global $tbl_users, $PHP_SELF;
+  global $user, $level, $min_user_editing_level, $max_content_length;
+  global $fields;
+  
+  $html = '';
+  $html .= "<div class=\"$class\">\n";
+  $html .= "<table class=\"admin_table\">\n";
+  $html .= "<thead>\n";
+  $html .= "<tr>";
+  if ($action)
+  {
+    // First column which is an action button
+    $html .= "<th><div>" . get_vocab("action") . "</div></th>";
+  }
+  
+  // Column headers
+  foreach ($fields as $field)
+  {
+    $fieldname = $field['name'];
+    if (in_array($fieldname, $columns))
+    {
+      $html .= "<th><div>" . get_loc_field_name($tbl_users, $fieldname) . 
"</div></th>";
+    }
+  }
+
+  $html .= "</tr>\n";
+  $html .= "</thead>\n";
+  
+  $html .= "<tbody>\n";
+  $row_class = "odd_row";
+  foreach ($info as $line)
+  {
+    $row_class = ($row_class == "even_row") ? "odd_row" : "even_row";
+    $html .= "<tr class=\"$row_class\">\n";
+    if ($action)
+    {
+      // First column (the action button)
+      $html .= "<td class=\"action\"><div>\n";
+      // You can only edit a user if you have sufficient admin rights, or else 
if that user is yourself
+      if (($level >= $min_user_editing_level) || (strcasecmp($line['name'], 
$user) == 0))
+      {
+        $html .= "<form method=\"post\" action=\"" . 
htmlspecialchars(basename($PHP_SELF)) . "\">\n";
+        $html .= "<div>\n";
+        $html .= "<input type=\"hidden\" name=\"Action\" value=\"Edit\">\n";
+        $html .= "<input type=\"hidden\" name=\"Id\" value=\"" . $line['id'] . 
"\">\n";
+        $html .= "<button type=\"submit\" name=\"action\" value=\"edit\" 
title=\"" . get_vocab("edit") . "\">\n";
+        $html .= "<img src=\"images/edit.png\" width=\"16\" height=\"16\" 
alt=\"" . get_vocab("edit") . "\">\n";
+        $html .= "</button>\n";
+        $html .= "</div>\n";
+        $html .= "</form>\n";
+      }
+      else
+      {
+        $html .= "&nbsp;\n";
+      }
+      $html .= "</div></td>\n";
+    }
+    
+    // Column contents
+    foreach ($fields as $field)
+    {
+      $key = $field['name'];
+      if (in_array($key, $columns))
+      {
+        $col_value = $line[$key];
+        switch($key)
+        {
+          // special treatment for some fields
+          case 'level':
+            // the level field contains a code and we want to display a string
+            $html .= "<td><div>" . get_vocab("level_$col_value") . 
"</div></td>\n";
+            break;
+          case 'email':
+            // we don't want to truncate the email address
+            $html .= "<td><div>" . htmlspecialchars($col_value) . 
"</div></td>\n";
+            break;
+          default:
+            if (($field['nature'] == 'boolean') || 
+                (($field['nature'] == 'integer') && isset($field['length']) && 
($field['length'] <= 2)) )
+            {
+              // booleans: represent by a checkmark
+              $html .= "<td class=\"int\"><div>";
+              $html .= (!empty($col_value)) ? "<img src=\"images/check.png\" 
alt=\"check mark\" width=\"16\" height=\"16\">" : "&nbsp;";
+              $html .= "</div></td>\n";
+            }
+            elseif (($field['nature'] == 'integer') && isset($field['length']) 
&& ($field['length'] > 2))
+            {
+              // integer values
+              $html .= "<td class=\"int\"><div>" . $col_value . 
"</div></td>\n";
+            }
+            else
+            {
+              // strings
+              $text = htmlspecialchars($col_value);
+              $html .= "<td title=\"$text\"><div>";
+              $html .= substr($text, 0, $max_content_length);
+              $html .= (strlen($text) > $max_content_length) ? " ..." : "";
+              $html .= "</div></td>\n";
+            }
+            break;
+        }  // end switch
+      }
+    }  // end foreach
+    
+    $html .= "</tr>\n";
+    
+  }  // end while
+  
+  $html .= "</tbody>\n";
+  $html .= "</table>\n";
+  $html .= "</div>\n";
+  
+  return $html;
+}
+
+
+// Get the information about the fields in the users table
+$fields = sql_field_info($tbl_users);
+
+$nusers = sql_query1("SELECT COUNT(*) FROM $tbl_users");
+
 /*---------------------------------------------------------------------------*\
 |                         Authenticate the current user                        
 |
 \*---------------------------------------------------------------------------*/
@@ -205,10 +326,11 @@
     // query string if there was an error on validating the data after it
     // had been submitted.   We want to preserve the user's original values
     // so that they don't have to re-type them).
-    foreach ($fields as $fieldname)
+    foreach ($fields as $field)
     {
-      $value = get_form_var($fieldname, $field_props[$fieldname]['type']);
-      $data[$fieldname] = (isset($value)) ? $value : "";
+      $type = get_form_var_type($field);
+      $value = get_form_var($field['name'], $type);
+      $data[$field['name']] = (isset($value)) ? $value : "";
     }
   }
 
@@ -251,8 +373,9 @@
           // (b) it's the last admin left or (c) they don't have admin rights
           $disable_select = ($initial_user_creation || $editing_last_admin || 
($level < $min_user_editing_level));
           
-          foreach ($fields as $fieldname)
+          foreach ($fields as $field)
           {
+            $fieldname = $field['name'];
             // First of all output the input for the field
             // The ID field cannot change; The password field must not be 
shown.
             switch($fieldname)
@@ -263,70 +386,94 @@
               case 'password':
                 echo "<input type=\"hidden\" name=\"Field_$fieldname\" 
value=\"". htmlspecialchars($data[$fieldname]) . "\">\n";
                 break;
-              case 'level':
+              default:
+                $html_fieldname = htmlspecialchars("Field_$fieldname");
                 echo "<div>\n";
-                echo "<label for=\"Field_$fieldname\">" . 
get_loc_field_name($fieldname) . ":</label>\n";
-                echo "<select id=\"Field_$fieldname\" 
name=\"Field_$fieldname\"" . ($disable_select ? " disabled=\"disabled\"" : "") 
. ">\n";
-                // Only display options up to and including one's own level 
(you can't upgrade yourself).
-                // If you're not some kind of admin then the select will also 
be disabled.
-                // (Note - disabling individual options doesn't work in older 
browsers, eg IE6)     
-                for ($i=0; $i<=$level; $i++)
+                echo "<label for=\"Field_$fieldname\">" . 
get_loc_field_name($tbl_users, $fieldname) . ":</label>\n";
+                switch($fieldname)
                 {
-                  echo "<option value=\"$i\"";
-                  // Work out which option should be selected by default:
-                  //   if we're editing an existing entry, then it should be 
the current value;
-                  //   if we're adding the very first entry, then it should be 
an admin;
-                  //   if we're adding a subsequent entry, then it should be 
an ordinary user;
-                  if ( (($Action == "Edit")  && ($i == $data[$fieldname])) ||
-                       (($Action == "Add") && $initial_user_creation && ($i == 
$max_level)) ||
-                       (($Action == "Add") && !$initial_user_creation && ($i 
== 1)) )
-                  {
-                    echo " selected=\"selected\"";
-                  }
-                  echo ">" . get_vocab("level_$i") . "</option>\n";
-                }
-                echo "</select>\n";
-                // If the level select input was disabled, we still need to 
submit a value with 
-                // the form.   <select> can't be set to 'readonly' so instead 
we'll use a hidden input
-                if ($disable_select)
-                {
-                  if ($initial_user_creation)
-                  {
-                    $v = $max_level;
-                  }
-                  else
-                  {
-                    $v = $data[$fieldname];
-                  }
-                  echo "<input type=\"hidden\" name=\"Field_$fieldname\" 
value=\"$v\">\n";
-                }
+                  case 'level':
+                    echo "<select id=\"Field_$fieldname\" 
name=\"Field_$fieldname\"" . ($disable_select ? " disabled=\"disabled\"" : "") 
. ">\n";
+                    // Only display options up to and including one's own 
level (you can't upgrade yourself).
+                    // If you're not some kind of admin then the select will 
also be disabled.
+                    // (Note - disabling individual options doesn't work in 
older browsers, eg IE6)     
+                    for ($i=0; $i<=$level; $i++)
+                    {
+                      echo "<option value=\"$i\"";
+                      // Work out which option should be selected by default:
+                      //   if we're editing an existing entry, then it should 
be the current value;
+                      //   if we're adding the very first entry, then it 
should be an admin;
+                      //   if we're adding a subsequent entry, then it should 
be an ordinary user;
+                      if ( (($Action == "Edit")  && ($i == $data[$fieldname])) 
||
+                           (($Action == "Add") && $initial_user_creation && 
($i == $max_level)) ||
+                           (($Action == "Add") && !$initial_user_creation && 
($i == 1)) )
+                      {
+                        echo " selected=\"selected\"";
+                      }
+                      echo ">" . get_vocab("level_$i") . "</option>\n";
+                    }
+                    echo "</select>\n";
+                    // If the level select input was disabled, we still need 
to submit a value with 
+                    // the form.   <select> can't be set to 'readonly' so 
instead we'll use a hidden input
+                    if ($disable_select)
+                    {
+                      if ($initial_user_creation)
+                      {
+                        $v = $max_level;
+                      }
+                      else
+                      {
+                        $v = $data[$fieldname];
+                      }
+                      echo "<input type=\"hidden\" name=\"Field_$fieldname\" 
value=\"$v\">\n";
+                    }
+                    break;
+                  case 'name':
+                    // you cannot change a username (even your own) unless you 
have user editing rights
+                    echo "<input id=\"$html_fieldname\" 
name=\"$html_fieldname\" type=\"text\" " .
+                          "maxlength=\"" . $maxlength['users.name'] . "\" " .
+                         (($level < $min_user_editing_level) ? 
"disabled=\"disabled\" " : "") .
+                          "value=\"" . htmlspecialchars($data[$fieldname]) . 
"\">\n";
+                    // if the field was disabled then we still need to pass 
through the value as a hidden input
+                    if ($level < $min_user_editing_level)
+                    {
+                      echo "<input type=\"hidden\" name=\"Field_$fieldname\" 
value=\"" . $data[$fieldname] . "\">\n";
+                    }
+                    break;
+                  case 'email':
+                    echo "<input id=\"$html_fieldname\" 
name=\"$html_fieldname\" type=\"text\" " .
+                          (isset($maxlength["users.$fieldname"]) ? 
"maxlength=\"" . $maxlength["users.$fieldname"] . "\" " : "") .
+                          "value=\"" . htmlspecialchars($data[$fieldname]) . 
"\">\n";
+                    break;
+                  default:    
+                    // Output a checkbox if it's a boolean or integer <= 2 
bytes (which we will
+                    // assume are intended to be booleans)
+                    if (($field['nature'] == 'boolean') || 
+                        (($field['nature'] == 'integer') && 
isset($field['length']) && ($field['length'] <= 2)) )
+                    {
+                      echo "<input type=\"checkbox\" class=\"checkbox\" " .
+                            "id=\"$html_fieldname\" name=\"$html_fieldname\" 
value=\"1\"" .
+                            ((!empty($data[$fieldname])) ? " 
checked=\"checked\"" : "") .
+                            ">\n";
+                    }
+                    // Output a textarea if it's a character string longer 
than the limit for a
+                    // text input
+                    elseif (($field['nature'] == 'character') && 
isset($field['length']) && ($field['length'] > $text_input_max))
+                    {
+                      echo "<textarea rows=\"8\" cols=\"40\" 
id=\"$html_fieldname\" name=\"$html_fieldname\">\n";
+                      echo htmlspecialchars($data[$fieldname]);
+                      echo "</textarea>\n";
+                    }
+                    // Otherwise output a text input
+                    else
+                    {
+                      echo "<input id=\"$html_fieldname\" 
name=\"$html_fieldname\" type=\"text\" " .
+                           (isset($maxlength["users.$fieldname"]) ? 
"maxlength=\"" . $maxlength["users.$fieldname"] . "\" " : "") .
+                            "value=\"" . htmlspecialchars($data[$fieldname]) . 
"\">\n";
+                    }
+                    break;
+                } // end switch
                 echo "</div>\n";
-                break;
-              case 'name':
-                // you cannot change a username (even your own) unless you 
have user editing rights
-                $html_fieldname = htmlspecialchars("Field_$fieldname");
-                echo ("<div>\n");
-                echo ("<label for=\"$html_fieldname\">" . 
get_loc_field_name($fieldname) . ":</label>\n");
-                echo ("<input id=\"$html_fieldname\" name=\"$html_fieldname\" 
type=\"text\" " .
-                      "maxlength=\"" . $maxlength['users.name'] . "\" " .
-                     (($level < $min_user_editing_level) ? 
"disabled=\"disabled\" " : "") .
-                      "value=\"" . htmlspecialchars($data[$fieldname]) . 
"\">\n");
-                // if the field was disabled then we still need to pass 
through the value as a hidden input
-                if ($level < $min_user_editing_level)
-                {
-                  echo "<input type=\"hidden\" name=\"Field_$fieldname\" 
value=\"" . $data[$fieldname] . "\">\n";
-                }
-                echo ("</div>\n");
-                break;
-              default:
-                $html_fieldname = htmlspecialchars("Field_$fieldname");
-                echo ("<div>\n");
-                echo ("<label for=\"$html_fieldname\">" . 
get_loc_field_name($fieldname) . ":</label>\n");
-                echo ("<input id=\"$html_fieldname\" name=\"$html_fieldname\" 
type=\"text\" " .
-                     (isset($maxlength["users.$fieldname"]) ? "maxlength=\"" . 
$maxlength["users.$fieldname"] . "\" " : "") .
-                      "value=\"" . htmlspecialchars($data[$fieldname]) . 
"\">\n");
-                echo ("</div>\n");
-                break;
             } // end switch
             
             
@@ -337,7 +484,7 @@
               case 'email':
                 if (!empty($invalid_email))
                 {
-                  echo "<p class=\"error\">" . get_vocab('invalid_email') . 
"<p>\n";
+                  echo "<p class=\"error\">" . get_vocab('invalid_email') . 
"</p>\n";
                 }
                 break;
               case 'name':
@@ -435,8 +582,10 @@
   {
     $values = array();
     $q_string = ($Id >= 0) ? "Action=Edit" : "Action=Add";
-    foreach ($fields as $fieldname)
+    foreach ($fields as $field)
     {
+      $fieldname = $field['name'];
+      $type = get_form_var_type($field);
       if ($fieldname == 'id')
       {
         // id: don't need to do anything except add the id to the query string;
@@ -446,7 +595,7 @@
       }
       // first, get all the other form variables and put them into an array, 
$values, which 
       // we will use for entering into the database assuming we pass validation
-      $values[$fieldname] = get_form_var("Field_$fieldname", 
$field_props[$fieldname]['type']);
+      $values[$fieldname] = get_form_var("Field_$fieldname", $type);
       // Truncate the field to the maximum length as a precaution.
       if (isset($maxlength["users.$fieldname"]))
       {
@@ -576,44 +725,30 @@
     $sql_fields = array();
   
     // For each db column get the value ready for the database
-    foreach ($values as $fieldname => $value)
+    foreach ($fields as $field)
     {
-      // pre-process the field value for SQL
-      if ($field_props[$fieldname]['istext'])
+      $fieldname = $field['name'];
+      if ($fieldname != 'id')
       {
-        $value = "'" . addslashes($value) . "'";
-      }
-      else if ($field_props[$fieldname]['isbool'])
-      {
-        if ($value && $value == true)
+        // pre-process the field value for SQL
+        $value = $values[$fieldname];
+        switch ($field['nature'])
         {
-          $value = "TRUE";
+          case 'integer':
+            if (!isset($value))
+            {
+              $value = 'NULL';
+            }
+            break;
+          default:
+            $value = "'" . addslashes($value) . "'";
+            break;
         }
-        else
-        {
-          $value = "FALSE";
-        }
-      }
-      else
-      {
-        // put in a sensible default for a missing field
-        if (($value == null) || ($value == ''))
-        {
-          if ($field_props[$fieldname]['isnum'])
-          {
-           $value = "0";
-          }
-          else
-          {
-            $value = "NULL";
-          }
-        }
-      }
-      
-      /* If we got here, we have a valid, sql-ified value for this field,
-       * so save it for later */
-      $sql_fields[$fieldname] = $value;
-                           
+       
+        /* If we got here, we have a valid, sql-ified value for this field,
+         * so save it for later */
+        $sql_fields[$fieldname] = $value;
+      }                   
     } /* end for each column of user database */
   
     /* Now generate the SQL operation based on the given array of fields */
@@ -742,76 +877,37 @@
 
 if ($initial_user_creation != 1)   // don't print the user table if there are 
no users
 {
-  $list = sql_query("SELECT * FROM $tbl_users ORDER BY level DESC, name");
-  print "<table id=\"edit_users_list\" class=\"admin_table\">\n";
-  print "<thead>\n";
-  print "<tr>";
-  // First column which is an action button
-  print "<th>" . get_vocab("action") . "</th>";
-  
-  // Column headers (we don't use 'id' and 'password')
-  foreach ($fields as $fieldname)
+  // Get the user information
+  $res = sql_query("SELECT * FROM $tbl_users ORDER BY level DESC, name");
+  // Build an array with the user info
+  $info = array();
+  for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   {
-    if ($fieldname != 'id' && $fieldname != 'password')
-    {
-      print "<th>" . get_loc_field_name($fieldname) . "</th>";
-    }
+    $info[] = $row;
   }
-
-  print "</tr>\n";
-  print "</thead>\n";
+  // Display it in a table [Actually two tables side by side so that we can
+  // achieve a "Freeze Panes" effect: there doesn't seem to be a good way of
+  // getting a colgroup to scroll, so we have to distort the mark-up a little]
+  echo "<div id=\"user_list\">\n";
+  echo "<div class=\"freeze_panes\">\n";
+  // (a) the "header" columns containing the user names
+  // For the header column we just want to use the level and name fields
+  $columns = array('level', 'name');
+  echo freeze_panes_table_html($info, $columns, 'header_columns', TRUE);
   
-  print "<tbody>\n";
-  $i = 0;
-  $row_class = "odd_row";
-  while ($line = sql_row_keyed($list, $i++))
+  // (b) the "body" columns containing the user info
+  // For the body column we want all the other columns, except the id and 
password
+  $columns[] = 'id';
+  $columns[] = 'password';
+  $all_columns = array();
+  foreach ($fields as $field)
   {
-    $row_class = ($row_class == "even_row") ? "odd_row" : "even_row";
-    echo "<tr class=\"$row_class\">\n";
-    // First column (the action button)
-    print "<td style=\"text-align: center\">\n";
-    // You can only edit a user if you have sufficient admin rights, or else 
if that user is yourself
-    if (($level >= $min_user_editing_level) || (strcasecmp($line['name'], 
$user) == 0))
-    {
-      echo "<form method=\"post\" action=\"" . 
htmlspecialchars(basename($PHP_SELF)) . "\">\n";
-      echo "<div>\n";
-      echo "<input type=\"hidden\" name=\"Action\" value=\"Edit\">\n";
-      echo "<input type=\"hidden\" name=\"Id\" value=\"" . $line['id'] . 
"\">\n";
-      echo "<button type=\"submit\" name=\"action\" value=\"edit\" title=\"" . 
get_vocab("edit") . "\">\n";
-      echo "<img src=\"images/edit.png\" width=\"16\" height=\"16\" alt=\"" . 
get_vocab("edit") . "\">\n";
-      echo "</button>\n";
-      echo "</div>\n";
-      echo "</form>\n";
-    }
-    else
-    {
-      print "&nbsp;\n";
-    }
-    print "</td>\n";
-    
-    // Column contents
-    foreach ($line as $key=>$col_value) 
-    { 
-      switch($key)
-      {
-        case 'id':
-        case 'password':
-          break;                  // Don't display the id or password
-        case 'level':
-          echo "<td>" . get_vocab("level_$col_value") . "</td>\n";
-          break;
-        default:
-          echo "<td>" . ((empty($col_value)) ? "&nbsp;" : 
htmlspecialchars($col_value)) . "</td>\n";
-          break;
-      }  // end switch   
-    }  // end foreach
-    
-    print "</tr>\n";
-    
-  }  // end while
-  
-  print "</tbody>\n";
-  print "</table>\n";
+    $all_columns[] = $field['name'];
+  }
+  $columns = array_diff($all_columns, $columns);
+  echo freeze_panes_table_html($info, $columns, 'body_columns', FALSE);
+  echo "</div>\n";   // freeze_panes
+  echo "</div>\n";
 }   // ($initial_user_creation != 1)
 
 require_once "trailer.inc";

Modified: mrbs/trunk/web/mrbs-ielte6.css
===================================================================
--- mrbs/trunk/web/mrbs-ielte6.css      2010-03-21 10:38:46 UTC (rev 1308)
+++ mrbs/trunk/web/mrbs-ielte6.css      2010-03-21 18:16:42 UTC (rev 1309)
@@ -8,9 +8,9 @@
 .form_admin label {height: 2.0em}            /* min-height not recognised by 
IE6 and below */
 .form_admin input {margin-top: 0}            /* negative margins remove the 
input border in IE6 */
 .form_admin input.submit {display: inline}   /* stops IE6 "double margin float 
bug" appearing */
-div#header_column {width: 20%}               /* IE6 doesn't understand 
max-width */
-#header_column table {width: 100%}           /* so force the table to fill all 
of the 20% */
-div#body_columns {width: 80%}
+div.header_columns {width: 20%}              /* IE6 doesn't understand 
max-width */
+.header_columns table {width: 100%}          /* so force the table to fill all 
of the 20% */
+div.body_columns {width: 80%}
 
 /* ------------ DAY/WEEK/MONTH.PHP ------------------*/
 div.cell_container {height: 100px}           /* NOTE:  if you change the value 
of height, make sure you */

Modified: mrbs/trunk/web/mrbs.css.php
===================================================================
--- mrbs/trunk/web/mrbs.css.php 2010-03-21 10:38:46 UTC (rev 1308)
+++ mrbs/trunk/web/mrbs.css.php 2010-03-21 18:16:42 UTC (rev 1309)
@@ -70,8 +70,16 @@
 .admin_table th {color: <?php echo $admin_table_header_font_color ?>; 
     background-color: <?php echo $admin_table_header_back_color ?>}
 .admin_table td, .admin_table th {border-color: <?php echo 
$admin_table_border_color ?>}
-.admin_table th:first-child {border-left-color: <?php echo 
$admin_table_header_back_color ?>}    
-    
+.admin_table th:first-child {border-left-color: <?php echo 
$admin_table_header_back_color ?>}
+.admin_table td.action {text-align: center}
+.admin_table td.action div {display: inline-block}   
+
+div.freeze_panes {width: 100%; float: left}
+.freeze_panes th div, .freeze_panes td div {display: table-cell; 
vertical-align: middle; white-space: nowrap; overflow: hidden}
+.freeze_panes th div {height: 1.5em; max-height: 1.5em; min-height: 1.5em}
+.freeze_panes td div {height: 2em; max-height: 2em; min-height: 2em}
+.freeze_panes td.int div {width: 6em; text-align: right; padding-right: 0.5em}
+   
 select.room_area_select {margin-right: 0.5em}
 
 /* ------------ ADMIN.PHP ---------------------------*/
@@ -108,16 +116,11 @@
 #areaChangeForm input {float: left; margin: -0.2em 0.5em 0 0}
 #areaChangeForm button {display: block; float: left; margin: -0.2em 0.5em 0 
0.5em}
 
-div#room_info {width: 100%; float: left}
-div#header_column, div#body_columns {position: relative; float: left; 
overflow-x: scroll; overflow-y: hidden}
-div#header_column {max-width: 20%}
-div#body_columns {max-width: 80%}
+div.header_columns, div.body_columns {position: relative; float: left; 
overflow-x: scroll; overflow-y: hidden}
+div.header_columns {max-width: 20%}
+div.body_columns {max-width: 80%}
 
-#room_info th div, #room_info td div {display: table-cell; vertical-align: 
middle; white-space: nowrap; overflow: hidden}
-#room_info th div {height: 1.5em; max-height: 1.5em; min-height: 1.5em}
-#room_info td div {height: 2em; max-height: 2em; min-height: 2em}
-#room_info td.int div {width: 6em; text-align: right; padding-right: 0.5em}
-#body_columns .admin_table th:first-child {border-left-color: <?php echo 
$admin_table_border_color ?>}
+.body_columns .admin_table th:first-child {border-left-color: <?php echo 
$admin_table_border_color ?>}
 
 
 /* ------------ DAY/WEEK/MONTH.PHP ------------------*/
@@ -593,8 +596,6 @@
 $edit_users_label_width      = '10.0';   // em
 $edit_users_gap              = '1.0';    // em
 $edit_users_input_width      = '10.0';   // em
-$edit_users_form_width       = $edit_users_label_width + $edit_users_gap + 
$edit_users_input_width + 5;
-$edit_users_form_width       = number_format($edit_users_form_width, 1, '.', 
'');   // get rid of any commas
 // This CSS works by using absolute positioning to bring the Delete button up 
into the main form.
 // Logically the HTML for the Delete button is implemented and because you 
can't nest a form within
 // a form it appears as a second form after the main form.    However, to the 
user it is more logical to
@@ -604,11 +605,11 @@
 // users by mistake.    Having it on the edit form at least means that you 
have to press two buttons to
 // delete a user (the Edit button followed by the Delete button)]
 ?>
-div#form_container {position: relative; float: left}    /* this is the 
containing block against which the absolute positioning works */
+div#form_container {width: auto; position: relative; float: left}    /* this 
is the containing block against which the absolute positioning works */
 #form_container input.submit {width: auto; position: absolute; bottom: 2.0em}  
/* bring both buttons up          */
-form#form_edit_users {width: <?php echo $edit_users_form_width ?>em; 
margin-top: 2.0em}
-#form_edit_users fieldset {width: auto}  
-#form_edit_users div {float: left; width: 100%}
+form#form_edit_users {width: auto; margin-top: 2.0em}
+#form_edit_users fieldset {float: left; width: auto}  
+#form_edit_users div {float: left; clear: left; width: auto}
 #form_edit_users div#edit_users_input_container {padding-bottom: 4.0em}    /* 
padding-bottom leaves room for the submit buttons. */
                                                                            /* 
Apply it to the div because applying it to the     */
                                                                            /* 
fieldset does not work in all browsers (eg Safari) */
@@ -623,14 +624,19 @@
     width: <?php echo $edit_users_input_width ?>em; 
     margin-left: <?php echo $edit_users_gap ?>em; 
 }
-#form_edit_users select {
+#form_edit_users select, #form_edit_users textarea {
     margin-left: <?php echo $edit_users_gap ?>em;
 }
+#form_edit_users p {display: block; float: left; clear: left; padding: 0.5em 0 
0.7em 0; margin: 0}
 #form_edit_users input.submit {right: 2.0em}                                   
/* and put the OK on the right     */
 #form_delete_users input.submit {left: 2.0em}                                  
/* and put the Delete on the left */
+#form_edit_users input.checkbox {width: auto; margin-left: <?php echo 
$edit_users_gap ?>em}
 form.edit_users_error {width: 10em; margin-top: 2.0em}
-table#edit_users_list {margin-top: 1.0em; margin-bottom: 1.0em}
+div#user_list {float: left; width: 95%; padding: 2em 0 2em 1em}
+form#add_new_user {margin-left: 1em}
 
+
+
 /* ------------ FUNCTIONS.INC -------------------*/
 #logon_box a {display: block; width: 100%; padding-top: 0.3em; padding-bottom: 
0.3em}
 table#banner {width: 100%; border-spacing: 0; border-collapse: collapse;

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2010-03-21 10:38:46 UTC (rev 
1308)
+++ mrbs/trunk/web/systemdefaults.inc.php       2010-03-21 18:16:42 UTC (rev 
1309)
@@ -355,10 +355,19 @@
 // accommodate the bookings.   (NOTE: (1) scrolling doesn't work in IE6 and so 
the table
 // cell will always expand in IE6.  (2) In IE8 Beta 2 scrolling doesn't work 
either and
 // the cell content is clipped when $month_cell_scrolling is set to TRUE.)
-$month_cell_scrolling = TRUE;   
+$month_cell_scrolling = TRUE;
+
+// Define the maximum length of a string that can be displayed in an admin 
table cell
+// (eg the rooms and users lists) before it is truncated.  (This is necessary 
because 
+// you don't want a cell to contain for example a 2 kbyte text string, which 
could happen
+// with user defined fields).
+$max_content_length = 20;  // characters
+
+// The maximum length of a database field for which a text input can be used 
on a form
+// (eg when editing a user or room).  If longer than this a text area will be 
used.
+$text_input_max = 70;  // characters
                                 
 
-
 /************************
  * Miscellaneous settings
  ************************/


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

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to