'.print_r($_POST,1).''.N; use function mysqli_real_escape_string as myesc; // praticamente una macro function hspech($str) { return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8')); } function inputerr(&$account) { muoribene(t('

Errori di input.
Stavi cercando di editare il tuo account?

','

Input errors.
Where you trying to edit your account?

').N,true); } $postmisskeys=ckkeys(array('id','Username','Email','Password','CPassword'),$_POST); if (count($postmisskeys)==0 && preg_match('/^[0-9]+$/',$_POST['id'])===1 && mb_strlen($_POST['Username'])>=1 && mb_strlen($_POST['Username'])<=$fields['Username'] && mb_strlen($_POST['Email'])>=3 && mb_strlen($_POST['Email'])<=$fields['Email'] && $_POST['Password']==$_POST['CPassword'] && ($_POST['Password']=='' || (mb_strlen($_POST['Password'])>=8 && mb_strlen($_POST['Password'])<=64))) { $id=$_POST['id']+0; $post=true; } elseif (array_key_exists('id',$_GET) && preg_match('/^[0-9]+$/',$_GET['id'])==1) { $id=$_GET['id']+0; $post=false; } else { inputerr($account); } if ($account['Level']=='guest' && $id==0) inputerr($account); if ($account['Level']=='guest' && $id!=$account['ID']) muoribene('

You can edit your account only.

'.N,true); if ($id!=0) { $res=mysqli_query($link,'SELECT * FROM Admins WHERE ID='.$id) or muoribene(__LINE__.': '.mysqli_error($link),true); if (mysqli_num_rows($res)==0) muoribene('

Non esiste alcun account con ID='.$id.'
Se vuoi puoi editare il tuo account.

',true); $acc=mysqli_fetch_assoc($res); $passreq=''; } else { $acc=array( 'ID'=>0, 'Username'=>'', 'Email'=>'', 'Password'=>'', 'Level'=>'normal', 'MaxLocalities'=>1, 'MaxLanguages'=>0, 'MaxFinancing'=>3, 'MaxPolicies'=>3, 'MaxTags'=>3, 'Enabled'=>1 ); $passreq=' required'; } ($account['ID']==$acc['ID']) ? $ownacc=true : $ownacc=false; if ($id!=0 && $account['Level']=='normal' && !$ownacc && $acc['Level']!='guest') muoribene('

Come admin di livello “normale” puoi editare solo il tuo account e gli account di livello “guest”.

',true); if ($id==0) $atit=t('Nuovo account','New account'); elseif ($ownacc) $atit=t('Il tuo account','Your account'); else $atit='Account «'.hspech($acc['Email']).'»'; /* [id] => 3 [Username] => bida [Email] => mastodon@bida.im [Password] => [CPassword] => [Level] => guest [MaxLocalities] => 1 [MaxLanguages] => 0 [MaxFinancing] => 5 [MaxPolicies] => 3 [MaxTags] => 3 [Enabled] => 1 */ function ckmax($key) { global $fields; if (preg_match('/^[0-9]+$/',$_POST[$key])==1 && $_POST[$key]+0>=$fields[$key]['min'] && $_POST[$key]+0<=$fields[$key]['max']) return(true); else return(false); } if ($post) { $quea=array(); $quea[]='Username="'.myesc($link,$_POST['Username']).'"'; $quea[]='Email="'.myesc($link,$_POST['Email']).'"'; if ($_POST['Password']!='' || $_POST['CPassword']!='') { if ($_POST['Password']!=$_POST['CPassword']) inputerr($account); $quea[]='Password="'.myesc($link,password_hash($_POST['Password'],PASSWORD_DEFAULT)).'"'; } $ok=true; if (array_key_exists('Level',$_POST)) { if (!in_array($_POST['Level'],array('guest','normal','super'))) $ok=false; if ($account['Level']=='normal' && !$ownacc && !in_array($_POST['Level'],array('guest','normal'))) $ok=false; if ($account['Level']=='normal' && $ownacc) $ok=false; if ($account['Level']=='guest') $ok=false; if (!$ok) inputerr($account); $quea[]='Level="'.$_POST['Level'].'"'; } if (count(ckkeys(array('MaxLocalities','MaxLanguages','MaxFinancing','MaxPolicies','MaxTags'),$_POST))==0) { if ($account['Level']=='guest') $ok=false; if ($account['Level']=='normal' && $ownacc) $ok=false; if ($ok && ckmax('MaxLocalities') && ckmax('MaxLanguages') && ckmax('MaxFinancing') && ckmax('MaxPolicies') && ckmax('MaxTags')) { $quea[]='MaxLocalities='.$_POST['MaxLocalities']; $quea[]='MaxLanguages='.$_POST['MaxLanguages']; $quea[]='MaxFinancing='.$_POST['MaxFinancing']; $quea[]='MaxPolicies='.$_POST['MaxPolicies']; $quea[]='MaxTags='.$_POST['MaxTags']; } else { inputerr($account); } } if (array_key_exists('Enabled',$_POST)) { if (!in_array($_POST['Enabled'],array('0','1'))) inputerr($account); ($ownacc && $_POST['Enabled']=='0') ? $logout=true : $logout=false; $quea[]='Enabled='.$_POST['Enabled']; } if ($id!=0) $que='UPDATE Admins SET '.implode(', ',$quea).' WHERE ID='.$id; else $que='INSERT INTO Admins SET '.implode(', ',$quea); $dbg.='QUERONA: '.hspech($que); mysqli_query($link,$que) or muoribene(__LINE__.': '.mysqli_error($link),true); if ($logout) { $_SESSION=array(); session_destroy(); muoribene('

'.t('Il tuo account è stato disattivato correttamente. Ciao! :-)','Your account has been correctly disabled. Bye! :-)').'

'.N,true); } $out='
'; if ($id!=0) { if ($ownacc) $out.=t('L’aggiornamento del tuo account («'.hspech($_POST['Email']).'») è andato a buon fine.','Your account («'.hspech($_POST['Email']).'») was updated successfully.'); else $out.=t('L’aggiornamento dell’account «'.hspech($_POST['Email']).'» è andato a buon fine.','Account «'.hspech($_POST['Email']).'» was updated successfully.'); } else { $id=mysqli_insert_id($link); $out.='Il nuovo account «'.hspech($_POST['Email']).'» è stato creato correttamente.'; } $out.='
'.N; } else { $out='
'.N; $out.=''.N; $out.=''.N; $out.=''.N; $out.=''.N; $out.=''.N; $out.='
'.$atit.'
'.N; $out.=''.N; $out.='
'.N; $out.='
'.N; if ($id!=0) $out.='
'.t('Lascia vuoti i campi “Password” e “Conferma password” per mantenere la password attuale.','Leave “Password” and “Password confirm” fields blank to keep your current password.').'
'.N; $out.='
'.N; $out.='
'.N; if ($account['Level']!='guest' && !$ownacc) { $out.='
'.N; $out.='
'.N; $out.='
'.N; $out.='
'.N; $out.='
'.N; $out.='
'.N; } $out.='
'.N; $out.=''.N; $out.='
'.N; $out.='
'.N; } mysqli_close($link); ?> Mustard - <?php echo($atit); ?>