source: trunk/www/table.php@ 15

Last change on this file since 15 was 15, checked in by george, 16 years ago
  • Přidáno: Nastavení parametrů gcc překladu emulátoru přes konfigurační soubor.
  • Přidáno: Podpora řazení dle sloupců v tabulkách.
  • Upraveno: Nezjišťovat informace o stavu serverů z tabulek mangosu, ale ukládat stavové informace serverů přímo do tabulky Server. Nutno provádět aktualizaci tabulky.
File size: 2.5 KB
Line 
1<?php
2
3class Table
4{
5 var $Id;
6 var $Definition;
7 var $Values;
8 var $Header;
9 var $OnRow;
10 var $QueryParameters;
11
12 function __construct($ClassName)
13 {
14 global $FormClasses;
15
16 $this->Definition = &$FormClasses[$ClassName];
17 $this->QueryParameters = array();
18 }
19
20 function Show()
21 {
22 $Header = array();
23 if(!array_key_exists('Order', $_GET)) $_GET['Order'] = 0;
24 if(!array_key_exists('Column', $_GET)) $_GET['Column'] = 0;
25 $QueryParts = explode('&', $_SERVER['QUERY_STRING']);
26 foreach($QueryParts as $Part)
27 {
28 $Part2 = explode('=', $Part);
29 $QueryItems[$Part2[0]] = $Part2[1];
30 }
31 $QueryItems['Order'] = $_GET['Order'];
32 foreach($this->Definition['Items'] as $Index => $Item)
33 {
34 $QueryItems['Column'] = $Index;
35 if($_GET['Column'] == $Index) $QueryItems['Order'] = 1 - $_GET['Order'];
36 else $QueryItems['Order'] = $_GET['Order'];
37 $QueryParts = array();
38 foreach($QueryItems as $Index2 => $Item2)
39 {
40 $QueryParts[] = $Index2.'='.$Item2;
41 }
42 $Header[] = '<a href="?'.implode('&amp;', $QueryParts).'">'.$Item['Caption'].'</a>';
43 }
44 $Table = array(
45 'Header' => $Header,
46 'Rows' => $this->Values,
47 );
48 $Output = Table($Table, 'WideTable');
49 return($Output);
50 }
51
52 function LoadValuesFromDatabase($Database)
53 {
54 $OrderType = array('ASC', 'DESC');
55 if(!array_key_exists('Order', $_GET)) $_GET['Order'] = 0;
56 else if($_GET['Order'] == 'Asc') $_GET['Order'] = 1;
57 if(!array_key_exists('Column', $_GET))
58 {
59 $Keys = array_keys($this->Definition['Items']);
60 $_GET['Column'] = $Keys[0];
61 }
62 $this->Header = array();
63 foreach($this->Definition['Items'] as $Index => $Item)
64 {
65 $this->Header[] = $Item['Caption'];
66 }
67 $this->Values = array();
68 $Table = $this->Definition['Table'];
69 foreach($this->QueryParameters as $Index => $Item)
70 $Table = str_replace('%'.$Index, $Item, $Table);
71 $DbResult = $Database->query('SELECT * FROM '.$Table.' ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']]);
72 while($DbRow = $DbResult->fetch_assoc())
73 {
74 if(method_exists($this->OnRow[0], $this->OnRow[1]))
75 {
76 $Object = $this->OnRow[0];
77 $Method = $this->OnRow[1];
78 $DbRow = $Object->$Method($DbRow);
79 }
80 $Row = array();
81 foreach($this->Definition['Items'] as $Index => $Item)
82 {
83 $Row[] = $DbRow[$Index];
84 }
85 $this->Values[] = $Row;
86 }
87 }
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.