"
);
?>
# Getestet mit diesen Testzeiten
# $frame[] = "10-12";
# $frame[] = "10:30-12";
# $frame[] = "10.20-12";
# $frame[] = "12";
# $frame[] = "11.30";
# $frame[] = "23.29";
# $frame[] = "23.30";
#
# while (list($k,$v) = each ($frame)) {
# $foo = split_timeframe ($v);
# printf ("%s -- %s - %s", $v, $foo[0], $foo[1]);
# }
#
function split_timeframe ($timeframe)
{
$fromto = explode ("-", $timeframe);
if (!preg_match("/([0-9]+)[\.:]([0-9]+)/", $fromto[0], $frompart)) {
$frompart[1] = $fromto[0];
$frompart[2] = 0;
}
$from = sprintf ("%02d:%02d", $frompart[1], $frompart[2]);
if (strlen ($fromto[1])) {
if (!preg_match("/([0-9]+)[\.:]([0-9]+)/", $fromto[1], $to)) {
$to[1] = $fromto[1];
$to[2] = 0;
}
$to = sprintf ("%02d:%02d", $to[1], $to[2]);
} else {
# Bug: This can't handle cases like 23:30 -> 0:00
if ($frompart[2] <30) {
$to = sprintf ("%02d:%02d", $frompart[1], $frompart[2]+30);
} else {
$to = sprintf ("%02d:%02d", $frompart[1]+1, ($frompart[2]+30)%60);
}
}
# Special encoding for 24:00 which we can't handle otherwise
if ($from == "24:00") { $from = "23:59"; }
if ($to == "24:00") { $to = "23:59"; }
return array ($from, $to);
}
?>
function build_timeframe ($start, $end)
{
# Bug: This can only handle fragments that don't pass day borders
$foo = explode (" ", $start);
$bar = explode (" ", $end);
$foo = explode (":", $foo[1]);
$bar = explode (":", $bar[1]);
# Special decoding for 24:00 which we can't handle otherwise
if ($foo[0] == 23 && $foo[1] == 59) { $foo[0] = 24; $foo[1] = 0; }
if ($bar[0] == 23 && $bar[1] == 59) { $bar[0] = 24; $bar[1] = 0; }
if ($foo[1] == 0) {
if ($bar[1] == 0) {
return sprintf ("%d-%d", $foo[0], $bar[0]);
} else {
return sprintf ("%d-%d:%02d", $foo[0], $bar[0], $bar[1]);
}
} else {
if ($bar[1] == 0) {
return sprintf ("%d:%02d-%d", $foo[0], $foo[1], $bar[0]);
} else {
return sprintf ("%d:%02d-%d:%02d", $foo[0], $foo[1], $bar[0], $bar[1]);
}
}
}
?>
function normal_time ($start, $end)
{
# Bug: This can only handle fragments that don't pass day borders
$foo = explode (" ", $start);
$bar = explode (" ", $end);
$date = $foo[0];
$foo = explode (":", $foo[1]);
$bar = explode (":", $bar[1]);
# Special decoding for 24:00 which we can't handle otherwise
if ($foo[0] == 23 && $foo[1] == 59) { $foo[0] = 24; $foo[1] = 0; }
if ($bar[0] == 23 && $bar[1] == 59) { $bar[0] = 24; $bar[1] = 0; }
$starttime = sprintf ("%02d:%02d", $foo[0], $foo[1]);
$endtime = sprintf ("%02d:%02d", $bar[0], $bar[1]);
return array ($date, $starttime, $endtime);
}
function time_lt ($this, $that)
{
$foo = explode (":", $this);
$bar = explode (":", $that);
if ($foo[0] < $bar[0]) {
return true;
} elseif ($foo[0] == $bar[0] && $foo[1] < $bar[1]) {
return true;
} else {
return false;
}
}
?>
function fragment_ok ($dbh, $fragment)
{
return missing_supporters ($dbh, $fragment)==0?true:false;
}
function missing_supporters ($dbh, $fragment)
{
$query = sprintf ("SELECT max FROM fragment WHERE id = %d ", $fragment);
$sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
if ( pg_NumRows ($sth) > 0) {
$row = pg_fetch_array ($sth, 0);
$query = sprintf ("SELECT max,person FROM fragment,assignment WHERE id = %d "
."AND fragment.id = assignment.fragment",
$fragment);
$sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
if ( pg_NumRows ($sth) > 0) {
$row = pg_fetch_array ($sth, 0);
if (pg_NumRows ($sth) >= $row['max']) {
return 0;
} else {
return $row['max'] - pg_NumRows ($sth);
}
} else {
return $row['max'];
}
} else {
return 0;
}
}
?>
$f_header_head = '| Name | ';
$f_header_tail = '
';
$f_header_day = '%s | ';
$f_row_head = '| '
.'%s | ';
$f_row_tail = '
';
$f_row_day = '%s | ';
?>
$f_header_head = '| Title | ';
$f_header_tail = '
';
$f_header_day = '%s | ';
$f_row_head = '| '
.'%s | ';
$f_row_tail = '
';
$f_row_day = '%s | ';
?>
function strip_space($foo)
{
return str_replace (" ", "_", $foo);
}
?>
# Local variables:
# mode: text
# mode: auto-fill
# end: