Support options from array
[misc/kostenrechnung] / lib / mask.php
index a6f80f6..f2503cc 100644 (file)
@@ -14,7 +14,7 @@ function build_form($fields)
 {
   $ret = array();
 
-  $ret[] = '<div class="form">';
+  $ret[] = '<div class="form" style="clear: both;">';
   $ret[] = '<form id="form_edit">';
 
   $ret[] = '<input type="hidden" id="edit_id" name="id" value="">';
@@ -25,9 +25,18 @@ function build_form($fields)
                 'name="'.$id.'"',
                 'size="'.$info['size'].'"',
                 'type="text"');
-      $ret[] = sprintf('<label for="edit_%s"><b>%s</b></label><br>', $id, $info['name']);
+      $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
       $ret[] = sprintf('<input %s><br>', implode(' ', $v));
-
+    } elseif ($info['type'] == 'select') {
+      $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
+      $ret[] = sprintf('<select id="edit_%s" name="%s">', $id, $id);
+      if (is_array($info['options'])) $options = $info['options'];
+      else $options = query_db($info['options']);
+      foreach ($options as $row)
+       $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
+      $ret[] = '</select><br>';
+
+      error_log('type = select');
     } elseif ($info['type'] == 'date') {
       error_log('type = date');
     }