<html>
<head>
 <title>编辑文件</title>
 <meta http-equiv='Pragma' content='no-cache' />
 <meta http-equiv=Content-Type content="text/html; charset=UTF-8" />
</head>
<body >

<!--Important-->
<!--div id='topdiv' style='width:100%;height:100%;position:absolute;top:0px;left:0px;overflow-y:scroll;overflow-x:hidden;padding:0px;margin:0px;border-width:0px;'-->
<div id='titledivtop' style='width:100%;margin:10px;display:block;'>
<div style="float:left;clear:left;"><span class=title>模板<?php echo $template_dir;?> 文件<?php echo $template_file;?></span></div><div style="float:right;clear:right;"><a href='?action=selectTemplate'>返回</a></div>
</div>

<div id='maindiv' style="clear:left;">
<div style="padding:3px;width:100%;overflow:hidden;">





<script>
function $(obj)
{
	return document.getElementById(obj);
}
/*
*#########################################
* PHPCMS File Manager
* Copyright (c) 2004-2007 Longbill.cn
* By Longbill ( http://www.longbill.cn )
* longbill.cn@gmail.com
*#########################################
*/
window.debug = 0;
function repon()
{
	var o = replacediv.style;
	o.display = (o.display == "none" )?"":"none";
}

function breakline(b)
{
	if (b)
	{
		$('txt_ln').style.width = "2px";
		var a=$('txt_main');
		a.style.wordWrap = "break-word";
	}
	else
	{
		$('txt_ln').style.width = "35px";
		var a=$('txt_main');
		a.style.wordWrap = "normal";
	}
}


var lg_strback='';
function str_undo()
{
	var str;
	if(lg_strback=='') alert('Cannot return');
	str=window.editform.content.innerText;
	window.editform.content.innerText=lg_strback;
	lg_strback=str;
}

function repit(mstr,sstr,tstr)
{
	var i;
	i=0;
	if(mstr==''||sstr=='')
		return '';
	while(1)
	{
		i=mstr.indexOf(sstr,i);
		if(i<0)break;
		mstr=mstr.replace(sstr,tstr);
		i+=tstr.length;
	}
	return mstr;
}

function str_replace()
{
	var i1,i2,str,strLeft,strRight,strMid;
	strLeft=window.editform.repLeft.innerText;
	strRight=window.editform.repRight.innerText;
	strMid=window.editform.repMid.innerText;
	str=window.editform.content.innerText;
	lg_strback=str;
	i1=0;
	i2=0;
	if(strLeft=='') return;

	if(strRight=='')
	{
		strMid=repit(strMid,'[$]',strLeft);
		str=repit(str,strLeft,strMid);
	}
	else
	while(1)
	{
		i1=str.indexOf(strLeft,i1);
		if(i1<0) break;
		i2=str.indexOf(strRight,i1+strLeft.length);
		if(i2<0) break;
		str1=str.substring(i1+strLeft.length,i2);
		str2=repit(strMid,'[$]',str1);
		str1=strLeft+str1+strRight;
		if(!window.editform.isRemove.checked)
		{
			str2=strLeft+str2;
			str=str.replace(str1,str2+strRight);
		}
		else str=str.replace(str1,str2);
		i1+=str2.length;
	}
	window.editform.content.innerText=str;
}


var ctrlon = false;

function editTab(a,obj)
{
	if (!a) a = window.event;
	var code, sel, tmp, r;
	var tabs='';
	a.returnValue = false;
	if (document.all)
	{
		sel = obj.document.selection.createRange(); 
		r = obj.createTextRange(); 
	}
	if (a.keyCode == 17)
	{
		window.ctrlon = true;
		return false;
	}
	switch (a.keyCode)
	{
		case (9) :
			if (document.all)
			{
				if (sel.getClientRects().length > 1)
				{
					code = sel.text;
					tmp = sel.duplicate();
					tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top);
					sel.setEndPoint('startToStart', tmp);
					sel.text = '\t'+sel.text.replace(/\r\n/g, '\r\t');
					code = code.replace(/\r\n/g, '\r\t');
					r.findText(code);
					r.select();
				}else
				{
					sel.text = '\t';
					sel.select();
				}
			}
			else	//firefox	
			{
				var orig_top = obj.scrollTop;
				var rangeStart = obj.selectionStart;
				var rangeEnd = rangeStart;
				var tempStr1 = obj.value.substring(0,rangeStart);
				tempStr1 += '\t';
 				var tempStr2 = obj.value.substring(rangeEnd);
				obj.value = tempStr1+ tempStr2;
				obj.selectionStart = rangeEnd+1;
				obj.selectionEnd  = obj.selectionStart;
				obj.scrollTop = orig_top;
				return false;
			}
			break;
		case (13) :
			if (document.all)
			{
				tmp = sel.duplicate();
				tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top);
				tmp.setEndPoint('endToEnd', sel);
				for (var i=0; tmp.text.match(/^[\t]+/g) && i<tmp.text.match(/^[\t]+/g)[0].length; i++) tabs += '\t';
				sel.text = '\r\n'+tabs;
				sel.select();
			}
			else // firefox
			{
				var orig_top = obj.scrollTop;
				var rangeStart = obj.selectionStart;
				var rangeEnd = rangeStart;
				var tempStr1 = obj.value.substring(0,rangeStart);
				var tabs = "";
				if(tempStr1.indexOf('\t') != -1)
				{
					var arr = tempStr1.split('\n');
					var ts = arr[arr.length-1];
					for (var i=0; ts.match(/^[\t]+/g) && i<ts.match(/^[\t]+/g)[0].length; i++) tabs += '\t';
				}
 				var tempStr2 = obj.value.substring(rangeEnd);
				obj.value = tempStr1+ "\r\n" + tabs+ tempStr2;
				obj.selectionStart = rangeEnd+tabs.length+1;
				obj.selectionEnd  = obj.selectionStart;
				obj.scrollTop = orig_top + parseInt(obj.style.lineHeight);
				return false;
			}
			break;
		case (83) :
			if (a.ctrlKey)
			{

				editform_submit();
				a.returnValue = false;
				return false;
			}
		default  :
			a.returnValue = true;
			break;
	}
	return true;
}


function $(obj)
{
	return document.getElementById(obj);
}

function show_ln()
{
	document.getElementById('txt_ln').scrollTop = parseInt(document.getElementById('txt_main').scrollTop);
}

function runme()
{
	var openwin=window.open("","_blank","");
	openwin.document.write($('txt_main').value);
}


function resize_text()
{
	var h = parseInt(document.body.clientHeight) - 150;
	$('txt_ln').style.height = h;
	$('txt_main').style.height = h;
}

function save_if_close(o)
{
	//document.editform.target = o.checked?'_self':'inwin';
	if (o.checked)
		document.cookie = "if_close=true;";
	else
		document.cookie = "if_close=false;";
}


function set_charset(charset)
{
	var url = window.location.toString();
	url.replace("charset=","");
	url += "&charset="+charset;
	window.location = url;
}

window.onload = function ()
{
	if (debug) alert('on load');
	$("loading").style.display = "none";
	//$('topdiv').style.width = document.body.offsetWidth;//window.screen.availWidth;
	if (!(document.all))
	{
		setInterval(show_ln,100);
	}
	document.body.onmousemove = show_ln;
	resize_text();
	window.onresize = resize_text;
}

</script>

<iframe name=inwin id=inwin src='' width=0px height=0px style="display:none"></iframe>

<form action='?action=saveTemplate' method=post target=inwin name=editform  onsubmit="return editform_submit()">
<input type=hidden name="template_dir" value="<?php echo $template_dir;?>" />
<input type=hidden name="template_file" value="<?php echo $template_file;?>" />

<table border=0 cellspacing=0 cellpadding=0 width=100% style="layout:fixed;">
 <tr>
  <td width=100% colspan=9 height=23 background=images/titleback.gif>&nbsp;&nbsp;&nbsp;
   <a href='javascript:repon();'>字符替换</a>   
   <font style='font-size:10pt;'>查找请按Ctrl+F</font> 
   <a href="javascript:runme();">本地预览</a> 
   <input type=checkbox onclick="breakline(this.checked);" name=autobreak>自动换行&nbsp; &nbsp; &nbsp;
  </td>
 </tr>	
 <tr id='replacediv' style='display:none'><td>
<!---字符串替换--->
<div style='background-color:lightblue;padding:10px;' >
 <textarea name="repLeft" id="repLeft" rows=3 cols=20></textarea><textarea name="repRight" id="repRight" style="display:none"></textarea>替换为<textarea name="repMid" id="repMid" rows=3 cols=20></textarea><br>
<input type="hidden" name="isRemove" id="isRemove" value="y" checked><input type="button" name="Submit322" value="开始替换" onClick="str_replace();">&nbsp;<input type="button" name="Submit3222" value="撤销替换" onClick="str_undo();"> <a href="javascript:repon()">关闭</a>
</div>
 </td>
 </tr>
 <tr>

  <td>
   <table width=100% border=0 cellspacing=0 cellpadding=0>
    <tr>
     <td>
      <textarea id='txt_ln' style='overflow:hidden;border:2px;border-right:0px;border-style:inset;padding-right:5px;text-align:right;scrolling:no;height:600px;font-family:verdana;font-size:12px;line-height:15px;background-color:#eeeeee;width:40px;padding:2px;' readonly><?php echo $lines;?></textarea>
     </td>
     <td width=100%>
      <textarea id='txt_main' name='content' onkeydown='return editTab(event,this)'   onscroll="show_ln()" onkeyup='if($("loading").style.display == "none") document.editform.sub_bt.disabled = false; if (event.keyCode == 17) window.ctrlon=false;'   style='word-wrap:normal;word-break: break-all;padding:2px;height:600px;border:2px;border-style:inset;overflow:auto;scrolling:yes;border-left:0px;font-family:verdana;font-size:12px;line-height:15px;width:100%;'><?php echo $content;?></textarea>
     </td>
    </tr>
   </table>

<div>
文件大小:<?php echo dealsize(filesize($filepath));?> &nbsp;
<input type=checkbox onclick="save_if_close(this)" checked id='if_close' name='if_close' /><label for='if_close' >保存后返回</label>&nbsp;<input type=submit name='sub_bt' value=保存  onclick="if (this.disabled) {this.disabled=false;}" />  <input type=reset value=还原 ><br>
</div>

</form>
<script>
var timer;
function save_suc(s)
{
	if (window.timer)
	{
		clearTimeout(timer);
		window.timer = null;
	}
	$('loading').innerHTML = s;
	if (document.editform.if_close.checked) alert(s);
	setTimeout('$("loading").style.display = "none"',1000);
	document.editform.sub_bt.value = '保存';
	document.editform.sub_bt.disabled = true;
	if (document.editform.if_close.checked)
	{
		//if (window.parent.location == window.self.location ) window.close();
		window.self.location = "?action=selectTemplate";
	}
}
function save_err(s)
{
	window.timer = null;
	inwin.window.location = "about:blank";
	$('loading').innerHTML = s;
	alert(s);
	setTimeout('$("loading").style.display = "none"',1000);
	document.editform.sub_bt.value = '保存';
	document.editform.sub_bt.disabled = false;
}

function editform_submit()
{
	if (window.timer)
	{
		clearTimeout(timer);
	}
	$('loading').innerHTML = '保存中...';
	$('loading').style.display = '';
	document.editform.sub_bt.value = '保存中...';
	document.editform.sub_bt.disabled = true;
	document.editform.submit();
	window.timer = setTimeout("save_err('连接超时!');",60*1000);
	setTimeout("if (window.timer) {document.editform.sub_bt.disabled = false;document.editform.sub_bt.value='保存';}",5*1000);
	return false;
}
if (debug) alert('check if close window after saving');
if (document.cookie.toString().indexOf('if_close=true') != -1)
{
	$('if_close').checked = true;
}
else if (document.cookie.toString().indexOf('if_close=false') != -1)
{
	$('if_close').checked = false;
}
if (debug) alert('page loaded');
</script>
  </td>
 </tr>
</table>







</div>
</div>
<div id='footer' style="width:100%;text-align:center;font-size:12px;color#333333;">
PHPCMS文件管理器 for O-Blog &copy;2005-2007 <a href="http://www.longbill.cn" target=_blank>Longbill.cn</a>
</div>

<!--/div-->

<!---Loading...--->
<div id='loading' style='position:absolute;overflow:hidden;top:0px;right:18px;width:70px;height:18px;color:#ffffff;z-index:9;background-color:#e45b50;font-family:宋体;font-size:12px;vertical-align:middle;padding:2px;'>Loading...</div>
