Location: PHPKode > projects > Course-manager > courseman-0.1.1/abstractions.php
<?php
  require_once('objects.php');
  require_once('html.php');
  require_once('javascript.php');
  require_once('operations.php');
  require_once('sql.php');
  require_once('input.php');
  require_once('output.php');
  require_once('data-types.php');
  require_once('data-structuring.php');
  require_once('array-operations.php');
  require_once('visual-customization.php');
  function course_relations($verbindung, $show_disabled) {
    global $course_date_readable;
    return course_relations_filtered($verbindung, $show_disabled ? ""
				: (" AND NOT EXISTS ("
				. "SELECT true FROM disabled_course "
				. "WHERE disabled=$course_date_readable.id)"));
  }
  function course_relations_filtered($verbindung, $filter) {
    global $course_period, $course_date_readable;       // input
    global $course_date_translated, $language;		// input
    global $kategorienzahl,$date_offset,$course_offset; // output
    $javascript = '
  var kategorien = new Array(';
    $ergebnis = db_exec($verbindung, "SELECT max(id) + 1 FROM category");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $kategorienzahl = pg_result($ergebnis, $lt, 0);
      $javascript .= ($kategorienzahl);
    }
    $javascript .= ');';
  	/* ein Feld, das die Kategorien den verfügbaren Kursen zuordnet */
    $ergebnis = db_exec($verbindung,
    			"SELECT min(course.id) "
    				. "FROM course "
				. "WHERE course_period=$course_period;");
    $course_offset = pg_result($ergebnis, 0, 0);
    $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);
    $ergebnis = db_exec($verbindung,
    			"SELECT max(course.id) + 1 FROM course "
				. "WHERE course_period=$course_period;");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0) - $course_offset;
      $javascript .= ("
  var kurse = new Array($id);"); // ein Feld mit den Namen der verfügbaren Kurse
      $javascript .= ("
  var kurs_termine = new Array($id);");
  		// ein Feld, das die Kurse den möglichen Terminen zuordnet
    }
    $ergebnis = db_exec($verbindung,
    			"SELECT DISTINCT course.id,name "
				. "FROM course,$course_date_readable "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. $filter
				. ";");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0) - $course_offset;
      $name = pg_result($ergebnis, $lt, 1);
      $javascript .= ("
  kurse[$id] = \"$name\";");
    }
    $ergebnis = db_exec($verbindung,
    			"SELECT DISTINCT count(id),category "
				. "FROM (SELECT DISTINCT course.id,category "
				. "FROM course,$course_date_readable "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. $filter
				. ") "
				. "AS courses_for_category "
				. "GROUP BY category;");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $kurse = pg_result($ergebnis, $lt, 0);
      $kategorie = pg_result($ergebnis, $lt, 1);
      $javascript .= ("
  var kurse_kategorie_$kategorie = Array($kurse);
  kategorien[$kategorie] = kurse_kategorie_$kategorie;");
    }
    $ergebnis = db_exec($verbindung, "SELECT id FROM category");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0);
      $inner_result = db_exec($verbindung,
      			"SELECT DISTINCT id,name,position "
				. "FROM (SELECT course.id,name,max(position) "
				. "AS position "
				. "FROM course,$course_date_readable "
				. "WHERE course_period=$course_period "
				. "AND course=course.id "
				. "AND category = $id"
				. $filter
				. " "
				. "GROUP BY course.id,name) "
				. "AS by_course "
				. "ORDER BY position,name");
      for ($kurs = 0; $kurs < pg_numrows($inner_result); $kurs++) {
        $global_kurs = pg_result($inner_result, $kurs, 0) - $course_offset;
	$javascript .= ("
  kurse_kategorie_$id" . "[$kurs] = $global_kurs;");
      }
    }
    $javascript .= '
  var termine = new Array(';
    $ergebnis = db_exec($verbindung,
    			"SELECT max($course_date_readable.id) + 1 "
				. "FROM $course_date_readable,course "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. $filter
				. ";");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0) - $date_offset;
      $javascript .= ($id);
    }
    $javascript .= ');'; /* ein Feld mit den Terminangaben in Textform */
    $ergebnis = db_exec($verbindung,
    			"SELECT $course_date_readable.id,description "
				. "FROM $course_date_readable,course,language "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. ($course_date_translated
					? (" AND code='$language' "
						. "AND language=language.id")
					: "")
				. $filter
				. ";");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0) - $date_offset;
      $termin = pg_result($ergebnis, $lt, 1);
      $javascript .= ("
  termine[$id] = \"$termin\";");
    }
    $ergebnis = db_exec($verbindung,
    			"SELECT count($course_date_readable.id),course "
				. "FROM $course_date_readable,course "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. $filter
				. " "
				. "GROUP BY course"
				. ($course_date_translated ? ",language" : ""));
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $termine = pg_result($ergebnis, $lt, 0);
      $kurs = pg_result($ergebnis, $lt, 1) - $course_offset;
      $javascript .= ("
  termine_kurs_$kurs = Array($termine);
  kurs_termine[$kurs] = termine_kurs_$kurs;");
    }
    $ergebnis = db_exec($verbindung,
    			"SELECT DISTINCT course.id FROM course,"
				. "$course_date_readable "
				. "WHERE course_period=$course_period "
				. "AND course=course.id"
				. $filter
				. ";");
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis, $lt, 0);
      $kurs = $id - $course_offset;
      $inner_result = db_exec($verbindung,
      				"SELECT DISTINCT $course_date_readable.id "
				. "FROM $course_date_readable,course "
				. "WHERE course_period=$course_period "
				. "AND course=course.id "
				. "AND course = $id"
				. $filter
				. ";");
      for ($termin = 0; $termin < pg_numrows($inner_result); $termin++) {
        $global_termin = pg_result($inner_result, $termin, 0) - $date_offset;
	$javascript .= ("
  termine_kurs_$kurs" . "[$termin] = $global_termin;");
      }
    }
    return $javascript;
  }
  function course_data_pass() {
    $result = value_pass('kursanzahl');
    for ($kurs = 1; $kurs <= $_REQUEST['kursanzahl']; $kurs++) {
      $result .= value_pass("kategorie_kurs$kurs")
		. value_pass("kurs_kurs$kurs")
		. value_pass("termin_kurs$kurs")
		. value_pass("kurs_kurs_alternative$kurs")
		. value_pass("termin_kurs_alternative$kurs")
		. value_pass("kommentar_kurs$kurs");
    }
    return $result;
  }
  function static_course_period() {
    global $verbindung, $course_term, $course_begin_year;
    $ergebnis = db_exec($verbindung,
  			"SELECT course_period.id "
				. "FROM course_period,course_term "
				. "WHERE course_period.term=course_term.id "
				. "AND course_term.term='$course_term' "
				. "AND begin_year=$course_begin_year;");
    return (pg_numrows($ergebnis) > 0) ? pg_result($ergebnis, 0, 0) : 0;
  }
  function static_option_value($option) {
    $value = $option['default']();
    $option['set-hook']($value);
    return $value;
  }
  function option_value($option) {
    if ($_REQUEST[$option['variable']]) {
      $value = intval($_REQUEST[$option['variable']]);
    } else {
      $value = $option['default']();
    }
    $option['set-hook']($value);
    return $value;
  }
  function option_setter($language,$option) {
    global $lang_choose;
    return '<a href="' . $option['configurator']
		. '?continuation=' . urlencode($_SERVER['REQUEST_URI']) . '">'
		. ling_verb_short($language,
				$lang_choose[$language],
				$option['name']) . '</a>';
  }
  function set_date_tables($course_period) {
    global $course_date, $course_date_readable, $date_columns, $verbindung;
    global $course_date_translated;
    $ergebnis = db_exec($verbindung,
			"SELECT date_table,readable_table,columns,translated "
				. "FROM course_period_date_tables,"
					. "course_date_tables,"
					. "course_date_columns,"
					. "course_date_translated "
				. "WHERE course_date_tables="
					. "course_date_tables.id "
				. "AND course_date_columns.tables="
					. "course_date_tables.id "
				. "AND course_date_translated.tables="
					. "course_date_tables.id "
				. "AND course_period=$course_period");
    if (pg_numrows($ergebnis) > 0) {
      $course_date = pg_result($ergebnis, 0, 0);
      $course_date_readable = pg_result($ergebnis, 0, 1);
      $date_columns = pg_result($ergebnis, 0, 2);
      $course_date_translated = (pg_result($ergebnis, 0, 3) == 't');
    } else {
      $course_date = 'course_date';
      $course_date_readable = 'course_date_readable_translated';
      $date_columns = 'weekday,begin_time,end_time';
      $course_date_translated = true;
    }
  }
  function configure_option($option) {
    global $presented;
    if ($_GET[$option['variable']]) {
      setcookie($option['variable'], $_GET[$option['variable']]);
      header('Location: ' . $_GET['continuation']);
    } else {
      $option_value = option_value($option);
      $option_choices = $option['choices']($option);
      require('local-criteria.php');
      $presented = array(
		'choices' => $option_choices,
		'value' => $option_value,
		'name' => $option['name'],
		'configurator' => $option['configurator'],
		'variable' => $option['variable']);
      load_template_overridable('set-option');
    }
  }
  function choices_from_database($option) {
    global $verbindung;
    $ergebnis = db_exec($verbindung, $option['choice_query']);
    $choices = array();
    for ($lt = 0; $lt < pg_numrows($ergebnis); $lt++) {
      $id = pg_result($ergebnis,$lt,0);
      $description = pg_result($ergebnis,$lt,1)
    			. ' '
			. pg_result($ergebnis,$lt,2);
      array_push($choices, array(
		'id' => $id,
		'description' => $description));
    }
    return $choices;
  }
  function static_choices($option) {
    return $option['static_choices'];
  }
  function static_default($option) {
    return $option['static_default'];
  }
  function null_string_generator($input) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
null_string_generator
</pre>
<?php
    }
    return '';
  }
  function truth($input) {
    return true;
  }
  function parenthesized($raw) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
parenthesized
</pre>
<?php
    }
    return "(" . $raw . ")";
  }
  function field_name_identifier($input,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
field_name_identifier
</pre>
<?php
    }
    return 'field' . $input["field"];
  }
  function table_with_registration($table_name,$ignored) {
    global $table_registration;
    return "$table_name," . $table_registration[$table_name]['table'];
  }
  function registration_table($table_name,$ignored) {
    global $table_registration;
    return $table_registration[$table_name]['table'];
  }
  function empty_data_record($input,$arguments) {
    return array();
  }
  function user_possessed_formulation($possessed) { /* returns a formulation for
			the object $possessed belonging to the reader */
    global $gender,$possessive;
    return $possessive[2]["polite"][$gender[$possessed]] . " " . $possessed;
  }
  function accusative_plural($base) { /* returns the accusative plural form of
  						the word $base */
    global $accusative_plural;
    $looked_up = $accusative_plural[$base];
    if ($looked_up == "") {
      return $base . "en";
    } else {
      return $looked_up;
    }
  }
  function set_debug_marker($id) { /* set a debug marker to globally bisect
  					bugs */
    global $debug_mark;
    $debug_mark[$id] = '
';
  }
  $templates = array();
  function register_template($name) { /* registers a template as being secure
  					to plug in every data source */
    global $templates;
    $templates[$name] = "template-$name.php";
  }
  function load_template_overridable($default) { /* loads specified template
  					unless other template is requested */
    global $templates,$presented,$javascript,$local_stylesheets;
    global $language,$plural;
    $template = $templates[($_REQUEST['template'] == "")
    				? $default
				: $_REQUEST['template']];
    if ($template == "") {
      $template = $templates[$default];
      $presented['error'] .= "
Gewünschtes Template '"
		. $_REQUEST['template']
		. "' konnte nicht geladen werden!";
    }
    require_once($template);
  }
  require('templates.php');
?>
Return current item: Course-manager