-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsubmit-approve.php
More file actions
129 lines (74 loc) · 2.45 KB
/
submit-approve.php
File metadata and controls
129 lines (74 loc) · 2.45 KB
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
//ob_start();
session_start();
// If User is logged => redirect to tavern.php and announce it
if ( !isset($_SESSION['user']) ) {
$_SESSION['logged'] = 1;
header("Location: tavern.php");
echo "<meta http-equiv='refresh' content='0; url=tavern.php'>";
exit;
}
require_once 'inc.php';
// ------------------------------
// Start of Page with some functions
html_head("Approval Submit of Challenge");
navbar('bgimg_index_logged');
pageFade();
HelpButton();
$id = $_POST['challenge'];
$user = $_POST['user'];
if(($id != "") || ($id != 0)) {
$conn = connect_db();
$sql = "SELECT * FROM challenges WHERE id_challenge=". $id;
$res = mysqli_query($conn, $sql);
$challengeRow = mysqli_fetch_array($res, MYSQLI_ASSOC);
mysqli_close($conn);
$date_end = date_create(date('Y-m-d H:i:s', strtotime($challengeRow['date_end'])));
$date_start = date_create(date('Y-m-d H:i:s', strtotime($challengeRow['date_set'])));
$date_now = date_create(date('Y-m-d H:i:s', strtotime("now")));
if(($date_end < $date_now) || ($date_start > $date_now)) die();
$conn = connect_db();
$sql = "SELECT * FROM profiles WHERE id_user=". $user;
$res = mysqli_query($conn, $sql);
$profileRow = mysqli_fetch_array($res, MYSQLI_ASSOC);
mysqli_close($conn);
$exp = $challengeRow['r_exp'] + $profileRow['exp'];
$money = $challengeRow['r_money'] + $profileRow['money'];
$now = date("Y-m-d");
$conn = connect_db();
$sql = "UPDATE userchallenges SET state=2, date_completed='". $now ."' WHERE id_challenge=". $id;
$res_uch = mysqli_query($conn, $sql);
$sql = "UPDATE profiles SET exp=". $exp .", money=". $money ." WHERE id_user=". $user;
$res_p = mysqli_query($conn, $sql);
if ($res_uch && $res_p) {
echo '
<script>
swal({
title: "Successfully approved!!",
text: "Challenge Submission has been approved without any problem!",
type: "success",
showConfirmButton: false,
timer: 1990
});
</script>';
$sql = "INSERT INTO notifications (id_user, id_challenge, decision) VALUES ('". $user ."', '". $id ."', 1)";
$res_n = mysqli_query($conn, $sql);
echo "<meta http-equiv='refresh' content='2; url=submissions.php'>";
} else mysqli_error($conn);
} else {
echo '
<script>
swal({
title: "No challenge on route!!",
text: "You will be redirected to the Public Challenges!",
type: "warning",
showConfirmButton: false,
timer: 1990
});
</script>';
echo "<meta http-equiv='refresh' content='2; url=submissions.php'>";
}
mysqli_close($conn);
echo "</body>
</html>";
?>