<%
include("language.html")
if _SESSION["logined"] ~= nil then
%>
<!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>Domain File Mask</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
if _GET["domain"] ~= nil then
	local FileMask = c_GetFileMaskList(_GET["domain"])
		FileMask = json.encode_s(FileMask)
%>
<style type="text/css">
html, body {height: 100%;margin:0;padding:0;}
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 {font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {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;}

button{
border:none;background:none;padding:0;
margin:0;width:auto;overflow:visible;text-align:center;
white-space:nowrap;height:24px;line-height:24px;
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{
font-size:8pt;
padding-left:12px;
background:url("images/button_left.gif") no-repeat 0 0;
}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 101% 0;
}
<%else%>
button em{
font-style:normal;padding-right:10px;
background:url("images/button.gif") no-repeat 100% 0;
}
<%end%>
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;
}


.listhead
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #E1E2E3;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EFEFEF; overflow:hidden; height:18px;
}

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #FCC247;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #FAF9F4; overflow:hidden; height:18px;
}

.listtr01
{
		background-color: #FFFFFF;
		text-align: left;
		padding: 3px;
}

.listtr02
{
		background-color: #3366CC;
		color: #FFF;
		text-align: left;
		padding: 3px;
}

.resizeblock{
	background-color:transparent;
	width:2px;
	float:right;
	cursor:e-resize;
}

</style>

<script language="javascript" src="include/common.js"></script>
<script language="javascript" src="include/json.js"></script>
<script language="javascript">
var ajaxlock = false;
var selectedRow = null;
var lastObj = null;
var lastObjIndex = -1;

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(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_add_filemask': addFileMask_result();break;
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
		}
		else
		{
			alert("<%=LANG['error_ajax']%>");
		}
	}
}


var filemasks = new Array();
var last_dir_id = null;

function addFileMaskSubmit()
{
	var domain = $("domain").value;
	var FileMaskString = urlEncode(JSON.stringify(filemasks));
	ajaxRequest("admin_add_filemask","domain="+domain+"&filemask="+FileMaskString);
}

function addFileMask_result()
{
	top.closewindow(1);
}

function FileMaskInit()
{
	var FileMask = '<%=FileMask%>';
	if(FileMask != "")
	{
		try
		{
			var FileMaskObject = JSON.parse(FileMask);
			filemasks = (FileMaskObject != null ? FileMaskObject : new Array());
			AddBlockfile_updateview();
		}
		catch(e)
		{
			alert("<%=LANG['str_loadfilemask_fail']%>");
		}
	}
}



function AddBlockfile()
{
	showMessagebox("<%=LANG['str_addblockfile']%>","<span style='padding:5px;'><%=LANG['str_filemask_tip']%><span><br><br><%=LANG['str_filemask']%>: <input type='text' style='width:190px' id='blockfilename'><br><input type='radio' name='radio' id='radio_deny' checked><%=LANG['str_denied']%> <input type='radio' name='radio' id='radio_allow'><%=LANG['str_allowed']%><br><br><br><button id='btn_submit' type='submit' onclick='return AddBlockfile_submit()'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button>",null,340,190);
	top.$("blockfilename").focus();

	top.$("btn_submit").onclick = function(){return AddBlockfile_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};
}

function AddBlockfile_updateview()
{
	var htmltext = "<table id='listtable3' width='100%' border='0' cellpadding='2' cellspacing='0' style='table-layout:fixed;'><tbody>";
	for(var i=0;i<filemasks.length;i++)
	{
		var refuse = filemasks[i].refuse ? "<font color='red'>Deny</font>":"<font color='green'>Allow</font>";
		htmltext += "<tr class='listtr01' onmouseup='do_list_click3(this);'><td width='70%' f_id='"+i+"'>"+filemasks[i].filename+"</td><td width='30%'>"+refuse+"</td></tr>";
	}
	htmltext += "</tbody></table>";
	clear("listview_div3");
	write("listview_div3",htmltext);
	selectedRow = null;
	lastsortcol = -1;
}

function AddBlockfile_submit()
{
	var blockfilename = htmldecode(top.$("blockfilename").value);
	if(blockfilename.length == 0 || blockfilename.search(/[\<\>\"\']/i) != -1)
	{
		alert("<%=LANG['str_invalid_filename']%>");
		top.$("blockfilename").focus();
		return;
	}
	var mask = new Object();
	mask.filename = blockfilename;
	mask.refuse = top.$("radio_deny").checked ? true:false;
	filemasks.push(mask);
	mask = null;
	AddBlockfile_updateview();
	top.closewindow();
}

function do_list_click3(obj)
{
	var row_index = obj.rowIndex;
	if(selectedRow != $("listtable3").rows[row_index])
	{
		if(lastObj != null)
			lastObj.className = "listtr01";

		selectedRow = $("listtable3").rows[row_index];
		obj.className = "listtr02";
		lastObj = obj;
		try{
			lastObjIndex = parseInt(selectedRow.cells[0].innerHTML);
		}catch(e){
			lastObjIndex = -1;
		}
	}
	else
	{
		ModifyBlockfile();
	}

	return false;
}

function ModifyBlockfile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}
	var f_id = parseInt(selectedRow.cells[0].getAttribute("f_id"));
	var f_filename = filemasks[f_id].filename;
	var f_deny = filemasks[f_id].refuse ? "checked":"";
	var f_allow = filemasks[f_id].refuse ? "":"checked";
	showMessagebox("<%=LANG['str_modifyblockfile']%>","<span style='padding:5px;'><%=LANG['str_filemask_tip']%><span><br><input type='hidden' id='blockfileid' value='"+f_id+"'><br><%=LANG['str_filemask']%>: <input type='text' style='width:190px' id='blockfilename' value='"+f_filename+"'><br><input type='radio' name='radio' id='radio_deny' "+f_deny+"><%=LANG['str_denied']%> <input type='radio' name='radio' id='radio_allow' "+f_allow+"><%=LANG['str_allowed']%><br><br><br><button id='btn_submit' type='submit' onclick='return ModifyBlockfile_submit()'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button>",null,340,190);
	top.$("blockfilename").focus();

	top.$("btn_submit").onclick = function(){return ModifyBlockfile_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};
}

function ModifyBlockfile_submit()
{
	var f_id = parseInt(htmldecode(top.$("blockfileid").value));
	var blockfilename = htmldecode(top.$("blockfilename").value);
	if(blockfilename.length == 0 || blockfilename.search(/[\<\>\"\']/i) != -1)
	{
		alert("<%=LANG['str_invalid_filename']%>");
		top.$("blockfilename").focus();
		return;
	}
	filemasks[f_id].filename = blockfilename;
	filemasks[f_id].refuse = top.$("radio_deny").checked ? true:false;
	AddBlockfile_updateview();
	top.closewindow();
}

function DeleteBlockfile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}

	var f_id = parseInt(selectedRow.cells[0].getAttribute("f_id"));
	filemasks.splice(f_id,1);
	AddBlockfile_updateview();
}

function UpBlockfile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}
	var f_id = parseInt(selectedRow.cells[0].getAttribute("f_id"));
	if(f_id > 0)
	{
		var temp = filemasks[f_id-1]; 
		filemasks[f_id-1] = filemasks[f_id];
		filemasks[f_id] = temp;
	}

	AddBlockfile_updateview();

	if(f_id > 0)
	{
		for(var i=0; i < filemasks.length; i++)
		{
			var tempID = parseInt($("listtable3").rows[i].cells[0].getAttribute("f_id"));
			if(tempID == f_id-1)
			{
				$("listtable3").rows[i].className = "listtr02";
				lastObj = $("listtable3").rows[i];
				selectedRow = lastObj;
			}
		}
	}
}

function DownBlockfile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}
	var f_id = parseInt(selectedRow.cells[0].getAttribute("f_id"));
	if(f_id < filemasks.length-1)
	{
		var temp = filemasks[f_id+1]; 
		filemasks[f_id+1] = filemasks[f_id];
		filemasks[f_id] = temp;
	}

	AddBlockfile_updateview();

	if(f_id < filemasks.length-1)
	{
		for(var i=0; i < filemasks.length; i++)
		{
			var tempID = parseInt($("listtable3").rows[i].cells[0].getAttribute("f_id"));
			if(tempID == f_id+1)
			{
				$("listtable3").rows[i].className = "listtr02";
				lastObj = $("listtable3").rows[i];
				selectedRow = lastObj;
			}
		}
	}
}

</script>
</head>
<body style="background-color:#E6E6E6;">

<div style="height:290px; width:100%; overflow:auto; overflow-x:hidden; padding-left:4px;">
	<input id="domain" type="hidden" value="<%=_GET["domain"]%>">
	<table id="listhead3" width="98%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
	<tr>
	<td colspan="2">
		<button onclick="AddBlockfile();"><span><em><%=LANG["button_addblockfile"]%></em></span></button><button onclick="ModifyBlockfile();"><span><em><%=LANG["button_modify"]%></em></span></button><button onclick="DeleteBlockfile();"><span><em><%=LANG["button_delete"]%></em></span></button><button onclick="UpBlockfile();"><span><em><%=LANG["button_up"]%></em></span></button><button onclick="DownBlockfile();"><span><em><%=LANG["button_down"]%></em></span></button>			
	</td>
	</tr>

	<tr>
	<td colspan="2">
	<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #919B9C;">
		<tr>
		<td class="listhead" width="70%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable3', 0);"><%=LANG["title_file"]%></td>
		<td class="listhead" width="30%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable3', 1);"><%=LANG["title_allowdeny"]%></td>
		</tr>
		<tr>
		<td colspan="2">
		<div id="listview_div3" style="height:220px; width:100%; background-color:#FFF; overflow:auto; overflow-x:hidden;">
		<table id="listtable3" width="100%" border="0" cellpadding="2" cellspacing="0" style="table-layout:fixed;"></table>
		</div>
		</td></tr>
	</table>
	</td></tr>

	</table>
</div>

<div style="margin-top:10px;width:100%;text-align:center;">
<button type='submit' onclick='addFileMaskSubmit();'><span><em><%=LANG["button_submit"]%></em></span></button>&nbsp;
<button onclick='top.closewindow();'><span><em><%=LANG["button_cancel"]%></em></span></button>
</div>

<script type="text/javascript">
FileMaskInit();

</script>
</body>
</html>

<% end %>

<% 
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 
%>

<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>