<?
require_once('include/global.php');
require_once('include/addr_lib.php');
require_once('conf.inc.php');


// check
	if (!$_POST['adg_name'])
		msg('올바른 URL로 접근하여 주십시오');

	// 중복여부 체크
	$adg_cnt = db_get_one("SELECT COUNT(*)  FROM " . $TB['ADDR_GROUP'] . " WHERE " . get_addr_group_where() . " AND adg_parent='" . $_POST['adg_parent'] . "' AND adg_name='" . $_POST['adg_name'] . "'");
	if ($adg_cnt > 0)
		msg("이미 존재하는 그룹 이름입니다.\\n\\n다른 이름을 사용하여 주십시오.");


// data
	to_db_str(&$_POST['adg_name'], 50);

	/*
	if ($_GET['isadmin'])
	{
		$sql = "
			INSERT INTO
				" . $TB['ADDR_GROUP'] . "
				(adg_no, m_no, adg_name, d_no)
			VALUES
				(".db_sqc_next($TB['ADDR_GROUP']).", '0', '" . $_POST['adg_name'] . "', '" . $G['DINFO']['d_no'] . "')
			";
	} else 
	{
		$sql = "
			INSERT INTO
				" . $TB['ADDR_GROUP'] . "
				(adg_no, m_no, adg_name)
			VALUES
				(".db_sqc_next($TB['ADDR_GROUP']).", '" . $AUTH['auth_m_no'] . "', '" . $_POST['adg_name'] . "')
			";
	}	// if()
	db_query($sql);
	*/
	// [2012-10-15] 주소록 그룹 트리 지원
	$cg = get_addr_group_tree_class();
	if ($_GET['isadmin'])
	{
		$ext_fields = "d_no, m_no, adg_sort";
		$ext_datas = "'".$G['DINFO']['d_no']."', '0', '".$_POST['adg_sort']."'";
	} else 
	{
		$ext_fields = "m_no, adg_sort";
		$ext_datas = "'".$AUTH['auth_m_no']."', '".$_POST['adg_sort']."'";
	}	// if()
	$cg->addRow($_POST['adg_name'], $_POST['adg_parent'], $ext_fields, $ext_datas);


// end
	#msg("그룹이 등록되었습니다.", 0);
	movepage('addr_group.php?'.get_qs());


require_once('include/global_end.php');
?>