2017-08-04 16:28:16 +02:00
< ? php
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' ) {
2017-08-04 16:28:16 +02:00
$matricole_old = $dbo -> fetchArray ( 'SELECT * FROM my_impianti_interventi WHERE idintervento=' . prepare ( $id_record ));
$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 ));
$components = $dbo -> fetchArray ( 'SELECT * FROM my_impianto_componenti WHERE idimpianto = ' . 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 ));
}
}
}
}
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
2019-05-17 19:17:12 +02:00
$dbo -> query ( 'DELETE FROM my_componenti_interventi WHERE id_componente IN (SELECT id FROM my_impianto_componenti WHERE idimpianto = ' . 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
}
2018-02-16 15:45:15 +01:00
//Blocco della modifica impianti se l'intervento è completato
2020-03-12 22:15:02 +01:00
$rss = $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 ));
$flg_completato = $rss [ 0 ][ 'is_completato' ];
2018-02-16 15:45:15 +01:00
2018-02-18 19:53:23 +01:00
if ( $flg_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 " >
2017-09-04 12:02:29 +02:00
< h3 class = " box-title " > '.tr("Impianti dell' intervento " ).'</h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " box-body " >
2017-09-04 12:02:29 +02:00
< p > '.tr("Impianti su cui è stato effettuato l' intervento " ).'</p>';
2017-08-04 16:28:16 +02:00
$query = 'SELECT * FROM my_impianti_interventi INNER JOIN my_impianti ON my_impianti_interventi.idimpianto=my_impianti.id WHERE idintervento=' . prepare ( $id_record );
$rs = $dbo -> fetchArray ( $query );
echo '
< div class = " row " > ' ;
foreach ( $rs as $r ) {
echo '
< div class = " col-md-3 " >
< table class = " table table-hover table-condensed table-striped " > ' ;
// MATRICOLA
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.tr(' Matricola ').' :</ td >
2017-08-04 16:28:16 +02:00
< td valign = " top " > '.$r[' matricola '].' </ td >
</ 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-07-31 16:20:31 +02:00
'.Modules::link(' Impianti ', $r[' id '], $r[' 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 >
2017-08-04 16:28:16 +02:00
< td valign = " top " > '.Translator::dateToLocale($r[' data ']).' </ td >
</ tr > ' ;
// DESCRIZIONE
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.tr(' Descrizione ').' :</ td >
2017-08-04 16:28:16 +02:00
< td valign = " top " > '.$r[' descrizione '].' </ td >
</ 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 " >
< form action = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=link_componenti&matricola='. $r['id'] .' " method = " post " >
< input type = " hidden " name = " backto " value = " record-edit " >
2019-05-17 19:17:12 +02:00
< input type = " hidden " name = " id_impianto " value = " '. $r['id'] .' " > ' ;
2017-08-04 16:28:16 +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-08-17 16:25:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Componenti').' " , " multiple " : 1 , " name " : " componenti[] " , " ajax-source " : " componenti " , " select-options " : { " matricola " : '.$r[' id '].' }, " value " : " '.implode(',', $ids ).' " , " readonly " : " '.!empty( $readonly ).' " , " disabled " : " '.!empty( $disabled ).' " ]}
2017-08-04 16:28:16 +02:00
2018-02-16 15:45:15 +01: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 '
2017-09-04 12:02:29 +02:00
< p >< strong > '.tr(' Impianti disponibili ').' </ strong ></ p >
2020-08-17 16:25:01 +02:00
< form action = " '. $rootdir .'/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 " >
2020-08-17 16:25:01 +02:00
{[ " type " : " select " , " name " : " matricole[] " , " multiple " : 1 , " value " : " '.implode(',', $impianti ).' " , " ajax-source " : " impianti-cliente " , " select-options " : { " idanagrafica " : '.$record[' idanagrafica '].' }, " extra " : " '. $readonly .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< br >< br >
2019-05-16 19:36:57 +02:00
< button type = " submit " class = " btn btn-success " '.$disabled.' >< i class = " fa fa-check " ></ i > '.tr(' Salva impianti ').' </ button >
2019-05-17 19:17:12 +02:00
2020-08-17 16:25:01 +02:00
< button type = " button " class = " btn btn-primary " data - toggle = " modal " data - title = " '.tr('Aggiungi impianto').' " data - href = " '. $rootdir .'/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 > ' ;