<?
if ($_SESSION['username'] == "admin") {


if ($_POST['spaceQuota'] == "limited") {
	$spaceQuota = $_POST['spaceQuotaSize']*1024*1024;
} elseif ($_POST['spaceQuota'] == "inherit") {
	$spaceQuota = "";
} else {
	$spaceQuota = "-";
}

if ($_POST['trafficQuota'] == "limited") {
	$trafficQuota = $_POST['trafficQuotaSize']*1024*1024;
} elseif ($_POST['trafficQuota'] == "inherit") {
	$trafficQuota = "";
} else {
	$trafficQuota = "-";
}


$data['username'] = strtolower($str->fromHTML($_POST['username']));
$data['password'] = $str->fromHTML($_POST['password']);

$data['gid'] = $_GET['gid'];



$data['firstname'] = $_POST['firstname'];
$data['lastname'] = $_POST['lastname'];
$data['email'] = $_POST['email'];
$data['company'] = $_POST['company'];

if ($_POST['permstyle']['path'] == "inherit") {
	$data['path'] = "";
} else {
	$data['path'] = ($settings->config['demomode'])?$settings->config['demorestrictedfolder']:cleanPath(rawurldecode($_POST['userpath']));
}

$data['lastlogin'] = "0";

if ($_POST['permstyle']['notReadOnly'] == "inherit") {
	$data['readonly'] = "";
} else {
	$data['readonly'] = ($_POST['notReadOnly'])?"0":"1";
}

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']['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'] = "0";
$data['trafficquota'] = $trafficQuota;




if ($_POST['permstyle']['shareaccess'] == "inherit") {
	$data['shareaccess'] = "";
} else {
	$data['shareaccess'] = ($_POST['shareaccess'])?"1":"0";
}
$data['suspended'] = $str->fromHTML($_POST['suspended']);
$data['trafficdate'] = time();



if (strlen($data['username']) < 1) {
	$msg = $lang->get("Please enter a username.")."<br><span class=\"nowrap\">".$lang->get("Check the form before resubmitting.")."</span>";
	$statusBarMessage[] = array($msg, 1);
} elseif (!$str->okUsername($data['username'])) {
	$msg = "<span class=\"nowrap\">".$lang->get("The username can contain only letter, numbers, dashes and underscores.")."</span><br>".$lang->get("Check the form before resubmitting.")."";
	$statusBarMessage[] = array($msg, 1);
} elseif ($db->GetOne("SELECT username FROM ".$settings->config['auth_tablename']." WHERE username='".$data['username']."'")) {
	$msg = $lang->get("Username already in use.");
	$statusBarMessage[] = array($msg, 1);
} else {

	if ($_POST['password'] == $_POST['repassword']) {
	
	
	if (isCleanPath($data['path'])) {
		$functionReturn = $auth->addUser($data);
		
		//exit();
		
		if ($functionReturn != false) {
			$log->act("0", "user creation", $data['username']." (".$db->lastInsertId.")");
			$msg = $lang->get("User \"%1\" added", array($str->fromHTML($data['username'])));
				if ($auth->error) {
					$msg .= "<br><span class=\"nowrap\" style=\"color:red;\">".$auth->error."</span>";
				}
			$statusBarMessage[] = array($msg, 0);
			$userAdded = true;
		} else {
			$log->act("1", "user creation", $str->fromHTML($_POST['username']));
			$msg = $lang->get("Failed to add user \"%1\"", array($str->fromHTML($_POST['username'])))."\". ".$auth->error;
			$statusBarMessage[] = array($msg, 1);
		}
	
	} else {
		$msg = $lang->get("Please enter a clean path (full path).")."<br><span class=\"nowrap\">".$lang->get("Please recheck the form.")."</span>";
		$statusBarMessage[] = array($msg, 1);
	}
	
	} else {
		$msg = $lang->get("Please retype the password correctly.")."<br><span class=\"nowrap\">".$lang->get("Please recheck the form.")."</span>";
		$statusBarMessage[] = array($msg, 1);
	}

}

}
?>