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


// set
	$CFG['TITLE'] = '<b>환경설정</b> >> <b>외부 메일(POP3)</b> >> <b>수정</b>';


// check
	if ($G['DINFO']['d_svc_external_pop3'] === 'N') {
		msg("외부 메일(POP3)를 사용할 수 없습니다.\\n\\n서버관리자에게 문의하여 주십시오.");
	}

	if (!$_GET['p3_no'])
		msg('올바른 URL로 접근하여 주십시오');

// [2006-03-08] 메일서버가 동작중인지 확인
	require_once('include/admin_lib.php');
	mail_server_check_limit();

// data
	// get
		$sql = "
			SELECT
				*
			FROM
				".$TB['POP3']."
			WHERE
				m_no='". $AUTH['auth_m_no'] . "'
				AND p3_no='". $_GET['p3_no'] . "'
			";
		$row = db_get_row($sql);

		// [2025-09-25] p3_server와 port로 분리
		if (strpos($row['p3_server'], ':') !== false) {
			list($host, $port) = explode(':', $row['p3_server']); // 최대 2개로 분리
		} else {
			$host = $row['p3_server'];
			$port = null; // 포트 없음
		}

		// [2025-09-25] Xmail SSL 설정 가져오기
		require_once('include/admin_lib.php');
		$cfgs = nm_cfgfileget('server.tab');

		// view
		$p3_view = array();
		$p3_view['p3_server'] = input_value($host, 1);
		$p3_view['p3_server_port'] = input_value($port, 1);
		$p3_view['p3_id'] = input_value($row['p3_id'], 1);
		$p3_view['p3_pwd'] = input_value($row['p3_pwd'], 1);
		if($row['p3_authtype']==="POP3S"){
			$p3_view['p3_authtype'] = " checked";
		}else{
			$p3_view['p3_authtype'] = "";
		}
		if($row['p3_leave']==="Leave"){
			$p3_view['p3_leave'] = " checked";
		}else{
			$p3_view['p3_leave'] = "";
		}

		$p3_view['enable_smtp'] = nm_cfg_val_get($cfgs, 'EnableSMTP-TLS');

		$mail_service = array(
			""        => "직접 입력",
			"NAVER"   => "네이버",
			"daum"    => "다음",
			'NATE'    => '네이트',
			'Google'  => 'Gmail (Google)',
			'Outlook' => 'Outlook.com (Microsoft)',
		);

		$p3_view['external_mail_service'] = radio_value("external_mail_service", $_GET['external_mail_service'], array_values($mail_service), array_keys($mail_service), 0, 0, 1);

		if ($p3_view['enable_smtp']) {
			$p3_view['port'] = '995';
		} else {
			$p3_view['port'] = '110';
		}


// skin view
	nskinset('webmail', 'pop3_mod.html');
	include($NSKIN['view_layout']);


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