-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdepartment.php
125 lines (116 loc) · 5.36 KB
/
department.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
<?php include('header.php');?>
<div class="container">
<div class="page-header"><h1>Data Department</h1></div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#create">Create New</button>
<div id="create" class="modal fade" role="dialog">
<div class="modal-dialog">
<form class="modal-content" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">New Department</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 form-group">
<label for="">Name</label>
<input type="text" name="name" class="form-control" required="true">
</div>
<div class="col-md-12 form-group">
<label for="">Description:</label>
<textarea class="form-control" name="description"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="save" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
<br><br>
<div class="row">
<div class="col-md-12">
<table class="table table-bordered">
<tr style="font-weight:bold;">
<td>NO</td>
<td>NAME</td>
<td>DESCRIPTION</td>
<td>ACTION</td>
</tr>
<?php
$data = Q_array("SELECT * FROM tbl_department ORDER BY td_id DESC");
foreach ($data as $key => $val) {
echo "
<tr>
<td>".($key+1)."</td>
<td>".$val['td_name']."</td>
<td>".$val['td_description']."</td>
<td>
<a class='btn btn-default' data-toggle='modal' data-target='#ed-".$key."'>Edit/Delete</a>
</td>
</tr>
";
?>
<div id="ed-<?=$key;?>" class="modal fade" role="dialog">
<div class="modal-dialog" style="background-color:#FFFFFF;">
<form class="modal-content" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit <?=$val['td_name'];?></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 form-group">
<label for="">Name</label>
<input type="text" name="name" class="form-control" required="true" value="<?=$val['td_name'];?>">
<input type="hidden" name="id" value="<?=$val['td_id'];?>">
</div>
<div class="col-md-12 form-group">
<label for="">Description:</label>
<textarea class="form-control" name="description"><?=$val['td_description'];?></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="update" class="btn btn-default">Save Change</button>
<button type="submit" name="delete" class="btn btn-danger">Delete</button>
</div>
</form>
</div>
</div>
<?php } ?>
</table>
</div>
</div>
</div>
<?php
if(isset($_POST['save']))
{
$a = Q_mres($_POST['name']);
$b = Q_mres($_POST['description']);
$sql = "INSERT INTO tbl_department (td_name, td_description) VALUES ('$a', '$b')";
if(Q_execute($sql)){
redirect_to("department.php");
}
}
if(isset($_POST['update']))
{
$a = Q_mres($_POST['name']);
$b = Q_mres($_POST['description']);
$c = Q_mres($_POST['id']);
$sql = "UPDATE tbl_department SET td_name='$a', td_description='$b' WHERE td_id='$c'";
if(Q_execute($sql)){
redirect_to("department.php");
}
}
if(isset($_POST['delete']))
{
$a = Q_mres($_POST['id']);
$sql = "DELETE FROM tbl_department WHERE td_id='$a'";
if(Q_execute($sql)){
redirect_to("department.php");
}
}
?>
<?php include('footer.php');?>