ITClub/code/users.php

95 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
//
// users.php
// IT Club
//
// Copyright (c) 2015, Mr. Gecko's Media (James Coleman)
// All rights reserved.
//
// User management page.
//
require_once("header.php");
?>
<div id="user_edit" class="modal hide fade" tabindex="-1" role="dialog" style="width: 260px; margin-left: -130px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 id="myModalLabel">Edit User</h3>
</div>
<div class="modal-body">
<div style="display: none;" id="user_edit_id"></div>
<input type="text" id="user_edit_email" placeholder="Email" /><br />
<input type="password" id="user_edit_password" placeholder="Password" /><br />
<select id="user_edit_level">
<option value="2">Normal</option>
<option value="1">Administrator</option>
<option value="0">Disabled</option>
</select>
<div style="display: none;" id="user_edit_load"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">Cancel</button>
<button class="btn btn-primary" data-dismiss="modal" id="user_edit_save">Save</button>
</div>
</div>
<div id="user_add" class="modal hide fade" tabindex="-1" role="dialog" style="width: 260px; margin-left: -130px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 id="myModalLabel">Create User</h3>
</div>
<div class="modal-body">
<input type="text" id="user_add_email" placeholder="Email" /><br />
<input type="password" id="user_add_password" placeholder="Password" /><br />
<select id="user_add_level">
<option value="2">Normal</option>
<option value="1">Administrator</option>
<option value="0">Disabled</option>
</select>
<div style="display: none;" id="user_add_load"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">Cancel</button>
<button class="btn btn-primary" data-dismiss="modal" id="user_add_create">Create</button>
</div>
</div>
<button class="btn btn-primary" id="add_user">Create User</button><br /><br />
<table class="table table-striped table-bordered table-hover" id="users_list">
<thead>
<tr><th>#</th><th>Email</th><th>Level</th></tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
function loadUsers() {
$("#users_list tbody").load("<?=generateURL("api/users/list")?>/");
}
$(document).ready(function() {
$("#users_list").on("click", "tbody tr", function() {
$("#user_edit_id").text($(this).find(".id").text());
$("#user_edit_email").val($(this).find(".email").text());
$("#user_edit_level").val($(this).find(".level").attr("value"));
$("#user_edit").modal();
});
$("#user_edit_save").click(function() {
$("#user_edit_load").load("<?=generateURL("api/users/update")?>/", {id: $("#user_edit_id").text(), email: $("#user_edit_email").val(), password: $("#user_edit_password").val(), level: $("#user_edit_level").val()}, function(response, status, xhr) {
loadUsers();
});
});
$("#add_user").click(function() {
$("#user_add").modal();
});
$("#user_add_create").click(function() {
$("#user_add_load").load("<?=generateURL("api/users/create")?>/", {email: $("#user_add_email").val(), password: $("#user_add_password").val(), level: $("#user_add_level").val()}, function(response, status, xhr) {
loadUsers();
});
});
loadUsers();
});
</script>
<?
require_once("footer.php");
exit();
?>