Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Page.php

    r768 r816  
    77  var $RawPage;
    88  var $Title;
    9  
     9
    1010  function __construct($System)
    1111  {
     
    1414    $this->RawPage = false;
    1515  }
    16        
    17         function Show()
    18         {
    19                 return('');
    20   } 
    21  
     16
     17  function Show()
     18  {
     19    return('');
     20  }
     21
    2222  function GetOutput()
    23   {     
    24         $Output = $this->Show();
    25         return($Output);
     23  {
     24    $Output = $this->Show();
     25    return($Output);
    2626  }
    2727}
     
    2929class PageEdit extends Page
    3030{
    31         var $Table;
    32         var $Definition;
    33         var $ItemActions;
    34        
    35         function __construct($System)
    36         {
     31  var $Table;
     32  var $Definition;
     33  var $ItemActions;
     34
     35  function __construct($System)
     36  {
    3737    parent::__construct($System);
    3838    $this->Table = '';
     
    4141      array('Name' => T('View'), 'URL' => '?action=view&id=#Id'),
    4242    );
    43     $this->AllowEdit = false;   
     43    $this->AllowEdit = false;
    4444    if($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id');
    45         }
    46        
    47         function Show()
    48         {
    49                 $Output = '';
    50         if(array_key_exists('action', $_GET))
     45  }
     46
     47  function Show()
     48  {
     49    $Output = '';
     50    if(array_key_exists('action', $_GET))
    5151    {
    52       if($_GET['action'] == 'add') $Output .= $this->AddItem(); 
     52      if($_GET['action'] == 'add') $Output .= $this->AddItem();
    5353      else if($_GET['action'] == 'view') $Output .= $this->ViewItem();
    5454      else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
     
    5656      else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
    5757      else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL);
    58     } else $Output .= $this->ViewList();       
    59     return($Output); 
     58    } else $Output .= $this->ViewList();
     59    return($Output);
    6060  }
    61  
     61
    6262  function ViewItem()
    6363  {
    64                 $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
    65                 if($DbResult->num_rows > 0)
    66                 {
    67                   $DbRow = $DbResult->fetch_assoc();
     64    $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
     65    if($DbResult->num_rows > 0)
     66    {
     67      $DbRow = $DbResult->fetch_assoc();
    6868
    6969      $Output = T('Item').
     
    7171      foreach($this->Definition as $DefIndex => $Def)
    7272      {
    73           $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>';
    74       }       
     73        $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>';
     74      }
    7575      $Output .= '<tr>'.
    7676        '</table>';
    77                 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    78                 if($this->AllowEdit)
    79                 {
    80                   $Output .= '<a href="?action=add">'.T('Add').'</a> ';
    81                   $Output .= '<a href="?action=edit&amp;id='.$_GET['id'].'">'.T('Edit').'</a> ';
    82                   $Output .= '<a href="?action=delete&amp;id='.$_GET['id'].'">'.T('Add').'</a> ';
    83                 }
    84                 $Output .= '<a href="?">'.T('List').'</a><br/>';
    85     return($Output); 
     77    } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     78    if($this->AllowEdit)
     79    {
     80      $Output .= '<a href="?action=add">'.T('Add').'</a> ';
     81      $Output .= '<a href="?action=edit&amp;id='.$_GET['id'].'">'.T('Edit').'</a> ';
     82      $Output .= '<a href="?action=delete&amp;id='.$_GET['id'].'">'.T('Add').'</a> ';
     83    }
     84    $Output .= '<a href="?">'.T('List').'</a><br/>';
     85    return($Output);
    8686  }
    8787
    8888  function ViewList()
    8989  {
    90                 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`');
    91                 $DbRow = $DbResult->fetch_row();
    92                 $PageList = GetPageList($DbRow[0]);
    93                 $Output = $PageList['Output'];
    94        
    95                 $Output .= '<table class="BaseTable">';
    96                 $TableColumns = array();
    97                 foreach($this->Definition as $Index => $Def)
    98                   if($Def['InList'])
    99                     $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
    100                 if(count($this->ItemActions) > 0)
    101                   $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    102        
    103                 $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
    104                 $Output .= $Order['Output'];
    105        
    106                 $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
    107                 while($Item = $DbResult->fetch_assoc())
    108                 {
    109                         $Output .= '<tr>';
     90    $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`');
     91    $DbRow = $DbResult->fetch_row();
     92    $PageList = GetPageList($DbRow[0]);
     93    $Output = $PageList['Output'];
     94
     95    $Output .= '<table class="BaseTable">';
     96    $TableColumns = array();
     97    foreach($this->Definition as $Index => $Def)
     98      if($Def['InList'])
     99        $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
     100    if(count($this->ItemActions) > 0)
     101      $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
     102
     103    $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
     104    $Output .= $Order['Output'];
     105
     106    $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
     107    while($Item = $DbResult->fetch_assoc())
     108    {
     109      $Output .= '<tr>';
    110110      foreach($this->Definition as $Index => $Def)
    111111      if($Def['InList'])
    112112      {
    113         if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
    114                 else $Output .= '<td>'.$Item[$Index].'</td>';
     113        if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
     114          else $Output .= '<td>'.$Item[$Index].'</td>';
    115115      }
    116116      if(count($this->ItemActions) > 0)
    117       {         
    118         $Output .= '<td>';
    119         foreach($this->ItemActions as $Index => $Action)
    120         {
    121                 $URL = $Action['URL'];
    122                 if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
     117      {
     118        $Output .= '<td>';
     119        foreach($this->ItemActions as $Index => $Action)
     120        {
     121          $URL = $Action['URL'];
     122          if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
    123123          $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> ';
    124         }       
     124        }
    125125        $Output .= '</td>';
    126126      }
    127                   $Output .= '</tr>';   
    128                 }
    129                 $Output .= '</table>';
    130                 if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
    131                 return($Output);
     127      $Output .= '</tr>';
     128    }
     129    $Output .= '</table>';
     130    if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
     131    return($Output);
    132132  }
    133        
    134         function AddItem()
     133
     134  function AddItem()
    135135  {
    136136    $Output = '';
    137137    if($this->System->User->Licence(LICENCE_USER))
    138138    {
    139         if(array_key_exists('finish', $_GET))
    140         {
    141                 $Items = array();
    142                 foreach($this->Definition as $Index => $Def)
    143                 {
    144                         $Items[$Index] = $_POST[$Index];
    145                 }
    146                 $this->Database->insert($this->Table, $Items);
    147           $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION); 
    148         } else
    149         {
     139      if(array_key_exists('finish', $_GET))
     140      {
     141        $Items = array();
     142        foreach($this->Definition as $Index => $Def)
     143        {
     144          $Items[$Index] = $_POST[$Index];
     145        }
     146        $this->Database->insert($this->Table, $Items);
     147        $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION);
     148      } else
     149      {
    150150        $Output .= '<form action="?action=add&amp;finish=1" method="post">'.
    151151          '<fieldset><legend>'.T('New item').'</legend>'.
     
    153153        foreach($this->Definition as $DefIndex => $Def)
    154154        {
    155               $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>';
    156         }       
     155          $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>';
     156        }
    157157        $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'.
    158158          '</table>'.
    159159          '</fieldset>'.
    160160          '</form>';
    161         }
     161      }
    162162    } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    163     return($Output); 
    164   }     
    165        
    166         function DeleteItem()
     163    return($Output);
     164  }
     165
     166  function DeleteItem()
    167167  {
    168168    if($this->System->User->Licence(LICENCE_USER))
     
    173173    return($Output);
    174174  }
    175  
     175
    176176  function GetControl($Type, $Name, $Value)
    177177  {
    178         if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
    179         else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
    180         else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
    181         return($Output);
    182   }     
     178    if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
     179    else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
     180    else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
     181    return($Output);
     182  }
    183183
    184184  function ViewControl($Type, $Name, $Value)
    185185  {
    186         if($Type == 'Text') $Output = $Value;
    187         else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
    188         else if($Type == 'Boolean') $Output = $Value;
    189         else $Output = $Value;
    190         return($Output);
    191   }     
     186    if($Type == 'Text') $Output = $Value;
     187    else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
     188    else if($Type == 'Boolean') $Output = $Value;
     189    else $Output = $Value;
     190    return($Output);
     191  }
    192192}
Note: See TracChangeset for help on using the changeset viewer.