Gestione azioni di gruppo allegati

This commit is contained in:
MatteoPistorello 2023-03-30 14:29:51 +02:00
parent a16e003e9c
commit 4cbb37e658
4 changed files with 171 additions and 21 deletions

View File

@ -26,6 +26,7 @@ use Modules\Checklists\Check;
use Modules\Checklists\Checklist;
use Modules\Emails\Template;
use Notifications\EmailNotification;
use Util\Zip;
if (empty($structure) || empty($structure['enabled'])) {
exit(tr('Accesso negato'));
@ -181,15 +182,62 @@ elseif (filter('op') == 'download-allegato') {
include_once base_dir().'/include/modifica_allegato.php';
}
// Zip allegati
elseif (filter('op') == 'download-zip-allegati') {
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id IN('.implode(',',json_decode(filter('id'))).')');
$dir = base_dir().'/'.$module->upload_directory;
directory($dir.'tmp/');
$dir = slashes($dir);
$zip = slashes($dir.'_'.time().'.zip');
// Rimozione dei contenuti precedenti
$files = glob($dir.'/*.zip');
foreach ($files as $file) {
delete($file);
}
foreach ($rs as $r) {
$allegato = Upload::find($r['id']);
$src = basename($allegato->filepath);
$dst = basename($allegato->original_name);
$file = slashes($module->upload_directory.'/'.$src);
$dest = slashes($dir.'tmp/'.$dst);
$result = copy($file, $dest);
}
// Creazione zip
if (extension_loaded('zip')) {
Zip::create($dir.'tmp/', $zip);
// Invio al browser il file zip
download($zip);
// Rimozione dei contenuti
delete($dir.'tmp/');
}
}
// Modifica dati di un allegato
elseif (filter('op') == 'modifica-allegato') {
$id_allegato = filter('id_allegato');
$upload = Upload::find($id_allegato);
$upload->name = post('nome_allegato');
$upload->category = post('categoria_allegato');
$upload->save();
$id_allegati = explode(';',filter('id_allegati'));
if ($id_allegato) {
$upload = Upload::find($id_allegato);
$upload->name = post('nome_allegato');
$upload->category = post('categoria_allegato');
$upload->save();
} else {
foreach ($id_allegati as $id_allegato) {
$upload = Upload::find($id_allegato);
$upload->category = post('categoria_allegato');
$upload->save();
}
}
}
// Modifica nome della categoria degli allegati
@ -258,12 +306,12 @@ elseif (filter('op') == 'rimuovi-nota') {
elseif (filter('op') == 'copia-checklist') {
$content = post('content');
$checklist_id = post('checklist');
$users = post('assigned_users');
$users = array_clean($users);
$group_id = post('group_id');
$checklist = Checklist::find($checklist_id);
$checklist->copia($user, $id_record, $users, $group_id);
}
@ -275,7 +323,7 @@ elseif (filter('op') == 'aggiungi-check') {
$users = post('assigned_users');
$users = array_clean($users);
$group_id = post('group_id');
$check = Check::build($user, $structure, $id_record, $content, $parent_id);

View File

@ -191,17 +191,19 @@ function ricaricaAllegati(gestione) {
/**
* Funzione per l'apertura della pagina di gestione dei dati dell'allegato.
* @param button
* @param id
* @param ids
*/
function modificaAllegato(button) {
function modificaAllegato(button, id, ids) {
const gestione = $(button).closest(".gestione-allegati");
const allegato = $(button).closest("tr").data();
let params = new URLSearchParams({
op: "visualizza-modifica-allegato",
id_module: gestione.data('id_module'),
id_plugin: gestione.data('id_plugin'),
id_record: gestione.data('id_record'),
id_allegato: allegato.id,
id_allegati: ids,
id_allegato: id,
}).toString();
openModal(globals.translations.allegati.modifica, globals.rootdir + "/actions.php?" + params);
@ -227,6 +229,25 @@ function scaricaAllegato(button) {
window.open(globals.rootdir + "/actions.php?" + params, "_blank")
}
/**
* Funzione per gestire il download zip di allegati.
* @param button
* @param ids
*/
function scaricaZipAllegati(button, ids) {
const gestione = $(button).closest(".gestione-allegati");
let params = new URLSearchParams({
op: "download-zip-allegati",
id_module: gestione.data('id_module'),
id_plugin: gestione.data('id_plugin'),
id_record: gestione.data('id_record'),
id: ids,
}).toString();
window.open(globals.rootdir + "/actions.php?" + params, "_blank")
}
/**
* Funzione per l'apertura dell'anteprima di visualizzazione allegato.
* @param button

View File

@ -19,24 +19,35 @@
use Models\Upload;
$id_allegato = filter('id_allegato');
$allegato = Upload::find($id_allegato);
$id_allegati = json_decode(filter('id_allegati'));
$id_allegato = json_decode(filter('id_allegato'));
// Form di inserimento riga documento
echo '
<form action="" method="post" id="modifica-allegato">
<input type="hidden" name="id_allegati" value="'.implode(';',$id_allegati).'">
<input type="hidden" name="id_allegato" value="'.$id_allegato.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="modifica-allegato">
<div class="row">
<div class="row">';
if ($id_allegato) {
$allegato = Upload::find($id_allegato);
echo '
<div class="col-md-6">
{[ "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'])).'" ]}
</div>
</div>';
} else {
$allegato = Upload::find($id_allegati[0]);
echo '
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "value": "" ]}
</div>';
}
echo '
</div>
<!-- PULSANTI -->

View File

@ -119,18 +119,26 @@ class FileManager implements ManagerInterface
<table class="table table-striped table-condensed ">
<thead>
<tr>
<th scope="col" width="5%" class="text-center"></th>
<th scope="col" >'.tr('Nome').'</th>
<th scope="col" width="15%" >'.tr('Data').'</th>
<th scope="col" width="10%" class="text-center">#</th>
</tr>
</thead>
<tbody>';
<tbody class="files">';
foreach ($rs as $r) {
$file = Upload::find($r['id']);
$result .= '
<tr id="row_'.$file->id.'" data-id="'.$file->id.'" data-filename="'.$file->filename.'" data-nome="'.$file->name.'">
<td class="text-center">';
if (!$options['readonly']) {
$result .= '
<input class="check_files" type="checkbox"/>';
}
$result .= '
</td>
<td align="left">';
if ($file->user && $file->user->photo) {
@ -173,7 +181,7 @@ class FileManager implements ManagerInterface
if (!$options['readonly']) {
$result .= '
<button type="button" class="btn btn-xs btn-warning" onclick="modificaAllegato(this)">
<button type="button" class="btn btn-xs btn-warning" onclick="modificaAllegato(this,$(this).closest(\'tr\').data(\'id\'))">
<i class="fa fa-edit"></i>
</button>';
if (!$file->isFatturaElettronica() || $options['abilita_genera']) {
@ -198,10 +206,29 @@ class FileManager implements ManagerInterface
</div>
<div class="clearfix"></div>
<br>';
';
}
}
if (!$options['readonly']) {
$result .= '
<div class="btn-group">';
if (!$options['readonly']) {
$result .= '
<button type="button" class="btn btn-xs btn-default">
<input class="pull-left" id="check_all_files" type="checkbox"/>
</button>';
}
$result .= '
<button type="button" class="btn btn-xs btn-default disabled" id="modifica_files" onclick="modificaAllegato(this,0,JSON.stringify(getSelectData()));">
<i class="fa fa-edit"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="zip_files" onclick="scaricaZipAllegati(this,JSON.stringify(getSelectData()));">
<i class="fa fa-file-archive-o"></i>
</button>
</div>';
}
// Form per l'upload di un nuovo file
if (!$options['readonly']) {
$result .= '
@ -267,6 +294,49 @@ $("#'.$attachment_id.' #upload").click(function(){
aggiungiAllegato(container);
});
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'.files\').find(\'.check_files:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
$(".check_files").on("change", function() {
let checked = 0;
$(".check_files").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#zip_files").removeClass("disabled");
$("#modifica_files").removeClass("disabled");
} else {
$("#zip_files").addClass("disabled");
$("#modifica_files").addClass("disabled");
}
});
$("#check_all_files").click(function(){
if( $(this).is(":checked") ){
$(".check_files").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check_files").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';
return $result;