-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
1028 lines (792 loc) · 30.3 KB
/
functions.php
File metadata and controls
1028 lines (792 loc) · 30.3 KB
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// koneksi ke database
$conn = mysqli_connect("localhost", "root", "", "usecase_psi");
function query($query){
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while ($row = mysqli_fetch_assoc($result)){
$rows[] = $row;
}
return $rows;
}
function listFitur($id_aktor){
global $conn;
$sql = "SELECT * FROM `fitur` WHERE id_aktor = '$id_aktor'";
return query($sql);
}
function detailFitur($id_fitur){
global $conn;
$sql = "SELECT * FROM `fitur` INNER JOIN aktor ON fitur.id_aktor = aktor.id_aktor WHERE id_fitur = '$id_fitur'";
// echo $sql;die;
return query($sql);
}
function listAktor($id_sistem){
global $conn;
$sql = "SELECT * FROM `aktor` WHERE id_sistem = '$id_sistem'";
return query($sql);
}
function listSistem(){
global $conn;
$sql = "SELECT * FROM `sistem`";
return query($sql);
}
function tambahScenario($data, $id_fitur){
global $conn;
$namaFitur = htmlspecialchars(trim($data["nama-fitur"]));
$deskripsiFitur = htmlspecialchars(trim($data["deskripsi-fitur"]));
$kondisiAwal = htmlspecialchars(trim($data["kondisi-awal"]));
$kondisiAkhir = htmlspecialchars(trim($data["kondisi-akhir"]));
$scenarioNormal = htmlspecialchars(trim($data["scenario-normal"]));
$scenarioAlternatif = htmlspecialchars(trim($data["scenario-alternatif"]));
$scenarioException = htmlspecialchars(trim($data["scenario-exception"]));
$arraySN = explode(PHP_EOL,trim($scenarioNormal));
$arraySA = explode(PHP_EOL,trim($scenarioAlternatif));
$arraySE = explode(PHP_EOL,trim($scenarioException));
//tiap baris di textarea scenarionormal divek apakah punya @halaman_view
foreach ($arraySN as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key => $value2) {
if (strpos($value2, '@') !== false) {
//masukkan @halaman_view ke tabel 'view'
$sql = "SELECT * FROM `view` WHERE id_fitur = '$id_fitur'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord > 0){
$sql = "UPDATE `view` SET nama_view = '$value2' WHERE id_fitur = '$id_fitur'";
mysqli_query($conn, $sql);
$sql = "SELECT * FROM `view` WHERE id_fitur ='$id_fitur'";
$id_view = query($sql)[0]['id_view'];
// echo "Update " .$value2." ke tabel view";
// echo "<br>";
} else {
$sql = "INSERT INTO `view` (id_fitur, nama_view) VALUES ('$id_fitur', '$value2')";
mysqli_query($conn, $sql);
// echo "Masukkan " .$value2." ke tabel view";
// echo "<br>";
$id_view = mysqli_insert_id($conn);
}
}
}
}
foreach ($arraySN as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key2 => $value2) {
if (strpos($value2, '#') !== false) {
//ambil id @view yang barusan dimasukkan
//masukkan id view dan nama_component ke tabel component_view
$index_underscore = strpos($value2, '_');
$tipe_component = substr($value2, 0, $index_underscore);
if($tipe_component == '#form'){
$tipe_fix = 'Form';
} elseif ($tipe_component == '#tombol') {
$tipe_fix = 'Tombol';
} elseif ($tipe_component == '#tabel') {
$tipe_fix = 'Tabel';
} else {
$tipe_fix = 'Belum ditentukan';
}
$sql = "SELECT * FROM `component_view` WHERE nama_component = '$value2' AND id_view = '$id_view'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord == 0){
// echo "Masukkan ".$value2." ke tabel component view";
// echo "<br>";
$sql = "INSERT INTO `component_view` (id_view, nama_component, jenis_component) VALUES ('$id_view', '$value2', '$tipe_fix')";
mysqli_query($conn, $sql);
}
}
}
}
//tiap baris di textarea scenarioAlternatif divek apakah punya @halaman_view
foreach ($arraySA as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key => $value2) {
if (strpos($value2, '@') !== false) {
//masukkan @halaman_view ke tabel 'view'
$sql = "SELECT * FROM `view` WHERE id_fitur = '$id_fitur'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord > 0){
$sql = "UPDATE `view` SET nama_view = '$value2' WHERE id_fitur = '$id_fitur'";
mysqli_query($conn, $sql);
$sql = "SELECT * FROM `view` WHERE id_fitur ='$id_fitur'";
$id_view = query($sql)[0]['id_view'];
// echo "Update " .$value2." ke tabel view";
// echo "<br>";
} else {
$sql = "INSERT INTO `view` (id_fitur, nama_view) VALUES ('$id_fitur', '$value2')";
mysqli_query($conn, $sql);
// echo "Masukkan " .$value2." ke tabel view";
// echo "<br>";
$id_view = mysqli_insert_id($conn);
}
}
}
}
foreach ($arraySA as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key2 => $value2) {
# code...
if (strpos($value2, '#') !== false) {
//ambil id @view yang barusan dimasukkan
//masukkan id view dan nama_component ke tabel component_view
$index_underscore = strpos($value2, '_');
$tipe_component = substr($value2, 0, $index_underscore);
if($tipe_component == '#form'){
$tipe_fix = 'Form';
} elseif ($tipe_component == '#tombol') {
$tipe_fix = 'Tombol';
} elseif ($tipe_component == '#tabel') {
$tipe_fix = 'Tabel';
} else {
$tipe_fix = 'Belum ditentukan';
}
$sql = "SELECT * FROM `component_view` WHERE nama_component = '$value2' AND id_view = '$id_view'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord == 0){
// echo "Masukkan ".$value2." ke tabel component view";
// echo "<br>";
$sql = "INSERT INTO `component_view` (id_view, nama_component, jenis_component) VALUES ('$id_view', '$value2','$tipe_fix')";
mysqli_query($conn, $sql);
}
}
}
}
//tiap baris di textarea scenarioException divek apakah punya @halaman_view
foreach ($arraySE as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key => $value2) {
if (strpos($value2, '@') !== false) {
//masukkan @halaman_view ke tabel 'view'
$sql = "SELECT * FROM `view` WHERE id_fitur = '$id_fitur'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord > 0){
$sql = "UPDATE `view` SET nama_view = '$value2' WHERE id_fitur = '$id_fitur'";
mysqli_query($conn, $sql);
$sql = "SELECT * FROM `view` WHERE id_fitur ='$id_fitur'";
$id_view = query($sql)[0]['id_view'];
// echo "Update " .$value2." ke tabel view";
// echo "<br>";
} else {
$sql = "INSERT INTO `view` (id_fitur, nama_view) VALUES ('$id_fitur', '$value2')";
mysqli_query($conn, $sql);
// echo "Masukkan " .$value2." ke tabel view";
// echo "<br>";
$id_view = mysqli_insert_id($conn);
}
}
}
}
foreach ($arraySE as $key => $value) {
$pecah = explode(" ",$value);
foreach ($pecah as $key2 => $value2) {
# code...
if (strpos($value2, '#') !== false) {
//ambil id @view yang barusan dimasukkan
//masukkan id view dan nama_component ke tabel component_view
$index_underscore = strpos($value2, '_');
$tipe_component = substr($value2, 0, $index_underscore);
if($tipe_component == '#form'){
$tipe_fix = 'Form';
} elseif ($tipe_component == '#tombol') {
$tipe_fix = 'Tombol';
} elseif ($tipe_component == '#tabel') {
$tipe_fix = 'Tabel';
} else {
$tipe_fix = 'Belum ditentukan';
}
$sql = "SELECT * FROM `component_view` WHERE nama_component = '$value2' AND id_view = '$id_view'";
$jumlahRecord = count(query($sql));
if ($jumlahRecord == 0){
// echo "Masukkan ".$value2." ke tabel component view";
// echo "<br>";
$sql = "INSERT INTO `component_view` (id_view, nama_component, jenis_component) VALUES ('$id_view', '$value2', '$tipe_fix')";
mysqli_query($conn, $sql);
}
}
}
}
// die; // sampai sini dulu yaa
// ----> minta masukkan title untuk view tsb
// for setiap component_view pada view tsb (select pake id view), isi jenis_component di tabel component_view
//kalau milih :
// - tabel pilih berapa kolom, dan tiap kolom namanya apa aja
// - form typenya apa (text file dsb)
// - tombol tulisannya apa
//kalau datanya belum ada tinggal tambah
// kalau daranya sudah ada di tambah lagi aja gapapa
//jadi dicek dulu apakah sudah ada view dengan id_fitur yang sedang ingin ditambahkan
//ingat 1 fitur, cuma ada 1 view
//di component view dashboard bisa hapus dan ubah jenis component
// die;
$query = "UPDATE `fitur` SET nama_fitur = '$namaFitur', deskripsi = '$deskripsiFitur', kondisi_awal = '$kondisiAwal', kondisi_akhir = '$kondisiAkhir', scenario_normal = '$scenarioNormal', scenario_alternatif = '$scenarioAlternatif', scenario_exception = '$scenarioException' WHERE id_fitur = '$id_fitur'";
// echo $query;die;
return mysqli_query($conn, $query);
}
function simpanTitle($data){
global $conn;
$namaTitle = htmlspecialchars($data["nama-title"]);
$idView = htmlspecialchars($data["id-view"]);
$query = "UPDATE `view` SET title = '$namaTitle' WHERE id_view = $idView";
mysqli_query($conn, $query);
return mysqli_query($conn, $query);
}
function tambahSistem($data){
global $conn;
$namaSistem = htmlspecialchars($data["nama-sistem"]);
$query = "INSERT INTO sistem
VALUES ('','$namaSistem')
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function ubahSistem($data){
global $conn;
$idSistem = $data["id-sistem"];
$namaSistem = htmlspecialchars($data["nama-sistem"]);
$query = "UPDATE sistem SET
nama_sistem = '$namaSistem'
WHERE id_sistem = $idSistem";
return mysqli_query($conn, $query);
}
function ubahAktor($data){
global $conn;
$idAktor = $data["id-aktor"];
$namaAktor = htmlspecialchars($data["nama-aktor"]);
$query = "UPDATE aktor SET
nama_aktor = '$namaAktor'
WHERE id_aktor = $idAktor";
return mysqli_query($conn, $query);
}
function ubahComponent($data){
global $conn;
// $idAktor = $data["id-aktor"];
// $namaAktor = htmlspecialchars($data["nama-aktor"]);
// $query = "UPDATE aktor SET
// nama_aktor = '$namaAktor'
// WHERE id_aktor = $idAktor";
// echo "Ubah!";
$idComponent = $_POST['id-component'];
$namaComponent = $_POST['nama-component'];
$tipeComponent = $_POST['tipe-component'];
if($tipeComponent == "Belum Ditentukan"){
echo "<script>alert('Tipe component harus ditentukan!')</script>";
return false;
}
$componentAsli = query("SELECT * FROM `component_view` WHERE id_component = $idComponent");
$tipeComponentAsli = $componentAsli[0]['jenis_component'];
//hapus dulu data info component di tiap tabel ybs, yang lama sebelum update
if ($tipeComponentAsli == "Form") {
$sql = "DELETE FROM `info_form` WHERE `info_form`.`id_component_view` = $idComponent";
mysqli_query($conn, $sql);
} elseif($tipeComponentAsli == "Tabel"){
$sql = "DELETE FROM `info_tabel` WHERE `info_tabel`.`id_component_view` = $idComponent";
mysqli_query($conn, $sql);
} elseif($tipeComponentAsli == "Tombol"){
$sql = "DELETE FROM `info_tombol` WHERE `info_tombol`.`id_component_view` = $idComponent";
mysqli_query($conn, $sql);
}
//update info component nama, jenis untuk tabel component_view
$query = "UPDATE component_view SET
nama_component = '$namaComponent',
jenis_component = '$tipeComponent'
WHERE id_component = $idComponent";
mysqli_query($conn, $query);
//insert data info component yang baru sesuai tipe componentnya
if ($tipeComponent == "Form") {
$label = $_POST['label-form'];
$tipe = $_POST['tipe-form'];
$placeholder = $_POST['placeholder-form'];
$sql = "INSERT INTO `info_form` (id_component_view, label_form, tipe_form, placeholder_form) VALUES ('$idComponent', '$label', '$tipe', '$placeholder')";
mysqli_query($conn, $sql);
} elseif($tipeComponent == "Tabel"){
$jumlahKolom = 0;
foreach ($_POST as $key => $value) {
// var_dump(strpos($key, '-kolom-'));
// echo "<br>";
if(strpos($key, 'nama-kolom-') !== false){
$jumlahKolom++;
$sql = "INSERT INTO `info_tabel` (id_component_view, nama_kolom) VALUES ('$idComponent', '$value')";
mysqli_query($conn, $sql);
}
}
} elseif($tipeComponent == "Tombol"){
$namaTombol = $_POST['nama-tombol'];
$tipeTombol = $_POST['tipe-tombol'];
$sql = "INSERT INTO `info_tombol` (id_component_view, nama_tombol, jenis_tombol) VALUES ('$idComponent', '$namaTombol', '$tipeTombol')";
mysqli_query($conn, $sql);
} else {
echo "<script>alert('Tipe component harus ditentukan!')</script>";
return false;
}
return mysqli_affected_rows($conn);
}
function cekPernahGenerate($id_sistem){
$cek = query("SELECT * FROM `generate` WHERE id_sistem = '$id_sistem'");
$jumlahCek = count($cek);
if ($jumlahCek > 0){
// return $cek[0]['id_generate'];
return true;
}
return false;
}
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
rrmdir($dir."/".$object);
else unlink ($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
function prosesGenerate($id_sistem){
global $conn;
$cek = query("SELECT * FROM `generate` WHERE id_sistem = '$id_sistem'");
$sistem = query("SELECT * FROM `sistem` WHERE id_sistem = '$id_sistem'");
$aktor = query("SELECT * FROM `aktor` WHERE id_sistem = '$id_sistem'");
$namaSistem = $sistem[0]['nama_sistem'];
$jumlahCek = count($cek);
if ($jumlahCek > 0){ //kalau sudah ada datanya hapus dulu, baru buat ulang (generate ulang case )
rrmdir("hasil/".$id_sistem);
}
//cari id sistem
//bikin folder utk sistem ybs, taruh di /hasil/...folder_sistem.../
//cari aktor tiap sistem
//bikin folder utk tiap aktor ybs
//cari fitur tiap aktor
//cari view dari tiap fitur
//cari component view dari tiap fitur
//concate tiap component view sesuai urutan db
//bikin file html untuk tiap fitur ybs (isi titlenya, dll)
//compress folder sistem jadi .zip, taruh di /download/..... .zip
mkdir("hasil/".$id_sistem);
foreach($aktor as $akt){
mkdir(getcwd()."/hasil/".$id_sistem."/".$akt['nama_aktor']);
//cari fitur
$idAktor = $akt['id_aktor'];
$namaAktor = $akt['nama_aktor'];
$fitur = query("SELECT * FROM `fitur` WHERE id_aktor = '$idAktor'");
foreach($fitur as $fit){
$idFitur = $fit['id_fitur'];
$namaFitur = $fit['nama_fitur'];
$namaFileFitur = strtolower($namaFitur);
$namaFileFitur = str_replace(" ", "-", $namaFileFitur);
$namaFileFitur .= '.html';
$view = query("SELECT * FROM `view` WHERE id_fitur = $idFitur");
if (count($view) > 0){
$judulHalaman = $view[0]['title'];
} else {
$judulHalaman = '';
}
//buat html
$fh = fopen("hasil/".$id_sistem."/".$namaAktor."/".$namaFileFitur, 'w'); // or die("error");
$bagianAtas = '
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>'.$judulHalaman.'</title>
<!-- Theme style -->
<link rel="stylesheet" href="https://dimassatria.tech/psi/adminlte.min.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<!-- Left navbar links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#"><i class="fa fa-bars" aria-hidden="true"></i></a>
</li>
</ul>
<!-- Right navbar links -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#"><i
class="fas fa-th-large"></i></a>
</li>
</ul>
</nav>
<!-- /.navbar -->
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="#" class="brand-link">
<img src="https://dimassatria.tech/psi/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">'.$namaSistem.'</span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="https://dimassatria.tech/psi/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
</div>
<div class="info">
<a href="#" class="d-block">'.$namaAktor.'</a>
</div>
</div>';
$bagianSidebar =
'<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->';
foreach($fitur as $fit2){
$namaFileFitur2 = strtolower($fit2['nama_fitur']);
$namaFileFitur2 = str_replace(" ", "-", $namaFileFitur2);
$namaFileFitur2 .= '.html';
if($namaFitur == $fit2['nama_fitur']){
$bagianSidebar .=
'<li class="nav-item">
<a href="'.$namaFileFitur2.'" style="background-color:#E11584" class="nav-link active">
<p>'
.$fit2['nama_fitur'].
'</p>
</a>
</li>';
}else {
$bagianSidebar .=
'<li class="nav-item">
<a href="'.$namaFileFitur2.'" class="nav-link">
<p>'
.$fit2['nama_fitur'].
'</p>
</a>
</li>';
}
}
$bagianSidebar .=
'</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>';
$bagianContent = '<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">'.$namaFitur.'</h1>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<dic class="card">
<div class="card-body">';
foreach($view as $vi){
$idView = $vi['id_view'];
$component_view = query("SELECT * FROM `component_view` WHERE id_view='$idView'");
foreach($component_view as $comp){
$idComponent = $comp['id_component'];
if($comp['jenis_component'] == 'Form' ){
$info_form = query("SELECT * FROM `info_form` WHERE id_component_view ='$idComponent'");
if(count($info_form) > 0){
$labelForm = $info_form[0]['label_form'];
$tipeForm = $info_form[0]['tipe_form'];
$placeholderForm = $info_form[0]['placeholder_form'];
$bagianContent .= '
<div class="form-group row">
<label for="nama-fitur" class="col-sm-2 col-form-label">'.$labelForm.'</label>
<div class="col-sm-10">
<input placeholder="'.$placeholderForm.'" type="'.$tipeForm.'" class="form-control">
</div>
</div>
';
}
} elseif($comp['jenis_component'] == 'Tabel'){
$info_tabel = query("SELECT * FROM `info_tabel` WHERE id_component_view ='$idComponent'");
$htmlTabel = '
<table id="example1" class="mt-5 text-center table table-bordered table-striped dataTable" role="grid"
aria-describedby="example1_info">
<thead>
<tr role="row">';
if(count($info_tabel) > 0){
$jumlahKolom = count($info_tabel);
foreach($info_tabel as $info){
$namaKolom = $info['nama_kolom'];
$htmlTabel .= '
<th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1"
colspan="1" aria-sort="ascending"
aria-label="Rendering engine: activate to sort column descending"
style="width: 5px;">'.$namaKolom.'
</th>
';
}
$htmlTabel .= '
</tr>
</thead>
<tbody>';
$jumlahBaris = 5; //angka terserah
for ($i=0; $i < $jumlahBaris ; $i++) {
$htmlTabel .= '<tr role="row" class="even">';
for ($j=0; $j < $jumlahKolom ; $j++) {
$htmlTabel .= '<td>-</td>';
}
$htmlTabel .= '</tr>';
}
$htmlTabel .= '
</tbody>
</table>
';
$bagianContent .= $htmlTabel;
}
} elseif($comp['jenis_component'] == 'Tombol'){
$info_tombol = query("SELECT * FROM `info_tombol` WHERE id_component_view ='$idComponent'");
if(count($info_tombol) > 0){
$namaTombol = $info_tombol[0]['nama_tombol'];
$jenisTombol = $info_tombol[0]['jenis_tombol'];
$bagianContent .= '
<div class="row">
<button class="btn btn-'.$jenisTombol.' btn-block">'.$namaTombol.'</button>
</div>
';
}
}
}
}
$bagianContent .= '</div>
</dic>
</div>
</div>
</div><!-- /.container-fluid -->
</div>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- REQUIRED SCRIPTS -->
<!-- jQuery -->
<script src="https://dimassatria.tech/psi/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="https://dimassatria.tech/psi/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="https://dimassatria.tech/psi/adminlte.min.js"></script>
</body>
</html>
';
$stringData = $bagianAtas;
$stringData .= $bagianSidebar;
$stringData .= $bagianContent;
fwrite($fh, $stringData);
fclose($fh);
}
}
$folderToCompress = "hasil/".$id_sistem."/";
$folderTujuanZip = "download/".uniqid().".zip";
// var_dump($folderTujuanZip);die;
if(Zip($folderToCompress, $folderTujuanZip) != false){
$query = "INSERT INTO `generate` (id_sistem, url_hasil)
VALUES ('$id_sistem', '$folderTujuanZip')";
return mysqli_query($conn, $query);
} else {
return false;
}
}
function Zip($source, $destination)
{
// echo $source;
// var_dump(file_exists($source));die;
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', $source);
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
// $file = realpath($file);
if (is_dir($file) === true)
{
$namaFolder = str_replace($source . '/', '', $file . '/');
$zip->addEmptyDir($namaFolder);
}
else if (is_file($file) === true)
{
$namaFile = str_replace($source . '/', '', $file);
$zip->addFromString($namaFile, file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
function tambahAktor($data, $id_sistem){
global $conn;
$namaAktor = htmlspecialchars($data["nama-aktor"]);
$query = "INSERT INTO aktor
VALUES ('','$namaAktor', '$id_sistem')
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function tambahFitur($data, $id_aktor){
global $conn;
$namaFitur = htmlspecialchars($data["nama-fitur"]);
$query = "INSERT INTO `fitur` (nama_fitur, id_aktor)
VALUES ('$namaFitur', $id_aktor)";
// echo $query;die;
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function upload(){
$namaFile = $_FILES['gambar']['name'];
$ukuranFile = $_FILES['gambar']['size'];
$error = $_FILES['gambar']['error'];
$tmpName = $_FILES['gambar']['tmp_name'];
// cek apakah tidak ada gambar yang diupload
if ($error === 4){
echo "<script>
alert('pilih gambar terlebih dahulu!')
</script>
";
return false;
}
// cek apakah yang diupload adalah gambar
$ekstensiGambarValid = ['jpg', 'jpeg', 'png'];
$ekstensiGambar = explode('.',$namaFile);
// dimas.jpg = ['dimas']['jpg']
$ekstensiGambar = strtolower(end($ekstensiGambar));
if(!in_array($ekstensiGambar, $ekstensiGambarValid)){
echo "<script>
alert('YANG KAMU UPLOAD BUKAN GAMBAR TAUK! :)')
</script>
";
return false;
}
// cek ukuran gambar terlalu besar
if ($ukuranFile > 1000000){
echo "<script>
alert('ukuran file gambar terlalu besar!')
</script>
";
return false;
}
// lolos pengecekan, gambar siap diupload
// generate nama gambar baru
$namaFileBaru = uniqid();
$namaFileBaru .= '.';
$namaFileBaru .= $ekstensiGambar;
// var_dump($namaFileBaru); die;
move_uploaded_file($tmpName, 'img/'. $namaFileBaru);
return $namaFileBaru;
}
function hapusSistem($id_sistem){
global $conn;
mysqli_query($conn, "DELETE FROM sistem WHERE id_sistem = $id_sistem");
return mysqli_affected_rows($conn);
}
function hapusAktor($id_aktor){
global $conn;
mysqli_query($conn, "DELETE FROM aktor WHERE id_aktor = $id_aktor");
return mysqli_affected_rows($conn);
}
function hapusFitur($id_fitur){
global $conn;
mysqli_query($conn, "DELETE FROM fitur WHERE id_fitur = $id_fitur");
return mysqli_affected_rows($conn);
}
function hapusComponent($id_component){
global $conn;
mysqli_query($conn, "DELETE FROM component_view WHERE id_component = $id_component");
return mysqli_affected_rows($conn);
}
function ubah($data){
global $conn;
$id = $data["id"];
$nrp = htmlspecialchars($data["nrp"]);
$nama = htmlspecialchars($data["nama"]);
$email = htmlspecialchars($data["email"]);
$jurusan = htmlspecialchars($data["jurusan"]);
$gambarLama = htmlspecialchars($data["gambarLama"]);
if ($_FILES['gambar']['error'] === 4){
$gambar = $gambarLama;
// var_dump($gambar); die;
} else {
$gambar = upload();
// var_dump($gambar); die;
}
// $gambar = htmlspecialchars($data["gambar"]);
$query = "UPDATE mahasiswa SET
nrp = '$nrp',
nama = '$nama',
email = '$email',
jurusan = '$jurusan',
gambar = '$gambar'
WHERE id = $id";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function cari($keyword){
$query = "SELECT * FROM mahasiswa
WHERE
nama LIKE '%$keyword%' OR
nrp LIKE '%$keyword%' OR
email LIKE '%$keyword%' OR
jurusan LIKE '%$keyword%'
";
return query($query);
}
function registrasi($data){
global $conn;
$username = strtolower(stripslashes($data["username"]));
$password = mysqli_real_escape_string($conn, $data["password"]);
$password2 = mysqli_real_escape_string($conn, $data["password2"]);
// cek username sudah ada atau belum
$result = mysqli_query($conn, "SELECT username FROM users WHERE username = '$username'");
if (mysqli_fetch_assoc($result)){