<!DOCTYPE html>
<html dir="ltr" lang="zh-TW">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<title>管理後臺</title>
<meta name="robots" content="noindex, nofollow" />
<link href="less/page.less" rel="stylesheet/less">
<link href="css/main.css" rel="stylesheet">
<link href="css/page.css" rel="stylesheet">
<script src="/jquery/jquery-1.10.js"></script>
<!--tabs-->
<script src="/jquery/horizontalmenu/jquery.horizontalmenu.js"></script>
<!-- 下拉選單 -->
<link href="/jquery/select/nice-select.css" rel="stylesheet">
<script src="/jquery/select/jquery.nice-select.js"></script>
<script>
	if('<?# alertMsg ?>' != ''){
		alert('<?# alertMsg ?>');
		if('<?# goBack ?>' == 'Y') history.back();
	}
	if('<?# locationHref ?>' != '') location.href = '<?# locationHref ?>';
</script>
</head>
<body>
	<?# sidePage ?>
	<div class="pos_rel" id="content">
		<?# header ?>
		<form id="form1" name="form1" method="post">
			<div class="row mt_10 mb_5 h3 page_title"><?# page_name ?></div>
			<div class="card">
				<div class="pos_rel bg_g_100 tabs_warp" id="tabs_warp">
					<div class="tabs_list">
						<a class="tabs_item" data-action="true" data-id="box1" href="javascript:void(0);">寄件信箱設定</a>
						<a class="tabs_item" data-id="box2" href="javascript:void(0);">HEAD區外掛安裝</a>
						<a class="tabs_item" data-id="box3" href="javascript:void(0);">BODY區外掛安裝</a>
					</div>
				</div>
				<div id="tabs_box" class="card_body form_box">
					<div id="box1" class="d_md_flex flex_wrap tab_content" data-action="true">
						<div class="col_md_6 d_flex form_list">
							<label>信箱類型<span>*</span></label>
                            <select id="sendMailType" name="sendMailType">
                                <option value="">不啟用</option>
                                <option value="1">預設一</option>
                                <option value="5">預設二</option>
                                <option value="2">GMail</option>
                                <option value="3">Yahoo!</option>
                                <option value="4">Outlook</option>
                                <option value="0">其他</option>
                            </select>
						</div>
						<div class="col_md_6 d_flex form_list"><label>信箱<span>*</span></label><input type="text" id="sendMailAddress" name="sendMailAddress" value="<?# sendMailAddress ?>" /></div>
						<div class="col_md_6 d_flex form_list"><label>密碼<span>*</span></label><input type="text" id="sendMailPassword" name="sendMailPassword" value="<?# sendMailPassword ?>" /></div>
						<div class="col_md_6 d_flex form_list"><label>主機位置<span>*</span></label><input type="text" id="sendMailHost" name="sendMailHost" value="<?# sendMailHost ?>" /></div>
						<div class="col_md_6 d_flex form_list"><label>通訊埠<span>*</span></label><input type="text" id="sendMailPort" name="sendMailPort" value="<?# sendMailPort ?>" /></div>
						<div class="col_md_6 d_flex form_list">
							<label>加密方式<span>*</span></label>
                            <select id="sendMailSMTPSecure" name="sendMailSMTPSecure">
                                <option value="">不加密</option>
                                <option value="ssl">SSL</option>
                                <option value="tls">TLS</option>
                            </select>
						</div>
						<div class="col_md_6 d_flex form_list"><label>安全驗證</label><p><font class="checkbox"><input type="checkbox" id="sendMailSMTPAuth" name="sendMailSMTPAuth" value="1"><span></span></font></p></div>
						<div class="col_12 d_flex form_btn">
							<a class="ml_2 btn btn_tertiary" data-action="nextPage" href="javascript:void(0);">下一步</a>
							<a class="ml_2 btn btn_indigo" id="btnT" href="javascript:void(0);">測試</a>
						</div>
					</div>
					<div id="box2" class="tab_content">
						<div class="form_list"><label>原始碼</label><textarea id="headHTML" name="headHTML"><?# headHTML ?></textarea></div>
						<div class="d_flex form_btn">
							<a class="ml_2 btn btn_orange" data-action="upPage" href="javascript:void(0);">上一步</a>
							<a class="ml_2 btn btn_tertiary" data-action="nextPage" href="javascript:void(0);">下一步</a>
						</div>
					</div>
					<div id="box3" class="tab_content">
						<div class="form_list"><label>原始碼</label><textarea id="bodyTopHTML" name="bodyTopHTML"><?# bodyTopHTML ?></textarea></div>
						<div class="d_flex form_btn"><a class="ml_2 btn btn_orange" data-action="upPage" href="javascript:void(0);">上一步</a></div>
					</div>
				</div>
			</div>
            <div class="row mt_5 d_flex start_box"><a class="mr_2 btn btn_info" id="btnOK" href="javascript:void(0);">送出</a></div>
		</form>
		<?# footer ?>
	</div>
</body>
</html>
<script>
	$(function(){
		$('#sendMailType').val('<?# sendMailType ?>');
		$('#sendMailSMTPSecure').val('<?# sendMailSMTPSecure ?>');
		if('<?# sendMailSMTPAuth ?>' == '1') $('#sendMailSMTPAuth').prop('checked', true);
		
		$('select').niceSelect();
		
		$('#tabs_warp').horizontalmenu({
			itemClick: function (item) {
				$('#tabs_box .tab_content').removeAttr('data-action');
				$('#tabs_box .tab_content:eq(' + $(item).index() + ')').attr('data-action', 'true');
				return false;
			}
		});

		$('#sendMailType').change(function(){
			var val = $(this).val();

			var isDisabled = false;
			var btnTDisplay = 'inline-block';
			var defaultValues = {
				'1': { address: 'mail@cd.com.tw', password: '', host: '', port: '', secure: '', auth: false },
				'2': { host: 'smtp.gmail.com', port: '587', secure: 'tls', auth: true },
				'3': { host: 'smtp.mail.yahoo.com', port: '25', secure: 'tls', auth: true },
				'4': { host: 'smtp-mail.outlook.com', port: '25', secure: 'tls', auth: true },
				'5': { address: 'system@iweb.com.tw', password: '', host: '', port: '', secure: '', auth: false }
			};

			if (val === '1' || val === '5') {
				isDisabled = true;
				btnTDisplay = 'none';
			}

			$('#sendMailAddress').val(defaultValues[val]?.address || '');
			$('#sendMailPassword').val(defaultValues[val]?.password || '');
			$('#sendMailHost').val(defaultValues[val]?.host || '');
			$('#sendMailPort').val(defaultValues[val]?.port || '');
			$('#sendMailSMTPSecure').val(defaultValues[val]?.secure || '');
			$('#sendMailSMTPAuth').prop('checked', defaultValues[val]?.auth || false);

			$('#sendMailAddress').attr('disabled', isDisabled);
			$('#sendMailPassword').attr('disabled', isDisabled);
			$('#sendMailHost').attr('disabled', isDisabled);
			$('#sendMailPort').attr('disabled', isDisabled);
			$('#sendMailSMTPSecure').attr('disabled', isDisabled);
			$('#sendMailSMTPAuth').prop('disabled', isDisabled);
			$('#btnT').css('display', btnTDisplay);
			
			$('select').niceSelect('destroy');
			$('select').niceSelect();
		});
		$('#sendMailType').change();
		
		$('#btnT').click(function(){
			$.ajax({
				'url': 'ajax/smtp.php',
				'async': false,
				'type': 'POST',
				'data': {
					'ma': $('#sendMailAddress').val(),
					'pa': $('#sendMailPassword').val(),
					'ho': $('#sendMailHost').val(),
					'po': $('#sendMailPort').val(),
					'se': $('#sendMailSMTPSecure').val(),
					'sm': $('#sendMailSMTPAuth').is(':checked')
				},
				'dataType': 'text',
				'success': function(msg){
					alert(msg);
				},
				'error': function(){
					alert('系統異常!請重新整理頁面再試一次!');
				}
			});
		});

		$('#btnOK').click(function(){
			$('#form1').submit();
		});
	});
</script>