2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
|
|
|
* Copyright (C) DevCode s.n.c.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
$op = post('op');
|
|
|
|
|
2020-07-31 16:20:31 +02:00
|
|
|
$upload_dir = $docroot.'/files/'.Modules::get('Impianti')['directory'];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
switch ($op) {
|
|
|
|
// Aggiorno informazioni di base impianto
|
|
|
|
case 'update':
|
|
|
|
$matricola = post('matricola');
|
|
|
|
|
|
|
|
if (!empty($matricola)) {
|
2018-07-10 16:39:02 +02:00
|
|
|
$dbo->update('my_impianti', [
|
|
|
|
'idanagrafica' => post('idanagrafica'),
|
|
|
|
'nome' => post('nome'),
|
|
|
|
'matricola' => $matricola,
|
2018-10-19 10:53:47 +02:00
|
|
|
'id_categoria' => post('id_categoria') ?: null,
|
2018-07-10 16:39:02 +02:00
|
|
|
'descrizione' => post('descrizione'),
|
|
|
|
'idsede' => post('idsede'),
|
|
|
|
'data' => post('data'),
|
|
|
|
'proprietario' => post('proprietario'),
|
|
|
|
'palazzo' => post('palazzo'),
|
|
|
|
'ubicazione' => post('ubicazione'),
|
|
|
|
'idtecnico' => post('idtecnico'),
|
|
|
|
'scala' => post('scala'),
|
|
|
|
'piano' => post('piano'),
|
|
|
|
'interno' => post('interno'),
|
|
|
|
'occupante' => post('occupante'),
|
|
|
|
], ['id' => $id_record]);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Informazioni salvate correttamente!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Upload file
|
|
|
|
if (!empty($_FILES) && !empty($_FILES['immagine']['name'])) {
|
2018-07-10 16:39:02 +02:00
|
|
|
$filename = Uploads::upload($_FILES['immagine'], [
|
|
|
|
'name' => 'Immagine',
|
|
|
|
'id_module' => $id_module,
|
|
|
|
'id_record' => $id_record,
|
|
|
|
], [
|
|
|
|
'thumbnails' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!empty($filename)) {
|
|
|
|
$dbo->update('my_impianti', [
|
|
|
|
'immagine' => $filename,
|
|
|
|
], [
|
|
|
|
'id' => $id_record,
|
|
|
|
]);
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->warning(tr('Errore durante il caricamento del file in _DIR_!', [
|
2017-09-10 14:35:41 +02:00
|
|
|
'_DIR_' => $upload_dir,
|
2018-07-07 13:56:22 +02:00
|
|
|
]));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eliminazione file
|
|
|
|
if (post('delete_immagine') !== null) {
|
2018-07-18 15:20:10 +02:00
|
|
|
Uploads::delete($record['immagine'], [
|
2018-07-10 16:39:02 +02:00
|
|
|
'id_module' => $id_module,
|
|
|
|
'id_record' => $id_record,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$dbo->update('my_impianti', [
|
|
|
|
'immagine' => null,
|
|
|
|
], [
|
|
|
|
'id' => $id_record,
|
|
|
|
]);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Aggiungo impianto
|
|
|
|
case 'add':
|
|
|
|
$matricola = post('matricola');
|
|
|
|
$idanagrafica = post('idanagrafica');
|
|
|
|
$nome = post('nome');
|
|
|
|
$idtecnico = post('idtecnico');
|
2019-01-10 18:41:25 +01:00
|
|
|
$idsede = post('idsede');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
if (!empty($matricola)) {
|
2019-01-10 18:41:25 +01:00
|
|
|
$dbo->query('INSERT INTO my_impianti(matricola, idanagrafica, nome, data, idtecnico, idsede) VALUES ('.prepare($matricola).', '.prepare($idanagrafica).', '.prepare($nome).', NOW(), '.prepare($idtecnico).', '.prepare($idsede).')');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$id_record = $dbo->lastInsertedID();
|
2018-06-26 09:41:43 +02:00
|
|
|
|
2019-11-14 18:37:42 +01:00
|
|
|
if (isAjaxRequest()) {
|
2018-06-26 14:30:26 +02:00
|
|
|
echo json_encode(['id' => $id_record, 'text' => $matricola.' - '.$nome]);
|
2018-05-14 14:31:18 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Aggiunto nuovo impianto!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Carica i campi da compilare del componente
|
|
|
|
case 'load_componente':
|
|
|
|
$filename = post('filename');
|
|
|
|
$idarticolo = post('idarticolo');
|
|
|
|
|
|
|
|
// Se è stato specificato un idarticolo, carico il file .ini dal campo `contenuto` di quell'idarticolo
|
|
|
|
$rs = $dbo->fetchArray('SELECT contenuto, componente_filename FROM mg_articoli WHERE id='.prepare($idarticolo));
|
|
|
|
|
|
|
|
// Se i campi da caricare sono del componente già salvato leggo dal campo `contenuto`...
|
|
|
|
if ($rs[0]['componente_filename'] == $filename) {
|
|
|
|
$contenuto = $rs[0]['contenuto'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...altrimenti carico dal file .ini
|
2017-09-10 14:35:41 +02:00
|
|
|
elseif (file_exists($docroot.'/files/my_impianti/'.$filename)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$contenuto = file_get_contents($docroot.'/files/my_impianti/'.$filename);
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:14:10 +02:00
|
|
|
crea_form_componente($contenuto);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-05-03 16:31:58 +02:00
|
|
|
// Duplica impianto
|
|
|
|
case 'copy':
|
|
|
|
|
|
|
|
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM my_impianti WHERE id= '.prepare($id_record));
|
|
|
|
$dbo->query('ALTER TABLE tmp DROP id');
|
|
|
|
$dbo->query('INSERT INTO my_impianti SELECT NULL,tmp. * FROM tmp');
|
|
|
|
$id_record = $dbo->lastInsertedID();
|
2019-05-04 03:29:43 +02:00
|
|
|
$dbo->query('DROP TEMPORARY TABLE tmp');
|
2019-05-03 16:31:58 +02:00
|
|
|
|
2019-05-04 03:29:43 +02:00
|
|
|
$dbo->query('UPDATE my_impianti SET matricola = CONCAT (matricola, " (copia)") WHERE id = '.prepare($id_record));
|
2019-05-03 16:31:58 +02:00
|
|
|
|
|
|
|
flash()->info(tr('Impianto duplicato correttamente!'));
|
2019-05-04 03:29:43 +02:00
|
|
|
|
2019-05-03 16:31:58 +02:00
|
|
|
break;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Rimuovo impianto e scollego tutti i suoi componenti
|
|
|
|
case 'delete':
|
|
|
|
$dbo->query('DELETE FROM my_impianti WHERE id='.prepare($id_record));
|
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Impianto e relativi componenti eliminati!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-07-10 16:39:02 +02:00
|
|
|
|
|
|
|
// Operazioni aggiuntive per l'immagine
|
2018-07-18 15:20:10 +02:00
|
|
|
if (filter('op') == 'unlink_file' && filter('filename') == $record['immagine']) {
|
2018-07-10 16:39:02 +02:00
|
|
|
$dbo->update('my_impianti', [
|
|
|
|
'immagine' => null,
|
|
|
|
], [
|
|
|
|
'id' => $id_record,
|
|
|
|
]);
|
|
|
|
} elseif (filter('op') == 'link_file' && filter('nome_allegato') == 'Immagine') {
|
|
|
|
$dbo->update('my_impianti', [
|
|
|
|
'immagine' => $upload,
|
|
|
|
], [
|
|
|
|
'id' => $id_record,
|
|
|
|
]);
|
|
|
|
}
|