# Begin transaction
pg_exec($dbh, "BEGIN TRANSACTION") or die ("Could not start transaction.");
- if (!strlen ($section))
- {
+ if ($id > 0 && $delete == 1) {
+ $query = sprintf ("DELETE FROM job WHERE id = %d", $id);
+ pg_exec($dbh, $query) or die ("Can't delete job.");
+ $query = sprintf ("DELETE FROM jobfragment WHERE jobid = %d", $id);
+ pg_exec($dbh, $query) or die ("Can't delete job fragments.");
+ } else {
+
+ if (!strlen ($section))
+ {
$section = $usersection;
- }
- if (!strlen ($section)) {
+ }
+ if (!strlen ($section)) {
die ("Error: Section required.");
- }
- if ($id == 0) {
+ }
+ if ($id == 0) {
$query = sprintf("INSERT INTO job (title, location, description, priority, comment, section) " .
" VALUES ('%s', '%s', '%s', %d, '%s', '%s')",
addslashes($title), addslashes($location), addslashes($description),
$priority, addslashes($comment), addslashes($section));
- } else {
+ } else {
$query = sprintf("UPDATE job SET title = '%s', location = '%s', description = '%s', " .
" priority = %d, comment = '%s', section = '%s' WHERE id = %d",
addslashes($title), addslashes($location), addslashes($description),
$priority, addslashes($comment), addslashes($section), $id);
- }
- $sth = pg_exec($dbh, $query) or die ("Database Query.");
-
- if ($id == 0) {
- $query = sprintf ("SELECT id FROM job WHERE oid = %d", pg_getlastoid ($sth));
+ }
$sth = pg_exec($dbh, $query) or die ("Database Query.");
- if (pg_NumRows ($sth) > 0) {
- $row = pg_fetch_array ($sth, 0);
- $id = $row['id'];
- } else {
- die ("Can't find the job.");
+
+ if ($id == 0) {
+ $query = sprintf ("SELECT id FROM job WHERE oid = %d", pg_getlastoid ($sth));
+ $sth = pg_exec($dbh, $query) or die ("Database Query.");
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ $id = $row['id'];
+ } else {
+ die ("Can't find the job.");
+ }
}
- }
- for ($nr=0; $nr < <nrfragments>; $nr++) {
- $append = sprintf ("_%d", $nr);
+ for ($nr=0; $nr < <nrfragments>; $nr++) {
+ $append = sprintf ("_%d", $nr);
- # Calculate min. and max. people required
- #
- $foo = explode ("-", $GLOBALS["minmax".$append]);
- $min = $foo[0];
- $max = $foo[1];
- if ($max < $min) { $max = $min; }
+ # Calculate min. and max. people required
+ #
+ $foo = explode ("-", $GLOBALS["minmax".$append]);
+ $min = $foo[0];
+ $max = $foo[1];
+ if ($max < $min) { $max = $min; }
- if ($min > 0) {
- $fromto = split_timeframe ($GLOBALS["timeframe".$append]);
+ if ($min > 0) {
+ $fromto = split_timeframe ($GLOBALS["timeframe".$append]);
- $query = sprintf ("INSERT INTO jobfragment (jobid, min, max, starttime, endtime, comment) "
+ $query = sprintf ("INSERT INTO jobfragment (jobid, min, max, starttime, endtime, comment) "
."VALUES (%d, %d, %d, '%s', '%s', '%s')",
$id, $min, $max,
addslashes ($GLOBALS["date".$append] . " " . $fromto[0]),
addslashes ($GLOBALS["date".$append] . " " . $fromto[1]),
addslashes ($GLOBALS["comment".$append]));
- pg_exec($dbh, $query) or die ("Database Query.");
+ pg_exec($dbh, $query) or die ("Database Query.");
+ }
}
- }
- # Let's see if old fragments need to be altered
- if (isset ($oids)) {
- $bar = explode (" ", $oids);
- reset ($bar);
- while (list(,$oid) = each ($bar)) {
- if ($oid == 0) { continue; }
+ # Let's see if old fragments need to be altered
+ if (isset ($oids)) {
+ $bar = explode (" ", $oids);
+ reset ($bar);
+ while (list(,$oid) = each ($bar)) {
+ if ($oid == 0) { continue; }
- $append = sprintf ("_%d", $oid);
+ $append = sprintf ("_%d", $oid);
- # Calculate min. and max. people required
- #
- $foo = explode ("-", $GLOBALS["minmax".$append]);
- $min = $foo[0];
- $max = $foo[1];
- if ($max < $min) { $max = $min; }
+ # Calculate min. and max. people required
+ #
+ $foo = explode ("-", $GLOBALS["minmax".$append]);
+ $min = $foo[0];
+ $max = $foo[1];
+ if ($max < $min) { $max = $min; }
- if ($min > 0) {
- $fromto = split_timeframe ($GLOBALS["timeframe".$append]);
+ if ($min > 0) {
+ $fromto = split_timeframe ($GLOBALS["timeframe".$append]);
- $query = sprintf ("UPDATE jobfragment SET min=%d,max=%d,starttime='%s',endtime='%s',comment='%s' "
+ $query = sprintf ("UPDATE jobfragment SET min=%d,max=%d,starttime='%s',endtime='%s',comment='%s' "
."WHERE oid = %d",
$min, $max,
addslashes ($GLOBALS["date".$append] . " " . $fromto[0]),
addslashes ($GLOBALS["date".$append] . " " . $fromto[1]),
addslashes ($GLOBALS["comment".$append]),
$oid);
- pg_exec($dbh, $query) or die ("Database Query.");
- } else {
- $query = sprintf ("DELETE FROM jobfragment WHERE oid = %d", $oid);
- pg_exec($dbh, $query) or die ("Database Query.");
+ pg_exec($dbh, $query) or die ("Database Query.");
+ } else {
+ $query = sprintf ("DELETE FROM jobfragment WHERE oid = %d", $oid);
+ pg_exec($dbh, $query) or die ("Database Query.");
+ }
}
}
}