Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/PageEdit.php

    r838 r880  
    1616    );
    1717    $this->AllowEdit = false;
    18     if($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id');
     18    if ($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id');
    1919  }
    2020
     
    2222  {
    2323    $Output = '';
    24     if(array_key_exists('action', $_GET))
     24    if (array_key_exists('action', $_GET))
    2525    {
    26       if($_GET['action'] == 'add') $Output .= $this->AddItem();
    27       else if($_GET['action'] == 'view') $Output .= $this->ViewItem();
    28       else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
    29       else if($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
    30       else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
     26      if ($_GET['action'] == 'add') $Output .= $this->AddItem();
     27      else if ($_GET['action'] == 'view') $Output .= $this->ViewItem();
     28      else if ($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
     29      else if ($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
     30      else if ($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
    3131      else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL);
    3232    } else $Output .= $this->ViewList();
    33     return($Output);
     33    return $Output;
    3434  }
    3535
     
    3737  {
    3838    $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
    39     if($DbResult->num_rows > 0)
     39    if ($DbResult->num_rows > 0)
    4040    {
    4141      $DbRow = $DbResult->fetch_assoc();
     
    4343      $Output = T('Item').
    4444        '<table>';
    45       foreach($this->Definition as $DefIndex => $Def)
     45      foreach ($this->Definition as $DefIndex => $Def)
    4646      {
    4747        $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>';
     
    5050        '</table>';
    5151    } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    52     if($this->AllowEdit)
     52    if ($this->AllowEdit)
    5353    {
    5454      $Output .= '<a href="?action=add">'.T('Add').'</a> ';
     
    5757    }
    5858    $Output .= '<a href="?">'.T('List').'</a><br/>';
    59     return($Output);
     59    return $Output;
    6060  }
    6161
     
    6969    $Output .= '<table class="BaseTable">';
    7070    $TableColumns = array();
    71     foreach($this->Definition as $Index => $Def)
    72       if($Def['InList'])
     71    foreach ($this->Definition as $Index => $Def)
     72      if ($Def['InList'])
    7373        $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
    74     if(count($this->ItemActions) > 0)
     74    if (count($this->ItemActions) > 0)
    7575      $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    7676
     
    7979
    8080    $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
    81     while($Item = $DbResult->fetch_assoc())
     81    while ($Item = $DbResult->fetch_assoc())
    8282    {
    8383      $Output .= '<tr>';
    84       foreach($this->Definition as $Index => $Def)
    85       if($Def['InList'])
     84      foreach ($this->Definition as $Index => $Def)
     85      if ($Def['InList'])
    8686      {
    87         if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
     87        if ($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
    8888          else $Output .= '<td>'.$Item[$Index].'</td>';
    8989      }
    90       if(count($this->ItemActions) > 0)
     90      if (count($this->ItemActions) > 0)
    9191      {
    9292        $Output .= '<td>';
    93         foreach($this->ItemActions as $Index => $Action)
     93        foreach ($this->ItemActions as $Index => $Action)
    9494        {
    9595          $URL = $Action['URL'];
    96           if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
     96          if (strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
    9797          $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> ';
    9898        }
     
    102102    }
    103103    $Output .= '</table>';
    104     if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
    105     return($Output);
     104    if ($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
     105    return $Output;
    106106  }
    107107
     
    109109  {
    110110    $Output = '';
    111     if($this->System->User->Licence(LICENCE_USER))
     111    if ($this->System->User->Licence(LICENCE_USER))
    112112    {
    113       if(array_key_exists('finish', $_GET))
     113      if (array_key_exists('finish', $_GET))
    114114      {
    115115        $Items = array();
    116         foreach($this->Definition as $Index => $Def)
     116        foreach ($this->Definition as $Index => $Def)
    117117        {
    118118          $Items[$Index] = $_POST[$Index];
     
    125125          '<fieldset><legend>'.T('New item').'</legend>'.
    126126          '<table>';
    127         foreach($this->Definition as $DefIndex => $Def)
     127        foreach ($this->Definition as $DefIndex => $Def)
    128128        {
    129129          $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>';
     
    135135      }
    136136    } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    137     return($Output);
     137    return $Output;
    138138  }
    139139
    140140  function DeleteItem()
    141141  {
    142     if($this->System->User->Licence(LICENCE_USER))
     142    if ($this->System->User->Licence(LICENCE_USER))
    143143    {
    144144      $this->Database->query('DELETE FROM `'.$this->Table.'` WHERE (`User`='.$this->System->User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
    145145      $Output = ShowMessage(T('Record removed'));
    146146    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    147     return($Output);
     147    return $Output;
    148148  }
    149149
    150150  function GetControl($Type, $Name, $Value)
    151151  {
    152     if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
    153     else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
     152    if ($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
     153    else if ($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
    154154    else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
    155     return($Output);
     155    return $Output;
    156156  }
    157157
    158158  function ViewControl($Type, $Name, $Value)
    159159  {
    160     if($Type == 'Text') $Output = $Value;
    161     else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
    162     else if($Type == 'Boolean') $Output = $Value;
     160    if ($Type == 'Text') $Output = $Value;
     161    else if ($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
     162    else if ($Type == 'Boolean') $Output = $Value;
    163163    else $Output = $Value;
    164     return($Output);
     164    return $Output;
    165165  }
    166166}
Note: See TracChangeset for help on using the changeset viewer.