<?php require_once 'database.php'; ?>
<?php require_once 'genformformats.php'; ?>
<?php
/* __ Defines _____________________________________________________________ */
/* Field types
*/
define ("FT_INTEGER", 1);
define ("FT_STRING", 2);
define ("FT_LOOKUP", 3);
define ("FT_MULTILINE", 4);
/* Visilibility types
*/
define ("VS_NOTVISIBLE", 0);
define ("VS_READONLY", 1);
define ("VS_EDITABLE", 2);
/* __ Implementation ______________________________________________________ */
/*
*
*/
function gf_generateField($fieldName, $fieldDisplay, $visible, $size)
{
print(GF_TABLE_ROW_BEGIN."\n");
print(GF_TABLE_CELL_BEGIN . $fieldDisplay . GF_TABLE_CELL_END);
print(GF_TABLE_CELL_BEGIN);
switch ($visible) {
case VS_READONLY:
break;
case VS_EDITABLE:
print("<INPUT TYPE=text NAME=\"$fieldName\" SIZE=$size>\n");
break;
default:
}
print(GF_TABLE_CELL_END);
print(GF_TABLE_ROW_END."\n");
}
/*
*
*/
function gf_generateLookupField($db, $fieldName, $fieldDisplay, $query,
$lookupIdField, $lookupDisplayField,
$onchangeText = "")
{
print("<SELECT NAME=\"$fieldName\" onchange = \"$onchangeText\">\n");
$lookup = ttdb_execQuery($db, $query);
if ($lookup) {
while ( ($fields = ttdb_getArray($lookup)) != false) {
echo '<OPTION VALUE="'.
$fields[$lookupIdField].'">'.
$fields[$lookupDisplayField]."\n";
}
}
print("</SELECT>\n");
}
/*
*
*/
function gf_generateLookupFieldSelected($db, $fieldName, $fieldDisplay, $query,
$lookupIdField, $lookupDisplayField, $selectedIdValue,
$allowNull = True, $onchangeText = "")
{
// We want to return also one value, either the selected item, or the first in the list
$returnValue = -1;
print("<SELECT NAME=\"$fieldName\" onchange=\"$onchangeText\">\n");
$lookup = ttdb_execQuery($db, $query);
$i = 0;
if ($lookup) {
while (($fields = ttdb_getArray($lookup)) != false) {
$currIdValue = $fields[$lookupIdField];
$currFieldValue = $fields[$lookupDisplayField];
if ($i == 0) $returnValue = $currIdValue;
if ($currIdValue == $selectedIdValue) {
print('<OPTION VALUE="'.$currIdValue.'" SELECTED>'.$currFieldValue."\n");
$returnValue = $currIdValue;
$selected = 1;
} else
print('<OPTION VALUE="'.$currIdValue.'">'.$currFieldValue."\n");
$i++;
} // while
if (!$selected)
$selText = " SELECTED";
else
$selText = "";
if ($allowNull) {
print("<OPTION VALUE=\"null\"$selText>\n");
} // if
} // if
print("</SELECT>\n");
return $returnValue;
}
?>