-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_submit.php
52 lines (40 loc) · 1.05 KB
/
remove_submit.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
<?php
require "includes/helper.php";
if(!isLogin()){
redirect("login");
}
if(!isAdmin()){
alert("you are not authorized");
redirect("index.php");
}
if(!isset($_GET["hash"])){
die();
}
$hash = $_GET["hash"];
if(!$db->numberOf("usr","hash",$hash)){
alert("user with hash ".$hash." does not exist");
die();
}
if(!$db->numberOf("submits","hash",$hash)){
alert("user with hash ".$hash." does not have submission yet!");
die();
}
$usr = $db->select("usr","hash",$hash);
$tables = ["submits","votes","publishing"];
foreach($tables as $table){
remove($table);
}
//
//$sql="DELETE FROM votes WHERE `voter_hash` = ".hash;
// $stmt = $conn->prepare($sql);
// $stmt->execute([]);
rmdir_recursive("uploads/".$hash);
alert("user ".$usr["username"]." with hash as ".$hash." successfully deleted");
function remove($table){
$db = $GLOBALS["db"];
$conn = $GLOBALS["conn"];
$hash = $GLOBALS["hash"];
$sql="DELETE FROM ".$table." WHERE `hash` = '".$hash."'";
$stmt = $conn->prepare($sql);
$stmt->execute([]);
}