<?

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

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

$Site = new Site;
$Site->init("mail");

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

if (! $_POST["action"] or trim($_POST["action"]) == "") {
	$_SESSION["tmp"]["msg"]["content"] = $string["error3"];
	goprev();
}

if (count($_POST["one"]) < 1) {
	$_SESSION["tmp"]["msg"]["content"] = $string["error4"];
	goprev();
}

switch ($_POST["action"]) {
	case ("remove") :

		$Site->DB->transaction_start(true);
		$Item = new Item();
		$retval = true;

		while (list($i, $j) = each($_POST["one"])) {
			$Item->no = $Item->get_no($j, "3");
			if (! $Item->remove()) {
				$retval = false;
				break;
			}
		}

		$Site->DB->retval = $retval;

		if (! $retval) $_SESSION["tmp"]["msg"]["content"] = $string["error18"];

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

		$Site->end();

		Header($url);
		exit;

	break;
	case ("sendEmail") :

		$SQL_GET_EMAIL = "select SQL_CACHE email from card_%s where no = '%s'";

		while (list($i, $j) = each($_POST["one"])) {
			unset($o);
			$o = $Site->DB->fetch_one(sprintf($SQL_GET_EMAIL, $_SESSION["config_id"], $j));
			if (! $o["email"]) continue;
			$a[] = $o["email"];
		}
		$a = array_unique($a);

		$url = sprintf("Location: %s/mail?mode=add&no=1&address=%s",
			$_SESSION["user_www_url"], implode(",", $a));

		$Site->end();

		Header($url);
		exit;
	break;
}

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

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

Changelog
---------

Usage
-----

*/

?>
