-
Notifications
You must be signed in to change notification settings - Fork 3
/
function.php
244 lines (187 loc) · 7.54 KB
/
function.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
<?php
$config = mysqli_connect("localhost", "root", "", "absensi") or die;
function add($data) {
global $config;
$nama = htmlspecialchars($data["nama"]);
$emailSign = mysqli_real_escape_string($config, htmlspecialchars($data["emailSign"]));
$passwordSign = htmlspecialchars($data["passwordSign"]);
$id_level = $data["id_level"];
$passwordSign = password_hash($passwordSign, PASSWORD_DEFAULT);
$result = mysqli_query($config, "SELECT * FROM tb_users WHERE email = '$emailSign' ");
if (mysqli_num_rows($result) == 1) {
return false;
}
$query = "INSERT INTO tb_users (nama, email, password, id_level)
VALUES ('$nama', '$emailSign', '$passwordSign', '$id_level')
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function hapusUsers($id) {
global $config;
$result = mysqli_query($config, "SELECT * FROM pekerja INNER JOIN tb_users ON tb_users.id = pekerja.users_id WHERE users_id = $id");
$data = mysqli_fetch_assoc($result);
$users = $data["photo"];
$query = "DELETE FROM tb_users WHERE id = $id";
mysqli_query($config, $query);
unlink("../assets/image/".$users);
return mysqli_affected_rows($config);
}
function login($data) {
global $config;
$email = mysqli_real_escape_string($config, htmlspecialchars($_POST["email"]));
$password = htmlspecialchars($_POST["password"]);
$result = mysqli_query($config, "SELECT * FROM tb_users WHERE email = '$email'");
if(mysqli_num_rows($result) == 1 ) {
$row = mysqli_fetch_assoc($result);
if(password_verify($password, $row["password"])) {
if($row["id_level"] == 2) {
session_start();
$_SESSION["email"] = $row["email"];
$_SESSION["nama"] = $row["nama"];
$_SESSION["id"] = $row["id"];
$_SESSION["password"] = $row["password"];
header("Location: home.php");
exit;
} else if($row["id_level"] == 1) {
session_start();
$_SESSION["nama"] = $row["nama"];
$_SESSION["email"] = $row["email"];
$_SESSION["id"] = $row["id"];
$_SESSION["password"] = $row["password"];
header("Location: admin/admin.php");
exit;
}
}
}
}
function addKegiatan($data) {
global $config;
$users_id = htmlspecialchars($data["users_id"]);
$namaKegiatan = htmlspecialchars($data["kegiatan"]);
$tgl_kegiatan = htmlspecialchars($data["tgl_kegiatan"]);
$jam = htmlspecialchars($data["jam"]);
$query = "INSERT INTO kegiatan (users_id, kegiatan, tgl_kegiatan, jam)
VALUES
('$users_id', '$namaKegiatan','$tgl_kegiatan', '$jam')
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function query($query) {
global $config;
$result = mysqli_query($config, $query);
$rows = [];
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
function delete($id) {
global $config;
$query = "DELETE FROM kegiatan WHERE kegiatan_id = $id";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function updateKegiatan($data) {
global $config;
$id = $data["kegiatan_id"];
$users_id = htmlspecialchars($data["users_id"]);
$nameKegiatan = htmlspecialchars($data["kegiatan"]);
$tgl_kegiatan = htmlspecialchars($data["tgl_kegiatan"]);
$jam = htmlspecialchars($data["jam"]);
$query = "UPDATE kegiatan SET users_id = $users_id, kegiatan = '$nameKegiatan', tgl_kegiatan = '$tgl_kegiatan', jam = '$jam' WHERE kegiatan_id = $id";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function addProfil($data) {
global $config;
$users_id = $data["users_id"];
$id_jk = $data["id_jk"];
$id_jabatan = $data["id_jabatan"];
$photo = upload();
if( !$photo ) {
// echo $errors["photo"] = "silahkan upload photo";
return false;
}
$query = "INSERT INTO pekerja (users_id, id_jk, id_jabatan, photo)
VALUES
('$users_id','$id_jk','$id_jabatan', '$photo')
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function upload() {
$namaFile = $_FILES["photo"]["name"];
$sizeFile = $_FILES["photo"]["size"];
$tmpName = $_FILES["photo"]["tmp_name"];
$error = $_FILES["photo"]["error"];
if($error === 4) {
echo $errors["photo"] = "silahkan upload terlebih dahulu";
return false;
}
$fileValid = ['jpg', 'jpeg','png'];
$extensiValid = explode(".", $namaFile);
$extensiValid = strtolower(end($extensiValid) );
if(!in_array($extensiValid, $fileValid)) {
echo "yang anda upload bukan gambar";
return false;
}
if($sizeFile > 1000000) {
echo "ukuran file terlalu besar";
return false;
}
$namaFileBaru = uniqid();
$namaFileBaru .= ".";
$namaFileBaru .= $extensiValid;
// move_uploaded_file($tmpName, 'assets/image/'. $namaFileBaru );
if(!move_uploaded_file($tmpName, 'assets/image/'. $namaFileBaru)) {
move_uploaded_file($tmpName, '../assets/image/'. $namaFileBaru);
}
return $namaFileBaru;
}
function addJabatan($data) {
global $config;
$jabatan_name = htmlspecialchars($data["jabatan_name"]);
$query = "INSERT INTO jabatan (jabatan_name)
VALUES
('$jabatan_name');
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function hapusJabatan($id) {
global $config;
$query = "DELETE FROM jabatan WHERE id =$id ";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function absenMasuk($data) {
global $config;
$users_id = $data["users_id"];
$jam_masuk = $data["jam_masuk"];
$query = "INSERT INTO absen (users_id, jam_masuk)
VALUES
('$users_id', '$jam_masuk')
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function absenPulang($data) {
global $config;
$absen_id = $data["absen_id"];
$users_id = $data["users_id"];
$jam_masuk = $data["jam_masuk"];
$jam_pulang = $data["jam_pulang"];
$query = "UPDATE absen SET users_id = '$users_id', jam_masuk = '$jam_masuk', jam_pulang = '$jam_pulang' WHERE absen_id = $absen_id;
";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
function hapusAbsen($id) {
global $config;
$query = "DELETE FROM absen WHERE absen_id = $id";
mysqli_query($config, $query);
return mysqli_affected_rows($config);
}
?>