Location: PHPKode > projects > Course-manager > courseman-0.1.1/delete_registration.php
<?php
  require('global-php.php');
  header('Content-type: text/xml; charset=utf-8');
  $verbindung = database_connection(
  	      "<status>" . $lang_database_failure[$language] . "</status>");
  $PHP_AUTH_USER = $_SERVER["PHP_AUTH_USER"];
  $PHP_AUTH_PW = $_SERVER["PHP_AUTH_PW"];
  $ergebnis = db_exec($verbindung,
			"SELECT * FROM staff_authorization,"
					. "superuser,capability "
				. "WHERE superuser.account"
				. "=staff_authorization.id "
				. "AND superuser.capability=capability.id "
				. "AND capability.name='registrants' "
				. "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 '<status>' . $lang_authentication_failure[$language] . '</status>';
    db_close($verbindung);
    exit;
  }
  $person = intval($_REQUEST["person"]);
  $deleted = 0;
  $course_period = option_value($course_period_option);
  $ergebnis = db_exec($verbindung, "SELECT registration_person.registration "
  			. "FROM registration_person,valid_registration "
			. "WHERE person=$person "
			. "AND registration_person.registration="
				. "valid_registration.registration "
			. "AND course_period=$course_period;");
  for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
    $registration = pg_result($ergebnis, $lt, 0);
    $deleted += pg_cmdtuples(db_exec($verbindung,
    			"DELETE FROM registration_person "
    			. "WHERE registration=$registration;"));
    $deleted += pg_cmdtuples(db_exec($verbindung,
    			"DELETE FROM valid_registration "
    			. "WHERE registration=$registration;"));
    $deleted += pg_cmdtuples(db_exec($verbindung,
    			"DELETE FROM registration_course "
    			. "WHERE registration=$registration;"));
    $deleted += pg_cmdtuples(db_exec($verbindung,
    			"DELETE FROM registration_salutation "
    			. "WHERE registration=$registration;"));
    $deleted += pg_cmdtuples(db_exec($verbindung,
    			"DELETE FROM registration "
    			. "WHERE id=$registration;"));
  }
  $deleted += pg_cmdtuples(db_exec($verbindung,
  			"DELETE FROM person_login "
  			. "WHERE person=$person;"));
  $deleted += pg_cmdtuples(db_exec($verbindung,
  			"DELETE FROM person_password "
  			. "WHERE person=$person;"));
  $deleted += pg_cmdtuples(db_exec($verbindung,
  			"DELETE FROM person "
  			. "WHERE id=$person "
			. "AND NOT EXISTS ("
				. "SELECT true FROM registration_person "
					. "WHERE person=$person) "
			. "AND NOT EXISTS ("
				. "SELECT true FROM person_course "
					. "WHERE person=$person);"));
  db_close($verbindung);
  if ($deleted > 0) {
?>
<status><?=ucfirst($plural[$lang_registration[$language]])?>
<?=$done[$lang_delete[$language]]?>.</status>
<?php
  } else {
?>
<status><?=ucfirst($lang_nil[$language])?>
<?=$plural[$lang_registration[$language]]?>
<?=$done[$lang_delete[$language]]?>.</status>
<?php
  }
?>
Return current item: Course-manager