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