<!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>
<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 ?>
		<div class="row mt_10 mb_5 h3 page_title"><?# page_name ?></div>
		<form id="form1" name="form1">
			<div class="card">
				<div class="pos_rel bg_g_100 tabs_warp" id="tabs_warp">
					<div class="tabs_list">
						<a class="tabs_item" href="index.php">控制台</a>
						<a class="tabs_item" data-action="true" href="javascript:void(0);"><?# page_name ?></a>
					</div>
				</div>
				<div class="mall_5 search_box">
					<div class="mr_5 mb_3 d_inblock">
                        <label>關鍵字</label>
                        <input type="text" id="kw" name="kw" value="<?# kw ?>" />
                    </div>
					<div class="mb_3 d_inblock"><a id="btnOK" class="btn btn_info" href="javascript:void(0);">搜尋</a></div>
				</div>
				<div class="pos_rel chklist">
					<?# chk_all ?>
					<ul class="list_box">
						<php:repeater id="list">
						<template>
						<li class="d_lg_flex">
							<p class="chk"><label></label><b class="el-checkbox"><input type="checkbox" name="chk[]" value="<?# ContactID ?>"><span class="el-checkbox-style"></span></b></p>
							<p class="col_lg_1"><label>讀取</label><font><?# IsView ?></font></p>
							<p class="col_lg_1"><label>回覆</label><font><?# IsReply ?></font></p>
							<p class="col_lg_2"><label>標題</label><font><?# Title ?></font></p>
							<p class="col_lg_2"><label>姓名</label><font><?# Name ?></font></p>
							<p class="col_lg_2"><label>信箱</label><font><?# Email ?></font></p>
							<p class="col_lg_2"><label>電話</label><font><?# Phone ?></font></p>
							<p class="col_lg_2"><label>日期</label><font><?# CreatedTime ?></font></p>
							<p class="col_lg_2"><label>操作</label><font><a class="mr_2 btn btn_primary" href="contactView.php?id=<?# ContactID ?>&pUrl=<?# encodedUrl ?>">修改</a><?# DelBtn ?></font></p>
						</li>
						</template>
						</php:repeater>
					</ul>
				</div>
			</div>
            <div class="mt_5 d_flex flex_wrap f_justify_space_b f_aitems_center row">
                <div>
                    <a class="mr_2 btn btn_red" data-action="delall" data-type="1" href="javascript:void(0);">刪除</a>
                    <?# recoveryAllB ?>
                </div>
                <div class="d_flex flex_wrap f_justify_end f_aitems_center pag_box">
                    <font class="mr_3 d_flex pag_no"><?# pagtxt ?></font>
                    <font><span>每頁</span><input type="text" id="pz" name="pz" value="<?# pz ?>"><span>筆資料，</span></font>
                    <font><span>跳到第</span><input type="text" id="p" name="p" value="<?# p ?>"><span>頁</span></font>
                    <a class="ml_3 btn btn_info" id="btnGO" href="javascript:void(0);">GO</a>
                </div>
            </div>
		</form>
		<?# footer ?>
	</div>
</body>
</html>
<script>
	$(function(){
		$('#btnOK').click(function(){
			$('#p').val('1');
			$('#form1').submit();
		});
		$('#chkAll').click(function(){
			var id = $(this).val();
			
			if($(this).eq(0).prop("checked") == true){
				$('input:checkbox[name="chk[]"]').each(function(){
					$(this).prop("checked", true);
				});
			}else{
				$('input:checkbox[name="chk[]"]').each(function(){
					$(this).prop("checked", false);
				});
			}
		});
		$('a[data-action="delItem"]').click(function(){
			if(!confirm('<?# isDelTxt ?>是否確定要'+$(this).text()+'聯絡我們資料?')){
				return false;
			}else{
				$.ajax({
					url: 'ajax/contact.php',
					async: false,
					type: 'POST',
					data: {'do':'del','type':$(this).data('type'),'id':$(this).data('id')},
					dataType: "json",
					context: $(this),
					success: function(obj){
						if(obj.error == 0){
							if(obj.uid == 1){
								var classname = ($(this).data('type') == '1') ?'btn btn_success':'btn btn_danger';
								var typ = ($(this).data('type') == '1') ?0:1;
								var txt = ($(this).data('type') == '1') ?'復原':'刪除';
								$(this).attr('class', classname).data('type', typ).text(txt);
							}else{
								$(this).parents('li').remove();
							}
						}else{
							alert(obj.msg);
						}
					},
					error: function(){
						alert('系統異常!!');
					}
				});
			}
		});
		$('a[data-action="delall"]').click(function(){
			var ids = [];
			$('input:checkbox[name="chk[]"]:checked').each(function(index, element){
				ids[ids.length] = $(element).val();
			});
			if(ids.length == 0){
				alert('請先勾選要'+$(this).text()+'的聯絡我們!');
				return false;
			}else{
				if(!confirm('<?# isDelTxt ?>是否確定要'+$(this).text()+'勾選的聯絡我們資料?')){
					return false;
				}else{
					$.ajax({
						url: 'ajax/contact.php',
						async: false,
						type: 'POST',
						data: {'do':'del','type':$(this).data('type'),'ids':ids.join(',')},
						dataType: "json",
						context: $(this),
						success: function(obj){
							if(obj.error == 0){
								location.href = ('<?# currentUrl ?>' == '') ?'contactList.php':'<?# currentUrl ?>';
							}else{
								alert(obj.msg);
							}
						},
						error: function(){
							alert('系統異常!!');
						}
					});
				}
			}
		});
		$('a[data-action="goPage"]').click(function(){
			$('#p').val($(this).data('id'));
			$('#form1').submit();
		});
		$('#btnGO').click(function(){
			$('#form1').submit();
		});
	});
</script>