<?
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_new_mail_box'] = checkbox_value("m_cfg_new_mail_box[]", explode('|', $row['m_cfg_new_mail_box']), $_mail_box['mb_name'], $_mail_box['mb_id'], 0);
	$view['m_cfg_new_cnt'] = select_list_value($row['m_cfg_new_cnt'], array_values($G_SYS['M_CFG_NEW_CNT']), array_keys($G_SYS['M_CFG_NEW_CNT']), NULL, 0, 1);
	$view['m_cfg_week_diray_cnt'] = select_list_value($row['m_cfg_week_diray_cnt'], array_values($G_SYS['M_CFG_NEW_CNT']), array_keys($G_SYS['M_CFG_NEW_CNT']), NULL, 0, 1);
	$view['m_cfg_from_name'] = input_value($row['m_cfg_from_name'], 1);

	// [2026-07-13] 페이지당 출력수 - 쿠키와 저장된 값이 다를 경우 쿠키값 기준으로 가져오도록 추가
	if ($_COOKIE['nm_mail_pagesize'] !== null && $row['m_cfg_mail_list_cnt'] !== $_COOKIE['nm_mail_pagesize']) {
		$row['m_cfg_mail_list_cnt'] = $_COOKIE['nm_mail_pagesize'];
	}

	$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);
	// [2025-11-12] 편지함 백업 타입
	$view['m_mail_box_backup_type'] = radio_value('m_mail_box_backup_type', $row['m_mail_box_backup_type'], array_values($G_SYS['MAIL_BOX_BACKUP_TYPE']), array_keys($G_SYS['MAIL_BOX_BACKUP_TYPE']), 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()

	// [2025-11-27] 편지함 트리 적용
	foreach ($mail_box as $item) {
		$view['mb_depth'][] = $item['mb_depth'];
	}

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


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