Location: PHPKode > projects > Course-manager > courseman-0.1.1/operations.php
<?php
  function populate_table_and_registration($table,$data) {
    global $verbindung,$table_registration,$registration_id,$debug;
    insert_data($table,$data);
    register_data(
			$table,
			$table_registration[$table]['registration'],
			$table_registration[$table]['table'],
			$table_registration[$table]['data_column'],
			$table_registration[$table]['registration_column'],
			$registration_id,
			$data);
  }
  function register_and_validate_by_identification($schema) {
    global $verbindung,$registration_id,$validity_requested,$course_period;
    global $debug;
    global $allow_multiple_registrations,$table_registration;
    $all_fields = $schema['calls']($schema,'data_record',array());
    $identifying_fields
	= $schema['calls']($schema,'identifying_record',array());
    $inserted_fields = array();
    $authentication_tables = array();
    $authentication_joins = array();
    $validation_joins = array();
    foreach ($identifying_fields as $table => $data) {
      $inserted_fields[$table]=$all_fields[$table];
      $pushed = $table_registration[$table]['login_table'];
      array_push($authentication_tables,$pushed);
      $pushed = $table_registration[$table]['password_table'];
      array_push($authentication_tables,$pushed);
      array_push($authentication_joins,
		 $table_registration[$table]['login_join']);
      array_push($authentication_joins,
		 $table_registration[$table]['password_join']);
      array_push($authentication_joins,
		 "valid_registration.registration="
		 . $table_registration[$table]['table']
		 . ".registration");
      array_push($validation_joins,
		 "valid_registration.registration="
		 . $table_registration[$table]['table']
		 . ".registration");
      array_push($validation_joins,
		 "$table." . $table_registration[$table]['data_column']
		 . "=" . $table_registration[$table]['table'] . "."
		 . $table_registration[$table]['registration_column']);
    }
    $validity_clause = $allow_multiple_registrations
  	? ""
	: "
	AND NOT EXISTS (
		SELECT true
	       		FROM valid_registration,
                             " . delimited_array_elements(
					map_function_using_key(
						table_with_registration,
					        $identifying_fields),
					",
                             ",
					"(SELECT true)") . "
			WHERE course_period=$course_period
			AND " . delimited_array_elements($validation_joins,"
	       		AND ","true ") . "
			AND " . delimited_array_elements(
					map_function_using_key(
						exact_join,
					        $identifying_fields),
					"
	       		AND ",
					"true ") . ")";
    db_exec($verbindung, "START TRANSACTION;");
    map_function_using_key(lock_table_key_with_registration,$inserted_fields);
    map_function_using_key(populate_table_and_registration,$inserted_fields);
    if (sizeof($authentication_tables) > 0) {
      db_exec($verbindung, "DELETE FROM valid_registration
	WHERE EXISTS (
		SELECT true
	       		FROM " . delimited_array_elements(
						$authentication_tables,",
                             ","(SELECT true)") . ",
                             " . delimited_array_elements(
						map_function_using_key(
							registration_table,
							$identifying_fields),",
                             ","(SELECT true)") . "
	       		WHERE " . delimited_array_elements(
						$authentication_joins,"
	       		AND ","true ") . ");");
    }
    if ($validity_requested) {
      if ($debug["old-debug"]) {
?>
<pre>
<?="INSERT
	INTO valid_registration (registration,course_period)
	SELECT $registration_id,$course_period
		WHERE true$validity_clause;"?>
</pre>
<?php
      }
      if (sizeof($authentication_tables) > 0) {
        db_exec($verbindung, "INSERT
	INTO valid_registration (registration,course_period)
	SELECT $registration_id,$course_period
		WHERE true$validity_clause;");
      }
    }
    db_exec($verbindung, "COMMIT;");
    foreach ($all_fields as $table => $data) {
      if (!isset($identifying_fields[$table])) {
        db_exec($verbindung, "START TRANSACTION;");
	lock_table_key_with_registration($table,$data);
	populate_table_and_registration($table,$data);
	db_exec($verbindung, "COMMIT;");
      }
    }
  }
?>
Return current item: Course-manager