2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
// Decido la lunghezza minima della password, e la lunghezza minima del nome utente
$min_length = 8 ;
$min_length_username = 4 ;
2017-09-12 14:53:19 +02:00
2018-02-20 14:23:00 +01:00
$self_edit = Modules :: getPermission ( 'Utenti e permessi' ) == 'rw' && filter ( 'id_utente' ) != null ;
if ( $self_edit ) {
$idgruppo = intval ( filter ( 'idgruppo' ));
$id_utente = filter ( 'id_utente' );
} else {
$user = Auth :: user ();
$id_utente = $user [ 'id' ];
}
2017-09-12 14:53:19 +02:00
2017-08-04 16:28:16 +02:00
if ( ! empty ( $id_utente )) {
2018-02-20 14:23:00 +01:00
$op = 'change_pwd' ;
2017-09-12 16:17:11 +02:00
$message = tr ( 'Modifica' );
2017-08-04 16:28:16 +02:00
2017-09-12 16:17:11 +02:00
$rs = $dbo -> fetchArray ( 'SELECT idanagrafica, idtipoanagrafica, username FROM zz_users WHERE id=' . prepare ( $id_utente ));
2017-08-04 16:28:16 +02:00
$username = $rs [ 0 ][ 'username' ];
2017-09-12 16:17:11 +02:00
$id_anagrafica = $rs [ 0 ][ 'idtipoanagrafica' ] . '-' . $rs [ 0 ][ 'idanagrafica' ];
2017-08-04 16:28:16 +02:00
} else {
2018-02-20 14:23:00 +01:00
$op = 'adduser' ;
2017-09-04 12:02:29 +02:00
$message = tr ( 'Aggiungi' );
2017-09-12 16:17:11 +02:00
$username = '' ;
$id_anagrafica = '' ;
2017-08-04 16:28:16 +02:00
}
echo '
2017-09-22 15:19:59 +02:00
< form id = " link_form " action = " '. $rootdir .'/editor.php?id_module='.Modules::get('Utenti e permessi')['id'].'&id_record='. $idgruppo .' " method = " post " >
2018-02-20 14:23:00 +01:00
< input type = " hidden " name = " op " value = " '. $op .' " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " min_length " value = " '. $min_length .' " >
2018-02-20 14:23:00 +01:00
< input type = " hidden " name = " min_length_username " value = " '. $min_length_username .' " > ' ;
2017-08-04 16:28:16 +02:00
if ( ! empty ( $id_utente )) {
echo '
2017-09-01 18:13:25 +02:00
< input type = " hidden " name = " id_utente " value = " '. $id_utente .' " > ' ;
2017-08-04 16:28:16 +02:00
}
2018-02-20 14:23:00 +01:00
if ( $self_edit ) {
echo '
< input type = " hidden " name = " backto " value = " record-edit " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " " >
2017-09-12 14:53:19 +02:00
{[ " type " : " text " , " label " : " '.tr('Username').' " , " name " : " username " , " required " : 1 , " value " : " '. $username .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 14:23:00 +01:00
</ div > ' ;
} else {
echo '
< input type = " hidden " id = " username " name = " username " value = " '. $username .' " > ' ;
}
echo '
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-21 17:47:43 +01:00
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " password " , " label " : " '.tr('Password').' " , " name " : " password1 " , " required " : 1 , " value " : " " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 14:23:00 +01:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
2018-02-20 14:23:00 +01:00
echo '
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-21 17:47:43 +01:00
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " password " , " label " : " '.tr('Ripeti la password').' " , " name " : " password2 " , " value " : " " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
2018-02-20 14:23:00 +01:00
if ( $self_edit ) {
echo '
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " " >
2017-09-12 16:17:11 +02:00
{[ " type " : " select " , " label " : " '.tr('Collega ad una anagrafica').' " , " name " : " idanag " , " values " : " query=SELECT CONCAT(`an_tipianagrafiche`.`idtipoanagrafica`, \ '- \ ', `an_anagrafiche`.`idanagrafica`) AS \ 'id \ ', `ragione_sociale` AS \ 'descrizione \ ', `descrizione` AS \ 'optgroup \ ' FROM `an_tipianagrafiche` INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche`.`idtipoanagrafica`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` ORDER BY `descrizione` ASC " , " value " : " '. $id_anagrafica .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 14:23:00 +01:00
</ div > ' ;
} else {
echo '
< input type = " hidden " id = " idanag " name = " idanag " value = " '. $id_anagrafica .' " > ' ;
}
2017-08-04 16:28:16 +02:00
echo '
< button type = " button " onclick = " do_submit() " class = " btn btn-primary " >< i class = " fa fa-plus " ></ i > '.$message.' </ button >
</ form >
2018-02-20 14:23:00 +01:00
2017-08-04 16:28:16 +02:00
< script type = " text/javascript " >
var min_length = '.$min_length.' ;
var min_length_username = '.$min_length_username.' ;
function do_submit (){
if ( $ ( " #password1 " ) . val () == " " || $ ( " #password2 " ) . val () == " " )
2017-09-04 12:02:29 +02:00
alert ( " '.tr('Inserire una password valida').'. " );
2017-08-04 16:28:16 +02:00
else if ( $ ( " #password1 " ) . val () != $ ( " #password2 " ) . val () )
2017-09-04 12:02:29 +02:00
alert ( " '.tr('Le password non coincidono').'. " );
2017-08-04 16:28:16 +02:00
else if ( $ ( " #password1 " ) . val () . length < min_length )
2017-09-10 14:35:41 +02:00
alert ( " '.tr('La password deve essere lunga minimo _MIN_ caratteri!', [
'_MIN_' => $min_length ,
]) . ' " );
2017-08-04 16:28:16 +02:00
else if ( $ ( " #username " ) . val () . length < min_length_username )
2017-09-10 14:35:41 +02:00
alert ( " '.tr( " L ' username deve essere lungo minimo _MIN_ caratteri ! " , [
'_MIN_' => $min_length_username ,
]) . ' " );
2017-08-04 16:28:16 +02:00
else
$ ( " #link_form " ) . submit ();
}
</ script >
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;