<?
// Wriiten by Spike^ekipS <spike@spikeekips.net>

include_once "./setting.php";

// include
include_once $global["root"] . "/include/handle.php";
include_once $global["root"] . "/include/print_array.php";

// lib
include_once $global["root"] . "/lib/Site.php";
include_once $global["root"] . "/lib/Authentication.php";
include_once $global["root"] . "/lib/User.php";

include_once $global["root"] . "/config/tables.php";

$Site = new Site;
$Site->init("domain", "_GET");

extract($_POST);

include_once $global["lang"] . "/" . $_SESSION["config_lang"] . ".php";

switch ($_POST["action"]) {

	case ("save") :

		$retval = true;

		$User = new User;

		//////////////////////////////////////////////////// user
		// set valid
		if (is_array($_POST["valid"])) {
			while (list($i, $j) = each($_POST["valid"])) {
				if ($j == "0") {
					$retval = $User->set_not_valid($i);
				} else {
					$retval = $User->set_valid($i);
				}

				if (! $retval) break;
			}
		}

		// remove
		if ($retval and is_array($_POST["remove"])) {

			while (list($i, $j) = each($_POST["remove"])) {
				$retval = $User->remove($i, $j);

				if (! $retval) break;
			}
		}

		//////////////////////////////////////////////////// user alias
		// set valid
		if (is_array($_POST["valid_alias"])) {
			while (list($i, $j) = each($_POST["valid_alias"])) {
				if ($j == "0") {
					$retval = $User->set_not_valid_alias($i);
				} else {
					$retval = $User->set_valid_alias($i);
				}

				if (! $retval) break;
			}
		}

		// remove
		if ($retval and is_array($_POST["remove_alias"])) {

			while (list($i, $j) = each($_POST["remove_alias"])) {
				$retval = $User->remove_alias($j);

				if (! $retval) break;
			}
		}
		////////////////////////////////////////////////////

		if (! $retval) $_SESSION["user_msg"]["content"] = $string["msg1"];

	break;

	case ("make_new_user") :
		$User = new User;

		$retval = $User->add($_POST["new_username"],
			$_SESSION["config_domain"], $_POST["user_password"]);

		switch ($retval) {
			case (false) :
				$_SESSION["user_msg"]["content"] = $string["error14"];
			break;
			case ("-2") :
				$_SESSION["user_msg"]["content"] = $string["error15"];
			break;
			case ("-3") :
				$_SESSION["user_msg"]["content"] = $string["error16"];
			break;
		}

	break;

	default :
		$Auth = new Authentication;
		$Auth->logout();
		exit;
}

$url = sprintf("Location: %s/domain?mode=list", $_SESSION["user_www_url"]);

if ($retval === true) {
	$_SESSION["user_msg"]["content"] = $string["msg"];
	$_SESSION["user_msg"]["type"] = "2";

	$Site->end1();
	Header($url);
	exit;
} else {
	//$_SESSION["user_msg"]["content"] = $string["msg1"];

	$Site->end1();

	goprev();
}

/*
Description
-----------

Author
------
 Spike^ekipS <spike@spikeekips.net>

Changelog
---------

Usage
-----

*/

?>
