No debug output
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / status.wml
1 #include <infocon.style>
2
3 <?
4   function min2hour($minutes)
5   {
6       return sprintf('%02d:%02d', $minutes/60, $minutes%60);
7   }
8
9   function update_db()
10   {
11     global $dbh;
12
13     $count = 0;
14     for ($idx=0; $idx < $_POST["fields"]; $idx++) {
15       if (isset($_POST["oid_".$idx])) {
16         $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
17                  $_POST["status"], $_POST["oid_".$idx]);
18         $count++;
19         $sth = pg_exec ($dbh, $query);
20 echo '<br'.$query;
21       }
22     }
23     return sprintf("<br>%d records updated.", $count);
24   }
25
26   function display_tables()
27   {
28     global $month;
29     global $status;
30     global $dbh;
31
32     $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
33   <table class="font" width="100%%" border=0 cellpadding=2 cellspacing=0>
34   <tr bgcolor=#<colh>>
35     <th width=15%%>Datum</th>
36     <th width=10%%>Dauer</th>
37     <th width=75%%>Verwendungszweck</th>
38   </tr>';
39     $table_foot = '</table><center>'.
40                   '<input type="radio" name="status" value="0" checked>unbekannt'.
41                   '<input type="radio" name="status" value="1">ignoriert'.
42                   '<input type="radio" name="status" value="2">wartung'.
43                   '<input type="radio" name="status" value="3">berechnet'.
44                   '</center>'.
45                   '<center><input type="submit" value="Aktualisieren"></center>'.
46                   '<input type="hidden" name="fields" value="%d">'.
47                   '</form>';
48     $table_row = '<tr bgcolor=#%s><td>%s</td><td align="center">%s</td><td>%s</td></tr>';
49
50     $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ";
51     if (isset($month) && $month !== 'all')
52       $query .= "AND start LIKE '".$month."-%' ";
53     if (isset($status)) {
54       if ($status != 'all')
55         $query .= "AND status = $status ";
56     } else
57       $query .= "AND status = 0 ";
58     $query .= "ORDER BY customer,start";
59
60     $sth = pg_exec ($dbh, $query);
61
62     $customer = '';
63     while ($row = pg_fetch_array ($sth)) {
64
65       if ($customer != $row['customer']) {
66         if (strlen($customer))
67           printf($table_foot, $fieldnr);
68         printf($table_head, $row['customer']);
69         $customer = $row['customer'];
70         $fieldnr = 0;
71         $sum = 0;
72         $color = "<cold>";
73       }
74
75       $sum += $row['time'];
76       $d = explode(' ', $row['start']);
77
78       $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
79       printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['task']);
80       $color = $color=="<cold>"?"<coln>":"<cold>";
81     }
82     printf($table_foot, $fieldnr);
83   }
84
85   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
86          or die("Unable to connect to SQL server");
87
88   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
89
90   if (isset($_POST["status"]) && isset($_POST["fields"])) {
91     $msg = update_db();
92   } else {
93     if (isset($_GET['month']))
94       $month = $_GET['month'];
95     else
96       if (isset($_POST["filter"])) {
97         $month = $_POST["month"];
98         $status = $_POST["status"];
99       } else
100         $month = date('Y-m');
101   }
102 ?>
103
104 <page func=InfoCon title="Stempeluhr">
105
106 <?
107   if (!empty($msg))
108     echo $msg;
109   else {
110     display_tables();
111 ?>
112
113 <h3 class=bar>Display</h3>
114
115 <form action=status.php method=POST>
116 <select name=month>
117 <option value="all">alle</option>
118 <?
119   foreach ($months as $m) {
120     printf('<option value="%s">%s</option>', $m, $m);
121   }
122 ?>
123 </select>
124
125 <input type="radio" name="status" value="all">alle
126 <input type="radio" name="status" value="0">unbekannt
127 <input type="radio" name="status" value="1">ignoriert
128 <input type="radio" name="status" value="2">wartung
129 <input type="radio" name="status" value="3">berechnet
130
131 <input type="hidden" name="filter" value="form">
132 <input type="submit" value="Display">
133 </form>
134
135 <? } ?>
136 </page>
137
138 # Local variables:
139 # mode: text
140 # mode: auto-fill
141 # end: