Changeset 738 for trunk/Common/Table.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/Common/Table.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Table.php
r636 r738 1 1 <?php 2 2 3 class Control 3 class Control 4 4 { 5 var $Name;6 5 var $Name; 6 7 7 function Show() 8 8 { 9 return('');9 return(''); 10 10 } 11 11 } … … 13 13 class Table 14 14 { 15 function GetCell($Y, $X)16 {17 return('');18 }15 function GetCell($Y, $X) 16 { 17 return(''); 18 } 19 19 20 function BeginRead()21 {22 }23 24 function EndRead()25 {26 }27 20 function BeginRead() 21 { 22 } 23 24 function EndRead() 25 { 26 } 27 28 28 function RowsCount() 29 29 { 30 return(0);30 return(0); 31 31 } 32 32 } … … 34 34 class TableMemory extends Table 35 35 { 36 var $Cells;37 38 function GetCell($Y, $X)39 {40 return($this->Cells[$Y][$X]);41 }36 var $Cells; 37 38 function GetCell($Y, $X) 39 { 40 return($this->Cells[$Y][$X]); 41 } 42 42 43 43 function RowsCount() 44 44 { 45 return(count($this->Cells));45 return(count($this->Cells)); 46 46 } 47 47 } … … 49 49 class TableSQL extends Table 50 50 { 51 var $Query;52 var $Database;53 var $Cells; 54 55 function GetCell($Y, $X)56 {57 return($this->Cells[$Y][$X]);58 }59 60 function BeginRead()61 {62 $this->Cells = array();63 $DbResult = $this->Database->query($this->Query);64 while($DbRow = $DbResult->fetch_row())65 {66 $this->Cells[] = $DbRow;67 }68 }69 70 function EndRead()71 {72 $this->Cells = array();73 }51 var $Query; 52 var $Database; 53 var $Cells; 54 55 function GetCell($Y, $X) 56 { 57 return($this->Cells[$Y][$X]); 58 } 59 60 function BeginRead() 61 { 62 $this->Cells = array(); 63 $DbResult = $this->Database->query($this->Query); 64 while($DbRow = $DbResult->fetch_row()) 65 { 66 $this->Cells[] = $DbRow; 67 } 68 } 69 70 function EndRead() 71 { 72 $this->Cells = array(); 73 } 74 74 75 75 function RowsCount() 76 76 { 77 return(count($this->Cells));77 return(count($this->Cells)); 78 78 } 79 79 } … … 81 81 class TableColumn 82 82 { 83 var $Name;84 var $Title;83 var $Name; 84 var $Title; 85 85 } 86 86 … … 96 96 var $DefaultOrder; 97 97 var $Table; 98 98 99 99 function __construct() 100 100 { 101 global $System;102 103 $this->Columns = array();104 $this->Table = new TableMemory();101 global $System; 102 103 $this->Columns = array(); 104 $this->Table = new TableMemory(); 105 105 $this->OrderDirSQL = array('ASC', 'DESC'); 106 $this->OrderArrowImage = array($System->Link('/images/sort_asc.png'), 106 $this->OrderArrowImage = array($System->Link('/images/sort_asc.png'), 107 107 $System->Link('/images/sort_desc.png')); 108 108 $this->DefaultOrder = 0; 109 109 } 110 110 111 111 function SetColumns($Columns) 112 112 { 113 $this->Columns = array();114 foreach($Columns as $Column)115 {116 $NewCol = new TableColumn();117 $NewCol->Name = $Column['Name'];118 $NewCol->Title = $Column['Title'];119 $this->Columns[] = $NewCol;120 }121 if(count($this->Columns) > 0)122 $this->DefaultColumn = $this->Columns[0]->Name;123 else $this->DefaultColumn = '';113 $this->Columns = array(); 114 foreach($Columns as $Column) 115 { 116 $NewCol = new TableColumn(); 117 $NewCol->Name = $Column['Name']; 118 $NewCol->Title = $Column['Title']; 119 $this->Columns[] = $NewCol; 120 } 121 if(count($this->Columns) > 0) 122 $this->DefaultColumn = $this->Columns[0]->Name; 123 else $this->DefaultColumn = ''; 124 124 } 125 125 126 126 function Show() 127 127 { 128 $Output = '<table class="WideTable">';129 $Output .= $this->GetOrderHeader();130 $this->Table->BeginRead();131 for($Y = 0; $Y < $this->Table->RowsCount(); $Y++)132 {133 $Output .= '<tr>';134 135 for($X = 0; $X < count($this->Columns); $X++)136 {137 $Cell = $this->Table->GetCell($Y, $X);138 if($Cell == '') $Output .= '<td> </td>'; 139 else $Output .= '<td>'.$Cell.'</td>';140 } 141 $Output .= '</tr>';142 }143 $this->Table->EndRead();144 $Output .= '</table>';128 $Output = '<table class="WideTable">'; 129 $Output .= $this->GetOrderHeader(); 130 $this->Table->BeginRead(); 131 for($Y = 0; $Y < $this->Table->RowsCount(); $Y++) 132 { 133 $Output .= '<tr>'; 134 135 for($X = 0; $X < count($this->Columns); $X++) 136 { 137 $Cell = $this->Table->GetCell($Y, $X); 138 if($Cell == '') $Output .= '<td> </td>'; 139 else $Output .= '<td>'.$Cell.'</td>'; 140 } 141 $Output .= '</tr>'; 142 } 143 $this->Table->EndRead(); 144 $Output .= '</table>'; 145 145 return($Output); 146 146 } 147 147 148 148 function GetOrderHeader() 149 149 { … … 152 152 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $this->DefaultColumn; 153 153 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $this->DefaultOrder; 154 154 155 155 // Check OrderCol 156 156 $Found = false; … … 159 159 if($Column->Name == $_SESSION['OrderCol']) 160 160 { 161 $Found = true; 161 $Found = true; 162 162 break; 163 163 } … … 169 169 } 170 170 // Check OrderDir 171 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) 171 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) 172 172 $_SESSION['OrderDir'] = 0; 173 173 174 174 $Result = ''; 175 175 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); … … 178 178 $QueryItems['OrderCol'] = $Column->Name; 179 179 $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir']; 180 if($Column->Name == $_SESSION['OrderCol']) 180 if($Column->Name == $_SESSION['OrderCol']) 181 181 $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$this->OrderArrowImage[$_SESSION['OrderDir']].'" alt="order arrow">'; 182 182 else $ArrowImage = ''; … … 187 187 $this->OrderColumn = $_SESSION['OrderCol']; 188 188 $this->OrderDirection = $_SESSION['OrderDir']; 189 189 190 190 return($Result); 191 191 }
Note:
See TracChangeset
for help on using the changeset viewer.
