-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathuser.php
198 lines (188 loc) · 6.15 KB
/
user.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
<?php
// Start from getting the hader which contains some settings we need
require_once 'includes/header.php';
// Redirect visitor to the login page if he is trying to access
// this page without being logged in
if (!isset($_SESSION['admin_session']) )
{
$commons->redirectTo(SITE_PATH.'login.php');
}
?>
<?php
require_once "includes/classes/admin-class.php";
$admins = new Admins($dbh);
?>
<div class="dashboard">
<div class="col-md-12 col-sm-12" id="employee_table">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Employeer</h4>
</div>
<div class="panel-body">
<div class="col-md-6">
<button type="button" name="add" id="add" class="btn btn-info" data-toggle="modal" data-target="#add_data_Modal">ADD</button>
</div>
<div class="col-md-6">
<form class="form-inline pull-right">
<div class="form-group">
<label class="sr-only" for="search">Search for</label>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></div>
<input type="text" class="form-control" id="search" placeholder="Type a name">
<div class="input-group-addon"></div>
</div>
</div>
<!-- <button type="submit" class="btn btn-info">Search</button> -->
</form>
</div>
<?php if ( isset($_SESSION['errors']) ) {?>
<div class="pannel panel-warning">
<?php foreach ($_SESSION['errors'] as $error):?>
<li><?= $error ?></li>
<?php endforeach ?>
</div>
<?php session::destroy('errors');
} ?>
</div>
<table class="table table-striped" id="grid-basic">
<thead class="thead-inverse">
<tr class="info">
<th>ID </th>
<th>Action</th>
<th>Username</th>
<th>Name</th>
<th>Email</th>
<th>Cellphone</th>
<th>Address</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- invisible content -->
<!-- Insert modal for users -->
<div id="add_data_Modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4>Insert Data</h4>
</div>
<form action="" method="POST" id="insert_form">
<div class="modal-body">
<!-- form content -->
<div class="form-group">
<label for="username">Username</label>
<input type="username" class="form-control" id="username" name="username" aria-describedby="emailHelp" placeholder="Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
</div>
<div class="form-group">
<label for="repassword">Re enter Password</label>
<input type="password" class="form-control" id="repassword" name="repassword" placeholder="Re enter password" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Email Address" required>
</div>
<div class="form-group">
<label for="fullname">Full Name</label>
<input type="text" class="form-control" id="fullname" name="fullname" placeholder="Full Name" required>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="textarea" class="form-control" id="address" name="address" placeholder="Address">
</div>
<div class="form-group">
<label for="contact">Contact</label>
<input type="tel" class="form-control" id="contact" name="contact" placeholder="Contact">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Submit</button>
<a href="#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
</div>
</form>
</div>
</div>
</div>
<?php
include 'includes/footer.php';
?>
<script type="text/javascript">
$('#insert_form').on('submit',function(event){
event.preventDefault();
$.ajax({
url: "user_approve.php?p=add",
method:"POST",
data:$('#insert_form').serialize(),
success: function (data) {
$('#insert_form')[0].reset();
$('#add_data_Modal').modal('hide');
viewData();
}
});
});
function viewData() {
$.ajax({
method: "GET",
url:"user_approve.php",
success: function(data){
$('tbody').html(data);
}
});
}
function delData(del_id){
var id = del_id;
$.ajax({
method:"POST",
url: "user_approve.php?p=delta",
data: "id="+id,
success: function (data){
viewData();
}
});
}
function updateData(str){
var user_id = str;
var username = $('#usr-'+str).val();
var full_name = $('#fnm-'+str).val();
var email = $('#em-'+str).val();
var contact = $('#con-'+str).val();
var address = $('#ad-'+str).val();
$.ajax({
method:"POST",
url: "user_approve.php?p=edit",
data: "username="+username+"&full_name="+full_name+"&email="+email+"&contact="+contact+"&address="+address+"&user_id="+user_id,
//console.log(data);
success: function (data){
viewData();
}
});
}
window.onload = viewData();
</script>
<script type="text/javascript">
$(function() {
grid = $('#grid-basic');
// handle search fields of members key up event
$('#search').keyup(function(e) {
text = $(this).val(); // grab search term
if(text.length > 1) {
grid.find('tr:has(td)').hide(); // hide data rows, leave header row showing
// iterate through all grid rows
grid.find('tr').each(function(i) {
// check to see if search term matches Name column
if($(this).find('.search').text().toUpperCase().match(text.toUpperCase()))
$(this).show(); // show matching row
});
}
else
grid.find('tr').show(); // if no matching name is found, show all rows
});
});
</script>