<%
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>Log List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
local domain = _GET["domain"] or _POST["domain"]
%>
<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: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;
}
span{
	vertical-align:middle;
}


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

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 3px 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: 3px solid #CBC7B8;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EBEADB; overflow:hidden; height:22px;
}

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

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

<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_username = "";
var sel_username = "=";
var f_filename = "";
var sel_filename = "=";
var f_ip = "";
var sel_ip = "=";
var f_size = "";
var sel_size = ">=";
var f_starttime = "";
var f_endtime = "";
var f_custom_sql  = false;
var f_sql_str = "";


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(filters)+"&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";

				var filename = txt2html(fieldArray[6]);
				if(fieldArray[3] == "3" || fieldArray[3] == "4" || fieldArray[3] == "9") 
				{
					filename = txt2html(fieldArray[7]);
				}
				htmltext += "<tr class='listtr01' onclick='do_list_click(this);'><td>"+fieldArray[0]+"</td><td>"+protocol+"</td><td>"+type+"</td><td title='"+txt2html(fieldArray[2])+"'>"+txt2html(fieldArray[2])+"</td><td>"+fieldArray[5]+"</td><td class='fixedwidth' title='"+(type == "Rename" ? 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()
{
	filters = "";
	if($("filters").value != "")
	{
		filters = $("filters").value + " order by f_id asc";
	}
	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) or (_SESSION["admin_domainadmin"] ~= nil and _SESSION["admin_domainadmin"] == 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:120px' 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:160px;'><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:160px;'><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></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:120px' 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:120px' 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:120px' 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:120px' 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:120px' 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:120px' 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 align='right'><input id='f_custom_sql' type='checkbox' onclick='UseCustomSQL();' "+(f_custom_sql==true?"checked":"")+"><%=LANG['title_custom_sql']%>: <br><span style='cursor:pointer;' onclick='window.open(\"help/english/index.html?audit__report.htm\",\"_blank\");'><img src='images/ico_question.gif'><%=LANG['button_help']%></span></td><td align='left'><textarea id='strSQL' style='width:320px;height:50px;' "+(f_custom_sql==false?"disabled":"")+">"+f_sql_str+"</textarea></tr><tr><td height=80 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,530,420);
	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.$("f_custom_sql").onclick = function(){UseCustomSQL();};
	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_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;
	sel_size = top.$("sel_size").value;
	f_size = top.$("f_size").value;
	f_starttime = top.$("f_starttime").value;
	f_endtime = top.$("f_endtime").value;

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

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

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

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

		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.replace(/\*/ig, "%") + "'";
		else
			strSQL += "f_filename " + top.$("sel_filename").value + " '" + f_filename.replace(/\*/ig, "%") + "'";
	}

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

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

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

	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 + "'";
	}

	if(top.$("f_custom_sql").checked == true)
	{
		strSQL = top.$("strSQL").value;
	}

	f_sql_str = strSQL;
	f_custom_sql = top.$("f_custom_sql").checked;

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

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

function UseCustomSQL()
{
	if(top.$("f_custom_sql").checked)
	{
		top.$("strSQL").disabled = false;
	}
	else
	{
		top.$("strSQL").disabled = true;
	}
}

function ViewReport(type)
{
<%
if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) or (_SESSION["admin_domainadmin"] ~= nil and _SESSION["admin_domainadmin"] == 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) or (_SESSION["admin_domainadmin"] ~= nil and _SESSION["admin_domainadmin"] == 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) or (_SESSION["admin_domainadmin"] ~= nil and _SESSION["admin_domainadmin"] == 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;

	filters = " 1=1 order by " + lastsortcol + " " + orderby;
	if($("filters").value != "")
	{
		filters = $("filters").value + " order by " + lastsortcol + " " + orderby;
	}

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

}

</script>
</head>
<body style="background-color:#E7E6DA;" 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 width="70%" style="padding-left:2px;">
		<button onclick="ViewReport(0);"><span><em><img src="images/ico_general.gif" align="absmiddle"> <%=LANG["title_weekly_report"]%></em></span></button><button onclick="ViewReport(1);"><span><em><img src="images/ico_general.gif" align="absmiddle"> <%=LANG["title_monthly_report"]%></em></span></button><button onclick="CustomReport();"><span><em><img src="images/ico_general.gif" align="absmiddle"> <%=LANG["title_custom_report"]%></em></span></button>
	</td>
	<td align="right" style="padding-right:10px;"><span><%=LANG["str_domain"]%>:<b><%=specialhtml_encode(unescape(_GET["domain"]))%></b><span>
	</td>
	</tr>
	</table>

</div>

<div style="background-color:#E7E6DA;">
	<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: #EBEADB;">
			<td class="listhead" width="8%" onmousedown="sortSQLTable(this,'f_id')"><%=LANG["title_id"]%></td>
			<td class="listhead" width="7%" onmousedown="sortSQLTable(this,'f_protocol')"><%=LANG["title_protocol"]%></td>
			<td class="listhead" width="10%" onmousedown="sortSQLTable(this,'f_action')"><%=LANG["str_action"]%></td>
			<td class="listhead" width="15%" onmousedown="sortSQLTable(this,'f_username')"><%=LANG["title_username"]%></td>
			<td class="listhead" width="15%" onmousedown="sortSQLTable(this,'f_time')"><%=LANG["calendar_static_time"]%></td>
			<td class="listhead" width="18%" onmousedown="sortSQLTable(this,'f_filename')"><%=LANG["str_filename"]%></td>
			<td class="listhead" width="12%" onmousedown="sortSQLTable(this,'f_filesize')"><%=LANG["title_size"]%></td>
			<td class="listhead" width="15%" 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="42%">
	<input type='text' id='filters' title='<%=LANG["str_add_filters"]%>' onclick="AddFilters();" style="width:160px;">&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>
</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>