Beautification
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / index.wml
1 #include <infocon.style>
2
3 <?
4   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
5          or die("Unable to connect to SQL server");
6
7   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
8
9   if (isset($_GET['month']))
10     $month = $_GET['month'];
11   else
12     $month = date('Y-m');
13 ?>
14
15 <page func=InfoCon title="Stempeluhr">
16
17 <?
18   function min2hour($minutes)
19   {
20       return sprintf('%02d:%02d', $minutes/60, $minutes%60);
21   }
22
23   $table_head = '<h3 class="bar">Kunde: %s</h3>
24 <table class="font" width="100%%" border=0 cellpadding=2 cellspacing=0>
25 <tr bgcolor=#<colh>>
26   <th width=15%%>Datum</th>
27   <th width=10%%>Dauer</th>
28   <th width=75%%>Verwendungszweck</th>
29 </tr>';
30   $table_foot = '</table>';
31   $table_row = '<tr bgcolor=#%s><td>%s</td><td align="center">%s</td><td><a href="edit.php?id=%d">%s</a></td></tr>';
32   $table_sum = '<tr bgcolor=#%s><td>&nbsp;</td><td align="center">%s</td><td>Summe</td></tr>';
33
34   $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ";
35   if (isset($month) && $month !== 'all')
36     $query .= "AND start LIKE '".$month."-%' ";
37   $query .= "ORDER BY customer,start";
38
39   $sth = pg_exec ($dbh, $query);
40
41   $customer = '';
42   while ($row = pg_fetch_array ($sth)) {
43
44     if ($customer != $row['customer']) {
45       if (strlen($customer)) {
46         printf($table_sum, $color, min2hour($sum));
47         echo($table_foot);
48       }
49       printf($table_head, $row['customer']);
50       $customer = $row['customer'];
51       $sum = 0;
52       $color = "<coln>";
53     }
54
55     $sum += $row['time'];
56     $d = explode(' ', $row['start']);
57
58     printf($table_row, $color, $d[0], min2hour($row['time']), $row['oid'], $row['task']);
59     $color = $color=="<cold>"?"<coln>":"<cold>";
60   }
61   printf($table_sum, $color, min2hour($sum));
62   echo($table_foot);
63 ?>
64 <div style="padding-top: 0.5em"></div>
65
66 </page>
67
68 # Local variables:
69 # mode: text
70 # mode: auto-fill
71 # end: