<%@ Import Namespace="HTCOMNET.Main" %>
<%@ Import Namespace="System.IO" %>
<%@ Page%>
<html>
<head>
<%Session(SK_LANGUAGE).SetPage("EDITFILE")%>
<title><%=Session(SK_LANGUAGE).GetText("FILE_EDIT")%></title>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Session(SK_CHARSET)%>">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<link rel="stylesheet" href="Scripts<%=JS_CSS_VERSION%>/Style.css" type="text/css">
</head>
<body leftmargin="5" topmargin="5" bgcolor="#F8F6E6">
<%
       
	If Session(SK_ROOT) = "" Then Response.Redirect("logoff.aspx")
	If Not Session(SK_CURRENT_FOLDER).CanModify Then Exit Sub
	
	Response.Expires = -1
	Response.CacheControl = "No-cache"
	' Here you can add you own Editor. 
	' "FilePath" variable stores full path to the file
	' or use Response.Redirect() for redirect to your own Text Editor
	' To change Editor's window size open Up.js file, find "function open_editor" and
	' set "mywidth" and "myheight" values.
		
	Dim FileName, FilePath as String
	FileName = DeleteDangerouseRoots(Request.QueryString("file"))
	FilePath = Session(SK_ROOT) & Session(SK_DIR) & SlForDir(Session(SK_DIR)) & filename
	' Uncomment the line below and HTTP Commander will redirect user to your own Text Editor
	' Response.Redirect("http://www.yousite.com/Youreditor/Default.asp?filetoedit=" & FilePath)
%>
   
<!--Default Editor. Begin--> 
				<%  
					Const ForReading = 1
					dim WasError as boolean=false
					Dim MyFile as FileInfo
					Dim FileContent as FileStream
					If Not File.Exists(filepath) Then
						Session(SK_ERROR_MESSAGE)= String.Format(Session(SK_LANGUAGE).GetText("COMMON", "FILE_NOT_FOUND"), filename) 
						WasError=true
					Else
						try 
							MyFile = new FileInfo(filepath)							
							FileInfo.Text = "<font class=""subactionsfont"">" & Session(SK_LANGUAGE).GetText("FILE") & ": <font color=""#0066CC"">" & filename & "</font><br>" & _
							 Session(SK_LANGUAGE).GetText("SIZE") & ": <font color=""#0066CC"">" & MyFile.Length & "&nbsp;" & Session(SK_LANGUAGE).GetText("BYTES") & "</font><br>" & Session(SK_LANGUAGE).GetText("DATE_LAST_MODIFIED") & ": <font color=""#0066CC"">" & MyFile.LastWriteTime.ToString & "</font><br></font>"
							try
								FileContent = new FileStream(filepath, FileMode.Open, FileAccess.Read)															
								Dim Content(MyFile.Length-1) as byte
								FileContent.Read(Content, 0, MyFile.Length)								
								TextArea.Text = "<textarea name=""textfield"" cols=""70"" rows=""18"">"	
								Dim FileEncoding as Encoding = GetEncodingForTextFile(Content)						
								Dim UTF8Content() as byte=Encoding.Convert(FileEncoding, Encoding.UTF8, Content)
								TextArea.Text &= Server.HtmlEncode(encoding.UTF8.GetString(UTF8Content))
								TextArea.Text &= "</textarea>"	
								Session(SK_EDIT_FILE_ENCODING)=	FileEncoding					
							catch ex As Exception
								Session(SK_ERROR_MESSAGE)=String.Format(Session(SK_LANGUAGE).GetText("DONT_HAVE_PERMISSIONS"), filename) & Session(SK_LANGUAGE).GetText("COMMON", "ERROR_DESCRIPTION") & ex.message
								WasError=true
							finally
								if not FileContent is Nothing then FileContent.Close()
							end try
						catch ex As Exception
							Session(SK_ERROR_MESSAGE)=String.Format(Session(SK_LANGUAGE).GetText("DONT_HAVE_PERMISSIONS"), filename) & Session(SK_LANGUAGE).GetText("COMMON", "ERROR_DESCRIPTION") & ex.message
							WasError=true
						end try
					End If
				%>
				<Asp:Literal Runat=server ID="FileInfo" Text="" />
				<p style="width:350;" class="info"><%=string.format(Session(SK_LANGUAGE).GetText("CAN_DAMAGE"),"<BR>")%></p>
				<%if Session(SK_ERROR_MESSAGE)<>"" then%>
					<p align="center"><font class="subactionsfont"><%=Session(SK_ERROR_MESSAGE)%></font></p>
				<%Session(SK_ERROR_MESSAGE)=""
				end if%>		
				<%if WasError=false then%>						
				<form name="form1" method="post" action="savefile.aspx">
				<table border="0" cellspacing="0" cellpadding="0">
				<tr> 
					<td height="25"> 
							<p align="center"> <span clAss="active"><a href="#" onclick="javAscript: if(document.form1.textfield.cols>3)document.form1.textfield.cols=document.form1.textfield.cols-3;" ><b><font size="5"> 
								<font size="4" color="#CC0000">-</font><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;</font></font></b></a></span><a clAss="rc" href="#" onclick="javaScript:document.form1.textfield.cols=document.form1.textfield.cols+10;" ><b><span clAss="active"><font size="4"> 
								<font color="#CC0000">+</font></font></span></b></a></p>
					</td>
					<td width="25" height="25">&nbsp;</td>
				</tr>
				<tr> 
					<td height="293"> 
						<p><font color="#FF6600">
							<Asp:Literal Runat=server ID="TextArea" Text="" />
						</font>
						</p>
					</td>
					<td width="25" height="293"> &nbsp;&nbsp;&nbsp;&nbsp; 
						<table border="0" cellspacing="0" cellpadding="0" align="right">
							<tr> 
							<td height="50"><a href="#" onClick="javaScript: document.form1.textfield.rows=document.form1.textfield.rows+10;" ><font size="5"><b><font size="4" color="#CC0000">+</font></b></font></a></td>
							</tr>
							<tr> 
							<td><a href="#" onClick="javaScript: if(document.form1.textfield.rows>3) document.form1.textfield.rows=document.form1.textfield.rows-3;"><b><font size="4" color="#CC0000">-</font></b></a></td>
							</tr>
						</table>
					</td>
				</tr>
				</table>
				<p>
				<font color="#FF6600"> &nbsp;&nbsp;&nbsp;&nbsp; 
					<input clAss="button" type="submit" name="Submit" value="   <%=Session(SK_LANGUAGE).GetText("SAVE")%>   ">
					<input clAss="button" type="reset" name="Submit2" value="   <%=Session(SK_LANGUAGE).GetText("UNDO_CHANGES")%>   ">
					<br>
					<br>
					</font> 
				</p>
				<input type="hidden" name="file" value="<%=filename%>">
				</form>
				<%end if%>
<!--Default Editor. End--> 

</body>
</html>