Changeset 873 for trunk/Modules/News/NewsPage.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/NewsPage.php
r839 r873 11 11 { 12 12 $this->UploadedFilesFolder = $this->System->ModuleManager->Modules['News']->UploadedFilesFolder; 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());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 19 } 20 20 … … 22 22 { 23 23 $Output = ''; 24 if (!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';24 if (!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění'; 25 25 else 26 26 { 27 27 $Category = $this->GetCategory(); 28 if (array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;28 if (array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1; 29 29 $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '. 30 30 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id); 31 if ($DbResult->num_rows > 0)31 if ($DbResult->num_rows > 0) 32 32 { 33 33 $Row = $DbResult->fetch_array(); 34 if ($Row['Name'] == '') $Author = $Row['Author'];34 if ($Row['Name'] == '') $Author = $Row['Author']; 35 35 else $Author = $Row['Name']; 36 36 $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')'; 37 if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))37 if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) 38 38 { 39 39 $Output .= '<div class="Action">'; … … 43 43 } 44 44 $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />'; 45 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';46 if ($Row['Enclosure'] != '')45 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>'; 46 if ($Row['Enclosure'] != '') 47 47 { 48 48 $Output .= '<br />Přílohy: '; 49 49 $Enclosures = explode(';', $Row['Enclosure']); 50 foreach ($Enclosures as $Enclosure)50 foreach ($Enclosures as $Enclosure) 51 51 { 52 if (file_exists($this->UploadedFilesFolder.$Enclosure))52 if (file_exists($this->UploadedFilesFolder.$Enclosure)) 53 53 $Output .= ' <a href="'.$this->System->Link('/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 54 54 } … … 57 57 } else $Output .= 'Položka nenalezena.'; 58 58 } 59 return ($Output);59 return ($Output); 60 60 } 61 61 … … 64 64 $Output = ''; 65 65 $Category = $this->GetCategory(); 66 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))66 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 67 67 { 68 68 $this->System->PageHeaders[] = array($this, 'GetPageHeader'); 69 69 $Output = '<strong>Vložení nové aktuality:</strong><br />'; 70 70 // TODO: Static reference to dynamic category item 71 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.';71 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.'; 72 72 $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'. 73 73 'Kategorie: <select name="category">'; 74 74 $DbResult = $this->Database->select('NewsCategory', '*'); 75 while ($DbRow = $DbResult->fetch_array())76 { 77 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))78 { 79 if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';75 while ($DbRow = $DbResult->fetch_array()) 76 { 77 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id'])) 78 { 79 if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"'; 80 80 else $Selected = ''; 81 81 $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>'; … … 93 93 '</form>'; 94 94 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 95 return ($Output);95 return ($Output); 96 96 } 97 97 … … 101 101 $RemoteAddr = GetRemoteAddress(); 102 102 $Category = $this->GetCategory(); 103 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))103 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 104 104 { 105 105 // Process uploaded file … … 107 107 $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3'); 108 108 $Enclosures = ''; 109 foreach ($EnclosureFileNames as $EnclosureName)110 if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))109 foreach ($EnclosureFileNames as $EnclosureName) 110 if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != '')) 111 111 { 112 112 $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']); 113 if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))113 if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath)) 114 114 { 115 115 $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.<br />'; … … 130 130 $this->System->ModuleManager->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id); 131 131 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 132 return ($Output);132 return ($Output); 133 133 } 134 134 135 135 function GetPageHeader() 136 136 { 137 return ('<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'.137 return ('<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'. 138 138 "<script>tinymce.init({ 139 139 selector: 'textarea', … … 156 156 $Output = ''; 157 157 $Category = $this->GetCategory(); 158 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))158 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 159 159 { 160 160 $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']); 161 161 $Row = $DbResult->fetch_array(); 162 if (($this->System->User->User['Id'] == $Row['User']))162 if (($this->System->User->User['Id'] == $Row['User'])) 163 163 { 164 164 $this->System->PageHeaders[] = array($this, 'GetPageHeader'); … … 174 174 } else $Output .= 'Nepovolená operace!'; 175 175 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 176 return ($Output);176 return ($Output); 177 177 } 178 178 … … 182 182 $RemoteAddr = GetRemoteAddress(); 183 183 $Category = $this->GetCategory(); 184 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))184 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 185 185 { 186 186 $_POST['id'] = $_POST['id'] * 1; 187 187 $DbResult = $this->Database->select('News', '*', '`Id`='.$_POST['id']); 188 if ($DbResult->num_rows > 0)188 if ($DbResult->num_rows > 0) 189 189 { 190 190 $Row = $DbResult->fetch_array(); 191 if ($this->System->User->User['Id'] == $Row['User'])191 if ($this->System->User->User['Id'] == $Row['User']) 192 192 { 193 193 $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'], … … 198 198 } else $Output .= 'ID nenalezeno!'; 199 199 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 200 return ($Output);200 return ($Output); 201 201 } 202 202 … … 205 205 $Output = ''; 206 206 $Category = $this->GetCategory(); 207 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))207 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 208 208 { 209 209 $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']); 210 210 $Row = $DbResult->fetch_array(); 211 if ($this->System->User->User['Id'] == $Row['User'])211 if ($this->System->User->User['Id'] == $Row['User']) 212 212 { 213 213 // TODO: Make upload using general File class 214 if ($Row['Enclosure'] != '')214 if ($Row['Enclosure'] != '') 215 215 { 216 216 $Output .= '<br />Přílohy: '; 217 217 $Enclosures = explode(';', $Row['Enclosure']); 218 foreach ($Enclosures as $Enclosure)218 foreach ($Enclosures as $Enclosure) 219 219 { 220 if (file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);220 if (file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure); 221 221 } 222 222 } … … 225 225 } else $Output .= 'Nemáte oprávnění.'; 226 226 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 227 return ($Output);227 return ($Output); 228 228 } 229 229 … … 232 232 $Output = ''; 233 233 $Category = $this->GetCategory(); 234 if ($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id']))234 if ($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id'])) 235 235 { 236 236 $PerPage = 20; … … 238 238 $RowTotal = $DbResult->fetch_array(); 239 239 $PageMax = $RowTotal[0]; 240 if (array_key_exists('page', $_GET)) $Page = $_GET['page'];240 if (array_key_exists('page', $_GET)) $Page = $_GET['page']; 241 241 else $Page = 0; //round($PageMax/$PerPage); 242 242 $Output .= '<strong>Seznam aktualit kategorie '.$Category['Caption'].':</strong><div style="font-size: small;">'; … … 245 245 $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '. 246 246 'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `Category`='.$Category['Id'].' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage); 247 while ($Row = $DbResult->fetch_array())248 { 249 if ($Row['Name'] == '') $Author = $Row['Author'];247 while ($Row = $DbResult->fetch_array()) 248 { 249 if ($Row['Name'] == '') $Author = $Row['Author']; 250 250 else $Author = $Row['Name']; 251 251 $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')'; 252 if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))252 if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) 253 253 { 254 254 $Output .= '<div class="Action">'; … … 258 258 } 259 259 $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />'; 260 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';261 if ($Row['Enclosure'] != '')260 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>'; 261 if ($Row['Enclosure'] != '') 262 262 { 263 263 $Output .= '<br />Přílohy: '; 264 264 $Enclosures = explode(';', $Row['Enclosure']); 265 foreach ($Enclosures as $Enclosure)265 foreach ($Enclosures as $Enclosure) 266 266 { 267 if (file_exists($this->UploadedFilesFolder.$Enclosure))267 if (file_exists($this->UploadedFilesFolder.$Enclosure)) 268 268 $Output .= ' <a href="'.$this->System->Link('/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 269 269 } … … 274 274 $Output .= '</div>'; 275 275 } else $Output .= 'Nemáte oprávnění.'; 276 return ($Output);276 return ($Output); 277 277 } 278 278 … … 280 280 { 281 281 $Category = array('Id' => 1); // Default category 282 if (array_key_exists('category', $_GET)) $Category['Id'] = $_GET['category'] * 1;283 if (array_key_exists('category', $_POST)) $Category['Id'] = $_POST['category'] * 1;284 //if (is_null($Category)) throw new Exception('Kategorie neurčena');282 if (array_key_exists('category', $_GET)) $Category['Id'] = $_GET['category'] * 1; 283 if (array_key_exists('category', $_POST)) $Category['Id'] = $_POST['category'] * 1; 284 //if (is_null($Category)) throw new Exception('Kategorie neurčena'); 285 285 else 286 286 { 287 287 $DbResult = $this->Database->select('NewsCategory', '*', '`Id`='.$Category['Id'].' ORDER BY `Sequence`'); 288 if ($DbResult->num_rows > 0) $Category = $DbResult->fetch_array();288 if ($DbResult->num_rows > 0) $Category = $DbResult->fetch_array(); 289 289 else $Category = array('Id' => 0); //throw new Exception('Kategorie nenalezena'); 290 290 } 291 return ($Category);291 return ($Category); 292 292 } 293 293 … … 295 295 { 296 296 $Output = ''; 297 if (array_key_exists('action',$_GET)) $Action = $_GET['action'];297 if (array_key_exists('action',$_GET)) $Action = $_GET['action']; 298 298 else $Action = ''; 299 if ($Action == 'view') $Output .= $this->ShowView();300 else if ($Action == 'add') $Output .= $this->ShowAdd();301 else if ($Action == 'add2') $Output .= $this->ShowAdd2();302 else if ($Action == 'edit') $Output .= $this->ShowEdit();303 else if ($Action == 'update') $Output .= $this->ShowUpdate();304 else if ($Action == 'del') $Output .= $this->ShowDelete();299 if ($Action == 'view') $Output .= $this->ShowView(); 300 else if ($Action == 'add') $Output .= $this->ShowAdd(); 301 else if ($Action == 'add2') $Output .= $this->ShowAdd2(); 302 else if ($Action == 'edit') $Output .= $this->ShowEdit(); 303 else if ($Action == 'update') $Output .= $this->ShowUpdate(); 304 else if ($Action == 'del') $Output .= $this->ShowDelete(); 305 305 else $Output .= $this->ShowList(); 306 return ($Output);306 return ($Output); 307 307 } 308 308 309 309 function ShowSubscription() 310 310 { 311 if (array_key_exists('build', $_GET))311 if (array_key_exists('build', $_GET)) 312 312 { 313 313 $Select = ''; 314 foreach ($_POST as $Index => $Item)315 { 316 if (substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);314 foreach ($_POST as $Index => $Item) 315 { 316 if (substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8); 317 317 } 318 318 $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1); … … 324 324 $Output .= '<form action="?build=1" method="post">'; 325 325 $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY `Caption`'); 326 while ($Category = $DbResult->fetch_array())326 while ($Category = $DbResult->fetch_array()) 327 327 { 328 328 $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />'; … … 331 331 '</form>'; 332 332 } 333 return ($Output);333 return ($Output); 334 334 } 335 335 … … 349 349 350 350 // Prepare WHERE condition 351 if (array_key_exists('select', $_GET))351 if (array_key_exists('select', $_GET)) 352 352 { 353 353 $Where = ''; 354 354 $Parts = explode('-', $_GET['select']); 355 foreach ($Parts as $Part)355 foreach ($Parts as $Part) 356 356 { 357 357 $Where .= 'OR (`Category`='.($Part * 1).')'; … … 363 363 $Categories = array(); 364 364 $DbResult = $this->Database->select('NewsCategory', '*'); 365 while ($Category = $DbResult->fetch_array())365 while ($Category = $DbResult->fetch_array()) 366 366 { 367 367 $Categories[$Category['Id']] = $Category['Caption']; … … 375 375 $Index = 0; 376 376 //echo(DB_NumRows().','); 377 while ($Row = $DbResult->fetch_array())377 while ($Row = $DbResult->fetch_array()) 378 378 { 379 379 $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); … … 390 390 //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); 391 391 $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); 392 if ($DbResult2->num_rows == 0) //echo('.'); else echo('x');392 if ($DbResult2->num_rows == 0) //echo('.'); else echo('x'); 393 393 $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date)); 394 394 //echo($Date); … … 400 400 // Get news from database by selected categories 401 401 $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(`Date`) AS `UnixTime` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount); 402 while ($Row = $DbResult->fetch_assoc())402 while ($Row = $DbResult->fetch_assoc()) 403 403 { 404 404 $EnclosuresText = ''; 405 if ($Row['Enclosure'] != '')405 if ($Row['Enclosure'] != '') 406 406 { 407 407 $EnclosuresText .= '<br />Přílohy: '; 408 408 $Enclosures = explode(';', $Row['Enclosure']); 409 foreach ($Enclosures as $Enclosure)410 { 411 if (file_exists($this->UploadedFilesFolder.$Enclosure))409 foreach ($Enclosures as $Enclosure) 410 { 411 if (file_exists($this->UploadedFilesFolder.$Enclosure)) 412 412 $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 413 413 } 414 414 } 415 if ($Row['Name'] == '') $Author = $Row['Author'];415 if ($Row['Name'] == '') $Author = $Row['Author']; 416 416 else $Author = $Row['Name']; 417 417 $Items[] = array( … … 429 429 $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail']; 430 430 $RSS->Items = $Items; 431 return ($RSS->Generate());431 return ($RSS->Generate()); 432 432 } 433 433 }
Note:
See TracChangeset
for help on using the changeset viewer.