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' ;
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 );
2018-07-19 17:29:21 +02:00
flash () -> info ( 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 ;
2018-07-19 17:29:21 +02:00
flash () -> info ( 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 );
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Aggiunto un nuovo componente in sostituzione al precedente!' ));
2017-08-04 16:28:16 +02:00
} else {
2018-07-19 17:29:21 +02:00
flash () -> error ( 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 );
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( " Rimosso componente dall'impianto! " ));
2017-08-04 16:28:16 +02:00
break ;
}
// Componenti non ancora collegati
2018-06-23 18:35:08 +02:00
if ( empty ( $id_list )) {
2017-08-04 16:28:16 +02:00
$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 " >
2019-05-16 19:36:57 +02:00
< div class = " col-md-9 " >
2017-08-04 16:28:16 +02:00
< 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 >
2019-05-16 19:36:57 +02:00
< div class = " col-md-3 " > ' ;
2017-08-04 16:28:16 +02:00
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 );
2019-11-22 16:28:03 +01:00
2017-08-04 16:28:16 +02:00
if ( get ( 'id' ) == $rs2 [ $j ][ 'id' ]) {
2019-11-21 00:01:08 +01:00
$collapsed = '' ;
$icon = 'minus' ;
2017-08-04 16:28:16 +02:00
} elseif ( $_SESSION [ 'idcomponente' ] == $rs2 [ $j ][ 'id' ]) {
unset ( $_SESSION [ 'idcomponente' ]);
2019-11-21 00:01:08 +01:00
$collapsed = '' ;
$icon = 'minus' ;
2017-08-04 16:28:16 +02:00
} else {
2019-11-21 00:01:08 +01:00
$collapsed = 'collapsed-box' ;
$icon = 'plus' ;
2017-08-04 16:28:16 +02:00
}
echo '
2019-11-21 00:01:08 +01:00
< div class = " box '. $collapsed .' box-'.( $same ? 'default' : 'primary').' " >
< div class = " box-header with-border'.( $same ? ' mini' : '').' " >
< h3 class = " box-title'.( $same ? ' mini' : '').' " > ' .
( $same ? '<small>' : '' ) . $nome_componente . ' (' . $statocomponente . ')' . ( $same ? '</small>' : '' ) . '
</ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-'. $icon .' " ></ i >
</ button >
</ div >
</ div > ' ;
echo '
< div id = " collapse_'. $j .' " class = " box-body " >
< div class = " row " > ' ;
2017-08-04 16:28:16 +02:00
// 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 " >
2018-08-28 17:10:23 +02:00
< div class = " alert alert-info " >< i class = \ 'fa fa-info-circle\'></i> ' . tr ( 'Nessun intervento collegato a questo componente!' ) . ' </ div >
2017-08-04 16:28:16 +02:00
</ div > ' ;
}
if ( ! empty ( $rs2 [ $j ][ 'idintervento' ])) {
echo '
2018-08-11 15:37:38 +02:00
'.Modules::link(' Interventi ', $rs2[$j][' idintervento '], 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 '
2020-09-07 15:04:06 +02:00
< div class = " col-md-12 " >
2019-05-16 19:36:57 +02:00
< a class = " btn btn-danger ask " data - backto = " record-edit " data - op = " unlinkcomponente " data - id = " '. $rs2[$j] ['id'].' " >< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').' </ a > ' ;
2019-05-17 05:56:10 +02:00
// Sostituisci componente con un altro dello stesso tipo, posso sostituire solo i componenti installati
2018-09-03 16:49:43 +02:00
if ( empty ( $rs2 [ $j ][ 'data_sostituzione' ])) {
echo "
2019-05-16 19:36:57 +02:00
< button class = \ " btn btn-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' ] . " '; }else { return false} \" ><i class='fa fa-refresh'></i> " . tr ( 'Sostituisci questo componente' ) . '</button>' ;
2018-09-03 16:49:43 +02:00
} else {
echo '
2019-05-16 19:36:57 +02:00
< button class = " btn btn-warning disabled " disabled > '.tr(' Componente già sostituito ').' </ button > ' ;
2018-09-03 16:49:43 +02:00
}
2019-05-17 05:56:10 +02:00
echo '
2019-05-16 19:36:57 +02:00
< button type = " submit " class = " btn btn-success pull-right " >< i class = " fa fa-check " ></ i > '.tr(' Salva modifiche ').' </ button > ' ;
2017-08-04 16:28:16 +02:00
2018-09-03 16:49:43 +02:00
echo '
2017-08-04 16:28:16 +02:00
</ div >
</ form >
</ div >
</ div >
</ div > ' ;
$prev_componente = $nome_componente ;
}
echo '
</ div > ' ;
} else {
echo '
2018-08-28 17:10:23 +02:00
< div class = \ 'alert alert-info\' ><i class=\'fa fa-info-circle\'></i> ' . tr ( 'Nessun componente inserito' ) . '.</div>' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;