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


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

	if ($_GET['isadmin'])
	{
		auth_limit('admin');
		$_GET['d_no'] = $G['DINFO']['d_no'];
		$url = 'sdomain_mod.php?' . get_qs();
	} else
	{
		auth_limit('serveradmin');
		$url = 'sdomain_list.php?' . get_qs('d_no');
	}	// if()

// data
	$_POST['d_webmail_url'] = to_db_str($_POST['d_webmail_url'], 255, false);
	$_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;

	// [2008-03-25] 웹사이트 로고
		$sql = "
			SELECT
				d_name, d_site_logo1, d_site_logo2, d_site_favicon
			FROM
				".$TB['DOMAIN']."
			WHERE
				d_no='". $_GET['d_no'] . "'
			";
		$dm = db_get_row($sql);

		$errorMsg = '';
		$upload_dir = 'logo/'.$dm['d_name'];
		$upload_dir2 = 'favicon/'.$dm['d_name'];

		// d_site_logo1
		if ($_POST['d_site_logo1_del'] && $dm['d_site_logo1'] != '')
		{
			$errorMsg .= file_del($dm['d_site_logo1'], '1', $upload_dir);
			$dm['d_site_logo1'] = '';
		}	// if()
		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;

			if ($dm['d_site_logo1'] != '')
			{
				$errorMsg .= file_del($dm['d_site_logo1'], '1', $upload_dir);
				$dm['d_site_logo1'] = '';
			}	// if()

			$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'] : $dm['d_site_logo1'];
		} else
		{
			$_POST['d_site_logo1'] = $dm['d_site_logo1'];
		}	// if()


		// d_site_logo2
		if ($_POST['d_site_logo2_del'] && $dm['d_site_logo2'] != '')
		{
			$errorMsg .= file_del($dm['d_site_logo2'], '2', $upload_dir);
			$dm['d_site_logo2'] = '';
		}	// if()
		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;

			if ($dm['d_site_logo2'] != '')
			{
				$errorMsg .= file_del($dm['d_site_logo2'], '2', $upload_dir);
				$dm['d_site_logo2'] = '';
			}	// if()

			$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'] : $dm['d_site_logo2'];
		} else
		{
			$_POST['d_site_logo2'] = $dm['d_site_logo2'];
		}	// if()

		// d_site_favicon
		if ($_POST['d_site_favicon_del'] && $dm['d_site_favicon'] != '')
		{
			$errorMsg .= file_del($dm['d_site_favicon'], '1', $upload_dir2);
			$dm['d_site_favicon'] = '';
		}	// if()
		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;

			if ($dm['d_site_favicon'] != '')
			{
				$errorMsg .= file_del($dm['d_site_favicon'], '1', $upload_dir2);
				$dm['d_site_favicon'] = '';
			}	// if()

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

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


	$q_set = '';
	if (!$_GET['isadmin'])
	{
		$q_set = "
			d_webmail_url='" . $_POST['d_webmail_url'] . "',
			d_is_use='" . $_POST['d_is_use'] . "',
			d_quota='" . $_POST['d_quota'] . "',
			d_quota_mbr_count='" . $_POST['d_quota_mbr_count'] . "',
			d_quota_board='" . $_POST['d_quota_board'] . "',
			d_saveday='" . $_POST['d_saveday'] . "',
			d_memo='" . $_POST['d_memo'] . "',
			d_svc_smtp='" . $_POST['d_svc_smtp'] . "',
			d_svc_pop3='" . $_POST['d_svc_pop3'] . "',
			d_svc_forward='" . $_POST['d_svc_forward'] . "',
			d_svc_external_pop3='" . $_POST['d_svc_external_pop3'] . "',
			d_svc_mailing_list='" . $_POST['d_svc_mailing_list'] . "',
			d_svc_2fa='" . $_POST['d_svc_2fa'] . "',
			d_bigfile_isuse='" . $_POST['d_bigfile_isuse'] . "',
			d_bigfile_quota='" . $_POST['d_bigfile_quota'] . "',
			d_webhard_isuse='" . $_POST['d_webhard_isuse'] . "',
			d_webhard_quota='" . $_POST['d_webhard_quota'] . "',
			";
	}	// if()

	$now = date('Y-m-d H:i:s');
	$sql = "
		UPDATE
			" . $TB['DOMAIN'] . "
		SET
			$q_set
			d_bigfile_quota_default='" . $_POST['d_bigfile_quota_default'] . "',
			d_webhard_quota_default='" . $_POST['d_webhard_quota_default'] . "',
			d_quota_mbr_default='" . $_POST['d_quota_mbr_default'] . "',
			d_skin_limit_level='" . $_POST['d_skin_limit_level'] . "',
			d_skin_main='" . $_POST['d_skin_main'] . "',
			d_skin_webmail='" . $_POST['d_skin_webmail'] . "',
			d_skin_member='" . $_POST['d_skin_member'] . "',
			d_skin_board='" . $_POST['d_skin_board'] . "',
			d_skin_webhard='" . $_POST['d_skin_webhard'] . "',
			d_skin_birthday='" . $_POST['d_skin_birthday'] . "',
			d_mbrgrp_isuse='" . $_POST['d_mbrgrp_isuse'] . "',
			d_shareaddr_isuse='" . $_POST['d_shareaddr_isuse'] . "',
			d_shareaddr_reg='" . $_POST['d_shareaddr_reg'] . "',
			d_sharediary_isuse='" . $_POST['d_sharediary_isuse'] . "',
			d_sharediary_target='" . $_POST['d_sharediary_target'] . "',
			d_sharediary_reg='" . $_POST['d_sharediary_reg'] . "',
			d_site_name='" . $_POST['d_site_name'] . "',
			d_site_owner='" . $_POST['d_site_owner'] . "',
			d_site_title='" . $_POST['d_site_title'] . "',
			d_site_license='" . $_POST['d_site_license'] . "',
			d_site_top_notice='" . $_POST['d_site_top_notice'] . "',
			d_site_bottom_notice='" . $_POST['d_site_bottom_notice'] . "',
			d_site_logo1='" . addslashes($_POST['d_site_logo1']) . "',
			d_site_logo1_w='" . $_POST['d_site_logo1_w'] . "',
			d_site_logo1_h='" . $_POST['d_site_logo1_h'] . "',
			d_site_logo2='" . addslashes($_POST['d_site_logo2']) . "',
			d_site_logo2_w='" . $_POST['d_site_logo2_w'] . "',
			d_site_logo2_h='" . $_POST['d_site_logo2_h'] . "',
			d_site_favicon='" . addslashes($_POST['d_site_favicon']) . "',
			d_login_signup='" . addslashes($_POST['d_login_signup']) . "',
			d_login_account_recovery='" . addslashes($_POST['d_login_account_recovery']) . "',
			d_login_account_delete='" . addslashes($_POST['d_login_account_delete']) . "',
			d_login_profile_edit='" . addslashes($_POST['d_login_profile_edit']) . "',
			d_modifydate='". $now . "'
		WHERE
			d_no='" . $_GET['d_no'] . "'
		";

	db_query($sql);


	// [2007-11-27] [도메인관리]최대 보관기간을 변경할 경우 기존에 가입된 회원들에게도 적용함.
	// : 30일로 지정할 경우, '제한없음, 40,50,60일'을 선택한 사용자의 디비를 모두 갱신해야함.
	if (!$_GET['isadmin'] && $_POST['d_saveday'] > 0)
	{
		set_time_limit(0);
		$q = "
			SELECT
				mb.m_no, mb.mb_id
			FROM
				" . $TB['MEMBER'] . " m,
				" . $TB['MAIL_BOX'] . " mb
			WHERE
				m.d_no='" . $_GET['d_no'] . "'
				AND m.m_no = mb.m_no
				AND ( mb.mb_saveday > '" . $_POST['d_saveday'] . "' OR mb.mb_saveday = 0 )
				AND mb.mb_id IN ('trash', 'spam')
			";
		$rows = db_get_rows($q);

		for ($i=0; $i<sizeof($rows); $i++)
		{
			$q = "UPDATE " . $TB['MAIL_BOX'] . " SET mb_saveday = '" . $_POST['d_saveday'] . "' WHERE m_no = '" . $rows[$i]['m_no'] . "' AND mb_id = '" . $rows[$i]['mb_id'] . "'";
			db_query($q);
		}	// for()
	}	// if()


// end
	if ($errorMsg != '')
		msg("수정되었습니다.".$errorMsg, 0);
	movepage($url);


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