-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployees.php
220 lines (204 loc) · 12.3 KB
/
employees.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
<?php
session_start();
?> <?php require_once 'header.php'; ?>
<?php require_once 'sidebar.php'; ?>
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<?php if(isset($_GET['action']) && $_GET['action'] == 'add') : ?>
<div class="col-md-12">
<h1>Add New Employee</h1>
<?php include 'forms/add_employee.php'; ?>
</div>
<?php elseif(isset($_GET['action']) && $_GET['action'] == 'view_all') : ?>
<div class="col-md-12">
<h3>Find Employee:</h3>
<form action="search.php" method="GET">
<div class="searchBox input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
<input type="hidden" name="for" value="employee" style="display:none" />
<input id="text" type="text" class="inputBox form-control" name="id" placeholder="Enter Employee Id" required="" />
</div>
<div style="margin-top:10px">
<button type="submit" class="btn btn-success">Search</button>
<a href="search.php?for=employee" class="btn btn-warning">Advanced Search</a>
</div>
</form>
</div>
<div class="col-md-12">
<?php
$q="select e.employee_id,et.typename,e.fname,e.lname,e.sex,e.cnic,e.mobile1 from employee e,employee_type et where e.employee_type_id=et.employee_type_id";
$arr=$db->query($q);
$no=0;
$no=count($arr);
if($no==0) : ?>
<h3>No Employee Found</h1>
<?php else: ?>
<h1>All Employees:</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>Employee Id</th>
<th>Employee Type</th>
<th>First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>CNIC</th>
<th>Mobile No</th>
<th>Option</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
while($i<$no)
{
echo "<tr>
<td>{$arr[$i]['employee_id']}</td>
<td>{$arr[$i]['typename']}</td>
<td>{$arr[$i]['fname']}</td>
<td>{$arr[$i]['lname']}</td>
<td>{$arr[$i]['sex']}</td>
<td>{$arr[$i]['cnic']}</td>
<td>{$arr[$i]['mobile1']}</td>
<td>
<a href=\"employees.php?action=single_view&id={$arr[$i]['employee_id']}\" class=\"btn btn-primary btn-sm\">View</a>
<a href=\"employees.php?action=single_edit&id={$arr[$i]['employee_id']}\" class=\"btn btn-warning btn-sm\">Edit</a>
<a href=\"employees.php?action=single_delete&id={$arr[$i]['employee_id']}\" class=\"btn btn-danger btn-sm\">Delete</a>
</td>
</tr>";
$i++;
}
?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<?php elseif(isset($_GET['action']) && $_GET['action'] == 'single_view') :
// single view
$employee_id = $db->cleanString($_GET['id']);
$employee = $db->query("SELECT e.employee_id, et.typename, d.name as deptname, e.dob, e.username, e.qualification, e.email, e.hiredate,e.mobile1,e.mobile2, e.fname,e.lname,e.sex,e.cnic,e.mobile1 from employee e,employee_type et, department d where e.employee_type_id=et.employee_type_id and e.dept_id = d.dept_id and e.employee_id = {$employee_id} LIMIT 1");
if(count($employee) == 0) {
echo '<div class="col-md-12"><div class="alert alert-danger">No employee found</div><a href="employees.php?action=view_all" class="btn btn-default">Go Back</a></div>';
} else {
$employee = $employee[0];
?>
<div class="col-md-12">
<h1>Employee Details:</h1>
<br>
<div class="row statsboxes">
<div class="stats_title clearfix"><span class="pull-left">Employee Id: <?php echo $employee['employee_id']; ?></span></div>
<div class="col-md-3 statsbox">
<h3>Employee Type:</h3>
<div class="stats_content">
<?php echo $employee['typename']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Department Name:</h3>
<div class="stats_content">
<?php echo $employee['deptname']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Name:</h3>
<div class="stats_content">
<?php echo $employee['fname'] . ' '. $employee['lname']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Date Of Birth:</h3>
<div class="stats_content">
<?php echo $employee['dob']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Sex:</h3>
<div class="stats_content">
<?php echo $employee['sex']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>CNIC:</h3>
<div class="stats_content">
<?php echo $employee['cnic']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Username:</h3>
<div class="stats_content">
<?php echo $employee['username']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Qualification:</h3>
<div class="stats_content">
<?php echo $employee['qualification']; ?>
</div>
</div>
<div class="col-md-3 statsbox ">
<h3>Email:</h3>
<div class="stats_content">
<?php echo $employee['email']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Hiredate:</h3>
<div class="stats_content">
<?php echo $employee['hiredate']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Mobile No:</h3>
<div class="stats_content">
<?php echo $employee['mobile1']; ?>
</div>
</div>
<div class="col-md-3 statsbox">
<h3>Secondary Mobile no:</h3>
<div class="stats_content">
<?php echo $employee['mobile2']; ?>
</div>
</div>
</div>
<br>
<a href="employees.php?action=single_edit&id=<?php echo $employee['employee_id']; ?>" class="btn btn-lg btn-warning">Edit Employee</a>
<a href="employees.php?action=single_delete&id=<?php echo $employee['employee_id']; ?>" class="btn btn-lg btn-danger">Delete Employee</a>
</div>
<?php } // endif ?>
<?php
elseif(isset($_GET['action']) && $_GET['action'] == 'single_edit'):
// single edit
?>
<div class="col-md-12">
<h1>Update Employee:</h1>
<?php require_once 'forms/edit_employee.php'; ?>
</div>
<?php elseif(isset($_GET['action']) && $_GET['action'] == 'single_delete'):
echo '<h1>Employee Details:</h1>';
// single delete
/* check if nurse assigned room */
$db->query("UPDATE room SET nurse_id = NULL WHERE nurse_id = '{$db->cleanString($_GET['id'])}'", true);
$q = $db->query("DELETE from employee WHERE employee_id = '{$db->cleanString($_GET['id'])}'", true);
if($q) {
echo '<div class="alert alert-success">Employee deleted successfully</div><a href="employees.php" class="btn btn-default">Go Back</a>';
} else {
echo '<div class="alert alert-danger">Error occured, please try again.</div><a href="employees.php?action=add" class="btn btn-default">Go Back</a>';
}
?>
<?php else: ?>
<div class="col-md-12">
<h1>Employees</h1>
<br>
<div class="row">
<a href="employees.php?action=add" class="btn btn-lg btn-success">Add New Employee</a>
<a href="employees.php?action=view_all" class="btn btn-lg btn-primary">View All Employees</a>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- /#page-content-wrapper -->
<?php require_once 'footer.php'; ?>