<!DOCTYPE html>
<!--[if IE 8 ]><html dir="ltr" lang="zh-TW" class="ie8"><![endif]-->
<!--[if IE 9 ]><html dir="ltr" lang="zh-TW" class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html dir="ltr" lang="zh-TW">
<!--<![endif]-->
<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>
<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">
            <input type="hidden" id="id" name="id" value="<?# id ?>" />
            <input type="hidden" id="pUrl" name="pUrl" value="<?# pUrl ?>" />
			<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);">修改<?# page_name ?></a>
						<a class="tabs_item" data-id="box2" href="javascript:void(0);">帳號綁定</a>
						<a class="tabs_item" data-id="box3" href="javascript:void(0);">管理權限</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>管理帳號</label><input type="text" value="<?# LoginName ?>" readonly /></div>
						<div class="col_md_6 d_flex form_list"><label>管理密碼</label><input type="text" id="Password" name="Password" value="<?# Password ?>" /></div>
						<div class="col_md_6 d_flex form_list"><label>管理人名稱</label><input type="text" id="UserName" name="UserName" value="<?# UserName ?>" /></div>
						<div class="col_md_6 d_flex form_list"><label>管理人信箱</label><input type="text" id="Email" name="Email" value="<?# Email ?>" /></div>
						<div class="col_12 d_flex form_list"><label>狀態</label><p><font class="checkbox"><input type="checkbox" id="Visible" name="Visible" 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></div>
					</div>
					<div id="box2" class="tab_content">
						<?# line_box ?>
						<div class="d_flex form_list">
							<label>Line user id</label>
							<p class="in_group">
								<input type="text" id="LineUID" name="LineUID" value="<?# LineUID ?>" />
								<font class="group"><?# line_btn ?></font>
							</p>
						</div>
						<div class="d_flex form_list"><label>Gmail</label><input type="text" id="Gmail" name="Gmail" value="<?# Gmail ?>" /></div>
						<div class="d_flex form_list"><label>fb帳號</label><input type="text" id="FbAccount" name="FbAccount" value="<?# FbAccount ?>" /></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="mb_5" id="divMenu"></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>
                <a class="mr_2 btn btn_g_300" id="btnCancel" href="javascript:void(0);">返回</a>
			</div>
		</form>
		<?# footer ?>
	</div>
</body>
</html>
<script>
	var txtJ = '<?# txtJ ?>';
	var aryJ = JSON.parse(txtJ);
	$(function(){
		if('<?# Visible ?>' == '1') $('#Visible').prop('checked', true);
		
		$('#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;
			}
		});
		
		$.each(aryJ, function(a,b){
			var list = $('<div></div>').attr('class', 'mb_3 list');
			
			var parent = $('<font></font>').attr('class', 'el-checkbox parent').html('<input type="checkbox" data-action="chk_parent" name="MenuID[]" value="' + b.MenuID + '"><span class="el-checkbox-style"></span><span>' + b.MenuName + '</span>');
			
			if(b.aryCL.length > 0){
				var div = $('<div></div>').attr('class', 'mt_1 pall_2 pr_4 pl_4 bg_g_100');
				$.each(b.aryCL, function(c,d){
					var font = $('<font></font>').attr('class', 'el-checkbox mr_5').html('<input type="checkbox" data-action="chkM" data-id="' + b.MenuID + '" name="MenuID[]" value="' + d.MenuID + '"><span class="el-checkbox-style"></span><span>' + d.MenuName + '</span>');
					div.append(font);
				});
			}
			$('#divMenu').append(list.append(parent).append(div));
		});
		<php:repeater id="listL">
        <template>
        $('input:checkbox[name="MenuID[]"][value="<?# MenuID ?>"]').prop('checked', true);
        </template>
		</php:repeater>
		
		$('input:checkbox[data-action="chk_parent"]').click(function(){
			var id = $(this).val();
			
			if($(this).eq(0).prop("checked") == true){
				$('input:checkbox[data-action="chkM"][data-id="'+id+'"]').each(function(){
					$(this).prop("checked", true);
				});
			}else{
				$('input:checkbox[data-action="chkM"][data-id="'+id+'"]').each(function(){
					$(this).prop("checked", false);
				});
			}
		});
		$('#btnOK').click(function(){
			if($('#Password').val() == ''){
				alert('管理密碼不可空白!');
				$('#Password').focus();
				tabchk(1);
				return false;
			}
			if($('#UserName').val() == ''){
				alert('管理人名稱不可空白!');
				$('#UserName').focus();
				tabchk(1);
				return false;
			}
			if($('#id').val() > 1 && $('input:checkbox[name="MenuID[]"]:checked').size() == 0){
                if(!confirm('此帳號完全沒有勾選權限!是否確定要送出儲存?')){
                    tabchk(3);
                    return false;
                }
			}
			$('#form1').submit();
		});
		$('#btnCancel').click(function(){
			location.href = ($('#pUrl').val() == '')?'userList.php':$('#pUrl').val();
		});
		$('a[data-action="upLine"]').click(function(){
			$.ajax({
				'url': 'ajax/line.php',
				'async': false,
				'type': 'POST',
				'data': {'do': 'upline'},
				'dataType': 'json',
				'success': function(Jdata){
					alert(Jdata.Message);
					if(Jdata.Status == '1'){
						document.execCommand('Refresh');
					}
				},
				'error': function(){
					alert('系統異常!!請重新整理再試一次!');
				}
			});
		});
		$('a[data-action="delItem"]').click(function(){
			$.ajax({
				'url': 'ajax/line.php',
				'async': false,
				'type': 'POST',
				'data': {'do': 'del' , 'id': $('#id').val()},
				'dataType': 'json',
				'success': function(Jdata){
					alert(Jdata.Message);
					if(Jdata.Status == '0'){
						location.href = location.href;
					}else{
						document.execCommand('Refresh');
					}
				},
				'error': function(){
					alert('系統異常!!請重新整理再試一次!');
				}
			});
		});
	});
</script>