source: Base/HTML/Table.php

Last change on this file was 1, checked in by george, 15 years ago
  • Přidáno: Výchozí verze systému.
File size: 3.6 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/HTML.php');
4
5class Table extends HTML
6{
7 var $Id;
8 var $System;
9 var $Definition;
10 var $Values;
11 var $Header;
12 var $OnRow;
13 var $QueryParameters;
14 var $TotalRowCount;
15 var $RowPerPage = 20;
16
17 function __construct($System, $FormClass)
18 {
19 $this->System = $System;
20 $this->Definition = $FormClass;
21 $this->QueryParameters = array();
22 }
23
24 function CheckOrder()
25 {
26 if(!array_key_exists('Order', $_GET) or (array_key_exists('Order', $_GET) and
27 ($_GET['Order'] != '0') and ($_GET['Order'] != '1')))
28 {
29 if(array_key_exists('DefaultOrderDirection', $this->Definition)) $_GET['Order'] = $this->Definition['DefaultOrderDirection'];
30 else $_GET['Order'] = 0;
31 };
32 if(!array_key_exists('Column', $_GET) or (array_key_exists('Column', $_GET) and !array_key_exists($_GET['Column'], $this->Definition['Items'])))
33 {
34 if(array_key_exists('DefaultOrderColumn', $this->Definition)) $_GET['Column'] = $this->Definition['DefaultOrderColumn'];
35 else
36 {
37 $Keys = array_keys($this->Definition['Items']);
38 $_GET['Column'] = $Keys[0];
39 }
40 }
41 }
42
43 function Show()
44 {
45 $this->CheckOrder();
46 $Header = array();
47 $QueryStringArray = $this->System->HTTP->GetQueryStringArray();
48 $QueryStringArray['Order'] = $_GET['Order'];
49 foreach($this->Definition['Items'] as $Index => $Item)
50 {
51 if($Item['Type'] != 'Hidden')
52 {
53 $QueryStringArray['Column'] = $Index;
54 if($_GET['Column'] == $Index) $QueryStringArray['Order'] = 1 - $_GET['Order'];
55 else $QueryStringArray['Order'] = $_GET['Order'];
56 $Header[] = '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">'.$Item['Caption'].'</a>';
57 }
58 }
59 $Table = array(
60 'Header' => $Header,
61 'Rows' => $this->Values,
62 );
63 $Output = $this->Table($Table, 'WideTable', 'LiftList');
64 $Output .= '<div class="Pager">'.$this->PageList('Page', $this->Page, $this->TotalRowCount, $this->RowPerPage).'</div>';
65 return($Output);
66 }
67
68 function LoadValuesFromDatabase($Database)
69 {
70 $this->CheckOrder();
71 $OrderType = array('ASC', 'DESC');
72 $this->Header = array();
73 foreach($this->Definition['Items'] as $Index => $Item)
74 {
75 $this->Header[] = $Item['Caption'];
76 }
77 $this->Values = array();
78 $Table = $this->Definition['Table'];
79 foreach($this->QueryParameters as $Index => $Item)
80 $Table = str_replace('%'.$Index, $Item, $Table);
81 $DbResult = $Database->query('SELECT COUNT(*) FROM '.$Table.' AS T ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']]);
82 $DbRow = $DbResult->fetch_row();
83 $this->TotalRowCount = $DbRow[0];
84 if(array_key_exists('Page', $_GET)) $this->Page = $_GET['Page']; else $this->Page = 0;
85 if($this->Page > ($this->TotalRowCount / $this->RowPerPage)) $this->Page = 0;
86 $DbResult = $Database->query('SELECT * FROM '.$Table.' AS T ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']].' LIMIT '.($this->Page * $this->RowPerPage).', '.$this->RowPerPage);
87 echo($Database->error);
88 while($DbRow = $DbResult->fetch_assoc())
89 {
90 if(method_exists($this->OnRow[0], $this->OnRow[1]))
91 {
92 $Object = $this->OnRow[0];
93 $Method = $this->OnRow[1];
94 $DbRow = $Object->$Method($DbRow);
95 }
96 $Row = array();
97 foreach($this->Definition['Items'] as $Index => $Item)
98 {
99 $DbRow[$Index] = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnView',
100 array('Name' => $Index, 'Value' => $DbRow[$Index], 'Type' => $Item['Type']));
101 $Row[$Index] = $DbRow[$Index];
102 }
103 $this->Values[] = $Row;
104 }
105 }
106}
107
108?>
Note: See TracBrowser for help on using the repository browser.