<?


if ($_SESSION['username'] == "admin") {
	if ($_POST['spaceQuota'] == "limited") {
		$spaceQuota = $str->fromHTML($_POST['spaceQuotaSize'])*1024*1024;
	} elseif ($str->fromHTML($_POST['spaceQuota']) == "inherit") {
		$spaceQuota = "";
	} else {
		$spaceQuota = "-";
	}
	
	if ($str->fromHTML($_POST['trafficQuota']) == "limited") {
		$trafficQuota = $str->fromHTML($_POST['trafficQuotaSize'])*1024*1024;
	} elseif ($str->fromHTML($_POST['trafficQuota']) == "inherit") {
		$trafficQuota = "";
	} else {
		$trafficQuota = "-";
	}
	
	$oldInfo = $auth->getUserInfoById($str->fromHTML($_GET['uid']));
	
	
	$data['gid'] = $oldInfo['gid'];
	
	$optionalInfo['firstname'] = $str->fromHTML($_POST['firstname']);
	$optionalInfo['lastname'] = $str->fromHTML($_POST['lastname']);
	$optionalInfo['email'] = $str->fromHTML($_POST['email']);
	$optionalInfo['company'] = $str->fromHTML($_POST['company']);
	
	if ($_POST['permstyle']['path'] == "inherit") {
		$data['path'] = "";
	} else {
		$data['path'] = ($settings->config['demomode'])?$settings->config['demorestrictedfolder']:cleanPath(rawurldecode($_POST['userpath']));
	}
	
	$data['lastlogin'] = $oldInfo['lastlogin'];
	
	if ($_POST['permstyle']['upload'] == "inherit") {
		$data['upload'] = "";
	} else {
		$data['upload'] = ($_POST['upload'])?"1":"0";
	}
	
	if ($_POST['permstyle']['download'] == "inherit") {
		$data['download'] = "";
	} else {
		$data['download'] = ($_POST['download'])?"1":"0";
	}
	
	if ($_POST['permstyle']['notReadOnly'] == "inherit") {
		$data['readonly'] = "";
	} else {
		$data['readonly'] = ($_POST['notReadOnly'])?"0":"1";
	}
	
	if ($_POST['permstyle']['sendbyemail'] == "inherit") {
		$data['sendbyemail'] = "";
	} else {
		$data['sendbyemail'] = ($_POST['sendbyemail'])?"1":"0";
	}
	
	if ($_POST['permstyle']['view_others'] == "inherit") {
		$data['view_others'] = "";
	} else {
		if ($_POST['view_others_type'] == "specific") {
			$data['view_others'] = $str->fromHTML($_POST['view_others_specific']);
		} else {
			$data['view_others'] = $str->fromHTML($_POST['view_others_type']);
		}
	}
	
	
	
	if ($_POST['permstyle']['simpleInterface'] == "inherit") {
		$data['ui_type'] = "";
	} else {
		$data['ui_type'] = ($_POST['ui_type'])?($_POST['ui_type']):"AFIAN_STANDARD";
	}
	
	
	
	
	
	
	if ($_POST['permstyle']['uploadNotice'] == "inherit") {
		$data['uploadnotice'] = "";
	} else {
		$data['uploadnotice'] = ($_POST['uploadNotice'])?"1":"0";
	}
	
	if ($_POST['permstyle']['downloadNotice'] == "inherit") {
		$data['downloadnotice'] = "";
	} else {
		$data['downloadnotice'] = ($_POST['downloadNotice'])?"1":"0";
	}
	
	
	
	if ($_POST['permstyle']['sharing'] == "inherit") {
		$data['sharing'] = "";
	} else {
		$data['sharing'] = ($_POST['sharing'])?"1":"0";
	}
	
	$data['spacequota'] = $spaceQuota;
	
	$data['traffic'] = $oldInfo['traffic'];
	$data['trafficquota'] = $trafficQuota;
	
	
	
	
	if ($_POST['permstyle']['shareaccess'] == "inherit") {
		$data['shareaccess'] = "";
	} else {
		$data['shareaccess'] = ($_POST['shareaccess'])?"1":"0";
	}
	
	
	
	$data['suspended'] = $str->fromHTML($_POST['suspended']);
	
	if ($_GET['user'] == "admin") {
		if ($_POST['suspended'] == "1") {
			$msg = "You cannot suspend user \"admin\".";
			$statusBarMessage[] = array($msg, 1);
		}
		$data['suspended'] = "";
	}
	
	
	
	$data['trafficdate'] = $oldInfo['trafficdate'];
	
	
	
	
	if ($settings->config['demomode'] && $oldInfo['id'] == "1") {
		$msg = $lang->get("You cannot edit user \"admin\" in this demo version of Afian.");
		$statusBarMessage[] = array($msg, 1);
	} else {
	
		if ($_POST['password'] == $_POST['repassword']) {
		
		
		if (isCleanPath($data['path'])) {
			//$db->debug=1;
			$auth->updateUser($oldInfo['id'], $data);
			$auth->updateUserPass($oldInfo['username'], $str->fromHTML($_POST['password']));
			$auth->updateUserOptInfo($oldInfo['id'], $optionalInfo);
			//$db->debug=0;
			if (!$auth->error) {
				//refresh current user
				if ($data['username'] == $_SESSION['username']) {
					$auth->currentUser = $auth->getUserInfoById($oldInfo['id']);
				}
				
				$log->act("0", "user update", $str->fromHTML($oldInfo['username'])." (".$oldInfo['id'].")");
				$msg = $lang->get("User \"%1\" updated.", array($str->fromHTML($oldInfo['username'])));
				$statusBarMessage[] = array($msg, 0);
			} else {
				$log->act("1", "user update", $str->fromHTML($_GET['user']));
				$msg = $lang->get("Failed to update user \"%1\"", array($str->fromHTML($_GET['user'])))." (".$auth->error.")";
				$statusBarMessage[] = array($msg, 1);
			}
		
		} else {
			$msg = $lang->get("Please enter a clean path.");
			$statusBarMessage[] = array($msg, 1);
		}
		
		} else {
			$msg = $lang->get("Please retype the password correctly.");
			$statusBarMessage[] = array($msg, 1);
		}
	}
}
?>