#include #include "common.inc" %d records updated.", $count); } function load_customers() { global $dbh; $info = array(); $sth = pg_exec ($dbh, 'SELECT short,name FROM stempel_customer'); while ($row = pg_fetch_array ($sth)) $info[$row['short']] = $row['name']; return $info; } $stati = false; function display_tables() { global $month; global $cust; global $status; global $dbh; global $stati; $name = load_customers(); $table_head = '

Kunde: %s

'; if (!is_array($stati)) $stati = find_status(); $table_foot = '
Datum Dauer St. Verwendungszweck

'; foreach ($stati as $k=>$v) $table_foot .= sprintf('%s ', $k, 0==$k?' checked':'', $v); $table_foot .= '

'. ''. '
'; $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) && 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 $query .= "AND status = 0 "; $query .= "ORDER BY customer,start"; $sth = pg_exec ($dbh, $query); $form = 0; $customer = ''; while ($row = pg_fetch_array ($sth)) { if ($customer != $row['customer']) { if (strlen($customer)) { printf($table_sum, $color, min2hour($sum)); printf($table_foot, $fieldnr); $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 = 0; } $sum += $row['time']; $d = explode(' ', $row['start']); $check = sprintf('',$form); printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']); $color = !$color; } if (pg_num_rows($sth) > 0) { printf($table_sum, $color, min2hour($sum)); 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 ("", "", "") 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(); $_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'])) { $month = $_GET['month']; $_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"]; $_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']); } } ?>

Display

alle ', $status=='all'?' checked':''); foreach ($stati as $k=>$v) printf('%s ', $k, $status==$k?' checked':'', $v); ?>
# Local variables: # mode: text # mode: auto-fill # end: