<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理後臺</title>
<meta name="keywords" content="管理後臺" />
<meta name="description" content="管理後臺" />
<script src="/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<!-- 瀏覽用燈箱片效果 -->
<link rel="stylesheet" href="/jquery/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="/jquery/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
</head>
<body>
	<div class="wrapper">
    	<?# header ?>
    	<div class="wrap">
        	<?# sidePage ?>
            <div class="contentMain">
            	<h3>批量新增產品</h3>
                <div class="article">
                	<form id="form1" name="form1" action="productMultiAdd.php" method="post">
                    	<fieldset style="width: 100%;">
                        	<p>
                            	<label>產品分類</label>
                                <select id="cid" name="cid"></select>
                            </p>
                            <p>
                            	<label>首頁顯示</label>
                                <input type="radio" name="IsIndex" value="1" />首頁顯示
								<input type="radio" name="IsIndex" value="0" checked="checked" />首頁不顯示
                            </p>
                            <p>
                            	<label>啟用</label>
								<input type="radio" name="Visible" value="1" />啟用
								<input type="radio" name="Visible" value="0" checked="checked" />不啟用
                            </p>
                            <p>
                            	<label>產品</label>
                                <input type="button" id="btnMulti" name="btnMulti" value="瀏覽" />
                            </p>
                            <ul id="productUL"></ul>
                            <p>
                            </p><p>
                            	<input type="button" id="btnOK" name="btnOK" value="確 定" />
								<input type="button" id="btnCancel" value="返 回" />
                            </p>
                            <input type="hidden" id="pUrl" name="pUrl" value="<?# pUrl ?>" />
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
        <?# footer ?>
    </div>
<script>
<!--
var jsonC = '<?# jsonC ?>';
var aryC = JSON.parse(jsonC);
function SetFileField(fileUrl,data,allFiles){
	for(var i=0;i<allFiles.length;i++){
		$('#'+data["selectActionData"]).append(
			$('<li></li>').html('<a class="fancybox" href="'+allFiles[i]["url"]+'"><img src="'+allFiles[i]["url"]+'" style="width:50px; height:50px;"></a><input type="hidden" name="IconImage[]" value="'+allFiles[i]["url"]+'" />產品名稱：<input type="text" class="productInp" name="ProductName[]" value="'+(($('#'+data["selectActionData"]+' li').size()+1) * 10).toString()+'">排序：<input type="text" class="productInp" name="OrderNO[]" value="'+(($('#'+data["selectActionData"]+' li').size()+1) * 10).toString()+'" /><input type="button" class="del" data-action="delItem" value="刪除" />')
		);
	}
}
$(function(){
	$(".fancybox").fancybox();
	$('#productUL').on('click','input:button[data-action="delItem"]',function(){
		$(this).parent('li').remove();
	});

	$.each(aryC,function(a,b){
		if(b.Sub.length == 0){
			$('#cid').append($('<option></option>').val(b.ID).text(b.Name));
		}else{
			var optg = $('<optgroup></optgroup>').attr('label',b.Name);
			$.each(b.Sub,function(c,d){
				optg.append($('<option></option>').val(d.SubID).text(d.SubName));
			});
			$('#cid').append(optg);
		}
	});
	$('#cid').val('<?# cid ?>');
	
	$('#btnMulti').click(function(){
		var finder = new CKFinder();
		finder.basePath = 'ckfinder/';
		finder.resourceType = 'Images';
		finder.selectActionFunction = SetFileField;
		finder.selectActionData = 'productUL';
		finder.popup();
	});
	$('#btnOK').click(function(){
		if($("#productUL > li").size() == 0){
			alert('請至少上傳一張相片!');
			return false;
		}
		$('#form1').submit();
	});
	$('#btnCancle').click(function(){
		if($('#pUrl').val() == ''){
			location.href = 'productList.php';
		}else{
			location.href = $('#pUrl').val();
		}
	});
});
//-->
</script>
</body>
</html>