Revision: 1378
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1378&view=rev
Author:   cimorrison
Date:     2010-07-23 20:15:37 +0000 (Fri, 23 Jul 2010)

Log Message:
-----------
Made edit_entry recognise custom fields - but edit_entry_handler has still to 
be modified, so the custom fields are ignored on Save.

Modified Paths:
--------------
    mrbs/branches/custom_entry_fields/web/edit_entry.php
    mrbs/branches/custom_entry_fields/web/mrbs.css.php

Modified: mrbs/branches/custom_entry_fields/web/edit_entry.php
===================================================================
--- mrbs/branches/custom_entry_fields/web/edit_entry.php        2010-07-23 
17:52:46 UTC (rev 1377)
+++ mrbs/branches/custom_entry_fields/web/edit_entry.php        2010-07-23 
20:15:37 UTC (rev 1378)
@@ -56,8 +56,7 @@
 // If we had $id passed in then it's a modification.
 if (isset($id))
 {
-  $sql = "SELECT name, create_by, description, start_time, end_time,
-                 type, room_id, entry_type, repeat_id, private
+  $sql = "SELECT *
             FROM $tbl_entry
            WHERE id=$id
            LIMIT 1";
@@ -79,24 +78,58 @@
   // for this area.
   $area = get_area($row['room_id']);
   get_area_settings($area);
-
-  $name        = $row['name'];
-  // If we're copying an existing entry then we need to change the create_by 
(they could be
-  // different if it's an admin doing the copying)
-  $create_by   = (isset($copy)) ? $user : $row['create_by'];
-  $description = $row['description'];
-  $start_day   = strftime('%d', $row['start_time']);
-  $start_month = strftime('%m', $row['start_time']);
-  $start_year  = strftime('%Y', $row['start_time']);
-  $start_hour  = strftime('%H', $row['start_time']);
-  $start_min   = strftime('%M', $row['start_time']);
-  $duration    = $row['end_time'] - $row['start_time'] - 
cross_dst($row['start_time'], $row['end_time']);
-  $type        = $row['type'];
-  $room_id     = $row['room_id'];
-  $entry_type  = $row['entry_type'];
-  $rep_id      = $row['repeat_id'];
-  $private     = $row['private'];
-
+  
+  $custom_fields = array();
+  foreach ($row as $column => $value)
+  {
+    switch ($column)
+    {
+      // Don't bother with these columns
+      case 'id':
+      case 'timestamp':
+      case 'status':
+      case 'reminded':
+      case 'info_time':
+      case 'info_user':
+      case 'info_text':
+        break;
+        
+      case 'name':
+      case 'description':
+      case 'type':
+      case 'room_id':
+      case 'entry_type':
+      case 'private':
+        $$column = $row[$column];
+        break;
+      
+      case 'repeat_id':
+        $rep_id      = $row['repeat_id'];
+        
+      case 'create_by':
+        // If we're copying an existing entry then we need to change the 
create_by (they could be
+        // different if it's an admin doing the copying)
+        $create_by   = (isset($copy)) ? $user : $row['create_by'];
+        break;
+        
+      case 'start_time':
+        $start_day   = strftime('%d', $row['start_time']);
+        $start_month = strftime('%m', $row['start_time']);
+        $start_year  = strftime('%Y', $row['start_time']);
+        $start_hour  = strftime('%H', $row['start_time']);
+        $start_min   = strftime('%M', $row['start_time']);
+        break;
+        
+      case 'end_time':
+        $duration = $row['end_time'] - $row['start_time'] - 
cross_dst($row['start_time'], $row['end_time']);
+        break;
+        
+      default:
+        $custom_fields[$column] = $row[$column];
+        break;
+    }
+  }
+  
   if ($private_mandatory) 
   {
     $private = $private_default;
@@ -742,9 +775,57 @@
       } ?>
      </div>
     </div>
+    
+    <?php
+    
+    // CUSTOM FIELDS
+    if (count($custom_fields))
+    {
+      $fields = sql_field_info($tbl_entry);
+      $field_natures = array();
+      $field_lengths = array();
+      foreach ($fields as $field)
+      {
+        $field_natures[$field['name']] = $field['nature'];
+        $field_lengths[$field['name']] = $field['length'];
+      }
+      foreach ($custom_fields as $key => $value)
+      {
+        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_natures[$key] == 'boolean') || 
+            (($field_natures[$key] == 'integer') && 
isset($field_lengths[$key]) && ($field_lengths[$key] <= 2)) )
+        {
+          echo "<input type=\"checkbox\" class=\"checkbox\" " .
+                "id=\"f_$key\" name=\"f_$key\" value=\"1\" " .
+                ((!empty($value)) ? " checked=\"checked\"" : "") .
+                ">\n";
+        }
+        // Output a textarea if it's a character string longer than the limit 
for a
+        // text input
+        elseif (($field_natures[$key] == 'character') && 
isset($field_lengths[$key]) && ($field_lengths[$key] > $text_input_max))
+        {
+          echo "<textarea rows=\"8\" cols=\"40\" " .
+                "id=\"f_$key\" name=\"f_$key\" " .
+                ">\n";
+          echo htmlspecialchars($value);
+          echo "</textarea>\n";
+        }
+        // Otherwise output a text input
+        else
+        {
+          echo "<input type=\"text\" " .
+                "id=\"f_$key\" name=\"f_$key\" " .
+                "value=\"" . htmlspecialchars($value) . "\"" .
+                ">\n";
+        }
+        echo "</div>\n";
+      }
+    }
 
 
-    <?php
     // REPEAT BOOKING INPUTS
     if (($edit_type == "series") && $repeats_allowed)
     {
@@ -817,7 +898,7 @@
       echo "<legend></legend>\n";
       echo "<div>\n";
       echo "<label>" . get_vocab("rep_type") . ":</label>\n";
-      echo "<select value =\"" . get_vocab($key) . "\" 
disabled=\"disabled\">\n";
+      echo "<select disabled=\"disabled\">\n";
       echo "<option>" . get_vocab($key) . "</option>\n";
       echo "</select>\n";
       echo "<input type=\"hidden\" name=\"rep_type\" value=\"" . REP_NONE . 
"\">\n";

Modified: mrbs/branches/custom_entry_fields/web/mrbs.css.php
===================================================================
--- mrbs/branches/custom_entry_fields/web/mrbs.css.php  2010-07-23 17:52:46 UTC 
(rev 1377)
+++ mrbs/branches/custom_entry_fields/web/mrbs.css.php  2010-07-23 20:15:37 UTC 
(rev 1378)
@@ -560,8 +560,8 @@
 }
 .form_general select {float: left; margin-left: <?php echo $general_gap ?>em; 
margin-right: -0.5em; margin-bottom: 0.5em}
 .form_general input.radio {margin-top: 0.1em}
-.form_general input.checkbox {margin-top: 0.2em}
-.edit_area_room .form_general input.checkbox {width: auto; margin-left: <?php 
echo $general_gap ?>em}
+.form_general input.checkbox {width: auto; margin-top: 0.2em}
+.edit_area_room .form_general input.checkbox {margin-left: <?php echo 
$general_gap ?>em}
 .edit_area_room .form_general #booking_policies input.text {width: 2.0em}
 .form_general input.submit {display: block; width: auto; float: left; clear: 
left; margin-top: 1.0em}
 


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

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to