#include <lt2002.style>
#include "../edit.style"
-#include "../phpfunctions.inc"
+#include "jobs.inc"
+<build_timeframe>
+<tab_frag_stubs>
+<normal_time>
+<fragment_ok>
<page func="LinuxTag 2002 Organisation" title="Jobs">
-<job>
+
+# This page intends to provide an overview about a given job and
+# provide means to assign a person to the job. Hence, the page contains:
+# . All Job fragments through the entire week
+# . Fragments and assignments splitted by day
+# . Including hooks to unassigned supporters for assignments
<?
$dbh = pg_pconnect ("<dbconnstring>")
or die("Unable to connect to SQL server");
pg_exec($dbh, "SET DateStyle='ISO'") or die ("Cannot set datestyle");
- $query = sprintf("SELECT id, title from job order by priority");
- $sth = pg_exec($dbh, $query) or die ("Datenbank-Fehler");
+ pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
- for ($x = 0; $x < pg_NumRows($sth); $x++)
- {
- $row = pg_fetch_array($sth, $x);
- $query = sprintf("SELECT * from fragment where job = %d", $row['id']);
- $sth2 = pg_exec($dbh, $query) or die ("Cannot find fragments");
- echo '<h2><a href="edit_job.php3?id=' . $row['id'] . '">' . $row['title'] . '</a></h2> ';
- echo '<a href="edit_job_fragment.php3?job=' . $row['id'] . '">Add fragment</a><br>';
- echo '<a href="update.php3?type=delete_job&id=' . $row['id'] . '">Delete job</a><br>';
- for ($y = 0; $y < pg_NumRows($sth2); $y++)
+ $title = '';
+ if (isset ($id)) {
+ $query = sprintf ("SELECT title,location,description,priority,comment,section FROM job WHERE id = %d", $id);
+ $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+
+ printf ("<h3>%s</h3>", $row['title']);
+
+ if (strlen ($row['section']) > 0) { printf ("<br>Section: %s</p>", $row['section']); }
+ if ($row['priority'] > 0) { printf ("<br>Priority: %s</p>", $row['priority']); }
+ if (strlen ($row['location']) > 0) { printf ("<br>Location: %s</p>", $row['location']); }
+ if (strlen ($row['comment']) > 0) { printf ("<br>Comment: %s</p>", $row['comment']); }
+
+ $title = $row['title'];
+ $description = $row['description'];
+ }
+ }
+
+ if ($id > 0 && strlen ($title) > 0) {
+ $query = sprintf ("SELECT oid,* FROM fragment WHERE job = %d ORDER BY starttime", $id);
+ $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+
+ $foo = explode (" ", $row['starttime']);
+ $time = build_timeframe ($row['starttime'], $row['endtime']);
+ if (strlen ($frag[$foo[0]]) > 0) {
+ $frag[$foo[0]] .= " " . $time;
+ } else {
+ $frag[$foo[0]] = $time;
+ }
+
+ $foo = normal_time ($row['starttime'], $row['endtime']);
+ $fragments[$foo[0]][] = array ('start' => $foo[1],
+ 'end' => $foo[2],
+ 'id' => $row['id'],
+ 'oid' => $row['oid']);
+ }
+
+ $query = sprintf ("SELECT assignment.starttime,assignment.endtime,assignment.person,assignment.oid,person.oid as peroid "
+ ."FROM assignment,fragment,job,person WHERE job.id = %d "
+ ."AND assignment.fragment = fragment.id "
+ ."AND fragment.job = job.id "
+ ."AND person.name = assignment.person "
+ ."ORDER BY starttime", $id);
+ $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+
+ $foo = normal_time ($row['starttime'], $row['endtime']);
+ $assignment[$foo[0]][] = array ('start' => $foo[1],
+ 'end' => $foo[2],
+ 'person' => $row['person'],
+ 'oid' => $row['oid'],
+ 'peroid' => $row['peroid']);
+ }
+?>
+
+# Basically, this table is a copy of a single line from jobs
+#
+<p><table cellpadding=0 cellspacing=1>
+<?
+ printf ($f_header_head, "<colh>");
+ reset ($ltdays);
+ while (list($key,$day) = each ($ltdays)) {
+ $foo = explode (",", $day);
+ printf ($f_header_day, $foo[0]);
+ $col[] = $key;
+ }
+ echo ($f_header_tail);
+
+ printf ($f_row_head, "<cold>", "edit_job", $id, $title);
+
+ reset ($ltdays);
+ while (list($date,$day) = each ($ltdays)) {
+ if (strlen ($frag[$date]) > 0) {
+ printf ($f_row_day, $frag[$date]);
+ } else {
+ printf ($f_row_day, " ");
+ }
+ }
+ echo ($f_row_tail);
+?>
+</table>
+<hr>
+<?
+
+ function display_supporters ($dbh, $date, $start, $end, $fragment)
{
- $row2 = pg_fetch_array($sth2, $y);
- fragment_overview($row2['id'], 1, 1, 1);
+ $query = sprintf ("SELECT name,starttime,endtime FROM person,availability "
+ ."WHERE starttime <= '%s %s' AND endtime >= '%s %s' "
+ ."AND person.name = availability.person ORDER BY name",
+ $date, $start, $date, $end);
+ $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+
+ if ( pg_NumRows ($sth) > 0) {
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+
+ $query = sprintf ("SELECT person FROM assignment "
+ ."WHERE person = '%s' "
+ ."AND starttime >= '%s %s' AND endtime <= '%s %s' ",
+ $row['name'], $date, $start, $date, $end);
+ $sth2 = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+ if ( pg_NumRows ($sth2) == 0) {
+ echo ("<br> ->");
+
+ printf (" %s-%s: <a href=\"update.php3?type=assign&fragment=%d&person=%s\">%s</a>",
+ $start, $end, $fragment, urlencode ($row['name']), $row['name']);
+ }
+ }
+ }
}
- echo '<br><br>';
+
+ reset ($ltdays);
+ while (list($date,$day) = each ($ltdays)) {
+ if (strlen ($frag[$date]) > 0) {
+ printf ("<h3>%s</h3>", $day);
+ # printf ("<p><b>Fragments:</b> %s (DEBUG)", $frag[$date]);
+
+ if (is_array ($assignment[$date])) {
+ $assign = $assignment[$date];
+ } else {
+ $assign = array ();
+ }
+
+ if (is_array ($fragments[$date])) {
+ $fragment = $fragments[$date];
+ } else {
+ $fragment = array ();
+ }
+
+ $as_pivot = 0; // assignment
+ for ($nr=0; $nr < count ($fragment); $nr++) {
+ while ($as_pivot < count ($assign) && time_lt ($assign[$as_pivot]['start'], $fragment[$nr]['start'])) { $as_pivot++; }
+ if ($as_pivot < count ($assign)) {
+ if ( ($assign[$as_pivot]['start'] == $fragment[$nr]['start'])
+ && ($assign[$as_pivot]['end'] == $fragment[$nr]['end'])) {
+
+ while ( ($assign[$as_pivot]['start'] == $fragment[$nr]['start'])
+ && ($assign[$as_pivot]['end'] == $fragment[$nr]['end'])) {
+ printf ("<br>%s-%s: <a href=\"edit.php3?oid=%d\">%s</a> "
+ ."(<a href=\"update.php3?type=loose&assignment=%d\">loose this</a>)",
+ $fragment[$nr]['start'], $fragment[$nr]['end'],
+ $assign[$as_pivot]['peroid'], $assign[$as_pivot]['person'],
+ $assign[$as_pivot]['oid']);
+ $as_pivot++;
+ }
+
+ if (!fragment_ok ($dbh, $fragment[$nr]['id'])) {
+ display_supporters ($dbh, $date, $fragment[$nr]['start'], $fragment[$nr]['end'], $fragment[$nr]['id']);
+ }
+ # FIXME
+ } else {
+ printf ("<br>%s-%s: %s"
+ ."(<a href=\"update.php3?type=loose&assignment=%d\">loose this</a>)",
+ $assign[$as_pivot]['start'], $assign[$as_pivot]['end'], $assign[$as_pivot]['person'],
+ $assign[$as_pivot]['oid']);
+ printf ("<br>%s-%s: free", $fragment[$nr]['start'], $fragment[$nr]['end']);
+ display_supporters ($dbh, $date, $fragment[$nr]['start'], $fragment[$nr]['end'], $fragment[$nr]['id']);
+ }
+ } else {
+ printf ("<br>%s-%s: free", $fragment[$nr]['start'], $fragment[$nr]['end']);
+ display_supporters ($dbh, $date, $fragment[$nr]['start'], $fragment[$nr]['end'], $fragment[$nr]['id']);
+ }
+ }
+ }
+ }
+
+ } else {
+ echo "<p><b>No such job found.</b></p>";
}
-
?>
+
</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end: