Revision: 1457
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1457&view=rev
Author:   cimorrison
Date:     2010-09-17 15:28:10 +0000 (Fri, 17 Sep 2010)

Log Message:
-----------
Added the ability to constrain certain fields (name, description and custom 
fields) in the entry table to a set of values defined in the config file.

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/systemdefaults.inc.php

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2010-09-17 09:57:54 UTC (rev 1456)
+++ mrbs/trunk/web/edit_entry.php       2010-09-17 15:28:10 UTC (rev 1457)
@@ -51,6 +51,49 @@
 require_once "defaultincludes.inc";
 require_once "mrbs_sql.inc";
 
+// Generate an input field with an associated label
+// Optional fourth parameter: $maxlength - the maximum length of input allowed
+function generate_input($label_text, $name, $value)
+{
+  // get any optional fourth parameter
+  if (func_num_args() > 3)
+  {
+    $maxlength = func_get_arg(3);
+  }
+  // generate the HTML
+  $html  = "<label for=\"$name\">$label_text</label>\n";
+  $html .= "<input id=\"$name\" name=\"$name\"";
+  $html .= (isset($maxlength)) ? " maxlength=\"$maxlength\"" : '';
+  $html .= " value=\"" . htmlspecialchars($value) . "\">\n";
+  echo $html;
+}
+
+// Generates a select box from $options, an array of options
+function generate_select($label_text, $name, $value, $options)
+{
+  // generate the HTML
+  $html  = "<label for=\"$name\">$label_text</label>\n";
+  $html .= "<select id=\"$name\" name=\"$name\">\n";
+  foreach ($options as $option)
+  {
+    $html .= "<option";
+    $html .= (isset($value) && ($value == $option)) ? " selected=\"selected\"" 
: '';
+    $html .= ">$option</option>\n";
+  }
+  $html .= "</select>\n";
+  echo $html;
+}
+
+// Generate a textarea with an associated label
+function generate_textarea($label_text, $name, $value)
+{
+  $html  = "<label for=\"$name\">$label_text</label>\n";
+  // textarea rows and cols are overridden by CSS height and width
+  $html .= "<textarea id=\"$name\" name=\"$name\" rows=\"8\" cols=\"40\">" . 
htmlspecialchars ($value) . "</textarea>\n";
+  echo $html;
+}
+    
+
 global $twentyfourhour_format;
 
 // Get non-standard form variables
@@ -539,19 +582,32 @@
   <fieldset>
   <legend><?php echo get_vocab($token); ?></legend>
 
-    <div id="div_name">
-      <label for="name"><?php echo get_vocab("namebooker")?>:</label>
-      <?php
-      echo "<input id=\"name\" name=\"name\" maxlength=\"" . 
$maxlength['entry.name'] . "\" value=\"" . htmlspecialchars($name) . "\">\n";
-      ?>
-    </div>
+    <?php  
+    echo "<div id=\"div_name\">\n";
+    $label_text = get_vocab("namebooker") . ":";
+    if (count($select_options['entry.name']) > 0)
+    {
+      generate_select($label_text, 'name', $name, 
$select_options['entry.name']);  
+    }
+    else
+    {
+      generate_input($label_text, 'name', $name, $maxlength['entry.name']);
+    }
+    echo "</div>\n";
+    
+    echo "<div id=\"div_description\">\n";
+    $label_text = get_vocab("fulldescription");
+    if (count($select_options['entry.description']) > 0)
+    {
+      generate_select($label_text, 'description', $description, 
$select_options['entry.description']);
+    }
+    else
+    {
+      generate_textarea($label_text, 'description', $description);
+    }
+    echo "</div>\n";
+    ?>
 
-    <div id="div_description">
-      <label for="description"><?php echo 
get_vocab("fulldescription")?></label>
-      <!-- textarea rows and cols are overridden by CSS height and width -->
-      <textarea id="description" name="description" rows="8" cols="40"><?php 
echo htmlspecialchars ( $description ); ?></textarea>
-    </div>
-
     <div id="div_date">
       <?php
       echo "<label for=\"start_datepicker\">" . get_vocab("date") . 
":</label>\n";
@@ -847,35 +903,34 @@
       if (!in_array($key, $standard_fields['entry']))
       {
         $value = $custom_fields[$key];
+        $label_text = get_loc_field_name($tbl_entry, $key) . ":";
         echo "<div>\n";
-        echo "<label for=\"f_$key\">" . get_loc_field_name($tbl_entry, $key) . 
":</label>\n";
         // 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 "<label for=\"f_$key\">$label_text</label>\n";
           echo "<input type=\"checkbox\" class=\"checkbox\" " .
                 "id=\"f_$key\" name=\"f_$key\" value=\"1\" " .
                 ((!empty($value)) ? " checked=\"checked\"" : "") .
                 ">\n";
         }
+        // Output a select box if they want one
+        elseif (count($select_options["entry.$key"]) > 0)
+        {
+          generate_select($label_text, "f_$key", $value, 
$select_options["entry.$key"]);
+        }
         // 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=\"f_$key\" name=\"f_$key\" " .
-                ">\n";
-          echo htmlspecialchars($value);
-          echo "</textarea>\n";
+          generate_textarea($label_text, "f_$key", $value);   
         }
         // Otherwise output a text input
         else
         {
-          echo "<input type=\"text\" " .
-                "id=\"f_$key\" name=\"f_$key\" " .
-                "value=\"" . htmlspecialchars($value) . "\"" .
-                ">\n";
+          generate_input($label_text, "f_$key", $value);
         }
         echo "</div>\n";
       }
@@ -933,11 +988,13 @@
           ?>
         </div>
       </div>
-      <div>
-        <label for="rep_num_weeks"><?php echo 
get_vocab("rep_num_weeks")?>:<br><?php echo 
get_vocab("rep_for_nweekly")?></label>
-        <input type="text" id="rep_num_weeks" name="rep_num_weeks" 
value="<?php echo $rep_num_weeks?>">
-      </div>
+     
       <?php
+      echo "<div>\n";
+      $label_text = get_vocab("rep_num_weeks") . ":<br>" . 
get_vocab("rep_for_nweekly");
+      generate_input($label_text, 'rep_num_weeks', $rep_num_weeks);
+      echo "</div>\n";
+
       echo "</fieldset>\n";
     }
     elseif (isset($id))

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2010-09-17 09:57:54 UTC (rev 
1456)
+++ mrbs/trunk/web/systemdefaults.inc.php       2010-09-17 15:28:10 UTC (rev 
1457)
@@ -465,7 +465,28 @@
 // Days of the week that are working days (Sunday = 0, etc.)
 $working_days = array(1,2,3,4,5);  // Mon-Fri
 
+
 /***********************************************
+ * Form values
+ ***********************************************/
+
+// It is possible to constrain some form values to be selected from a drop-
+// down select box, rather than allowing free form input.   This is done by
+// putting the permitted options in an array as part of the $select_options
+// two dimensional array.   The first index specifies the form field in the
+// format tablename.columnname.    For example to restrict the name of a 
booking
+// to 'Physics', 'Chemistry' or 'Biology' uncomment the line below.
+
+//$select_options['entry.name'] = array('Physics', 'Chemistry', 'Biology');
+
+// At the moment this feature is only supported for the name, description and
+// any custom fields in the entry table.   However the indexing format of
+// tablename.columnname has been chosen to allow it to be extended to other
+// tables in the future.
+
+
+ 
+/***********************************************
  * Authentication settings - read AUTHENTICATION
  ***********************************************/
 


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

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to