Need explicit cast
[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     $table_sum = '<tr bgcolor="#%s"><td>&nbsp;</td><td align="center">%s</td><td>Summe</td></tr>';
50
51     $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ";
52     if (isset($month) && $month !== 'all')
53       $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
54     if (isset($status)) {
55       if ($status != 'all')
56         $query .= "AND status = $status ";
57     } else
58       $query .= "AND status = 0 ";
59     $query .= "ORDER BY customer,start";
60
61     $sth = pg_exec ($dbh, $query);
62
63     $customer = '';
64     while ($row = pg_fetch_array ($sth)) {
65
66       if ($customer != $row['customer']) {
67         if (strlen($customer)) {
68           printf($table_sum, $color, min2hour($sum));
69           printf($table_foot, $fieldnr);
70         }
71         printf($table_head, $row['customer']);
72         $customer = $row['customer'];
73         $fieldnr = 0;
74         $sum = 0;
75         $color = "<cold>";
76       }
77
78       $sum += $row['time'];
79       $d = explode(' ', $row['start']);
80
81       $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
82       printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['task']);
83       $color = $color=="<cold>"?"<coln>":"<cold>";
84     }
85     printf($table_sum, $color, min2hour($sum));
86     printf($table_foot, $fieldnr);
87   }
88
89   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
90          or die("Unable to connect to SQL server");
91
92   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
93
94   if (isset($_POST["status"]) && isset($_POST["fields"])) {
95     $msg = update_db();
96   } else {
97     if (isset($_GET['month']))
98       $month = $_GET['month'];
99     else
100       if (isset($_POST["filter"])) {
101         $month = $_POST["month"];
102         $status = $_POST["status"];
103       } else
104         $month = date('Y-m');
105   }
106 ?>
107
108 <page func=InfoCon title="Stempeluhr">
109
110 <?
111   if (!empty($msg))
112     echo $msg;
113   else {
114     display_tables();
115 ?>
116
117 <h3 class=bar>Display</h3>
118
119 <form action=status.php method=POST>
120 <select name=month>
121 <option value="all">alle</option>
122 <?
123   if (!is_array($months))
124     $months = find_months();
125
126   foreach ($months as $m) {
127     printf('<option value="%s">%s</option>', $m, $m);
128   }
129 ?>
130 </select>
131
132 <input type="radio" name="status" value="all">alle
133 <input type="radio" name="status" value="0">unbekannt
134 <input type="radio" name="status" value="1">ignoriert
135 <input type="radio" name="status" value="2">wartung
136 <input type="radio" name="status" value="3">berechnet
137
138 <input type="hidden" name="filter" value="form">
139 <input type="submit" value="Display">
140 </form>
141
142 <? } ?>
143 </page>
144
145 # Local variables:
146 # mode: text
147 # mode: auto-fill
148 # end: