Convert in-place edit of task to jquery.editable
[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 <future>
28 <page func=InfoCon title="Stempeluhr">
29 <script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
30
31 <?
32   $name = load_customers();
33
34   $table_head = '<h3 class="bar">Kunde: %s</h3>
35 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
36 <tr class="head">
37   <th width=10%%>Datum</th>
38   <th width=5%%>Dauer</th>
39   <th width=5%%>St.</th>
40   <th width=80%%>Arbeitsbeschreibung</th>
41 </tr>';
42   $table_foot = '</table>';
43   if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false)
44     $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>';
45   else
46     $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td><span route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
47   $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>';
48
49   $query = <<<EOS
50 SELECT stempel.oid,stempel.id,start,stempel_customer.name AS customer,time,task,kurz
51 FROM stempel
52 JOIN stempel_customer ON (stempel.customer = stempel_customer.short)
53 JOIN stempel_status ON (stempel.status = stempel_status.id)
54 WHERE time IS NOT NULL
55 EOS;
56   if (isset($month) && $month !== 'all')
57     $query .= " AND cast(start AS TEXT) LIKE '".$month."-%'";
58   $query .= " ORDER BY customer,start";
59
60   $sth = pg_exec ($dbh, $query);
61
62   $customer = '';
63   while ($row = pg_fetch_array ($sth)) {
64
65     if ($customer != $row['customer']) {
66       if (strlen($customer)) {
67         printf($table_sum, $color, min2hour($sum));
68         echo($table_foot);
69       }
70       $cname = $name[$row['customer']];
71       if (!strlen($cname)) $cname = $row['customer'];
72       printf($table_head, $cname);
73       $customer = $row['customer'];
74       $sum = 0;
75       $color = 0;
76     }
77
78     $sum += $row['time'];
79     $d = explode(' ', $row['start']);
80  
81     printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'],
82            strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false ? $row['oid'] : $row['id'],
83            htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
84     $color = !$color;
85   }
86   printf($table_sum, $color, min2hour($sum));
87   echo($table_foot);
88 ?>
89 <div style="padding-top: 0.5em"></div>
90
91 <form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
92 <b>Select month</b>: <select name=month>
93 <?
94   $months = find_months();
95
96   foreach ($months as $m) {
97     if ($m == $month)
98       $sel = ' selected';
99     else
100       $sel = '';
101
102     printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
103   }
104   printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
105 ?>
106 </select>
107 <input class=button type=submit value="Select">
108 </form>
109 <div style="padding-top: 0.5em"></div>
110
111 <protect><script type="text/javascript">
112 $(function(){
113     make_editable('table.smallfont tr span');
114 });
115 </script></protect>
116 </page>
117
118 # Local variables:
119 # mode: text
120 # mode: auto-fill
121 # end: