_server/user.php
/**
 * @param $userID
 * @param $mail
 * @param $name
 * @param $passwd
 * @param $color
 * @param $role
 * @param $active

 * Returning codes:
 * 0 = success
 * 1 = UserDB could not be find
 * 2 = User is not Admin and not himself
 * 3 = All data has been saved but mail because its not valid. so old mailadress will still be saved/used

 */


Returning codes:
0 = success
1 = UserDB could not be find
2 = User is not Admin and not himself
3 = All data has been saved but mail because its not valid. so old mailadress will still be saved/used
Returning codes : 0 = success 1 = UserDB could not be find 2 = User is not Admin and not himself 3 = All data has been saved but mail because its not valid . so old mailadress will still be saved / used
function userChange($userID,$mail,$name,$passwd,$color,$role,$active) {
	global $conf;
	$userFile = $conf["dir"]["data"]."/users.json";
	if (!file_exists($userFile)) {
		$return["status"] = "fail";
		$return["code"] = 1;
		$return["string"] = "User DB missing";
		return $return;
	}
	if ($_SESSION["ohv"]["login"] == 1) {
		$file = new sharedFile($userFile);
		$json = $file->read();
		$userdb = json_decode($json,true);
		$tmpUserID = $_SESSION["ohv"]["user"]["id"];
		$_SESSION["ohv"]["user"] = $userdb["user"][$tmpUserID];
		$_SESSION["ohv"]["user"]["id"] = $tmpUserID;
		if ((($_SESSION["ohv"]["user"]["role"] != "admin") && ($userID != $tmpUserID))) {
			$return["status"] = "fail";
			$return["code"] = 2;
			$return["string"] = "user is not admin nor himself";
		} elseif (($_SESSION["ohv"]["user"]["active"] != 1)) {
			$return["status"] = "fail";
			$return["code"] = 5;
			$return["string"] = "user is not active";
			unset($_SESSION["ohv"]);
		} else {
			if ($userdb["user"][$userID]) {
				$return["code"] = 0;
				if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
					$mail = strtolower($userdb["user"][$userID]["mail"]);
					$return["code"] = 3;
				} else {
					$mail = strtolower($mail);
				}
				$userdb["user"][$userID]["role"] = ((($role) && ($_SESSION["ohv"]["user"]["role"] == "admin")) ? $role : $userdb["user"][$userID]["role"]);
				$userdb["user"][$userID]["name"] = $name;
				$userdb["user"][$userID]["mail"] = $mail;
				$userdb["user"][$userID]["color"] = $color;
				$userdb["user"][$userID]["active"] = ((($active==="1" || $active==="0") && (($_SESSION["ohv"]["user"]["role"] == "admin"))) ? $active*1 : $userdb["user"][$userID]["active"]*1);
				$userdb["user"][$userID]["passwd"] = ($passwd) ? hash("sha256",$passwd.$userdb["user"][$userID]["registrationDate"]) : $userdb["user"][$userID]["passwd"];
				$file->write(json_encode($userdb, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));				
				$return["status"] = "success";
				$return["string"] = "userdata updated";
				$return["response"] = $userdb["user"][$userID];
				unset($return["response"]["passwd"]);
			} else {
				$return["status"] = "fail";
				$return["code"] = 6;
				$return["string"] = "Targeted User not found";
			}
		}
		$file->close();
	} else {
		$return["status"] = "fail";
		$return["code"] = 4;
		$return["string"] = "User not logged in";
	}
	return $return;
}
function userChange ( $ userID , $ mail , $ name , $ passwd , $ color , $ role , $ active ) { global $ conf ; $ userFile = $ conf [ " dir " ] [ " data " ] . " /users.json " ; if ( ! file_exists ( $ userFile ) ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 1 ; $ return [ " string " ] = " User DB missing " ; return $ return ; } if ( $ _SESSION [ " ohv " ] [ " login " ] == 1 ) { $ file = new sharedFile ( $ userFile ) ; $ json = $ file -> read ( ) ; $ userdb = json_decode ( $ json , true ) ; $ tmpUserID = $ _SESSION [ " ohv " ] [ " user " ] [ " id " ] ; $ _SESSION [ " ohv " ] [ " user " ] = $ userdb [ " user " ] [ $ tmpUserID ] ; $ _SESSION [ " ohv " ] [ " user " ] [ " id " ] = $ tmpUserID ; if ( ( ( $ _SESSION [ " ohv " ] [ " user " ] [ " role " ] != " admin " ) && ( $ userID != $ tmpUserID ) ) ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 2 ; $ return [ " string " ] = " user is not admin nor himself " ; } elseif ( ( $ _SESSION [ " ohv " ] [ " user " ] [ " active " ] != 1 ) ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 5 ; $ return [ " string " ] = " user is not active " ; unset ( $ _SESSION [ " ohv " ] ) ; } else { if ( $ userdb [ " user " ] [ $ userID ] ) { $ return [ " code " ] = 0 ; if ( ! filter_var ( $ mail , FILTER_VALIDATE_EMAIL ) ) { $ mail = strtolower ( $ userdb [ " user " ] [ $ userID ] [ " mail " ] ) ; $ return [ " code " ] = 3 ; } else { $ mail = strtolower ( $ mail ) ; } $ userdb [ " user " ] [ $ userID ] [ " role " ] = ( ( ( $ role ) && ( $ _SESSION [ " ohv " ] [ " user " ] [ " role " ] == " admin " ) ) ? $ role : $ userdb [ " user " ] [ $ userID ] [ " role " ] ) ; $ userdb [ " user " ] [ $ userID ] [ " name " ] = $ name ; $ userdb [ " user " ] [ $ userID ] [ " mail " ] = $ mail ; $ userdb [ " user " ] [ $ userID ] [ " color " ] = $ color ; $ userdb [ " user " ] [ $ userID ] [ " active " ] = ( ( ( $ active === " 1 " || $ active === " 0 " ) && ( ( $ _SESSION [ " ohv " ] [ " user " ] [ " role " ] == " admin " ) ) ) ? $ active * 1 : $ userdb [ " user " ] [ $ userID ] [ " active " ] * 1 ) ; $ userdb [ " user " ] [ $ userID ] [ " passwd " ] = ( $ passwd ) ? hash ( " sha256 " , $ passwd . $ userdb [ " user " ] [ $ userID ] [ " registrationDate " ] ) : $ userdb [ " user " ] [ $ userID ] [ " passwd " ] ; $ file -> write ( json_encode ( $ userdb , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) ) ; $ return [ " status " ] = " success " ; $ return [ " string " ] = " userdata updated " ; $ return [ " response " ] = $ userdb [ " user " ] [ $ userID ] ; unset ( $ return [ " response " ] [ " passwd " ] ) ; } else { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 6 ; $ return [ " string " ] = " Targeted User not found " ; } } $ file -> close ( ) ; } else { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 4 ; $ return [ " string " ] = " User not logged in " ; } return $ return ; }
@param $userID
 @param $mail
 @param $name
 @param $passwd
 @param $color
 @param $role
 @param $active
@param $userID @param $mail @param $name @param $passwd @param $color @param $role @param $active
//Update own data to check if user is still admin