<?php
require_once "../config/config.php";
require_once INCLUDE_DIR."/users_class.php";
require_once INCLUDE_DIR."/system_log_class.php";
$users=new users_class();
$lsmanagelog=true;
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view User Log')==false)
{
Redirect('admin_nopermission.php',true);
}
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage User Log')==false)
{
$lsmanagelog=false;
}
require_once INCLUDE_DIR."/datepicker/class/class.oCalendarPicker.php";
$aMonthNames=array(
"FR"=>array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"),
"EN"=>array("January","February","March","April","May","June","July","August","September","October","November","December")
);
$aDaysNames=array(
"FR"=>array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"),
"EN"=>array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
);
$sDateFormat=array(
"FR"=>"m/d/Y",
//"EN"=>"m/d/Y"
"EN"=>"Y-m-d"
);
$sDate=(!empty($_GET['sDate']))?$_GET['sDate']:date("Ymd");
$lsuserid='';
if(isset($_GET['userid']))
{
if($_GET['userid']!='')
{
$lsuserid=(int)$_GET['userid'];
$userQuery = 'SELECT username FROM '.TABLE_PREFIX.'users WHERE id = '.$lsuserid;
$lsusername = $users->View($userQuery);
$lsquserid="pet.userid=$lsuserid and ";
}
else
{
Redirect('admin_users_v.php',true);
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if((isset($_POST['chkDeleteItem']) and $_POST['chkDeleteItem'] != '') or isset($_POST['btnDeleteAll']))
{
$losystemLog=new system_log_class();
$delete = (isset($_POST['btnDeleteSelected'])) ? $_POST['btnDeleteSelected'] : $_POST['btnDeleteAll'];
switch($delete)
{
case 'Delete Selected':
$deleteQuery = 'DELETE FROM '.TABLE_PREFIX.'users_log WHERE id=?';
foreach($_POST['chkDeleteItem'] as $k=>$val)
{
$laDeleteID = array($val);
$qsueryResult = $losystemLog->Delete($deleteQuery,$laDeleteID,null);
unset($laDeleteID);
}
break;
case 'Delete All':
if(isset($_GET['userid']))
{
$deleteQuery = 'DELETE FROM '.TABLE_PREFIX.'users_log where userid='.$_GET['userid'];
}
else
{
$deleteQuery = 'DELETE FROM '.TABLE_PREFIX.'users_log';
}
$qsueryResult = $losystemLog->Delete($deleteQuery,null,null);
break;
}
$message->SetMessage('User log deleted successfully.');
if(isset($_GET))
{
$action="admin_user_log_v.php?search=del";
if(isset($_GET['userid']))
$action.='&userid='.trim($lsuserid);
if(isset($_GET['pagename']))
$action.='&pagename='.urldecode(trim($_GET['pagename']));
if(isset($_GET['redirectedfrom']))
$action.='&redirectedfrom='.urldecode(trim($_GET['redirectedfrom']));
if(isset($_GET['visitedon']))
$action.='&visitedon='.urldecode(trim($_GET['visitedon']));
if(isset($_GET['visitedby']))
$action.='&visitedby='.urldecode(trim($_GET['visitedby']));
if(isset($_GET['hostname']))
$action.='&visitedby='.urldecode(trim($_GET['hostname']));
if(isset($_GET['hostAddress']))
$action.='&visitedby='.urldecode(trim($_GET['hostAddress']));
$lsredirecturl=$action;
}
else
{
$lsredirecturl="admin_user_log_v.php";
}
$quest="&";
if(isset($_GET) && !empty($_GET))
{
foreach($_GET as $keyname => $value) {
$quest.=$keyname."=".$value."&";
}
}
Redirect($lsredirecturl.$quest,true);
}
// exit();
}
echo($smarty->fetch('admin_header.php'));
//echo PrintABCDPaging();
//phpinfo();
echo "<div id=\"content\" class=\"setdiv\"> ";
if($message->IsMessageExists())
{
$lsmsg=$message->GetMessage();
echo "<div class=\"succmsg\" style=\"width:200px\">$lsmsg</div>";
}
echo "
<script language=\"JavaScript\">;
function CheckAll(elementID)
{
var CheckSelect = document.getElementById('chkSelectAll');
var LabelCheckSelect = document.getElementById('lblSelect');
var AllCheckBox = document.getElementsByName('chkDeleteItem[]');
//alert(CheckSelect.checked);
//alert(AllCheckBox.length);
switch(elementID)
{
case 'chkSelectAll':
if(CheckSelect.checked)
{
//alert(AllCheckBox.length);
LabelCheckSelect.innerHTML = 'Uncheck All';
for(i=0;i<AllCheckBox.length;i++)
{
AllCheckBox[i].checked = 'true';
}
}
else
{
LabelCheckSelect.innerHTML = 'Check All';
for(i=0;i<AllCheckBox.length;i++)
{
AllCheckBox[i].checked = '';
}
}
break;
case 'ckhDeleteItem':
var flag = 1;
for(i=0;i<AllCheckBox.length;i++)
{
if(!AllCheckBox[i].checked)
{
flag = 0;
}
}
if(flag == 0)
{
LabelCheckSelect.innerHTML = 'Check All';
CheckSelect.checked = '';
}
else
{
LabelCheckSelect.innerHTML = 'Uncheck All';
CheckSelect.checked = 'true';
}
}
}
function validateIP(url) {
if (url.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
var myArray = url.split(/\./);
if (myArray[0] > 255 || myArray[1] > 255 || myArray[2] > 255 || myArray[3] > 255)
return false;
if (myArray[0] == 0 && myArray[1] == 0 && myArray[2] == 0 && myArray[3] == 0)
return false;
return true;
}
else
return false;
}
function ValidateSearchForm()
{
var pagename = document.getElementById('pagename');
var redirectedfrom = document.getElementById('redirectedfrom');
var visitedon = document.getElementById('visitedon');
var visitedby= document.getElementById('visitedby');
var hostname = document.getElementById('hostname');
var hostAddress = document.getElementById('hostAddress');
var flag = 1;
if(pagename.value == '' && redirectedfrom.value == '' && visitedon.value == '' && visitedby.value == '' && hostname.value == '' && hostAddress.value == '' )
{
flag = 0;
}
else
{
var hostaddval=hostAddress.value.replace(/^\s+|\s+$/g,'');
if(hostAddress.value!='' && validateIP(hostaddval)==false)
{
alert('please enter valid host address');
hostAddress.focus();
return false;
}
}
if(flag == 0)
{
//alert('Please enter atleast one field for search?');
//return false;
return true;
}
else
{
return true;
}
}
function ValidateCheckbox(str)
{
var AllCheckBox = document.getElementsByName('chkDeleteItem[]');
var flag = 0;
for(i=0;i<AllCheckBox.length;i++)
{
if(AllCheckBox[i].checked)
{
flag = 1;
}
}
if(flag == 0 && str == 'selected')
{
alert('Please select atleast one record to delete!');
return false;
}
else
{
return confirm('Are you sure to delete '+str+' user logs?');
//return true;
}
}
</script>
";
if(isset($_GET['pagename']))
$pagename=urldecode(trim($_GET['pagename']));
else
$pagename="";
if(isset($_GET['redirectedfrom']))
$redirectedfrom=urldecode(trim($_GET['redirectedfrom']));
else
$redirectedfrom="";
if(isset($_GET['visitedon']) and $_GET['visitedon']!="")
$vison=(double)$_GET['visitedon'];
else
$vison="";
if(isset($_GET['visitedon']) and $_GET['visitedon']!="")
$visitedon1=date('Y-m-d',$vison);
else
$visitedon1="";
if(isset($_GET['visitedby']))
$visitedby=urldecode(trim($_GET['visitedby']));
else
$visitedby="";
if(isset($_GET['hostname']))
$hostname=urldecode(trim($_GET['hostname']));
else
$hostname="";
if(isset($_GET['hostAddress']))
$hostAddress=urldecode($_GET['hostAddress']);
else
$hostAddress="";
echo "<div id=\"full-contentdiv\">";
echo "<div class=\"righttop\">";
echo "<h2 align=\"center\">";
if(isset($lsusername))
{
if(is_array($lsusername) && sizeof($lsusername))
echo "User Log List of ".$lsusername[0]['username'];
else
{
echo "Users Log List";
}
}
else
{
echo "Users Log List";
}
echo "</h2>";
echo "</div>";
echo "<div class=\"whole-page clear\">";
echo "
<div style='width:890px;margin-bottom:10px' class='formformat'>
<form action='admin_userlog_m.php?action=search_log' method='POST' name='frmSearchLog' id='frmSearchLog'>
<table cellspacing='0' cellpadding='0' border='0' width='100%'>
<tr>
<td class='right-side-text' style='width:150px'>
<label>Page Name</label>
</td>
<td class='left-side-text' style='width:150px'>
<input type='text' id='pagename' value='$pagename' name='pagename' class='txtcss'>";
if($lsuserid!="") ?>
<input type='hidden' id='userid' name='userid' value="<?php echo $lsuserid; ?>" class='txtcss'>
<?php
echo"</td>
<td class='right-side-text' style='width:150px'>
<label>Redirected From</label>
</td>
<td class='left-side-text' style='width:150px'>
<input type='text' id='redirectedfrom' value='$redirectedfrom' name='redirectedfrom' class='txtcss'>
</td>
<td class='right-side-text'>
<label>Visited By</label>
</td>
<td class='left-side-text'>
<input type='text' id='visitedby' value='$visitedby' name='visitedby' class='txtcss'>
</td>
</tr>
<tr>
<td class='right-side-text'>
<label>Visited On</label>
</td>
<td class='left-side-text'>
<input type='text' id='visitedon' value='$visitedon1' readonly='readonly' name='visitedon' class='txtcss' style='width:95px'>";
echo "<input type='button' value='' style='background:url(".ADMIN_IMAGE_DIR."/calendar1.gif) no-repeat;height:20px;width:21px;border:0px;' onclick=\"displayCalendar(document.forms[0].visitedon,'yyyy-mm-dd',this)\">";
/* $aCalendarParams=array(
"sIconPath" => ADMIN_IMAGE_DIR."/calendar1.gif",
"iAction" => 1, //0=>reloadCurrentPage with get param sDate, 1=>fill field sFieldName
"sFieldName" => "visitedon",
"iStyle" => 1, //0=>display calendar, 1=>display div on icon click
"aMonthNames" => $aMonthNames["EN"],
"aDaysNames" => $aDaysNames["EN"],
"sDateFormat" => $sDateFormat["EN"]
);
new oCalendarPicker("calFixe1",$sDate,$aCalendarParams); */
echo" </td>
<td class='right-side-text'>
<label>Host Name</label>
</td>
<td class='left-side-text'>
<input type='text' id='hostname' value='$hostname' name='hostname' class='txtcss'>
</td>
<td class='right-side-text'>
<label>Host Address</label>
</td>
<td class='left-side-text'>
<input type='text' id='hostAddress' value='$hostAddress' name='hostAddress' class='txtcss'>
</td>
</tr>
<tr>
<td colspan='6' class='buttontd' style='text-align:center;'>
<input type='submit' id='FilterSubmit' name='FilterSubmit' value='Search User Log' style='width:150px' class='btncss' onclick='return ValidateSearchForm();'>
</td>
</tr>
</table>
</form>
</div>
";
echo "<form name=\"frmDeleteLog\" action=\"\" method=\"POST\">";
/****************************************************************************
* Updated By Jayesh : for display character based paging
*****************************************************************************/
echo "<div class=\"divABCDPaging\">";
echo PrintABCDPaging();
echo "</div>";
echo "<div style=\"text-align:center;margin:2px;overflow:hidden;clear:both;height:30px;\">";
echo "<div style=\"margin-left:3px;margin-top:3px;text-align:left;font-weight:bold !important;float:left;width:120px;\">";
if($lsmanagelog==true)
{
echo "<input type=\"checkbox\" class=\"chkcss\" id=\"chkSelectAll\" name=\"chkSelectAll\" onclick=\"return CheckAll(this.id)\"> <label id=\"lblSelect\" for=\"chkSelectAll\">Check All</label>";
}
echo "</div>";
//echo "<div style=\"float: left;margin-left:110px\">";
echo "<div style=\"text-align:right;margin:2px;\">";
if($lsuserid!='')
// echo"<div style=\"width:17%px;margin-left:40px;margin-top:6px;text-align:left;font-weight:bold !important;float:left;width<span style=\"margin-left:4px;\"><a href=\"admin_users_v.php?userid=$lsuserid\">Back To Users List</a></span></div>";
echo"<div style=\"float:left;width:17%;margin-top:6px;\"><span style=\"margin-left:4px;\"><a href=\"admin_users_v.php\">Back To Users List</a></span></div>";
echo "</div>";
echo "</div>";
if(isset($_GET['letter']) and $_GET['letter'] != 'all')
{
$lsSearchLetter = $_GET['letter'];
}
else
{
$lsSearchLetter = '';
}
$pagename=urldecode(trim($_GET['pagename']));
$redirectedfrom=urldecode(trim($_GET['redirectedfrom']));
$visitedon=urldecode($_GET['visitedon']);
$visitedby=urldecode(trim($_GET['visitedby']));
$hostname=urldecode(trim($_GET['hostname']));
$hostAddress=urldecode(trim($_GET['hostAddress']));
$lsAddtionalSearch="";
//echo $res;
/*$sql = 'SELECT *,CASE WHEN bantype = 1 THEN \'IP Address\' WHEN bantype = 2 THEN \'Hostname\' WHEN bantype = 3 THEN \'Range\' END AS `BanType`,CASE WHEN `isactive` = 1 THEN \'Active\' WHEN `isactive` = 0 THEN \'InActive\' END AS `Status` FROM '.TABLE_PREFIX.'banlist';*/
/*
$sql = "select pu.username,pet.id,pet.page_name,(case when LENGTH(pet.referer_page_name) >= 55 then CONCAT(SUBSTR(pet.referer_page_name,1,55),'...') else pet.referer_page_name end) as referer_page_name ,pet.host_name,pet.host_address,
from_unixtime(pet.visitedon,'%Y-%m-%d<br/>%h:%i:%s') as `visitedon`,
concat('<input type=\"checkbox\" id=\"ckhDeleteItem\" name=\"chkDeleteItem[]\" onclick=\"return CheckAll(this.id)\" value=\"',pet.id,'\" />') as `CheckToDelete`,
concat('<a href=\"#\" onclick=\"window.open(\'admin_userlog_m.php?ID=',pet.id,'\',\'\',\'dependent=1,scrollbars=1,diretories=0,height=400,width=1000,location=0\');return false;\">more</a>') as `More`
from ".TABLE_PREFIX."users_log pet
join ".TABLE_PREFIX."users pu on pu.id = pet.userid
WHERE ".$lsquserid." pet.page_name like '$lsSearchLetter%'";
*/
$sql = "select pu.username,pet.id,(case when LENGTH(pet.page_name) >=25 then CONCAT(SUBSTR(pet.page_name,1,25),'...') else pet.page_name end) as page_name,(case when LENGTH(pet.referer_page_name) >= 55 then CONCAT(SUBSTR(pet.referer_page_name,1,55),'...') else pet.referer_page_name end) as referer_page_name ,(case when LENGTH(pet.host_name) >=20 then CONCAT(SUBSTR(pet.host_name,1,20),'...') else pet.host_name end) as host_name ,(case when LENGTH(pet.host_address) >=20 then CONCAT(SUBSTR(pet.host_address,1,20),'...') else pet.host_address end) as host_address,
from_unixtime(pet.visitedon,'%Y-%m-%d<br/>%h:%i:%s') as `visitedon`,
concat('<input type=\"checkbox\" id=\"ckhDeleteItem\" name=\"chkDeleteItem[]\" onclick=\"return CheckAll(this.id)\" value=\"',pet.id,'\" />') as `CheckToDelete`,
concat('<a href=\"#\" onclick=\"window.open(\'admin_userlog_m.php?ID=',pet.id,'\',\'\',\'dependent=1,scrollbars=1,diretories=0,height=400,width=1000,location=0\');return false;\">more</a>') as `More`
from ".TABLE_PREFIX."users_log pet
join ".TABLE_PREFIX."users pu on pu.id = pet.userid
WHERE ".$lsquserid." pet.page_name like '$lsSearchLetter%'";
if($pagename!="")
$lsAddtionalSearch.=" and pet.page_name like '%$pagename%' ";
if($redirectedfrom!="")
$lsAddtionalSearch.=" and pet.referer_page_name like '%$redirectedfrom%' ";
if($visitedon!="")
$lsAddtionalSearch.=" and from_unixtime(pet.visitedon,'%d/%m/%Y') = from_unixtime($visitedon,'%d/%m/%Y') ";
if($visitedby!="")
$lsAddtionalSearch.=" and pu.username like '%$visitedby%' ";
if($hostname!="")
$lsAddtionalSearch.=" and pet.host_address like '%$hostname%' ";
if($hostAddress!="")
$lsAddtionalSearch.=" and pet.host_name like '%$hostAddress%' ";
//echo $sql; window.open('admin_email_uploader.php?','','dependent=1,scrollbars=1,directories=0,height=600,width=1000,location=0');
# execute the sql query
if($lsAddtionalSearch!="")
$sql.=" ".$lsAddtionalSearch;
$db->execute($sql);
$totalrowcount=$db->rowCount();
// if($lsmanagelog==true)
// {
# creates a new phpSortColumn object for ID´s
//$col_0 = new phpSortColumn("id", "ID");
#creates a new phpSortcolunm objects for name
if($lsmanagelog==true)
$col_0 = new phpSortColumn("CheckToDelete","");
$col_1 = new phpSortColumn("page_name", "Page Name");
# creates a new phpSortColumn object for Tile
$col_2 = new phpSortColumn("referer_page_name", "Redirected From");
# creates a new phpSortColumn object for Field Type
$col_3 = new phpSortColumn("username", "Visited By");
$col_4 = new phpSortColumn("visitedon","Visited On");
$col_6 = new phpSortColumn("host_address","host Name");
$col_7 = new phpSortColumn("host_name","Host Address");
if($lsmanagelog==true)
$col_8 = new phpSortColumn("More","");
# add the columns to an array
if($lsmanagelog==true)
$columns = array(0=>$col_0, 1=>$col_1, 2=>$col_2, 3=>$col_3, 4=>$col_4,6=>$col_6, 7=>$col_7, 8=>$col_8);
else
$columns = array(1=>$col_1, 2=>$col_2, 3=>$col_3, 4=>$col_4,6=>$col_6, 7=>$col_7);
# create a new phpSortable object with the abstracted db object
# and the array of column object
$sortable = new phpSortable($db, $columns);
# define the table format: cellpadding, cellspacing, border
$sortable->setTableFormat ("2", "2", "0");
# define the table title
$sortable->tableTitle = "";
# Encrypt Edit and Delete Link
$sortable->encryptlink = false;
# define the key name to be attached to links
$sortable->urlKeyName = "id";
# define the column name of to be attached to links as key value
$sortable->tableKeyName = "id";
# define the message to be diplayed if there are no results found
$sortable->emptyMsg = "No User Logs Found.";
#define the deafult row number to be displayed
$sortable->defaultRowsNum = "10";
#define the path for the css file
$sortable->cssFilePath = ADMIN_CSS_DIR."/phpSortable.css";
#define the path for of the images directory
$sortable->imgFilePath = ADMIN_IMAGE_DIR."/phpgrid/";
# print the table
$sortable->printTable();
if($lsmanagelog==true)
{
echo '<input style="margin:5px;" type="submit" value="Delete Selected" name="btnDeleteSelected" id="btnDeleteSelected" class="btncss" onclick="return ValidateCheckbox(\'selected\');"/>';
echo '<input style="margin:5px;width:108px" type="submit" value="Delete All" name="btnDeleteAll" id="btnDeleteAll" class="btncss" onclick="return ValidateCheckbox(\'all\');"/>';
echo '<input style="margin:5px;" type="submit" value="View Members" name="btnViewMembers" id="btnViewMembers" class="btncss" onclick="window.location.href=\'admin_users_v.php\';return false;"/>';
}
if($totalrowcount<=0 && $lsmanagelog==true)
{
echo "<script>";
echo "document.getElementById('chkSelectAll').style.display='none';";
echo "document.getElementById('lblSelect').style.display='none';";
echo "document.getElementById('btnDeleteSelected').style.display='none';";
echo "document.getElementById('btnDeleteAll').style.display='none';";
echo "</script>";
}
/* if(isset($_GET['userid']))
{
echo "<br>";
echo "<div style='text-align: right; margin-right: 3px;'><input type='button' onclick='javascript:window.history.go(-1);' value='Back' name='btnBack' class='btncss'/></div>";
}*/
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
//For display footer.php
echo($smarty->fetch('admin_footer.php'));
?>