<?
require_once('include/global.php');
require_once('include/admin_lib.php');
require_once('include/file.php');
require_once('sadmin_conf.inc.php');

mail_server_check_limit();		// 메일서버가 동작중인지 확인

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

	$_POST['d_name'] = strtolower($_POST['d_name']);

	// 중복여부 체크
	$d_name_cnt = db_get_one("
			SELECT 
				COUNT(*) 
			FROM 
				" . $TB['DOMAIN'] . "
			WHERE 
				d_name='" . $_POST['d_name'] . "'
			");
	if ($d_name_cnt > 0)
		msg("이미 추가된 도메인입니다.");

	$d_name_cnt = db_get_one("
			SELECT 
				COUNT(*) 
			FROM 
				" . $TB['DOMAIN_ALIAS'] . "
			WHERE 
				da_name='" . $_POST['d_name'] . "'
			");
	if ($d_name_cnt > 0)
		msg("이미 앨리어스 도메인으로 등록되어 있습니다.\\n도메인을 추가하려면 앨리어스 도메인을 먼저 삭제해야 합니다.");

// data
	$_POST['d_webmail_url'] = to_db_str($_POST['d_webmail_url'], 255, false);
	$_POST['d_name'] = to_db_str($_POST['d_name'], 255);
	$_POST['d_is_use'] = to_db_str($_POST['d_is_use'], 1);
	$_POST['d_quota'] = to_db_str($_POST['d_quota'], 10);
	$_POST['d_quota_mbr_default'] = to_db_str($_POST['d_quota_mbr_default'],	10);
	$_POST['d_quota_mbr_count'] = to_db_str($_POST['d_quota_mbr_count'],	10);
	$_POST['d_quota_board'] = to_db_str($_POST['d_quota_board'],	10);
	$_POST['d_memo'] = to_db_str($_POST['d_memo'], $G_SYS['DB_TEXT']);

	$_POST['d_site_name'] = to_db_str($_POST['d_site_name'], 255);
	$_POST['d_site_owner'] = to_db_str($_POST['d_site_owner'], 255);
	$_POST['d_site_title'] = to_db_str($_POST['d_site_title'], 255);
	$_POST['d_site_license'] = to_db_str($_POST['d_site_license'], $G_SYS['DB_TEXT'], false);
	$_POST['d_site_top_notice'] = to_db_str($_POST['d_site_top_notice'], $G_SYS['DB_TEXT'], false);
	$_POST['d_site_bottom_notice'] = to_db_str($_POST['d_site_bottom_notice'], $G_SYS['DB_TEXT'], false);

	$_POST['d_quota'] = $_POST['d_quota']*1024;
	$_POST['d_quota_mbr_default'] = $_POST['d_quota_mbr_default']*1024;
	$_POST['d_quota_board'] = $_POST['d_quota_board']*1024;

	// [2007-12-28] 대용량첨부, 웹하드
	$_POST['d_bigfile_quota'] = $_POST['d_bigfile_quota']*1024;
	$_POST['d_bigfile_quota_default'] = $_POST['d_bigfile_quota_default']*1024;
	$_POST['d_webhard_quota'] = $_POST['d_webhard_quota']*1024;
	$_POST['d_webhard_quota_default'] = $_POST['d_webhard_quota_default']*1024;

	$_POST['d_regdate'] = date('Y-m-d H:i:s');
	$_POST['d_modifydate'] = date('Y-m-d H:i:s');


	// [2008-03-25] 웹사이트 로고
		$errorMsg = '';
		$upload_dir = 'logo/'.stripslashes($_POST['d_name']);
		$upload_dir2 = 'favicon/'.stripslashes($_POST['d_name']);

		// d_site_logo1
		if ($_FILES['d_site_logo1']['name'] != '')
		{
			$_errorMsg = file_upload_error_msg($_FILES['d_site_logo1'], $_FILES['d_site_logo1']['size'], $G_SYS[UPLOAD_LOGO_MAX_SIZE]);
			if ($_errorMsg != '')
				$errorMsg .= "\\n\\n[로그인화면 상단 로고]의 업로드가 실패하였습니다.\\n\\n원인 : ".$_errorMsg;

			$errorMsg .= file_up_new('d_site_logo1', $_FILES['d_site_logo1']['name'], '1', $upload_dir, $G_SYS[UPLOAD_LOGO_MAX_SIZE]);

			$_POST['d_site_logo1'] = ($errorMsg == '') ? $_FILES['d_site_logo1']['name'] : '';
		}	// if()

		// d_site_logo2
		if ($_FILES['d_site_logo2']['name'] != '')
		{
			$_errorMsg = file_upload_error_msg($_FILES['d_site_logo2'], $_FILES['d_site_logo2']['size'], $G_SYS[UPLOAD_LOGO_MAX_SIZE]);
			if ($_errorMsg != '')
				$errorMsg .= "\\n\\n[로그인화면 상단 로고]의 업로드가 실패하였습니다.\\n\\n원인 : ".$_errorMsg;

			$errorMsg .= file_up_new('d_site_logo2', $_FILES['d_site_logo2']['name'], '2', $upload_dir, $G_SYS[UPLOAD_LOGO_MAX_SIZE]);

			$_POST['d_site_logo2'] = ($errorMsg == '') ? $_FILES['d_site_logo2']['name'] : '';
		}	// if()

		// d_site_favicon
		if ($_FILES['d_site_favicon']['name'] != '')
		{
			$_errorMsg = file_upload_error_msg($_FILES['d_site_favicon'], $_FILES['d_site_favicon']['size'], $G_SYS[UPLOAD_LOGO_MAX_SIZE]);
			if ($_errorMsg != '')
				$errorMsg .= "\\n\\n[파비콘(favicon)]의 업로드가 실패하였습니다.\\n\\n원인 : ".$_errorMsg;

			$errorMsg .= file_up_new('d_site_favicon', $_FILES['d_site_favicon']['name'], '2', $upload_dir2, $G_SYS[UPLOAD_LOGO_MAX_SIZE]);

			$_POST['d_site_favicon'] = ($errorMsg == '') ? $_FILES['d_site_favicon']['name'] : '';
		}	// if()


	// 도메인 추가
		$sql = "
			INSERT INTO
				" .	$TB['DOMAIN']	. "
				( d_no , d_name , d_webmail_url, d_is_use ,	d_quota , d_quota_mbr_default , d_quota_mbr_count, d_quota_board, d_saveday, d_svc_smtp, d_svc_pop3, d_svc_forward, d_bigfile_isuse, d_bigfile_quota, d_bigfile_quota_default, d_webhard_isuse, d_webhard_quota, d_webhard_quota_default, d_skin_limit_level, d_skin_main, d_skin_webmail, d_skin_member, d_skin_board, d_skin_webhard, d_skin_birthday, d_memo, d_regdate, d_modifydate, d_site_name, d_site_owner, d_site_title, d_site_license, d_site_top_notice, d_site_bottom_notice, d_site_logo1, d_site_logo1_w, d_site_logo1_h, d_site_logo2, d_site_logo2_w, d_site_logo2_h, d_site_favicon, d_mbrgrp_isuse, d_shareaddr_isuse, d_shareaddr_reg, d_sharediary_isuse, d_sharediary_target, d_sharediary_reg, d_login_signup, d_login_account_recovery, d_login_account_delete, d_login_profile_edit)
			VALUES
				( ".db_sqc_next($TB['DOMAIN']).", '" . $_POST['d_name'] . "', '" . $_POST['d_webmail_url'] . "', '" .	$_POST['d_is_use'] . "', '"	. $_POST['d_quota'] .	"',	'" . $_POST['d_quota_mbr_default'] . "', '" . $_POST['d_quota_mbr_count'] . "',  '" . $_POST['d_quota_board'] . "', '" . $_POST['d_saveday'] . "', '" . $_POST['d_svc_smtp'] . "', '" . $_POST['d_svc_pop3'] . "', '" . $_POST['d_svc_forward'] . "', '" . $_POST['d_bigfile_isuse'] . "', '" . $_POST['d_bigfile_quota'] . "', '" . $_POST['d_bigfile_quota_default'] . "', '" . $_POST['d_webhard_isuse'] . "', '" . $_POST['d_webhard_quota'] . "', '" . $_POST['d_webhard_quota_default'] . "', '" . $_POST['d_skin_limit_level'] . "', '" . $_POST['d_skin_main'] . "', '" . $_POST['d_skin_webmail'] . "', '" . $_POST['d_skin_member'] . "', '" . $_POST['d_skin_board'] . "', '" . $_POST['d_skin_webhard'] . "', '" . $_POST['d_skin_birthday'] . "', '" . $_POST['d_memo'] . "' , '" . $_POST['d_regdate'] . "' , '" . $_POST['d_modifydate'] . "' , '" . $_POST['d_site_name'] . "' , '" . $_POST['d_site_owner'] . "' , '" . $_POST['d_site_title'] . "' , '" . $_POST['d_site_license'] . "' , '" . $_POST['d_site_top_notice'] . "' , '" . $_POST['d_site_bottom_notice'] . "' , '" . addslashes($_POST['d_site_logo1']) . "' , '" . $_POST['d_site_logo1_w'] . "' , '" . $_POST['d_site_logo1_h'] . "' , '" . addslashes($_POST['d_site_logo2']) . "' , '" . $_POST['d_site_logo2_w'] . "' , '" . $_POST['d_site_logo2_h'] . "' , '" . $_POST['d_site_favicon'] . "' , '" . $_POST['d_mbrgrp_isuse'] . "' , '" . $_POST['d_shareaddr_isuse'] . "' , '" . $_POST['d_shareaddr_reg'] . "' , '" . $_POST['d_sharediary_isuse'] . "' , '" . $_POST['d_sharediary_target'] . "' , '" . $_POST['d_sharediary_reg'] . "' , '" .  $_POST['d_login_signup'] . "' , '" . $_POST['d_login_account_recovery'] . "' , '" . $_POST['d_login_account_delete'] . "' , '" . $_POST['d_login_profile_edit'] . "' )
			";
		db_query($sql);
		$curr_d_no = db_sqc_curr($TB['DOMAIN']);		// 삽입된 데이타 키

	// 웹메일용 처리.
		require_once('include/admin_lib.php');
		domain_add($curr_d_no, $_POST['d_name']);

// end
	msg("추가되었습니다.", 0);
	if ($_GET['is_window_close'])
	{
		?>
			<script language="JavaScript">
			<!--
				window.close();
			//-->
			</script>
		<?
	} else if ($_POST['back_url'])
	{
		movepage($_POST['back_url']);
	} else
	{
		movepage('sdomain_list.php');
	}	// if()

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