Several improvements:
authorJoey Schulze <joey@infodrom.org>
Mon, 15 Sep 2008 16:40:35 +0000 (16:40 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 15 Sep 2008 16:40:35 +0000 (16:40 +0000)
 . retrieve status names from database for forms
 . display short status names in overview tables
 . save form values for display form
 . use table layout in CSS
 . beautify table

src/InfoCon/stempel/status.wml

index 85d10b6..21d4983 100644 (file)
@@ -1,3 +1,4 @@
+
 #include <infocon.style>
 
 <?
@@ -23,32 +24,52 @@ echo '<br'.$query;
     return sprintf("<br>%d records updated.", $count);
   }
 
+  function find_status()
+  {
+    global $dbh;
+
+    $a = array();
+    $query = "SELECT id,name FROM stempel_status ORDER BY id";
+    $sth = pg_exec ($dbh, $query);
+
+    while ($row = pg_fetch_array ($sth)) {
+      $a[$row['id']] = $row['name'];
+    }
+    return $a;
+  }
+
+  $stati = false;
   function display_tables()
   {
     global $month;
     global $status;
     global $dbh;
+    global $stati;
 
     $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
-  <table class="font" width="100%%" border=0 cellpadding=2 cellspacing=0>
-  <tr bgcolor=#<colh>>
+  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
+  <tr class="head">
     <th width=15%%>Datum</th>
-    <th width=10%%>Dauer</th>
+    <th width=5%%>Dauer</th>
+    <th width=5%%>St.</th>
     <th width=75%%>Verwendungszweck</th>
   </tr>';
-    $table_foot = '</table><center>'.
-                 '<input type="radio" name="status" value="0" checked>unbekannt'.
-                 '<input type="radio" name="status" value="1">ignoriert'.
-                 '<input type="radio" name="status" value="2">wartung'.
-                 '<input type="radio" name="status" value="3">berechnet'.
-                 '</center>'.
-                 '<center><input type="submit" value="Aktualisieren"></center>'.
-                 '<input type="hidden" name="fields" value="%d">'.
+
+    if (!is_array($stati))
+      $stati = find_status();
+
+    $table_foot = '</table><div align="center"><p>';
+
+    foreach ($stati as $k=>$v)
+      $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s&nbsp;', $k, 0==$k?' checked':'', $v);
+      $table_foot .= '</p><p><input type="submit" value="Aktualisieren"></div>'.
+                 '<input type="hidden" name="fields" value="%d"></p>'.
                  '</form>';
-    $table_row = '<tr bgcolor=#%s><td>%s</td><td align="center">%s</td><td>%s</td></tr>';
-    $table_sum = '<tr bgcolor="#%s"><td>&nbsp;</td><td align="center">%s</td><td>Summe</td></tr>';
 
-    $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ";
+    $table_row = '<tr class=t%d><td>%s</td><td align="center">%s</td><td align="center">%s</td><td>%s</td></tr>';
+    $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr>';
+
+    $query = "SELECT stempel.oid,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
     if (isset($month) && $month !== 'all')
       $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
     if (isset($status)) {
@@ -72,15 +93,15 @@ echo '<br'.$query;
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
-       $color = "<cold>";
+       $color = 0;
       }
 
       $sum += $row['time'];
       $d = explode(' ', $row['start']);
 
       $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
-      printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['task']);
-      $color = $color=="<cold>"?"<coln>":"<cold>";
+      printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
+      $color = !$color;
     }
     printf($table_sum, $color, min2hour($sum));
     printf($table_foot, $fieldnr);
@@ -118,25 +139,28 @@ echo '<br'.$query;
 
 <form action=status.php method=POST>
 <select name=month>
-<option value="all">alle</option>
 <?
   if (!is_array($months))
     $months = find_months();
 
+  printf('<option value="all"%s>alle</option>', $_POST['month']=='alle'?' selected':'');
   foreach ($months as $m) {
-    printf('<option value="%s">%s</option>', $m, $m);
+    printf('<option value="%s"%s>%s</option>', $m, $_POST['month']==$m?' selected':'', $m);
   }
 ?>
 </select>
 
-<input type="radio" name="status" value="all">alle
-<input type="radio" name="status" value="0">unbekannt
-<input type="radio" name="status" value="1">ignoriert
-<input type="radio" name="status" value="2">wartung
-<input type="radio" name="status" value="3">berechnet
+<?
+  if (!is_array($stati))
+    $stati = find_status();
+
+  printf('<input type="radio" name="status" value="all"%s>alle&nbsp;', $status=='all'?' checked':'');
+  foreach ($stati as $k=>$v)
+    printf('<input type="radio" name="status" value="%s"%s>%s&nbsp;', $k, $status==$k?' checked':'', $v);
+?>
 
 <input type="hidden" name="filter" value="form">
-<input type="submit" value="Display">
+<input class="button" type="submit" value="Display">
 </form>
 
 <? } ?>