forked from jvbkw8/Group2Final
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.php
154 lines (149 loc) · 4.07 KB
/
account.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
<?php
include "security.php";
if(!isset($_SESSION['ADMIN']) || $_SESSION['ADMIN'] == 0){
header("Location: /Group2Final/");
}
?>
<!DOCTYPE html>
<html lang="en">
<style>
input[type=checkbox] + label {
color: #ccc;
font-style: italic;
}
input[type=checkbox]:checked + label {
color: #f00;
font-style: normal;
}
#error, #success{
position:fixed;
top:15px;
right:15px;
z-index:60000;
}
</style>
<head>
<title>RADs(Research Analysis and Database for Scientists)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
include "header.php";
?>
<div id="error" class="alert alert-danger" style="display:none"><?php echo $_GET['error'];?></div>
<div id="success" class="alert alert-success" style="display:none"><?php echo $_GET['success'];?></div>
<div class="container">
<?php
require_once "DBConn.php";
$conn = new DBConn();
if($conn->connectToDatabase()){
$q = "SELECT id, username, isadmin, activeuserflag from db.user";
$rows = $conn->select($q);
$Yes = "<span style='color:green'>Yes</span>";
$No = "<span style='color:red'>No</span>";
if($rows){
?>
<table class="table">
<thead>
<th>Username</th>
<th>Active User?</th>
<th>Admin User?</th>
<th>Activate/Deactivate</th>
<th>Admin Control</th>
<th>Reset Password</th>
</thead>
<tbody>
<?php
foreach($rows as $row){
?>
<tr>
<td><?php echo $row['username'];?></td>
<td><?php if($row['activeuserflag']){echo $Yes;} else {echo $No;}?></td>
<td><?php if($row['isadmin']){echo $Yes;} else {echo $No;}?></td>
<td><div id="<?php echo $row['id']?>_active" class="btn btn-info" onclick="toggleUserActive(<?php echo $row['id'];?>);"><?php if($row['activeuserflag']){echo "Deactivate";} else {echo "Activate";}?></div></td>
<td><div id="<?php echo $row['id']?>_admin" class="btn btn-info" onclick="toggleUserAdmin(<?php echo $row['id'];?>);"><?php if($row['isadmin']){echo "De-adminify";} else {echo "Adminify";}?></div></td>
<td><div id="<?php echo $row['id']?>_password" class="btn btn-info" onclick="resetPassword(<?php echo $row['id'];?>);">Reset Password</div></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
}
?>
</div>
<script>
$(document).ready(function(){
<?php
if(isset($_GET['error'])){
?>
$('#error').show();
setTimeout(function(){
$("#error").fadeOut(1000);
}, 7000);
<?php
}
if(isset($_GET['success'])){
?>
$('#success').show();
setTimeout(function(){
$("#success").fadeOut(1000);
}, 7000);
<?php
}
?>
});
var timeout;
function toggleUserActive(id){
if($('#'+id+'_active').html() == "Activate"){
var action = "activateUser";
} else {
var action = "deactivateUser";
}
editUser(id, action);
}
function resetPassword(id){
editUser(id, "resetPassword");
}
function toggleUserAdmin(id){
if($('#'+id+"_admin").html() == "Adminify"){
var action = "adminify";
} else {
var action = "deadminify";
}
editUser(id, action);
}
function editUser(id, action){
$.ajax({
url:"editUser.php",
method:"POST",
data:{id:id, action:action},
success:function(html){
if(html.error){
// $("#error").html(html.error);
// $('#error').show();
locaton.replace("account.php?error="+html.error);
}
if(html.success){
// $('#success').html(html.success);
// $('#success').show();
location.replace("account.php?success="+html.success);
}
},
error:function(bla, error, errortext){
// $('#error').html("Oops! Something went wrong.");
// $('#error').show();
location.replace("account.php?error=Oops! Something went wrong.");
// console.log("ajax error when toggling user active. " + error + " " + errortext);
},
});
}
</script>
</body>
</html>