New area to report status messages and errors
[misc/kostenrechnung] / lib / mask.php
index a6f80f6..e85e313 100644 (file)
 #   return $ret;
 # }
 
-function build_form($fields)
+function build_form($name, $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="">';
+  $ret[] = sprintf('<input type="hidden" id="edit_source" name="source" value="%s">', $name);
 
   foreach ($fields as $id => $info) {
-    if ($info['type'] == 'text') {
+    if ($info['type'] == 'text' || $info['type'] == 'number') {
       $v = array('id="edit_'.$id.'"',
                 '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'] == 'boolean') {
+      $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
+      $ret[] = sprintf('<input type="checkbox" id="edit_%s" name="%s"><br>', $id, $id);
+    } 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>';
     } elseif ($info['type'] == 'date') {
       error_log('type = date');
     }
@@ -125,6 +136,7 @@ function build_details($name, $details)
 function build_mask($name, $mask)
 {
   $grid = build_grid($name, $mask);
+  $status = array('<span id="status"></span><br>');
 
   if (array_key_exists('details', $mask))
     $details = build_details($name, $mask['details']);
@@ -142,6 +154,7 @@ function build_mask($name, $mask)
   return array_merge($head,
                     $grid,
                     array('</div>','<div class="left">'),
+                    $status,
                     $details,
                     array('</div>'));
 }
@@ -163,7 +176,7 @@ function mask($name)
     $ret = build_mask($name, $mask);
 
   if (array_key_exists('edit', $mask))
-    $ret = array_merge($ret, build_form($mask['edit']));
+    $ret = array_merge($ret, build_form($name, $mask['edit']));
 
   return implode("\n", $ret);
 }