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
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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' ;
2018-06-26 10:25:50 +02:00
$matricole = ( array ) post ( 'matricole' );
2017-08-04 16:28:16 +02:00
// Salvo gli impianti selezionati
2020-08-17 16:25:01 +02:00
if ( filter ( 'op' ) == 'link_impianti' ) {
2021-08-05 18:17:26 +02:00
$matricole_old = $dbo -> fetchArray ( 'SELECT * FROM my_impianti_interventi WHERE idintervento = ' . prepare ( $id_record ));
2017-08-04 16:28:16 +02:00
$matricole_old = array_column ( $matricole_old , 'idimpianto' );
// Individuazione delle matricole mancanti
foreach ( $matricole_old as $matricola ) {
if ( ! in_array ( $matricola , $matricole )) {
$dbo -> query ( 'DELETE FROM my_impianti_interventi WHERE idintervento=' . prepare ( $id_record ) . ' AND idimpianto = ' . prepare ( $matricola ));
2021-08-05 18:17:26 +02:00
$components = $dbo -> fetchArray ( 'SELECT * FROM my_componenti WHERE id_impianto = ' . prepare ( $matricola ));
2017-08-04 16:28:16 +02:00
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 ));
}
}
}
}
foreach ( $matricole as $matricola ) {
if ( ! in_array ( $matricola , $matricole_old )) {
$dbo -> query ( 'INSERT INTO my_impianti_interventi(idimpianto, idintervento) VALUES(' . prepare ( $matricola ) . ', ' . prepare ( $id_record ) . ')' );
}
}
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Informazioni impianti salvate!' ));
2017-08-04 16:28:16 +02:00
} elseif ( filter ( 'op' ) == 'link_componenti' ) {
2018-07-19 15:33:32 +02:00
$components = ( array ) post ( 'componenti' );
2019-05-17 19:17:12 +02:00
$id_impianto = post ( 'id_impianto' );
2017-08-04 16:28:16 +02:00
2021-08-05 18:17:26 +02: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 ));
2017-08-04 16:28:16 +02:00
foreach ( $components as $component ) {
2019-05-17 19:17:12 +02:00
$dbo -> query ( 'INSERT INTO my_componenti_interventi(id_componente, id_intervento) VALUES (' . prepare ( $component ) . ', ' . prepare ( $id_record ) . ')' );
2017-08-04 16:28:16 +02:00
}
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Informazioni componenti salvate!' ));
2017-08-04 16:28:16 +02:00
}
2020-09-07 14:52:46 +02:00
// Blocco della modifica impianti se l'intervento è completato
$dati_intervento = $dbo -> fetchArray ( 'SELECT in_statiintervento.is_completato FROM in_statiintervento INNER JOIN in_interventi ON in_statiintervento.idstatointervento = in_interventi.idstatointervento WHERE in_interventi.id=' . prepare ( $id_record ));
$is_completato = $dati_intervento [ 0 ][ 'is_completato' ];
2018-02-16 15:45:15 +01:00
2020-09-07 14:52:46 +02:00
if ( $is_completato ) {
2018-02-16 15:45:15 +01:00
$readonly = 'readonly' ;
$disabled = 'disabled' ;
} else {
$readonly = '' ;
$disabled = '' ;
}
2017-08-04 16:28:16 +02:00
// IMPIANTI
echo '
< div class = " box " >
< div class = " box-header with-border " >
2022-02-05 22:22:48 +01:00
< h3 class = " box-title " > '.tr("Impianti soggetti ad intervento").' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2022-02-05 22:22:48 +01:00
< div class = " box-body " > ' ;
2017-08-04 16:28:16 +02:00
2020-09-07 14:52:46 +02:00
$impianti_collegati = $dbo -> fetchArray ( 'SELECT * FROM my_impianti_interventi INNER JOIN my_impianti ON my_impianti_interventi.idimpianto = my_impianti.id WHERE idintervento = ' . prepare ( $id_record ));
2017-08-04 16:28:16 +02:00
echo '
< div class = " row " > ' ;
2020-09-07 14:52:46 +02:00
foreach ( $impianti_collegati as $impianto ) {
2017-08-04 16:28:16 +02:00
echo '
2021-08-05 18:17:26 +02:00
< div class = " col-md-4 " >
2017-08-04 16:28:16 +02:00
< table class = " table table-hover table-condensed table-striped " > ' ;
// MATRICOLA
echo '
< tr >
2021-08-05 18:17:26 +02:00
< td class = " text-right " width = " 25% " > '.tr(' Matricola ').' :</ td >
2020-09-07 14:52:46 +02:00
< td valign = " top " > '.$impianto[' matricola '].' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
// NOME
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.tr(' Nome ').' :</ td >
2017-08-04 16:28:16 +02:00
< td valign = " top " >
2020-09-07 14:52:46 +02:00
'.Modules::link(' Impianti ', $impianto[' id '], $impianto[' nome ']).'
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
// DATA
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.tr(' Data ').' :</ td >
2020-09-07 14:52:46 +02:00
< td valign = " top " > '.dateFormat($impianto[' data ']).' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
// DESCRIZIONE
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.tr(' Descrizione ').' :</ td >
2020-09-07 14:52:46 +02:00
< td valign = " top " > '.$impianto[' descrizione '].' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td valign = " top " class = " text-right " > '.tr("Componenti soggetti all' intervento " ).'</td>
2017-08-04 16:28:16 +02:00
< td valign = " top " >
2020-09-23 17:53:19 +02:00
< form action = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=link_componenti&matricola='. $impianto['id'] .' " method = " post " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
2020-09-07 14:52:46 +02:00
< input type = " hidden " name = " id_impianto " value = " '. $impianto['id'] .' " > ' ;
2017-08-04 16:28:16 +02:00
2020-09-07 14:52:46 +02:00
$inseriti = $dbo -> fetchArray ( 'SELECT * FROM my_componenti_interventi WHERE id_intervento = ' . prepare ( $id_record ));
2019-05-17 19:17:12 +02:00
$ids = array_column ( $inseriti , 'id_componente' );
2017-08-04 16:28:16 +02:00
echo '
2019-05-17 19:17:12 +02:00
2020-09-07 14:52:46 +02:00
{[ " type " : " select " , " label " : " '.tr('Componenti').' " , " multiple " : 1 , " name " : " componenti[] " , " id " : " componenti_'. $impianto['id'] .' " , " ajax-source " : " componenti " , " select-options " : { " matricola " : '.$impianto[' id '].' }, " value " : " '.implode(',', $ids ).' " , " readonly " : " '.!empty( $readonly ).' " , " disabled " : " '.!empty( $disabled ).' " ]}
2017-08-04 16:28:16 +02:00
2021-08-05 18:17:26 +02:00
< button type = " submit " class = " btn btn-success " '.$disabled.' >
< i class = " fa fa-check " ></ i > '.tr(' Salva componenti ').'
</ button >
2017-08-04 16:28:16 +02:00
</ form >
</ td >
</ tr >
</ table >
</ div > ' ;
}
echo '
</ div > ' ;
/*
Aggiunta impianti all ' intervento
*/
// Elenco impianti collegati all'intervento
2017-09-18 18:11:19 +02:00
$impianti = $dbo -> fetchArray ( 'SELECT idimpianto FROM my_impianti_interventi WHERE idintervento=' . prepare ( $id_record ));
$impianti = ! empty ( $impianti ) ? array_column ( $impianti , 'idimpianto' ) : [];
2017-08-04 16:28:16 +02:00
// Elenco sedi
2018-07-18 15:20:10 +02:00
$sedi = $dbo -> fetchArray ( 'SELECT id, nomesede, citta FROM an_sedi WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . " UNION SELECT 0, 'Sede legale', '' ORDER BY id " );
2017-08-04 16:28:16 +02:00
echo '
2020-09-23 17:53:19 +02:00
< form action = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=link_impianti " method = " post " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
< div class = " row " >
< div class = " col-xs-12 col-md-6 " >
2022-02-05 22:22:48 +01:00
{[ " type " : " select " , " name " : " matricole[] " , " label " : " '.tr('Impianti').' " , " multiple " : 1 , " value " : " '.implode(',', $impianti ).' " , " ajax-source " : " impianti-cliente " , " select-options " : { " idanagrafica " : '.$record[' idanagrafica '].' , " idsede_destinazione " : '.($record[' idsede_destinazione '] ?: ' " " ').' }, " extra " : " '. $readonly .' " , " icon-after " : " add|'.Modules::get('Impianti')['id'].'|id_anagrafica='. $record['idanagrafica'] .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< br >< br >
2022-02-06 00:15:35 +01:00
< button type = " submit " class = " btn btn-success pull-right " '.$disabled.' >< i class = " fa fa-check " ></ i > '.tr(' Salva impianti ').' </ button >
2019-05-17 19:17:12 +02:00
2022-02-06 00:15:35 +01:00
< button type = " button " class = " btn btn-primary hide " data - toggle = " modal " data - title = " '.tr('Aggiungi impianto').' " data - href = " '.base_path().'/add.php?id_module='.Modules::get('Impianti')['id'].'&source=Attività&select=idimpianti&id_anagrafica='. $record['idanagrafica'] .'&ajax=yes " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi impianto ').' </ button >
2019-05-17 19:17:12 +02:00
2017-08-04 16:28:16 +02:00
</ form > ' ;
echo '
</ div >
2019-05-17 05:56:10 +02:00
</ div > ' ;