-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminPage.php
266 lines (226 loc) · 11.9 KB
/
AdminPage.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
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
<?php
session_start();
if($_SESSION["accountType"] != 'admin')
{
header('Location: index.php');
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/tether.min.js"></script>
<script src ="js/bootstrap.min.js"></script>
<script src="DataTables/datatables.min.js"></script>
<script type="text/javascript">
$( document ).ready(function()
{
var table = $('#myDataTable').DataTable( {
"ajax": "PhpScripts/ViewAccountsTable.php",
"bPaginate":true,
"bProcessing": true,
"columns": [
{ mData: 'username', "searchable": true } ,
{ mData: 'active', "searchable": false },
{ mData: 'type', "searchable": false },
{ "targets": -1,
"data": null,
"orderable":false,
"className": "editButton",
"defaultContent": "<button>Edit</button>"}
],
"columnDefs": [
{
"render": function(data,type,row) {
return data == 1 ? 'Active' : 'Inactive';
},
"targets":1
},
{
"render": function(data,type,row) {
return data == 0 ? 'User' : 'Admin';
},
"targets":2
}
]
} );
//Function that responds to user clicking edit button
$('#myDataTable tbody').on( 'click', 'button', function () {
//Get the data from the selected row
var dataObj = table.row( $(this).parents('td') ).data();
var data = Object.values(dataObj);
var AccID = data[0];
var TypeValue = data[3];
var activeValue = data[4];
var modal = document.getElementById('myEditModal');
modal.style.display = "block";
var accountLabel = document.getElementById('accountLabel');
accountLabel.value = AccID;
if (activeValue == 1)
document.getElementById("statusARadioBtn").checked = true;
else
document.getElementById("statusInARadioBtn").checked = true;
if(TypeValue == 1)
document.getElementById("typeAdminRadioBtn").checked = true;
else
document.getElementById("typeRegRadioBtn").checked = true;
} );
setInterval( function () {
table.ajax.reload(null, false);
}, 10000 );
});
var interval;
function changePagesAutomatically()
{
var table = $('#myDataTable').DataTable();
if(interval)
{
document.getElementById("start").value = "Start Rotating Pages";
clearInterval(interval);
interval = null;
}
else
{
document.getElementById("start").value = "Stop Rotating Pages";
interval = setInterval( function () {
var info = table.page.info();
var pageNum = (info.page < info.pages) ? info.page + 1 : 1;
table.page(pageNum).draw(false);
}, 10000);
}
}
function createAccount()
{
var modal = document.getElementById('createAccountModal');
modal.style.display = "block";
}
//Validate that an account is fully created before submit
function validateAccount()
{
var username = document.getElementById( "usernameLabel" ).value;
var password = document.getElementById( "newPasswordText2" ).value;
var activeBtn = document.getElementById( "statusARadioBtn2" ).checked;
var inActiveBtn = document.getElementById( "statusInARadioBtn2" ).checked;
var adminBtn = document.getElementById( "typeAdminRadioBtn2" ).checked;
var regUserBtn = document.getElementById( "typeRegRadioBtn2" ).checked;
if(username === '' || username == null)
{
alert("You have not given the account a username.");
return false;
}
if( activeBtn == false && inActiveBtn == false)
{
alert("You have not selected user activity.");
return false;
}
if( adminBtn == false && regUserBtn == false )
{
alert("You have not selected user type.");
return false;
}
if( password === '' || password == null)
{
alert("You have not created a user password.");
return false;
}
//alert("Success.");
return true;
}
//Radio button action buttons
function clickActive() {document.getElementById("statusInARadioBtn").checked = false;}
function clickInActive() {document.getElementById("statusARadioBtn").checked = false;}
function clickAdmin(){document.getElementById("typeRegRadioBtn").checked = false;}
function clickRegular(){document.getElementById("typeAdminRadioBtn").checked = false}
function clickActive2() {document.getElementById("statusInARadioBtn2").checked = false;}
function clickInActive2() {document.getElementById("statusARadioBtn2").checked = false;}
function clickAdmin2(){document.getElementById("typeRegRadioBtn2").checked = false;}
function clickRegular2(){document.getElementById("typeAdminRadioBtn2").checked = false}
</script>
<link href="css/bootstrap.min.css" text="text/css" rel="stylesheet">
<link href="css/customStyles.css" text="text/css" rel="stylesheet">
<link href="DataTables/datatables.min.css" text="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title></title>
</head>
<body id="UserManagementBody">
<?php include "PhpScripts/Templates/Nav.php";?>
<div class="container body-content top">
<table id="myDataTable" class="stripe" cellspacing="0" width="100%">
<thead>
<tr>
<td class="first head">Username</td>
<td class="head">State</td>
<td class="head">User Type</td>
<td class="last head">Edit</td>
</tr>
</thead>
</table>
<button onclick= "createAccount();" class="btn btn-primary" type="button">Create Account</button>
<input id="start" type="button" class="center btn-info" value="Start Rotating Through Pages" onclick="changePagesAutomatically();" />
</div>
<!--
Html for the edit modal view
-->
<div id="myEditModal" class="modal-custom">
<div class="modal-content-custom page">
<form class="form-group" action="PhpScripts/EditUser.php" method="post">
<span class="name"></span>
<div id = "radioBtns" class="form-group">
<label for "accountLabel">Account Number</label>
<input type="text" class="form-control" name="autoId" id="accountLabel" value="" readonly>
<label>Status</label><br>
<input onclick="clickActive()" id = "statusARadioBtn" type="radio" name="active"> Active<br>
<input onclick="clickInActive()" id = "statusInARadioBtn" type="radio" name="inActive"> Inactive<br>
<label>Type of User</label><br>
<input onclick="clickAdmin()" id = "typeAdminRadioBtn" type="radio" name="typeAdmin" value = false > Admin <br>
<input onclick="clickRegular()" id = "typeRegRadioBtn" type="radio" name="typeRegular"> Regular <br>
</div>
<div class="form-group">
<label for="newPassword">New Password</label><br>
<input id="newPasswordText" class="form-control" type="text" name="newPassword">
</div>
<div class="form-group">
<button class="btn btn-primary" id = "updateButton" name = "update" type="submit">Update</button>
<button class="btn btn-primary" id = "deleteButton" name = "delete" type="submit">Delete</button>
<button onclick="location.href = 'AdminPage.php';" class="btn btn-primary" id = "cancelButton" type="button">Cancel</button>
</div>
</form>
<p id="error_para" ></p>
</div>
</div>
<!--
Create Acount Modal
-->
<div id="createAccountModal" class="modal-custom">
<div class="modal-content-custom page">
<form class="form-group" action="PhpScripts/CreateAccount.php" onsubmit = "return validateAccount()" method="post">
<span class="name"></span>
<div class="form-group">
<label for "usernameLabel">Account Username</label>
<input type="text" class="form-control" name="username" id="usernameLabel" >
<label>Status</label><br>
<input onclick="clickActive2()" id = "statusARadioBtn2" type="radio" name="active"> Active<br>
<input onclick="clickInActive2()" id = "statusInARadioBtn2" type="radio" name="inActive"> Inactive<br>
<label>Type of User</label><br>
<input onclick="clickAdmin2()" id = "typeAdminRadioBtn2" type="radio" name="typeAdmin" value = false > Admin <br>
<input onclick="clickRegular2()" id = "typeRegRadioBtn2" type="radio" name="typeRegular"> Regular <br>
</div>
<div class="form-group">
<label for="newPassword">New Password</label><br>
<input id="newPasswordText2" class="form-control" type="text" name="newPassword">
</div>
<div class="form-group">
<button class="btn btn-primary" id = "createButton" name = "create" type="submit">Create</button>
<button onclick="location.href = 'AdminPage.php';" class="btn btn-primary" id = "cancelButton2" type="button">Cancel</button>
</div>
</form>
<p id="error_para" ></p>
</div>
</div>
</body>
</html>