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);
23 return sprintf("<br>%d records updated.", $count);
27 function display_tables()
35 $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
36 <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
38 <th width=15%%>Datum</th>
39 <th width=5%%>Dauer</th>
40 <th width=5%%>St.</th>
41 <th width=75%%>Verwendungszweck</th>
44 if (!is_array($stati))
45 $stati = find_status();
47 $table_foot = '</table><div align="center"><p>';
49 foreach ($stati as $k=>$v)
50 $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
51 $table_foot .= '</p><p><input type="submit" class="button" value="Aktualisieren"></div>'.
52 '<input type="hidden" name="fields" value="%d"></p>'.
55 $table_row = '<tr class=t%d><td>%s</td><td align="center">%s</td><td align="center">%s</td><td>%s</td></tr>';
56 $table_sum = '<tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr>';
58 $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 ";
59 if (isset($month) && strlen($month))
60 $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
61 if (isset($cust) && strlen($cust))
62 $query .= "AND customer ='".$cust."' ";
67 $query .= "AND status = $status ";
69 $query .= "AND status = 0 ";
70 $query .= "ORDER BY customer,start";
72 $sth = pg_exec ($dbh, $query);
75 while ($row = pg_fetch_array ($sth)) {
77 if ($customer != $row['customer']) {
78 if (strlen($customer)) {
79 printf($table_sum, $color, min2hour($sum));
80 printf($table_foot, $fieldnr);
82 printf($table_head, $row['customer']);
83 $customer = $row['customer'];
90 $d = explode(' ', $row['start']);
92 $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
93 printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
96 if (pg_num_rows($sth) > 0) {
97 printf($table_sum, $color, min2hour($sum));
98 printf($table_foot, $fieldnr);
102 function find_customers()
107 $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
108 $sth = pg_exec ($dbh, $query);
110 while ($row = pg_fetch_array ($sth))
116 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
117 or die("Unable to connect to SQL server");
119 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
121 if (isset($_POST["status"]) && isset($_POST["fields"])) {
124 if (isset($_GET['month']))
125 $month = $_GET['month'];
127 if (isset($_POST["filter"])) {
128 $month = $_POST["month"];
129 $cust = $_POST["customer"];
130 $status = $_POST["status"];
132 $month = date('Y-m');
136 <page func=InfoCon title="Stempeluhr">
145 <h3 class=bar>Display</h3>
147 <form action=status.php method=POST>
150 if (!is_array($months))
151 $months = find_months();
153 printf('<option value=""%s>alle</option>', !strlen($_POST['month'])?' selected':'');
154 foreach ($months as $m) {
155 printf('<option value="%s"%s>%s</option>', $m, $_POST['month']==$m?' selected':'', $m);
160 <select name=customer>
162 if (!is_array($customers))
163 $customers = find_customers();
165 printf('<option value=""%s>alle</option>', !strlen($_POST['month'])?' selected':'');
166 foreach ($customers as $c) {
167 printf('<option value="%s"%s>%s</option>', $c, $_POST['customer']==$c?' selected':'', $c);
173 if (!is_array($stati))
174 $stati = find_status();
176 printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
177 foreach ($stati as $k=>$v)
178 printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
181 <input type="hidden" name="filter" value="form">
182 <input class="button" type="submit" value="Display">