<?php include $this->admin_tpl('meta', 'admin');?>
<link rel="stylesheet" href="<?php echo STATIC_URL;?>plugin/webuploader/webuploader.css?v=<?php echo YZMCMS_VERSION;?>"/>
<title>附件上传 - YzmCMS内容管理系统</title>
</head>
<body>
<div class="page-container">
	<div id="tab_system" class="HuiTab">
		<div class="tabBar cl"><span>上传文件</span><span>站内文件</span></div>
		<div class="tabCon">
			<div class="yzm-notice">
				类型:  <?php echo $type;?>
			</div>
			<div class="yzm-notice">
				单文件最大: <span class="c-red"><?php echo $s;?></span> ，数量: <span class="c-red"><?php echo $n;?></span>个
				<label class="yzm-open-watermark"><input type="checkbox" name="open_watermark" id="open_watermark" value="1"> 添加水印</label>
			</div>
			<div id="fileList" class="yzm-uploader-list">
			</div>
			<div id="filePicker" class="yzm-upload-button">选择文件</div>
			<div id="uploadlist" class="yzm-imagelist">
				<ul>
				</ul>
			</div>
		</div>

		<div class="tabCon">
			<div class="yzm-attachment-search">
				<form action="" method="get">
					<input type="hidden" name="m" value="<?php echo ROUTE_M;?>" >
					<input type="hidden" name="c" value="<?php echo ROUTE_C;?>" >
					<input type="hidden" name="a" value="<?php echo ROUTE_A;?>" >
					<input type="hidden" name="tab" value="1">
					名称：<input type="text" class="input-text" name="originname" value="<?php echo $originname;?>" placeholder="附件名称" > &nbsp;
					日期：<input type="text" class="input-text" name="uploadtime" value="<?php echo $uploadtime;?>" placeholder="上传日期" onclick="laydate({format:'YYYY-MM-DD'})">
					<button name="dosubmit" class="yzm-search-btn btn-success" type="submit" value="1"><i class="yzm-iconfont yzm-iconsousuo"></i> 搜索</button>
				</form>
			</div>
			<div class="yzm-imagelist">
				<ul>
					<?php
					foreach($data as $val){
						$thum = $val['isimage'] ? $val['filepath'].$val['filename'] : file_icon($val['filename']);
						echo '<li><a href="javascript:;" onclick="album_cancel(this)" title="'.$val['originname'].'"><img class="img_src" src="'.$thum.'" attid="'.$val['id'].'" path="'.$val['filepath'].$val['filename'].'"><img src="'.STATIC_URL.'images/checked.gif" class="checkd hidden"></a><span class="yzm-iconfont img_del" onclick="yzm_att_del(\''.U('delete', array('id'=>$val['id'])).'\', \''.$val['originname'].'\')">&#xe625;</span></li>';
					}
					?>
				</ul>
				<div class="clearfix"></div>
				 <div id="page"><span class="page_left">共<?php echo $total?>条记录</span><span class="page_right"><?php echo $page->gethome().$page->getlist().$page->getend();?></span></div>
			</div>
		</div>
	</div>
	<div class="yzm-bottom-button">
		<input type="button" class="btn btn-primary radius" id="determine" value="&nbsp;&nbsp;确定&nbsp;&nbsp;">
		<input type="button" class="btn btn-default radius" id="cancel" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
	</div>
</div>
<div id="att_id" class="hidden"></div>
<div id="att_status" class="hidden"></div>
<div id="att_titles" class="hidden"></div>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/laydate/1.1/laydate.js"></script>
<script type="text/javascript">
	var STATIC_URL = '<?php echo STATIC_URL;?>';
	var $ = jQuery, $list = $('#fileList'), uploader;
	var yzm_uploader_config = {
	    auto: true,
	    swf: STATIC_URL + 'plugin/ueditor/third-party/webuploader/Uploader.swf',
	    server: '<?php echo U('upload');?>',
	    pick: '#filePicker',
	    fileNumLimit : <?php echo $n;?>,
	    fileSingleSizeLimit : <?php echo 1024*get_config('upload_maxsize');?>,
	    compress: false,
	    accept: {
	    	title: '文件上传',
	        extensions: '<?php echo $type;?>'
	    },
	    formData : {
	        'open_watermark' : 0,
	        'filetype' : '<?php echo $t;?>',
	        'module' : '<?php echo $module;?>',
	    }
	    
	};

$(function(){
	
	var index = parent.layer.getFrameIndex(window.name);
	$('#determine').on('click', function(){
		var att_id = $("#att_id").html();
		var att_status = $("#att_status").html();
		var att_titles = $("#att_titles").html();
		if(att_status == ''){
			layer.alert('你还没选择附件呢？'); 
			return false;
		}
		att_id = att_id.substr(1);		
		att_status = att_status.substr(1);		
		att_titles = att_titles.substr(1);		
		<?php
			if($t == 1) echo 'if(!isimg(att_status)){ layer.alert("选择的类型必须为图片类型!"); return false;}';
		?>
		<?php if($n == 1) { ?>
		
		parent.$("#<?php echo $pid;?>").val(att_status);
		parent.$("#<?php echo $pid;?>_attid").val(att_id);
		parent.$("#<?php echo $pid;?>_src").attr("src", att_status);
		
		<?php }else{ ?>
		
		var string = '';
		var strs, tits; 
		strs = att_status.split('|');
		tits = att_titles.split('|');
		tits.forEach(function(val,index,tits){
		    tits[index] = val.substring(0, val.lastIndexOf('.'));
		});
		var title = parent.$("input[name='title']").val();
		for (i=0;i<strs.length;i++ ){ 
			var alt = title ? title+'-'+(i+1) : tits[i];
			string += '<li>文件：<input type="text" name="<?php echo $pid;?>[url][]" value="'+strs[i]+'" id="<?php echo $pid;?>_'+i+'" onMouseOver="yzm_img_preview(\'<?php echo $pid;?>_'+i+'\', this.value)"  onmouseout="layer.closeAll();" class="input-text yzm-input-url"> 描述：<input type="text" name="<?php echo $pid;?>[alt][]" value="'+alt+'" class="input-text yzm-input-alt"><a href="javascript:;" class="secondary" onclick="yzm_move_li(this, 1);">上移</a> <a href="javascript:;" class="secondary" onclick="yzm_move_li(this, 0);">下移</a> <a href="javascript:;" class="danger" onclick="yzm_delete_li(this);">删除</a></li>';
		} 
		parent.$("#<?php echo $pid;?>").append(string);	
		
		<?php } ?>
		parent.layer.close(index);
	});

	if(localStorage.getItem('open_watermark')) {
		$('#open_watermark').prop('checked', localStorage.getItem('open_watermark') === 'true');
	}

	$('#open_watermark').on('change', function(){
		localStorage.setItem('open_watermark', this.checked);
	});
	
	$('#cancel').on('click', function(){
		parent.layer.close(index);
	});
	
	$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","<?php echo isset($_GET['tab']) ? intval($_GET['tab']) : '0'?>");
});

</script>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/webuploader/webuploader.nolog.min.js?v=<?php echo YZMCMS_VERSION;?>"></script>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/webuploader/yzm.upload.js?v=<?php echo YZMCMS_VERSION;?>"></script>

</body>
</html>