Changeset 738 for trunk/Common/Table.php


Ignore:
Timestamp:
Apr 14, 2015, 10:20:16 PM (9 years ago)
Author:
chronos
Message:
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Table.php

    r636 r738  
    11<?php
    22
    3 class Control 
     3class Control
    44{
    5         var $Name;
    6        
     5  var $Name;
     6
    77  function Show()
    88  {
    9           return('');
     9    return('');
    1010  }
    1111}
     
    1313class Table
    1414{
    15         function GetCell($Y, $X)
    16         {
    17                 return('');
    18         }
     15  function GetCell($Y, $X)
     16  {
     17    return('');
     18  }
    1919
    20         function BeginRead()
    21         {
    22         }
    23        
    24         function EndRead()
    25         {
    26         }
    27        
     20  function BeginRead()
     21  {
     22  }
     23
     24  function EndRead()
     25  {
     26  }
     27
    2828  function RowsCount()
    2929  {
    30         return(0);
     30    return(0);
    3131  }
    3232}
     
    3434class TableMemory extends Table
    3535{
    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  }
    4242
    4343  function RowsCount()
    4444  {
    45         return(count($this->Cells));
     45    return(count($this->Cells));
    4646  }
    4747}
     
    4949class TableSQL extends Table
    5050{
    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  }
    7474
    7575  function RowsCount()
    7676  {
    77         return(count($this->Cells));
     77    return(count($this->Cells));
    7878  }
    7979}
     
    8181class TableColumn
    8282{
    83         var $Name;
    84         var $Title;
     83  var $Name;
     84  var $Title;
    8585}
    8686
     
    9696  var $DefaultOrder;
    9797  var $Table;
    98  
     98
    9999  function __construct()
    100100  {
    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();
    105105    $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'),
    107107      $System->Link('/images/sort_desc.png'));
    108108    $this->DefaultOrder = 0;
    109109  }
    110  
     110
    111111  function SetColumns($Columns)
    112112  {
    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 = '';
    124124  }
    125  
     125
    126126  function Show()
    127127  {
    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>&nbsp;</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>&nbsp;</td>';
     139          else $Output .= '<td>'.$Cell.'</td>';
     140      }
     141      $Output .= '</tr>';
     142    }
     143    $this->Table->EndRead();
     144    $Output .= '</table>';
    145145    return($Output);
    146146  }
    147  
     147
    148148  function GetOrderHeader()
    149149  {
     
    152152    if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $this->DefaultColumn;
    153153    if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $this->DefaultOrder;
    154  
     154
    155155    // Check OrderCol
    156156    $Found = false;
     
    159159      if($Column->Name == $_SESSION['OrderCol'])
    160160      {
    161         $Found = true;   
     161        $Found = true;
    162162        break;
    163163      }
     
    169169    }
    170170    // Check OrderDir
    171     if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) 
     171    if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1))
    172172      $_SESSION['OrderDir'] = 0;
    173  
     173
    174174    $Result = '';
    175175    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     
    178178      $QueryItems['OrderCol'] = $Column->Name;
    179179      $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
    180       if($Column->Name == $_SESSION['OrderCol']) 
     180      if($Column->Name == $_SESSION['OrderCol'])
    181181        $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$this->OrderArrowImage[$_SESSION['OrderDir']].'" alt="order arrow">';
    182182        else $ArrowImage = '';
     
    187187    $this->OrderColumn = $_SESSION['OrderCol'];
    188188    $this->OrderDirection = $_SESSION['OrderDir'];
    189  
     189
    190190    return($Result);
    191191  }
Note: See TracChangeset for help on using the changeset viewer.