2024-03-05 17:31:36 +01:00
< ? 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 />.
*/
include_once __DIR__ . '/../../core.php' ;
2024-03-06 09:23:43 +01:00
use Models\Module ;
2024-03-22 15:52:24 +01:00
use Modules\Checklists\Check ;
2024-03-05 17:31:36 +01:00
$operazione = filter ( 'op' );
2024-06-11 16:58:27 +02:00
$id_modulo_impianti = Module :: where ( 'name' , 'Impianti' ) -> first () -> id ;
2024-03-05 17:31:36 +01:00
switch ( $operazione ) {
case 'add_impianto' :
if ( post ( 'id_impianto' )) {
$dbo -> query ( 'INSERT INTO my_impianti_interventi(idimpianto, idintervento) VALUES(' . prepare ( post ( 'id_impianto' )) . ', ' . prepare ( $id_record ) . ')' );
2024-03-06 09:23:43 +01:00
$checks_impianti = $dbo -> fetchArray ( 'SELECT * FROM zz_checks WHERE id_module = ' . prepare ( $id_modulo_impianti ) . ' AND id_record = ' . prepare ( post ( 'id_impianto' )));
2024-03-05 17:31:36 +01:00
foreach ( $checks_impianti as $check_impianto ) {
$id_parent_new = null ;
if ( $check_impianto [ 'id_parent' ]) {
$parent = $dbo -> selectOne ( 'zz_checks' , '*' , [ 'id' => $check_impianto [ 'id_parent' ]]);
$id_parent_new = $dbo -> selectOne ( 'zz_checks' , '*' , [ 'content' => $parent [ 'content' ], 'id_module' => $id_module , 'id_record' => $id_record ])[ 'id' ];
}
2024-03-06 09:23:43 +01:00
$check = Check :: build ( $user , $structure , $id_record , $check_impianto [ 'content' ], $id_parent_new , $check_impianto [ 'is_titolo' ], $check_impianto [ 'order' ], $id_modulo_impianti , post ( 'id_impianto' ));
2024-03-05 17:31:36 +01:00
$check -> id_module = $id_module ;
$check -> id_plugin = $id_plugin ;
$check -> note = $check_impianto [ 'note' ];
$check -> save ();
}
flash () -> info ( tr ( 'Impianto aggiunto correttamente!' ));
} else {
flash () -> warning ( tr ( 'Selezionare un impianto!' ));
}
break ;
case 'update_impianto' :
2024-04-23 17:14:56 +02:00
$components = ( post ( 'componenti' ) ? ( array ) post ( 'componenti' ) : []);
2024-03-05 17:31:36 +01:00
$note = post ( 'note' );
$id_impianto = post ( 'id_impianto' );
2024-03-22 15:52:24 +01:00
2024-03-05 17:31:36 +01:00
$dbo -> query ( 'DELETE FROM my_componenti_interventi WHERE id_componente IN (SELECT id FROM my_componenti WHERE id_impianto = ' . prepare ( $id_impianto ) . ') AND id_intervento = ' . prepare ( $id_record ));
2024-03-22 15:52:24 +01:00
2024-03-05 17:31:36 +01:00
foreach ( $components as $component ) {
$dbo -> query ( 'INSERT INTO my_componenti_interventi(id_componente, id_intervento) VALUES (' . prepare ( $component ) . ', ' . prepare ( $id_record ) . ')' );
}
$dbo -> update ( 'my_impianti_interventi' , [
2024-03-22 15:52:24 +01:00
'note' => $note ,
2024-03-05 17:31:36 +01:00
], [
'idintervento' => $id_record ,
2024-03-22 15:52:24 +01:00
'idimpianto' => $id_impianto ,
2024-03-05 17:31:36 +01:00
]);
flash () -> info ( tr ( 'Impianto modificato correttamente!' ));
break ;
case 'delete_impianto' :
$dbo -> query ( 'DELETE FROM my_impianti_interventi WHERE idintervento=' . prepare ( $id_record ) . ' AND idimpianto = ' . prepare ( post ( 'id' )));
Check :: deleteLinked ([
'id_module' => $id_module ,
'id_record' => $id_record ,
2024-03-06 09:23:43 +01:00
'id_module_from' => $id_modulo_impianti ,
2024-03-05 17:31:36 +01:00
'id_record_from' => post ( 'id' ),
]);
$components = $dbo -> fetchArray ( 'SELECT * FROM my_componenti WHERE id_impianto = ' . prepare ( $matricola ));
if ( ! empty ( $components )) {
foreach ( $components as $component ) {
$dbo -> query ( 'DELETE FROM my_componenti_interventi WHERE id_componente = ' . prepare ( $component [ 'id' ]) . ' AND id_intervento = ' . prepare ( $id_record ));
}
}
flash () -> info ( tr ( 'Impianto rimosso correttamente!' ));
2024-04-23 17:14:56 +02:00
break ;
case 'load_checklist' :
$checks = Check :: where ( 'id_module_from' , $id_modulo_impianti ) -> where ( 'id_record_from' , post ( 'id_impianto' )) -> where ( 'id_module' , $id_module ) -> where ( 'id_record' , $id_record ) -> where ( 'id_parent' , null ) -> get ();
$response = '' ;
foreach ( $checks as $check ) {
$response .= renderChecklist ( $check );
}
/* echo json_encode ([
'checklist' => $response
]); */
echo $response ;
2024-03-05 17:31:36 +01:00
break ;
}