#include <infocon.style>
+#include "common.inc"
<?
- function min2hour($minutes)
- {
- return sprintf('%02d:%02d', $minutes/60, $minutes%60);
- }
+ session_name('STEMPEL');
+ session_start();
function update_db()
{
$_POST["status"], $_POST["oid_".$idx]);
$count++;
$sth = pg_exec ($dbh, $query);
-echo '<br'.$query;
}
}
return sprintf("<br>%d records updated.", $count);
}
+ $stati = false;
function display_tables()
{
global $month;
+ global $cust;
global $status;
global $dbh;
+ global $stati;
- $table_head = '<h3 class="bar">Kunde: %s</h3><form action="status.php" method="POST">
- <table class="font" width="100%%" border=0 cellpadding=2 cellspacing=0>
- <tr bgcolor=#<colh>>
+ $name = load_customers();
+
+ $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d);</script>
+ <form action="status.php" method="POST">
+ <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
+ <tr class="head" onclick="edit_task_finish(this)">
<th width=15%%>Datum</th>
- <th width=10%%>Dauer</th>
- <th width=75%%>Verwendungszweck</th>
+ <th width=5%%>Dauer</th>
+ <th width=5%%>St.</th>
+ <th width=75%% align=left>Arbeitsbeschreibung</th>
</tr>';
- $table_foot = '</table><center>'.
- '<input type="radio" name="status" value="0" checked>unbekannt'.
- '<input type="radio" name="status" value="1">ignoriert'.
- '<input type="radio" name="status" value="2">wartung'.
- '<input type="radio" name="status" value="3">berechnet'.
- '</center>'.
- '<center><input type="submit" value="Aktualisieren"></center>'.
+
+ if (!is_array($stati))
+ $stati = find_status();
+
+ $table_foot = '</table><div align="center"><p>';
+
+ foreach ($stati as $k=>$v)
+ $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s ', $k, 0==$k?' checked':'', $v);
+ $table_foot .= '<input type="submit" class="button" value="Aktualisieren"></p></div>'.
'<input type="hidden" name="fields" value="%d">'.
'</form>';
- $table_row = '<tr bgcolor=#%s><td>%s</td><td align="center">%s</td><td>%s</td></tr>';
- $query = "SELECT oid,start,customer,time,task FROM stempel WHERE time IS NOT NULL ";
- if (isset($month) && $month !== 'all')
- $query .= "AND start LIKE '".$month."-%' ";
- if (isset($status)) {
+ $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td onclick="edit_task(this)">%s</td></tr>';
+ $table_sum = '<tr class="t%d"><td> </td><td align="center">%s</td><td> </td><td>Summe</td></tr>';
+
+ $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) && strlen($month))
+ $query .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
+ if (isset($cust) && strlen($cust))
+ $query .= "AND customer ='".$cust."' ";
+
+ if (isset($status) && strlen($status)) {
if ($status != 'all')
$query .= "AND status = $status ";
} else
$sth = pg_exec ($dbh, $query);
+ $form = 0;
$customer = '';
while ($row = pg_fetch_array ($sth)) {
if ($customer != $row['customer']) {
- if (strlen($customer))
+ if (strlen($customer)) {
+ printf($table_sum, $color, min2hour($sum));
printf($table_foot, $fieldnr);
- printf($table_head, $row['customer']);
+ $form++;
+ }
+ $cname = $name[$row['customer']];
+ if (!strlen($cname)) $cname = ucfirst($row['customer']);
+ printf($table_head, $cname, $form);
$customer = $row['customer'];
$fieldnr = 0;
$sum = 0;
- $color = "<cold>";
+ $color = 0;
}
$sum += $row['time'];
$d = explode(' ', $row['start']);
- $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
- printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['task']);
- $color = $color=="<cold>"?"<coln>":"<cold>";
+ $check = sprintf('<input type="checkbox" class="checkbox" name="oid_%d" value="%d" onclick="add_sum(%d,this)">',
+ $fieldnr++,
+ $row['oid'],
+ $form);
+ printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], htmlspecialchars($row['task']));
+ $color = !$color;
+ }
+ if (pg_num_rows($sth) > 0) {
+ printf($table_sum, $color, min2hour($sum));
+ printf($table_foot, $fieldnr);
}
- printf($table_foot, $fieldnr);
+ }
+
+ function find_customers()
+ {
+ global $dbh;
+
+ $a = array();
+ $query = "SELECT DISTINCT customer FROM stempel ORDER BY customer";
+ $sth = pg_exec ($dbh, $query);
+
+ while ($row = pg_fetch_array ($sth))
+ $a[] = $row[0];
+
+ return $a;
}
$dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
if (isset($_POST["status"]) && isset($_POST["fields"])) {
$msg = update_db();
+ $_SESSION['redirect'] = true;
+ header('Location: status.php');
+ exit;
+ } elseif ($_SESSION['redirect']) {
+ $month = $_SESSION['save']["month"];
+ $cust = $_SESSION['save']["customer"];
+ $status = $_SESSION['save']["status"];
+ $_SESSION['redirect'] = false;
} else {
- if (isset($_GET['month']))
+ if (isset($_GET['month'])) {
$month = $_GET['month'];
- else
+ $_SESSION['save']['month'] = $month;
+ unset($_SESSION['save']['customer']);
+ unset($_SESSION['save']['status']);
+ } else
if (isset($_POST["filter"])) {
$month = $_POST["month"];
+ $cust = $_POST["customer"];
$status = $_POST["status"];
- } else
+ $_SESSION['save']['month'] = $month;
+ $_SESSION['save']['customer'] = $cust;
+ $_SESSION['save']['status'] = $status;
+ } else {
$month = date('Y-m');
+ $_SESSION['save']['month'] = $month;
+ unset($_SESSION['save']['customer']);
+ unset($_SESSION['save']['status']);
+ }
}
?>
+<script src="<root_prefix>basics.js"></script>
+<script type="text/javascript">
+var color_checked = '#c4ffc3';
+function format_int(value, width)
+{
+ var s = value.toString();
+
+ while (s.length < width)
+ s = '0' + s;
+
+ return s;
+}
+
+function timestr(duration)
+{
+ return format_int(Math.floor(duration / 60), 1) + ':'
+ + format_int(duration - (Math.floor(duration / 60) * 60), 2);
+}
+
+function strtime(time)
+{
+ var a = time.split(':');
+ return parseInt(a[0],10) * 60 + parseInt(a[1],10);
+}
+
+function check(id, value)
+{
+ var form = document.forms[id];
+ var sum = document.getElementById('sum_'+id.toString());
+ var newval = 0;
+
+ for (i=0; i< form.elements.length; i++) {
+ if (form.elements[i].name.substr(0,4) == 'oid_') {
+ form.elements[i].checked = value;
+ if (value) {
+ var ta = form.elements[i].parentNode.nextSibling.innerHTML.split(':');
+ newval = newval + parseInt(ta[0],10) * 60 + parseInt(ta[1],10);
+ form.elements[i].parentNode.parentNode.style.backgroundColor = color_checked;
+ } else
+ form.elements[i].parentNode.parentNode.style.backgroundColor = '';
+ }
+ }
+
+ sum.innerHTML = timestr(newval);
+}
+
+function plant(form)
+{
+ document.write('<div class="jscode">');
+ document.write('<a href="javascript:check('+form+',true)">Check all</a>');
+ document.write(" / ");
+ document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
+ document.write(" ");
+ document.write('<span id="sum_'+form+'" class="sum">0:00</span>');
+ document.write(" ");
+ document.write('</div>');
+}
+
+function add_sum(form, checkbox)
+{
+ var sum = document.getElementById('sum_'+form.toString());
+ var time = strtime(checkbox.parentNode.nextSibling.innerHTML);
+ var newval;
+
+ if (checkbox.checked) {
+ newval = strtime(sum.innerHTML) + time;
+ checkbox.parentNode.parentNode.style.backgroundColor = color_checked;
+ } else {
+ newval = strtime(sum.innerHTML) - time;
+ checkbox.parentNode.parentNode.style.backgroundColor = '';
+ }
+ sum.innerHTML = timestr(newval);
+}
+
+var task_parent = null;
+var task_title = '';
+var task_oid = 0;
+function edit_task(obj)
+{
+ if (task_oid) {
+ if (task_oid != obj.parentNode.children[0].children[0].value)
+ edit_task_save();
+ }
+
+ if (!task_oid) {
+ task_parent = obj;
+ task_title = obj.innerHTML;
+ task_oid = obj.parentNode.children[0].children[0].value;
+
+ var input = document.createElement('input');
+ input.value = obj.innerHTML
+ input.style.fontSize = '100%';
+ input.style.width = '100%';
+ input.style.background = 'yellow';
+
+ obj.innerHTML = '';
+ obj.appendChild(input);
+ input.focus();
+ }
+}
+
+function edit_task_save()
+{
+ if (!task_parent) return;
+
+ if (task_parent.children[0].value != task_title)
+ ajax_request('save','oid='+task_oid+'&task='+encodeURIComponent(task_parent.children[0].value));
+
+ task_parent.innerHTML = task_parent.children[0].value;
+ task_parent = null;
+ task_title = '';
+ task_oid = 0;
+}
+
+function edit_task_finish(obj)
+{
+ if (task_oid)
+ edit_task_save();
+}
+
+</script>
+
+<style type="text/css">
+div.jscode {
+ text-align: right;
+ margin-top: -13px;
+ font-size: 12px;
+}
+span.sum {
+ display: inline;
+ border: 1px solid #9b9b9b;
+ background: #d9e2ea;
+ width: 20px;
+ margin-left: 3px;
+}
+</style>
+
<page func=InfoCon title="Stempeluhr">
<?
<form action=status.php method=POST>
<select name=month>
-<option value="all">alle</option>
<?
+ if (!is_array($months))
+ $months = find_months();
+
+ printf('<option value=""%s>alle</option>', !strlen($month)?' selected':'');
foreach ($months as $m) {
- printf('<option value="%s">%s</option>', $m, $m);
+ printf('<option value="%s"%s>%s</option>', $m, $month==$m?' selected':'', $m);
}
?>
</select>
-<input type="radio" name="status" value="all">alle
-<input type="radio" name="status" value="0">unbekannt
-<input type="radio" name="status" value="1">ignoriert
-<input type="radio" name="status" value="2">wartung
-<input type="radio" name="status" value="3">berechnet
+<select name=customer>
+<?
+ if (!is_array($customers))
+ $customers = find_customers();
+
+ printf('<option value=""%s>alle</option>', !strlen($cust)?' selected':'');
+ foreach ($customers as $c) {
+ printf('<option value="%s"%s>%s</option>', $c, $cust==$c?' selected':'', $c);
+ }
+?>
+</select>
+
+<?
+ if (!is_array($stati))
+ $stati = find_status();
+
+ printf('<input type="radio" name="status" value="all"%s>alle ', $status=='all'?' checked':'');
+ foreach ($stati as $k=>$v)
+ printf('<input type="radio" name="status" value="%s"%s>%s ', $k, $status==$k?' checked':'', $v);
+?>
<input type="hidden" name="filter" value="form">
-<input type="submit" value="Display">
+<input class="button" type="submit" value="Display">
</form>
<? } ?>
</page>
# Local variables:
-# mode: text
-# mode: auto-fill
+# mode: php
# end: