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


// set
	$CFG['TITLE'] = '<b>편지쓰기</b> >> <b>편지쓰기 설정</b>';


// data
	$row = get_default_config($AUTH['auth_m_no']);

	$view = array();
	// 메일박스
		$mail_box = get_mail_box();
		$_mail_box = db_rows_fieldtokey($mail_box);
		$select_mail_box = select_list_value($_GET['mb_id'], $_mail_box['mb_name'], $_mail_box['mb_id'], NULL, 0, 1);

	$view['m_cfg_from_name'] = input_value($row['m_cfg_from_name'], 1);
	$view['m_cfg_mail_list_cnt'] = select_list_value($row['m_cfg_mail_list_cnt'], array_values($G_SYS['M_CFG_MAIL_LIST_CNT']), array_keys($G_SYS['M_CFG_MAIL_LIST_CNT']), NULL, 0, 1);
	// [2025-11-06] 발송 전 미리보기
	$view['m_send_preview'] = radio_value('m_send_preview', $row['m_send_preview'], array_values($G[ISUSE]), array_keys($G[ISUSE]), NULL, 0, 1);

	// [2013-01-28] 보낸사람 선택기능 (앨리어스 도메인/주소 연동)
	$view['mf_from_name_default'] = $row['m_cfg_from_name'];

	$view['mf_from_select'] = array();

	if (!$G_SYS['NM_ALIAS_MAIL_FROM_SEL_SKIP'])
	{
		$q = "SELECT m_id, m_cfg_from_name name, m_cfg_from_addr FROM " . $TB['MEMBER'] . " WHERE d_no='" . $G['DINFO']['d_no'] . "' AND m_usertype='A' AND m_name='" . $AUTH['auth_m_id'] . "' ORDER BY m_id";
		$member_alias = db_get_rows($q);

		foreach ($member_alias as $key2=>$member)
		{
			if ($member['name'] == '')
				$member['name'] = $view['mf_from_name_default'];
			$view['mf_from_select'][] = array('name'=>$member['name'], 'email'=>$member['m_id'].'@'.$G['DINFO']['d_name'], 'id'=>$member['m_id'], 'isuse'=>$member['m_cfg_from_addr']);
		}	// foreach()
	}	// if()

	// [2025-12-02] 대표 계정 보낸 주소 추가
	if ($G_SYS['NM_TEAM_MAIL']) {
		$q = "SELECT 
	                    tm.* , m.m_name
					FROM
						" . $TB['TEAM_MAIL'] . " tm
						JOIN " . $TB['MEMBER'] . " m on tm.d_no = m.d_no AND tm.team_m_id = m.m_id
					WHERE
						1=1
						AND tm.d_no = '" . $G['DINFO']['d_no'] . "' 
						and tm.m_id = '" . $AUTH['auth_m_id'] . "'
						AND tm.tm_is_from_use = 'Y'
					ORDER BY tm.team_m_id
					";

		$team_mails = db_get_rows($q);
		foreach ($team_mails as $team_mail) {
			$view['mf_from_select'][] = array('name'=>$team_mail['m_name'], 'email'=>$team_mail['team_m_id'].'@'.$G['DINFO']['d_name'], 'id'=>$team_mail['team_m_id'], 'is_team_mail'=>'Y');
		}
	}	// if()


// skin view
	$CFG['ACTION'] = 'mail_write_config_ok.php';
	nskinset('webmail', 'mail_write_config.html', 'window_open');
	include($NSKIN['view_layout']);


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