-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdminPage.php
65 lines (61 loc) · 1.7 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
64
65
<?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");
$rows = self::select(from: '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::delete(from: 'threads', where: 'id', value: $id);
// self::delete(from: 'threads', where: 'thread_ID', value: $id);
// Not necessary because of:
/*
ALTER TABLE `tbl_posts`
ADD CONSTRAINT `tbl_posts_ibfk_1` FOREIGN KEY (`thread_ID`) REFERENCES `tbl_threads` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE;
*/
}
if (isset($_POST["newthread"])) { // New entry
$val = trim(htmlspecialchars($_POST["newthread"]));
if ($val != "") {
self::insert('threads', array($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;
}
}
?>