2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
$id_record = filter ( 'id_record' );
$operazione = filter ( 'op' );
switch ( $operazione ) {
case 'addreferente' :
$nome = filter ( 'nome' );
$mansione = filter ( 'mansione' );
$telefono = filter ( 'telefono' );
$email = filter ( 'email' );
$idsede = filter ( 'idsede' );
if ( isset ( $nome ) && isset ( $idsede )) {
$query = 'INSERT INTO `an_referenti` (`nome`, `mansione`, `telefono`, `email`, `idanagrafica`, `idsede`) VALUES (' . prepare ( $nome ) . ', ' . prepare ( $mansione ) . ', ' . prepare ( $telefono ) . ', ' . prepare ( $email ) . ', ' . prepare ( $id_record ) . ', ' . prepare ( $idsede ) . ')' ;
$dbo -> query ( $query );
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Aggiunto nuovo referente!' );
2017-08-04 16:28:16 +02:00
}
break ;
case 'updatereferenti' :
foreach ( $_POST [ 'idreferente' ] as $key => $value ) {
$query = 'UPDATE `an_referenti` SET `nome`=' . prepare ( $_POST [ 'nome' ][ $key ]) . ', `mansione`=' . prepare ( $_POST [ 'mansione' ][ $key ]) . ', `telefono`=' . prepare ( $_POST [ 'telefono' ][ $key ]) . ', `email`=' . prepare ( $_POST [ 'email' ][ $key ]) . ', `idsede`=' . prepare ( $_POST [ 'idsede' ][ $key ]) . ' WHERE `id`=' . prepare ( $value );
$dbo -> query ( $query );
}
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Salvataggio completato!' );
2017-08-04 16:28:16 +02:00
break ;
case 'deletereferente' :
$idreferente = filter ( 'id' );
$dbo -> query ( " DELETE FROM `an_referenti` WHERE `id`= " . prepare ( $idreferente ));
2017-09-04 12:02:29 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Referente eliminato!' );
2017-08-04 16:28:16 +02:00
break ;
}
if ( filter ( 'add' ) != null ) {
echo '
2017-08-28 10:07:38 +02:00
< form action = " " method = " post " role = " form " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " addreferente " >
< div class = " row " >
< div class = " col-xs-12 col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " label " : " '.tr('Nominativo').' " , " name " : " nome " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-xs-12 col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " label " : " '.tr('Mansione').' " , " name " : " mansione " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-xs-12 col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " label " : " '.tr('Telefono').' " , " name " : " telefono " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-xs-12 col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " label " : " '.tr('Indirizzo email').' " , " name " : " email " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-xs-12 col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Sede').' " , " name " : " idsede " , " values " : " query=SELECT -1 AS id, \ 'Sede legale \ ' AS descrizione UNION SELECT id, CONCAT_WS( \ ' - \ ', nomesede, citta) AS descrizione FROM an_sedi WHERE idanagrafica='. $id_record .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-xs-12 col-md-12 text-right " >
2017-09-04 12:02:29 +02:00
< button type = " submit " class = " btn btn-primary " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').' </ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form >
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;
} else {
echo '
< div class = " box " >
< div class = " box-header with-border " >
2017-09-04 12:02:29 +02:00
< h3 class = " box-title " > '.tr(' Referenti ').' </ h3 >
< a class = " btn btn-primary pull-right " data - toggle = " modal " data - target = " #bs-popup " data - title = " Nuovo referente " data - href = " '. $rootdir .'/modules/anagrafiche/plugins/referenti.php?add=1&id_record='. $id_record .' " >< i class = " fa fa-plus " ></ i > '.tr(' Nuovo referente ').' </ a >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " box-body " >
2017-09-04 12:02:29 +02:00
< p > '.tr(' Qui hai la possibilità di gestire i referenti di questa anagrafica ').' .</ p >
2017-08-04 16:28:16 +02:00
< form action = " " method = " post " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " updatereferenti " > ' ;
$query = 'SELECT * FROM an_referenti WHERE idanagrafica=' . prepare ( $id_record ) . ' ORDER BY id DESC' ;
$results = $dbo -> fetchArray ( $query );
if ( count ( $results ) != 0 ) {
echo '
< table class = " table table-condensed table-striped table-hover " >
< thead >
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Nominativo ').' </ th >
< th > '.tr(' Mansione ').' </ th >
< th > '.tr(' Telefono ').' </ th >
< th > '.tr(' Indirizzo email ').' </ th >
< th > '.tr(' Sede ').' </ th >
< th > '.tr(' Opzioni ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr >
</ thead >
< tbody > ' ;
foreach ( $results as $result ) {
echo '
< tr >
< td >
< input type = " hidden " name = " idreferente[] " value = " '. $result['id'] .' " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " placeholder " : " '.tr('Nominativo').' " , " name " : " nome[] " , " required " : 1 , " value " : " '. $result['nome'] .' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " placeholder " : " '.tr('Mansione').' " , " name " : " mansione[] " , " required " : 1 , " value " : " '. $result['mansione'] .' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " placeholder " : " '.tr('Telefono').' " , " name " : " telefono[] " , " value " : " '. $result['telefono'] .' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " placeholder " : " '.tr('Indirizzo email').' " , " name " : " email[] " , " value " : " '. $result['email'] .' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " placeholder " : " '.tr('Sede').' " , " name " : " idsede[] " , " values " : " query=SELECT -1 AS id, \ 'Sede legale \ ' AS descrizione UNION SELECT id, CONCAT( CONCAT_WS( \ ' ( \ ', CONCAT_WS( \ ', \ ', `nomesede`, `citta`), `indirizzo` ), \ ') \ ') AS descrizione FROM an_sedi WHERE idanagrafica='. $id_record .' " , " value " : " '. $result['idsede'] .' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td >
< a class = " btn btn-danger pull-right ask " data - op = " deletereferente " data - id = " '. $result['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 >
</ td >
</ tr > ' ;
}
echo '
</ tbody >
</ table >
< div class = " pull-right " >
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
</ div >
< div class = " clearfix " ></ div > ' ;
}
echo '
</ form >
</ div >
</ div > ' ;
}