<?php
require('global-php.php');
$verbindung = database_connection($lang_database_failure[$language]);
$PHP_AUTH_USER = $_SERVER["PHP_AUTH_USER"];
$PHP_AUTH_PW = $_SERVER["PHP_AUTH_PW"];
$ergebnis = db_exec($verbindung,
"SELECT * FROM staff_authorization,superuser "
. "WHERE superuser.account"
. "=staff_authorization.id "
. "AND "
. login_query_clauses(
$PHP_AUTH_USER,
$PHP_AUTH_PW)
. ";");
if (pg_numrows($ergebnis) < 1) {
header('WWW-Authenticate: Basic realm="Kursverwaltung"');
header("HTTP/1.0 401 Unauthorized");
echo $lang_authentication_failure[$language];
db_close($verbindung);
exit;
}
$direction = $_REQUEST["direction"];
if ($direction == "up") {
$ahead = "<";
$behind = ">";
$forward = "-";
$backward = "+";
$nearest_ahead = "max";
} else {
$ahead = ">";
$behind = "<";
$forward = "+";
$backward = "-";
$nearest_ahead = "min";
}
$course = intval($_REQUEST["course"]);
$course_period = option_value($course_period_option);
db_exec($verbindung, "START TRANSACTION;");
db_exec($verbindung, "LOCK TABLE $course_date;");
$ergebnis = db_exec($verbindung, "SELECT category FROM $course_date,course "
. "WHERE $course_date.id=$course "
. "AND course=course.id;");
$category = pg_result($ergebnis,0,0);
$ergebnis = db_exec($verbindung,
"SELECT $nearest_ahead($course_date.position),"
. "this_one.position "
. "FROM $course_date,course,"
. "$course_date AS this_one "
. "WHERE course_period=$course_period "
. "AND $course_date.course=course.id "
. "AND this_one.id=$course "
. "AND category=$category "
. "AND $course_date.position $ahead this_one.position "
. "GROUP BY this_one.position;");
if (pg_numrows($ergebnis) > 0) {
$next_position = pg_result($ergebnis,0,0);
$this_position = pg_result($ergebnis,0,1);
$ergebnis = db_exec($verbindung,
"UPDATE $course_date SET position=-1 "
. "WHERE position=$next_position;");
$ergebnis = db_exec($verbindung,
"UPDATE $course_date SET position=$next_position "
. "WHERE position=$this_position;");
$ergebnis = db_exec($verbindung,
"UPDATE $course_date SET position=$this_position "
. "WHERE position=-1;");
}
$ergebnis = db_exec($verbindung, "COMMIT;");
db_close($verbindung);
?>