Convert foreign characters from UTF8 to latin1
[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   $table_head = '<h3 class="bar">Kunde: %s</h3>
31 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
32 <tr class="head">
33   <th width=10%%>Datum</th>
34   <th width=5%%>Dauer</th>
35   <th width=5%%>St.</th>
36   <th width=80%%>Arbeitsbeschreibung</th>
37 </tr>';
38   $table_foot = '</table>';
39   $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>';
40   $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>';
41
42   $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 ";
43   if (isset($month) && $month !== 'all')
44     $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
45   $query .= "ORDER BY customer,start";
46
47   $sth = pg_exec ($dbh, $query);
48
49   $customer = '';
50   while ($row = pg_fetch_array ($sth)) {
51
52     if ($customer != $row['customer']) {
53       if (strlen($customer)) {
54         printf($table_sum, $color, min2hour($sum));
55         echo($table_foot);
56       }
57       printf($table_head, $row['customer']);
58       $customer = $row['customer'];
59       $sum = 0;
60       $color = 0;
61     }
62
63     $sum += $row['time'];
64     $d = explode(' ', $row['start']);
65  
66     printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], htmlspecialchars($row['task']));
67     $color = !$color;
68   }
69   printf($table_sum, $color, min2hour($sum));
70   echo($table_foot);
71 ?>
72 <div style="padding-top: 0.5em"></div>
73
74 <form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
75 <b>Select month</b>: <select name=month>
76 <?
77   $months = find_months();
78
79   foreach ($months as $m) {
80     if ($m == $month)
81       $sel = ' selected';
82     else
83       $sel = '';
84
85     printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
86   }
87   printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
88 ?>
89 </select>
90 <input class=button type=submit value="Select">
91 </form>
92 <div style="padding-top: 0.5em"></div>
93
94 </page>
95
96 # Local variables:
97 # mode: text
98 # mode: auto-fill
99 # end: