Location: PHPKode > projects > Course-manager > courseman-0.1.1/absenden.php
<?php
  require('global-php.php');
  require('local-criteria.php');
  $registration_id = -1;
  function insert_registration($verbindung) {
    global $bestaetigungsmail,$registration_id,$personal_data;    //output
    global $passwort,$validity_requested,$omission_alerts;        //output
    global $course_period,$debug,$personal_data,$language;        //input
    global $registration_notification,$max_comment_length;        //input
    global $server_side_input_checking, $course_date_readable;    //input
    $ergebnis = db_exec($verbindung,
    			"SELECT min($course_date_readable.id) "
    				. "FROM course,$course_date_readable "
				. "WHERE course_period=$course_period "
				. "AND course=course.id;");
    $date_offset = pg_result($ergebnis, 0, 0);
    $session = generated_password(64);
    db_exec($verbindung, "INSERT INTO registration (session) SELECT '"
  				. $session . "'");
    $ergebnis = db_exec($verbindung, "SELECT id FROM registration WHERE "
  					. "session='" . $session . "'");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $registration_id = pg_result($ergebnis, $lt, 0);
      if ($debug["submission"]) {
        foreach ($_REQUEST as $key => $value) {
	  db_exec($verbindung, "START TRANSACTION;");
	  db_exec($verbindung, "LOCK TABLE form_key;");
	  db_exec($verbindung, "LOCK TABLE form_value;");
	  db_exec($verbindung, "LOCK TABLE form_tuple;");
	  db_exec($verbindung, "INSERT INTO form_key (value)
	SELECT '" . pg_escape_string($key) . "'
		WHERE NOT EXISTS (
			SELECT true FROM form_key
				WHERE value='"
			. pg_escape_string($key) . "');");
	  db_exec($verbindung, "INSERT INTO form_value (value)
	SELECT '" . pg_escape_string($value) . "'
		WHERE NOT EXISTS (
			SELECT true FROM form_value
				WHERE value='"
			. pg_escape_string($value) . "');");
          db_exec($verbindung, "INSERT INTO form_tuple (registration,key,value)
	SELECT $registration_id,form_key.id,form_value.id
		FROM form_key,form_value
		WHERE form_key.value='" . pg_escape_string($key) . "'
		AND form_value.value='" . pg_escape_string($value) . "';");
          db_exec($verbindung, "COMMIT;");
	}
      }
    }
    $validity_requested = false;
    if ($_REQUEST["kursanzahl"] != "0") {
      $validity_requested = true;
    }
    if ($server_side_input_checking) {
      $omission_alerts = $personal_data['calls']($personal_data,
                                                 'server_input_check',
  					         array());
      if ($omission_alerts == "") {
        register_and_validate_by_identification($personal_data);
        store_personal_information($verbindung);
      }
    } else {
      register_and_validate_by_identification($personal_data);
      store_personal_information($verbindung);
    }
    for ($kurs = 1; $kurs <= $_REQUEST["kursanzahl"]; $kurs++) {
      $erster = $_REQUEST["termin_kurs" . $kurs];
      $zweiter = $_REQUEST["termin_kurs_alternative" . $kurs];
      $vorkurs = $_REQUEST["vorkurs_kurs" . $kurs];
      $kommentar = $_REQUEST["kommentar_kurs" . $kurs];
      if (strlen($kommentar) > $max_comment_length) {
        $kommentar = substr($kommentar, 0, $max_comment_length);
      }
      $erster = (($erster == "")
    		? "null"
		: "'" . ($erster + $date_offset) . "'");
      $zweiter = (($zweiter == "")
    		? "null"
		: "'" . ($zweiter + $date_offset) . "'");
      if ($erster == $zweiter) {
        $zweiter = 'null';
      }
      $vorkurs = (($vorkurs == "")
    		? "null"
		: "'" . pg_escape_string($vorkurs) . "'");
      $kommentar = (($kommentar == "")
    		? "null"
		: "'" . pg_escape_string($kommentar) . "'");
      db_exec($verbindung, "INSERT INTO registration_course "
    		. "(registration,course,secondary,prep_course,commentary) "
		. "SELECT $registration_id,$erster,$zweiter,$vorkurs,"
		. "$kommentar");
    }
    $passwort = $_REQUEST["key"];
    if ($passwort == "") {
      $passwort = generated_password(10);
    }
    $identifying_fields = $personal_data['calls']($personal_data,
                                                  'identifying_record',
						  array());
    if (sizeof($identifying_fields) > 0) {
      db_exec($verbindung, "START TRANSACTION;");
      db_exec($verbindung, "LOCK TABLE person;");
      db_exec($verbindung, "LOCK TABLE person_password;");
      db_exec($verbindung, "LOCK TABLE person_login;");
      db_exec($verbindung, "INSERT INTO person_password (person,hash) "
			. "SELECT id,md5('$passwort') FROM person"
			. " WHERE " . delimited_array_elements(
					map_function_using_key(
						exact_join,
						$identifying_fields),
					" "
			. "AND ",
					"true ")
			. " AND NOT EXISTS (SELECT true FROM person_password "
			. "WHERE person=id);");
      db_exec($verbindung, "INSERT INTO person_login (person,login) "
			. "SELECT id,md5(random()||id) FROM person"
			. " WHERE " . delimited_array_elements(
					map_function_using_key(
						exact_join,
						$identifying_fields),
					" "
			. "AND ",
					"true ")
			. " AND NOT EXISTS (SELECT true FROM person_login "
			. "WHERE person=id);");
      db_exec($verbindung, "COMMIT;");
    }
    $bestaetigungsmail = $registration_notification[$language] . "

";
  }
  check_registration_period();
  if(!$denied) {
    $verbindung = database_connection($lang_database_failure[$language]);
    $course_period = static_option_value($course_period_option);
    insert_registration($verbindung);
  }
  require_once('template-absenden.php');
  db_close($verbindung);
?>
Return current item: Course-manager