-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaculty.php
executable file
·178 lines (172 loc) · 5.14 KB
/
faculty.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
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<?php include('header.php') ?>
<?php include('auth.php') ?>
<?php include('db_connect.php') ?>
<title>Faculty List</title>
</head>
<body>
<?php include('nav_bar.php') ?>
<div class="container-fluid admin">
<div class="col-md-12 alert alert-primary">Faculty List</div>
<button class="btn btn-primary bt-sm" id="new_faculty"><i class="fa fa-plus"></i> Add New</button>
<br>
<br>
<div class="card">
<div class="card-body">
<table class="table table-bordered" id='table'>
<colgroup>
<col width="10%">
<col width="40%">
<col width="30%">
<col width="20%">
</colgroup>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Subject</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$qry = $conn->query("SELECT f.*,u.name from faculty f left join users u on f.user_id = u.id order by u.name asc ");
$i = 1;
if($qry->num_rows > 0){
while($row= $qry->fetch_assoc()){
?>
<tr>
<td><?php echo $i++ ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['subject'] ?></td>
<td>
<center>
<button class="btn btn-sm btn-outline-primary edit_faculty" data-id="<?php echo $row['id']?>" type="button"><i class="fa fa-edit"></i> Edit</button>
<button class="btn btn-sm btn-outline-danger remove_faculty" data-id="<?php echo $row['id']?>" type="button"><i class="fa fa-trash"></i> Delete</button>
</center>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal fade" id="manage_faculty" tabindex="-1" role="dialog" >
<div class="modal-dialog modal-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModallabel">Add New Faculty</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<form id='faculty-frm'>
<div class ="modal-body">
<div id="msg"></div>
<div class="form-group">
<label>Name</label>
<input type="hidden" name="id" />
<input type="hidden" name="uid" />
<input type="hidden" name="user_type" value = '2' />
<input type="text" name="name" required="required" class="form-control" />
</div>
<div class="form-group">
<label>Subject</label>
<input type="text" name ="subject" required="" class="form-control" />
</div>
<div class="form-group">
<label>Username</label>
<input type="text" name ="username" required="" class="form-control" />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" required="required" class="form-control" />
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" name="save"><span class="glyphicon glyphicon-save"></span> Save</button>
</div>
</form>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function(){
$('#table').DataTable();
$('#new_faculty').click(function(){
$('#msg').html('')
$('#manage_faculty .modal-title').html('Add New Faculty')
$('#manage_faculty #faculty-frm').get(0).reset()
$('#manage_faculty').modal('show')
})
$('.edit_faculty').click(function(){
var id = $(this).attr('data-id')
$.ajax({
url:'./get_faculty.php?id='+id,
error:err=>console.log(err),
success:function(resp){
if(typeof resp != undefined){
resp = JSON.parse(resp)
$('[name="id"]').val(resp.id)
$('[name="uid"]').val(resp.uid)
$('[name="name"]').val(resp.name)
$('[name="subject"]').val(resp.subject)
$('[name="username"]').val(resp.username)
$('[name="password"]').val(resp.password)
$('#manage_faculty .modal-title').html('Edit Faculty')
$('#manage_faculty').modal('show')
}
}
})
})
$('.remove_faculty').click(function(){
var id = $(this).attr('data-id')
var conf = confirm('Are you sure to delete this data.');
if(conf == true){
$.ajax({
url:'./delete_faculty.php?id='+id,
error:err=>console.log(err),
success:function(resp){
if(resp == true)
location.reload()
}
})
}
})
$('#faculty-frm').submit(function(e){
e.preventDefault();
$('#faculty-frm [name="submit"]').attr('disabled',true)
$('#faculty-frm [name="submit"]').html('Saving...')
$('#msg').html('')
$.ajax({
url:'./save_faculty.php',
method:'POST',
data:$(this).serialize(),
error:err=>{
console.log(err)
alert('An error occured')
$('#faculty-frm [name="submit"]').removeAttr('disabled')
$('#faculty-frm [name="submit"]').html('Save')
},
success:function(resp){
if(typeof resp != undefined){
resp = JSON.parse(resp)
if(resp.status == 1){
alert('Data successfully saved');
location.reload()
}else{
$('#msg').html('<div class="alert alert-danger">'+resp.msg+'</div>')
}
}
}
})
})
})
</script>
</html>