forked from Schnurber/MyForum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminPage.php
63 lines (59 loc) · 1.72 KB
/
AdminPage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace MyForum;
/**
* Page to manage the threads
*/
final class AdminPage extends lib\HomePage {
use lib\DataBase;
/*
* Evaluate when reloading
*/
protected function init(){
$pre = self::prefix();
session_start();
$rows=self::query("select * from {$pre}threads");
$toDelete=[];//Leer
foreach ($rows as $row){
$id=$row['id'];
if (isset($_POST["del$id"])){//Eintrag Loeschen
error_log("ID:".$id);
array_push($toDelete,$id);
}
}
//Alle raus
foreach ($toDelete as $id) {
self::query("delete from {$pre}threads where ID = :id", array(':id' => $id));
//self::query("delete from tbl_beitraege where thread_ID = :id", array(':id' => $id));
/* Not necessary because of:
ALTER TABLE `tbl_beitraege`
ADD CONSTRAINT `tbl_beitraege_ibfk_1` FOREIGN KEY (`thread_ID`) REFERENCES `tbl_threads` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE;
*/
}
if (isset($_POST["newthread"])) { // New entry
$val=trim($_POST["newthread"]);
if ($val!="") {
self::query("insert into {$pre}threads values (NULL, :val)", array(':val' => $val));
}
}
}
/*
* Ausgabe
*/
protected function body(){
$pre = self::prefix();
$ret='';
if (!isset($_SESSION['loggedin'])) {
die ($this->render('admin.php', 'admin_die'));
}
$ret .= $this->render('admin.php', 'admin_subnav');
$rows=self::query("select * from {$pre}threads");
$ret .= $this->render('admin.php', 'table_head');
foreach ($rows as $row) {
$ret .= $this->render('admin.php', 'table_row', array('title' => $row['name'], 'name' => 'del'.$row['id'], 'id' => $row['id']));
}
$ret .= $this->render('admin.php', 'table_end');
return $ret;
}
}
?>