-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathedit_surat_masuk.php
369 lines (331 loc) · 23.4 KB
/
edit_surat_masuk.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
//cek session
if(empty($_SESSION['admin'])){
$_SESSION['err'] = '<center>Anda harus login terlebih dahulu!</center>';
header("Location: ./");
die();
} else {
if(isset($_REQUEST['submit'])){
//validasi form kosong
if($_REQUEST['no_agenda'] == "" || $_REQUEST['no_surat'] == "" || $_REQUEST['asal_surat'] == "" || $_REQUEST['isi'] == ""
|| $_REQUEST['kode'] == "" || $_REQUEST['indeks'] == "" || $_REQUEST['tgl_surat'] == "" || $_REQUEST['keterangan'] == ""){
$_SESSION['errEmpty'] = 'ERROR! Semua form wajib diisi';
echo '<script language="javascript">window.history.back();</script>';
} else {
$no_agenda = $_REQUEST['no_agenda'];
$no_surat = $_REQUEST['no_surat'];
$asal_surat = $_REQUEST['asal_surat'];
$isi = $_REQUEST['isi'];
$kode = substr($_REQUEST['kode'],0,30);
$nkode = trim($kode);
$indeks = $_REQUEST['indeks'];
$tgl_surat = $_REQUEST['tgl_surat'];
$keterangan = $_REQUEST['keterangan'];
$id_user = $_SESSION['id_user'];
//validasi input data
if(!preg_match("/^[0-9]*$/", $no_agenda)){
$_SESSION['eno_agenda'] = 'Form Nomor Agenda harus diisi angka!';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9.\/ -]*$/", $no_surat)){
$_SESSION['eno_surat'] = 'Form No Surat hanya boleh mengandung karakter huruf, angka, spasi, titik(.), minus(-) dan garis miring(/)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9.,() \/ -]*$/", $asal_surat)){
$_SESSION['easal_surat'] = 'Form Asal Surat hanya boleh mengandung karakter huruf, angka, spasi, titik(.), koma(,), minus(-),kurung() dan garis miring(/)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9.,_()%&@\/\r\n -]*$/", $isi)){
$_SESSION['eisi'] = 'Form Isi Ringkas hanya boleh mengandung karakter huruf, angka, spasi, titik(.), koma(,), minus(-), garis miring(/), kurung(), underscore(_), dan(&) persen(%) dan at(@)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9., ]*$/", $nkode)){
$_SESSION['ekode'] = 'Form Kode Klasifikasi hanya boleh mengandung karakter huruf, angka, spasi, titik(.) dan koma(,)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9., -]*$/", $indeks)){
$_SESSION['eindeks'] = 'Form Indeks hanya boleh mengandung karakter huruf, angka, spasi, titik(.) dan koma(,) dan minus (-)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[0-9.-]*$/", $tgl_surat)){
$_SESSION['etgl_surat'] = 'Form Tanggal Surat hanya boleh mengandung angka dan minus(-)';
echo '<script language="javascript">window.history.back();</script>';
} else {
if(!preg_match("/^[a-zA-Z0-9.,()\/ -]*$/", $keterangan)){
$_SESSION['eketerangan'] = 'Form Keterangan hanya boleh mengandung karakter huruf, angka, spasi, titik(.), koma(,), minus(-), garis miring(/), dan kurung()';
echo '<script language="javascript">window.history.back();</script>';
} else {
$ekstensi = array('jpg','png','jpeg','doc','docx','pdf');
$file = $_FILES['file']['name'];
$x = explode('.', $file);
$eks = strtolower(end($x));
$ukuran = $_FILES['file']['size'];
$target_dir = "upload/surat_masuk/";
if (! is_dir($target_dir)) {
mkdir($target_dir, 0755, true);
}
//jika form file tidak kosong akan mengeksekusi script dibawah ini
if($file != ""){
$rand = rand(1,10000);
$nfile = $rand."-".$file;
//validasi file
if(in_array($eks, $ekstensi) == true){
if($ukuran < 2300000){
$id_surat = $_REQUEST['id_surat'];
$query = mysqli_query($config, "SELECT file FROM tbl_surat_masuk WHERE id_surat='$id_surat'");
list($file) = mysqli_fetch_array($query);
//jika file tidak kosong akan mengeksekusi script dibawah ini
if(!empty($file)){
unlink($target_dir.$file);
move_uploaded_file($_FILES['file']['tmp_name'], $target_dir.$nfile);
$query = mysqli_query($config, "UPDATE tbl_surat_masuk SET no_agenda='$no_agenda',no_surat='$no_surat',asal_surat='$asal_surat',isi='$isi',kode='$nkode',indeks='$indeks',tgl_surat='$tgl_surat',file='$nfile',keterangan='$keterangan',id_user='$id_user' WHERE id_surat='$id_surat'");
if($query == true){
$_SESSION['succEdit'] = 'SUKSES! Data berhasil diupdate';
header("Location: ./admin.php?page=tsm");
die();
} else {
$_SESSION['errQ'] = 'ERROR! Ada masalah dengan query';
echo '<script language="javascript">window.history.back();</script>';
}
} else {
//jika file kosong akan mengeksekusi script dibawah ini
move_uploaded_file($_FILES['file']['tmp_name'], $target_dir.$nfile);
$query = mysqli_query($config, "UPDATE tbl_surat_masuk SET no_agenda='$no_agenda',no_surat='$no_surat',asal_surat='$asal_surat',isi='$isi',kode='$nkode',indeks='$indeks',tgl_surat='$tgl_surat',file='$nfile',keterangan='$keterangan',id_user='$id_user' WHERE id_surat='$id_surat'");
if($query == true){
$_SESSION['succEdit'] = 'SUKSES! Data berhasil diupdate';
header("Location: ./admin.php?page=tsm");
die();
} else {
$_SESSION['errQ'] = 'ERROR! Ada masalah dengan query';
echo '<script language="javascript">window.history.back();</script>';
}
}
} else {
$_SESSION['errSize'] = 'Ukuran file yang diupload terlalu besar!';
echo '<script language="javascript">window.history.back();</script>';
}
} else {
$_SESSION['errFormat'] = 'Format file yang diperbolehkan hanya *.JPG, *.PNG, *.DOC, *.DOCX atau *.PDF!';
echo '<script language="javascript">window.history.back();</script>';
}
} else {
//jika form file kosong akan mengeksekusi script dibawah ini
$id_surat = $_REQUEST['id_surat'];
$query = mysqli_query($config, "UPDATE tbl_surat_masuk SET no_agenda='$no_agenda',no_surat='$no_surat',asal_surat='$asal_surat',isi='$isi',kode='$nkode',indeks='$indeks',tgl_surat='$tgl_surat',keterangan='$keterangan',id_user='$id_user' WHERE id_surat='$id_surat'");
if($query == true){
$_SESSION['succEdit'] = 'SUKSES! Data berhasil diupdate';
header("Location: ./admin.php?page=tsm");
die();
} else {
$_SESSION['errQ'] = 'ERROR! Ada masalah dengan query';
echo '<script language="javascript">window.history.back();</script>';
}
}
}
}
}
}
}
}
}
}
}
} else {
$id_surat = mysqli_real_escape_string($config, $_REQUEST['id_surat']);
$query = mysqli_query($config, "SELECT id_surat, no_agenda, no_surat, asal_surat, isi, kode, indeks, tgl_surat, file, keterangan, id_user FROM tbl_surat_masuk WHERE id_surat='$id_surat'");
list($id_surat, $no_agenda, $no_surat, $asal_surat, $isi, $kode, $indeks, $tgl_surat, $file, $keterangan, $id_user) = mysqli_fetch_array($query);
if($_SESSION['id_user'] != $id_user AND $_SESSION['id_user'] != 1){
echo '<script language="javascript">
window.alert("ERROR! Anda tidak memiliki hak akses untuk mengedit data ini");
window.location.href="./admin.php?page=tsm";
</script>';
} else {?>
<!-- Row Start -->
<div class="row">
<!-- Secondary Nav START -->
<div class="col s12">
<nav class="secondary-nav">
<div class="nav-wrapper blue-grey darken-1">
<ul class="left">
<li class="waves-effect waves-light"><a href="#" class="judul"><i class="material-icons">edit</i> Edit Data Surat Masuk</a></li>
</ul>
</div>
</nav>
</div>
<!-- Secondary Nav END -->
</div>
<!-- Row END -->
<?php
if(isset($_SESSION['errQ'])){
$errQ = $_SESSION['errQ'];
echo '<div id="alert-message" class="row">
<div class="col m12">
<div class="card red lighten-5">
<div class="card-content notif">
<span class="card-title red-text"><i class="material-icons md-36">clear</i> '.$errQ.'</span>
</div>
</div>
</div>
</div>';
unset($_SESSION['errQ']);
}
if(isset($_SESSION['errEmpty'])){
$errEmpty = $_SESSION['errEmpty'];
echo '<div id="alert-message" class="row">
<div class="col m12">
<div class="card red lighten-5">
<div class="card-content notif">
<span class="card-title red-text"><i class="material-icons md-36">clear</i> '.$errEmpty.'</span>
</div>
</div>
</div>
</div>';
unset($_SESSION['errEmpty']);
}
?>
<!-- Row form Start -->
<div class="row jarak-form">
<!-- Form START -->
<form class="col s12" method="POST" action="?page=tsm&act=edit" enctype="multipart/form-data">
<!-- Row in form START -->
<div class="row">
<div class="input-field col s6">
<input type="hidden" name="id_surat" value="<?php echo $id_surat ;?>">
<i class="material-icons prefix md-prefix">looks_one</i>
<input id="no_agenda" type="number" class="validate" value="<?php echo $no_agenda ;?>" name="no_agenda" required>
<?php
if(isset($_SESSION['eno_agenda'])){
$eno_agenda = $_SESSION['eno_agenda'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$eno_agenda.'</div>';
unset($_SESSION['eno_agenda']);
}
?>
<label for="no_agenda">Nomor Agenda</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">bookmark</i>
<input id="kode" type="text" class="validate" name="kode" value="<?php echo $kode ;?>" required>
<?php
if(isset($_SESSION['ekode'])){
$ekode = $_SESSION['ekode'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$ekode.'</div>';
unset($_SESSION['ekode']);
}
?>
<label for="kode">Kode Klasifikasi</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">place</i>
<input id="asal_surat" type="text" class="validate" name="asal_surat" value="<?php echo $asal_surat ;?>" required>
<?php
if(isset($_SESSION['easal_surat'])){
$easal_surat = $_SESSION['easal_surat'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$easal_surat.'</div>';
unset($_SESSION['easal_surat']);
}
?>
<label for="asal_surat">Asal Surat</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">storage</i>
<input id="indeks" type="text" class="validate" name="indeks" value="<?php echo $indeks ;?>" required>
<?php
if(isset($_SESSION['eindeks'])){
$eindeks = $_SESSION['eindeks'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$eindeks.'</div>';
unset($_SESSION['eindeks']);
}
?>
<label for="indeks">Indeks Berkas</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">looks_two</i>
<input id="no_surat" type="text" class="validate" name="no_surat" value="<?php echo $no_surat ;?>" required>
<?php
if(isset($_SESSION['eno_surat'])){
$eno_surat = $_SESSION['eno_surat'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$eno_surat.'</div>';
unset($_SESSION['eno_surat']);
}
?>
<label for="no_surat">Nomor Surat</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">date_range</i>
<input id="tgl_surat" type="text" name="tgl_surat" class="datepicker" value="<?php echo $tgl_surat ;?>" required>
<?php
if(isset($_SESSION['etgl_surat'])){
$etgl_surat = $_SESSION['etgl_surat'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$etgl_surat.'</div>';
unset($_SESSION['etgl_surat']);
}
?>
<label for="tgl_surat">Tanggal Surat</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">description</i>
<textarea id="isi" class="materialize-textarea validate" name="isi" required><?php echo $isi ;?></textarea>
<?php
if(isset($_SESSION['eisi'])){
$eisi = $_SESSION['eisi'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$eisi.'</div>';
unset($_SESSION['eisi']);
}
?>
<label for="isi">Isi Ringkas</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">featured_play_list</i>
<input id="keterangan" type="text" class="validate" name="keterangan" value="<?php echo $keterangan ;?>" required>
<?php
if(isset($_SESSION['eketerangan'])){
$eketerangan = $_SESSION['eketerangan'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$eketerangan.'</div>';
unset($_SESSION['eketerangan']);
}
?>
<label for="keterangan">Keterangan</label>
</div>
<div class="input-field col s6">
<div class="file-field input-field">
<div class="btn light-green darken-1">
<span>File</span>
<input type="file" id="file" name="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" value="<?php echo $file ;?>" placeholder="Upload file/scan gambar surat masuk">
<?php
if(isset($_SESSION['errSize'])){
$errSize = $_SESSION['errSize'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$errSize.'</div>';
unset($_SESSION['errSize']);
}
if(isset($_SESSION['errFormat'])){
$errFormat = $_SESSION['errFormat'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$errFormat.'</div>';
unset($_SESSION['errFormat']);
}
?>
<small class="red-text">*Format file yang diperbolehkan *.JPG, *.PNG, *.DOC, *.DOCX, *.PDF dan ukuran maksimal file 2 MB!</small>
</div>
</div>
</div>
</div>
<!-- Row in form END -->
<div class="row">
<div class="col 6">
<button type="submit" name="submit" class="btn-large blue waves-effect waves-light">SIMPAN <i class="material-icons">done</i></button>
</div>
<div class="col 6">
<a href="?page=tsm" class="btn-large deep-orange waves-effect waves-light">BATAL <i class="material-icons">clear</i></a>
</div>
</div>
</form>
<!-- Form END -->
</div>
<!-- Row form END -->
<?php
}
}
}
?>