Merge branch 'sprit'
[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 ($_POST['func'] == 'save') {
11     $sql = sprintf("UPDATE stempel SET task = '%s' WHERE oid = %d",
12                   pg_escape_string(utf8_decode($_POST['task'])),
13                   $_POST['oid']);
14     pg_exec($sql);
15
16     header('Content-type: application/json; charset="UTF-8"');
17     echo json_encode(true);
18     exit;
19   }
20
21   if (isset($_GET['month']))
22     $month = $_GET['month'];
23   else
24     $month = date('Y-m');
25 ?>
26
27 <page func=InfoCon title="Stempeluhr">
28
29 <?
30   $name = load_customers();
31
32   $table_head = '<h3 class="bar">Kunde: %s</h3>
33 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
34 <tr class="head">
35   <th width=10%%>Datum</th>
36   <th width=5%%>Dauer</th>
37   <th width=5%%>St.</th>
38   <th width=80%%>Arbeitsbeschreibung</th>
39 </tr>';
40   $table_foot = '</table>';
41   $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>';
42   $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>';
43
44   $query = <<<EOS
45 SELECT stempel.oid,start,stempel_customer.name AS customer,time,task,kurz
46 FROM stempel
47 JOIN stempel_customer ON (stempel.customer = stempel_customer.short)
48 JOIN stempel_status ON (stempel.status = stempel_status.id)
49 WHERE time IS NOT NULL
50 EOS;
51   if (isset($month) && $month !== 'all')
52     $query .= " AND cast(start AS TEXT) LIKE '".$month."-%'";
53   $query .= " ORDER BY customer,start";
54
55   $sth = pg_exec ($dbh, $query);
56
57   $customer = '';
58   while ($row = pg_fetch_array ($sth)) {
59
60     if ($customer != $row['customer']) {
61       if (strlen($customer)) {
62         printf($table_sum, $color, min2hour($sum));
63         echo($table_foot);
64       }
65       $cname = $name[$row['customer']];
66       if (!strlen($cname)) $cname = $row['customer'];
67       printf($table_head, $cname);
68       $customer = $row['customer'];
69       $sum = 0;
70       $color = 0;
71     }
72
73     $sum += $row['time'];
74     $d = explode(' ', $row['start']);
75  
76     printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
77     $color = !$color;
78   }
79   printf($table_sum, $color, min2hour($sum));
80   echo($table_foot);
81 ?>
82 <div style="padding-top: 0.5em"></div>
83
84 <form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
85 <b>Select month</b>: <select name=month>
86 <?
87   $months = find_months();
88
89   foreach ($months as $m) {
90     if ($m == $month)
91       $sel = ' selected';
92     else
93       $sel = '';
94
95     printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
96   }
97   printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
98 ?>
99 </select>
100 <input class=button type=submit value="Select">
101 </form>
102 <div style="padding-top: 0.5em"></div>
103
104 </page>
105
106 # Local variables:
107 # mode: text
108 # mode: auto-fill
109 # end: