Ignore:
Timestamp:
Apr 24, 2013, 9:09:32 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Metoda ShowMain v PageNews rozdělena do jednotlivých metod dle vybrané akce.
  • Opraveno: V souboru EmailQueue se vkládaly na výstup chybně dva znaky mezer.
  • Opraveno: Zamezení úpravy aktualit vložených bez nastaveného uživatele (jako anonym).
  • Opraveno: Odstraněny některé pevné reference na server centrala.
  • Opraveno: Uložení úpravy odkazu aktualit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/News/NewsPage.php

    r525 r532  
    2020  }
    2121 
    22   function ShowMain()
    23   {
    24     $Output = '';
    25     $Category = 1;
    26     $CategoryName = '';
     22  function ShowView()
     23  {
     24    $Output = '';
     25    if(!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
     26    else
     27    {
     28      $Category = $this->GetCategory();
     29      if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
     30      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
     31        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id);
     32      if($DbResult->num_rows > 0)
     33      {
     34        $Row = $DbResult->fetch_array();
     35        if($Row['Name'] == '') $Author = $Row['Author'];
     36          else $Author = $Row['Name'];
     37        $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')';
     38        if($this->System->User->User['Id'] == $Row['User'])
     39        {
     40          $Output .= '<div class="Action">';
     41          $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category['Id'].'&amp;id='.$Row['Id'].'">Smazat</a>';
     42          $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category['Id'].'&amp;id='.$Row['Id'].'">Upravit</a>';
     43          $Output .= '</div>';
     44        }
     45        $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
     46        if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
     47        if($Row['Enclosure'] != '')
     48        {
     49          $Output .= '<br />Přílohy: ';
     50          $Enclosures = explode(';', $Row['Enclosure']);
     51          foreach($Enclosures as $Enclosure)
     52          {
     53            if(file_exists($this->UploadedFilesFolder.$Enclosure))
     54              $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
     55          }
     56        }
     57        $Output .= '</div></div>';
     58      } else $Output .= 'Položka nenalezena.';
     59    }
     60    return($Output);
     61  }
     62 
     63  function ShowAdd()
     64  {
     65    $Category = $this->GetCategory();
     66    if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     67    {
     68      $Output = '<strong>Vložení nové aktuality:</strong><br />';
     69      // TODO: Static reference to dynamic category item
     70      if($Category['Id'] == 2) $Output .= 'U inzerátů uvádějte co nejvíce informací ať případný zájemce ví co kupuje. Uvádějte kontaktní údaje jako Jméno, email, tel. číslo, ICQ. Dále navrženou cenu, detajlní popis předmětu nejlépe s odkazem na stránky výrobce. Pokud váš inzerát již není platný, připište do něj např. "Prodáno" pomocí editace.';
     71      $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
     72        'Kategorie: <select name="category">';
     73      $DbResult = $this->Database->select('NewsCategory', '*');
     74      while($DbRow = $DbResult->fetch_array())
     75      {
     76        if($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
     77        {
     78          if($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';
     79            else $Selected = '';
     80          $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>';
     81        }
     82      }
     83      $Output .= '</select><br />'.
     84        'Nadpis:<br /><input type="text" size="54" name="title"><br />'.
     85        'Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />'.
     86        'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
     87        'Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">'.
     88        '<input name="enclosure1" size="38" type="file"><br />'.
     89        '<input name="enclosure2" size="38" type="file"><br />'.
     90        '<input name="enclosure3" size="38" type="file"><br />'.
     91        '<input type="submit" value="Vložit">'.
     92        '</form>';
     93    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     94    return($Output);
     95  }
     96 
     97  function ShowAdd2()
     98  {
     99    $Output = '';
     100    $RemoteAddr = GetRemoteAddress();
     101    $Category = $this->GetCategory();
     102    if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     103    {
     104      // Process uploaded file
     105      $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3');
     106      $Enclosures = '';
     107      foreach($EnclosureFileNames as $EnclosureName)
     108        if(array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
     109        {
     110          $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
     111          if(move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
     112          {
     113            $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.<br />';
     114            $Enclosures = $Enclosures.';'.basename($_FILES[$EnclosureName]['name']);
     115          } else
     116          {
     117            $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' se nepodařilo nahrát na server.<br />';
     118          }
     119        }
     120        $Enclosures = substr($Enclosures, 1);
     121   
     122        $_POST['content'] = str_replace("\n",'<br />',$_POST['content']);
     123        $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'],
     124          'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr,
     125          'Enclosure' => $Enclosures, 'Author' => $this->System->User->User['Name'],
     126          'User' => $this->System->User->User['Id'], 'Link' => $_POST['link']));
     127        $Output .= 'Aktualita přidána!<br />Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.<br /><br />';
     128        $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
     129        $this->System->ModuleManager->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
     130    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     131    return($Output);
     132  }
     133 
     134  function ShowEdit()
     135  {
     136    $Output = '';
     137    $Category = $this->GetCategory();
     138    if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     139    {
     140      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
     141      $Row = $DbResult->fetch_array();
     142      if(($this->System->User->User['Id'] == $Row['User']))
     143      {
     144        $Row['Content'] = str_replace('<br />', '', $Row['Content']);
     145        $Output .= '<strong>Editace aktuality v kategorii '.$Category['Caption'].':</strong><br />';
     146        $Output .= '<form action="?action=update" method="post">'.
     147        '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
     148        'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'.
     149        'Obsah:<br /><textarea name="content" rows="20" cols="40">'.$Row['Content'].'</textarea><br />'.
     150        'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
     151        '<input type="hidden" name="category" value="'.$Category['Id'].'"><br />'.
     152        '<input type="submit" value="Uložit">'.
     153        '</form>';
     154      } else $Output .= 'Nepovolená operace!';
     155    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     156    return($Output);
     157  }
     158 
     159  function ShowUpdate()
     160  {
     161    $Output = '';
     162    $RemoteAddr = GetRemoteAddress(); 
     163    $Category = $this->GetCategory();
     164    if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     165    {
     166      $_POST['id'] = $_POST['id'] * 1;
     167      $DbResult = $this->Database->select('News', '*', '`Id`='.$_POST['id']);
     168      if($DbResult->num_rows > 0)
     169      {
     170        $Row = $DbResult->fetch_array();
     171        if($this->System->User->User['Id'] == $Row['User'])
     172        {
     173          $_POST['content'] = str_replace("\n", '<br />', $_POST['content']);
     174          $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'],
     175            'Content' => $_POST['content'], 'Link' => $_POST['link']));
     176          $Output .= 'Aktualita uložena!<br />';
     177          $Output .= '<a href="?category='.$Category['Id'].'">Zpět na seznam aktualit</a>';
     178        } else $Output .= 'Nelze měnit cizí aktualitu!<br />';
     179      } else $Output .= 'ID nenalezeno!';
     180    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     181    return($Output);
     182  }
     183 
     184  function ShowDelete()
     185  {
     186    $Output = '';
     187    $Category = $this->GetCategory();
     188    if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     189    {
     190      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
     191      $Row = $DbResult->fetch_array();
     192      if($this->System->User->User['Id'] == $Row['User'])
     193      {
     194        if($Row['Enclosure'] != '')
     195        {
     196          $Output .= '<br />Přílohy: ';
     197          $Enclosures = explode(';', $Row['Enclosure']);
     198          foreach($Enclosures as $Enclosure)
     199          {
     200            if(file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
     201          }
     202        }
     203        $this->Database->query('DELETE FROM `News` WHERE `Id`='.$_GET['id']);
     204        $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category['Id'].'">Zpět na seznam aktualit</a>';
     205      } else $Output .= 'Nemáte oprávnění.';
     206    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     207    return($Output);
     208  }
     209 
     210  function ShowList()
     211  {
     212    $Output = '';
     213    $Category = $this->GetCategory();
     214    if($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id']))
     215    {
     216      $PerPage = 20;
     217      $DbResult = $this->Database->select('News', 'COUNT(*)', ' `Category`='.$Category['Id']);
     218      $RowTotal = $DbResult->fetch_array();
     219      $PageMax = $RowTotal[0];
     220      if(array_key_exists('page', $_GET)) $Page = $_GET['page'];
     221        else $Page = 0; //round($PageMax/$PerPage);
     222      $Output .= '<strong>Seznam aktualit kategorie '.$Category['Caption'].':</strong><div style="font-size: small;">';
     223      $Output .= PagesList('?category='.$Category['Id'].'&amp;page=', $Page, $PageMax, $PerPage);
     224   
     225      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
     226        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `Category`='.$Category['Id'].' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
     227      while($Row = $DbResult->fetch_array())
     228      {
     229        if($Row['Name'] == '') $Author = $Row['Author'];
     230          else $Author = $Row['Name'];
     231        $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&amp;id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')';
     232        if(($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
     233        {
     234          $Output .= '<div class="Action">';
     235          $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category['Id'].'&amp;id='.$Row['Id'].'">Smazat</a>';
     236          $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category['Id'].'&amp;id='.$Row['Id'].'">Upravit</a>';
     237          $Output .= '</div>';
     238        }
     239        $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
     240        if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
     241        if($Row['Enclosure'] != '')
     242        {
     243          $Output .= '<br />Přílohy: ';
     244          $Enclosures = explode(';', $Row['Enclosure']);
     245          foreach($Enclosures as $Enclosure)
     246          {
     247            if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
     248          }
     249        }
     250        $Output .= '</div></div>';
     251      }
     252      $Output .= PagesList('?category='.$Category['Id'].'&amp;page=', $Page, $PageMax, $PerPage);
     253      $Output .= '</div>';
     254    } else $Output .= 'Nemáte oprávnění.';
     255    return($Output);
     256  }
     257 
     258  function GetCategory()
     259  {
     260    $Category = 1; // Default category
    27261    if(array_key_exists('category', $_GET)) $Category = $_GET['category'] * 1;
    28262    if(array_key_exists('category', $_POST)) $Category = $_POST['category'] * 1;
    29     $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$Category.' ORDER BY Sequence');
    30     if($DbResult->num_rows > 0)
    31     {
    32       $Row = $DbResult->fetch_array();
    33       $CategoryName = $Row['Caption'];
     263    if(is_null($Category)) throw new Exception('Kategorie neurčena');
     264    else
     265    {
     266      $DbResult = $this->Database->select('NewsCategory', '*', '`Id`='.$Category.' ORDER BY `Sequence`');
     267      if($DbResult->num_rows > 0) $Category = $DbResult->fetch_array();
     268        else throw new Exception('Kategorie nenalezena');
    34269    }
    35 
    36     if(!array_key_exists('action',$_GET)) $_GET['action'] = '';
    37     switch($_GET['action'])
    38     {
    39       case 'view':
    40         if(!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
    41         else
    42         {
    43           if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
    44           $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE  `News`.`Id`='.$Id);
    45           if($DbResult->num_rows > 0)
    46           {
    47             $Row = $DbResult->fetch_array();
    48             if($Row['Name'] == '') $Author = $Row['Author'];
    49               else $Author = $Row['Name'];
    50             $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')';
    51             if($this->System->User->User['Id'] == $Row['User'])
    52             {
    53               $Output .= '<div class="Action">';
    54               $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
    55               $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
    56               $Output .= '</div>';
    57             }
    58             $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
    59             if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    60             if($Row['Enclosure'] != '')
    61             {
    62               $Output .= '<br />Přílohy: ';
    63               $Enclosures = explode(';', $Row['Enclosure']);
    64         foreach($Enclosures as $Enclosure)
    65               {
    66           if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
    67               }
    68             }
    69             $Output .= '</div></div>';
    70           } else $Output .= 'Položka nenalezena.';
    71         }
    72         break;
    73       case 'add':
    74         $Output .= '<strong>Vložení nové aktuality:</strong><br />';
    75         if($Category == 2) $Output .= 'U inzerátů uvádějte co nejvíce informací ať případný zájemce ví co kupuje. Uvádějte kontaktní údaje jako Jméno, email, tel. číslo, ICQ. Dále navrženou cenu, detajlní popis předmětu nejlépe s odkazem na stránky výrobce. Pokud váš inzerát již není platný, připište do něj např. "Prodáno" pomocí editace.';
    76         $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
    77     'Kategorie: <select name="category">';
    78         $DbResult = $this->Database->select('NewsCategory', '*');
    79         while($DbRow = $DbResult->fetch_array())
    80         {
    81           if($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
    82           {
    83             if($DbRow['Id'] == $Category) $Selected = ' selected="1"'; else $Selected = '';
    84             $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>';
    85           }
    86         }
    87         $Output .= '</select><br />'.
    88     'Nadpis:<br /><input type="text" size="54" name="title"><br />
    89     Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />
    90     Odkaz:<br /><input type="text" size="54" name="link"><br />
    91     Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    92     <input name="enclosure1" size="38" type="file"><br />
    93     <input name="enclosure2" size="38" type="file"><br />
    94     <input name="enclosure3" size="38" type="file"><br />
    95     <input type="submit" value="Vložit">
    96     </form>';
    97         break;
    98       case 'add2':
    99         $RemoteAddr = GetRemoteAddress(); 
    100         if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category))
    101         {
    102           // Process uploaded file
    103           $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3');
    104           $Enclosures = '';
    105           foreach($EnclosureFileNames as $EnclosureName)
    106           if(array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
    107           {
    108             $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
    109             if(move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
    110             {
    111               $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.<br />';
    112           $Enclosures = $Enclosures.';'.basename($_FILES[$EnclosureName]['name']);
    113             } else
    114             {
    115               $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' se nepodařilo nahrát na server.<br />';
    116             }
    117           }
    118           $Enclosures = substr($Enclosures, 1);
    119 
    120           $_POST['content'] = str_replace("\n",'<br />',$_POST['content']);
    121           $this->Database->insert('News', array('Category' => $Category, 'Title' => $_POST['title'],
    122             'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr,
    123             'Enclosure' => $Enclosures, 'Author' => $this->System->User->User['Name'], 'User' => $this->System->User->User['Id'], 'Link' => $_POST['link']));
    124           $Output .= 'Aktualita přidána!<br />Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.<br /><br />';
    125           $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
    126           $this->System->ModuleManager->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
    127         } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    128         break;
    129       case 'edit':
    130         $DbResult = $this->Database->query('SELECT * FROM News WHERE Id='.$_GET['id']);
    131         $Row = $DbResult->fetch_array();
    132         if($this->System->User->User['Id'] == $Row['User'])
    133         {
    134           $Row['Content'] = str_replace('<br />', '', $Row['Content']);
    135           $Output .= '<strong>Editace aktuality v kategorii '.$CategoryName.':</strong><br />';
    136           $Output .= '<form action="?action=update" method="post">'.
    137           '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
    138           'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'.
    139           'Obsah:<br /><textarea name="content" rows="20" cols="40">'.$Row['Content'].'</textarea><br />'.
    140           'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
    141           '<input type="hidden" name="category" value="'.$Category.'"><br />'.
    142           '<input type="submit" value="Uložit">'.
    143           '</form>';
    144         } else $Output .= 'Nepovolená operace!';
    145         break;
    146       case 'update':
    147         $RemoteAddr = GetRemoteAddress(); 
    148         $_POST['id'] = $_POST['id'] * 1;
    149         $DbResult = $this->Database->select('News', '*', 'Id='.$_POST['id']);
    150         if($DbResult->num_rows > 0)
    151         {
    152           $Row = $DbResult->fetch_array();
    153           if($this->System->User->User['Id'] == $Row['User'])
    154           {
    155             $_POST['content'] = str_replace("\n", '<br />', $_POST['content']);
    156             $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'], 'Content' => $_POST['content']));
    157             $Output .= 'Aktualita uložena!<br />';
    158             $Output .= '<a href="index.php?category='.$Category.'">Zpět na seznam aktualit</a>';
    159           } else $Output .= 'Nelze měnit cizí aktualitu!<br />';
    160         } else $Output .= 'ID nenalezeno!';
    161         break;
    162       case 'del':
    163         $DbResult = $this->Database->query('SELECT * FROM News WHERE Id='.$_GET['id']);
    164         $Row = $DbResult->fetch_array();
    165         if($this->System->User->User['Id'] == $Row['User'])
    166         {
    167           if($Row['Enclosure'] != '')
    168           {
    169             $Output .= '<br />Přílohy: ';
    170             $Enclosures = explode(';', $Row['Enclosure']);
    171             foreach($Enclosures as $Enclosure)
    172             {
    173               if(file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
    174             }
    175           }
    176           $this->Database->query('DELETE FROM News WHERE Id='.$_GET['id']);
    177           $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category.'">Zpět na seznam aktualit</a>';
    178         } else $Output .= 'Nemáte oprávnění.';
    179         break;
    180       default:
    181         if($this->System->User->CheckPermission('News', 'Display', 'Group', $Category))
    182         {
    183           $PerPage = 20;
    184           $DbResult = $this->Database->select('News', 'COUNT(*)', ' Category='.$Category);
    185           $RowTotal = $DbResult->fetch_array();
    186           $PageMax = $RowTotal[0];
    187           if(array_key_exists('page', $_GET)) $Page = $_GET['page'];
    188             else $Page = 0; //round($PageMax/$PerPage);
    189           $Output .= '<strong>Seznam aktualit kategorie '.$CategoryName.':</strong><div style="font-size: small;">';
    190           $Output .= PagesList('?category='.$Category.'&amp;page=', $Page, $PageMax, $PerPage);
    191 
    192           //echo(GetRemoteAddress().','.$_SERVER['HTTP_X_FORWARDED_FOR'].'<br />');
    193           $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `Category`='.$Category.' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
    194           while($Row = $DbResult->fetch_array())
    195           {
    196             if($Row['Name'] == '') $Author = $Row['Author'];
    197               else $Author = $Row['Name'];
    198             $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&amp;id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')';
    199             if($this->System->User->User['Id'] == $Row['User'])
    200             {
    201               $Output .= '<div class="Action">';
    202               $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
    203               $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
    204               $Output .= '</div>';
    205             }
    206             $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
    207             if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    208             if($Row['Enclosure'] != '')
    209             {
    210               $Output .= '<br />Přílohy: ';
    211               $Enclosures = explode(';', $Row['Enclosure']);
    212               foreach($Enclosures as $Enclosure)
    213               {
    214                 if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
    215               }
    216             }
    217             $Output .= '</div></div>';
    218           }
    219           $Output .= PagesList('?category='.$Category.'&amp;page=', $Page, $PageMax, $PerPage);
    220           $Output .= '</div>';
    221         } else $Output .= 'Nemáte oprávnění.';
    222     }
     270    return($Category);
     271  }
     272 
     273  function ShowMain()
     274  {
     275    $Output = '';   
     276    if(array_key_exists('action',$_GET)) $Action = $_GET['action'];
     277      else $Action = '';
     278    if($Action == 'view') $Output .= $this->ShowView();
     279    else if($Action == 'add') $Output .= $this->ShowAdd();
     280    else if($Action == 'add2') $Output .= $this->ShowAdd2();
     281    else if($Action == 'edit') $Output .= $this->ShowEdit();
     282    else if($Action == 'update') $Output .= $this->ShowUpdate();
     283    else if($Action == 'del') $Output .= $this->ShowDelete();
     284    else $Output .= $this->ShowList();
    223285    return($Output);
    224286  }
     
    240302      '<br />Kategorie:<br />';
    241303      $Output .= '<form action="?build=1" method="post">';
    242       $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Caption');
     304      $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY `Caption`');
    243305      while($Category = $DbResult->fetch_array())
    244306      {
    245307        $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';
    246308      }
    247       $Output.= '<input type="submit" value="Sestavit " />'.
     309      $Output.= '<input type="submit" value="Sestavit"/>'.
    248310        '</form>';
    249311    } 
     
    272334      foreach($Parts as $Part)
    273335      {
    274         $Where .= 'OR (category='.($Part * 1).')';
     336        $Where .= 'OR (`Category`='.($Part * 1).')';
    275337      }
    276338      $Where = substr($Where, 2);
     
    317379    // Get news from database by selected categories
    318380    $UploadedFilesFolder = 'uploads/';
    319     $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
     381    $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(`Date`) AS `UnixTime` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
    320382    while($Row = $DbResult->fetch_assoc())
    321383    {
     
    327389        foreach($Enclosures as $Enclosure)
    328390        {
    329           if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
     391          if(file_exists($UploadedFilesFolder.$Enclosure))
     392            $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'.$UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
    330393        }
    331394      }
     
    334397      $Items[] = array(
    335398        'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
    336         'Link' => 'http://'.$this->System->Config['Web']['Host'].'/aktuality/index.php?category='.$Row['Category'],
     399        'Link' => 'http://'.$this->System->Config['Web']['Host'].'/aktuality/?category='.$Row['Category'],
    337400        'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
    338         'Time' => $Row['UNIX_TIMESTAMP(Date)'],
     401        'Time' => $Row['UnixTime'],
    339402      );
    340403    }
     
    343406    $RSS->Title = $this->System->Config['Web']['Title'].' - Aktuality';
    344407    $RSS->Link = 'http://'.$this->System->Config['Web']['Host'].'/';
    345     $RSS->Description = 'Aktuality komunitní počítačové sítě ZděchovNET';
     408    $RSS->Description = 'Aktuality '.$this->System->Config['Web']['Description'];
    346409    $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
    347410    $RSS->Items = $Items;
Note: See TracChangeset for help on using the changeset viewer.