-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtambah_surat_keluar.php
341 lines (310 loc) · 20.7 KB
/
tambah_surat_keluar.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
<?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['tujuan'] == "" || $_REQUEST['isi'] == ""
|| $_REQUEST['kode'] == "" || $_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'];
$tujuan = $_REQUEST['tujuan'];
$isi = $_REQUEST['isi'];
$kode = substr($_REQUEST['kode'],0,30);
$nkode = trim($kode);
$tgl_surat = $_REQUEST['tgl_surat'];
$keterangan = $_REQUEST['keterangan'];
$id_user = $_SESSION['id_user'];
//validasi input data
if(!preg_match("/^[0-9]*$/", $no_agenda)){
$_SESSION['no_agendak'] = '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['no_suratk'] = '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.,() \/ -]*$/", $tujuan)){
$_SESSION['tujuan_surat'] = 'Form Tujuan 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['isik'] = '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['kodek'] = '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("/^[0-9.-]*$/", $tgl_surat)){
$_SESSION['tgl_suratk'] = '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['keterangank'] = '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 {
$cek = mysqli_query($config, "SELECT * FROM tbl_surat_keluar WHERE no_surat='$no_surat'");
$result = mysqli_num_rows($cek);
if($result > 0){
$_SESSION['errDup'] = 'Nomor Surat sudah terpakai, gunakan yang lain!';
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_keluar/";
if (! is_dir($target_dir)) {
mkdir($target_dir, 0755, true);
}
//jika form file tidak kosong akan mengekse
if($file != ""){
$rand = rand(1,10000);
$nfile = $rand."-".$file;
if(in_array($eks, $ekstensi) == true){
if($ukuran < 2500000){
move_uploaded_file($_FILES['file']['tmp_name'], $target_dir.$nfile);
$query = mysqli_query($config, "INSERT INTO tbl_surat_keluar(no_agenda,tujuan,no_surat,isi,kode,tgl_surat,
tgl_catat,file,keterangan,id_user)
VALUES('$no_agenda','$tujuan','$no_surat','$isi','$nkode','$tgl_surat',NOW(),'$nfile','$keterangan','$id_user')");
if($query == true){
$_SESSION['succAdd'] = 'SUKSES! Data berhasil ditambahkan';
header("Location: ./admin.php?page=tsk");
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 {
$query = mysqli_query($config, "INSERT INTO tbl_surat_keluar(no_agenda,tujuan,no_surat,isi,kode,tgl_surat,
tgl_catat,file,keterangan,id_user)
VALUES('$no_agenda','$tujuan','$no_surat','$isi','$nkode','$tgl_surat',NOW(),'','$keterangan','$id_user')");
if($query == true){
$_SESSION['succAdd'] = 'SUKSES! Data berhasil ditambahkan';
header("Location: ./admin.php?page=tsk");
die();
} else {
$_SESSION['errQ'] = 'ERROR! Ada masalah dengan query';
echo '<script language="javascript">window.history.back();</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="?page=tsk&act=add" class="judul"><i class="material-icons">drafts</i> Tambah Data Surat Keluar</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=tsk&act=add" enctype="multipart/form-data">
<!-- Row in form START -->
<div class="row">
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">looks_one</i>
<?php
echo '<input id="no_agenda" type="number" class="validate" name="no_agenda" value="';
$sql = mysqli_query($config, "SELECT no_agenda FROM tbl_surat_keluar");
$no_agenda = "1";
if (mysqli_num_rows($sql) == 0){
echo $no_agenda;
}
$result = mysqli_num_rows($sql);
$counter = 0;
while(list($no_agenda) = mysqli_fetch_array($sql)){
if (++$counter == $result) {
$no_agenda++;
echo $no_agenda;
}
}
echo '" required>';
if(isset($_SESSION['no_agendak'])){
$no_agendak = $_SESSION['no_agendak'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$no_agendak.'</div>';
unset($_SESSION['no_agendak']);
}
?>
<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" required>
<?php
if(isset($_SESSION['kodek'])){
$kodek = $_SESSION['kodek'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$kodek.'</div>';
unset($_SESSION['kodek']);
}
?>
<label for="kode">Kode Klasifikasi</label>
</div>
<div class="input-field col s6">
<i class="material-icons prefix md-prefix">place</i>
<input id="tujuan" type="text" class="validate" name="tujuan" required>
<?php
if(isset($_SESSION['tujuan_surat'])){
$tujuan_surat = $_SESSION['tujuan_surat'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$tujuan_surat.'</div>';
unset($_SESSION['tujuan_surat']);
}
?>
<label for="tujuan">Tujuan Surat</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" required>
<?php
if(isset($_SESSION['no_suratk'])){
$no_suratk = $_SESSION['no_suratk'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$no_suratk.'</div>';
unset($_SESSION['no_suratk']);
}
if(isset($_SESSION['errDup'])){
$errDup = $_SESSION['errDup'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$errDup.'</div>';
unset($_SESSION['errDup']);
}
?>
<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" required>
<?php
if(isset($_SESSION['tgl_suratk'])){
$tgl_suratk = $_SESSION['tgl_suratk'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$tgl_suratk.'</div>';
unset($_SESSION['tgl_suratk']);
}
?>
<label for="tgl_surat">Tanggal Surat</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" required>
<?php
if(isset($_SESSION['keterangank'])){
$keterangank = $_SESSION['keterangank'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$keterangank.'</div>';
unset($_SESSION['keterangank']);
}
?>
<label for="keterangan">Keterangan</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></textarea>
<?php
if(isset($_SESSION['isik'])){
$isik = $_SESSION['isik'];
echo '<div id="alert-message" class="callout bottom z-depth-1 red lighten-4 red-text">'.$isik.'</div>';
unset($_SESSION['isik']);
}
?>
<label for="isi">Isi Ringkas</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" placeholder="Upload file/scan gambar surat keluar">
<?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=tsk" 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
}
}
?>