-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathagen.php
212 lines (178 loc) · 6.61 KB
/
agen.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
<?php
session_start();
include 'connect-db.php';
include 'functions/functions.php';
// harus agen yg kesini
cekAgen();
// ambil data agen
$idAgen = $_SESSION["agen"];
$query = "SELECT * FROM agen WHERE id_agen = '$idAgen'";
$result = mysqli_query($connect, $query);
$agen = mysqli_fetch_assoc($result);
$idAgen = $agen["id_agen"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include 'headtags.html'; ?>
<title>Profil Agen</title>
</head>
<body>
<!-- header -->
<?php include 'header.php'; ?>
<!-- end header -->
<!-- data agen -->
<div class="row">
<div class="col s6 offset-s3">
<h3 class="header light center">Data Agen</h3>
<br><br>
<form action="" method="post" enctype="multipart/form-data">
<div class="center">
<img src="img/agen/<?= $agen['foto'] ?>" class="circle responsive-img" width=25% alt="">
</div>
<div class="file-field input-field">
<div class="btn blue darken-2">
<span>Foto Profil</span>
<input type="file" name="foto" id="foto">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload foto profil">
</div>
</div>
<div class="input-field">
<ul>
<li>
<label for="namaLaundry">Nama Laundry</label>
<input type="text" id="namaLaundry" name="namaLaundry" value="<?= $agen['nama_laundry']?>">
</li>
<li>
<label for="namaPemilik">Nama Pemilik</label>
<input type="text" id="namaPemilik" name="namaPemilik" value="<?= $agen['nama_pemilik']?>">
</li>
<li>
<label for="email">Email</label>
<input type="text" id="email" name="email" value="<?= $agen['email']?>">
</li>
<li>
<label for="telp">No Telp</label>
<input type="text" id="telp" name="telp" value="<?= $agen['telp']?>">
</li>
<li>
<label for="plat">Plat Driver</label>
<input type="text" id="plat" name="platDriver" value="<?= $agen['plat_driver']?>">
</li>
<li>
<label for="kota">Kota / Kabupaten</label>
<input type="text" name="kota" value="<?= $agen['kota']?>">
</li>
<li>
<label for="alamat">Alamat</label>
<textarea class="materialize-textarea" name="alamat"><?= $agen['alamat']?></textarea>
</li>
<li>
<div class="center">
<button class="btn-large blue darken-2" type="submit" name="simpan">Simpan Data</button>
</div>
</li>
</ul>
</div>
</form>
<div class="center">
<a class="btn red darken-2" href="ganti-kata-sandi.php">Ganti Kata Sandi</a>
<a class="btn red darken-2" href="edit-harga.php">Ganti Data Harga</a>
</div>
</div>
</div>
<!-- end data agen -->
<!-- footer -->
<?php include "footer.php"; ?>
<!-- end footer -->
</body>
</html>
<?php
// klo ubah data agen
if ( isset($_POST["simpan"]) ){
function uploadFoto(){
//data foto
$ukuranFile = $_FILES["foto"]["size"];
$temp = $_FILES["foto"]["tmp_name"];
$namaFile = $_FILES["foto"]["name"];
$error = $_FILES["foto"]["error"];
if ($namaFile == NULL){
return NULL;
exit;
}
//cek apakah file adalah gambar
$ekstensiGambarValid = ['jpg','jpeg','png'];
// 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('Masukkan Format Gambar','','warning');
</script>
";
return false;
exit;
}
//CEK ukuran file
if ( $ukuranFile > 3000000 ) {
echo "
<script>
Swal.fire('Ukuran Gambar Terlalu Besar','','warning');
</script>
";
return false;
exit;
}
//LOLOS CEK BROOO
//generate nama baru random
$namaFileBaru = uniqid() . '.' . $ekstensiGambar;
move_uploaded_file($temp,'img/agen/'.$namaFileBaru);
return $namaFileBaru;
}
//ambil data
$namaLaundry = htmlspecialchars($_POST["namaLaundry"]);
$namaPemilik = htmlspecialchars($_POST["namaPemilik"]);
$email = htmlspecialchars($_POST["email"]);
$telp = htmlspecialchars($_POST["telp"]);
$platDriver = htmlspecialchars($_POST["platDriver"]);
$kota = htmlspecialchars($_POST["kota"]);
$alamat = htmlspecialchars($_POST["alamat"]);
$foto = uploadFoto();
if ($foto == NULL){
$foto = $agen["foto"];
}
// validasi
validasiNama($namaPemilik);
validasiEmail($email);
validasiTelp($telp);
validasiNama($kota);
$query = "UPDATE agen SET
nama_laundry = '$namaLaundry',
nama_pemilik = '$namaPemilik',
email = '$email',
telp = '$telp',
kota = '$kota',
plat_driver = '$platDriver',
alamat = '$alamat',
foto = '$foto'
WHERE id_agen = $idAgen
";
mysqli_query($connect,$query);
if ( mysqli_affected_rows($connect) > 0){
echo "
<script>
Swal.fire('Data Berhasil Di Update','','success').then(function() {
window.location = 'agen.php';
});
</script>
";
}
}
?>