-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_wish.php
129 lines (114 loc) · 3.19 KB
/
delete_wish.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
<?php
session_start();
require_once(__DIR__ . "/global.php");
HtmlHeader("delete");
if (empty($_SESSION['IsLogged']) || $_SESSION['IsLogged'] != "online")
{
echo "<a>you have to be logged in.</a>";
echo "<input type=\"button\" value=\"Login\" onclick=\"window.location.href='login.php'\"/>";
fok();
}
$db = new PDO(DATABASE_PATH);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$stmt = $db->prepare('SELECT * FROM Accounts WHERE Username = ?');
$stmt->execute(array($_SESSION['Username']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
//SQL checks
$state = $rows[0]['STATE'];
$missionID = $rows[0]['missionID'];
if ($state == 1) //currently on mission --> send the user to mission state
{
header("Location: complete.php?id=$missionID");
}
}
function print_html_main($message)
{
echo
"
<h2> Delete wish </h2>
<a>$message</a>
<form>
<input type=\"button\" value=\"Okay\" onclick=\"window.location.href='index.php'\" />
</form>
";
}
$wish_id = 0; //sql ids start with 1 so it doesnt show shit here
if (!empty($_GET['id']))
{
$wish_id = $_GET['id'];
}
else
{
print_html_main("<font color=\"red\">Invalid wish id</font>");
fok();
}
$db = new PDO(DATABASE_PATH);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$stmt = $db->prepare('SELECT * FROM Wishes WHERE ID = ?');
$stmt->execute(array($wish_id));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
$wisher = $rows[0]['wisher'];
$title = $rows[0]['wish_name'];
$state = $rows[0]['wish_STATE'];
$reward = $rows[0]['wish_reward'];
$description = $rows[0]['wish_desc'];
$fullfiller = $rows[0]['wish_fullfiller'];
if ($wisher == $_SESSION['Username'])
{
if ($fullfiller != "")
{
//print_html_main("<font color=\"red\">Error '$fullfiller' is currently working on that wish</font>");
print_html_main("<font color=\"red\">Error someone is working on that wish already</font>");
fok();
}
if ($state == 3)
{
print_html_main("<font color=\"red\">Error this wish is deleted already (state=$state)</font>");
fok();
}
//DELETE WISH
/*
$db = new PDO(DATABASE_PATH);
$stmt = $db->prepare('UPDATE Wishes SET wish_STATE = 3 WHERE ID = ?');
$stmt->execute(array($wish_id));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
*/
if (DeleteWish($wish_id, "deleted by wisher") == -1)
{
print_html_main("<font color=\"red\">Failed to delete the wish</font>");
fok();
}
//GIVE POINTS
/*
$db = new PDO(DATABASE_PATH);
$stmt = $db->prepare('UPDATE Accounts SET Points = Points + ? WHERE Username = ?');
$stmt->execute(array($reward, $wisher));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
print_html_main("<font color=\"red\">Failed to give points back</font>");
fok();
}
*/
$send_reason = "deleted wish '$title'";
SendPoints($_SESSION['Username'], "SERVER", $reward, $send_reason);
print_html_main("Successfully deleted the wish '$title'</br> + $reward points");
fok();
}
else
{
print_html_main("<font color=\"red\">You can only delete your own wishes</font>");
fok();
}
}
else
{
print_html_main("<font color=\"red\">Something went wrong</font>");
fok();
}
fok();
?>