1 | <?php
|
---|
2 |
|
---|
3 | include_once('../global.php');
|
---|
4 |
|
---|
5 | class NewsPage extends Page
|
---|
6 | {
|
---|
7 | var $FullTitle = 'Aktualní informace';
|
---|
8 | var $ShortTitle = 'Aktuality';
|
---|
9 | var $UploadedFilesFolder = 'uploads/';
|
---|
10 |
|
---|
11 | function Show()
|
---|
12 | {
|
---|
13 | $Output = '';
|
---|
14 | $Category = 1;
|
---|
15 | $CategoryName = '';
|
---|
16 | if(array_key_exists('category', $_GET)) $Category = $_GET['category'] * 1;
|
---|
17 | if(array_key_exists('category', $_POST)) $Category = $_POST['category'] * 1;
|
---|
18 | $DbResult = $this->Database->select('news_category', '*', 'id='.$Category);
|
---|
19 | if($DbResult->num_rows > 0)
|
---|
20 | {
|
---|
21 | $Row = $DbResult->fetch_array();
|
---|
22 | $CategoryName = $Row['caption'];
|
---|
23 | }
|
---|
24 |
|
---|
25 | if(!array_key_exists('action',$_GET)) $_GET['action'] = '';
|
---|
26 | switch($_GET['action'])
|
---|
27 | {
|
---|
28 | case 'view':
|
---|
29 | if(!$this->System->Modules['User']->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
|
---|
30 | else
|
---|
31 | {
|
---|
32 | if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
|
---|
33 | $DbResult = $this->Database->query('SELECT `news`.*, `User`.`Name` FROM `news` LEFT JOIN `User` ON `User`.`Id`=`news`.`User` WHERE `news`.`id`='.$Id);
|
---|
34 | if($DbResult->num_rows > 0)
|
---|
35 | {
|
---|
36 | $Row = $DbResult->fetch_array();
|
---|
37 | $Output .= '<div style="border: thin dotted #97ADFF; background: #F6F7FF; margin-top: 5px; padding: 0px 5px 5px 5px;"><div style="padding-bottom: 1px; border-bottom-width: 1; border-bottom-style: solid; border-bottom-color: silver;"><strong>'.$Row['title'].' ('.HumanDate($Row['date']).', '.$Row['Name'].$Row['author'].')</strong>';
|
---|
38 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
39 | {
|
---|
40 | $Output .= ' <a href="index.php?action=del&category='.$Category.'&id='.$Row['id'].'">Smazat</a>';
|
---|
41 | $Output .= ' <a href="index.php?action=edit&category='.$Category.'&id='.$Row['id'].'">Editovat</a>';
|
---|
42 | }
|
---|
43 | $Output .= '</div>'.$Row['content'].'<br />';
|
---|
44 | if($Row['enclosure'] != '')
|
---|
45 | {
|
---|
46 | $Output .= '<br />Přílohy: ';
|
---|
47 | $Enclosures = explode(';', $Row['enclosure']);
|
---|
48 | foreach($Enclosures as $Enclosure)
|
---|
49 | {
|
---|
50 | if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
|
---|
51 | }
|
---|
52 | }
|
---|
53 | $Output .= '</div>';
|
---|
54 | } else $Output .= 'Položka nenalezena.';
|
---|
55 | }
|
---|
56 | break;
|
---|
57 | case 'add':
|
---|
58 | $Output .= '<strong>Vložení nové aktuality:</strong><br />';
|
---|
59 | 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.';
|
---|
60 | $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
|
---|
61 | 'Kategorie: <select name="category">';
|
---|
62 | $DbResult = $this->Database->select('news_category', '*');
|
---|
63 | while($DbRow = $DbResult->fetch_array())
|
---|
64 | {
|
---|
65 | if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $DbRow['id']))
|
---|
66 | {
|
---|
67 | if($DbRow['id'] == $Category) $Selected = ' selected="1"'; else $Selected = '';
|
---|
68 | $Output .= '<option value="'.$DbRow['id'].'"'.$Selected.'>'.$DbRow['caption'].'</option>';
|
---|
69 | }
|
---|
70 | }
|
---|
71 | $Output .= '</select><br />'.
|
---|
72 | 'Nadpis:<br /><input type="text" size="54" name="title"><br />
|
---|
73 | Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />
|
---|
74 | Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">
|
---|
75 | <input name="enclosure1" size="38" type="file"><br />
|
---|
76 | <input name="enclosure2" size="38" type="file"><br />
|
---|
77 | <input name="enclosure3" size="38" type="file"><br />
|
---|
78 | <input type="submit" value="Vložit">
|
---|
79 | </form>';
|
---|
80 | break;
|
---|
81 | case 'add2':
|
---|
82 | $RemoteAddr = GetRemoteAddress();
|
---|
83 | if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $Category))
|
---|
84 | {
|
---|
85 | //print_r($_FILES);
|
---|
86 | // Process uploaded file
|
---|
87 | $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3');
|
---|
88 | $Enclosures = '';
|
---|
89 | foreach($EnclosureFileNames as $EnclosureName)
|
---|
90 | if(array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
|
---|
91 | {
|
---|
92 | $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
|
---|
93 | if(move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
|
---|
94 | {
|
---|
95 | $Output .= "Soubor ".basename($_FILES[$EnclosureName]['name'])." byl uložen na serveru.<br />";
|
---|
96 | $Enclosures = $Enclosures.';'.basename($_FILES[$EnclosureName]['name']);
|
---|
97 | } else
|
---|
98 | {
|
---|
99 | $Output .= "Soubor ".basename($_FILES[$EnclosureName]['name'])." se nepodařilo nahrát na server.<br />";
|
---|
100 | }
|
---|
101 | }
|
---|
102 | $Enclosures = substr($Enclosures, 1);
|
---|
103 |
|
---|
104 | $_POST['content'] = str_replace("\n",'<br />',$_POST['content']);
|
---|
105 | $this->Database->insert('news',array('category' => $Category, 'title' => $_POST['title'], 'content' => $_POST['content'], 'date' => 'NOW()', 'ip' => $RemoteAddr, 'enclosure' => $Enclosures, 'User' => $this->System->Modules['User']->User['Id']));
|
---|
106 | $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 />';
|
---|
107 | $Output .= '<a href="index.php?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
|
---|
108 | $this->System->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
|
---|
109 | } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
|
---|
110 | break;
|
---|
111 | case 'edit':
|
---|
112 | $DbResult = $this->Database->query('SELECT * FROM news WHERE id='.$_GET['id']);
|
---|
113 | $Row = $DbResult->fetch_array();
|
---|
114 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
115 | {
|
---|
116 | $Row['content'] = str_replace('<br />', "", $Row['content']);
|
---|
117 | $Output .= '<strong>Editace aktuality v kategorii '.$CategoryName.':</strong><br />';
|
---|
118 | $Output .= '<form action="index.php?action=update" method="post">'.
|
---|
119 | '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
|
---|
120 | 'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['title'].'"><br />'.
|
---|
121 | 'Obsah:<br /><textarea name="content" rows="20" cols="40">'.$Row['content'].'</textarea><br />'.
|
---|
122 | '<input type="hidden" name="category" value="'.$Category.'"><br />'.
|
---|
123 | '<input type="submit" value="Uložit">'.
|
---|
124 | '</form>';
|
---|
125 | } else $Output .= 'Nepovolená operace!';
|
---|
126 | break;
|
---|
127 | case 'update':
|
---|
128 | $RemoteAddr = GetRemoteAddress();
|
---|
129 | $_POST['id'] = $_POST['id'] * 1;
|
---|
130 | $DbResult = $this->Database->select('news', '*', 'id='.$_POST['id']);
|
---|
131 | if($DbResult->num_rows > 0)
|
---|
132 | {
|
---|
133 | $Row = $DbResult->fetch_array();
|
---|
134 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
135 | {
|
---|
136 | $_POST['content'] = str_replace("\n",'<br />',$_POST['content']);
|
---|
137 | $this->Database->update('news', 'id='.$_POST['id'], array('title' => $_POST['title'], 'content' => $_POST['content']));
|
---|
138 | $Output .= 'Aktualita uložena!<br />';
|
---|
139 | $Output .= '<a href="index.php?category='.$Category.'">Zpět na seznam aktualit</a>';
|
---|
140 | } else $Output .= 'Nelze měnit cizí aktualitu!<br />';
|
---|
141 | } else $Output .= 'ID nenalezeno!';
|
---|
142 | break;
|
---|
143 | case 'del':
|
---|
144 | $DbResult = $this->Database->query('SELECT * FROM news WHERE id='.$_GET['id']);
|
---|
145 | $Row = $DbResult->fetch_array();
|
---|
146 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
147 | {
|
---|
148 | if($Row['enclosure'] != '')
|
---|
149 | {
|
---|
150 | $Output .= '<br />Přílohy: ';
|
---|
151 | $Enclosures = explode(';', $Row['enclosure']);
|
---|
152 | foreach($Enclosures as $Enclosure)
|
---|
153 | {
|
---|
154 | if(file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
|
---|
155 | }
|
---|
156 | }
|
---|
157 | $this->Database->query('DELETE FROM news WHERE id='.$_GET['id']);
|
---|
158 | $Output .= 'Aktualita smazána!<br /><a href="index.php?category='.$Category.'">Zpět na seznam aktualit</a>';
|
---|
159 | } else $Output .= 'Nemáte oprávnění.';
|
---|
160 | break;
|
---|
161 | default:
|
---|
162 | if($this->System->Modules['User']->CheckPermission('News', 'Display', 'Group', $Category))
|
---|
163 | {
|
---|
164 | $PerPage = 20;
|
---|
165 | $DbResult = $this->Database->select('news', 'COUNT(*)', ' category='.$Category);
|
---|
166 | $RowTotal = $DbResult->fetch_array();
|
---|
167 | $PageMax = $RowTotal[0];
|
---|
168 | if(array_key_exists('page', $_GET)) $Page = $_GET['page']; else $Page = 0; //round($PageMax/$PerPage);
|
---|
169 | $Output .= '<strong>Seznam aktualit kategorie '.$CategoryName.':</strong><div style="font-size: small;">';
|
---|
170 | $Output .= PagesList('?category='.$Category.'&page=',$Page,$PageMax,$PerPage);
|
---|
171 |
|
---|
172 | //echo(GetRemoteAddress().','.$_SERVER['HTTP_X_FORWARDED_FOR'].'<br />');
|
---|
173 | $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);
|
---|
174 | while($Row = $DbResult->fetch_array())
|
---|
175 | {
|
---|
176 | $Output .= '<div style="border: thin dotted #97ADFF; background: #F6F7FF; margin-top: 5px; padding: 0px 5px 5px 5px;"><div style="padding-bottom: 1px; border-bottom-width: 1; border-bottom-style: solid; border-bottom-color: silver;"><strong><a href="?action=view&id='.$Row['id'].'">'.$Row['title'].'</a> ('.HumanDate($Row['date']).', '.$Row['Name'].$Row['author'].')</strong>';
|
---|
177 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
178 | {
|
---|
179 | $Output .= ' <a href="index.php?action=del&category='.$Category.'&id='.$Row['id'].'">Smazat</a>';
|
---|
180 | $Output .= ' <a href="index.php?action=edit&category='.$Category.'&id='.$Row['id'].'">Editovat</a>';
|
---|
181 | }
|
---|
182 | $Output .= '</div>'.$Row['content'].'<br />';
|
---|
183 | if($Row['enclosure'] != '')
|
---|
184 | {
|
---|
185 | $Output .= '<br />Přílohy: ';
|
---|
186 | $Enclosures = explode(';', $Row['enclosure']);
|
---|
187 | foreach($Enclosures as $Enclosure)
|
---|
188 | {
|
---|
189 | if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
|
---|
190 | }
|
---|
191 | }
|
---|
192 | $Output .= '</div>';
|
---|
193 | }
|
---|
194 | $Output .= PagesList('?category='.$Category.'&page=', $Page, $PageMax, $PerPage);
|
---|
195 | $Output .= '</div>';
|
---|
196 | } else $Output .= 'Nemáte oprávnění.';
|
---|
197 | }
|
---|
198 | return($Output);
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | $System->AddModule(new NewsPage());
|
---|
203 | $System->Modules['NewsPage']->GetOutput();
|
---|
204 |
|
---|
205 | ?>
|
---|