<%
include("language.html")
%>
<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
<%
if _SESSION["logined"] ~= nil then

local JsonDir = _GET["dir"] or ""
if JsonDir ~= nil and JsonDir ~= "" and string.find(JsonDir, "'") ~= nil then
	JsonDir = json.encode(json.decode(_GET["dir"]))
end
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Directory</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
a {text-decoration:none;}
a,a:visited {color:#000;background:inherit;}
img {border:0px;}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {margin:0;padding:0;font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {margin:0;padding:0;font:11px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
input,select,textarea{margin:4px;}
input,textarea{background-color:expression((this.disabled && this.disabled==true)?"#D4D0C8":"")}
td{line-height:20px;padding-left:3px;}

button{
border:none;background:none;padding:0;
margin:0;width:auto;overflow:visible;text-align:center;	
white-space:nowrap;height:24px;line-height:22px;
cursor:pointer;
color:#000;
margin-left:2px;
margin-top:2px;
}
button span, button em{
display:block;height:24px;line-height:22px;margin:0;
}	
button span{
padding-left:14px;
background:url("images/button_left.gif") no-repeat 0 0;
}
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 100% 0;
}
button:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
button span:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
.buttonhover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}

fieldset {  
    border-color: #999;  
    border-style: solid;  
    border-width: 1px;  
}
</style>

<script language="javascript" src="include/common.js"></script>
<script language="javascript" src="include/json.js"></script>
<script language="javascript">

var ajaxlock = false;

var xmlhttp,page,post;
xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

function ajaxRequest(pagename,poststring,method)
{
	if(ajaxlock == false)
	{	
		delete xmlhttp;
		xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

		ajaxlock = true;
		page = pagename;
		post = poststring;
		if(page != "")
			$("waitingdiv").style.display = "";

		if(method == "GET")
			xmlhttp.open("GET",page+".html"+post);
		else
			xmlhttp.open("POST",page+".html");

		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajaxResponse;
		if(method != "GET")
			xmlhttp.send(post);
		else
			xmlhttp.send("");
	}
}

function ajaxResponse()
{
	if (xmlhttp.readyState == 4)
	{
		ajaxlock = false;
		if (xmlhttp.status == 200)
		{
			try
			{
				switch(page)
				{
					case 'admin_chkdir':		chkdirResult();break;
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
			finally
			{
				$("waitingdiv").style.display = "none";
			}
		}
		else
		{
			$("waitingdiv").style.display = "none";
			alert("<%=LANG['error_ajax']%>");
		}
	}
}

function chkdirResult()
{
	var result = xmlhttp.responseText;
	if(result == "1")
	{
		try
		{
			var alias = trim($("alias").value);
			if(alias.length >= 128 || alias == "<<SUBDIR PERMISSION>>" || (alias != "/" && alias.search(/[\\\<\>\:\?\"\'\|\[\]\{\}\*]/i) != -1) )
			{
				alert("<%=LANG['str_invalid_alias']%>");
				return false;
			}

			if($("is_home_dir").checked == false && alias == "")
			{
				alert("<%=LANG['str_virtualpath_tip']%>");
				return;
			}
			var directory = new Object();
			directory.dir = $("dir").value;
			directory.dir = directory.dir.replace(/\\/g,'/');
			directory.alias = alias.replace(/\\/g,'/');
			directory.alias = directory.alias.replace("//","/");
			if(directory.alias != "/")
			{
				directory.alias = directory.alias.replace(/(\/*$)/g,"");
			}

			if(directory.alias == "/")
			{
				$("is_home_dir").checked = true;
			}

			directory.is_home_dir = $("is_home_dir").checked ? true:false;
			directory.fileread = $("fileread").checked ? true:false;
			directory.filewrite = $("filewrite").checked ? true:false;
			directory.fileappend = $("fileappend").checked ? true:false;
			directory.filedelete = $("filedelete").checked ? true:false;
			directory.dirlist = $("dirlist").checked ? true:false;
			directory.dirmake = $("dirmake").checked ? true:false;
			directory.dirdelete = $("dirdelete").checked ? true:false;
			directory.dirrename = $("dirrename").checked ? true:false;
			directory.filerename = $("filerename").checked ? true:false;
			directory.zipfile = $("zipfile").checked ? true:false;
			directory.unzipfile = $("unzipfile").checked ? true:false;
			top.closewindow(directory);
			directory = null;
		}
		catch(e){}
	}
	else
	{
		alert("<%=LANG['error_invalid_dir']%>");
	}
}

function chooseDirectory()
{
	showMessagebox("<%=LANG['str_choosedir']%>","<iframe src='admin_dir_selector.html' width=580 height=500 border=0 frameborder=0></iframe>",callback_return,580,500);
}

function callback_return(value)
{
	if(value != null)
		$("dir").value = value;

	if($("is_home_dir").checked)
		$("dir").focus();
	else
		$("alias").focus();
}

function addDirectory()
{
	if($("dir").value == "")
	{
		alert("<%=LANG['str_realpath_tip']%>");
		return;
	}
	ajaxRequest("admin_chkdir","dir="+encodeURIComponent($("dir").value));
}


function initDirectory()
{
	var directory = '<%=JsonDir%>';
	if(directory != "")
	{
		var dirObject = JSON.parse(directory);
		$("dir").value = dirObject["dir"];
		$("alias").value = dirObject["alias"];
		$("is_home_dir").checked = dirObject["is_home_dir"];
		$("fileread").checked = dirObject["fileread"];
		$("filewrite").checked = dirObject["filewrite"];
		$("fileappend").checked = dirObject["fileappend"];
		$("filedelete").checked = dirObject["filedelete"];
		$("dirlist").checked = dirObject["dirlist"];
		$("dirmake").checked = dirObject["dirmake"];
		$("dirdelete").checked = dirObject["dirdelete"];
		$("dirrename").checked = dirObject["dirrename"];
		$("filerename").checked = dirObject["filerename"];
		$("zipfile").checked = dirObject["zipfile"];
		$("unzipfile").checked = dirObject["unzipfile"];
		dirObject = null;

		if($("is_home_dir").checked)
		{
			$("alias").value = "/";
			$("alias").disabled = true;
			$("dir").focus();
		}
		else
		{
			$("alias").focus();
		}
	}
}

function switchHomedir()
{
	if($("is_home_dir").checked)
	{
		$("alias").value = "/";
		$("alias").disabled = true;
	}
	else
	{
		$("alias").value = "";
		$("alias").disabled = false;
		$("alias").focus();
	}
}

</script>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="background-color:#E7E6DA;">

<table cellSpacing="0" cellPadding="0" border="0" width="100%" style="margin-left:5px; margin-top:5px;">
<tr>
<td width="100"><%=LANG["str_realpath"]%>:</td>
<td><input id="dir" type="text" style="width:170px;"> <button type='submit' onclick='chooseDirectory();'><span><em><%=LANG["button_choose"]%></em></span></button></td>
</tr>
<tr>
<td><%=LANG["str_virtualpath"]%>:</td>
<td><input id="alias" type="text" value="<%if _GET["homedir"] == "1" then print("/") end%>" <%if _GET["homedir"] == "1" then print("disabled") end%> style="width:170px;"></td>
</tr>
<tr>
  <td colspan="2"><input id="is_home_dir" type="checkbox" onclick="switchHomedir();" <%if _GET["homedir"] == "1" then print("checked") end%> <%if _GET["virtualdir"] == "1" then print("disabled") end%> > <%=LANG["str_ishomedir"]%></td>
</tr>
<tr>
  <td colspan="2">
 	<table cellSpacing="0" cellPadding="0" border="0" width="98%"> 
	<tr>
	  <td width="46%">
	  <table cellSpacing="0" cellPadding="0" border="0" width="100%">
		<tr>
		  <td>
		  <fieldset><legend><%=LANG["str_file_access"]%></legend>
		  <input id="fileread" type="checkbox" checked> <%=LANG["str_access_read"]%><br>
		   <input id="filewrite" type="checkbox"> <%=LANG["str_access_write"]%><br>
			<input id="fileappend" type="checkbox"> <%=LANG["str_access_append"]%><br>
			 <input id="filedelete" type="checkbox"> <%=LANG["str_access_delete"]%><br>
			 <input id="filerename" type="checkbox"> <%=LANG["str_access_rename"]%><br>
		  </fieldset>
		</td>
		</tr>
	  </table>
	  </td>
	  <td width="54%">
	  <table cellSpacing="0" cellPadding="0" border="0" width="100%">
		<tr>
		  <td>
		  <fieldset><legend><%=LANG["str_dir_access"]%></legend>
		  <input id="dirlist" type="checkbox" checked> <%=LANG["str_access_list"]%><br>
		   <input id="dirmake" type="checkbox"> <%=LANG["str_access_create"]%><br>
			<input id="dirdelete" type="checkbox"> <%=LANG["str_access_delete"]%><br>
			<input id="dirrename" type="checkbox"> <%=LANG["str_access_rename"]%><br>
		  </fieldset>
		</td>
		</tr>
		<tr>
		  <td>
			 <input id="zipfile" type="checkbox"> <%=LANG["str_access_zip"]%> &nbsp;
			 <input id="unzipfile" type="checkbox"> <%=LANG["str_access_unzip"]%>
		</td>
		</tr>
	  </table>
	  </td>
	</tr>
	</table>	
  </td>
</tr>
<tr><td colspan="2" style="text-align:right; padding-right:10px;padding-top:20px;">
<button type='submit' onclick='addDirectory();'><span><em><%=LANG["button_submit"]%></em></span></button>&nbsp;
<button onclick='top.closewindow();'><span><em><%=LANG["button_cancel"]%></em></span></button>
</td></tr>
</table>

<div id="waitingdiv" style="position:absolute; z-index:100; top:0px; left:0px; width:100%; height:100%; background:#777; filter:alpha(opacity=60); -moz-opacity: 0.60; opacity:0.60; display:none;" align="center">
<div style="position:absolute; top:20%; left:30%; width:250px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["title_updating"]%></b></H2>
</div>
</div>

</body>
</html>

<script language="javascript">
initDirectory();

$("alias").onchange = function()
{
	if($("alias").value != "/")
		$("is_home_dir").checked = false;
	else
		$("is_home_dir").checked = true;
}

$("alias").onmouseover = function()
{
	$("alias").focus();
}
</script>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('"..LANG["session_expire"].."');top.location='admin_login.html';</script>")
end 
%>