#include
function min2hour($minutes)
{
return sprintf('%02d:%02d', $minutes/60, $minutes%60);
}
function update_db()
{
global $dbh;
$count = 0;
for ($idx=0; $idx < $_POST["fields"]; $idx++) {
if (isset($_POST["oid_".$idx])) {
$query = sprintf('UPDATE stempel SET status=%d WHERE oid=%d',
$_POST["status"], $_POST["oid_".$idx]);
$count++;
$sth = pg_exec ($dbh, $query);
echo '
%d records updated.", $count);
}
$stati = false;
function display_tables()
{
global $month;
global $status;
global $dbh;
global $stati;
$table_head = 'Kunde: %s
'.
'';
$table_row = '%s | %s | %s | %s |
';
$table_sum = ' | %s | | Summe |
';
$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."-%' ";
if (isset($status)) {
if ($status != 'all')
$query .= "AND status = $status ";
} else
$query .= "AND status = 0 ";
$query .= "ORDER BY customer,start";
$sth = pg_exec ($dbh, $query);
$customer = '';
while ($row = pg_fetch_array ($sth)) {
if ($customer != $row['customer']) {
if (strlen($customer)) {
printf($table_sum, $color, min2hour($sum));
printf($table_foot, $fieldnr);
}
printf($table_head, $row['customer']);
$customer = $row['customer'];
$fieldnr = 0;
$sum = 0;
$color = 0;
}
$sum += $row['time'];
$d = explode(' ', $row['start']);
$check = '';
printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
$color = !$color;
}
printf($table_sum, $color, min2hour($sum));
printf($table_foot, $fieldnr);
}
$dbh = pg_pconnect ("", "", "")
or die("Unable to connect to SQL server");
pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
if (isset($_POST["status"]) && isset($_POST["fields"])) {
$msg = update_db();
} else {
if (isset($_GET['month']))
$month = $_GET['month'];
else
if (isset($_POST["filter"])) {
$month = $_POST["month"];
$status = $_POST["status"];
} else
$month = date('Y-m');
}
?>
if (!empty($msg))
echo $msg;
else {
display_tables();
?>
Display
} ?>
# Local variables:
# mode: text
# mode: auto-fill
# end: