Cells[$Y][$X]); } function RowsCount() { return(count($this->Cells)); } } class TableSQL extends Table { var $Query; var $Database; var $Cells; function GetCell($Y, $X) { return($this->Cells[$Y][$X]); } function BeginRead() { $this->Cells = array(); $DbResult = $this->Database->query($this->Query); while($DbRow = $DbResult->fetch_row()) { $this->Cells[] = $DbRow; } } function EndRead() { $this->Cells = array(); } function RowsCount() { return(count($this->Cells)); } } class TableColumn { var $Name; var $Title; } class VisualTable extends Control { var $Cells; var $Columns; var $OrderSQL; var $OrderColumn; var $OrderDirection; var $OrderArrowImage; var $DefaultColumn; var $DefaultOrder; var $Table; function __construct() { global $System; $this->Columns = array(); $this->Table = new TableMemory(); $this->OrderDirSQL = array('ASC', 'DESC'); $this->OrderArrowImage = array($System->Link('/images/sort_asc.png'), $System->Link('/images/sort_desc.png')); $this->DefaultOrder = 0; } function SetColumns($Columns) { $this->Columns = array(); foreach($Columns as $Column) { $NewCol = new TableColumn(); $NewCol->Name = $Column['Name']; $NewCol->Title = $Column['Title']; $this->Columns[] = $NewCol; } if(count($this->Columns) > 0) $this->DefaultColumn = $this->Columns[0]->Name; else $this->DefaultColumn = ''; } function Show() { $Output = ''; $Output .= $this->GetOrderHeader(); $this->Table->BeginRead(); for($Y = 0; $Y < $this->Table->RowsCount(); $Y++) { $Output .= ''; for($X = 0; $X < count($this->Columns); $X++) { $Cell = $this->Table->GetCell($Y, $X); if($Cell == '') $Output .= ''; else $Output .= ''; } $Output .= ''; } $this->Table->EndRead(); $Output .= '
 '.$Cell.'
'; return($Output); } function GetOrderHeader() { if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir']; if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $this->DefaultColumn; if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $this->DefaultOrder; // Check OrderCol $Found = false; foreach($this->Columns as $Column) { if($Column->Name == $_SESSION['OrderCol']) { $Found = true; break; } } if($Found == false) { $_SESSION['OrderCol'] = $this->DefaultColumn; $_SESSION['OrderDir'] = $this->DefaultOrder; } // Check OrderDir if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0; $Result = ''; $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); foreach($this->Columns as $Index => $Column) { $QueryItems['OrderCol'] = $Column->Name; $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir']; if($Column->Name == $_SESSION['OrderCol']) $ArrowImage = 'order arrow'; else $ArrowImage = ''; if($Column->Name == '') $Result .= ''.$Column->Title.''; else $Result .= ''.$Column->Title.$ArrowImage.''; } $this->OrderSQL = ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$this->OrderDirSQL[$_SESSION['OrderDir']]; $this->OrderColumn = $_SESSION['OrderCol']; $this->OrderDirection = $_SESSION['OrderDir']; return($Result); } }