<?

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";

// escape error.
if (! $_POST["name"] or trim($_POST["name"]) == "") {
	goprev();
}

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

// trim value
while (list($i, $j) = each($_POST)) {
	if ($i == "comment") continue;
	$a[$i] = trim($j);
}

$a["comment"] = $_POST["comment"];

$Site->DB->transaction_start(true);

$SQL_INSERT_CARD = "insert into card_%s
		(name, email, work_phone, home_phone, fax,
		mobile, zip_work, country_work, city_work,
		add_work, title_work, department_work,
		organization_work, zip_home, country_home,
		city_home, add_home, homepage, comment, date)
	values('%s', '%s', '%s', '%s', '%s', '%s', '%s',
		'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',
		'%s', '%s', '%s', '%s','%s')";

$Site->DB->query(sprintf($SQL_INSERT_CARD,
	$_SESSION["config_id"],
		addslashes($a["name"]), addslashes($a["email"]),
		addslashes($a["work_phone"]), addslashes($a["home_phone"]),
		addslashes($a["fax"]), addslashes($a["mobile"]),
		addslashes($a["zip_work"]), addslashes($a["country_work"]),
		addslashes($a["city_work"]), addslashes($a["add_work"]),
		addslashes($a["title_work"]), addslashes($a["department_work"]),
		addslashes($a["organization_work"]), addslashes($a["zip_home"]),
		addslashes($a["country_home"]), addslashes($a["city_home"]),
		addslashes($a["add_home"]), addslashes($a["homepage"]),
		addslashes($a["comment"]), mktime() ) );

if ($Site->DB->retval) {
	$Item = new Item;
	$Site->DB->retval = $Item->insert($Site->DB->get_last_insert_id(),
			$_SESSION["user_item_type_rv"]["card"], $_POST["directory_num"]);
}

$retval = $Site->DB->retval;
$Site->DB->close();

if ($retval) {
	$url = sprintf("Location: %s/mail?no=%s&pg=%s",
		$_SESSION["user_www_url"], $_SESSION["user_directory"],
		$_SESSION["user_page_number"]);

	$Site->end1();

	Header($url);
	exit;
} else {
	$Site->end1();

	goprev();
}

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

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

Changelog
---------

Usage
-----

*/

?>
