-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDBConnect.php
276 lines (247 loc) · 9.09 KB
/
DBConnect.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
266
267
268
269
270
271
272
273
274
275
276
<?php
class DBConnect
{
private $db = NULL;
const DB_SERVER = "localhost";
const DB_USER = "root";
const DB_PASSWORD = "";
const DB_NAME = "database";
public function __construct()
{
$dsn = 'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
try {
$this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
} catch (PDOException $e) {
throw new Exception('Connection failed: ' .
$e->getMessage());
}
return $this->db;
}
public function auth()
{
session_start();
if (!isset($_SESSION['username'])) {
header("Location: index.php");
}
}
public function authLogin()
{
session_start();
if (isset($_SESSION['username'])) {
header("Location: employee.php");
}
}
public function checkAuth()
{
session_start();
if (!isset($_SESSION['username'])) {
return false;
} else {
return true;
}
}
public function adminlogin($username, $password)
{
$stmt = $this->db->prepare("SELECT * FROM admin WHERE username=? AND password=?");
$stmt->execute([$username, $password]);
if ($stmt->rowCount() > 0) {
session_start();
$emp = $stmt->fetchAll();
foreach ($emp as $e) {
$_SESSION['id'] = $e['ID'];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
}
return true;
} else {
return false;
}
}
public function employeelogin($username, $password)
{
$stmt = $this->db->prepare("SELECT * FROM employeedetails WHERE uname=? AND psw=?");
$stmt->execute([$username, $password]);
if ($stmt->rowCount() > 0) {
session_start();
$emp = $stmt->fetchAll();
$_SESSION['emp'] = $username;
foreach ($emp as $e) {
$_SESSION['uname'] = $username;
$_SESSION['psw'] = $password;
}
return true;
} else {
return false;
}
}
public function addEmployee($uname, $psw, $fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode,$cnic,$loc)
{
$stmt = $this->db->prepare("INSERT INTO employeedetails (uname,psw,fname,mname,lname,sex,email,mobile,haddress,city,hstate,pincode,cnic,location)"
. "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$uname, $psw, $fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode,$cnic,$loc]);
return true;
}
public function addreport($fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode, $dob, $dov, $bg)
{
$stmt = $this->db->prepare("INSERT INTO register (fname,mname,lname,sex,email,mobile,haddress,city,hstate,pincode,dob,dov,bg)"
. "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode, $dob, $dov, $bg]);
return true;
}
public function registerUser($fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode, $dob, $dov, $bg, $cnic, $location)
{
$stmt = $this->db->prepare("INSERT INTO register (fname,mname,lname,sex,email,mobile,haddress,city,hstate,pincode,dob,dov,bg,cnic,location)"
. "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$fname, $mname, $lname, $sex, $mail, $mobile, $haddress, $city, $hstate, $pincode, $dob, $dov, $bg, $cnic, $location]);
return true;
}
public function reportdeatils($mobile, $dob)
{
$stmt = $this->db->prepare("SELECT * FROM register WHERE mobile=? AND dob=?");
$stmt->execute([$mobile, $dob]);
return $stmt->fetchAll();
}
public function getDetails($cnic, $dob)
{
// $stmt = $this->db->prepare("SELECT * FROM register WHERE cnic=? AND dob=?");
$stmt = $this->db->prepare(" select *,location.name from register,location where location.shortname = register.location AND cnic=? AND dob=?");
$stmt->execute([$cnic, $dob]);
return $stmt->fetchAll();
}
public function all_register()
{
$stmt = $this->db->prepare("SELECT * FROM register WHERE status='scheduled' ");
$stmt->execute();
return $stmt->fetchAll();
}
public function allschedule($location)
{
$stmt = $this->db->prepare("select * from register where register.location= ? AND status = 'scheduled'");
$stmt->execute([$location]);
return $stmt->fetchAll();
}
public function allVaccinated($location)
{
$stmt = $this->db->prepare("select * from register where register.location= ? AND status = 'vacinated'");
$stmt->execute([$location]);
return $stmt->fetchAll();
}
public function allRejected($location)
{
$stmt = $this->db->prepare("select * from register where register.location= ? AND status = 'rejected'");
$stmt->execute([$location]);
return $stmt->fetchAll();
}
public function allPVacinated($location)
{
$stmt = $this->db->prepare("select * from register where register.location= ? AND status = 'p-vacinated'");
$stmt->execute([$location]);
return $stmt->fetchAll();
}
public function getEmployeeDetails($uname)
{
$stmt = $this->db->prepare("select * from employeedetails where uname=?");
$stmt->execute([$uname]);
return $stmt->fetchAll();
}
public function vaccinate($vaccine, $totalDoses, $doneDoses, $cnic, $dob, $loc)
{
if ($doneDoses == $totalDoses) {
$stmt = $this->db->prepare("update register set vaccine=?,doses=?,doneDoses=?,status='vacinated',location=? where cnic=? AND dob=? AND status='p-vacinated'");
// Error Handling required
$stmt->execute([$vaccine, $totalDoses, $doneDoses, $loc, $cnic, $dob]);
return true;
} else {
$stmt = $this->db->prepare("update register set vaccine=?,doses=?,doneDoses=?,status='p-vacinated' where cnic=? AND dob=? AND status='scheduled'");
$stmt->execute([$vaccine, $totalDoses, $doneDoses, $cnic, $dob]);
return true;
}
}
public function reject($cnic, $dob, $loc)
{
$stmt = $this->db->prepare("update register set status='rejected',vaccine=null, doses=null,doneDoses=null,location=? where cnic=? AND dob=?");
// Error Handling required
$stmt->execute([$loc, $cnic, $dob]);
return true;
}
public function getVaccineList()
{
$stmt = $this->db->prepare("select * from vaccine");
$stmt->execute();
return $stmt->fetchAll();
}
public function getLocationsList()
{
$stmt = $this->db->prepare("select * from location");
$stmt->execute();
return $stmt->fetchAll();
}
public function getCenterName($loc)
{
$stmt = $this->db->prepare("select location.name from location where shortname =?");
$stmt->execute([$loc]);
return $stmt->fetchAll();
}
public function rejected()
{
$stmt = $this->db->prepare("SELECT * FROM register WHERE status='rejected' ");
$stmt->execute();
return $stmt->fetchAll();
}
public function perform($code, $option)
{
$stmt = $this->db->prepare("UPDATE register SET status=$option WHERE id=$code");
$stmt->execute();
return $stmt->fetchAll();
}
public function vaccinated()
{
$stmt = $this->db->prepare("SELECT * FROM register WHERE status='vaccinated' ");
$stmt->execute();
return $stmt->fetchAll();
}
public function getReportById($id)
{
$stmt = $this->db->prepare("SELECT * FROM register WHERE ID=?");
$stmt->execute([$id]);
return $stmt->fetchAll();
}
public function getEmployees()
{
$stmt = $this->db->prepare("SELECT * FROM employeedetails");
$stmt->execute();
return $stmt->fetchAll();
}
public function add_location($location,$short_name)
{
$stmt = $this->db->prepare("INSERT INTO location (`name`, `shortname`)"
. "VALUES (?,?)");
$stmt->execute([$location,$short_name]);
return true;
}
public function add_vaccine($vName,$doeses)
{
$stmt = $this->db->prepare("INSERT INTO vaccine (`vName`, `doses`)"
. "VALUES (?,?)");
$stmt->execute([$vName,$doeses]);
return true;
}
public function remove_vaccine($id)
{
$stmt = $this->db->prepare("DELETE FROM vaccine WHERE id=$id");
$stmt->execute();
return true;
}
public function remove_location($id)
{
$stmt = $this->db->prepare("DELETE FROM location WHERE id=$id");
$stmt->execute();
return true;
}
public function remove_employee($id)
{
$stmt = $this->db->prepare("DELETE FROM employeedetails WHERE ID=$id");
$stmt->execute();
return true;
}
}