<%
include("language.html")
if _SESSION["logined"] ~= nil then

local domain = _GET["domain"] or _POST["domain"]
local strBaseURL = c_GetOptionStr(domain, DOPTION_WEBLINK_URL)

if strBaseURL == "" then
	local listenerlist = c_GetListenerList(domain)
	for _,listener in pairs(listenerlist) do
		if type(listener) == "table" and listener["Is_Listening"] == true then
			if listener["Type"] == "3" or listener["Type"] == "4" then
				local strPort = ":"..listener["Port"]
				if listener["Type"] == "3" then
					strBaseURL = "http://"
					if listener["Port"] == "80" then
						strPort = ""
					end
				else
					strBaseURL = "https://"
					if listener["Port"] == "443" then
						strPort = ""
					end
				end

				if listener["Ip_Address"] == "*" then
					strBaseURL = strBaseURL.."127.0.0.1"
				else
					strBaseURL = strBaseURL..listener["Ip_Address"]
				end
				
				strBaseURL = strBaseURL..strPort.."/"
				break
			end
		end
	end
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>Log List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
html, body {height: 100%;}
<%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:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
img {border:0px;}

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;
}
span{
	vertical-align:middle;
}


.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:22px;
}

.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:22px;
}

.listhead3
{
		border-top: 1px solid white; border-right: 1px solid white; 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:22px;
}

.listhead4
{
		border-top: 1px solid white; border-right: 1px solid white; 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:22px;
}

.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;
}

.fixedwidth
{
	word-wrap: break-word;
	word-break: normal;
}

</style>

<!–[if IE 6]>
<link rel="stylesheet" type="text/css" href="css/ie6.css" />
<![endif]–>

<script language="javascript" src="include/common.js"></script>
<script language="javascript">
var domain = "<%=domain%>";
var totalrecords = 0;
var totalpages = 0;
var nowpage = 1;
var ajaxlock = false;
var selectedRow = null;
var lastObj = null;
var lastObjIndex = -1;
var filters = "";
var f_id = "";
var sel_id = ">=";
var f_protocol = "";
var f_action = "";
var f_size = "";
var sel_size = ">=";
var f_username = "";
var sel_username = "=";
var f_filename = "";
var sel_filename = "=";
var f_ip = "";
var sel_ip = "=";
var f_starttime = "";
var f_endtime = "";
var strSQLFilter = "";
var strOrderBy = "order by f_id desc";


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_get_loglist':	
					{
						loglist_result();
						break;
					}
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
			finally
			{
				$("waitingdiv").style.display = "none";
			}
		}
		else
		{
			$("waitingdiv").style.display = "none";
			alert("<%=LANG['error_ajax']%>");
		}
	}
}

function getloglistpage(page)
{
	ajaxRequest("admin_get_loglist","domain="+domain+"&page="+page+"&filters="+encodeURIComponent(strSQLFilter)+"&f_username="+encodeURIComponent(f_username)+"&f_filename="+encodeURIComponent(f_filename)+"&f_ip="+encodeURIComponent(f_ip)+"&f_starttime="+encodeURIComponent(f_starttime)+"&f_endtime="+encodeURIComponent(f_endtime)+"&orderby="+encodeURIComponent(strOrderBy)+"&r=" + Math.random() );
}

function loglist_result()
{
	$("waitingdiv").style.display = "";
	try
	{
		var headcell = $("listhead").rows[0].cells;
		var htmltext = "<table id='listtable' width='100%' border='0' cellpadding='2' cellspacing='0' style='table-layout:fixed;'><thead><tr height='0'><td width='"+headcell[0].width+"'></td><td width='"+headcell[1].width+"'></td><td width='"+headcell[2].width+"'></td><td width='"+headcell[3].width+"'></td><td width='"+headcell[4].width+"'></td><td width='"+headcell[5].width+"'><td width='"+headcell[6].width+"'></td><td width='"+headcell[7].width+"'></td></tr></thead><tbody id='maintable'>";

		var logArray = xmlhttp.responseText.split("\n");
		var pages = parseInt(logArray[0]);

		if(totalpages != pages)
		{


			$("page_selector").options.length=0;

			if(pages > 0)
			{
				try
				{
					var fragment = document.createDocumentFragment();
					for (var n=1; n<=pages; n++)
					{
						if(pages <= 10000 && (n < 50 || n > pages-50  || n % 50 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
						else if(pages > 10000 && pages <= 20000 && (n < 50 || n > pages-50 || n % 100 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
						else if(pages > 20000 && pages <= 50000 && (n < 50 || n > pages-50 || n % 200 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
						else if(pages > 50000 && pages <= 200000 && (n < 50 || n > pages-50 || n % 1000 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
						else if(pages > 200000 && pages <= 1000000 && (n < 50 || n > pages-50 || n % 5000 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
						else if(pages > 1000000 && (n < 50 || n > pages-50 || n % 50000 == 0))
						{
							var option = document.createElement("option");
							option.value = n;
							option.innerText = n;
							fragment.appendChild(option);
						}
					}

					$("page_selector").appendChild(fragment);
				}
				catch(e)
				{
					for (var n=1; n<=pages; n++)
						$("page_selector").options[n-1] = new Option(n, n);
				}
			}

			totalpages = pages;
			$("page_number").innerHTML = nowpage + " / " + totalpages;
		}

		for(var i=1;i<logArray.length;i++)
		{
			if(logArray[i] != "" && logArray[i] != " ")
			{
				var tempVal = logArray[i];
				var fieldArray = tempVal.split("||");
				var filesize = fieldArray[9] == "0" ? "":fileSize(fieldArray[9]);
				var protocol = "FTP";
				if(fieldArray[4] == "1") protocol = "SFTP";
				if(fieldArray[4] == "2") protocol = "HTTP";
				var type = "Login";
				if(fieldArray[3] == "3") 
					type = "Create Dir";
				else if(fieldArray[3] == "4") 
					type = "Delete Dir";
				else if(fieldArray[3] == "7") 
					type = "Delete";
				else if(fieldArray[3] == "8") 
					type = "Download";
				else if(fieldArray[3] == "9") 
					type = "Rename";
				else if(fieldArray[3] == "10") 
					type = "Upload";
				else if(fieldArray[3] == "30") 
					type = "Change Pass";
				else if(fieldArray[3] == "31") 
					type = "Copy Files";

				var filename = txt2html(fieldArray[6]);
				if(fieldArray[3] == "3" || fieldArray[3] == "4" || fieldArray[3] == "9" || fieldArray[3] == "31") 
				{
					filename = txt2html(fieldArray[7]);
				}
				var weblink = "";
				var username = txt2html(fieldArray[2]);
				if(fieldArray[2] == "<WEBLINK>" || fieldArray[2] == "<UPLOADLINK>")
				{
					weblink = txt2html(fieldArray[11]);
					if(weblink != "" && weblink != "/")
						username = txt2html(fieldArray[2])+"\n"+weblink
				}
				htmltext += "<tr class='listtr01' onmouseup='do_list_click(this);'><td>"+fieldArray[0]+"</td><td>"+protocol+"</td><td>"+type+"</td><td title='"+username+"' weblink='"+weblink+"'>"+txt2html(fieldArray[2])+"</td><td>"+fieldArray[5]+"</td><td class='fixedwidth' title='"+(type == "Rename" || type == "Copy Files" ? txt2html(fieldArray[8]+" --> "+fieldArray[7]) : txt2html(fieldArray[7]))+"'>"+filename+"</td><td align='right'>"+filesize+"</td><td title='"+fieldArray[12]+"'>"+fieldArray[12]+"</td><td></td></tr>";
			}
		}
		htmltext += "</tbody></table>";
		clear("listview_div");
		write("listview_div",htmltext);
		selectedRow = null;
	}
	catch(e){}
	$("waitingdiv").style.display = "none";
}

function do_list_click(obj)
{
	var row_index = obj.rowIndex-1;
	if(selectedRow != $("maintable").rows[row_index])
	{
		if(lastObj != null)
			lastObj.className = "listtr01";

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

	return false;
}

function DoRefresh()
{
	getloglistpage(nowpage);
}

function DoSearch()
{
	strOrderBy = "order by f_id desc";
	nowpage = 1;
	getloglistpage(nowpage);
	$("page_selector").value = 1;

	if(lastArrow != null)
		lastArrow.style.backgroundImage="";
}


function selectTime()
{
	var timeArray = ["", ""];
	if(top.$("f_starttime").value != "")
		timeArray = top.$("f_starttime").value.split(" ");
	var frametag = new Date().getTime();
	showMessagebox("<%=LANG['str_selecttime']%>","<iframe src='admin_time_selector.html?mydate="+timeArray[0]+"&mytime="+timeArray[1]+"&seeds=" + Math.random() +"' width=280 height=320 border=0 frameborder=0 id='modify"+frametag+"'></iframe>",selectTime_callback,280,320);
}

function selectTime_callback(str)
{
	if(str != "" && str != null)
	{
		top.$("f_starttime").value = str;
		top.$("f_username").focus();
	}
}

function clearTime()
{
	top.$("f_starttime").value = "";
	f_starttime = "";
}

function selectEndTime()
{
	var timeArray = ["", ""];
	if(top.$("f_endtime").value != "")
		timeArray = top.$("f_endtime").value.split(" ");
	var frametag = new Date().getTime();
	showMessagebox("<%=LANG['str_selecttime']%>","<iframe src='admin_time_selector.html?mydate="+timeArray[0]+"&mytime="+timeArray[1]+"&seeds=" + Math.random() +"' width=280 height=320 border=0 frameborder=0 id='modify"+frametag+"'></iframe>",selectEndTime_callback,280,320);
}

function selectEndTime_callback(str)
{
	if(str != "" && str != null)
	{
		top.$("f_endtime").value = str;
		top.$("f_username").focus();
	}
}

function clearTime2()
{
	top.$("f_endtime").value = "";
	f_endtime = "";
}

function AddFilters()
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then
	print("alert('"..RESULT_STR[-1].."'); return false;")
end
%>
	showMessagebox("<%=LANG['title_add_filters']%>","<br><table width='100%' border='0' cellpadding='0' cellspacing='0' style='padding-left:10px;'><tr><td width=120 align='right'><%=LANG['title_id']%>:</td><td align='left'><select id='sel_id' style='width:80px;'><option value='>=' "+(sel_id==">="?"selected":"")+">>=</option><option value='=' "+(sel_id=="="?"selected":"")+">=</option><option value='<=' "+(sel_id=="<="?"selected":"")+"><=</option></select>&nbsp;&nbsp;<input type='text' style='width:140px' id='f_id' value='"+f_id+"'></td></tr><tr><td height=30 align='right'><%=LANG['title_protocol']%>:</td><td align='left'><select id='f_protocol' style='width:180px;'><option value='' "+(f_protocol==""?"selected":"")+">-- Any --</option><option value='0' "+(f_protocol=="0"?"selected":"")+">FTP</option><option value='1' "+(f_protocol=="1"?"selected":"")+">SFTP</option><option value='2'  "+(f_protocol=="2"?"selected":"")+">HTTP</option></select></td></tr><tr><td height=30 align='right'><%=LANG['str_action']%>:</td><td align='left'><select id='f_action' style='width:180px;'><option value='' "+(f_action==""?"selected":"")+">-- Any --</option><option value='0' "+(f_action=="0"?"selected":"")+">Login</option><option value='3' "+(f_action=="3"?"selected":"")+">Create Dir</option><option value='4' "+(f_action=="4"?"selected":"")+">Delete Dir</option><option value='7' "+(f_action=="7"?"selected":"")+">Delete File</option><option value='8' "+(f_action=="8"?"selected":"")+">Download</option><option value='9' "+(f_action=="9"?"selected":"")+">Rename</option><option value='10' "+(f_action=="10"?"selected":"")+">Upload</option><option value='30' "+(f_action=="30"?"selected":"")+">Change Pass</option><option value='31' "+(f_action=="31"?"selected":"")+">Copy Files</option></select></td></tr><tr><td height=30 align='right'><%=LANG['title_username']%>:</td><td align='left'><select id='sel_username' style='width:80px;'><option value='=' "+(sel_username=="="?"selected":"")+">=</option><option value='LIKE'  "+(sel_username=="LIKE"?"selected":"")+">LIKE</option></select>&nbsp;&nbsp;<input type='text' style='width:140px' id='f_username' value='"+f_username+"'></td></tr><tr><td height=30 align='right'><%=LANG['str_filename']%>:</td><td align='left'><select id='sel_filename' style='width:80px;'><option value='='  "+(sel_filename=="="?"selected":"")+">=</option><option value='LIKE' "+(sel_filename=="LIKE"?"selected":"")+">LIKE</option></select>&nbsp;&nbsp;<input type='text' style='width:140px' id='f_filename' value='"+f_filename+"'></td></tr><tr><td height=30 align='right'><%=LANG['title_ip']%>:</td><td align='left'><select id='sel_ip' style='width:80px;'><option value='=' "+(sel_ip=="="?"selected":"")+">=</option><option value='LIKE' "+(sel_ip=="LIKE"?"selected":"")+">LIKE</option></select>&nbsp;&nbsp;<input type='text' style='width:140px' id='f_ip' value='"+f_ip+"'></td></tr><tr><td height=30 align='right'><%=LANG['title_size']%>:</td><td align='left'><select id='sel_size' style='width:80px;'><option value='>=' "+(sel_size==">="?"selected":"")+">>=</option><option value='=' "+(sel_size=="="?"selected":"")+">=</option><option value='<=' "+(sel_size=="<="?"selected":"")+"><=</option></select>&nbsp;&nbsp;<input type='text' style='width:140px' id='f_size' value='"+f_size+"'></td></tr><tr><td height=30 align='right'><%=LANG['title_starttime']%>:</td><td align='left'><input type='text' style='width:180px' id='f_starttime' value='"+f_starttime+"'  onclick='selectTime();'><button id='btn_clear_date' onclick='clearTime();'><span><em><img src='images/clean.gif' align='absmiddle' title='Clean'>&nbsp;</em></span></button></td></tr><tr><td height=30 align='right'><%=LANG['title_endtime']%>:</td><td align='left'><input type='text' style='width:180px' id='f_endtime' value='"+f_endtime+"'  onclick='selectEndTime();'><button id='btn_clear_date2' onclick='clearTime2();'><span><em><img src='images/clean.gif' align='absmiddle' title='Clean'>&nbsp;</em></span></button></td></tr><tr><td height=100 colspan=2><button id='btn_submit' type='submit' onclick='return AddFilters_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></td></tr></table>",null,520,400);
	top.$("f_starttime").onclick = function(){selectTime();};
	top.$("f_endtime").onclick = function(){selectEndTime();};
	top.$("btn_clear_date").onclick = function(){clearTime();};
	top.$("btn_clear_date2").onclick = function(){clearTime2();};
	top.$("btn_submit").onclick = function(){return AddFilters_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};
}

function AddFilters_submit()
{
	var strSQL = "";

	sel_id = top.$("sel_id").value;
	f_id = top.$("f_id").value;
	f_protocol = top.$("f_protocol").value;
	f_action = top.$("f_action").value;
	sel_size = top.$("sel_size").value;
	f_size = top.$("f_size").value;
	sel_filename = top.$("sel_filename").value;
	f_filename = top.$("f_filename").value;
	sel_username = top.$("sel_username").value;
	f_username = top.$("f_username").value;
	sel_ip = top.$("sel_ip").value;
	f_ip = top.$("f_ip").value;
	f_starttime = top.$("f_starttime").value;
	f_endtime = top.$("f_endtime").value;

	if(top.$("f_id").value != "")
	{
		strSQL += " and f_id " + top.$("sel_id").value + " " + top.$("f_id").value;
	}

	if(top.$("f_protocol").value != "")
	{
		strSQL += " and f_protocol = " + top.$("f_protocol").value;
	}

	if(top.$("f_action").value != "")
	{
		strSQL += " and f_action = " + top.$("f_action").value;
	}

	if(top.$("f_size").value != "")
	{
		strSQL += " and f_filesize " + top.$("sel_size").value + " " + top.$("f_size").value;
	}

	strSQLFilter = strSQL;

	if(f_filename != "")
	{
		if(strSQL != "") 
			strSQL += " and ";

		f_filename = f_filename.replace(/\*/ig, "%");
		if(top.$("f_action").value != "" && (top.$("f_action").value == "3" || top.$("f_action").value == "4" || top.$("f_action").value == "9") )
			strSQL += "f_filepath " + top.$("sel_filename").value + " '" + f_filename + "'";
		else
			strSQL += "f_filename " + top.$("sel_filename").value + " '" + f_filename + "'";
	}

	if(f_username != "")
	{
		if(strSQL != "") 
			strSQL += " and ";

		f_username = f_username.replace(/\*/ig, "%");
		strSQL += "f_username " + top.$("sel_username").value + " '" + f_username + "'";
	}

	if(f_ip != "")
	{
		if(strSQL != "") 
			strSQL += " and ";

		f_ip = f_ip.replace(/\*/ig, "%");
		strSQL += "f_ip " + top.$("sel_ip").value + " '" + f_ip + "'";
	}

	if(top.$("f_starttime").value != "")
	{
		if(strSQL != "") 
			strSQL += " and ";
		strSQL += "f_time >= '" + top.$("f_starttime").value + "'";
	}

	if(top.$("f_endtime").value != "")
	{
		if(strSQL != "") 
			strSQL += " and ";
		strSQL += "f_time <= '" + top.$("f_endtime").value + "'";
	}

	$("filters").value = strSQL;
	top.closewindow();

	$("btn_search").click();
}

function ViewReport(type)
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then
	print("alert('"..RESULT_STR[-1].."'); return false;")
end
%>

	var frametag = new Date().getTime();

	var title = "<%=LANG['title_weekly_report']%>";
	if(type == 1)
		title = "<%=LANG['title_monthly_report']%>";

	if(isIE)
		showMessagebox(title,"<div id='loading' style='background-color:#FFF; height:30px;'><%=LANG['str_generating_report']%> <img src='images/loading.gif'></div><iframe src='admin_view_report.html?domain="+domain+"&type="+type+"&seeds=" + Math.random() +"' width=620 height=480 border=0 frameborder=0 id='add"+frametag+"'></iframe>",null,620,480);
	else
		window.open("admin_view_report.html?domain="+domain+"&type="+type+"&seeds=" + Math.random());
}

function CustomReport()
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then
	print("alert('"..RESULT_STR[-1].."'); return false;")
end
%>

	showMessagebox("<%=LANG['title_custom_report']%>","<br><table width='100%' border='0' cellpadding='0' cellspacing='0' style='padding-left:10px;'><tr><td height=40 width=120 align='right'><%=LANG['title_starttime']%>:</td><td align='left'><input type='text' style='width:160px' id='f_starttime' onclick='selectTime();' value='<%=os.date("%Y-%m-%d %H:%M:%S",os.time()-3600*24*30)%>'></td></tr><tr><td height=40 width=120 align='right'><%=LANG['title_endtime']%>:</td><td align='left'><input type='text' style='width:160px' id='f_endtime' onclick='selectEndTime();' value='<%=os.date("%Y-%m-%d %H:%M:%S",os.time())%>'></td></tr><tr><td height=40 width=120 align='right'><%=LANG['title_username']%>:</td><td align='left'><input type='text' style='width:160px' id='f_username'> <%=LANG['str_optional']%></td></tr><tr><td height=80 colspan=2><button id='btn_submit' type='submit' onclick='return CustomReport_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></td></tr></table>",null,390,260);
	top.$("f_starttime").onclick = function(){selectTime();};
	top.$("f_endtime").onclick = function(){selectEndTime();};
	top.$("btn_submit").onclick = function(){return CustomReport_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};

	top.$("f_username").focus();
}

function CustomReport_submit()
{
	var frametag = new Date().getTime();
	var username = encodeURIComponent(top.$("f_username").value);
	var starttime = encodeURIComponent(top.$("f_starttime").value);
	var endtime = encodeURIComponent(top.$("f_endtime").value);

	top.closewindow();

	if(isIE)
		showMessagebox("<%=LANG['title_custom_report']%>","<div id='loading' style='background-color:#FFF; height:30px;'><%=LANG['str_generating_report']%> <img src='images/loading.gif'></div><iframe src='admin_view_report.html?domain="+domain+"&username="+username+"&starttime="+starttime+"&endtime="+endtime+"&type=2&seeds=" + Math.random() +"' width=620 height=480 border=0 frameborder=0 id='add"+frametag+"'></iframe>",null,620,480);
	else
		window.open("admin_view_report.html?domain="+domain+"&username="+username+"&starttime="+starttime+"&endtime="+endtime+"&type=2&seeds=" + Math.random());
}

function sortSQLTable(obj, iCol) 
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then
	print("return false;")
end
%>

	var orderby = "asc";

	if (lastsortcol == iCol)
	{
		sortArrow = !sortArrow;
	}
	else
	{
		sortArrow = false;
	}

	if(sortArrow == true)
	{
		orderby = "desc";
	}

	if(obj != null)
	{
		if(lastArrow != null)
			lastArrow.style.backgroundImage="";
		if(sortArrow == false)
			obj.style.backgroundImage="url('images/sortup.gif')";
		else
			obj.style.backgroundImage="url('images/sortdown.gif')";
		obj.style.backgroundPosition="10px";
		obj.style.backgroundRepeat="no-repeat";
		lastArrow = obj;
	}

	lastsortcol = iCol;

	strOrderBy = "order by " + lastsortcol + " " + orderby;

	nowpage = 1;
	getloglistpage(nowpage);
	$("page_selector").value = 1;

}

function DoCopy()
{
	var strResult = "";
	var baseURL = "<%=strBaseURL%>";
	if(window.location.hostname != "127.0.0.1" && baseURL.lastIndexOf("127.0.0.1") != -1)
	{
		baseURL = baseURL.replace(/127.0.0.1/g, window.location.hostname); 
	}

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


	var username = html2txt(selectedRow.cells[3].innerHTML);
	if(selectedRow.cells[3].getAttribute("weblink") == "" || selectedRow.cells[3].getAttribute("weblink") == "/")
	{
		strResult += selectedRow.cells[0].innerHTML+" "+selectedRow.cells[1].innerHTML+" "+selectedRow.cells[2].innerHTML+" "+username+" "+selectedRow.cells[4].innerHTML+" "+html2txt(selectedRow.cells[5].innerHTML)+" "+selectedRow.cells[6].innerHTML+" "+selectedRow.cells[7].innerHTML;
	}
	else
	{
		if(username == "<UPLOADLINK>")
			strResult += baseURL+"uploadlink.html?linkid="+selectedRow.cells[3].getAttribute("weblink");
		else if(username == "<WEBLINK>")
			strResult += baseURL+"main.html?download&weblink="+selectedRow.cells[3].getAttribute("weblink");

		strResult += "&\r\n"+selectedRow.cells[0].innerHTML+" "+selectedRow.cells[1].innerHTML+" "+selectedRow.cells[2].innerHTML+" "+username+" "+selectedRow.cells[4].innerHTML+" "+html2txt(selectedRow.cells[5].innerHTML)+" "+selectedRow.cells[6].innerHTML+" "+selectedRow.cells[7].innerHTML;
	}


	if(window.clipboardData)
	{
		window.clipboardData.setData("Text", strResult);
	}
	else
	{
		try
		{
			if(isFirefox || (isSafari && !isChrome))
			{
				$("ffcopy").value = strResult;
				$("ffcopy").select();
				$("ffcopy").setSelectionRange(0, $("ffcopy").value.length);
				document.execCommand("copy");
				$("ffcopy").value = "";
			}
			else
			{
				var copy = function (e) {
					e.preventDefault();
					if(e.clipboardData)
						e.clipboardData.setData("text/plain", strResult);
				}
				window.addEventListener("copy", copy);
				document.execCommand("copy");
				window.removeEventListener("copy", copy);
			}
		}
		catch(e){}
	}

	DoRefresh();

}

if(isOpera)
{
	top.document.onkeypress = myKeyDown;
	document.onkeypress = myKeyDown;
}
else
{
	top.document.onkeydown = myKeyDown;
	document.onkeydown = myKeyDown;
}

function CtrlPressed(e) {
	if (window.event) {
		return (window.event.ctrlKey);
	} else {
		return (e.ctrlKey || (e.modifiers==2) || (e.modifiers==3) || (e.modifiers>5));
	}
}

function myKeyDown(e)
{
	try
	{
		if(!e){	// if IE
			e=event;
		}

		if(CtrlPressed(e))
		{
			var letter = String.fromCharCode(e.keyCode).toLowerCase();
			if(letter == "c")
			{
				DoCopy();
				return false;
			}
		}
	}
	catch(e)
	{
	}
}

function ExportCsv()
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then
	print("alert('"..RESULT_STR[-1].."'); return false;")
end
%>

	showMessagebox("<%=LANG['str_export_data_title']%>","<br><table width='100%' border='0' cellpadding='0' cellspacing='0' style='padding:10px;'><td height=110 align='left' style='word-break:keep-all;'><%=LANG['str_export_data_from']%> #<input type='text' style='width:50px' id='f_frompage' value='"+nowpage+"''> <%=LANG['str_to']%> #<input type='text' style='width:50px' id='f_topage' value='"+totalpages+"'><br><br><%=LANG['str_export_data_tips']%></td></tr><tr><td height=90><button id='btn_submit' type='submit' onclick='return ExportCsv_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></td></tr></table>",null,420,260);
	top.$("btn_submit").onclick = function(){return ExportCsv_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};
}

function ExportCsv_submit()
{
	var f_frompage = parseInt(top.$("f_frompage").value);
	var f_topage = parseInt(top.$("f_topage").value);

	if(isNaN(top.$("f_frompage").value) == true || isNaN(top.$("f_topage").value) == true || top.$("f_frompage").value == "" || top.$("f_topage").value == "" || f_frompage <= 0 || f_topage <= 0 || f_frompage > totalpages || f_topage > totalpages || f_frompage > f_topage)
	{
		alert("<%=LANG['str_invalid_page']%>");
	}
	else
	{
		var f_total_records = (f_topage - f_frompage + 1)*100;
		if(f_total_records > 2000*100)
		{
			if(confirm("<%=LANG['str_export_confirm']%>") == false)
				return false;
		}
		top.window.location = "admin_get_loglist.html?domain="+domain+"&page="+f_frompage+"&filters="+encodeURIComponent(strSQLFilter)+"&f_username="+encodeURIComponent(f_username)+"&f_filename="+encodeURIComponent(f_filename)+"&f_ip="+encodeURIComponent(f_ip)+"&f_starttime="+encodeURIComponent(f_starttime)+"&f_endtime="+encodeURIComponent(f_endtime)+"&orderby="+encodeURIComponent(strOrderBy)+"&csv=1&pages="+(f_topage - f_frompage + 1)+"&r=" + Math.random();
		top.closewindow();
	}
}
</script>
</head>
<body style="background-color:#E6E6E6;" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<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:40%; width:250px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["title_updating"]%></b></H2></div></div>

<div style="padding-top:2px; overflow-x:hidden;">
	<table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
	<tr>
	<td style="padding-left:2px;">
		<button onclick="ViewReport(0);"><span><em><img src="images/ico_weekreport.png" align="absmiddle"> <%=LANG["title_weekly_report"]%></em></span></button>
		<button onclick="ViewReport(1);"><span><em><img src="images/ico_monthreport.png" align="absmiddle"> <%=LANG["title_monthly_report"]%></em></span></button>
		<button onclick="CustomReport();"><span><em><img src="images/ico_customreport.png" align="absmiddle"> <%=LANG["title_custom_report"]%></em></span></button>
		<button id="button_copy" onclick="DoCopy();" title="<%=LANG["str_copy_rowdata"]%> (Ctrl+C)"><span><em><img src="images/ico_adminlog.png" align="absmiddle"> <%=LANG["button_copy"]%></em></span></button>
		<button onclick="ExportCsv();"><span><em><img src="images/ico_connect.png" align="absmiddle"> <%=LANG["str_export_csv"]%></em></span></button>
	</td>
	</tr>
	</table>

</div>

<div style="background-color:#E6E6E6;">
	<div style="margin-top:3px; margin-left:5px; border:1px solid #919B9C; border-bottom:0px; width:98%;">
		<table id="listhead" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
			<tr style="background-color: #EFEFEF;">
			<td class="listhead" width="8%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_id')"><%=LANG["title_id"]%></td>
			<td class="listhead" width="7%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_protocol')"><%=LANG["title_protocol"]%></td>
			<td class="listhead" width="10%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_action')"><%=LANG["str_action"]%></td>
			<td class="listhead" width="15%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_username')"><%=LANG["title_username"]%></td>
			<td class="listhead" width="15%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_time')"><%=LANG["calendar_static_time"]%></td>
			<td class="listhead" width="18%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_filename')"><%=LANG["str_filename"]%></td>
			<td class="listhead" width="12%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_filesize')"><%=LANG["title_size"]%></td>
			<td class="listhead" width="15%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortSQLTable(this,'f_ip')"><%=LANG["title_ip"]%></td>
			<td class="listhead3">&nbsp;</td>
			</tr>
		</table>
	</div>
	<div id="listview_div" style="background-color:#FFF; margin-left:5px; border:1px solid #919B9C; border-top:0px; width:98%; height:420px; overflow:auto; overflow-x:hidden;">
		<table id="listtable" width="100%" border="0" cellpadding="2" cellspacing="0" style="table-layout:fixed;">
		<thead><tr height="0">
		<td width="8%"></td>
		<td width="7%"></td>
		<td width="10%"></td>
		<td width="15%"></td>
		<td width="15%"></td>
		<td width="18%"></td>
		<td width="12%"></td>
		<td width="15%"></td>
		<td></td>
		</tr></thead>
		<tbody id="maintable">
		</tbody>
		</table>
	</div>
</div>

<div style="padding-left:5px; padding-top:2px; ">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
	<tr>
	<td width="37%">
	<input type='text' id='filters' title='<%=LANG["str_add_filters"]%>' onclick="AddFilters();" style="width:140px;">&nbsp;<button title='<%=LANG["str_add_filters"]%>' onclick="AddFilters();"><span><em>+</em></span></button>&nbsp;<button id='btn_search' onclick='DoSearch();'><span><em><%=LANG["button_search"]%></em></span></button>

	</td>
	<td align="right" style="padding-right:10px;">

	<button onclick='jumpprevious();'><span><em><%=LANG["button_previous_page"]%></em></span></button>
	<select id='page_selector' onchange="pagejump(this.value)">
		<option value="1">1</option>
	</select>
	<span id="page_number" style="*vertical-align:20%;"></span>
	<button onclick='jumpnext();'><span><em><%=LANG["button_next_page"]%></em></span></button>&nbsp;
	<button onclick="DoRefresh();"><span><em><%=LANG["button_refresh"]%></em></span></button>

	</td>
	</tr>
	</table>

<script language="javascript">
pagejump(nowpage);


function jumpprevious()
{
	page = nowpage-1;
	pagejump(page);
}

function jumpnext()
{
	page = nowpage+1;
	pagejump(page);
}

function pagejump(page)
{
	page = parseInt(page);
	if(page > totalpages)
		page = totalpages;
	if(page < 1)
		page = 1;
	nowpage = page;
	getloglistpage(nowpage);

	$("page_selector").value = nowpage;
	$("page_number").innerHTML = nowpage + " / " + totalpages;
}
</script>
</div>
<input id="ffcopy" style="position:absolute; left:-100px; outline:none; border:0px; color:rgba(0,0,0,0.0); background-color:transparent;">
</body>
</html>

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