forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
451 lines (428 loc) · 19.3 KB
/
Copy pathadmin.php
File metadata and controls
451 lines (428 loc) · 19.3 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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
/********************************************************************************
* *
* Copyright 2012 Nicolas CARPi (nicolas.carpi@gmail.com) *
* http://www.elabftw.net/ *
* *
********************************************************************************/
/********************************************************************************
* This file is part of eLabFTW. *
* *
* eLabFTW is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* eLabFTW is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *
* PURPOSE. See the GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public *
* License along with eLabFTW. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
/* admin.php - for administration of the elab */
require_once 'inc/common.php';
if ($_SESSION['is_admin'] != 1) {
die('You are not admin !');
}
$page_title = 'Admin Panel';
require_once 'inc/head.php';
require_once 'inc/menu.php';
require_once 'inc/info_box.php';
// formkey stuff
require_once 'lib/classes/formkey.class.php';
$formKey = new formKey();
?>
<script src="js/tinymce/tinymce.min.js"></script>
<script src="js/raphael-2.1.0.min.js"></script>
<script src="js/colorwheel.min.js"></script>
<?php
// MAIN SQL FOR USERS
$sql = "SELECT * FROM users WHERE validated = :validated";
$user_req = $pdo->prepare($sql);
$user_req->bindValue(':validated', 0);
$user_req->execute();
$count = $user_req->rowCount();
// only show the frame if there is some users to validate
if ($count > 0) {
$message = "There are users waiting for validation of their account :";
$message .= "<form method='post' action='admin-exec.php'><ul>";
while ($data = $user_req->fetch()) {
$message .= "<li><label>
<input type='checkbox' name='validate[]'
value='".$data['userid']."'> ".$data['firstname']." ".$data['lastname']." (".$data['email'].")
</label></li>";
}
$message .= "</ul><div class='center'>
<input class='button' type='submit' value='Validate users' /></div></form>";
display_message('error', $message);
}
?>
<div id='tabs'>
<ul>
<li><a href='#tabs-1'>Main configuration</a></li>
<li><a href='#tabs-2'>Users</a></li>
<li><a href='#tabs-3'>Status</a></li>
<li><a href='#tabs-4'>Types of items</a></li>
</ul>
<!-- TABS 1 -->
<div id='tabs-1'>
<h3>CONFIGURATION</h3>
<form method='post' action='admin-exec.php'>
<div id='config_form'>
<label for='lab_name'>Name of the lab :</label>
<input type='text' value='<?php echo get_config('lab_name');?>' name='lab_name' id='lab_name' />
<br />
<br />
<label for='admin_validate'>Users need validation by admin after registration :</label>
<select name='admin_validate' id='admin_validate'>
<option value='1'<?php
if (get_config('admin_validate') == 1) { echo " selected='selected'"; } ?>
>yes</option>
<option value='0'<?php
if (get_config('admin_validate') == 0) { echo " selected='selected'"; } ?>
>no</option>
</select>
<br />
<br />
<label for='deletable_xp'>Users can delete experiments :</label>
<select name='deletable_xp' id='deletable_xp'>
<option value='1'<?php
if (get_config('deletable_xp') == 1) { echo " selected='selected'"; } ?>
>yes</option>
<option value='0'<?php
if (get_config('deletable_xp') == 0) { echo " selected='selected'"; } ?>
>no, only the admin can</option>
</select>
<br />
<br />
<label for='debug'>Activate debug mode :</label>
<select name='debug' id='debug'>
<option value='1'<?php
if (get_config('debug') == 1) { echo " selected='selected'"; } ?>
>yes</option>
<option value='0'<?php
if (get_config('debug') == 0) { echo " selected='selected'"; } ?>
>no</option>
</select>
<br />
<br />
<label for='link_name'>Name of the link in the main menu :</label>
<input type='text' value='<?php echo get_config('link_name');?>' name='link_name' id='link_name' />
<br />
<br />
<label for='link_href'>Address where this link should point :</label>
<input type='url' value='<?php echo get_config('link_href');?>' name='link_href' id='link_href' />
<br />
<br />
<label for='path'>Full path to the install folder :</label>
<input type='text' value='<?php echo get_config('path');?>' name='path' id='path' />
<br />
<br />
<label for='proxy'>Address of the proxy :</label>
<input type='text' value='<?php echo get_config('proxy');?>' name='proxy' id='proxy' />
<br />
<br />
<label for='smtp_address'>Address of the SMTP server :</label>
<input type='text' value='<?php echo get_config('smtp_address');?>' name='smtp_address' id='smtp_address' />
<br />
<br />
<label for='smtp_encryption'>SMTP encryption (can be TLS or STARTSSL):</label>
<input type='text' value='<?php echo get_config('smtp_encryption');?>' name='smtp_encryption' id='smtp_encryption' />
<br />
<br />
<label for='smtp_port'>SMTP port :</label>
<input type='text' value='<?php echo get_config('smtp_port');?>' name='smtp_port' id='smtp_port' />
<br />
<br />
<label for='smtp_username'>SMTP username :</label>
<input type='text' value='<?php echo get_config('smtp_username');?>' name='smtp_username' id='smtp_username' />
<br />
<br />
<label for='smtp_password'>SMTP password :</label>
<input type='password' value='<?php echo get_config('smtp_password');?>' name='smtp_password' id='smtp_password' />
<br />
<br />
<label for='login_tries'>Number of allowed login attempts :</label>
<input type='text' value='<?php echo get_config('login_tries');?>' name='login_tries' id='login_tries' />
<br />
<br />
<label for='ban_time'>Time of the ban after failed login attempts (in minutes) :</label>
<input type='text' value='<?php echo get_config('ban_time');?>' name='ban_time' id='ban_time' />
<br />
<br />
</div>
<div class='center'>
<input type='submit' name='submit_config' class='submit button' value='Save' />
</div>
</form>
</div>
<!-- TABS 2 -->
<div id='tabs-2'>
<h3>TEAM MEMBERS</h3>
<?php
// we show only the validated users here
$user_req->bindValue(':validated', 1);
$user_req->execute();
while ($users = $user_req->fetch()) {
?>
<div class='simple_border'>
<a class='trigger_users_<?php echo $users['userid'];?>'><img src='img/profile.png' alt='profile' /> <?php echo "Edit ".$users['firstname'];?></a>
<div class='toggle_users_<?php echo $users['userid'];?>'>
<br />
<form method='post' action='admin-exec.php' id='admin_user_form'>
<input type='hidden' value='<?php echo $users['userid'];?>' name='userid' />
<label for='edituser_firstname'>Firstname</label>
<input id='edituser_firstname' type='text' value='<?php echo $users['firstname'];?>' name='firstname' />
<label for='edituser_lastname'>Lastname</label>
<input id='edituser_lastname' type='text' value='<?php echo $users['lastname'];?>' name='lastname' />
<label for='edituser_username'>Username</label>
<input id='edituser_username' type='text' value='<?php echo $users['username'];?>' name='username' />
<label for='edituser_email'>Email</label>
<input id='edituser_email' type='email' value='<?php echo $users['email'];?>' name='email' /><br />
Has admin rights ?<select name='is_admin'>
<option value='1'<?php
if($users['is_admin'] == 1) {
echo " selected='selected'";
}
?>
>yes</option>
<option value='0'<?php
if ($users['is_admin'] == 0) {
echo " selected='selected'";
}
?>
>no</option>
</select>
<br />
Can lock experiments of others ?<select name='can_lock'>
<option value='1'<?php
if ($users['can_lock'] == 1) { echo " selected='selected'"; } ?>
>yes</option>
<option value='0'<?php
if ($users['can_lock'] == 0) { echo " selected='selected'"; } ?>
>no</option>
</select>
<br />
<label for'validated'>Has an active account ?</label>
<select name='validated' id='validated'>
<option value='1'<?php
if ($users['validated'] == 1) { echo " selected='selected'"; } ?>
>yes</option>
<option value='0'<?php
if ($users['validated'] == 0) { echo " selected='selected'"; } ?>
>no</option>
</select>
<br />
Reset user password : <input type='password' value='' name='new_password' />
<br />
Repeat new password : <input type='password' value='' name='confirm_new_password' />
<br />
<br />
<div class='center'>
<input type='submit' class='button' value='Edit this user' />
</div>
</form>
</div>
<script>
$(".toggle_users_<?php echo $users['userid'];?>").hide();
$("a.trigger_users_<?php echo $users['userid'];?>").click(function(){
$('div.toggle_users_<?php echo $users['userid'];?>').slideToggle(1);
});
</script>
</div>
<?php
}
?>
<section class='simple_border' style='background-color:#FF8080;'>
<h3>DANGER ZONE</h3>
<h4>Delete a user</h4>
<form action='admin-exec.php' method='post'>
<!-- form key -->
<?php $formKey->output_formkey(); ?>
<label for'delete_user'>Type EMAIL ADDRESS of a member to delete this user and all his experiments/files forever.</label>
<input type='email' name='delete_user' id='delete_user' />
<div class='center'>
<input type='submit' class='button submit' value='Delete this user !' />
</div>
</form>
</section>
</div>
<!-- TABS-3 -->
<div id='tabs-3'>
<h3>STATUS</h3>
<?php
// SQL to get all status
$sql = "SELECT * from status";
$req = $pdo->prepare($sql);
$req->execute();
while ($status = $req->fetch()) {
// count the experiments with this status
// don't allow deletion if experiments with this status exist
// but instead display a message to explain
$count_exp_sql = "SELECT COUNT(id) FROM experiments WHERE status = :status";
$count_exp_req = $pdo->prepare($count_exp_sql);
$count_exp_req->bindParam(':status', $status['id'], PDO::PARAM_INT);
$count_exp_req->execute();
$count = $count_exp_req->fetchColumn();
?>
<div class='simple_border'>
<a class='trigger_status_<?php echo $status['id'];?>'>Edit <?php echo $status['name'];?></a>
<div class='toggle_container_status_<?php echo $status['id'];?>'>
<?php
if ($count == 0) {
?>
<img class='align_right' src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' onClick="deleteThis('<?php echo $status['id'];?>','status', 'admin.php')" />
<?php
} else {
?>
<img class='align_right' src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' onClick="alert('Remove all experiments with this status before deleting this status.')" />
<?php
}
?>
<form action='admin-exec.php' method='post'>
<input type='text' name='status_name' value='<?php echo stripslashes($status['name']);?>' />
<label for='default_checkbox'>Make default</label>
<input type='checkbox' name='status_is_default' id='default_checkbox'
<?php
// check the box if the status is already default
if ($status['is_default'] == 1) {
echo " checked";
}
?>>
<div id='colorwheel_div_edit_status_<?php echo $status['id'];?>'>
<div class='colorwheel inline'></div>
<input type='text' name='status_color' value='#<?php echo $status['color'];?>' />
</div>
<input type='hidden' name='status_id' value='<?php echo $status['id'];?>' />
<br />
<div class='center'>
<input type='submit' class='button' value='Edit <?php echo stripslashes($status['name']);?>' /><br />
</div>
</form></div>
<script>$(document).ready(function() {
$(".toggle_container_status_<?php echo $status['id'];?>").hide();
$("a.trigger_status_<?php echo $status['id'];?>").click(function(){
$('div.toggle_container_status_<?php echo $status['id'];?>').slideToggle(1);
});
color_wheel('#colorwheel_div_edit_status_<?php echo $status['id'];?>')
});</script></div>
<?php
}
?>
<section class='simple_border'>
<h3>ADD NEW STATUS</h3>
<form action='admin-exec.php' method='post'>
<input type='text' class='biginput' name='new_status_name' />
<div id='colorwheel_div_new_status'>
<div class='colorwheel inline'></div>
<input type='text' name='new_status_color' value='#000000' />
</div>
<br />
<div class='center'>
<input type='submit' class='submit button' value='Add new status' />
</div>
</form>
</section>
</div>
<!-- TABS 4 ITEMS TYPES-->
<div id='tabs-4'>
<a id='items_types'></a>
<h3>EXISTING TYPES</h3>
<?php
// SQL to get all items type
$sql = "SELECT * from items_types";
$req = $pdo->prepare($sql);
$req->execute();
while ($items_types = $req->fetch()) {
?>
<div class='simple_border'>
<a class='trigger_<?php echo $items_types['id'];?>'>Edit <?php echo $items_types['name'];?></a>
<div class='toggle_container_<?php echo $items_types['id'];?>'>
<?php
// count the items with this type
// don't allow deletion if items with this type exist
// but instead display a message to explain
$count_db_sql = "SELECT COUNT(id) FROM items WHERE type = :type";
$count_db_req = $pdo->prepare($count_db_sql);
$count_db_req->bindParam(':type', $items_types['id'], PDO::PARAM_INT);
$count_db_req->execute();
$count = $count_db_req->fetchColumn();
if ($count == 0) {
?>
<img class='align_right' src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' onClick="deleteThis('<?php echo $items_types['id'];?>','item_type', 'admin.php')" />
<?php
} else {
?>
<img class='align_right' src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' onClick="alert('Remove all database items with this type before deleting this type.')" />
<?php
}
?>
<form action='admin-exec.php' method='post'>
<input type='text' class='biginput' name='item_type_name' value='<?php echo stripslashes($items_types['name']);?>' />
<input type='hidden' name='item_type_id' value='<?php echo $items_types['id'];?>' />
<div id='colorwheel_div_<?php echo $items_types['id'];?>'>
<div class='colorwheel inline'></div>
<input type='color' name='item_type_bgcolor' value='#<?php echo $items_types['bgcolor'];?>'/></div><br /><br />
<textarea class='mceditable' name='item_type_template' /><?php echo stripslashes($items_types['template']);?></textarea><br />
<div class='center'>
<input type='submit' class='button' value='Edit <?php echo stripslashes($items_types['name']);?>' /><br />
</div>
</form></div>
<script>$(document).ready(function() {
$(".toggle_container_<?php echo $items_types['id'];?>").hide();
$("a.trigger_<?php echo $items_types['id'];?>").click(function(){
$('div.toggle_container_<?php echo $items_types['id'];?>').slideToggle(1);
});
color_wheel('#colorwheel_div_<?php echo $items_types['id'];?>')
});</script></div>
<?php
}
?>
<section class='simple_border'>
<h3>ADD NEW TYPE OF DATABASE ITEM</h3>
<form action='admin-exec.php' method='post'>
<input type='text' class='biginput' name='new_item_type_name' />
<input type='hidden' name='new_item_type' value='1' />
<div id='colorwheel_div_new'>
<div class='colorwheel inline'></div>
<input type='text' name='new_item_type_bgcolor' value='#000000' /></div><br /><br />
<textarea class='mceditable' name='new_item_type_template' /></textarea><br />
<div class='center'>
<input type='submit' class='button' value='Add new item type' />
</div>
</form>
</section>
</div>
</div>
<script>
// color wheel
function color_wheel(div_name) {
var cw = Raphael.colorwheel($(div_name)[0], 80);
cw.input($(div_name+" input" )[0]);
}
$(document).ready(function() {
// TABS
$('#tabs').tabs();
$('#tabs li');
// TOGGLE
$(".toggle_users_<?php echo $users['userid'];?>").hide();
$("a.trigger_users_<?php echo $users['userid'];?>").click(function(){
$('div.toggle_users_<?php echo $users['userid'];?>').slideToggle(1);
});
color_wheel('#colorwheel_div_new')
color_wheel('#colorwheel_div_new_status')
// EDITOR
tinymce.init({
mode : "specific_textareas",
editor_selector : "mceditable",
content_css : "css/tinymce.css",
plugins : "table textcolor searchreplace code fullscreen insertdatetime paste charmap save image link",
toolbar1: "undo redo | bold italic underline | fontsizeselect | alignleft aligncenter alignright alignjustify | superscript subscript | bullist numlist outdent indent | forecolor backcolor | charmap | link",
removed_menuitems : "newdocument",
});
});
</script>
<?php require_once 'inc/footer.php';