-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.php
171 lines (125 loc) · 7.53 KB
/
remove.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!-- ******************************************************************* -->
<!-- PHP "self" code GET request for remove and POST delete data -->
<!-- ******************************************************************* -->
<!-- Vrsion: 1.0 Date: 27.9-3.10.2020 by CDesigner.eu -->
<!-- ******************************************************************* -->
<?php // leading part of page for simple header securing and basic variable setup
require_once('appvars.php'); // including variables for database
session_start(); // start the session - must be added on all pages for session variable accessing
// solution using SESSIONS with COOKIES for longer (30days) login persistency
if(!isset($_SESSION['users_id'])) { // if session is no more active
if(isset($_COOKIE['users_id']) && isset($_COOKIE['username'])) { // but cookie is set then renew session variables along them
$_SESSION['users_id'] = $_COOKIE['users_id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
// two variables for message and styling of the mesage with bootstrap
$msg = '';
$msgClass = '';
// default values of auxiliary variables
?>
<!-- ******************************************* -->
<!-- script for appropriate scode removal -->
<!-- ******************************************* -->
<!-- obtain GET data from admin.php and trough -->
<!-- POST submit remove data from database -->
<!-- ******************************************* -->
<!DOCTYPE html>
<html>
<head>
<title> Benchmark - admin </title>
<link rel="stylesheet" href="./css/bootstrap.min.css"> <!-- bootstrap mini.css file -->
<link rel="stylesheet" href="./css/style.css"> <!-- my local.css file -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar ">
<div class="container" id="header_container_580">
<div class="navbar-header" >
<?php
require_once('headerlogo.php');
?>
<a class="navbar-brand" href="admin.php">3dmark results chart v 1.0 - part for selected score removal</a>
<a class="navbar-brand" href="index.php"> --> return to main score page</a>
</div>
</div>
</nav>
<div class="container" id="formcontainer">
<?php if($msg != ''): ?> <!-- alert showing part -->
<div class="alert <?php echo $msgClass; ?>"><?php echo $msg; ?></div>
<?php endif; ?>
<br> <!-- logo on the center of the page -->
<h4>Confirmation of deletion selected score script.</h4>
<br>
<br> <!-- logo on the center of the page -->
<img id="calcimage" src="./images/admin.jpg" alt="Calc image" width="150" height="150">
<br>
<?php // code for GET info about what to remove and submit removing approval
if(isset($_GET['id']) && isset($_GET['score']) && isset($_GET['nickname']) && isset($_GET['write_date']) && isset($_GET['screenshot']) ){
// take a data from GET link generated by adminscript
$id = htmlspecialchars($_GET['id']);
$score = htmlspecialchars($_GET['score']);
$nickname = htmlspecialchars($_GET['nickname']);
$write_date = htmlspecialchars($_GET['write_date']);
$screenshot = htmlspecialchars($_GET['screenshot']);
} else if (isset($_POST['id']) && isset($_GET['score']) && isset($_GET['nickname'])) { //grab score from POST - different behavior for removal
$id = htmlspecialchars($_POST['id']);
$score = htmlspecialchars($_POST['score']);
$nickname = htmlspecialchars($_POST['nickname']);
} else { //error info message
echo '<p class="alert alert-danger"> Please specify any highscore for removal. </p>';
};
if(isset($_POST['submit'])){
if($_POST['confirm'] == 'Yes' ){ // delete appropriate score post with imagescreenshot
//delete the screenshotimage from the
$id = htmlspecialchars($_POST['id']);
$score = htmlspecialchars($_POST['score']);
$nickname = htmlspecialchars($_POST['nickname']);
$write_date = htmlspecialchars($_POST['write_date']);
$screenshot = htmlspecialchars($_POST['screenshot']);
@unlink(IMAGE_PATH . $screenshot);
// conect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME);
//Delete score data from the database
$sql = "DELETE FROM benchmark_chart WHERE id = $id LIMIT 1";
// execute SQL
mysqli_query($dbc, $sql);
// close database connection
mysqli_close($dbc);
// confirm executed command
echo '<p> The highscore of <strong>' . $score . '</strong> for <strong>' . $nickname . '</strong> was succesfully removed. </p>';
} else {
echo '<p class="alert alert-danger" > The highscore was not removed. </p>';
}
} else if (isset($id) && isset($nickname) && isset($write_date) && isset($score) && isset($screenshot)) {
echo '<h5>Are you sure to delete the next highscore? </h5>';
// show short describtion of score for deletion
echo '<p> <strong> ID: </strong> ' . $id . '<br> <strong> Nickname: </strong>' . $nickname .
'<br> <strong> Date: </strong>' . $write_date .
'<br> <strong> Score: </strong>' . $score .'</p>';
//show submited score image for deletion
$image_location = IMAGE_PATH.$screenshot; // supplementary construct of image path location
echo "<img src=\"$image_location\" alt=\" score image to delete \" height=\"95\">";
echo '<br><br>';
echo '<form method="POST" action="remove.php">'; //not self but direct this script remove.php - we dont want include any GET data tahat previously send
echo '<input type="radio" name="confirm" value="Yes" /> Yes ';
echo '<input type="radio" name="confirm" value="No" checked="checked" /> No <br><br>';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="nickname" value="'.$nickname.'" />';
echo '<input type="hidden" name="score" value="'.$score.'" />';
echo '<input type="hidden" name="screenshot" value="'.$screenshot.'" />';
echo '<input type="hidden" name="write_date" value="'.$write_date.'" />';
echo '<input type="submit" class="btn btn-danger" value="submit" name="submit" />';
echo '</form>';
};
echo '<br><br>';
echo '<p> <a href = "admin.php"> << Back to admin page. </a></p>';
?>
</div>
<?php // footer include code
require_once('footer.php'); // including footer
generate_footer(580); // function from footer.php for seting width, you can use 580 and 1060px width
?>
</body>
</html>