Update of /cvsroot/phpvortex/phpvortex
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24501
Added Files:
FT_List.class.php
Log Message:
Added FT_List class
--- NEW FILE: FT_List.class.php ---
<?php
/**
* File for class FT_List.
*
* @package Vortex
* @subpackage DB
* @author Thiago Ramon Gonçalves Montoya
* @copyright Copyright 2004, Thiago Ramon Gonçalves Montoya
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
/** Require the base class */
require_once('FT_Base.class.php');
/**
* Database field, List (<select>) with contents in a table.
*
* @package Vortex
* @subpackage DB
*/
class FT_List extends FT_Base
{
/**
* Default value of the field.
*
* @var string
*/
var $default = '-1';
/**
* Table to get the list from.
*
* @var string
*/
var $rel_table = '';
/**
* Field to use as key in the table.
*
* @var string
*/
var $rel_key = '';
/**
* Field to use as label in the table.
*
* @var string
*/
var $rel_label = '';
/**
* Field to order by in the table.
*
* @var string
*/
var $rel_order = '';
/**
* Output the field as a HTML Form.
*
* @param string $value Value to load the control with.
*/
function ShowForm($value)
{
global $vortex_msgs;
$sql = "SELECT {$this->rel_key}, {$this->rel_label} FROM {$this->rel_table}".(empty($this->rel_order)?'':" ORDER BY {$this->rel_order}");
if (!empty($debug)) dv(3, 'FT_List::ShowForm() SELECT', $sql);
if (!($rs = $this->db->Query($sql))) {
return;
}
echo "<select name='{$this->name_form}'>\n";
echo "\t<option value='-1'".((-1 == $value)?' selected':'').">{$vortex_msgs['list_default']}</option>\n";
while ($row = $rs->Row()) {
echo "\t<option value='{$row['$this->rel_key']}'".(($this->rel_key == $value)?' selected':'').">{$this->rel_label}</option>\n";
}
echo "</select>\n";
}
/**
* Output the field as plain text.
*
* @param string $value Value to load the control with.
*/
function ShowPlain($value)
{
$sql = "SELECT {$this->rel_label} FROM {$this->rel_table} WHERE {$this->rel_key} = $value";
if (!empty($debug)) dv(3, 'FT_List::ShowPlain() SELECT', $sql);
if (!($rs = $this->db->Query($sql))) {
return;
}
$row = $rs->Row();
echo $row[$this->rel_label];
}
/**
* Output the field consistency testing in JavaScript.
*/
function JSConsist()
{
if ($this->required) {
echo <<<END
if (frm.{$this->name_form}.selectedIndex < 1) errors += " * {$this->label}\\n";
END;
}
}
/**
* Test the field consistency.
*
* @param string $field The data from the field to be tested.
* @return bool Returns TRUE if the field is consistent, FALSE otherwise.
*/
function ConsistTest(&$field)
{
if ($this->required && (empty($field) || ($field < 0))) return FALSE;
return TRUE;
}
/**
* Format the field for database insertion.
*
* @param string $field The data from the field to be formated.
* @return string Returns the formated field.
*/
function ConsistFormat(&$field)
{
return (string)((int)$field);
}
}
?>
|