Title = 'Aktuality'; $this->Description = 'Aktualní informace'; $this->ParentClass = 'PagePortal'; } function ShowView(): string { $Output = ''; if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění'; else { $Category = $this->GetCategory(); if (array_key_exists('id', $_GET) and is_numeric($_GET['id'])) $Id = $_GET['id'] * 1; else return $Output .= 'Položka nenalezena.'; $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '. 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`News`.`Id`='.$Id.')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition()); if ($DbResult->num_rows > 0) { $Row = $DbResult->fetch_assoc(); if ($Row['Name'] == '') $Author = $Row['Author']; else $Author = $Row['Name']; $Output .= '
'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')'; if ((ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'] == $Row['User']) and (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) { $Output .= '
'; $Output .= ' Smazat'; $Output .= ' Upravit'; $Output .= '
'; } $Output .= '
'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'
'; if ($Row['Link'] != '') $Output .= '
Odkaz'; if ($Row['Enclosure'] != '') { $Output .= '
Přílohy: '; $Enclosures = explode(';', $Row['Enclosure']); foreach ($Enclosures as $Enclosure) { if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) $Output .= ' '.$Enclosure.''; } } $Output .= '
'; } else $Output .= 'Položka nenalezena.'; } return $Output; } function ShowAdd(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) { Core::Cast($this->System)->PageHeaders[] = array($this, 'GetPageHeader'); $Output = 'Vložení nové aktuality:
'; // TODO: Static reference to dynamic category item 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.'; $Output .= '
'. 'Kategorie:
'. 'Nadpis:

'. 'Obsah:

'. 'Odkaz:

'. 'Viditelné jen z vnitřní sítě:
'. 'Přílohy (Max. velikost souboru 1 MB):
'. '
'. '
'. '
'. ''. '
'; } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; return $Output; } function ShowAdd2(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $RemoteAddr = GetRemoteAddress(); $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) { // Process uploaded file // TODO: Make upload using general File class $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3'); $Enclosures = ''; foreach ($EnclosureFileNames as $EnclosureName) if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != '')) { $UploadedFilePath = ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']); if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath)) { $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.
'; $Enclosures = $Enclosures.';'.basename($_FILES[$EnclosureName]['name']); } else { $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' se nepodařilo nahrát na server.
'; } } $Enclosures = substr($Enclosures, 1); if (array_key_exists('intranet', $_POST)) $Intranet = 1; else $Intranet = 0; $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'], 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr, 'Enclosure' => $Enclosures, 'Author' => $User->User['Name'], 'User' => $User->User['Id'], 'Link' => $_POST['link'], 'Intranet' => $Intranet)); $Output .= 'Aktualita přidána!
Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.

'; $Output .= 'Zpět na seznam aktualit'; ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id); } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; return $Output; } function GetPageHeader(): string { return ''. ""; } function ShowEdit(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) { $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition()); $Row = $DbResult->fetch_assoc(); if (($User->User['Id'] == $Row['User'])) { if ($Row['Intranet'] == 1) $IntranetChecked = ' checked="1"'; else $IntranetChecked = 0; Core::Cast($this->System)->PageHeaders[] = array($this, 'GetPageHeader'); $Output .= 'Editace aktuality v kategorii '.$Category['Caption'].':
'; $Output .= '
'. ''. 'Nadpis:

'. 'Obsah:

'. 'Odkaz:

'. 'Viditelné jen z vnitřní sítě:
'. '
'. ''. '
'; } else $Output .= 'Nepovolená operace!'; } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; return $Output; } function ShowUpdate(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $RemoteAddr = GetRemoteAddress(); $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) { $_POST['id'] = $_POST['id'] * 1; $DbResult = $this->Database->select('News', '*', '(`Id`='.$_POST['id'].')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition()); if ($DbResult->num_rows > 0) { $Row = $DbResult->fetch_assoc(); if ($User->User['Id'] == $Row['User']) { if (array_key_exists('intranet', $_POST)) $Intranet = 1; else $Intranet = 0; $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'], 'Content' => $_POST['content'], 'Link' => $_POST['link'], 'Intranet' => $Intranet)); $Output .= 'Aktualita uložena!
'; $Output .= 'Zpět na seznam aktualit'; } else $Output .= 'Nelze měnit cizí aktualitu!
'; } else $Output .= 'ID nenalezeno!'; } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; return $Output; } function ShowDelete(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) { $DbResult = $this->Database->query('SELECT * FROM `News` WHERE (`Id`='.$_GET['id'].')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition()); $Row = $DbResult->fetch_assoc(); if ($User->User['Id'] == $Row['User']) { // TODO: Make upload using general File class if ($Row['Enclosure'] != '') { $Output .= '
Přílohy: '; $Enclosures = explode(';', $Row['Enclosure']); foreach ($Enclosures as $Enclosure) { if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) unlink(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure); } } $this->Database->query('DELETE FROM `News` WHERE `Id`='.$_GET['id']); $Output .= 'Aktualita smazána!
Zpět na seznam aktualit'; } else $Output .= 'Nemáte oprávnění.'; } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; return $Output; } function ShowList(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $Category = $this->GetCategory(); if ($User->CheckPermission('News', 'Display', 'Group', $Category['Id'])) { $PerPage = 20; $DbResult = $this->Database->select('News', 'COUNT(*)', '(`Category`='.$Category['Id'].')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition()); $RowTotal = $DbResult->fetch_array(); $PageMax = $RowTotal[0]; if (array_key_exists('page', $_GET)) $Page = $_GET['page']; else $Page = 0; //round($PageMax/$PerPage); $Output .= 'Seznam aktualit kategorie '.$Category['Caption'].':
'; $Output .= PagesList('?category='.$Category['Id'].'&page=', $Page, $PageMax, $PerPage); $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '. 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`Category`='.$Category['Id'].')'. ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition(). ' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage); while ($Row = $DbResult->fetch_assoc()) { if ($Row['Name'] == '') $Author = $Row['Author']; else $Author = $Row['Name']; $Output .= '
'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')'; if (($User->User['Id'] == $Row['User']) and ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) { $Output .= '
'; $Output .= ' Smazat'; $Output .= ' Upravit'; $Output .= '
'; } $Output .= '
'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'
'; if ($Row['Link'] != '') $Output .= '
Odkaz'; if ($Row['Enclosure'] != '') { $Output .= '
Přílohy: '; $Enclosures = explode(';', $Row['Enclosure']); foreach ($Enclosures as $Enclosure) { if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) $Output .= ' '.$Enclosure.''; } } $Output .= '
'; } $Output .= PagesList('?category='.$Category['Id'].'&page=', $Page, $PageMax, $PerPage); $Output .= '
'; } else $Output .= 'Nemáte oprávnění.'; return $Output; } function GetCategory(): array { $Category = array('Id' => 1); // Default category if (array_key_exists('category', $_GET) and is_numeric($_GET['category'])) $Category['Id'] = $_GET['category'] * 1; if (array_key_exists('category', $_POST) and is_numeric($_POST['category'])) $Category['Id'] = $_POST['category'] * 1; //if (is_null($Category)) throw new Exception('Kategorie neurčena'); else { $DbResult = $this->Database->select('NewsCategory', '*', '`Id`='.$Category['Id'].' ORDER BY `Sequence`'); if ($DbResult->num_rows > 0) $Category = $DbResult->fetch_array(); else $Category = array('Id' => 0); //throw new Exception('Kategorie nenalezena'); } return $Category; } function Show(): string { $Output = ''; if (array_key_exists('action', $_GET)) $Action = $_GET['action']; else $Action = ''; if ($Action == 'view') $Output .= $this->ShowView(); else if ($Action == 'add') $Output .= $this->ShowAdd(); else if ($Action == 'add2') $Output .= $this->ShowAdd2(); else if ($Action == 'edit') $Output .= $this->ShowEdit(); else if ($Action == 'update') $Output .= $this->ShowUpdate(); else if ($Action == 'del') $Output .= $this->ShowDelete(); else $Output .= $this->ShowList(); return $Output; } } class PageNewsUpdate extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Aktualizace aktualit'; $this->ParentClass = 'PageNews'; } function Show(): string { $NewsSources = new NewsSources(); $NewsSources->Database = $this->Database; if (array_key_exists('i', $_GET)) $Output = $NewsSources->Parse($_GET['i']); else $Output = $NewsSources->Parse(); return $Output; } } class PageNewsSubscription extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Odběry aktualit'; $this->ParentClass = 'PageNews'; } function Show(): string { if (array_key_exists('build', $_GET)) { $Select = ''; foreach ($_POST as $Index => $Item) { if (substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8); } if ($Select != '') { $Select = Core::Cast($this->System)->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1); $Output = 'Výsledný RSS kanál: '.$Select.''; } else { $Output = 'Nevybrána žádná kategorie pro vytvoření RSS kanálu.'; } } else { $Output = 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. '. 'Informace o technologii RSS a programech pro čtení kanálů najdete např. zde
'. '
Kategorie:
'; $Output .= '
'; $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY `Caption`'); while ($Category = $DbResult->fetch_assoc()) { $Output .= ''.$Category['Caption'].'
'; } $Output.= ''. '
'; } return $Output; } } class PageNewsRss extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Aktuality RSS'; $this->Description = 'RSS kanál aktualit'; $this->ParentClass = 'PageNews'; } function Show(): string { $this->RawPage = true; $this->FormatHTML = false; Header('Content-Type: text/xml'); $NewsCount = 15; $Items = array(); $Category = ''; $CategoryOption = ''; $CategoryOptionURL = ''; $CategoryName = ''; // Prepare WHERE condition if (array_key_exists('select', $_GET)) { $Where = ''; $Parts = array_filter(explode('-', $_GET['select'])); if (count($Parts) > 0) { foreach ($Parts as $Part) { if (is_numeric($Part)) $Where .= 'OR (`Category`='.($Part * 1).')'; } if (strlen($Where) > 2) $Where = substr($Where, 2); else $Where = 1; } else $Where = 1; } else $Where = 1; // Get category names $Categories = array(); $DbResult = $this->Database->select('NewsCategory', '*'); while ($Category = $DbResult->fetch_assoc()) { $Categories[$Category['Id']] = $Category['Caption']; } // Update news from discussion forum /* $ForumCategory = 4; $Database->select_db('forum'); $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); $Index = 0; //echo(DB_NumRows().','); while ($Row = $DbResult->fetch_array()) { $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); $Row['post_text'] = str_replace("\n","
", $Row['post_text']); $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); $Index = $Index + 1; $Title = $Row['topic_title'].'-'.$Row['post_subject']; $Content = $Row['post_text']; $Date = date('Y-m-d H:i:s', $Row['post_time']); $Author = $Row['username']; $Database->select_db('is'); //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); if ($DbResult2->num_rows == 0) //echo('.'); else echo('x'); $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date)); //echo($Date); $Database->select_db('forum'); } $Database->select_db('is'); */ // Get news from database by selected categories $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(`Date`) AS `UnixTime` FROM `News`'. ' LEFT JOIN `User` ON `User`.`Id`=`News`.`User`'. ' WHERE '.$Where.ModuleNews::Cast($this->System->GetModule('News'))->GetIntranetCondition(). ' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount); while ($Row = $DbResult->fetch_assoc()) { $EnclosuresText = ''; if ($Row['Enclosure'] != '') { $EnclosuresText .= '
Přílohy: '; $Enclosures = explode(';', $Row['Enclosure']); foreach ($Enclosures as $Enclosure) { if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' '.$Enclosure.''; } } if ($Row['Name'] == '') $Author = $Row['Author']; else $Author = $Row['Name']; $Items[] = array( 'Title' => $Categories[$Row['Category']].' - '.$Row['Title'], 'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].'/aktuality/?category='.$Row['Category'], 'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText, 'Time' => $Row['UnixTime'], ); } $RSS = new RSS(); $RSS->Title = Core::Cast($this->System)->Config['Web']['Title'].' - Aktuality'; $RSS->Link = 'https://'.Core::Cast($this->System)->Config['Web']['Host'].'/'; $RSS->Description = 'Aktuality '.Core::Cast($this->System)->Config['Web']['Description']; $RSS->WebmasterEmail = Core::Cast($this->System)->Config['Web']['AdminEmail']; $RSS->Items = $Items; return $RSS->Generate(); } }