2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2018-03-23 14:42:56 +01:00
// Lunghezza minima della password
$min_length_password = 8 ;
// Lunghezza minima del nome utente (username)
2017-08-04 16:28:16 +02:00
$min_length_username = 4 ;
2017-09-12 14:53:19 +02:00
2018-03-22 15:35:13 +01:00
$self_edit = Modules :: getPermission ( 'Utenti e permessi' ) != 'rw' || ( filter ( 'id_utente' ) == null && filter ( 'idgruppo' ) == null );
2018-02-20 14:23:00 +01:00
if ( $self_edit ) {
$user = Auth :: user ();
$id_utente = $user [ 'id' ];
2018-03-22 15:35:13 +01:00
} else {
$idgruppo = intval ( filter ( 'idgruppo' ));
$id_utente = filter ( 'id_utente' );
2018-06-25 19:15:46 +02:00
2018-06-26 14:30:26 +02:00
//gruppo della selezione
$nome_gruppo = $dbo -> fetchArray ( 'SELECT nome FROM zz_groups WHERE id=' . prepare ( $idgruppo ))[ 0 ][ 'nome' ];
$gruppi = [
'Clienti' => 'Cliente' ,
'Tecnici' => 'Tecnico' ,
'Agenti' => 'Agente' ,
];
$nome_gruppo = $gruppi [ $nome_gruppo ];
2018-02-20 14:23:00 +01:00
}
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
2018-11-20 22:39:06 +01:00
$rs = $dbo -> fetchArray ( 'SELECT idanagrafica, username, email FROM zz_users WHERE id=' . prepare ( $id_utente ));
2017-08-04 16:28:16 +02:00
$username = $rs [ 0 ][ 'username' ];
2018-11-20 22:39:06 +01:00
$email = $rs [ 0 ][ 'email' ];
2018-07-03 11:12:32 +02:00
$id_anagrafica = $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 = '' ;
2018-11-20 22:39:06 +01:00
$email = '' ;
2017-09-12 16:17:11 +02:00
$id_anagrafica = '' ;
2017-08-04 16:28:16 +02:00
}
echo '
2018-03-22 15:35:13 +01:00
< form action = " " method = " post " id = " link_form " >
2018-02-20 14:23:00 +01:00
< input type = " hidden " name = " op " value = " '. $op .' " >
2018-03-23 14:42:56 +01:00
< input type = " hidden " name = " min_length " value = " '. $min_length_password .' " >
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
2018-03-22 15:35:13 +01:00
if ( ! $self_edit ) {
2018-02-20 14:23:00 +01:00
echo '
< input type = " hidden " name = " backto " value = " record-edit " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-03-22 15:35:13 +01:00
< div class = " col-md-12 " >
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-11-20 22:39:06 +01:00
</ div >
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " text " , " label " : " '.tr('Email').' " , " name " : " email " , " required " : 0 , " value " : " '. $email .' " ]}
</ div >
2018-02-20 14:23:00 +01:00
</ div > ' ;
2018-11-20 22:39:06 +01:00
2018-02-20 14:23:00 +01:00
} else {
echo '
2018-11-20 22:39:06 +01:00
< input type = " hidden " id = " username " name = " username " value = " '. $username .' " >
< input type = " hidden " id = " email " name = " email " value = " '. $email .' " > ' ;
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 " >
2018-07-03 12:28:38 +02:00
{[ " type " : " password " , " label " : " '.tr('Password').' " , " name " : " password1 " , " required " : 1 ]}
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 " >
2018-07-03 12:28:38 +02:00
{[ " type " : " password " , " label " : " '.tr('Ripeti la password').' " , " name " : " password2 " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
2018-03-22 15:35:13 +01:00
if ( ! $self_edit ) {
2018-02-20 14:23:00 +01:00
echo '
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-03-22 15:35:13 +01:00
< div class = " col-md-12 " >
2018-06-26 14:30:26 +02:00
{[ " type " : " select " , " label " : " '.tr('Collega ad una anagrafica').' " , " name " : " idanag " , " required " : 1 , " ajax-source " : " anagrafiche_utenti " , " value " : " '. $id_anagrafica .' " , " icon-after " : " add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica='. $nome_gruppo .' " ]}
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 " >
2018-03-23 14:42:56 +01:00
var min_length = '.$min_length_password.' ;
2017-08-04 16:28:16 +02:00
var min_length_username = '.$min_length_username.' ;
function do_submit (){
if ( $ ( " #password1 " ) . val () == " " || $ ( " #password2 " ) . val () == " " )
2018-06-25 19:15:46 +02:00
swal ({
title : " '.tr('Inserire una password valida.').' " ,
type : " error " ,
});
2017-08-04 16:28:16 +02:00
else if ( $ ( " #password1 " ) . val () != $ ( " #password2 " ) . val () )
2018-06-25 19:15:46 +02:00
swal ({
title : " '.tr('Le password non coincidono.').' " ,
type : " error " ,
});
2017-08-04 16:28:16 +02:00
else if ( $ ( " #password1 " ) . val () . length < min_length )
2018-06-25 19:15:46 +02:00
swal ({
title : " '.tr('La password deve essere lunga minimo _MIN_ caratteri!', [
2018-06-26 14:30:26 +02:00
'_MIN_' => $min_length_password ,
]) . ' " ,
2018-06-25 19:15:46 +02:00
type : " error " ,
});
2017-08-04 16:28:16 +02:00
else if ( $ ( " #username " ) . val () . length < min_length_username )
2018-06-25 19:15:46 +02:00
swal ({
title : " '.tr('L \ 'username deve essere lungo minimo _MIN_ caratteri.', [
2018-06-26 14:30:26 +02:00
'_MIN_' => $min_length_username ,
]) . ' " ,
2018-06-25 19:15:46 +02:00
type : " error " ,
2018-07-03 11:12:32 +02:00
});
2017-08-04 16:28:16 +02:00
else
$ ( " #link_form " ) . submit ();
}
2018-11-20 11:30:01 +01:00
$ ( document ) . ready ( function (){
$ ( " #bs-popup #idanag " ) . val ( " '. $id_anagrafica .' " ) . change ();
});
2017-08-04 16:28:16 +02:00
</ script >
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;