System = $System; $this->Definition = $FormClass; $this->QueryParameters = array(); } function CheckOrder() { if(!array_key_exists('Order', $_GET) or (array_key_exists('Order', $_GET) and ($_GET['Order'] != '0') and ($_GET['Order'] != '1'))) { if(array_key_exists('DefaultOrderDirection', $this->Definition)) $_GET['Order'] = $this->Definition['DefaultOrderDirection']; else $_GET['Order'] = 0; }; if(!array_key_exists('Column', $_GET) or (array_key_exists('Column', $_GET) and !array_key_exists($_GET['Column'], $this->Definition['Items']))) { if(array_key_exists('DefaultOrderColumn', $this->Definition)) $_GET['Column'] = $this->Definition['DefaultOrderColumn']; else { $Keys = array_keys($this->Definition['Items']); $_GET['Column'] = $Keys[0]; } } } function Show() { $this->CheckOrder(); $Header = array(); $QueryStringArray = $this->System->HTTP->GetQueryStringArray(); $QueryStringArray['Order'] = $_GET['Order']; foreach($this->Definition['Items'] as $Index => $Item) { if($Item['Type'] != 'Hidden') { $QueryStringArray['Column'] = $Index; if($_GET['Column'] == $Index) $QueryStringArray['Order'] = 1 - $_GET['Order']; else $QueryStringArray['Order'] = $_GET['Order']; $Header[] = ''.$Item['Caption'].''; } } $Table = array( 'Header' => $Header, 'Rows' => $this->Values, ); $Output = $this->Table($Table, 'WideTable', 'LiftList'); $Output .= '
'.$this->PageList('Page', $this->Page, $this->TotalRowCount, $this->RowPerPage).'
'; return($Output); } function LoadValuesFromDatabase($Database) { $this->CheckOrder(); $OrderType = array('ASC', 'DESC'); $this->Header = array(); foreach($this->Definition['Items'] as $Index => $Item) { $this->Header[] = $Item['Caption']; } $this->Values = array(); $Table = $this->Definition['Table']; foreach($this->QueryParameters as $Index => $Item) $Table = str_replace('%'.$Index, $Item, $Table); $DbResult = $Database->query('SELECT COUNT(*) FROM '.$Table.' AS T ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']]); $DbRow = $DbResult->fetch_row(); $this->TotalRowCount = $DbRow[0]; if(array_key_exists('Page', $_GET)) $this->Page = $_GET['Page']; else $this->Page = 0; if($this->Page > ($this->TotalRowCount / $this->RowPerPage)) $this->Page = 0; $DbResult = $Database->query('SELECT * FROM '.$Table.' AS T ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']].' LIMIT '.($this->Page * $this->RowPerPage).', '.$this->RowPerPage); echo($Database->error); while($DbRow = $DbResult->fetch_assoc()) { if(method_exists($this->OnRow[0], $this->OnRow[1])) { $Object = $this->OnRow[0]; $Method = $this->OnRow[1]; $DbRow = $Object->$Method($DbRow); } $Row = array(); foreach($this->Definition['Items'] as $Index => $Item) { $DbRow[$Index] = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnView', array('Name' => $Index, 'Value' => $DbRow[$Index], 'Type' => $Item['Type'])); $Row[$Index] = $DbRow[$Index]; } $this->Values[] = $Row; } } } ?>