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

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

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

	if ($_GET['isadmin'])
	{
		auth_limit('admin');
		$_POST['sa_d_no'] = $G['DINFO']['d_no'];
	} else
	{
		auth_limit('serveradmin');

		// 사용가능한 도메인인지 확인.
			$sql = "SELECT d_name FROM ".$TB['DOMAIN']." WHERE d_no='". $_POST['sa_d_no'] . "' AND d_is_use='Y' ";
			$G_SYS['MAIL_DOMAIN'] = db_get_one($sql);
			if ($G_SYS['MAIL_DOMAIN'] == '')
				msg("존재하지 않거나 사용할 수 없는 도메인입니다.\\n\\n확인후 다시 시도하여 주십시오.");
	}	// if()

	$_POST['m_id'] = strtolower($_POST['m_id']);		// 소문자만 허용

	// 중복여부 체크
	$m_name_cnt = db_get_one("
			SELECT
				COUNT(*)
			FROM
				" . $TB['MEMBER'] . "
			WHERE
				m_id='" . $_POST['m_id'] . "'
				AND d_no='" . $_POST['sa_d_no'] . "'
			");
	if ($m_name_cnt > 0)
		msg("이미 사용된 아이디입니다.");

	// [2012-10-16] 메일링 리스트 개수 제한
	$q = "SELECT COUNT(*) FROM " . $TB['MEMBER'] . " WHERE m_usertype='M' AND d_no='" . $_POST['sa_d_no'] . "'";
	$limit_cnt = db_get_one($q);
	if ($limit_cnt >= $G_SYS['MAILING_USER_LIMIT'])
		msg("메일링 리스트는 최대 ".$G_SYS['MAILING_USER_LIMIT']."개까지 등록할 수 있습니다.");



// data
	to_db_str(&$_POST['m_name'], 255);
	to_db_str(&$_POST['m_email'], 255);
	to_db_str(&$_POST['m_memo'], $G_SYS['DB_TEXT']);


	// 메일링 리스트 추가
		$m_pwd = ' ';		// 널값이 들어갈 경우 메일서버에 추가시 에러가 발생함.
		$m_usertype = 'M';		// Mailing List User
		$m_mail_file_group = get_mail_file_group_now($_POST['sa_d_no']);
		/*
		$q = "
			INSERT INTO
				$TB[MEMBER]
				(m_no, m_id, m_pwd, m_lostpwd_q, m_lostpwd_a, m_level, m_name, m_last_name, m_email, m_homepage, m_jumin, m_sex, m_birthday, m_birthday_east, m_mobile, m_home_tel, m_home_zipcode, m_home_addr1, m_home_addr2, m_job, m_office, m_office_subject, m_office_tel, m_office_fax, m_office_zipcode, m_office_addr1, m_office_addr2, m_ismarry, m_marrydate, m_isremail, m_memo, m_etc1, m_etc2, m_etc3, m_etc4, m_etc5, m_date1, m_date2, m_date3, m_date4, m_date5, m_file1, m_file2, m_file3, m_file4, m_file5, m_regdate, m_reghost, m_login_cnt, m_last_logindate, m_last_loginhost, m_last_modifydate, m_last_modifyhost, d_no, m_is_use, m_mail_file_group, m_quota, mg_no, m_usertype)
			VALUES
				(".db_sqc_next($TB['MEMBER']).", '".$_POST['m_id']."', '$m_pwd_enc', '$m_lostpwd_q', '$m_lostpwd_a', '$m_level', '$m_name', '$m_last_name', '$m_email', '$m_homepage', '$m_jumin', '$m_sex', '$m_birthday', '$m_birthday_east', '$m_mobile', '$m_home_tel', '$m_home_zipcode', '$m_home_addr1', '$m_home_addr2', '$m_job', '$m_office', '$m_office_subject', '$m_office_tel', '$m_office_fax', '$m_office_zipcode', '$m_office_addr1', '$m_office_addr2', '$m_ismarry', '$m_marrydate', '$m_isremail', '$m_memo', '$m_etc1', '$m_etc2', '$m_etc3', '$m_etc4', '$m_etc5', '$m_date1', '$m_date2', '$m_date3', '$m_date4', '$m_date5', '$m_file1', '$m_file2', '$m_file3', '$m_file4', '$m_file5', '$m_regdate', '$m_reghost', '$m_login_cnt', '$m_last_logindate', '$m_last_loginhost', '$m_last_modifydate', '$m_last_modifyhost', '".$_POST['sa_d_no']."', '$m_is_use', '$m_mail_file_group', '$m_quota', '$mg_no', '$m_usertype')
			";
			not null - m_no, d_no, m_id, m_pwd, m_level, m_name, m_is_use, m_mail_file_group, m_quota, m_bigfile_quota, m_webhard_quota, m_forwarding_type, m_regdate, m_reghost, m_login_cnt, m_autoreply_isuse, m_svc_smtp, m_svc_pop3, m_usertype
		*/
		$q = "INSERT INTO ".$TB['MEMBER']." (m_no, d_no, m_id, m_pwd, m_level, m_name, m_is_use, m_mail_file_group, m_quota, m_bigfile_quota, m_webhard_quota, m_forwarding_type, m_regdate, m_reghost, m_login_cnt, m_autoreply_isuse, m_svc_smtp, m_svc_pop3, m_usertype, m_email, m_etc1, m_etc2, m_memo)";
		$q .= " VALUES (".db_sqc_next($TB['MEMBER']).", '".$_POST['sa_d_no']."', '".$_POST['m_id']."', '', 0, '".$_POST['m_name']."', 'Y', '".$m_mail_file_group."', 0, 0, 0, 'N', '".date("Y-m-d H:i:s")."', '".$_SERVER['REMOTE_ADDR']."', 0, 'N', 'N', 'N', '".$m_usertype."', '".$_POST['m_email']."', '".$_POST['m_etc1']."', '".$_POST['m_etc2']."', '".$_POST['m_memo']."')";
		db_query($q);

		$curr_m_no = db_sqc_curr($TB['MEMBER']);		// 삽입된 데이타 키

	// 웹메일용 처리.
		#require_once('include/admin_lib.php');
		mbr_add($curr_m_no, $m_id, $m_pwd, $m_quota, $m_mail_file_group, 'M', $m_etc1, $m_email, $m_etc2);


// 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('admin_mailing_list.php?'.get_qs());
	}	// if()
	*/
	movepage('admin_mailing_addr.php?m_no='.$curr_m_no.'&'.get_qs('m_no', 's_word'));

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