openstamanager/include/modifica_allegato.php

99 lines
3.5 KiB
PHP
Raw Normal View History

<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use Models\Upload;
2023-08-04 14:54:28 +02:00
$id_allegati = (array) json_decode(filter('id_allegati'));
// Form di inserimento riga documento
echo '
<form action="" method="post" id="modifica-allegato">
2023-08-04 14:54:28 +02:00
<input type="hidden" name="id_allegati" value="'.implode(';', $id_allegati).'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="modifica-allegato">
2023-03-30 14:29:51 +02:00
<div class="row">';
2024-01-15 15:30:45 +01:00
if (sizeof($id_allegati) == 1) {
$allegato = Upload::find($id_allegati[0]);
echo '
<div class="col-md-6">
2024-04-05 09:47:28 +02:00
{[ "type": "text", "label": "'.tr('Nome').'", "name": "nome_allegato", "value": "'.$allegato->name.'" ]}
</div>
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "value": "'.$allegato->category.'", "disabled": "'.intval(in_array($allegato->category, ['Fattura Elettronica'])).'" ]}
2023-03-30 14:29:51 +02:00
</div>';
2024-01-15 15:30:45 +01:00
} else {
$allegato = Upload::find($id_allegati[0]);
echo '
2023-03-30 14:29:51 +02:00
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "value": "" ]}
</div>';
2024-01-15 15:30:45 +01:00
}
echo '
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary pull-right">
<i class="fa fa-edit"></i> '.tr('Modifica').'
</button>
</div>
</div>
</form>';
// Elenco categoria disponibili per l'autocompletamento
$where = '`id_module` '.(!empty($allegato['id_module']) && empty($allegato['id_plugin']) ? '= '.prepare($allegato['id_module']) : 'IS NULL').' AND `id_plugin` '.(!empty($allegato['id_plugin']) ? '= '.prepare($allegato['id_plugin']) : 'IS NULL').'';
$categories = $dbo->fetchArray('SELECT DISTINCT(BINARY `category`) AS `category` FROM `zz_files` WHERE '.$where.' ORDER BY `category`');
$source = array_clean(array_column($categories, 'category'));
echo '
<script>
var categorie = '.json_encode($source).';
// Auto-completamento categoria
$(document).ready(function () {
const input = $("#modifica-allegato #categoria_allegato")[0];
autocomplete({
minLength: 0,
input: input,
emptyMsg: globals.translations.noResults,
fetch: function (text, update) {
text = text.toLowerCase();
const suggestions = categorie.filter(n => n.toLowerCase().startsWith(text));
// Trasformazione risultati in formato leggibile
const results = suggestions.map(function (result) {
return {
label: result,
value: result
}
});
update(results);
},
onSelect: function (item) {
input.value = item.label;
},
});
});
</script>
<script>$(document).ready(init)</script>';