<?php
/* Ulyxex version 1.6.7.8 ***************/
/* code http://ulyxex.logz.org **********/
/* Andre Lozano http://andre-lozano.org */
class UserModify extends Admin {
public int $user_id;
function __construct($userId=null){
$this->h = New Htmlz();
$this->t = New Translate();
$this->user_id = $this->h->num($userId);
}
public function update_user(){
$h = $this->h;$t = $this->t;
/* not check if login is in use because login is read only */
/* update user */
$date = $h->htmlDate2Php($_POST['newDate']);
$passWarning = "";
if ($h->num($_POST['level']) < $_SESSION['level']){
$result = $h->h3($t->w("wrong level !"));
} elseif ($_POST['userlogin'] == ""){
$result = $h->h3($t->w("login field empty !"));
} elseif ($this->user_id == 1 && $_SESSION['userid'] != 1){
$result = $h->h3($t->w("only admin can modify admin !"));
} else {
$query = UPDATE.USERS.SET. "LOGIN = '".$h->safe($_POST['userlogin'])."',".
"USERNAME = '".$h->safe($_POST['username'])."',".
"DESCRIPTION = '".$h->safe($_POST['description'])."',".
"MAIL = '".$h->safe($_POST['mail'])."',".
"USERLEVEL = ".$h->num($_POST['level']);
if (isset($_POST['confirmchangepass'])) {
$query .= ",PASSWORD = '".$h->crypt($_POST['password'])."'";
$passWarning = " (password changed)";
}
$query .= ",DATEPAGE = '".$h->safe($date)."'";
if (isset($_POST['userid']) && $_POST['userid'] != $_POST['old_userid']) $query .= ",USEROWNER = ".$h->num($_POST['userid']); // change userId
$query .= WHERE."ID = ".$this->user_id;
$query = $this->q($query);
$result = $h->h3($t->wr("user").strip_tags($_POST['username']).$t->wl("updated !").$passWarning,$h->v("class","warning"));
}
return $result;
}
public function data_user(){
$h = $this->h;$t = $this->t;
$query = SELECT.ALLFIELDS.FROM.USERS.WHERE."ID = ".$this->user_id.";";
$query = $this->q($query);
if ($dat = $this->fetch($query)){
if ( $_SESSION['userid'] == $dat['ID'] || $dat['USEROWNER'] == $_SESSION['userid'] || $_SESSION['userid'] == 1){
$_[] = $h->input("hidden","update",1);
$_[] = $h->input("hidden","user",$dat['ID']);
$_[] = $h->p(
"(id:".$dat['ID'].") ".$h->lbl($t->wr("login"),"userlogin").
$h->input("text","userlogin",$dat['LOGIN'],$h->v("readonly","readonly").$h->alt($t->w("cannot change login")))
);
$_[] = (
$_SESSION['userid'] == 1 && $dat['ID'] !=1)
?
$h->input("hidden","old_userid",$dat['USEROWNER']).$h->p($h->lbl($t->wr("choose owner"),"userid").$this->array_users($dat['USEROWNER']))
:
null;
$_[] = $h->p(
$h->lbl($t->wr("modify the password"),"password").$h->input("password","password","",$h->v("size",(FIELDWIDTH/2)))." ".
$h->lbl($t->wr("confirm the modification"),"confirmchangepass").$h->input("checkbox","confirmchangepass",null)
);
$_[] = $h->p(
$h->input("checkbox","viewpass",null,$h->v("onclick","showPassword(['password'])")).
$h->lbl($t->wl("show/hide password"),"viewpass")
);
if ($this->user_id == 1){
$_[] = $h->input("hidden","level",$dat['ID']);
} else {
$levels = array();
for ($i=0;$i < (5 - $_SESSION['level']);$i++){
$x = 4 - $i;
$levels["level ".$x] = $x;
}
$_[] = $h->p($h->lbl($t->wr("level"),"level").$h->select($levels,"level",$dat['USERLEVEL']),$h->alt($t->w("users levels")));
}
$_[] = $h->p($h->lbl($t->wr("name"),"username")).$h->p($h->input("text","username",$h->entities($dat['USERNAME']),$h->v("size",FIELDWIDTH)));
$_[] = $h->p($h->lbl($t->w("description"),"description")).$h->p($h->textarea($dat['DESCRIPTION'],"description",array(8,FIELDWIDTH)));
$_[] = $h->p($h->lbl($t->wr("mail"),"mail").$h->input("email","mail",$dat['MAIL'],$h->v("size",(FIELDWIDTH/2))));
$date = $h->phpDate2Html($dat['DATEPAGE']);
$_[] = $h->p(
$h->lbl($t->wr("modify date"),"newDate").
$h->input("datetime-local","newDate",$date).
" ".$h->button("⟳",$h->v("onclick","updateDateTime('newDate')").$h->alt($t->w("refresh")))
);
$_[] = $h->p($h->input("submit",null,$t->w("update")));
$inputs = implode("",$_);
return $h->form($inputs,"user","post","admin.php?action=modify_user");
} else {
return $h->p("error");
}
} else {
return $h->p("error");
}
}
}
?>