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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
<?php
include("config/parametres.php");
include("includes/sessions.php");
include("includes/functions.php");
// if user's ROLE is less then ADMIN : then go to Login | Panel
// -----------------------------------------------------------------------------
if (ROLE < ADMIN) {
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: /");
die();
}
// get records
// -----------------------------------------------------------------------------
$users = array();
// init database connection
$_dbc = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DBMS);
if ($_dbc->connect_errno) {
echo "Database connection failed; Please try in a few minutes. ";
if (TESTING) echo $_dbc->connect_error;
$_dbc->close(); die();
}
$_dbc->set_charset("utf8");
// prepare statemet
$_stm = $_dbc->prepare("SELECT realname, user_id, `user`, role, birthstamp FROM users");
$_stm->execute(); // execute query
$_stm->store_result(); // store result
if ($_stm->num_rows) {
$_stm->bind_result($name, $uid, $email, $role, $tm); // bind result variables
while ($_stm->fetch()) {
$users[] = array(
'uid' => $uid,
'name' => $name,
'email' => $email,
'role' => USER_ROLES[$role],
'birth' => local_dt($tm)
);
}
}
else {
return array('success' => false, 'data' => "No items found"); // return error(s)
}
$_stm->close(); // close statement
$_dbc->close(); // close connection
?><!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB" dir="ltr">
<head>
<!-- Metas + Title -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?=PROJECT?> : Διαχείριση Χρηστών'</title>
<!-- CSS needed -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu:400,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/css/bootstrap.min.css" /><!-- v4.4.1 -->
<link rel="stylesheet" href="/css/select2.min.css" /><!-- v4.0.10 -->
<link rel="stylesheet" href="/css/pi.css" />
</head>
<body>
<?php // Menu ----------------------------------------------------------------
include("includes/menu.php");
?>
<div class="profile-container">
<div class="row">
<div class="col-md-12">
<h2>Διαχείριση Χρηστών</h2>
<h4>Χρήστες</h4>
<hr />
<?php foreach ($users as $key => $user): ?>
<div class="user-list">
<div>
<strong><?=$user['name']?> : </strong> <?=$user['role']?><br />
<?=$user['email']?><br />
<span class="light-text">* <?=$user['birth']?></span>
<span class="pi-action"><a class="btn btn-pi-light" href="#">Reset password</a></span>
<span class="pi-action"><a class="btn btn-pi-light" href="#">Επεξεργασία</a></span>
</div>
</div>
<hr />
<?php endforeach; ?>
<div class="some-form">
<p>
<a class="btn btn-pi-light" data-toggle="collapse" href="#collapse-pass" role="button">Δημιουργία νέου χρήστη</a>
</p>
<div class="collapse" id="collapse-pass">
<div class="card card-body">
<form id="change-pass" method="post" action="#">
<div class="form-group">
<label for="name">Ονοματεπώνυμο χρήστη</label>
<input class="form-control" type="password" name="name" disabled>
</div>
<div class="form-group">
<label for="name">Ρόλος</label>
<select class="form-control" name="role">
<option>Καταχωρητής / Διορθωτής</option>
<option>Επόπτης</option>
<option>Διαχειριστής</option>
<?php if(ROLE == SYSADMIN) : ?>
<option>System Administrator</option>
<?php endif; ?>
</select>
</div>
<div class="form-group">
<label for="pass">Email (για σύνδεση)</label>
<input class="form-control" type="email" name="email" disabled>
</div>
<div class="form-group">
<label for="pass">Κωδικός πρόσβασης</label>
<input class="form-control" type="password" name="pass" disabled>
</div>
<div class="form-group">
<label for="confirm">Επιβεβαίωση κωδικού</label>
<input class="form-control" type="password" name="confirm" disabled>
</div>
<br />
<input class="btn btn-primary" type="submit" value="Δημιουργία χρήστη" disabled>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- scripts and libraries
load and register one by one, so you don't need to worry about if they are ready -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/1.4.1/jquery-migrate.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script>
var waitingResponse = false; // flag for an ajax request that was sent and still waiting response
// functions needed
// ---------------------------------------------------------------------------
// pure JS ajax GET request
// return data as JSON
// no fancy things like UTF8; if needed use base64 ---------------------------
function ajax_get(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {
console.log(err.message + " in " + xmlhttp.responseText);
return;
}
callback(data);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
// menu management
// ---------------------------------------------------------------------------
$('.dropdown-item').on('click', function(e){
e.preventDefault();
// all data-goto have the format: 'method,uri_address'
// uri_address is the url to call
// method options:
// * url : means goto url (redirect)
// * ajax : means call url via ajax; if 'success = true' then goto '/' after that
// -------------------------------------------------------------------------
var opt = $(this).data('goto').split(','); // split data-goto
if (opt[0] == 'url') { // if method = url
window.location.href = opt[1];
}
else { // else, method = ajax
ajax_get(opt[1], function(response) {
if (response.success) {
window.location.href = '/';
}
});
}
});
// 01. MENU MANAGEMENT
// ---------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////
// menu management
// ---------------------------------------------------------------------------
$('.dropdown-item').on('click', function(e){
e.preventDefault();
if (!waitingResponse) {
waitingResponse = true;
// var r = confirm("Δεν έχετε αποθηκεύσει το τρέχον αντικείμενο!\nΕίστε σίγουροι ότι θέλετε να εγκαταλείψετε τη σελίδα;");
r = true; // no need for confirmation
if (r == true) {
// all data-goto have the format: 'method,uri_address'
// uri_address is the url to call
// method options:
// * url : means goto url (redirect)
// * ajax : means call url via ajax; if 'success = true' then goto '/' after that
// -----------------------------------------------------------------------
var opt = $(this).data('goto').split(','); // split data-goto
if (opt[0] == 'url') { // if method = url
window.location.href = opt[1];
}
else { // else, method = ajax
ajax_get(opt[1], function(response) {
if (response.success) {
window.location.href = '/';
}
});
}
}
else {
// user did not confirmed the selection; do nothing
}
waitingResponse = false;
}
});
</script>
</body>
</html>
|