#include <infocon.style>
+#include "common.inc"
+
+<?
+ $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
+ or die("Unable to connect to SQL server");
+
+ pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
+
+ if ($_POST['func'] == 'save') {
+ $sql = sprintf("UPDATE stempel SET task = '%s' WHERE oid = %d",
+ pg_escape_string(utf8_decode($_POST['task'])),
+ $_POST['oid']);
+ pg_exec($sql);
+
+ header('Content-type: application/json; charset="UTF-8"');
+ echo json_encode(true);
+ exit;
+ }
+
+ if (isset($_GET['month']))
+ $month = $_GET['month'];
+ else
+ $month = date('Y-m');
+?>
<page func=InfoCon title="Stempeluhr">
<?
- function min2hour($minutes)
- {
- return sprintf('%02d:%02d', $minutes/60, $minutes%60);
- }
+ $name = load_customers();
- $table_head = '<hr class="bar">%s</h3>
-<table class=font width="100%%" border=0 cellpadding=2 cellspacing=0>
-<tr bgcolor=#<colh>>
- <th width=15%%>Datum</th>
- <th width=15%%>Dauer</th>
- <th width=70%%>Verwendungszweck</th>
+ $table_head = '<h3 class="bar">Kunde: %s</h3>
+<table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
+<tr class="head">
+ <th width=10%%>Datum</th>
+ <th width=5%%>Dauer</th>
+ <th width=5%%>St.</th>
+ <th width=80%%>Arbeitsbeschreibung</th>
</tr>';
$table_foot = '</table>';
- $table_row = '<tr bgcolor=#%s><td>%s</td><td>%s</td><td><a href="edit.php?id=%d">%s</a></td></tr>';
-
- $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
- or die("Unable to connect to SQL server");
-
- pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
+ $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>';
+ $table_sum = '<tr class="t%d"><td> </td><td align="center"><strong>%s</strong></td><td> </td><td><strong>Summe</strong></td></tr>';
- $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ORDER BY customer,start";
+ $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 ";
+ if (isset($month) && $month !== 'all')
+ $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
+ $query .= "ORDER BY customer,start";
$sth = pg_exec ($dbh, $query);
while ($row = pg_fetch_array ($sth)) {
if ($customer != $row['customer']) {
- if (strlen($customer))
+ if (strlen($customer)) {
+ printf($table_sum, $color, min2hour($sum));
echo($table_foot);
- printf($table_head, $row['customer']);
+ }
+ $cname = $name[$row['customer']];
+ if (!strlen($cname)) $cname = ucfirst($row['customer']);
+ printf($table_head, $cname);
$customer = $row['customer'];
- $color = "<cold>";
+ $sum = 0;
+ $color = 0;
}
+ $sum += $row['time'];
$d = explode(' ', $row['start']);
+
+ printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], htmlspecialchars($row['task']));
+ $color = !$color;
+ }
+ printf($table_sum, $color, min2hour($sum));
+ echo($table_foot);
+?>
+<div style="padding-top: 0.5em"></div>
+
+<form action=<?=$_SERVER["SCRIPT_NAME"]?> method=get>
+<b>Select month</b>: <select name=month>
+<?
+ $months = find_months();
+
+ foreach ($months as $m) {
+ if ($m == $month)
+ $sel = ' selected';
+ else
+ $sel = '';
- $color = $color=="<cold>"?"<coln>":"<cold>";
- printf($table_row, $color, $d[0], min2hour($row['time']), $row['oid'], $row['task']);
+ printf('<option value="%s"%s>%s</option>', $m, $sel, $m);
}
+ printf('<option value="all"%s>All</option>', $month == 'all'?' selected':'');
?>
-</table>
+</select>
+<input class=button type=submit value="Select">
+</form>
+<div style="padding-top: 0.5em"></div>
</page>