<!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>
<!-- 下拉選單 -->
<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 ?>
		<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">
					<a class="mr_2 btn btn_success" href="lineGearingSend.php">連動帳號</a>
					<a class="mr_2 btn btn_indigo" id="addLine" href="javascript:void(0);">手動增加連動帳號</a>
				</div>
				<div class="mr_5 ml_5 mb_8">
					<p>與Line通知連動可以將前台網站通知發送至您設定的Line對話視窗</p>
					<p class="mt_3 d_flex">如果您連動的是群組請先將 <a class="mr_3 ml_3 btn btn_tertiary" href="https://line.naver.jp/ti/p/~@linenotify" target="_blank">LINE Notify官方帳號</a> 加入至要連動的群組。手動新增連動帳號請至 <a class="mr_3 ml_3 btn btn_orange" href="https://notify-bot.line.me/my/" target="_blank">連動的服務</a> 介面新增</p>
				</div>
				<div class="over_hid 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="<?# LGID ?>"><span class="el-checkbox-style"></span></b></p>
							<p class="col_lg_1"><label>類別</label><font><?# TypeName ?></font></p>
							<p class="col_lg_3"><label>名稱</label><font><?# Target ?></font></p>
							<p class="col_lg_2"><label>建立日期</label><font><?# CreatedDate ?></font></p>
							<p class="col_lg_2">
								<label>操作</label>
								<font>
									<a class="mr_2 btn btn_warning" data-action="smessage" data-id="<?# LGID ?>">發訊息</a>
									<a class="mr_2 btn btn_red" data-action="delItem" data-id="<?# LGID ?>">取消連動</a>
								</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_warning" id="btnMessage" href="javascript:void(0);">發訊息</a>
                    <a class="mr_2 btn btn_red" id="btnDel" href="javascript:void(0);">取消連動</a>
                </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(){
		$('#v').val('<?# v ?>');
		
		$('select').niceSelect();
		
		$('#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);
				});
			}
		});
		
		$('#addLine').click(function(){
			var token = prompt("請輸入存取權杖!");
			if(token != "" && token != null){
				$.ajax({
					'url': 'ajax/line.php',
					'async': false,
					'type': 'POST',
					'data': {'do': 'addline' , 'token': token},
					'dataType': 'json',
					'success': function(Jdata){
						alert(Jdata.Message);
						if(Jdata.Status == '0'){
							location.href = location.href;
						}else{
							document.execCommand('Refresh');
						}
					},
					'error': function(){
						alert('系統異常!!請重新整理再試一次!');
					}
				});
			}
		});
		
		$('a[data-action="smessage"]').click(function(){
			var text = prompt("請輸入要發送的訊息!");
			if(text != "" && text != null){
				$.ajax({
					'url': 'ajax/line.php',
					'async': false,
					'type': 'POST',
					'data': {'do': 'smessage' , 'text': text , 'id': $(this).data('id')},
					'dataType': 'json',
					'success': function(Jdata){
						alert(Jdata.Message);
						if(Jdata.Status == '1'){
							document.execCommand('Refresh');
						}
					},
					'error': function(){
						alert('系統異常!!請重新整理再試一次!');
					}
				});
			}
		});
		
		$('a[data-action="delItem"]').click(function(){
			if(!confirm('取消連動後將無法恢復!是否確定要取消連動該帳號?')){
				return false;
			}else{
				$.ajax({
					'url': 'ajax/line.php',
					'async': false,
					'type': 'POST',
					'data': {'do': 'delgear' , 'id': $(this).data('id')},
					'dataType': 'json',
					'success': function(Jdata){
						alert(Jdata.Message);
						if(Jdata.Status == '0'){
							location.href = location.href;
						}else{
							document.execCommand('Refresh');
						}
					},
					'error': function(){
						alert('系統異常!!請重新整理再試一次!');
					}
				});
			}
		});
		
		$('#btnMessage').click(function(){
			var ids = [];
			$('input:checkbox[name="chk[]"]:checked').each(function(index, element){
				ids[ids.length] = $(element).val();
			});
			if(ids.length == 0){
				alert('請先勾選要發送訊息的帳號!');
				return false;
			}else{
				var text = prompt("請輸入要發送的訊息!");
				if(text != "" && text != null){
					$.ajax({
						'url': 'ajax/line.php',
						'async': false,
						'type': 'POST',
						'data': {'do': 'smessage' , 'text': text , 'ids': ids.join(',')},
						'dataType': 'json',
						'success': function(Jdata){
							alert(Jdata.Message);
							if(Jdata.Status == '1'){
								document.execCommand('Refresh');
							}
						},
						'error': function(){
							alert('系統異常!!請重新整理再試一次!');
						}
					});
				}
			}
		});
		
		$('#btnDel').click(function(){
			var ids = [];
			$('input:checkbox[name="chk[]"]:checked').each(function(index, element){
				ids[ids.length] = $(element).val();
			});
			if(ids.length == 0){
				alert('請先勾選要取消連動的帳號!');
				return false;
			}else{
				if(!confirm('取消連動後將無法恢復!是否確定要取消連動該帳號?')){
					return false;
				}else{
					$.ajax({
						'url': 'ajax/line.php',
						'async': false,
						'type': 'POST',
						'data': {'do': 'delgear' , 'ids': ids.join(',')},
						'dataType': 'json',
						'success': function(Jdata){
							alert(Jdata.Message);
							if(Jdata.Status == '0'){
								location.href = location.href;
							}else{
								document.execCommand('Refresh');
							}
						},
						'error': function(){
							alert('系統異常!!請重新整理再試一次!');
						}
					});
				}
			}
		});
		
		$('#btnOK').click(function(){
			$('#p').val('1');
			$('#form1').submit();
		});
		$('a[data-action="goPage"]').click(function(){
			$('#p').val($(this).data('id'));
			$('#form1').submit();
		});
		$('#btnGO').click(function(){
			$('#form1').submit();
		});
	});
</script>