-
Notifications
You must be signed in to change notification settings - Fork 1
/
profil.php
337 lines (299 loc) · 14.8 KB
/
profil.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
// panggil koneksi db
require "db.php";
// panggil file functions.php
require "functions.php";
// aktifkan session
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profil</title>
<?php require "headtags.php" ?>
</head>
<body>
<!-- navbar -->
<?php require "navbar.php" ?>
<div class="container mt-5">
<div class="card col-md-6 offset-md-3">
<div class="card-header text-center">
<h3>Profil</h3>
</div>
<div class="card-body">
<form action="" method="POST" enctype="multipart/form-data">
<?php
if (isset($_SESSION["admin"])) :
$admin = mysqli_query($db,"SELECT * FROM admin");
$admin = mysqli_fetch_assoc($admin);
?>
<div class="form-group text-center">
<label for="email">Email</label>
<input type="email" id="email" name="email" placeholder="Email" class="form-control" value="<?= $admin['email'] ?>">
</div>
<?php
elseif (isset($_SESSION["perusahaan"])) :
$email = $_SESSION['perusahaan'];
$perusahaan = mysqli_query($db,"SELECT * FROM perusahaan WHERE email = '$email'");
$perusahaan = mysqli_fetch_assoc($perusahaan);
?>
<!-- image -->
<div class="row my-3">
<div class="col text-center">
<img src="assets/perusahaan/<?= $perusahaan['foto'] ?>" alt="" class="rounded img-fluid" width=35% style="max-width:200px">
</div>
</div>
<!-- end image -->
<!-- input file -->
<div class="row">
<div class="col-md-6 offset-md-3 active mt-3">
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" name="foto" class="custom-file-input" id="name" aria-describedby="name">
<label class="custom-file-label" for="name">Foto Profil</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Nama Perusahaan" name="nama" value="<?= $perusahaan['nama'] ?>">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" name="email" value="<?= $perusahaan['email'] ?>">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Nomor Telp" name="telp" value="<?= $perusahaan['telp'] ?>">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Kota / Kabupaten" name="kota" value="<?= $perusahaan['kota'] ?>">
</div>
<div class="form-group">
<textarea type="text" class="form-control" placeholder="Alamat Lengkap" name="alamat"><?= $perusahaan['alamat'] ?></textarea>
</div>
<div class="form-group">
<textarea type="password" class="form-control" placeholder="Deskripsi Perusahaan" name="deskripsi"><?= $perusahaan['deskripsi'] ?></textarea>
</div>
<?php
elseif (isset($_SESSION["pelamar"])) :
$email = $_SESSION['pelamar'];
$pelamar = mysqli_query($db,"SELECT * FROM pelamar WHERE email = '$email'");
$pelamar = mysqli_fetch_assoc($pelamar);
?>
<!-- image -->
<div class="row my-3">
<div class="col text-center">
<img src="assets/pelamar/<?= $pelamar['foto'] ?>" alt="" class="rounded img-fluid" width=35% style="max-width:200px">
</div>
</div>
<!-- end image -->
<!-- input file -->
<div class="row">
<div class="col-md-6 offset-md-3 active mt-3">
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" name="foto" class="custom-file-input" id="name" aria-describedby="name">
<label class="custom-file-label" for="name">Foto Profil</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Nama Lengkap" name="nama" value="<?= $pelamar['nama'] ?>">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" name="email" value="<?= $pelamar['email'] ?>">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Nomor Telp" name="telp" value="<?= $pelamar['telp'] ?>">
</div>
<div class="form-group">
<select id="" class="form-control" name="gender">
<?php if ($pelamar["gender"] == "pria") : ?>
<option value="pria" selected>Laki-Laki</option>
<option value="wanita">Perempuan</option>
<?php else : ?>
<option value="pria">Laki-Laki</option>
<option value="wanita" selected>Perempuan</option>
<?php endif; ?>
</select>
</div>
<div class="form-group" name="alamat">
<textarea type="text" class="form-control" placeholder="Alamat Lengkap" name="alamat"><?= $pelamar['alamat'] ?></textarea>
</div>
<?php
endif;
?>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary" name="simpanData">Simpan Data</button> <a href="ganti-password.php" class="btn btn-danger">Ganti Password</a>
</div>
</form>
</div>
</div>
</div>
<!-- footer -->
<?php
include 'footer.php'
?>
</body>
</html>
<?php
// cek apakah sudah login atau belum
cekBelumLogin();
// jika melakukan perubahan profil
if (isset($_POST["simpanData"])) {
// jika role user = admin
if (isset($_SESSION["admin"])){
// ambil isi form
$email = htmlspecialchars($_POST["email"]);
// update db
mysqli_query($db, "UPDATE admin SET email = '$email'");
// alert
echo "
<script>
Swal.fire('SUCCESS','Perubahan Berhasil Disimpan','success').then(function(){
window.location = 'profil.php';
});
</script>
";
}else if (isset($_SESSION["perusahaan"])){ // jika role user = perusahaan
if (strlen($_FILES["foto"]["name"]) > 0){
$ukuranFile = $_FILES["foto"]["size"];
$temp = $_FILES["foto"]["tmp_name"];
$namaFile = $_FILES["foto"]["name"];
$error = $_FILES["foto"]["error"];
//cek apakah file adalah gambar
$ekstensiGambarValid = ['jpg','jpeg','png','pdf','doc','docx'];
// explode = memecah string menjadi array (dg pemisah delimiter)
$ekstensiGambar = explode('.',$namaFile);
//mengambil ekstensi gambar yg paling belakang dg strltolower (mengecilkan semua huruf)
$ekstensiGambar = strtolower(end($ekstensiGambar));
//CEK $ekstensiGambar ada di array $ekstensiGambarValid
if (!in_array($ekstensiGambar,$ekstensiGambarValid) ){
echo "
<script>
Swal.fire('Gagal Upload Foto Profil','Format File Tidak Valid','warning').then(function(){
window.location = 'profil.php';
});
</script>
";
}else if ( $ukuranFile > 3000000 ) { // cek ukuran max 3000000 byte atau 3 mb
echo "
<script>
Swal.fire('Gagal Upload Foto Profil','Ukuran Gambar Telalu Besar','warning').then(function(){
window.location = 'profil.php';
});
</script>
";
}
//generate nama baru
$namaFileBaru = 'perusahaan' . $perusahaan['id'] . '.' . $ekstensiGambar;
move_uploaded_file($temp,'assets/perusahaan/'.$namaFileBaru);
}else{
$namaFileBaru = $perusahaan["foto"];
}
// ambil data email
$emailLama = $_SESSION["perusahaan"];
// ambil isi form
$nama = htmlspecialchars($_POST["nama"]);
$email = htmlspecialchars($_POST["email"]);
$telp = htmlspecialchars($_POST["telp"]);
$kota = htmlspecialchars($_POST["kota"]);
$alamat = htmlspecialchars($_POST["alamat"]);
$deskripsi = htmlspecialchars($_POST["deskripsi"]);
// validasi form
if (cekKosong($email) == true) {
if (validasiNama($nama) == true){
if (validasiTelp($telp) == true) {
if (validasiKota($kota) == true){
if (validasiAlamat($alamat) == true) {
if (validasiDeskripsi($deskripsi) == true){
//LOLOS CEK BROOO
// update db
mysqli_query($db,"UPDATE perusahaan SET foto = '$namaFileBaru', nama = '$nama', email = '$email', telp = '$telp', kota = '$kota', alamat = '$alamat', deskripsi = '$deskripsi' WHERE email = '$emailLama'");
// ubah nilai session
$_SESSION["perusahaan"] = $email;
// alert
echo "
<script>
Swal.fire('UPDATE PROFIL BERHASIL','','success').then(function(){
window.location = 'profil.php';
});
</script>
";
}
}
}
}
}
}
}else if ($_SESSION["pelamar"]){ // jika role user = pelamar
// jika upload foto
if (strlen($_FILES["foto"]["name"]) > 0){
$ukuranFile = $_FILES["foto"]["size"];
$temp = $_FILES["foto"]["tmp_name"];
$namaFile = $_FILES["foto"]["name"];
$error = $_FILES["foto"]["error"];
//cek apakah file adalah gambar
$ekstensiGambarValid = ['jpg','jpeg','png','pdf','doc','docx'];
// explode = memecah string menjadi array (dg pemisah delimiter)
$ekstensiGambar = explode('.',$namaFile);
//mengambil ekstensi gambar yg paling belakang dg strltolower (mengecilkan semua huruf)
$ekstensiGambar = strtolower(end($ekstensiGambar));
//CEK $ekstensiGambar ada di array $ekstensiGambarValid
if (!in_array($ekstensiGambar,$ekstensiGambarValid) ){
echo "
<script>
Swal.fire('Gagal Upload Foto Profil','Format File Tidak Valid','warning').then(function(){
window.location = 'profil.php';
});
</script>
";
}else if ( $ukuranFile > 3000000 ) { // cek ukuran max 3000000 byte atau 3 mb
echo "
<script>
Swal.fire('Gagal Upload Foto Profil','Ukuran Gambar Telalu Besar','warning').then(function(){
window.location = 'profil.php';
});
</script>
";
}
//generate nama baru
$namaFileBaru = 'pelamar' . $pelamar['id'] . '.' . $ekstensiGambar;
move_uploaded_file($temp,'assets/pelamar/'.$namaFileBaru);
}else{
$namaFileBaru = $pelamar["foto"];
}
// ambil data email
$emailLama = $_SESSION["pelamar"];
// ambil isi form
$nama = htmlspecialchars($_POST["nama"]);
$email = htmlspecialchars($_POST["email"]);
$telp = htmlspecialchars($_POST["telp"]);
$gender = htmlspecialchars($_POST["gender"]);
$alamat = htmlspecialchars($_POST["alamat"]);
// validasi form
if (cekKosong($email)== true){
if (validasiNama($nama) == true){
if (validasiTelp($telp) == true){
if (validasiAlamat($alamat) == true){
// update db
mysqli_query($db,"UPDATE pelamar SET foto = '$namaFileBaru', nama = '$nama', email = '$email', telp = '$telp', gender = '$gender', alamat = '$alamat' WHERE email = '$emailLama'");
// ubah nilai session
$_SESSION["pelamar"] = $email;
// alert
echo "
<script>
Swal.fire('SUCCESS','Perubahan Berhasil Disimpan','success').then(function(){
window.location = 'profil.php';
});
</script>
";
}
}
}
}
}
}
?>