Fix encoding problem with htmlspecialcharacters
[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 = "SELECT stempel.oid,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
45   if (isset($month) && $month !== 'all')
46     $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
47   $query .= "ORDER BY customer,start";
48
49   $sth = pg_exec ($dbh, $query);
50
51   $customer = '';
52   while ($row = pg_fetch_array ($sth)) {
53
54     if ($customer != $row['customer']) {
55       if (strlen($customer)) {
56         printf($table_sum, $color, min2hour($sum));
57         echo($table_foot);
58       }
59       $cname = $name[$row['customer']];
60       if (!strlen($cname)) $cname = ucfirst($row['customer']);
61       printf($table_head, $cname);
62       $customer = $row['customer'];
63       $sum = 0;
64       $color = 0;
65     }
66
67     $sum += $row['time'];
68     $d = explode(' ', $row['start']);
69  
70     printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
71     $color = !$color;
72   }
73   printf($table_sum, $color, min2hour($sum));
74   echo($table_foot);
75 ?>
76 <div style="padding-top: 0.5em"></div>
77
78 <form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
79 <b>Select month</b>: <select name=month>
80 <?
81   $months = find_months();
82
83   foreach ($months as $m) {
84     if ($m == $month)
85       $sel = ' selected';
86     else
87       $sel = '';
88
89     printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
90   }
91   printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
92 ?>
93 </select>
94 <input class=button type=submit value="Select">
95 </form>
96 <div style="padding-top: 0.5em"></div>
97
98 </page>
99
100 # Local variables:
101 # mode: text
102 # mode: auto-fill
103 # end: