2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
switch ( filter ( 'op' )) {
case 'updatecomponente' :
$idcomponente = get ( 'id' );
$data = post ( 'data_componente' );
// Ricavo il valore di contenuto leggendolo dal db
$query = 'SELECT * FROM my_impianto_componenti WHERE idimpianto=' . prepare ( $id_record ) . ' AND id=' . prepare ( $idcomponente );
$rs = $dbo -> fetchArray ( $query );
$contenuto = $rs [ 0 ][ 'contenuto' ];
$contenuto = \Util\Ini :: write ( $contenuto , $post );
$query = 'UPDATE my_impianto_componenti SET data=' . prepare ( $data ) . ', contenuto=' . prepare ( $contenuto ) . ' WHERE idimpianto=' . prepare ( $id_record ) . ' AND id=' . prepare ( $idcomponente );
$dbo -> query ( $query );
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Informazioni componente aggiornate correttamente!' );
2017-08-04 16:28:16 +02:00
$_SESSION [ 'idcomponente' ] = $idcomponente ;
break ;
case 'linkcomponente' :
$filename = get ( 'filename' );
if ( ! empty ( $filename )) {
$contenuto = file_get_contents ( $docroot . '/files/my_impianti/' . $filename );
$nome = \Util\Ini :: getValue ( \Util\Ini :: readFile ( $docroot . '/files/my_impianti/' . $filename ), 'Nome' );
$query = 'INSERT INTO my_impianto_componenti(filename, idimpianto, contenuto, nome, data) VALUES(' . prepare ( $filename ) . ', ' . prepare ( $id_record ) . ', ' . prepare ( $contenuto ) . ', ' . prepare ( $nome ) . ', NOW())' ;
$dbo -> query ( $query );
$idcomponente = $dbo -> lastInsertedID ();
$_SESSION [ 'idcomponente' ] = $idcomponente ;
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( " Aggiunto un nuovo componente all'impianto! " );
2017-08-04 16:28:16 +02:00
}
break ;
case 'sostituiscicomponente' :
$filename = get ( 'filename' );
$id = get ( 'id' );
$nome = \Util\Ini :: getValue ( \Util\Ini :: readFile ( $docroot . '/files/my_impianti/' . $filename ), 'Nome' );
$contenuto = file_get_contents ( $docroot . '/files/my_impianti/' . $filename );
// Verifico che questo componente non sia già stato sostituito
$query = 'SELECT * FROM my_impianto_componenti WHERE idsostituto = ' . prepare ( $id );
$rs = $dbo -> fetchArray ( $query );
if ( empty ( $rs )) {
// Inserisco il nuovo componente in sostituzione
$query = 'INSERT INTO my_impianto_componenti(idsostituto, filename, idimpianto, contenuto, nome, data) VALUES(' . prepare ( $id ) . ', ' . prepare ( $filename ) . ', ' . prepare ( $id_record ) . ', ' . prepare ( $contenuto ) . ', ' . prepare ( $nome ) . ', NOW())' ;
$dbo -> query ( $query );
$idcomponente = $dbo -> lastInsertedID ();
$_SESSION [ 'idcomponente' ] = $idcomponente ;
// Aggiorno la data di sostituzione del componente precedente
$query = 'UPDATE my_impianto_componenti SET data_sostituzione = NOW() WHERE idimpianto = ' . prepare ( $id_record ) . ' AND id = ' . prepare ( $id );
$dbo -> query ( $query );
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Aggiunto un nuovo componente in sostituzione al precedente!' );
2017-08-04 16:28:16 +02:00
} else {
2017-09-04 12:02:29 +02:00
$_SESSION [ 'errors' ][] = tr ( 'Questo componente è già stato sostituito!' ) . ' ' . ( 'Nessuna modifica applicata' );
2017-08-04 16:28:16 +02:00
}
break ;
case 'unlinkcomponente' :
$idcomponente = filter ( 'id' );
$query = 'DELETE FROM my_impianto_componenti WHERE id=' . prepare ( $idcomponente ) . ' AND idimpianto=' . prepare ( $id_record );
$dbo -> query ( $query );
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( " Rimosso componente dall'impianto! " );
2017-08-04 16:28:16 +02:00
break ;
}
// Componenti non ancora collegati
if ( $id_list == '' ) {
$id_list = '0' ;
}
echo '
< div class = " box " >
< div class = " box-header with-border " >
2017-09-04 12:02:29 +02:00
< h3 class = " box-title " > '.tr(' Componenti installati ').' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " box-body " > ' ;
// Elenca i componenti disponibili
$cmp = \Util\Ini :: getList ( $docroot . '/files/my_impianti/' , $id_list );
echo '
< div class = " row " >
< div class = " col-md-4 col-md-push-6 " >
< select class = " superselect " id = " filename " name = " filename " > ' ;
if ( count ( $cmp ) > 0 ) {
echo '
2017-09-04 12:02:29 +02:00
< option value = " 0 " >- '.tr(' Aggiungi un componente ').' -</ option > ' ;
2017-08-04 16:28:16 +02:00
for ( $c = 0 ; $c < count ( $cmp ); ++ $c ) {
echo '
< option value = " '. $cmp[$c] [0].' " > '.$cmp[$c][1].' </ option > ' ;
}
} else {
echo '
2017-09-04 12:02:29 +02:00
< option value = " 0 " >- '.tr(' Hai già aggiunto tutti i componenti ').' -</ option > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ select >
</ div >
< div class = " col-md-2 col-md-push-6 " > ' ;
echo "
2017-09-12 12:49:05 +02:00
< a class = \ " btn btn-primary btn-block \" id= \" addta \" href= \" javascript:; \" onclick= \" if ( $ ('#filename').val()!='0' ) { redirect(' " . $rootdir . '/editor.php?id_module=' . $id_module . '&id_record=' . $id_record . " &op=linkcomponente&backto=record-edit&filename='+ $ ('#filename').val() + '&hash=tab_ " . $id_plugin . " ');}else { alert(' " . tr ( 'Seleziona prima un componente' ) . " '); $ ('#filename').focus(); } \" ><i class='fa fa-plus'></i> " . tr ( 'Aggiungi' ) . '</a>' ;
2017-08-04 16:28:16 +02:00
echo '
</ div >
</ div >
< div class = " clearfix " ></ div >
< br > ' ;
// Mostro tutti i componenti utilizzati elencando quelli attualmente installati per primi.
$q2 = 'SELECT *, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi.id=my_impianto_componenti.idintervento) AS data_intervento FROM my_impianto_componenti WHERE idimpianto = ' . prepare ( $id_record ) . ' ORDER by nome ASC, data_intervento DESC, idsostituto DESC' ;
$rs2 = $dbo -> fetchArray ( $q2 );
$n2 = count ( $rs2 );
if ( ! empty ( $rs2 )) {
$prev_componente = '' ;
echo '
< div class = " panel-group " id = " accordion " > ' ;
// Ciclo tra tutti i componenti
for ( $j = 0 ; $j < $n2 ; ++ $j ) {
$contenuto = $rs2 [ $j ][ 'contenuto' ];
$nome_componente = $rs2 [ $j ][ 'nome' ];
$filename = $rs2 [ $j ][ 'filename' ];
2017-08-29 16:34:02 +02:00
if ( empty ( $rs2 [ $j ][ 'data_sostituzione' ])) {
2017-09-10 14:35:41 +02:00
$statocomponente = tr ( 'INSTALLATO in data _DATE_' , [
'_DATE_' => Translator :: dateToLocale ( $rs2 [ $j ][ 'data' ]),
]);
2017-08-04 16:28:16 +02:00
} else {
2017-09-10 14:35:41 +02:00
$statocomponente = tr ( 'SOSTITUITO in data _DATE_' , [
'_DATE_' => Translator :: dateToLocale ( $rs2 [ $j ][ 'data_sostituzione' ]),
]);
2017-08-04 16:28:16 +02:00
}
// Per più "versioni" dello stesso componente mostro un riga meno evidente
// per non confonderlo come componente in uso in questo momento
$same = ( $prev_componente == $nome_componente );
echo '
< div class = " panel panel-'.( $same ? 'default' : 'primary').' " >
< div class = " panel-heading'.( $same ? ' mini' : '').' " >
< h4 class = " panel-title'.( $same ? ' mini' : '').' " >
2018-03-24 14:24:17 +01:00
< a data - toggle = " collapse " data - parent = " #accordion " href = " #collapse_'. $j .' " > '.($same ? ' < small > ' : ' ').$nome_componente.' ( '.$statocomponente.' ) '.($same ? ' </ small > ' : ' ').' </ a >
2017-08-04 16:28:16 +02:00
</ h4 >
</ div > ' ;
if ( get ( 'id' ) == $rs2 [ $j ][ 'id' ]) {
$in = 'in' ;
} elseif ( $_SESSION [ 'idcomponente' ] == $rs2 [ $j ][ 'id' ]) {
unset ( $_SESSION [ 'idcomponente' ]);
$in = 'in' ;
} else {
$in = '' ;
}
echo '
< div id = " collapse_'. $j .' " class = " panel-collapse collapse '. $in .' " >
< div class = " panel-body " > ' ;
// FORM COMPONENTE
echo '
< form method = " post " action = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=updatecomponente&id='. $rs2[$j] ['id'].' " >
< input type = " hidden " name = " backto " value = " record-edit " > ' ;
// Nome
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " span " , " label " : " '.tr('Nome').': " , " name " : " nome " , " value " : " '. $rs2[$j] ['nome'].' " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Data
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " date " , " label " : " '.tr('Data').': " , " name " : " data_componente " , " id " : " data_componente'. $j .' " , " value " : " '. $rs2[$j] ['data'].' " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
$fields = \Util\Ini :: getFields ( $contenuto );
array_shift ( $fields );
foreach ( $fields as $field ) {
echo '
< div class = " col-md-6 " >
'.$field.'
</ div > ' ;
}
2018-03-07 23:50:28 +01:00
$interventi = $dbo -> fetchArray ( 'SELECT *, DATE_FORMAT(data_richiesta,"%d/%m/%Y") AS data_richiesta, (SELECT descrizione FROM in_tipiintervento WHERE idtipointervento=in_interventi.idtipointervento) AS tipo, (SELECT descrizione FROM in_statiintervento WHERE idstatointervento=in_interventi.idstatointervento) AS stato, (SELECT colore FROM in_statiintervento WHERE idstatointervento=in_interventi.idstatointervento) AS colore FROM in_interventi INNER JOIN my_componenti_interventi ON my_componenti_interventi.id_intervento=in_interventi.id WHERE id_componente=' . prepare ( $rs2 [ $j ][ 'id' ]) . ' ORDER BY id_intervento' );
2017-08-04 16:28:16 +02:00
if ( $interventi != null ) {
// Collegamento a intervento se c'è
echo '
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
< b > '.tr(' Interventi collegati ').' :</ b >
2017-08-04 16:28:16 +02:00
< table class = " table table-condensed " >
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Codice ').' </ th >
< th > '.tr(' Tipo ').' </ th >
< th > '.tr(' Stato ').' </ th >
< th > '.tr(' Data richiesta ').' </ th >
< th > '.tr(' Dettagli ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
foreach ( $interventi as $intervento ) {
echo '
< tr bgcolor = " '. $intervento['colore'] .' " >
2018-03-07 23:50:28 +01:00
< td > '.$intervento[' codice '].' </ td >
2017-08-04 16:28:16 +02:00
< td > '.$intervento[' tipo '].' </ td >
< td > '.$intervento[' stato '].' </ td >
< td > '.$intervento[' data_richiesta '].' </ td >
< td > '.Modules::link(' Interventi ', $intervento[' id_intervento '], null, ' - ').' </ td >
</ tr > ' ;
}
echo '
</ table >
</ div > ' ;
} else {
echo '
< div class = " clearfix " ></ div >
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
< div class = " alert alert-info " > '.tr(' Nessun intervento collegato a questo componente ! ').' </ div >
2017-08-04 16:28:16 +02:00
</ div > ' ;
}
if ( ! empty ( $rs2 [ $j ][ 'idintervento' ])) {
echo '
2017-09-21 10:01:07 +02:00
'.Modules::link(' Interventi ', $rs2[$j][' id '], tr(' Intervento num . _NUM_ del _DATE_ ' , [
2017-09-10 14:35:41 +02:00
'_NUM_' => $rs2 [ $j ][ 'codice' ],
2017-09-12 12:49:05 +02:00
'_DATE_' => Translator :: dateToLocale ( $rs2 [ $j ][ 'data_intervento' ]),
2017-09-10 14:35:41 +02:00
])) . '<br>' ;
2017-08-04 16:28:16 +02:00
}
echo '
< div class = " clearfix " ></ div >
< br > ' ;
// Pulsante Salva/Elimina
echo '
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
< button type = " submit " class = " btn btn-success " >< i class = " fa fa-check " ></ i > '.tr(' Salva modifiche ').' </ button >
2017-08-04 16:28:16 +02:00
< a class = " btn btn-danger ask " data - backto = " record-edit " data - op = " unlinkcomponente " data - id = " '. $rs2[$j] ['id'].' " >
2017-09-04 12:02:29 +02:00
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
2017-08-04 16:28:16 +02:00
</ a >
</ div > ' ;
// Sostituisci componente con un altro dello stesso tipo, posso sostituire solo i componenti installati
echo '
< div class = " col-md-12 " > ' ;
2017-08-29 16:34:02 +02:00
if ( empty ( $rs2 [ $j ][ 'data_sostituzione' ])) {
2017-08-04 16:28:16 +02:00
echo "
2017-09-04 12:02:29 +02:00
< a href = \ " javascript:; \" class= \" text-warning \" onclick= \" if( confirm(' " . tr ( 'Vuoi sostituire questo componente con un altro dello stesso tipo?' ) . " ') ) { location.href=' " . $rootdir . '/editor.php?id_module=' . $id_module . '&id_record=' . $id_record . '&op=sostituiscicomponente&backto=record-edit&filename=' . $filename . '&id=' . $rs2 [ $j ][ 'id' ] . " '; } \" ><i class='fa fa-refresh'></i> " . tr ( 'Sostituisci questo componente' ) . '</a><br><br>' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2017-09-04 12:02:29 +02:00
< p class = " text-danger " > '.tr(' Componente già sostituito ').' </ p > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ form >
</ div >
</ div >
</ div > ' ;
$prev_componente = $nome_componente ;
}
echo '
</ div > ' ;
} else {
echo '
2017-09-04 12:02:29 +02:00
< p > '.tr(' Nessun componente inserito ').' .</ p > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;