<%
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>SFV Directory</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
if _GET["domain"] ~= nil then
	local domain = _GET["domain"]
	local SfvDir = c_GetSfvDirList(domain)
		SfvDir = json.encode_s(SfvDir)
%>
<style type="text/css">
html, body {height: 100%;}
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":"")}

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


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

function addSfvDirSubmit()
{
	var domain = "<%=domain%>";
	var SfvDirString = urlEncode(JSON.stringify(SfvDirs));
	var enable_sfv = ($("enable_sfv").checked ? 1:0);
	var create_missing = ($("enable_create_missing").checked ? 1:0);
	var bad_file = $("bad_file").value;
	var create_progress = $("create_progress").value;
	var send_result = ($("enable_send_result").checked ? 1:0);
	ajaxRequest("admin_add_sfvdir","domain="+domain+"&sfvdir="+SfvDirString+"&enable_sfv="+enable_sfv+"&create_missing="+create_missing+"&bad_file="+bad_file+"&create_progress="+create_progress+"&send_result="+send_result+"&r="+Math.random());
}

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

function SfvDirInit()
{
	var SfvDir = '<%=SfvDir%>';
	if(SfvDir != "")
	{
		try
		{
			var SfvDirObject = JSON.parse(SfvDir);
			SfvDirs = (SfvDirObject != null ? SfvDirObject : new Array());
			AddSfvDir_updateview();
		}
		catch(e)
		{
			alert("<%=LANG['str_loadsfv_fail']%>");
		}
	}
}


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

function callback_return(value)
{
	top.$("SfvDir").focus();
	if(value != null)
		top.$("SfvDir").value = value;
}


function AddSfvDir()
{
	if(enable_sfv == false)
		return;

	showMessagebox("<%=LANG['str_add_sfvdir']%>","<br><table width='100%' border='0' cellpadding='2' cellspacing='3'><tr><td align='right'><input type='text' style='width:190px' id='SfvDir'></td><td align='left'><button id='btn_directory' onclick='chooseDirectory();'><span><em><%=LANG['button_choose']%></em></span></button></td></tr><tr><td colspan=2 height=50>&nbsp;</td></tr><tr><td colspan=2><button id='btn_submit' type='submit' onclick='return AddSfvDir_submit()'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",null,340,180);
	top.$("SfvDir").focus();

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

function AddSfvDir_updateview()
{
	var htmltext = "<table id='listtable2' width='100%' border='0' cellpadding='2' cellspacing='0' style='table-layout:fixed;'>";
	for(var i=0;i<SfvDirs.length;i++)
	{
		htmltext += "<tr class='listtr01' onmouseup='do_list_click2(this);'><td f_id='"+i+"' height=20>"+SfvDirs[i].dir+"</td></tr>";
	}
	htmltext += "</table>";
	clear("listview_div2");
	write("listview_div2",htmltext);
	selectedRow = null;
	lastsortcol = -1;
}

function AddSfvDir_submit()
{
	var SfvDir = htmldecode(top.$("SfvDir").value);
	if(SfvDir.length == 0 )
	{
		alert("<%=LANG['str_invalid_dir']%>");
		top.$("SfvDir").focus();
		return;
	}
	var obj = new Object();
	obj.dir = SfvDir.replace(/\\/g,'/');
	SfvDirs.push(obj);
	obj = null;
	AddSfvDir_updateview();
	top.closewindow();
}

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

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

	return false;
}

function ModifySfvDir()
{
	if(enable_sfv == false)
		return;

	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}
	var f_id = parseInt(selectedRow.cells[0].getAttribute("f_id"));
	var f_dir = SfvDirs[f_id].dir;
	showMessagebox("<%=LANG['str_modify_sfvdir']%>","<br><table width='100%' border='0' cellpadding='2' cellspacing='3'><tr><td align='right'><input type='hidden' id='SfvDir_id' value='"+f_id+"'><input type='text' style='width:190px' id='SfvDir' value='"+f_dir+"'></td><td align='left'><button id='btn_directory' onclick='chooseDirectory();'><span><em><%=LANG['button_choose']%></em></span></button></td></tr><tr><td colspan=2 height=50>&nbsp;</td></tr><tr><td colspan=2><button id='btn_submit' type='submit' onclick='return ModifySfvDir_submit()'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",null,340,180);
	top.$("SfvDir").focus();

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

function ModifySfvDir_submit()
{
	var f_id = parseInt(htmldecode(top.$("SfvDir_id").value));
	var SfvDir = htmldecode(top.$("SfvDir").value);
	if(SfvDir.length == 0 )
	{
		alert("<%=LANG['str_invalid_dir']%>");
		top.$("SfvDir").focus();
		return;
	}
	SfvDirs[f_id].dir = SfvDir.replace(/\\/g,'/');
	AddSfvDir_updateview();
	top.closewindow();
}

function DeleteSfvDir()
{
	if(enable_sfv == false)
		return;

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

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

function UpSfvDir()
{
	if(enable_sfv == false)
		return;

	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 = SfvDirs[f_id-1]; 
		SfvDirs[f_id-1] = SfvDirs[f_id];
		SfvDirs[f_id] = temp;
	}

	AddSfvDir_updateview();

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

function DownSfvDir()
{
	if(enable_sfv == false)
		return;

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

	AddSfvDir_updateview();

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


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

<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding:5px;">
<tr><td>
<input id="enable_sfv" type="checkbox" onclick="checkSfv();" <%if c_GetOptionInt(domain,DOPTION_ENABLE_SFVCHECK_INT) == 1 then print("checked") end%> ><%=LANG["str_enable_sfv"]%>
</td></tr>
<tr><td id="checkbox_group">
<table width="100%" border="0" cellpadding="0" cellspacing="5" style="table-layout:fixed;">
<tr>
<td colspan="2">
<%=LANG["str_sfvdir_tip"]%>
</td></tr>
<tr>
<td colspan="2">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #919B9C;">
	<tr>
	<td class="listhead" onmouseover="className='listhead2';" onmouseout="className='listhead';"><%=LANG["title_sfvdir"]%></td>
	</tr>
	<tr>
	<td>
	<div id="listview_div2" style="height:155px; width:100%; background-color:#FFF; overflow:auto; overflow-x:hidden;">
	<table id="listtable2" width="100%" border="0" cellpadding="2" cellspacing="0" style="table-layout:fixed;"></table>
	<div>
	</td></tr>
</table>
</td></tr>
<tr>
<td colspan="2" id="button_group">
<button onclick="AddSfvDir();"><span><em><%=LANG["button_addsfvdir"]%></em></span></button><button onclick="ModifySfvDir();"><span><em><%=LANG["button_modify"]%></em></span></button><button onclick="DeleteSfvDir();"><span><em><%=LANG["button_delete"]%></em></span></button><button onclick="UpSfvDir();"><span><em><%=LANG["button_up"]%></em></span></button><button onclick="DownSfvDir();"><span><em><%=LANG["button_down"]%></em></span></button>
</td></tr>
<tr>
<td colspan="2">
<input id="enable_create_missing" type="checkbox" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_CREATMISSING_INT) == 1 then print("checked") end%>><%=LANG["str_create_file"]%>
</td></tr>
<tr>
<td colspan="2">
<input id="enable_send_result" type="checkbox" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_SENDRESULT_INT) == 1 then print("checked") end%>><%=LANG["str_send_result"]%>
</td></tr>
<tr>
<td colspan="2">
&nbsp;&nbsp;<%=LANG["str_badfile"]%>:
<select id="bad_file">
<option value="0" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_BADFILE_INT) == 0 then print("selected") end%>><%=LANG["str_badfile1"]%></option>
<option value="1" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_BADFILE_INT) == 1 then print("selected") end%>><%=LANG["str_badfile2"]%></option>
<option value="2" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_BADFILE_INT) == 2 then print("selected") end%>><%=LANG["str_badfile3"]%></option>
</select>
</td></tr>
<tr>
<td colspan="2">
&nbsp;&nbsp;<%=LANG["str_checkprogress"]%>:
<select id="create_progress">
<option value="0" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_PROGRESS_INT) == 0 then print("selected") end%>><%=LANG["str_checkprogress1"]%></option>
<option value="1" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_PROGRESS_INT) == 1 then print("selected") end%>><%=LANG["str_checkprogress2"]%></option>
<option value="2" <%if c_GetOptionInt(domain,DOPTION_SFVCHECK_PROGRESS_INT) == 2 then print("selected") end%>><%=LANG["str_checkprogress3"]%></option>
</select>
</td></tr>
</table>
</td></tr>
</table>

<div style="margin-top:10px;width:100%;text-align:center;">
<button type='submit' onclick='addSfvDirSubmit();'><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">
function checkSfv()
{
	if($("enable_sfv").checked)
	{
		$("listview_div2").disabled = false;
		$("button_group").disabled = false;
		$("checkbox_group").disabled = false;
		$("bad_file").disabled = false;
		$("create_progress").disabled = false;
		enable_sfv = true;
	}
	else
	{
		$("listview_div2").disabled = true;
		$("button_group").disabled = true;
		$("checkbox_group").disabled = true;
		$("bad_file").disabled = true;
		$("create_progress").disabled = true;
		enable_sfv = false;
	}
}

SfvDirInit();
checkSfv();

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