Ignore:
Timestamp:
Jan 27, 2014, 10:01:33 PM (10 years ago)
Author:
chronos
Message:
  • Added: Config parameter Description which is used for general web description included in meta section of HTML page and usable by modules.
  • Fixed: Error in RSS channels if no items loaded.
  • Modified: Log real last URI instead on script name in online users list in database.
  • Fixed: Serialization error in Database class if exception was raised.
  • Modified: Items in RSS channel of forum links to exact forum topics.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Page.php

    r639 r765  
    3131        var $Table;
    3232        var $Definition;
     33        var $ItemActions;
    3334       
    3435        function __construct($System)
     
    3738    $this->Table = '';
    3839    $this->Definition = array();
     40    $this->ItemActions = array(
     41      array('Name' => T('View'), 'URL' => '?action=view&id=#Id'),
     42      array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id'),
     43    );
    3944        }
    4045       
     
    4651      if($_GET['action'] == 'add') $Output .= $this->AddItem();
    4752      else if($_GET['action'] == 'view') $Output .= $this->ViewItem();
     53      else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
    4854      else if($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
    4955      else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
     
    5561  function ViewItem()
    5662  {
    57         $Output = '';
    58         return($Output);
     63                $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
     64                if($DbResult->num_rows > 0)
     65                {
     66                  $DbRow = $DbResult->fetch_assoc();
     67
     68      $Output = T('Item').
     69        '<table>';
     70      foreach($this->Definition as $DefIndex => $Def)
     71      {
     72          $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>';
     73      }       
     74      $Output .= '<tr>'.
     75        '</table>';
     76                } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     77                $Output .= '<a href="?action=add">'.T('Add').'</a> ';
     78                $Output .= '<a href="?action=edit&amp;id='.$_GET['id'].'">'.T('Edit').'</a> ';
     79                $Output .= '<a href="?action=delete&amp;id='.$_GET['id'].'">'.T('Add').'</a> ';
     80                $Output .= '<a href="?">'.T('List').'</a><br/>';
     81    return($Output);
    5982  }
    6083
     
    6992                $TableColumns = array();
    7093                foreach($this->Definition as $Index => $Def)
    71                   $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
     94                  if($Def['InList'])
     95                    $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
     96                if(count($this->ItemActions) > 0)
     97                  $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    7298       
    7399                $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
     
    79105                        $Output .= '<tr>';
    80106      foreach($this->Definition as $Index => $Def)
     107      if($Def['InList'])
    81108      {
    82109        if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
    83110                else $Output .= '<td>'.$Item[$Index].'</td>';
    84111      }
     112      if(count($this->ItemActions) > 0)
     113      {         
     114        $Output .= '<td>';
     115        foreach($this->ItemActions as $Index => $Action)
     116        {
     117                $URL = $Action['URL'];
     118                if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
     119          $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> ';
     120        }       
     121        $Output .= '</td>';
     122      }       
    85123                  $Output .= '</tr>';   
    86124                }
    87                 $Output .= '</table>';         
     125                $Output .= '</table>';
     126                $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
    88127                return($Output);
    89128  }
     
    105144        } else
    106145        {
    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>';
     146        $Output .= '<form action="?action=add&amp;finish=1" method="post">'.
     147          '<fieldset><legend>'.T('New item').'</legend>'.
     148          '<table>';
     149        foreach($this->Definition as $DefIndex => $Def)
     150        {
     151              $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>';
     152        }       
     153        $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'.
     154          '</table>'.
     155          '</fieldset>'.
     156          '</form>';
    118157        }
    119158    } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    120159    return($Output);
    121   }
    122        
     160  }     
    123161       
    124162        function DeleteItem()
     
    132170  }
    133171 
    134   function GetControl($Type, $Name)
     172  function GetControl($Type, $Name, $Value)
    135173  {
    136         if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'"/>';
     174        if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
    137175        else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
    138         else $Output = '<input type="text" name="'.$Name.'"/>';
     176        else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
     177        return($Output);
     178  }     
     179
     180  function ViewControl($Type, $Name, $Value)
     181  {
     182        if($Type == 'Text') $Output = $Value;
     183        else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
     184        else if($Type == 'Boolean') $Output = $Value;
     185        else $Output = $Value;
     186        return($Output);
    139187  }     
    140188}
Note: See TracChangeset for help on using the changeset viewer.