-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.admin.php
150 lines (135 loc) · 5.64 KB
/
report.admin.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
class adminModule {
public $banned_user_lvl = 4;
public function method_reports() {
$ReportsQ = $this->db->prepare("SELECT * FROM `user_reports` ORDER BY `UR_id` DESC ;");
$ReportsQ->execute();
$Reports=[];
foreach($ReportsQ->fetchAll(PDO::FETCH_ASSOC) as $data){
$reasonsQ = $this->db->prepare("SELECT * FROM `user_reports_reasons` WHERE `URR_id`= :id;");
$reasonsQ->bindParam(':id', $data['UR_report_reason']);
$reasonsQ->execute();
$reason = $reasonsQ->fetch(PDO::FETCH_ASSOC);
$user = new User($data['UR_reported_user']);
$by = new User($data['UR_reported_by']);
$Reports[] = [
'id'=> $data['UR_id'],
'user'=> $user->user,
'by'=> $by->user,
'text'=> $data['UR_report_text'],
'reason'=> $reason["URR_name"],
];
}
$output = array(
"Reports" => $Reports,
);
$this->html .= $this->page->buildElement("reportList", $output);
}
public function method_ban () {
$this->methodData->id = (int) abs(intval($this->methodData->id));
if (!isset($this->methodData->id) || $this->methodData->id < 1) {
return $this->html = $this->page->buildElement("error", array(
"text" => "No ID specified!"
));
}
$exist = $this->db->prepare("SELECT * FROM `user_reports` WHERE `UR_id` = :id LIMIT 1 ;");
$exist->bindParam(':id', $this->methodData->id);
$exist->execute();
if (!$exist->rowCount()) {
return $this->html .= $this->page->buildElement("error", array(
"text" => "This Report does not exist!"
));
}
$data = $exist->fetch(PDO::FETCH_ASSOC);
$u = new User($data['UR_reported_user']);
if (isset($this->methodData->commit)) {
if ($u->info->U_id == $this->user->info->U_id) {
## not sure what to do here what ur input in this?
// $delete = $this->db->prepare("DELETE FROM `user_reports` WHERE `UR_id` = :id;");
// $delete->bindParam(":id", $this->methodData->id);
// $delete->execute();
return $this->html = $this->page->buildElement("error", array(
"text" => "You cant ban your self!"
));
}
if (!isset($u->info->U_id)) {
return $this->html = $this->page->buildElement("error", array(
"text" => "This user does not exist!"
));
}
if ($u->info->U_userLevel == $this->banned_user_lvl) {
return $this->html = $this->page->buildElement("error", array(
"text" => "This user is already banned!"
));
}
$u->set("U_userLevel", $this->banned_user_lvl);
$delete = $this->db->prepare("DELETE FROM `user_reports` WHERE `UR_id` = :id;");
$delete->bindParam(":id", $this->methodData->id);
$delete->execute();
return $this->html = $this->page->buildElement("success", array(
"text" => "This user <b>\"". $u->info->U_name ."\"</b> is now banned!"
));
}
$output['id'] = $this->methodData->id;
$output['user'] = $u->user;
$this->html .= $this->page->buildElement("userBan", $output);
}
public function method_Reasons() {
if (isset($this->methodData->submit)) {
if(!empty($this->methodData->name)){
$exist = $this->db->prepare("SELECT * FROM `user_reports_reasons` WHERE `URR_name` = :name LIMIT 1 ;");
$exist->bindParam(':name', $this->methodData->name);
$exist->execute();
if ($exist->rowCount()>0) {
$this->html .= $this->page->buildElement("error", array(
"text" => "This reason <b>\"".$this->methodData->name."\"</b> exist already!"
));
}else{
$insert = $this->db->prepare("INSERT INTO `user_reports_reasons` (URR_name) VALUES (:name);");
$insert->bindParam(":name", $this->methodData->name);
$insert->execute();
$this->html .= $this->page->buildElement("success", array(
"text" => "This Report reason has been created!"
));
}
}
}
$reasonsQ = $this->db->prepare("SELECT * FROM `user_reports_reasons` order by `URR_id` ASC;");
$reasonsQ->execute();
foreach($reasonsQ->fetchAll(PDO::FETCH_ASSOC) as $data){
$Reasons[] = [
'id'=> $data['URR_id'],
'name'=> $data['URR_name'],
];
}
$output = array(
"Reasons" => $Reasons,
);
$this->html .= $this->page->buildElement("reasonsList", $output);
}
public function method_deleteReason () {
if (!isset($this->methodData->id) || $this->methodData->id < 1) {
return $this->html = $this->page->buildElement("error", array(
"text" => "No ID specified"
));
}
$exist = $this->db->prepare("SELECT * FROM `user_reports_reasons` WHERE `URR_id` = :id LIMIT 1 ;");
$exist->bindParam(':id', $this->methodData->id);
$exist->execute();
$data = $exist->fetch(PDO::FETCH_ASSOC);
$output['name'] = $data['URR_name'];
$output['id'] = $data['URR_id'];
if (!$exist->rowCount()>0) {
return $this->html = $this->page->buildElement("error", array(
"text" => "This Report Reason does not exist"
));
}
if (isset($this->methodData->commit)) {
$delete = $this->db->prepare("DELETE FROM `user_reports_reasons` WHERE `URR_id` = :id;");
$delete->bindParam(":id", $this->methodData->id);
$delete->execute();
header("Location: ?page=admin&module=report&action=Reasons");
}
$this->html .= $this->page->buildElement("reasonDelete", $output);
}
}