Ignore:
Timestamp:
Aug 11, 2023, 11:17:28 AM (17 months ago)
Author:
chronos
Message:
  • Added: News can be set as intranet only.
File:
1 edited

Legend:

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

    r929 r953  
    1111  }
    1212
     13  function GetIntranetCondition(): string
     14  {
     15    if (IsInternetAddr()) return ' AND (`Intranet`=0)';
     16      else return '';
     17  }
     18
    1319  function ShowView(): string
    1420  {
     
    2026      if (array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
    2127      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
    22         'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id);
     28        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`News`.`Id`='.$Id.')'.$this->GetIntranetCondition());
    2329      if ($DbResult->num_rows > 0)
    2430      {
     
    8086        'Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />'.
    8187        'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
     88        'Viditelné jen z vnitřní sítě: <input type="checkbox" name="intranet"/><br />'.
    8289        'Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">'.
    8390        '<input name="enclosure1" size="38" type="file"><br />'.
     
    116123        }
    117124        $Enclosures = substr($Enclosures, 1);
     125        if (array_key_exists('intranet', $_POST)) $Intranet = 1;
     126          else $Intranet = 0;
    118127
    119128        $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'],
    120129          'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr,
    121130          'Enclosure' => $Enclosures, 'Author' => $User->User['Name'],
    122           'User' => $User->User['Id'], 'Link' => $_POST['link']));
     131          'User' => $User->User['Id'], 'Link' => $_POST['link'], 'Intranet' => $Intranet));
    123132        $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 />';
    124133        $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
     
    154163    if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    155164    {
    156       $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
     165      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'.$this->GetIntranetCondition());
    157166      $Row = $DbResult->fetch_assoc();
    158167      if (($User->User['Id'] == $Row['User']))
    159168      {
     169        if ($Row['Intranet'] == 1) $IntranetChecked = ' checked="1"';
     170          else $IntranetChecked = 0;
    160171        $this->System->PageHeaders[] = array($this, 'GetPageHeader');
    161172        $Output .= '<strong>Editace aktuality v kategorii '.$Category['Caption'].':</strong><br />';
     
    165176        'Obsah:<br /><textarea name="content" rows="20" cols="40" style="width: 50%">'.$Row['Content'].'</textarea><br />'.
    166177        'Odkaz:<br /><input type="text" size="54" name="link" value="'.$Row['Link'].'"><br />'.
     178        'Viditelné jen z vnitřní sítě: <input type="checkbox" name="intranet" '.$IntranetChecked.'/><br />'.
    167179        '<input type="hidden" name="category" value="'.$Category['Id'].'"><br />'.
    168180        '<input type="submit" value="Uložit">'.
     
    182194    {
    183195      $_POST['id'] = $_POST['id'] * 1;
    184       $DbResult = $this->Database->select('News', '*', '`Id`='.$_POST['id']);
     196      $DbResult = $this->Database->select('News', '*', '(`Id`='.$_POST['id'].')'.$this->GetIntranetCondition());
    185197      if ($DbResult->num_rows > 0)
    186198      {
     
    188200        if ($User->User['Id'] == $Row['User'])
    189201        {
     202          if (array_key_exists('intranet', $_POST)) $Intranet = 1;
     203            else $Intranet = 0;
     204         
    190205          $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'],
    191             'Content' => $_POST['content'], 'Link' => $_POST['link']));
     206            'Content' => $_POST['content'], 'Link' => $_POST['link'], 'Intranet' => $Intranet));
    192207          $Output .= 'Aktualita uložena!<br />';
    193208          $Output .= '<a href="?category='.$Category['Id'].'">Zpět na seznam aktualit</a>';
     
    205220    if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    206221    {
    207       $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
     222      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'.$this->GetIntranetCondition());
    208223      $Row = $DbResult->fetch_assoc();
    209224      if ($User->User['Id'] == $Row['User'])
     
    234249    {
    235250      $PerPage = 20;
    236       $DbResult = $this->Database->select('News', 'COUNT(*)', ' `Category`='.$Category['Id']);
     251      $DbResult = $this->Database->select('News', 'COUNT(*)', '(`Category`='.$Category['Id'].')'.$this->GetIntranetCondition());
    237252      $RowTotal = $DbResult->fetch_array();
    238253      $PageMax = $RowTotal[0];
     
    243258
    244259      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
    245         'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `Category`='.$Category['Id'].' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
     260        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`Category`='.$Category['Id'].')'.$this->GetIntranetCondition().
     261        ' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
    246262      while ($Row = $DbResult->fetch_assoc())
    247263      {
Note: See TracChangeset for help on using the changeset viewer.