source: trunk/www/Base/Table.php

Last change on this file was 93, checked in by chronos, 11 years ago
  • Fixed: System variable as parameter to constructors of descendents of Module class.
  • Removed: End PHP mark "?>" from all files.
File size: 3.6 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Types/Type.php');
4include_once(dirname(__FILE__).'/Module.php');
5include_once(dirname(__FILE__).'/Global.php');
6
7class Table extends Module
8{
9 var $Id;
10 var $Definition;
11 var $Values;
12 var $Header;
13 var $OnRow;
14 var $QueryParameters;
15 var $TotalRowCount;
16
17 function __construct($FormClass, $System)
18 {
19 parent::__construct($System);
20 $this->Definition = $FormClass;
21 $this->QueryParameters = array();
22 }
23
24 function CheckOrder()
25 {
26 if(!array_key_exists('Order', $_GET))
27 {
28 if(array_key_exists('DefaultOrderDirection', $this->Definition)) $_GET['Order'] = $this->Definition['DefaultOrderDirection'];
29 else $_GET['Order'] = 0;
30 };
31 if(!array_key_exists('Column', $_GET))
32 {
33 if(array_key_exists('DefaultOrderColumn', $this->Definition)) $_GET['Column'] = $this->Definition['DefaultOrderColumn'];
34 else
35 {
36 $Keys = array_keys($this->Definition['Items']);
37 $_GET['Column'] = $Keys[0];
38 }
39 }
40 }
41
42 function Show()
43 {
44 $this->CheckOrder();
45 $Header = array();
46 $QueryStringArray = GetQueryStringArray();
47 $QueryStringArray['Order'] = $_GET['Order'];
48 foreach($this->Definition['Items'] as $Index => $Item)
49 {
50 if($Item['Type'] != 'Hidden')
51 {
52 $QueryStringArray['Column'] = $Index;
53 if($_GET['Column'] == $Index) $QueryStringArray['Order'] = 1 - $_GET['Order'];
54 else $QueryStringArray['Order'] = $_GET['Order'];
55 $Header[] = '<a href="?'.SetQueryStringArray($QueryStringArray).'">'.$Item['Caption'].'</a>';
56 }
57 }
58 $Table = array(
59 'Header' => $Header,
60 'Rows' => $this->Values,
61 );
62 $Html = new Html();
63 $Output = $Html->Table($Table, 'WideTable');
64 $Output .= '<div class="Pager">'.$Html->PageList('Page', $this->Page, $this->TotalRowCount, $this->Config['Web']['TableRowPerPage']).'</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->System->Config['Web']['TableRowPerPage'])) $this->Page = 0;
86 $DbResult = $Database->query('SELECT * FROM '.$Table.' AS T ORDER BY T.'.$_GET['Column'].' '.$OrderType[$_GET['Order']].' LIMIT '.($this->Page * $this->Config['Web']['TableRowPerPage']).', '.$this->Config['Web']['TableRowPerPage']);
87 //print_r(debug_backtrace());
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] = ExecuteTypeEvent($this->System, $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}
Note: See TracBrowser for help on using the repository browser.