-
Notifications
You must be signed in to change notification settings - Fork 0
/
comandoEdit.php
397 lines (349 loc) · 16.5 KB
/
comandoEdit.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
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
<?php
/* CLEAR CACHE */
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//header("Content-Type: application/xml; charset=utf-8");
require_once 'appConfig.php';
include_once 'api/config/database.php';
include_once 'api/objects/comando.php';
include_once 'api/objects/sistema.php';
include_once 'api/objects/arquivo.php';
// functionals functions
function checkImageExtension ($ext) {
switch ($ext) {
case 'jpg': return true; break;
case 'jpeg': return true; break;
case 'png': return true; break;
case 'gif': return true; break;
case 'tiff': return true; break;
case 'webp': return true; break;
case 'bmp': return true; break;
case 'svg': return true; break;
}
}
function checkCompactExtension ($ext) {
switch ($ext) {
case 'zip': return true; break;
case '7z': return true; break;
case 'rar': return true; break;
case '001': return true; break;
case 'arj': return true; break;
case 'bin': return true; break;
case 'bzip': return true; break;
case 'cab': return true; break;
case 'jar': return true; break;
case 'deb': return true; break;
case 'rpm': return true; break;
case 'gz': return true; break;
case 'tar': return true; break;
case 'war': return true; break;
}
}
function checkFileExtension ($ext) {
switch ($ext) {
case 'doc': return '<i class="fas fa-3x fa-file-word text-muted"></i>'; break;
case 'docx': return '<i class="fas fa-3x fa-file-word text-muted"></i>'; break;
case 'xls': return '<i class="fas fa-3x fa-file-excel text-muted"></i>'; break;
case 'xlsx': return '<i class="fas fa-3x fa-file-excel text-muted"></i>'; break;
case 'ppt': return '<i class="fas fa-3x fa-file-powerpoint text-muted"></i>'; break;
case 'pptx': return '<i class="fas fa-3x fa-file-powerpoint text-muted"></i>'; break;
case 'pdf': return $ext; /*'<i class="fas fa-3x fa-file-pdf text-muted"></i>';*/ break;
case 'txt': return '<i class="fas fa-3x fa-file-alt text-muted"></i>'; break;
case 'text': return '<i class="fas fa-3x fa-file-alt text-muted"></i>'; break;
case 'md': return true; break;
case 'wps': return '<i class="fas fa-3x fa-file-word text-muted"></i>'; break;
case 'eps': return true; break;
case 'psd': return true; break;
case 'odt': return '<i class="fas fa-3x fa-file-word text-muted"></i>'; break;
case 'rft': return '<i class="fas fa-3x fa-file-word text-muted"></i>'; break;
}
}
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare objects
$comando = new Comando($db);
$sistema = new Sistema($db);
$arquivo = new Arquivo($db);
// GET variables
$py_idcomando = md5('idcomando');
// read all records from secondary request for primary request
$sql = $comando->readLinkedSystem($_GET[''.$py_idcomando.'']);
if($sql->rowCount() > 0) {
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
$syslinked_array = array_column($row, 'idsistema');
$syslinked = implode(',', $syslinked_array);
} else {
$syslinked = '';
}
$sql->closeCursor();
// read data from primary request
$sql = $comando->readSingle($_GET[''.$py_idcomando.'']);
if ($sql->rowCount() > 0) {
#while($row = $sql->fetch(PDO::FETCH_OBJ)) {}
$row = $sql->fetch(PDO::FETCH_OBJ);
?>
<form class="form-edit-comando">
<div class="modal-header">
<h4 class="modal-title">
<span>Editar Conhecimento</span>
<span class="text-muted">
<small>(<i class="fas fa-bell"></i> Campo obrigatório)</small>
</span>
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="rand" id="rand_edit" value="<?php echo md5(mt_rand()); ?>">
<input type="hidden" name="idcomando" id="idcomando" value="<?php echo $_GET[''.$py_idcomando.'']; ?>">
<input type="hidden" name="sistema_selected_original" id="sistema_selected_original" value="<?php echo $syslinked; ?>">
<input type="hidden" name="sistema_selected" id="sistema_selected_edit">
<div class="form-group">
<label for="sistema"><i class="fas fa-bell"></i> Sistema</label>
<select name="sistema" id="sistema_edit" class="form-control"
data-placeholder="Encontre ou informe o sistema destino" style="width: 100%;" multiple required>
<?php
$sql2 = $sistema->readAll();
if($sql2->rowCount() > 0) {
while ($row2 = $sql2->fetch(PDO::FETCH_OBJ)) {
if (strstr($syslinked, $row2->idsistema)) {
echo'<option value="'.$row2->idsistema.'" selected>'.$row2->sistema.'</option>';
} else {
echo'<option value="'.$row2->idsistema.'">'.$row2->sistema.'</option>';
}
}
}
?>
</select>
</div>
<div class="form-group">
<label for="descricao"><i class="fas fa-bell"></i> Descrição</label>
<input type="text" name="descricao" id="descricao_edit" maxlength="100"
value="<?php echo $row->descricao; ?>" class="form-control" placeholder="Descrição" required>
</div>
<div class="form-group">
<label for="instrucao"><i class="fas fa-bell"></i> Comando</label>
<textarea name="instrucao" id="instrucao_edit" rows="3" class="form-control"
placeholder="Instrução" required><?php echo $row->instrucao; ?></textarea>
</div>
<!--<div class="form-group">
<label for="anexo">Anexo</label>
<input type="file" name="anexo[]" id="anexo_edit" class="form-control" placeholder="Anexe arquivos ao conhecimento" multiple>
</div>-->
<div class="custom-file">
<label class="custom-file-label" for="anexo">Escolher arquivos</label>
<input type="file" name="anexo[]" id="anexo_edit" class="custom-file-input">
</div>
<div class="anexo">
<?php
$sql2 = $arquivo->readForCommand($row->idcomando);
if ($sql2->rowCount() > 0) {
$dir = 'anexo/';
while ($row2 = $sql2->fetch(PDO::FETCH_OBJ)) {
$extensao = strrchr($row2->link, '.');
$extensao = substr($extensao, 1);
if (checkImageExtension($extensao)) {
echo'
<div>
<span><a href="' . $dir . $row2->link . '" data-toggle="lightbox"><img src="' . $dir . $row2->link . '" alt="anexo"></a></span>
<p class="anexo-action">
<a class="a-delete-arquivo" id="c87da4b82210d84b55cce6bc0e64e3de-'.$row2->idarquivo.'" href="#" title="Excluir anexo"><i class="fa fa-trash text-danger"></i></a>
</p>
</div>';
} elseif (checkCompactExtension($extensao)) {
echo'
<div>
<span><i class="fas fa-3x fa-file-archive text-muted"></i> <em><a href="' . $dir . $row2->link . '">' . $row2->link . '</a></em></span>
<p class="anexo-action">
<a class="a-delete-arquivo" id="c87da4b82210d84b55cce6bc0e64e3de-'.$row2->idarquivo.'" href="#" title="Excluir anexo"><i class="fa fa-trash text-danger"></i></a>
</p>
</div>';
} elseif ($fa = checkFileExtension($extensao)) {
if ($fa == 'pdf') {
echo'
<div>
<span><i class="fas fa-3x fa-file-pdf text-muted"></i> <em><a class="a-view-document" href="' . $dir . $row2->link . '">' . $row2->link . '</a></em></span>
<p class="anexo-action">
<a class="a-delete-arquivo" id="c87da4b82210d84b55cce6bc0e64e3de-'.$row2->idarquivo.'" href="#" title="Excluir anexo"><i class="fa fa-trash text-danger"></i></a>
</p>
</div>';
} else {
echo'
<div>
<span>' . $fa . ' <em><a href="' . $dir . $row2->link . '">' . $row2->link . '</a></em></span>
<p class="anexo-action">
<a class="a-delete-arquivo" id="c87da4b82210d84b55cce6bc0e64e3de-'.$row2->idarquivo.'" href="#" title="Excluir anexo"><i class="fa fa-trash text-danger"></i></a>
</p>
</div>';
}
} else {
echo'
<div>
<span><i class="fas fa-3x fa-shapes text-muted"></i> <em>' . $row2->link . '</em></span>
<p class="anexo-action">
<a class="a-delete-arquivo" id="c87da4b82210d84b55cce6bc0e64e3de-'.$row2->idarquivo.'" href="#" title="Excluir anexo"><i class="fa fa-trash text-danger"></i></a>
</p>
</div>';
}
}
}
?>
</div>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-primary btn-edit-comando">Salvar</button>
</div>
</form>
<script defer>
$(document).ready(function() {
const fade = 150,
delay = 100,
timeout = 60000,
filelist = [],
Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 1000
});
/* TOOLTIP */
$('div a, td span a, span a, div p a, p a').tooltip({
boundary: 'window'
});
/* SELECT MULTIPLE */
$('#sistema_edit').show(function() {
$('#sistema_edit').select2({
tags: true,
language: {
noResults: function () {
return 'No campo acima é possível criar um novo sistema.';
}
}
});
$('#sistema_edit').change(function (e) {
let obj = $('#sistema_edit').select2('val');
$('#sistema_selected_edit').attr('value', obj);
});
});
/* UPLOAD */
$('#anexo_edit').on('change', function(e) {
e.preventDefault();
for (let i = 0; i < this.files.length; i++) {
filelist.push(this.files[i]);
}
});
/* MODAL */
$('.anexo').on('click', '.a-view-document', function(e) {
e.preventDefault();
//$('#modal-view-document').modal('show').find('.modal-content').load($(this).attr('href'));
eModal.iframe($(this).attr('href'), 'Visualizador');
});
/* LIGHTBOX */
$('.anexo').on('click', '[data-toggle="lightbox"]', function(e) {
e.preventDefault();
$(this).ekkoLightbox({
alwaysShowClose: true
});
});
/* EDITAR CONHECIMENTO */
$('.form-edit-comando').submit(function(e) {
e.preventDefault();
let formdata = new FormData(this);
formdata.append('anexo', filelist);
$.ajax({
url: 'api/comando/update.php',
type: 'POST',
cache: false,
data: formdata,
processData: false,
contentType: false,
success: function (data) {
switch (data) {
case 'true':
Toast.fire({
icon: 'success',
title: 'Conhecimento editado.'
}).then((result) => {
window.setTimeout("location.href='inicio'", delay);
});
break;
default:
Toast.fire({
icon: 'error',
title: data
});
break;
}
},
error: function (data) {
Toast.fire({
icon: 'error',
title: data
});
}
});
return false;
});
/* DELETE ARQUIVO */
$('.anexo').on('click', '.a-delete-arquivo', function(e) {
e.preventDefault();
let target = $('.a-edit-comando').attr('href'),
click = this.id.split('-'),
py = click[0],
id = click[1];
Swal.fire({
icon: 'question',
title: 'Excluir o Arquivo',
showCancelButton: true,
confirmButtonText: 'Sim',
cancelButtonText: 'Não',
}).then((result) => {
if (result.value == true) {
$.ajax({
type: 'GET',
url: 'api/arquivo/delete.php?' + py + '=' + id,
dataType: 'json',
cache: false,
beforeSend: function(result) {
$('#search-result').empty().html(
'<p style="position: relative;top: 15px;" class="lead"><i class="fas fa-cog fa-spin"></i></p>'
);
},
error: function(result) {
Swal.fire({
icon: 'error',
html: result.responseText,
showConfirmButton: false
});
},
success: function(data) {
if (data == true) {
Toast.fire({
icon: 'success',
title: 'Arquivo excluído.'
}).then((result) => {
//window.setTimeout("location.href='inicio'", delay);
// load the url and show modal on success
$('#modal-edit-comando .modal-content').load(target);
});
}
}
});
}
});
});
});
<?php
} else {
echo'
<blockquote class="quote-danger">
<h5>Erro</h5>
<p>O conhecimento não foi encontrado.</p>
</blockquote>';
}
?>