source: trunk/Modules/News/NewsPage.php@ 358

Last change on this file since 358 was 358, checked in by chronos, 13 years ago
  • Opraveno: Generovalo se na výstup chybně odřádkování před začátek dokumentu díky nadbytečnému odřádkování za ukončením php v souboru Meals.php. Pak nebylo možné generovat dynamicky obrázky.
  • Upraveno: Generování topologie přesunuto do systémového modulu NetworkTopology.
  • Property svn:executable set to *
File size: 17.2 KB
Line 
1<?php
2
3include_once('Common/rss_generator.php');
4
5class NewsPage extends Page
6{
7 var $FullTitle = 'Aktualní informace';
8 var $ShortTitle = 'Aktuality';
9 var $UploadedFilesFolder = 'uploads/';
10
11 function Show()
12 {
13 if(count($this->System->PathItems) > 1)
14 {
15 if($this->System->PathItems[1] == 'subscription') return($this->ShowSubscription());
16 else if($this->System->PathItems[1] == 'rss') return($this->ShowRSS());
17 else return(PAGE_NOT_FOUND);
18 } else return($this->ShowMain());
19 }
20
21 function ShowMain()
22 {
23 $Output = '';
24 $Category = 1;
25 $CategoryName = '';
26 if(array_key_exists('category', $_GET)) $Category = $_GET['category'] * 1;
27 if(array_key_exists('category', $_POST)) $Category = $_POST['category'] * 1;
28 $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$Category.' ORDER BY Sequence');
29 if($DbResult->num_rows > 0)
30 {
31 $Row = $DbResult->fetch_array();
32 $CategoryName = $Row['Caption'];
33 }
34
35 if(!array_key_exists('action',$_GET)) $_GET['action'] = '';
36 switch($_GET['action'])
37 {
38 case 'view':
39 if(!$this->System->Models['User']->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
40 else
41 {
42 $News = new News($this->Database, $this->System);
43 if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
44 $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id);
45 if($DbResult->num_rows > 0)
46 {
47 $Row = $DbResult->fetch_array();
48 if($Row['Name'] == '') $Author = $Row['Author'];
49 else $Author = $Row['Name'];
50 $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')';
51 if($this->System->Models['User']->User['Id'] == $Row['User'])
52 {
53 $Output .= '<div class="Action">';
54 $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
55 $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
56 $Output .= '</div>';
57 }
58 $Output .= '</div><div class="Content">'.$News->ModifyContent($Row['Content']).'<br />';
59 if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
60 if($Row['Enclosure'] != '')
61 {
62 $Output .= '<br />Přílohy: ';
63 $Enclosures = explode(';', $Row['Enclosure']);
64 foreach($Enclosures as $Enclosure)
65 {
66 if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
67 }
68 }
69 $Output .= '</div></div>';
70 } else $Output .= 'Položka nenalezena.';
71 }
72 break;
73 case 'add':
74 $Output .= '<strong>Vložení nové aktuality:</strong><br />';
75 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.';
76 $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
77 'Kategorie: <select name="category">';
78 $DbResult = $this->Database->select('NewsCategory', '*');
79 while($DbRow = $DbResult->fetch_array())
80 {
81 if($this->System->Models['User']->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
82 {
83 if($DbRow['Id'] == $Category) $Selected = ' selected="1"'; else $Selected = '';
84 $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>';
85 }
86 }
87 $Output .= '</select><br />'.
88 'Nadpis:<br /><input type="text" size="54" name="title"><br />
89 Obsah:<br /><textarea name="content" rows="20" cols="40"></textarea><br />
90 Odkaz:<br /><input type="text" size="54" name="link"><br />
91 Přílohy (Max. velikost souboru 1 MB):<br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">
92 <input name="enclosure1" size="38" type="file"><br />
93 <input name="enclosure2" size="38" type="file"><br />
94 <input name="enclosure3" size="38" type="file"><br />
95 <input type="submit" value="Vložit">
96 </form>';
97 break;
98 case 'add2':
99 $RemoteAddr = GetRemoteAddress();
100 if($this->System->Models['User']->CheckPermission('News', 'Insert', 'Group', $Category))
101 {
102 //print_r($_FILES);
103 // Process uploaded file
104 $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3');
105 $Enclosures = '';
106 foreach($EnclosureFileNames as $EnclosureName)
107 if(array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
108 {
109 $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
110 if(move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
111 {
112 $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.<br />';
113 $Enclosures = $Enclosures.';'.basename($_FILES[$EnclosureName]['name']);
114 } else
115 {
116 $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' se nepodařilo nahrát na server.<br />';
117 }
118 }
119 $Enclosures = substr($Enclosures, 1);
120
121 $_POST['content'] = str_replace("\n",'<br />',$_POST['content']);
122 $this->Database->insert('News', array('Category' => $Category, 'Title' => $_POST['title'], 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr, 'Enclosure' => $Enclosures, 'Author' => $this->System->Models['User']->User['Name'], 'User' => $this->System->Models['User']->User['Id'], 'Link' => $_POST['link']));
123 $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 />';
124 $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
125 $this->System->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
126 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
127 break;
128 case 'edit':
129 $DbResult = $this->Database->query('SELECT * FROM News WHERE Id='.$_GET['id']);
130 $Row = $DbResult->fetch_array();
131 if($this->System->Models['User']->User['Id'] == $Row['User'])
132 {
133 $Row['Content'] = str_replace('<br />', '', $Row['Content']);
134 $Output .= '<strong>Editace aktuality v kategorii '.$CategoryName.':</strong><br />';
135 $Output .= '<form action="?action=update" method="post">'.
136 '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
137 'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'.
138 'Obsah:<br /><textarea name="content" rows="20" cols="40">'.$Row['Content'].'</textarea><br />'.
139 'Odkaz:<br /><input type="text" size="54" name="link"><br />'.
140 '<input type="hidden" name="category" value="'.$Category.'"><br />'.
141 '<input type="submit" value="Uložit">'.
142 '</form>';
143 } else $Output .= 'Nepovolená operace!';
144 break;
145 case 'update':
146 $RemoteAddr = GetRemoteAddress();
147 $_POST['id'] = $_POST['id'] * 1;
148 $DbResult = $this->Database->select('News', '*', 'Id='.$_POST['id']);
149 if($DbResult->num_rows > 0)
150 {
151 $Row = $DbResult->fetch_array();
152 if($this->System->Models['User']->User['Id'] == $Row['User'])
153 {
154 $_POST['content'] = str_replace("\n", '<br />', $_POST['content']);
155 $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'], 'Content' => $_POST['content']));
156 $Output .= 'Aktualita uložena!<br />';
157 $Output .= '<a href="index.php?category='.$Category.'">Zpět na seznam aktualit</a>';
158 } else $Output .= 'Nelze měnit cizí aktualitu!<br />';
159 } else $Output .= 'ID nenalezeno!';
160 break;
161 case 'del':
162 $DbResult = $this->Database->query('SELECT * FROM News WHERE Id='.$_GET['id']);
163 $Row = $DbResult->fetch_array();
164 if($this->System->Models['User']->User['Id'] == $Row['User'])
165 {
166 if($Row['Enclosure'] != '')
167 {
168 $Output .= '<br />Přílohy: ';
169 $Enclosures = explode(';', $Row['Enclosure']);
170 foreach($Enclosures as $Enclosure)
171 {
172 if(file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
173 }
174 }
175 $this->Database->query('DELETE FROM News WHERE Id='.$_GET['id']);
176 $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category.'">Zpět na seznam aktualit</a>';
177 } else $Output .= 'Nemáte oprávnění.';
178 break;
179 default:
180 if($this->System->Models['User']->CheckPermission('News', 'Display', 'Group', $Category))
181 {
182 $News = new News($this->Database, $this->System);
183 $PerPage = 20;
184 $DbResult = $this->Database->select('News', 'COUNT(*)', ' Category='.$Category);
185 $RowTotal = $DbResult->fetch_array();
186 $PageMax = $RowTotal[0];
187 if(array_key_exists('page', $_GET)) $Page = $_GET['page'];
188 else $Page = 0; //round($PageMax/$PerPage);
189 $Output .= '<strong>Seznam aktualit kategorie '.$CategoryName.':</strong><div style="font-size: small;">';
190 $Output .= PagesList('?category='.$Category.'&amp;page=', $Page, $PageMax, $PerPage);
191
192 //echo(GetRemoteAddress().','.$_SERVER['HTTP_X_FORWARDED_FOR'].'<br />');
193 $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);
194 while($Row = $DbResult->fetch_array())
195 {
196 if($Row['Name'] == '') $Author = $Row['Author'];
197 else $Author = $Row['Name'];
198 $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&amp;id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')';
199 if($this->System->Models['User']->User['Id'] == $Row['User'])
200 {
201 $Output .= '<div class="Action">';
202 $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
203 $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
204 $Output .= '</div>';
205 }
206 $Output .= '</div><div class="Content">'.$News->ModifyContent($Row['Content']).'<br />';
207 if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
208 if($Row['Enclosure'] != '')
209 {
210 $Output .= '<br />Přílohy: ';
211 $Enclosures = explode(';', $Row['Enclosure']);
212 foreach($Enclosures as $Enclosure)
213 {
214 if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
215 }
216 }
217 $Output .= '</div></div>';
218 }
219 $Output .= PagesList('?category='.$Category.'&amp;page=', $Page, $PageMax, $PerPage);
220 $Output .= '</div>';
221 } else $Output .= 'Nemáte oprávnění.';
222 }
223 return($Output);
224 }
225
226 function ShowSubscription()
227 {
228 if(array_key_exists('build', $_GET))
229 {
230 $Select = '';
231 foreach($_POST as $Index => $Item)
232 {
233 if(substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);
234 }
235 $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1);
236 $Output = 'Výsledný RSS kanál: <a href="'.$Select.'">'.$Select.'</a>';
237 } else
238 {
239 $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ř. <a href="http://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />'.
240 '<br />Kategorie:<br />';
241 $Output .= '<form action="?build=1" method="post">';
242 $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Caption');
243 while($Category = $DbResult->fetch_array())
244 {
245 $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';
246 }
247 $Output.= '<input type="submit" value="Sestavit " />'.
248 '</form>';
249 }
250 return($Output);
251 }
252
253 function ShowRSS()
254 {
255 $this->SimplePage = true;
256 $this->FormatHTML = false;
257 Header('Content-Type: text/xml');
258
259 $NewsCount = 15;
260
261 $Items = array();
262 $Category = '';
263 $CategoryOption = '';
264 $CategoryOptionURL = '';
265 $CategoryName = '';
266
267 // Prepare WHERE condition
268 if(array_key_exists('select', $_GET))
269 {
270 $Where = '';
271 $Parts = explode('-', $_GET['select']);
272 foreach($Parts as $Part)
273 {
274 $Where .= 'OR (category='.($Part * 1).')';
275 }
276 $Where = substr($Where, 2);
277 } else $Where = 1;
278
279 // Get category names
280 $Categories = array();
281 $DbResult = $this->Database->select('NewsCategory', '*');
282 while($Category = $DbResult->fetch_array())
283 {
284 $Categories[$Category['Id']] = $Category['Caption'];
285 }
286
287 // Update news from discussion forum
288 /*
289 $ForumCategory = 4;
290 $Database->select_db('forum');
291 $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);
292 $Index = 0;
293 //echo(DB_NumRows().',');
294 while($Row = $DbResult->fetch_array())
295 {
296 $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
297 $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
298 $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
299 $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
300 $Index = $Index + 1;
301
302 $Title = $Row['topic_title'].'-'.$Row['post_subject'];
303 $Content = $Row['post_text'];
304 $Date = date('Y-m-d H:i:s', $Row['post_time']);
305 $Author = $Row['username'];
306 $Database->select_db('is');
307 //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
308 $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
309 if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
310 $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
311 //echo($Date);
312 $Database->select_db('forum');
313 }
314 $Database->select_db('is');
315 */
316
317 // Get news from database by selected categories
318 $UploadedFilesFolder = 'uploads/';
319 $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
320 while($Row = $DbResult->fetch_assoc())
321 {
322 $EnclosuresText = '';
323 if($Row['Enclosure'] != '')
324 {
325 $EnclosuresText .= '<br />Přílohy: ';
326 $Enclosures = explode(';', $Row['Enclosure']);
327 foreach($Enclosures as $Enclosure)
328 {
329 if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
330 }
331 }
332 if($Row['Name'] == '') $Author = $Row['Author'];
333 else $Author = $Row['Name'];
334 $Items[] = array(
335 'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
336 'Link' => 'http://'.$this->System->Config['Web']['Host'].'/aktuality/index.php?category='.$Row['Category'],
337 'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
338 'Time' => $Row['UNIX_TIMESTAMP(Date)'],
339 );
340 }
341
342 return(GenerateRSS(array(
343 'Title' => $this->System->Config['Web']['Title'].' - Aktuality',
344 'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
345 'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',
346 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
347 'Items' => $Items)));
348 }
349}
350
351?>
Note: See TracBrowser for help on using the repository browser.