Ignore:
Timestamp:
Dec 11, 2013, 10:21:12 PM (10 years ago)
Author:
chronos
Message:
  • Added: Make server list more general to cover also non-translated servers.
  • Added: Partialy implemented generic view named PageEdit which serve as template to present item lists, add, delete and modify items.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Page.php

    r636 r639  
    2626  }
    2727}
     28
     29class PageEdit extends Page
     30{
     31        var $Table;
     32        var $Definition;
     33       
     34        function __construct($System)
     35        {
     36    parent::__construct($System);
     37    $this->Table = '';
     38    $this->Definition = array();
     39        }
     40       
     41        function Show()
     42        {
     43                $Output = '';
     44        if(array_key_exists('action', $_GET))
     45    {
     46      if($_GET['action'] == 'add') $Output .= $this->AddItem();
     47      else if($_GET['action'] == 'view') $Output .= $this->ViewItem();
     48      else if($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
     49      else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
     50      else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL);
     51    } else $Output .= $this->ViewList();       
     52    return($Output);
     53  }
     54 
     55  function ViewItem()
     56  {
     57        $Output = '';
     58        return($Output);
     59  }
     60
     61  function ViewList()
     62  {
     63                $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`');
     64                $DbRow = $DbResult->fetch_row();
     65                $PageList = GetPageList($DbRow[0]);
     66                $Output = $PageList['Output'];
     67       
     68                $Output .= '<table class="BaseTable">';
     69                $TableColumns = array();
     70                foreach($this->Definition as $Index => $Def)
     71                  $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
     72       
     73                $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
     74                $Output .= $Order['Output'];
     75       
     76                $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
     77                while($Item = $DbResult->fetch_assoc())
     78                {
     79                        $Output .= '<tr>';
     80      foreach($this->Definition as $Index => $Def)
     81      {
     82        if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
     83                else $Output .= '<td>'.$Item[$Index].'</td>';
     84      }
     85                  $Output .= '</tr>';   
     86                }
     87                $Output .= '</table>';         
     88                return($Output);
     89  }
     90       
     91        function AddItem()
     92  {
     93    $Output = '';
     94    if($this->System->User->Licence(LICENCE_USER))
     95    {
     96        if(array_key_exists('finish', $_GET))
     97        {
     98                $Items = array();
     99                foreach($this->Definition as $Index => $Def)
     100                {
     101                        $Items[$Index] = $_POST[$Index];
     102                }
     103                $this->Database->insert($this->Table, $Items);
     104          $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION); 
     105        } else
     106        {
     107      $Output .= '<form action="?action=add&amp;finish=1" method="post">'.
     108        '<fieldset><legend>'.T('New item').'</legend>'.
     109        '<table>';
     110      foreach($this->Definition as $DefIndex => $Def)
     111      {
     112              $Output .= '<tr><td>'.$Def['Title'].'</td><td>'.$this->GetControl($Def['Type'], $DefIndex).'</tr>';
     113      }       
     114      $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'.
     115        '</table>'.
     116        '</fieldset>'.
     117        '</form>';
     118        }
     119    } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     120    return($Output);
     121  }
     122       
     123       
     124        function DeleteItem()
     125  {
     126    if($this->System->User->Licence(LICENCE_USER))
     127    {
     128      $this->Database->query('DELETE FROM `'.$this->Table.'` WHERE (`User`='.$this->System->User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
     129      $Output = ShowMessage(T('Record removed'));
     130    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     131    return($Output);
     132  }
     133 
     134  function GetControl($Type, $Name)
     135  {
     136        if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'"/>';
     137        else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
     138        else $Output = '<input type="text" name="'.$Name.'"/>';
     139  }     
     140}
Note: See TracChangeset for help on using the changeset viewer.