-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
170 lines (144 loc) · 4.5 KB
/
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
session_start();
$ajans = $_GET["ajans"] ?? null;
$ceos = json_decode(file_get_contents("private/ceos.json"), true);
if (!isset($_SESSION["user"])) {
header("Location: /dc.php");
die("giriş yapmamışsın");
}
if ($ajans == null) {
header("Location: /?toast=ajansyok");
die("ajans yok");
}
if (!isset($ceos[$ajans])) {
header("Location: /?toast=ajansyok");
die("ajans yok");
}
if (!in_array($_SESSION["user"], $ceos[$ajans])) {
header("Location: /?toast=forbidden");
die("bu ajansın ceosu değilsin");
}
$jsonData = file_get_contents("data/$ajans.json");
$data = json_decode($jsonData, true);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data["sunucu_uyesayisi"] = intval($_POST["uyeler"]);
foreach ($_POST['oylar'] as $candidate => $votes) {
$data['oylar'][$candidate] = intval($votes);
}
$jsonData = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents("data/$ajans.json", $jsonData);
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gamer</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<!-- Toastr library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<!-- Toastr styles -->
<script>
$(document).ready(function () {
$('form').on('submit', function (event) {
event.preventDefault();
var formData = $(this).serialize();
$.ajax({
url: '<?php echo $_SERVER['PHP_SELF']; ?>?ajans=<?php echo $ajans; ?>',
type: 'POST',
data: formData,
success: function (response) {
toastr.success('Changes saved successfully');
console.log(response);
},
error: function (err) {
toastr.error('An error occurred');
console.log(err);
}
});
});
});
</script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}
h1 {
color: #333;
}
form {
max-width: 500px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"] {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border-radius: 4px;
border: 1px solid #ccc;
}
button[type="submit"] {
display: block;
width: 100%;
padding: 10px;
margin-top: 10px;
color: #fff;
background-color: #4caf50;
border: none;
border-radius: 4px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #45a049;
}
#toast-container {
position: fixed;
top: 0;
right: 0;
width: 300px;
z-index: 9999;
}
</style>
</head>
<body>
<a href="/">geri</a>
<h1>GAMER SİSTEMİ -
<?= $ajans ?>
</h1>
<form>
<label for="uyeler">Oy Kullanacak Üye Sayısı:</label>
<input type="text" name="uyeler" id="uyeler" value="<?= $data["sunucu_uyesayisi"] ?>">
<label for="oylar">Oylar:</label><br>
<?php foreach ($data['oylar'] as $candidate => $votes): ?>
<label for="oylar[<?php echo $candidate; ?>]">
<?php echo $candidate; ?>:
</label>
<input type="text" name="oylar[<?php echo $candidate; ?>]" value="<?php echo $votes; ?>"><br>
<?php endforeach; ?>
<button type="submit">Save Changes</button>
</form>
<script>
toastr.options = {
closeButton: true,
progressBar: true,
positionClass: 'toast-top-right',
timeOut: 3000
};
</script>
</body>
</html>