download_template.php
7.78 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
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
<div class="row">
<div class="col-xs-12"> <?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$ket = htmlspecialchars($purifier->purify(trim($_POST['ket'])), ENT_QUOTES);
$fileName = htmlspecialchars($_FILES['filesm']['name'], ENT_QUOTES);
$tipefile = pathinfo($fileName,PATHINFO_EXTENSION);
$extensionList = array("pdf","jpg","jpeg","png","PNG", "JPG", "JPEG","PDF", "doc", "docx");
$namaDir = 'berkas/template/';
$filesm = $namaDir."T"."_". slugify($ket)."_". date("d-m-Y_H-i-s", time()) .".".$tipefile;
$filedb = "T"."_". slugify($ket)."_". date("d-m-Y_H-i-s", time()) .".".$tipefile;
$created = date("Y-m-d H:i:s", time());
$field = array('file' => $filedb, 'ket' => $ket, 'created'=>$created);
$params = array(':file' => $filedb, ':ket'=>$ket, ':created'=>$created);
if(in_array($tipefile, $extensionList)){
if(move_uploaded_file($_FILES['filesm']['tmp_name'], $filesm)){
$insert = $this->model->insertprepare("download_template", $field, $params);
if($insert->rowCount() >= 1){
echo "<script type=\"text/javascript\">alert('Data Berhasil Tersimpan...!!');window.location.href=\"$_SESSION[url]\";</script>";
}else{
die("<script>alert('Data Gagal di simpan ke Database, Silahkan Coba Kembali..!!');window.history.go(-1);</script>");
}
}else{
echo "<script type=\"text/javascript\">alert('File gagal di Upload ke Folder, Silahkan ulangi!!!');window.history.go(-1);</script>";
}
}else{
echo "<script type=\"text/javascript\">alert('File gagal di Upload, Format file tidak di dukung!!!');window.history.go(-1);</script>";
}
}else{
if(isset($_GET['id']) && (isset($_GET['act']) && $_GET['act'] == "del")){
$id = htmlspecialchars($purifier->purify(trim($_GET['id'])), ENT_QUOTES);
## Cari data
$params = array(':id' => trim($_GET['id']));
$dataN = $this->model->selectprepare("download_template", $field=null, $params, "id=:id", $other=null);
$dataM= $dataN->fetch(PDO::FETCH_OBJ);
@unlink('berkas/template/'.$dataM->file);
$params = array(':id' => $id);
$delete = $this->model->hapusprepare("download_template", $params, "id=:id");
if($delete){
echo "<script type=\"text/javascript\">alert('Data Berhasil di Hapus...!!');window.location.href=\"./index.php?op=download_template\";</script>";
}else{
die("<script>alert('Gagal menghapus data hari libur, Silahkan Coba Kembali..!!');window.history.go(-1);</script>");
}
}?>
<div class="widget-box">
<div class="widget-header">
<h4 class="widget-title">Atur Template</h4>
<div class="widget-toolbar">
<a href="#" data-action="collapse">
<i class="ace-icon fa fa-chevron-up"></i>
</a>
<a href="#" data-action="close">
<i class="ace-icon fa fa-times"></i>
</a>
</div>
</div>
<div class="widget-body">
<div class="widget-main">
<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" name="formku" action="<?php echo $_SESSION['url'];?>">
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right" for="form-field-mask-1"> File Template *</label>
<span class="help-button" data-rel="popover" data-trigger="hover" data-placement="left" data-content="Pilih File template yang ingin di upload. Caranya klik menu Pilih File. Tipe file : .pdf, .jpg, .png, .doc, .docx" title="File Template">?</span>
<div class="col-sm-5">
<input type="file" class="form-control" name="filesm" id="filesm" required/>
</div>
</div>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right" for="form-field-mask-1"> Keterangan *</label>
<span class="help-button" data-rel="popover" data-trigger="hover" data-placement="left" data-content="Di isi Keterangan template" title="Keterangan">?</span>
<div class="col-sm-5">
<textarea class="form-control limited" placeholder="Keterangan Template" name="ket" id="ket" maxlength="150" required><?php if(isset($ket)){ echo $ket; }?></textarea>
</div>
</div>
<div class="clearfix form-actions">
<div class="col-md-offset-3 col-md-9">
<div class="col-sm-2">
<button type="submit" class="btn btn-info" type="button">
<i class="ace-icon fa fa-check bigger-110"></i>
Submit
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="space-4"></div>
<div class="widget-box"><?php
$getData = $this->model->selectprepare("download_template", $field=null, $params=null, $where=null, "order by id DESC");
if($getData->rowCount() >= 1){
while($data_Show = $getData->fetch(PDO::FETCH_OBJ)){
$dump_Data[]=$data_Show;
}?>
<div class="widget-body">
<div class="widget-main">
<table class="table table-striped table-bordered table-hover no-margin-bottom no-border-top">
<thead>
<tr>
<th width="50">No</th>
<th width="150">Keterangan</th>
<th width="100">Berkas</th>
<th width="30">ACT</th>
</tr>
</thead>
<tbody><?php
$no=1;
foreach($dump_Data as $key => $object){?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $object->ket;?></td>
<td>
<span class="label label-xs label-primary label-white middle">
<a href="./berkas/template/<?=$object->file?>" target="_blank"><b>Lihat</b></a>
</span>
</td>
<td><center>
<div class="hidden-sm hidden-xs btn-group">
<a href="./index.php?op=download_template&id=<?php echo $object->id;?>&act=del" onclick="return confirm('Anda yakin akan menghapus data ini??')">
<button class="btn btn-minier btn-danger">
<i class="ace-icon fa fa-trash-o bigger-110"></i>
</button>
</a>
</div>
</center>
</td>
</tr><?php
$no++;
}?>
</tbody>
</table>
</div>
</div><?php
}?>
</div><?php
}?>
</div><!-- /.span -->
</div><!-- /.row -->
<!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- page specific plugin scripts -->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<script src="assets/js/dataTables.buttons.min.js"></script>
<script src="assets/js/buttons.flash.min.js"></script>
<script src="assets/js/buttons.html5.min.js"></script>
<script src="assets/js/buttons.print.min.js"></script>
<script src="assets/js/buttons.colVis.min.js"></script>
<script src="assets/js/dataTables.select.min.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
jQuery(function($) {
//select/deselect a row when the checkbox is checked/unchecked
$('#simple-table').on('click', 'td input[type=checkbox]' , function(){
var $row = $(this).closest('tr');
if($row.is('.detail-row ')) return;
if(this.checked) $row.addClass(active_class);
else $row.removeClass(active_class);
});
/***************/
$('.show-details-btn').on('click', function(e) {
e.preventDefault();
$(this).closest('tr').next().toggleClass('open');
$(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-up');
});
/***************/
})
</script>