<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模板管理器</title>
<script language="javascript" src="<?=BASEURL?>public/share/jquery.js"></script>
<script language="javascript" src="<?=BASEURL?>public/admin/js/common.js"></script>
<link href="<?=BASEURL?>public/admin/css/main.css" rel="stylesheet" type="text/css" />
<script language="javascript">
//使用附件
function useFile(){
	var n			=	window.opener.$("#paths").find('tr').length-1
	if($("input:checked").length>0){
		$("input:checked").each(function(){
			var	path	=	$(this).attr('value');
			if(window.opener.$("#paths").html().indexOf(path)<=0&&path!='all'){
				var row		=	"<tr id='annex"+n+"'><td>"+n+"</td><td>"+base_name(path)+"</td><td><input type='text' name='annex[description][]' class='text' value=''><td><input type='text' name='annex[read_money][]' class='text' value='0'  style='width:40px;'></td><td><input type='text' name='annex[read_pointer][]' class='text' value='0'  style='width:40px;'></td><td><a href='javascript:void(0)' onclick='$(\"#annex"+n+"\").remove();'><IMG SRC='<?=BASEURL?>public/admin/images/delete.png' border=0></a><input type='hidden' name='annex[path][]' value='"+path+"'></td></tr>";
				window.opener.$("#useannex").before(row);
				n++;
			}
		});
		window.close();
	}
	else{
		alert('请选择需要操作的文件');
	}
	return false;
}

function usetpl(path){
	window.opener.$("#<?=$inputid?>").val(path);
	window.close();
}

function base_name(pFilePath){
	var temp_win = pFilePath.lastIndexOf("\\");
	var temp_unix = pFilePath.lastIndexOf("/");
	if (temp_win>0)
	{
		temp = temp_win;
	}
	else if (temp_unix>0)
	{
		temp = temp_unix;
	}
	else
	{
		temp = -1;
	}
	file_name = pFilePath.substr(temp+1);
	return(file_name);
}
$(document).ready(
	function(){
		$(".localupload").click(function(){
			if(!document.getElementById('localupload')){
				var url		=	$(this).attr('href');
				var height	=	$(window).height()/2-400/2;
				var width	=	$(window).width()/2-500/2;
				var dialog	=	"<div id='localupload'><div class='dialog_off' onclick='offdialog()'></div><div class='dialogiframe'><iframe src='"+url+"' name='main' width='500' height='400' frameborder='0' scrolling='auto' style='overflow: visible;' id='main'></iframe></div></div>";
				$("body").append(dialog);
				$("#localupload").css("top",height);
				$("#localupload").css("left",width);
			}
			else{
				$("#localupload").css('display',"block");
			}
			return false;
		});
	}
);
/*
*
*/
function offdialog(options){
	$(".dialog_off").click(function (){
		$("#list").addClass("ajax_loader");
		$("#list").html("");
		$("#localupload").css('display',"none");
		$.get("<?=BASEURI?>templates/select/<?=$inputid?>/<?=base64_encode($targPath)?>/list",function(response){$("#list").html(response);$("#list").removeClass("ajax_loader");});
	});
}
</script>
</head>
<body>
<form action="<?=@$formAction?>" id="templates" method="post" name="adminform">
<table class="adminlist" cellpadding="0" cellspacing="0" id="filebrowse">
  <thead>
    <tr>
      <th width="5%">&nbsp;</th>
      <th width="5%">序号</th>
      <th width="25%">文件名称</th>
      <th width="15%">路径</th>
      <th width="5%">类型</th>
      <th width="15%">上传时间</th>
      <th width="5%">大小</th>
      <th width="15%">操作</th>
    </tr>
  </thead>
  <tbody>
  <tr>
    <td class="list" id="filelist" valign="top" style="background:#FFFFFF;padding:0px;" colspan="9">
    <div id="list">
          <input type="hidden" name="boxchecked" value="0">
          <input type="hidden" name="current-path" value="<?=@$targPath?>">
          <table class="filelist" cellpadding="0" cellspacing="0" width="100%">
            <tbody>
              <tr>
                <td width="5%">&nbsp;</td>
                <td colspan="8"><a href="#" onclick="usetpl('')">无</a></td>
              </tr>
              <tr>
                <td width="5%">&nbsp;</td>
                <td colspan="8"><?=html::anchor(BASEURI."templates/select/".$inputid."/".base64_encode(dirname($targPath)),"上级目录");?></td>
              </tr>
              <?php foreach($paths as $tmp){if(!@$a){$a=1;}?>
              <?php 	if($tmp['type']=="dir"){?>
              <tr>
                <td width="5%">&nbsp;</td>
                <td width="5%"><?=$a++?></td>
                <td width="25%"><?=html::anchor(BASEURI."templates/select/".$inputid."/".base64_encode($tmp['path']),$tmp['file_name']);?></td>
                <td width="15%"><?=dirname($tmp['path'])?></td>
                <td width="5%">目录</td>
                <td width="15%">&nbsp;</td>
                <td width="5%">&nbsp;</td>
                <td width="15%">&nbsp;
                  
                </td>
              </tr>
              <?php }?>
              <?php }?>
              <?php foreach($paths as $tmp){if(!@$a){$a=1;}?>
              <?php 	if($tmp['type']=="file"){?>
              <tr>
                <td width="5%">&nbsp;</td>
                <td width="5%"><?=$a++?></td>
                <td width="25%"><a href="javascript:void(0)" onClick="usetpl('<?=$tmp['path']?>')"><?=$tmp['file_name']?></a></td>
                <td width="15%"><?=dirname($tmp['path'])?></td>
                <td width="5%"><?=$tmp['ext']?></td>
                <td width="15%"><?=$tmp['filemtime']?></td>
                <td style="text-align:right;" width="10%"><?=$tmp['file_size']?>
                  KB</td>
                <td width="15%">
				  <?=html::anchor(BASEURI.'','编辑')?>
                  <?=html::anchor(BASEURI.'#','使用模板',array("onclick"=>"usetpl('".$tmp['template_path']."')"))?>
                </td>
              </tr>
              <?php }?>
              <?php }?>
            </tbody>
          </table>
      </div></td>
  </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>显示模式</td>
      <td colspan="3">
      	<span class="file_show_list" title="列表">&nbsp;</span>
      	<span class="file_show_thumb" title="缩略图">&nbsp;</span>
      	<span class="file_show_thumblist" title="缩略图列表">&nbsp;</span>
      </td>
      <td colspan="5" style="text-align:right"><?=html::anchor(BASEURI.'','新建文件夹')?>
        <?=html::anchor(BASEURI.'#','批量删除',array("onclick"=>"select_control('".BASEURI."templates/delete','你是否要删除已选中的文件')"))?>
        <?=html::anchor(BASEURI.'file_upload/index','本地上传',array('class'=>'localupload'))?>
        <?=html::anchor(BASEURI.'#','使用附件',array("onclick"=>"useFile()"))?>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </td>
    </tr>
  </tfoot>
</table>
</form>
<div class="file_comment">
1,勾选复选框，点击使用“使用附件”，即可加入到附件列表
</div>
</body>
</html>
