Add support for decimal fields in form
[misc/kostenrechnung] / lib / mask.php
index 0325e7a..e3c7eab 100644 (file)
@@ -27,16 +27,17 @@ function build_form($name, $fields)
   $ret[] = sprintf('<input type="hidden" id="edit_source" name="source" value="%s">', $name);
 
   foreach ($fields as $id => $info) {
-    if ($info['type'] == 'text' || $info['type'] == 'passwd' || $info['type'] == 'number') {
+    if ($info['type'] == 'text' || $info['type'] == 'passwd' ||
+       $info['type'] == 'decimal' || $info['type'] == 'number') {
       $v = array('id="edit_'.$id.'"',
                 'name="'.$id.'"');
       $v[] = 'size="'.(empty($info['size'])?'10':$info['size']).'"';
       $v[] = 'type="'.($info['type']=='passwd'?'password':'text').'"';
       $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
-      $ret[] = sprintf('<input %s><br>', implode(' ', $v));
+      $ret[] = sprintf('<input %s>', 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);
+      $ret[] = sprintf('<input type="checkbox" id="edit_%s" name="%s">', $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);
@@ -44,13 +45,16 @@ function build_form($name, $fields)
       else $options = query_db($info['options']);
       foreach ($options as $row)
        $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
-      $ret[] = '</select><br>';
+      $ret[] = '</select>';
     } elseif ($info['type'] == 'date') {
       error_log('type = date');
     }
+    if (array_key_exists('comment',$info))
+      $ret[] = sprintf('<span class="comment">%s</span>', $info['comment']);
+    $ret[] = '<br>';
   }
 
-  $ret[] = '<span id="form_status"></span>';
+  $ret[] = '<span id="form_status">&nbsp;</span>';
   $ret[] = '<div class="buttons">';
   $ret[] = '<button id="button_save" onclick="return form_save(this);">Speichern</button>';
   $ret[] = '<span></span>';
@@ -95,6 +99,7 @@ function build_grid($name, $mask)
     if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
     if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
     if (array_key_exists('specs', $data)) $s[] = $data['specs'];
+    if (array_key_exists('control', $data)) $s[] = 'control: ' . $data['control'];
     $specs[] = '{' . implode(', ', $s) . '}';
 
     if (array_key_exists('sql', $data))