<script language="javascript" type="text/javascript" src="<?=BASEURL?>public/admin/js/dialog.js"></script>
<script language="javascript" type="text/javascript" src="<?=BASEURL?>public/share/js/table.js"></script>
<script language="javascript" type="text/javascript" src="<?=BASEURL?>public/share/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript" src="<?=BASEURL?>public/share/tiny_mce/plugins/imagemanager/jscripts/mcimagemanager.js"></script>
<input type="hidden" name="content[channel_id]"	value="<?=$channel_id?>" />
<input type="hidden" name="content_id" value="<?=@$content->content_id?>" />
<?=$form?>
<div class="tab" id="tab<?=SumTab?>">
<table class="adminform" cellpadding="0" cellspacing="0"  id="paths">
	<tr>
		<td>#</td>
		<td>文件名</td>
		<?php foreach($attachForm[TABID] as $input){?>
        <td><?=$input['title']?></td>
        <?php }?>
		<td>操作</td>
	</tr>
   <?php foreach($attachLists as $key=>$TrRow){?>
   <tr id="annex<?=$TrRow['annexid']?>">
   		<td><?=$key?></td>

<td align="center" valign="middle"><?=$TrRow['name']?></td>
        <?php foreach($TrRow['input'] as $input){?>
        <td><?=str_replace("{form}","oldannexs",$input['input']);?></td>
        <?php }?>
   		<td><?=$TrRow['action']?></td>
   </tr>
   <?php }?>
    <tr id="useannex">
    	<td colspan="<?=count($attachForm[TABID])+3?>"><span style="color:#CCCCCC">您有 <?=empty($total_annex)?"0":$total_annex?> 个已经上传的附件</span>   
        <a href="javascript:void(0)" rel="{type:'iframe',size:{w:800,h:500},url:'<?=BASEURI."file_manager/useattach"?>'}" class="Dialog">站内选择</a> 
        <a href="javascript:void(0)" rel="{type:'iframe',size:{w:600,h:400},url:'<?=BASEURI."file_upload/index/".$channel_id?>'}" class="Dialog">批量上传</a>
        <a href="javascript:void(0)" onclick="addAtachments()">添加地址</a>
        </td>
    </tr>
</table>
</div>
<div><input type="submit" name="sb" value="提交" class="submit" /></div>
<div class="adminform_bottom">
</div>
<script language="javascript">

function deleteannex(trid,annexid,channelid){
	$.get("<?=BASEURI?>model_content/deleteannex/"+channelid+"/"+annexid);
	$("#"+trid).remove();
	$("body").ajaxError(function(){
     window.location	=	"<?=BASEURI?>model_content/deleteannex/"+channelid+"/"+annexid;
	}); 
}
function updateAnnex(annexid,bool){
	if(bool){
		$("#name"+annexid).css('display','none');
		$("#newpath"+annexid).html("上传：<input type='file' name='newpaths"+annexid+"'>&nbsp;&nbsp;<a href='javascript:;' onclick='updateAnnex("+annexid+",false)'>取消</a>");
	}
	else{
		$("#name"+annexid).css('display','inline');
		$("#newpath"+annexid).html("[<a href=\"javascript:void(0)\" onclick=\"updateAnnex("+annexid+",true)\">修改</a>]");
	}
}
function updateAnnexthumb(annexid,bool){
	if(bool){
		$("#name"+annexid).css('display','none');
		$("#newthumb"+annexid).html("缩略图：<input type='file' name='newthumbs"+annexid+"'>&nbsp;&nbsp;<a href='javascript:;' onclick='updateAnnexthumb("+annexid+",false)'>取消</a>");
	}
	else{
		$("#name"+annexid).css('display','inline');
		$("#newthumb"+annexid).html("[<a href=\"javascript:;\" onclick=\"updateAnnexthumb("+annexid+",true)\">修改缩略图</a>]");
	}
}
function uploadAttachment(response){
	var path		=	response.get('temppath');
	var n			=	$("#paths").find('tr').length-1;
	var row			=	"<tr id='annex"+n+"'>";
	row				+=	"<td>"+n+"</td><td>"+base_name(path)+"</td>";
	<?php foreach($attachForm[TABID] as $input){?>
    row				+=  '<td><?=str_replace("{form}","annex",$input['input']);?></td>';
    <?php }?>
	row				+=	"<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>";
	row				+=	"</tr>";
	if($("#paths").html().indexOf(path)<=0&&path!='all'){
		$("#useannex").before(row);
	}
}

</script>
<script language="javascript">
//选择使用
function selectuse(path){
	var n		=	$("#paths").find('tr').length-1;
	var row		=	"<tr id='annex"+n+"'><td>"+n+"</td>";
	row			+=	"<td>"+base_name(path)+"</td>";
	<?php foreach($attachForm[TABID] as $input){?>
	row			+=  '<td><?=str_replace("{form}","annex",$input['input']);?></td>';
	<?php }?>
	row			+=	"<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>";
	if($("#paths").html().indexOf(path)<=0&&path!='all'){
		$("#useannex").before(row);
	}
	window.close();
}
//添加附件
function addAtachments(){
	var n		=	$("#paths").find('tr').length-1;
	var row		=	"<tr id='annex"+n+"'><td>"+n+"</td>";
	row			+=	"<td><input type='text' name='annex[path][]' value='' class='text'></td>";
	<?php foreach($attachForm[TABID] as $input){?>
	row			+=  '<td><?=str_replace("{form}","annex",$input['input']);?></td>';
	<?php }?>
	row			+=	"<td><a href='javascript:void(0)' onclick='$(\"#annex"+n+"\").remove();'><IMG SRC='<?=BASEURL?>public/admin/images/delete.png' border=0></a></td></tr>";
	$("#useannex").before(row);
	window.close();
}

</script>
