2 #include <infocon.style>
5 function min2hour($minutes)
7 return sprintf('%02d:%02d', $minutes/60, $minutes%60);
15 for ($idx=0; $idx < $_POST["fields"]; $idx++) {
16 if (isset($_POST["oid_".$idx])) {
17 $query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
18 $_POST["status"], $_POST["oid_".$idx]);
20 $sth = pg_exec ($dbh, $query);
24 return sprintf("<br>%d records updated.", $count);
27 function find_status()
32 $query = "SELECT id,name FROM stempel_status ORDER BY id";
33 $sth = pg_exec ($dbh, $query);
35 while ($row = pg_fetch_array ($sth)) {
36 $a[$row['id']] = $row['name'];
42 function display_tables()
49 $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
50 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
52 <th width=15%%>Datum</th>
53 <th width=5%%>Dauer</th>
54 <th width=5%%>St.</th>
55 <th width=75%%>Verwendungszweck</th>
58 if (!is_array($stati))
59 $stati = find_status();
61 $table_foot = '</table><div align="center"><p>';
63 foreach ($stati as $k=>$v)
64 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
65 $table_foot .= '</p><p><input type="submit" value="Aktualisieren"></div>'.
66 '<input type="hidden" name="fields" value="%d"></p>'.
69 $table_row = '<tr class=t%d><td>%s</td><td align="center">%s</td><td align="center">%s</td><td>%s</td></tr>';
70 $table_sum = '<tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr>';
72 $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 ";
73 if (isset($month) && $month !== 'all')
74 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
77 $query .= "AND status = $status ";
79 $query .= "AND status = 0 ";
80 $query .= "ORDER BY customer,start";
82 $sth = pg_exec ($dbh, $query);
85 while ($row = pg_fetch_array ($sth)) {
87 if ($customer != $row['customer']) {
88 if (strlen($customer)) {
89 printf($table_sum, $color, min2hour($sum));
90 printf($table_foot, $fieldnr);
92 printf($table_head, $row['customer']);
93 $customer = $row['customer'];
100 $d = explode(' ', $row['start']);
102 $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
103 printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
106 printf($table_sum, $color, min2hour($sum));
107 printf($table_foot, $fieldnr);
110 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
111 or die("Unable to connect to SQL server");
113 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
115 if (isset($_POST["status"]) && isset($_POST["fields"])) {
118 if (isset($_GET['month']))
119 $month = $_GET['month'];
121 if (isset($_POST["filter"])) {
122 $month = $_POST["month"];
123 $status = $_POST["status"];
125 $month = date('Y-m');
129 <page func=InfoCon title="Stempeluhr">
138 <h3 class=bar>Display</h3>
140 <form action=status.php method=POST>
143 if (!is_array($months))
144 $months = find_months();
146 printf('<option value="all"%s>alle</option>', $_POST['month']=='alle'?' selected':'');
147 foreach ($months as $m) {
148 printf('<option value="%s"%s>%s</option>', $m, $_POST['month']==$m?' selected':'', $m);
154 if (!is_array($stati))
155 $stati = find_status();
157 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
158 foreach ($stati as $k=>$v)
159 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
162 <input type="hidden" name="filter" value="form">
163 <input class="button" type="submit" value="Display">