| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | class PageNews extends Page
|
|---|
| 4 | {
|
|---|
| 5 | function __construct(System $System)
|
|---|
| 6 | {
|
|---|
| 7 | parent::__construct($System);
|
|---|
| 8 | $this->Title = 'Aktuality';
|
|---|
| 9 | $this->Description = 'Aktualní informace';
|
|---|
| 10 | $this->ParentClass = 'PagePortal';
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | function ShowView(): string
|
|---|
| 14 | {
|
|---|
| 15 | $Output = '';
|
|---|
| 16 | if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
|
|---|
| 17 | else
|
|---|
| 18 | {
|
|---|
| 19 | $Category = $this->GetCategory();
|
|---|
| 20 | if (array_key_exists('id', $_GET) and is_numeric($_GET['id'])) $Id = $_GET['id'] * 1;
|
|---|
| 21 | else return $Output .= 'Položka nenalezena.';
|
|---|
| 22 | $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
|
|---|
| 23 | 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`News`.`Id`='.$Id.')'.
|
|---|
| 24 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition());
|
|---|
| 25 | if ($DbResult->num_rows > 0)
|
|---|
| 26 | {
|
|---|
| 27 | $Row = $DbResult->fetch_assoc();
|
|---|
| 28 | if ($Row['Name'] == '') $Author = $Row['Author'];
|
|---|
| 29 | else $Author = $Row['Name'];
|
|---|
| 30 | $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')';
|
|---|
| 31 | if ((ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'] == $Row['User']) and
|
|---|
| 32 | (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
|
|---|
| 33 | {
|
|---|
| 34 | $Output .= '<div class="Action">';
|
|---|
| 35 | $Output .= ' <a href="?action=del&category='.$Category['Id'].'&id='.$Row['Id'].'">Smazat</a>';
|
|---|
| 36 | $Output .= ' <a href="?action=edit&category='.$Category['Id'].'&id='.$Row['Id'].'">Upravit</a>';
|
|---|
| 37 | $Output .= '</div>';
|
|---|
| 38 | }
|
|---|
| 39 | $Output .= '</div><div class="Content">'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'<br />';
|
|---|
| 40 | if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
|
|---|
| 41 | if ($Row['Enclosure'] != '')
|
|---|
| 42 | {
|
|---|
| 43 | $Output .= '<br />Přílohy: ';
|
|---|
| 44 | $Enclosures = explode(';', $Row['Enclosure']);
|
|---|
| 45 | foreach ($Enclosures as $Enclosure)
|
|---|
| 46 | {
|
|---|
| 47 | if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure))
|
|---|
| 48 | $Output .= ' <a href="'.$this->System->Link('/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 | $Output .= '</div></div>';
|
|---|
| 52 | } else $Output .= 'Položka nenalezena.';
|
|---|
| 53 | }
|
|---|
| 54 | return $Output;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | function ShowAdd(): string
|
|---|
| 58 | {
|
|---|
| 59 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 60 | $Output = '';
|
|---|
| 61 | $Category = $this->GetCategory();
|
|---|
| 62 | if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
|
|---|
| 63 | {
|
|---|
| 64 | Core::Cast($this->System)->PageHeaders[] = array($this, 'GetPageHeader');
|
|---|
| 65 | $Output = '<strong>Vložení nové aktuality:</strong><br />';
|
|---|
| 66 | // TODO: Static reference to dynamic category item
|
|---|
| 67 | 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.';
|
|---|
| 68 | $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
|
|---|
| 69 | 'Kategorie: <select name="category">';
|
|---|
| 70 | $DbResult = $this->Database->select('NewsCategory', '*');
|
|---|
| 71 | while ($DbRow = $DbResult->fetch_assoc())
|
|---|
| 72 | {
|
|---|
| 73 | if ($User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
|
|---|
| 74 | {
|
|---|
| 75 | if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';
|
|---|
| 76 | else $Selected = '';
|
|---|
| 77 | $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>';
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 | $Output .= '</select><br />'.
|
|---|
| 81 | 'Nadpis:<br /><input type="text" size="54" name="title"><br />'.
|
|---|
| 82 | 'Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />'.
|
|---|
| 83 | 'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
|
|---|
| 84 | 'Viditelné jen z vnitřní sítě: <input type="checkbox" name="intranet"/><br />'.
|
|---|
| 85 | 'Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">'.
|
|---|
| 86 | '<input name="enclosure1" size="38" type="file"><br />'.
|
|---|
| 87 | '<input name="enclosure2" size="38" type="file"><br />'.
|
|---|
| 88 | '<input name="enclosure3" size="38" type="file"><br />'.
|
|---|
| 89 | '<input type="submit" value="Vložit">'.
|
|---|
| 90 | '</form>';
|
|---|
| 91 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
|---|
| 92 | return $Output;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | function ShowAdd2(): string
|
|---|
| 96 | {
|
|---|
| 97 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 98 | $Output = '';
|
|---|
| 99 | $RemoteAddr = GetRemoteAddress();
|
|---|
| 100 | $Category = $this->GetCategory();
|
|---|
| 101 | if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
|
|---|
| 102 | {
|
|---|
| 103 | // Process uploaded file
|
|---|
| 104 | // TODO: Make upload using general File class
|
|---|
| 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 = ModuleNews::Cast($this->System->GetModule('News'))->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 | if (array_key_exists('intranet', $_POST)) $Intranet = 1;
|
|---|
| 122 | else $Intranet = 0;
|
|---|
| 123 |
|
|---|
| 124 | $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'],
|
|---|
| 125 | 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr,
|
|---|
| 126 | 'Enclosure' => $Enclosures, 'Author' => $User->User['Name'],
|
|---|
| 127 | 'User' => $User->User['Id'], 'Link' => $_POST['link'], 'Intranet' => $Intranet));
|
|---|
| 128 | $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 />';
|
|---|
| 129 | $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
|
|---|
| 130 | ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
|
|---|
| 131 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
|---|
| 132 | return $Output;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | function GetPageHeader(): string
|
|---|
| 136 | {
|
|---|
| 137 | return '<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'.
|
|---|
| 138 | "<script>tinymce.init({
|
|---|
| 139 | selector: 'textarea',
|
|---|
| 140 | force_p_newlines : false,
|
|---|
| 141 | force_br_newlines : true,
|
|---|
| 142 | convert_newlines_to_brs : false,
|
|---|
| 143 | remove_linebreaks : true,
|
|---|
| 144 | plugins: [
|
|---|
| 145 | 'advlist autolink lists link image charmap print preview anchor',
|
|---|
| 146 | 'searchreplace visualblocks code fullscreen',
|
|---|
| 147 | 'insertdatetime media table contextmenu paste code'
|
|---|
| 148 | ],
|
|---|
| 149 | toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
|
|---|
| 150 | language: 'cs_CZ',
|
|---|
| 151 | });</script>";
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | function ShowEdit(): string
|
|---|
| 155 | {
|
|---|
| 156 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 157 | $Output = '';
|
|---|
| 158 | $Category = $this->GetCategory();
|
|---|
| 159 | if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
|
|---|
| 160 | {
|
|---|
| 161 | $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'.
|
|---|
| 162 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition());
|
|---|
| 163 | $Row = $DbResult->fetch_assoc();
|
|---|
| 164 | if (($User->User['Id'] == $Row['User']))
|
|---|
| 165 | {
|
|---|
| 166 | if ($Row['Intranet'] == 1) $IntranetChecked = ' checked="1"';
|
|---|
| 167 | else $IntranetChecked = 0;
|
|---|
| 168 | Core::Cast($this->System)->PageHeaders[] = array($this, 'GetPageHeader');
|
|---|
| 169 | $Output .= '<strong>Editace aktuality v kategorii '.$Category['Caption'].':</strong><br />';
|
|---|
| 170 | $Output .= '<form action="?action=update" method="post">'.
|
|---|
| 171 | '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
|
|---|
| 172 | 'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'.
|
|---|
| 173 | 'Obsah:<br /><textarea name="content" rows="20" cols="40" style="width: 50%">'.$Row['Content'].'</textarea><br />'.
|
|---|
| 174 | 'Odkaz:<br /><input type="text" size="54" name="link" value="'.$Row['Link'].'"><br />'.
|
|---|
| 175 | 'Viditelné jen z vnitřní sítě: <input type="checkbox" name="intranet" '.$IntranetChecked.'/><br />'.
|
|---|
| 176 | '<input type="hidden" name="category" value="'.$Category['Id'].'"><br />'.
|
|---|
| 177 | '<input type="submit" value="Uložit">'.
|
|---|
| 178 | '</form>';
|
|---|
| 179 | } else $Output .= 'Nepovolená operace!';
|
|---|
| 180 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
|---|
| 181 | return $Output;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | function ShowUpdate(): string
|
|---|
| 185 | {
|
|---|
| 186 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 187 | $Output = '';
|
|---|
| 188 | $RemoteAddr = GetRemoteAddress();
|
|---|
| 189 | $Category = $this->GetCategory();
|
|---|
| 190 | if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
|
|---|
| 191 | {
|
|---|
| 192 | $_POST['id'] = $_POST['id'] * 1;
|
|---|
| 193 | $DbResult = $this->Database->select('News', '*', '(`Id`='.$_POST['id'].')'.
|
|---|
| 194 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition());
|
|---|
| 195 | if ($DbResult->num_rows > 0)
|
|---|
| 196 | {
|
|---|
| 197 | $Row = $DbResult->fetch_assoc();
|
|---|
| 198 | if ($User->User['Id'] == $Row['User'])
|
|---|
| 199 | {
|
|---|
| 200 | if (array_key_exists('intranet', $_POST)) $Intranet = 1;
|
|---|
| 201 | else $Intranet = 0;
|
|---|
| 202 |
|
|---|
| 203 | $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'],
|
|---|
| 204 | 'Content' => $_POST['content'], 'Link' => $_POST['link'], 'Intranet' => $Intranet));
|
|---|
| 205 | $Output .= 'Aktualita uložena!<br />';
|
|---|
| 206 | $Output .= '<a href="?category='.$Category['Id'].'">Zpět na seznam aktualit</a>';
|
|---|
| 207 | } else $Output .= 'Nelze měnit cizí aktualitu!<br />';
|
|---|
| 208 | } else $Output .= 'ID nenalezeno!';
|
|---|
| 209 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
|---|
| 210 | return $Output;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | function ShowDelete(): string
|
|---|
| 214 | {
|
|---|
| 215 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 216 | $Output = '';
|
|---|
| 217 | $Category = $this->GetCategory();
|
|---|
| 218 | if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
|
|---|
| 219 | {
|
|---|
| 220 | $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'.
|
|---|
| 221 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition());
|
|---|
| 222 | $Row = $DbResult->fetch_assoc();
|
|---|
| 223 | if ($User->User['Id'] == $Row['User'])
|
|---|
| 224 | {
|
|---|
| 225 | // TODO: Make upload using general File class
|
|---|
| 226 | if ($Row['Enclosure'] != '')
|
|---|
| 227 | {
|
|---|
| 228 | $Output .= '<br />Přílohy: ';
|
|---|
| 229 | $Enclosures = explode(';', $Row['Enclosure']);
|
|---|
| 230 | foreach ($Enclosures as $Enclosure)
|
|---|
| 231 | {
|
|---|
| 232 | if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) unlink(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure);
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 | $this->Database->query('DELETE FROM `News` WHERE `Id`='.$_GET['id']);
|
|---|
| 236 | $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category['Id'].'">Zpět na seznam aktualit</a>';
|
|---|
| 237 | } else $Output .= 'Nemáte oprávnění.';
|
|---|
| 238 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
|---|
| 239 | return $Output;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | function ShowList(): string
|
|---|
| 243 | {
|
|---|
| 244 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 245 | $Output = '';
|
|---|
| 246 | $Category = $this->GetCategory();
|
|---|
| 247 | if ($User->CheckPermission('News', 'Display', 'Group', $Category['Id']))
|
|---|
| 248 | {
|
|---|
| 249 | $PerPage = 20;
|
|---|
| 250 | $DbResult = $this->Database->select('News', 'COUNT(*)', '(`Category`='.$Category['Id'].')'.
|
|---|
| 251 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition());
|
|---|
| 252 | $RowTotal = $DbResult->fetch_array();
|
|---|
| 253 | $PageMax = $RowTotal[0];
|
|---|
| 254 | if (array_key_exists('page', $_GET) and is_numeric($_GET['page'])) $Page = $_GET['page'] * 1;
|
|---|
| 255 | else $Page = 0;
|
|---|
| 256 | $Output .= '<strong>Seznam aktualit kategorie '.$Category['Caption'].':</strong><div style="font-size: small;">';
|
|---|
| 257 | $Output .= PagesList('?category='.$Category['Id'].'&page=', $Page, $PageMax, $PerPage);
|
|---|
| 258 |
|
|---|
| 259 | $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
|
|---|
| 260 | 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`Category`='.$Category['Id'].')'.
|
|---|
| 261 | ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition().
|
|---|
| 262 | ' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
|
|---|
| 263 | while ($Row = $DbResult->fetch_assoc())
|
|---|
| 264 | {
|
|---|
| 265 | if ($Row['Name'] == '') $Author = $Row['Author'];
|
|---|
| 266 | else $Author = $Row['Name'];
|
|---|
| 267 | $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')';
|
|---|
| 268 | if (($User->User['Id'] == $Row['User']) and ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
|
|---|
| 269 | {
|
|---|
| 270 | $Output .= '<div class="Action">';
|
|---|
| 271 | $Output .= ' <a href="?action=del&category='.$Category['Id'].'&id='.$Row['Id'].'">Smazat</a>';
|
|---|
| 272 | $Output .= ' <a href="?action=edit&category='.$Category['Id'].'&id='.$Row['Id'].'">Upravit</a>';
|
|---|
| 273 | $Output .= '</div>';
|
|---|
| 274 | }
|
|---|
| 275 | $Output .= '</div><div class="Content">'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'<br />';
|
|---|
| 276 | if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
|
|---|
| 277 | if ($Row['Enclosure'] != '')
|
|---|
| 278 | {
|
|---|
| 279 | $Output .= '<br />Přílohy: ';
|
|---|
| 280 | $Enclosures = explode(';', $Row['Enclosure']);
|
|---|
| 281 | foreach ($Enclosures as $Enclosure)
|
|---|
| 282 | {
|
|---|
| 283 | if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure))
|
|---|
| 284 | $Output .= ' <a href="'.$this->System->Link('/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
|
|---|
| 285 | }
|
|---|
| 286 | }
|
|---|
| 287 | $Output .= '</div></div>';
|
|---|
| 288 | }
|
|---|
| 289 | $Output .= PagesList('?category='.$Category['Id'].'&page=', $Page, $PageMax, $PerPage);
|
|---|
| 290 | $Output .= '</div>';
|
|---|
| 291 | } else $Output .= 'Nemáte oprávnění.';
|
|---|
| 292 | return $Output;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | function GetCategory(): array
|
|---|
| 296 | {
|
|---|
| 297 | $Category = array('Id' => 1); // Default category
|
|---|
| 298 | if (array_key_exists('category', $_GET) and is_numeric($_GET['category'])) $Category['Id'] = $_GET['category'] * 1;
|
|---|
| 299 | if (array_key_exists('category', $_POST) and is_numeric($_POST['category'])) $Category['Id'] = $_POST['category'] * 1;
|
|---|
| 300 | //if (is_null($Category)) throw new Exception('Kategorie neurčena');
|
|---|
| 301 | else
|
|---|
| 302 | {
|
|---|
| 303 | $DbResult = $this->Database->select('NewsCategory', '*', '`Id`='.$Category['Id'].' ORDER BY `Sequence`');
|
|---|
| 304 | if ($DbResult->num_rows > 0) $Category = $DbResult->fetch_array();
|
|---|
| 305 | else $Category = array('Id' => 0); //throw new Exception('Kategorie nenalezena');
|
|---|
| 306 | }
|
|---|
| 307 | return $Category;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | function Show(): string
|
|---|
| 311 | {
|
|---|
| 312 | $Output = '';
|
|---|
| 313 | if (array_key_exists('action', $_GET)) $Action = $_GET['action'];
|
|---|
| 314 | else $Action = '';
|
|---|
| 315 | if ($Action == 'view') $Output .= $this->ShowView();
|
|---|
| 316 | else if ($Action == 'add') $Output .= $this->ShowAdd();
|
|---|
| 317 | else if ($Action == 'add2') $Output .= $this->ShowAdd2();
|
|---|
| 318 | else if ($Action == 'edit') $Output .= $this->ShowEdit();
|
|---|
| 319 | else if ($Action == 'update') $Output .= $this->ShowUpdate();
|
|---|
| 320 | else if ($Action == 'del') $Output .= $this->ShowDelete();
|
|---|
| 321 | else $Output .= $this->ShowList();
|
|---|
| 322 | return $Output;
|
|---|
| 323 | }
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | class PageNewsUpdate extends Page
|
|---|
| 327 | {
|
|---|
| 328 | function __construct(System $System)
|
|---|
| 329 | {
|
|---|
| 330 | parent::__construct($System);
|
|---|
| 331 | $this->Title = 'Aktualizace aktualit';
|
|---|
| 332 | $this->ParentClass = 'PageNews';
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | function Show(): string
|
|---|
| 336 | {
|
|---|
| 337 | $NewsSources = new NewsSources();
|
|---|
| 338 | $NewsSources->Database = $this->Database;
|
|---|
| 339 | if (array_key_exists('i', $_GET)) $Output = $NewsSources->Parse($_GET['i']);
|
|---|
| 340 | else $Output = $NewsSources->Parse();
|
|---|
| 341 | return $Output;
|
|---|
| 342 | }
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | class PageNewsSubscription extends Page
|
|---|
| 346 | {
|
|---|
| 347 | function __construct(System $System)
|
|---|
| 348 | {
|
|---|
| 349 | parent::__construct($System);
|
|---|
| 350 | $this->Title = 'Odběry aktualit';
|
|---|
| 351 | $this->ParentClass = 'PageNews';
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | function Show(): string
|
|---|
| 355 | {
|
|---|
| 356 | if (array_key_exists('build', $_GET))
|
|---|
| 357 | {
|
|---|
| 358 | $Select = '';
|
|---|
| 359 | foreach ($_POST as $Index => $Item)
|
|---|
| 360 | {
|
|---|
| 361 | if (substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);
|
|---|
| 362 | }
|
|---|
| 363 | if ($Select != '')
|
|---|
| 364 | {
|
|---|
| 365 | $Select = Core::Cast($this->System)->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1);
|
|---|
| 366 | $Output = 'Výsledný RSS kanál: <a href="'.$Select.'">'.$Select.'</a>';
|
|---|
| 367 | } else
|
|---|
| 368 | {
|
|---|
| 369 | $Output = 'Nevybrána žádná kategorie pro vytvoření RSS kanálu.';
|
|---|
| 370 | }
|
|---|
| 371 | } else
|
|---|
| 372 | {
|
|---|
| 373 | $Output = 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. '.
|
|---|
| 374 | 'Informace o technologii RSS a programech pro čtení kanálů najdete např. <a href="https://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />'.
|
|---|
| 375 | '<br />Kategorie:<br />';
|
|---|
| 376 | $Output .= '<form action="?build=1" method="post">';
|
|---|
| 377 | $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY `Caption`');
|
|---|
| 378 | while ($Category = $DbResult->fetch_assoc())
|
|---|
| 379 | {
|
|---|
| 380 | $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';
|
|---|
| 381 | }
|
|---|
| 382 | $Output.= '<input type="submit" value="Sestavit"/>'.
|
|---|
| 383 | '</form>';
|
|---|
| 384 | }
|
|---|
| 385 | return $Output;
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | class PageNewsRss extends Page
|
|---|
| 390 | {
|
|---|
| 391 | function __construct(System $System)
|
|---|
| 392 | {
|
|---|
| 393 | parent::__construct($System);
|
|---|
| 394 | $this->Title = 'Aktuality RSS';
|
|---|
| 395 | $this->Description = 'RSS kanál aktualit';
|
|---|
| 396 | $this->ParentClass = 'PageNews';
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | function Show(): string
|
|---|
| 400 | {
|
|---|
| 401 | $this->RawPage = true;
|
|---|
| 402 | Core::Cast($this->System)->BaseView->FormatHTML = false;
|
|---|
| 403 | Header('Content-Type: text/xml');
|
|---|
| 404 |
|
|---|
| 405 | $NewsCount = 15;
|
|---|
| 406 |
|
|---|
| 407 | $Items = array();
|
|---|
| 408 | $Category = '';
|
|---|
| 409 | $CategoryOption = '';
|
|---|
| 410 | $CategoryOptionURL = '';
|
|---|
| 411 | $CategoryName = '';
|
|---|
| 412 |
|
|---|
| 413 | // Prepare WHERE condition
|
|---|
| 414 | if (array_key_exists('select', $_GET))
|
|---|
| 415 | {
|
|---|
| 416 | $Where = '';
|
|---|
| 417 | $Parts = array_filter(explode('-', $_GET['select']));
|
|---|
| 418 | if (count($Parts) > 0)
|
|---|
| 419 | {
|
|---|
| 420 | foreach ($Parts as $Part)
|
|---|
| 421 | {
|
|---|
| 422 | if (is_numeric($Part)) $Where .= 'OR (`Category`='.($Part * 1).')';
|
|---|
| 423 | }
|
|---|
| 424 | if (strlen($Where) > 2) $Where = substr($Where, 2);
|
|---|
| 425 | else $Where = 1;
|
|---|
| 426 | } else $Where = 1;
|
|---|
| 427 | } else $Where = 1;
|
|---|
| 428 |
|
|---|
| 429 | // Get category names
|
|---|
| 430 | $Categories = array();
|
|---|
| 431 | $DbResult = $this->Database->select('NewsCategory', '*');
|
|---|
| 432 | while ($Category = $DbResult->fetch_assoc())
|
|---|
| 433 | {
|
|---|
| 434 | $Categories[$Category['Id']] = $Category['Caption'];
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | // Update news from discussion forum
|
|---|
| 438 | /*
|
|---|
| 439 | $ForumCategory = 4;
|
|---|
| 440 | $Database->select_db('forum');
|
|---|
| 441 | $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);
|
|---|
| 442 | $Index = 0;
|
|---|
| 443 | //echo(DB_NumRows().',');
|
|---|
| 444 | while ($Row = $DbResult->fetch_array())
|
|---|
| 445 | {
|
|---|
| 446 | $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
|
|---|
| 447 | $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
|
|---|
| 448 | $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
|
|---|
| 449 | $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
|
|---|
| 450 | $Index = $Index + 1;
|
|---|
| 451 |
|
|---|
| 452 | $Title = $Row['topic_title'].'-'.$Row['post_subject'];
|
|---|
| 453 | $Content = $Row['post_text'];
|
|---|
| 454 | $Date = date('Y-m-d H:i:s', $Row['post_time']);
|
|---|
| 455 | $Author = $Row['username'];
|
|---|
| 456 | $Database->select_db('is');
|
|---|
| 457 | //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
|
|---|
| 458 | $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
|
|---|
| 459 | if ($DbResult2->num_rows == 0) //echo('.'); else echo('x');
|
|---|
| 460 | $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
|
|---|
| 461 | //echo($Date);
|
|---|
| 462 | $Database->select_db('forum');
|
|---|
| 463 | }
|
|---|
| 464 | $Database->select_db('is');
|
|---|
| 465 | */
|
|---|
| 466 |
|
|---|
| 467 | // Get news from database by selected categories
|
|---|
| 468 | $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(`Date`) AS `UnixTime` FROM `News`'.
|
|---|
| 469 | ' LEFT JOIN `User` ON `User`.`Id`=`News`.`User`'.
|
|---|
| 470 | ' WHERE '.$Where.ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition().
|
|---|
| 471 | ' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
|
|---|
| 472 | while ($Row = $DbResult->fetch_assoc())
|
|---|
| 473 | {
|
|---|
| 474 | $EnclosuresText = '';
|
|---|
| 475 | if ($Row['Enclosure'] != '')
|
|---|
| 476 | {
|
|---|
| 477 | $EnclosuresText .= '<br />Přílohy: ';
|
|---|
| 478 | $Enclosures = explode(';', $Row['Enclosure']);
|
|---|
| 479 | foreach ($Enclosures as $Enclosure)
|
|---|
| 480 | {
|
|---|
| 481 | if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure))
|
|---|
| 482 | $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
|
|---|
| 483 | }
|
|---|
| 484 | }
|
|---|
| 485 | if ($Row['Name'] == '') $Author = $Row['Author'];
|
|---|
| 486 | else $Author = $Row['Name'];
|
|---|
| 487 | $Items[] = array(
|
|---|
| 488 | 'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
|
|---|
| 489 | 'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].'/aktuality/?category='.$Row['Category'],
|
|---|
| 490 | 'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
|
|---|
| 491 | 'Time' => $Row['UnixTime'],
|
|---|
| 492 | );
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | $RSS = new RSS();
|
|---|
| 496 | $RSS->Title = Core::Cast($this->System)->Config['Web']['Title'].' - Aktuality';
|
|---|
| 497 | $RSS->Link = 'https://'.Core::Cast($this->System)->Config['Web']['Host'].'/';
|
|---|
| 498 | $RSS->Description = 'Aktuality '.Core::Cast($this->System)->Config['Web']['Description'];
|
|---|
| 499 | $RSS->WebmasterEmail = Core::Cast($this->System)->Config['Web']['AdminEmail'];
|
|---|
| 500 | $RSS->Items = $Items;
|
|---|
| 501 | return $RSS->Generate();
|
|---|
| 502 | }
|
|---|
| 503 | }
|
|---|