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