Location: PHPKode > projects > Course-manager > courseman-0.1.1/input.php
<?php
  function horizontal_description_input_separator($input,$arguments) {
    return '</td>
<td>';
  }
  function vertical_description_input_separator($input,$arguments) {
    return '</td>
</tr>
<tr' . $input['attributes'] . ' id="field_' . $input['field'] . '_input">
<td>';
  }
  function visible_elements_registration_code($input,$arguments) {
    $field = $input['field'];
    $result = "
  var field_" . $field . "_values = new Array();";
    foreach ($input['layout_elements'] as $element) {
      $result .= "
  " . js_array_push("field_" . $field . "_values","'field_$field$element'");
    }
    return $result;
  }
  function requestable_code_once($input,$arguments) {
    if (!$input['requestable_code_returned']) {
      return $input['calls']($input,'requestable_code',$arguments);
      $input['requestable_code_returned'] = true;
    } else {
      return '';
    }
  }
  function option_choices($input,$arguments) {
    global $verbindung;
    $ergebnis = db_exec($verbindung, "SELECT "
		. $input["option_index_column"]
		. "," . $input["column"]
		. "
	FROM " . $input["table"] . "
	ORDER BY " . $input["option_index_column"] . ";");
    for ($row = 0; $row < pg_numrows($ergebnis); $row++) {
      $col = 0;
      $index = pg_result($ergebnis, $row, $col++);
      $value = pg_result($ergebnis, $row, $col++);
      $choices[$index] = $value;
		// order is kept, see http://bugs.php.net/bug.php?id=18629
    }
    return $choices;
  }
  function translated_choices($input,$arguments) {
    global $verbindung,$language;
    $ergebnis = db_exec($verbindung, "SELECT "
		. $input["option_index_column"]
		. "," . $input["column"]
		. "
	FROM " . $input["table"] . ",language
	WHERE language.id=language
	AND language.code='" . pg_escape_string($language) . "'
	ORDER BY " . $input["option_index_column"] . ";");
    for ($row = 0; $row < pg_numrows($ergebnis); $row++) {
      $col = 0;
      $index = pg_result($ergebnis, $row, $col++);
      $value = pg_result($ergebnis, $row, $col++);
      $choices[$index] = $value;
		// order is kept, see http://bugs.php.net/bug.php?id=18629
    }
    return $choices;
  }
  function input_trigger_code($input,$arguments) {
    global $debug_mark,$debug;
    $field = $input['field'];
    $result = "
  function init_$field() {" . $debug_mark[64];
    $choices = $input['input_choices']($input,array());
    foreach ($choices as $index => $value) {
      $result .= "
    var field = document.getElementById('"
    		. $field
		. "_$index');" . ($debug['javascript'] ? "
    alert('checking status of a ' + introspect(field));" : "") . "
    if (field.checked) {" . $debug_mark[71] . "
      set_" . $field . "_to($index);
    }" . $debug_mark[65];
    }
    $result .= "
  }
  " . js_array_push("window_initializers","init_$field") . "
  var value_$field;" . $debug_mark[66];
    foreach ($input['triggered']['elements'] as $triggered) {
      $result .= $triggered['calls']($triggered,
                                     'requestable_code_once',
				     array());
    }
    $result .= "
  function set_" . $field . "_to(value) {
    var triggered;
    var visibility;
    value_$field = value;" . $debug_mark[67];
    foreach ($input['triggered']['elements'] as $triggered) {
      foreach ($choices as $index => $value) {
        if ($triggered['trigger_value'] == $value) {
          $result .= "
    triggered = field_" . $triggered['field'] . "_values;" . $debug_mark[68] . "
    if (value == $index) {
      visibility = 'visible';
    } else {
      visibility = 'hidden';
    }" . $debug_mark[69] . "
    for (var id = 0; id < triggered.length; id++) {
      document.getElementById(triggered[id]).style.visibility = visibility;
    }";
        }
      }
    }
    $result .= "
  }
  function set_$field(event) {
    if (window.event) {
      event = window.event;
    }
    var target = event.srcElement;
    if (!target) {
      target = event.target;
    }" . $debug_mark[70] . "
    set_" . $field . "_to(target.value);
  }";
    return $result;
  }
  function annotated_layout($input,$arguments) {
    return $input['calls']($input,'annotation_layout',array())
    	. $input['calls']($input,'input_layout',array());
  }
  function annotation_layout($input,$arguments) {
    return "<tr id='field_"
    		. $input["field"]
		. "_annotation'"
		. $input["attributes"]
		. ">
<td colSpan='2'>
<span class='erlaeuterung'>" . $input['annotation'] . "</span>
</td>
</tr>
";
  }
  function text_input_layout($input,$arguments) {
    global $debug,$reload;
    if($debug["old-debug"]) {
?>
<pre>
text_input_layout
</pre>
<?php
    }
    return "<tr id='field_" . $input["field"] . "'" . $input["attributes"] . ">
<td>" . $input["field_marker"] . "
<b>" . $input["description"] . '</b>
' . $input["description_input_separator"]($input,$arguments) . '
<input type="TEXT"
       id="' . $input["field"] . '"
       name="' . $input["field"] . '"
       value="' . field_escape($reload[$input["field"]]
				? $reload[$input["field"]]
				: $_REQUEST[$input["field"]]) . '" />
</td>
</tr>
';
  }
  function checkbox_input_layout($input,$arguments) {
    return "<tr id='field_" . $input["field"] . "'" . $input["attributes"] . ">
<td colSpan='2'>" . $input["field_marker"] . "
<input type='CHECKBOX' name='" . $input["field"] . "' value='1' />
<b>" . $input["description"] . '</b>
</td>
</tr>
';
  }
  function radio_input_layout($input,$arguments) {
    global $reload;
    $layout = "<tr id='field_"
			. $input["field"]
			. "'"
			. $input["attributes"]
			. ">
<td valign='top'>" . $input["field_marker"] . "
<b>" . $input["description"] . "</b>
" . $input["description_input_separator"]($input,$arguments) . "
<table>
<tr>
<td>
";
    $choices = $input['input_choices']($input,array());
    $lt = 0;
    foreach ($choices as $index => $option) {
      if ($lt > 0) {
        $layout .= "</td>
</tr>
<tr>
<td>
";
      }
      $layout .= "<input type='RADIO' name='"
			. $input["field"]
			. "' value='$index'"
			. ((($reload[$input["field"]]
				? $reload[$input["field"]]
				: $_REQUEST[$input["field"]]) == $index)
				? ' checked'
				: '')
			. " />
$option
";
      $lt++;
    }
    $layout .= "</td>
</tr>
</table>
</td>
</tr>
";
    return $layout;
  }
  function menu_input_layout($input,$arguments) {
    global $reload;
    $layout = "<tr id='field_"
			. $input["field"]
			. "'"
			. $input["attributes"]
			. ">
<td>" . $input["field_marker"] . "
<b>" . $input["description"] . "</b>
" . $input["description_input_separator"]($input,$arguments) . "
<select name='" . $input["field"] . "' id='" . $input["field"] . "'>
<option value=''>Bitte w&auml;hlen Sie "
	. user_possessed_formulation($input["description"])
	. "</option>
";
    $choices = $input['input_choices']($input,array());
    foreach ($choices as $index => $option) {
      $layout .= "<option value='$index' "
			. ((($reload[$input["field"]]
					? $reload[$input["field"]]
					: $_REQUEST[$input["field"]]) == $index)
				? ' selected'
				: '')
			. ">$option</option>
";
    }
    $layout .= "</select>
</td>
</tr>
";
    return $layout;
  }
  function radio_input_layout_triggering($input,$arguments) {
    global $reload;
    $field = $input["field"];
    $layout = "<tr id='field_" . $field . "'" . $input["attributes"] . ">
<td valign='top'>" . $input["field_marker"] . "
<b>" . $input["description"] . "</b>
" . $input["description_input_separator"]($input,$arguments) . "
<table>
<tr>
<td>
";
    $choices = $input['input_choices']($input,array());
    foreach ($choices as $index => $option) {
      if ($lt > 0) {
        $layout .= "</td>
</tr>
<tr>
<td>
";
      }
      $layout .= "<input type='RADIO' name='"
			. $field
			. "' value='$index'"
			. " id='" . $field . "_" . $index . "'"
			. " onclick='set_" . $field . "_to($index)'"
			. ((($reload[$field]
				? $reload[$field]
				: $_REQUEST[$field]) == $index)
				? ' checked'
				: '')
			. " />
$option
";
      $lt++;
    }
    $layout .= "</td>
</tr>
</table>
</td>
<td>
<table>
" . $input['triggered']['calls']($input['triggered'],
                                 'annotated_layout',
                                 array()) . "</table>
</td>
</tr>
";
    return $layout;
  }
  function menu_input_layout_triggering($input,$arguments) {
    global $verbindung,$reload;
    $field = $input["field"];
    $layout = "<tr id='field_" . $field . "'" . $input["attributes"] . ">
<td>" . $input["field_marker"] . "
<b>" . $input["description"] . "</b>
" . $input["description_input_separator"]($input,$arguments) . "
<select name='$field' id='$field' onchange='set_$field'>
<option value=''>Bitte w&auml;hlen Sie "
	. user_possessed_formulation($input["description"])
	. "</option>
";
    $choices = $input['input_choices']($input,array());
    foreach ($choices as $index => $option) {
      $layout .= "<option value='$index' "
			. ((($reload[$field]
					? $reload[$field]
					: $_REQUEST[$field]) == $index)
				? ' selected'
				: '')
			. ">$option</option>
";
    }
    $layout .= "</select>
</td>
<td>
<table>
" . $input['triggered']['calls']($input['triggered'],
                                 'annotated_layout',
                                 array()) . "</table>
</td>
</tr>
";
    return $layout;
  }
  function input_unchecked_condition($input,$arguments) {
    global $verbindung;
    $condition = '!(';
    $possibilities = count($input['input_choices']($input,array()));
    for ($i = 0; $i < $possibilities; $i++) {
      if ($i > 0) {
        $condition .= ' ||
		';
      }
      $condition .= "document.daten." . $input["field"] . "[$i].checked";
    }
    $condition .= ')';
    return $condition;
  }
  function input_empty_condition($input,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
input_empty_condition
</pre>
<?php
    }
    return 'document.getElementById("' . $input["field"] . '").value == ""';
  }
  function input_invalid_number_condition($input,$arguments) {
    return '!valid_number(document.daten.' . $input["field"] . '.value)
			|| ' . input_empty_condition($input,$arguments);
  }
  function checkbox_unchecked_condition($input,$arguments) {
    return '!document.daten.' . $input["field"] . '.checked';
  }
  function mandatory_input_check($input,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
mandatory_input_check
</pre>
<?php
    }
    return $input['calls']($input,'input_check_condition',$arguments) . ') {
      alert("' . $input["omission_alert"] . '");
      return false;
    } else if (';
  }
  function triggered_condition($input,$arguments) {
    global $verbindung;
    $ergebnis = db_exec($verbindung, "SELECT "
			. $input['triggering']["option_index_column"]
			. "
			FROM " . $input['triggering']["table"]
			. $input['triggering']["specifying_tables"] . "
			WHERE " . $input['triggering']["column"] . "='"
			. pg_escape_string($input['trigger_value']) . "'"
			. $input['triggering']['specifying_joins'] . ";");
    if (pg_numrows($ergebnis) > 0) {
      return 'value_'
			. $input['trigger_field']
			. ' == "'
			. pg_result($ergebnis,0,0)
			. '"';
    } else {
      return 'false';
    }
  }
  function server_side_triggered_condition($input,$arguments) {
    global $verbindung;
    $ergebnis = db_exec($verbindung, "SELECT "
			. $input['triggering']["option_index_column"]
			. "
			FROM " . $input['triggering']["table"]
			. $input['triggering']["specifying_tables"] . "
			WHERE " . $input['triggering']["column"] . "='"
			. pg_escape_string($input['trigger_value']) . "'"
			. $input['triggering']['specifying_joins'] . ";");
    if (pg_numrows($ergebnis) == 0) {
      return false;
    }
    return $_REQUEST[$input['trigger_field']] == pg_result($ergebnis,0,0);
  }
  function triggered_input_condition($input,$arguments) {
    return '('
		. $input['calls']($input,
                                  'relevance',
                                  array())
                . ') && ('
		. $input['untriggered']['calls']($input['untriggered'],
                                                 'input_check_condition',
                                                 array())
		. ')';
  }
  function server_side_triggered_input_condition($input,$arguments) {
    return ($input['calls']($input,
                             'server_side_relevance',
                             array()))
	&& ($input['untriggered']['calls']($input['untriggered'],
                                           'server_input_check_condition',
                                           array()));
  }
  function server_side_input_condition($input,$arguments) {
    return $_REQUEST[$input["field"]] == "";
  }
  function server_side_invalid_number_condition($input,$arguments) {
    return preg_match("/[^0-9]/", $_REQUEST[$input["field"]])
    		|| server_side_input_condition($input,$arguments);
  }
  function server_side_input_check($input,$arguments) {
    if ($input['calls']($input,'server_input_check_condition',$arguments)) {
      return "<br />
" . $input["omission_alert"] . "
";
    }
    return '';
  }
  function hidden_value_pass($input,$arguments) {
    return value_pass($input["field"]);
  }
  function hook_conditional_input(&$input,$arguments) {
    global $data_fields,$debug,$objects;
    $trigger_field = &$data_fields[$input['trigger_field']];
    $input['triggering'] =& $trigger_field;
    if($debug["old-debug"]) {
?>
<pre>
hooking data field <?=$trigger_field['calls']($trigger_field,
                                              'object_identifier',
                                              array())?>
</pre>
<?php
    }
    if (!$trigger_field['triggered']) {
      foreach ($trigger_field['trigger_overlay'] as $name => $implementation) {
        if($debug["old-debug"]) {
?>
<pre>
replacing method <?=$name?>
</pre>
<?php
        }
        $trigger_field[$name] = $implementation;
      }
      $trigger_field['triggered'] = reduced_input(array());
    }
    $untriggered = $input;
    $untriggered['initialize_interoperations'] = null_string_generator;
    $untriggered = copied_object($untriggered);
    $input['untriggered'] =& $untriggered;
    array_push($trigger_field['triggered']['elements'],$untriggered);
    $input['input_check_condition'] = triggered_input_condition;
    $input['annotated_layout'] = null_string_generator;
    $input['server_input_check_condition']
		= server_side_triggered_input_condition;
    $objects[$trigger_field['oid']] = $trigger_field;
    return '';
  }
?>
Return current item: Course-manager