Move month selection to the page bottom
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / index.wml
1 #include <infocon.style>
2 #include "common.inc"
3
4 <?
5   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
6          or die("Unable to connect to SQL server");
7
8   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
9
10   if (isset($_GET['month']))
11     $month = $_GET['month'];
12   else
13     $month = date('Y-m');
14 ?>
15
16 <page func=InfoCon title="Stempeluhr">
17
18 <?
19   $table_head = '<h3 class="bar">Kunde: %s</h3>
20 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
21 <tr class="head">
22   <th width=10%%>Datum</th>
23   <th width=5%%>Dauer</th>
24   <th width=5%%>St.</th>
25   <th width=80%%>Arbeitsbeschreibung</th>
26 </tr>';
27   $table_foot = '</table>';
28   $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td><a href="edit.php?id=%d">%s</a></td></tr>';
29   $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center"><strong>%s</strong></td><td>&nbsp;</td><td><strong>Summe</strong></td></tr>';
30
31   $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 ";
32   if (isset($month) && $month !== 'all')
33     $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
34   $query .= "ORDER BY customer,start";
35
36   $sth = pg_exec ($dbh, $query);
37
38   $customer = '';
39   while ($row = pg_fetch_array ($sth)) {
40
41     if ($customer != $row['customer']) {
42       if (strlen($customer)) {
43         printf($table_sum, $color, min2hour($sum));
44         echo($table_foot);
45       }
46       printf($table_head, $row['customer']);
47       $customer = $row['customer'];
48       $sum = 0;
49       $color = 0;
50     }
51
52     $sum += $row['time'];
53     $d = explode(' ', $row['start']);
54  
55     printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], $row['task']);
56     $color = !$color;
57   }
58   printf($table_sum, $color, min2hour($sum));
59   echo($table_foot);
60 ?>
61 <div style="padding-top: 0.5em"></div>
62
63 <form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
64 <b>Select month</b>: <select name=month>
65 <?
66   $months = find_months();
67
68   foreach ($months as $m) {
69     if ($m == $month)
70       $sel = ' selected';
71     else
72       $sel = '';
73
74     printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
75   }
76   printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
77 ?>
78 </select>
79 <input class=button type=submit value="Select">
80 </form>
81 <div style="padding-top: 0.5em"></div>
82
83 </page>
84
85 # Local variables:
86 # mode: text
87 # mode: auto-fill
88 # end: