<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	$check_acc  = check_access('1');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $PROJECT_TITLE ?></title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script>
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="js/files/bootstrap.js"></script>
<script type="text/javascript" src="js/files/functions.js"></script>

<script type="text/javascript" src="js/charts/chart.js"></script>
<script type="text/javascript" src="js/charts/hBar_side.js"></script>
<script>
	function reload_page(ids)
	{
		window.location='login_log_list.php?cli_emp_id='+ids;
	}
</script>
<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body onload="document.getElementById('listpage').focus();">

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->
<!-- Content begins -->
<div id="content">

<?php include "menus/top_menu.php"; ?>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="home.php">Dashboard</a></li>
                <li><a href="javascript:">Login Details</a></li>
                <li><a href="javascript:">Client & Admin Log List</a></li>
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>
    </div>

    <!-- Main content -->
    <div class="wrapper">
<?php if($check_acc==1){?>
        <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->  
          <!--<li><a href="party_add.php" title="Add Party" id="addpage" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>-->
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>
            <li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
           <!-- <li><a href="login_det_list.php" id="listpage" title="List Login Details" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
            <li><a href="login_det_list.php" title="Login Deatails List" id="addpage" class="tipN"><img src="images/new_login.png" alt="" style="margin-top:-20px" /></a></li>
          <li><a href="login_det_pwd_change.php" title="Change Password" id="addpage" class="tipN"><img src="images/chng_pwd.png" style="margin-top:-20px" /></a></li>
		  <li><a href="login_log_list.php" title="Client & Admin Log List" id="addpage" class="tipN"><img src="images/icons/mainnav/log_list.png" /></a></li>
		  <li><a href="guest_login_log_list.php" title="Guest Log List" id="addpage" class="tipN"><img src="images/icons/mainnav/guest_user.png" /></a></li>
          <li><a href="emp_login_log_list.php" title="Employee Log List" id="addpage" class="tipN"><img src="images/icons/mainnav/emp_hk.png" style="margin-top:-20px" /></a></li>
    	</ul>
    	<?php 
			if(isset($_GET['cli_emp_id']))
			{
				$cli_emp_id =	$_GET['cli_emp_id'];	
				$log_chk = base64_decode(base64_decode(base64_decode($cli_emp_id)));
			}
			else
			{
				$cli_emp_id = base64_encode(base64_encode(base64_encode('client')));
				$log_chk = 'client';
			}

			$emp_name= base64_encode(base64_encode(base64_encode('employee')));
			$cli_name= base64_encode(base64_encode(base64_encode('client')));
			$adm_name= base64_encode(base64_encode(base64_encode('super_admin')));
			$mar_name= base64_encode(base64_encode(base64_encode('marketing')));
			//echo $cli_name;
		?>
    	<!-- Chart --><!-- 6 + 6 -->
		 <div class="fluid">
		<div class="widget">
        <div class="formRow">
            <div class="grid3"><label>Log For:<span class="req">*</span></label></div>
            <div class="grid6 searchDrop ">
			<select data-placeholder="" class="select" style="width:350px;" name="login_for" id="login_for"  data-rel="chosen" onChange="reload_page(this.value);">
				<option value=""></option>
				<option <?php if($adm_name == $cli_emp_id){ ?> selected="selected" <?php }?>value="<?php echo $adm_name;?>">Super Admin</option>
				<option <?php if($cli_name == $cli_emp_id){ ?> selected="selected" <?php }?>value="<?php echo $cli_name;?>">Client</option>
                <option <?php if($emp_name == $cli_emp_id){ ?> selected="selected" <?php }?>value="<?php echo $emp_name;?>">Employee</option>
                <option <?php if($mar_name == $cli_emp_id){ ?> selected="selected" <?php }?>value="<?php echo $mar_name;?>">Marketing Admin</option>
			</select>
            </div>
            <div class="clear"></div>
        </div>
        </div>
        </div>
    	<div class="widget"> <!--style="width:600px; margin-left:150px;"-->

        <div class="whead"><h6 style="text-transform:capitalize;"><?php echo str_replace('_',' ',$log_chk); ?> Log List</h6><div class="clear"></div></div>
        <div id="dyn" class="hiddenpars">
        	<a href="javascript:0" id="searchlink" onfocus="foc(this.id)" onblur="stnon(this.id)" class="tOptions" title="Options"><img src="images/icons/options.png" alt="" /></a>
            <table width="819" border="0" cellpadding="0" cellspacing="0" class="dTable" id="dynamic">
            <thead>
            <tr>
            <th width="30">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="68">User Status </th>
            <?php
			if($log_chk!='employee' && $log_chk!='marketing')
			{
			?>
            <th width="130" style="text-align:left;">Comp Name</th>
            <th width="105" style="text-align:center;">Comp Code</th>
            <?php
			}
			else if($log_chk=='employee' || $log_chk=='marketing')
			{
			?>
            <th width="130" style="text-align:left;">Employee Name</th>
            <?php
			}
			?>
            <th width="107" style="text-align:center;">User Type</th>
            <th width="121" style="text-align:center;">Login Time</th>
            <th width="91" style="text-align:center;">Logout Time</th>
            <th width="81" style="text-align:center;">IP</th>
            <!--<th width="101">Websit URL</th>-->
            <th width="86" style="text-align:center;">Total Time</th>
            <!--<th width="260">Status</th>-->
            </tr>
            </thead>
            <tbody>
            <?php
			$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for active inactive
			if($log_chk=='employee')
			{
				$SLCT = "SELECT * FROM login_log WHERE (designation='employee' || designation='admin') ORDER BY login_log_id DESC";
			}
			else
			{
				$SLCT = "SELECT * FROM login_log WHERE designation='$log_chk' ORDER BY login_log_id DESC";
			}
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			if(mysqli_num_rows($QURY)>0)
			{			
			while($FTCH = mysqli_fetch_object($QURY))
			{
				$sts = ($FTCH->update_dt=='0000-00-00 00:00:00')?"<b><font color='#00CC00'>Online</font></b>":"Offline"; 

				$now = new DateTime($FTCH->post_dt);
				$ref = new DateTime($FTCH->update_dt);
				$diff = $now->diff($ref);

				if($FTCH->designation=='super_admin')
				{
					$comp_name = '------';
					$comp_code = '------';
					$des 	   = str_replace('_',' ',$FTCH->designation);	
				}
				else if($FTCH->designation=='client')
				{
					$SLCTp = "SELECT * FROM login_details,party_det WHERE party_det.party_det_id = login_details.party_det_id AND login_details.admin_id = '$FTCH->admin_id'";
					$QURYp = mysqli_query($connect,$SLCTp);
					$FTCHp = mysqli_fetch_object($QURYp);
					$comp_name = $FTCHp->cmp_name;
					$comp_code = $FTCHp->party_code;
					$des 	   = str_replace('_',' ',$FTCH->designation);
				}
				else if($FTCH->designation=='employee')
				{
					$SLCTp = "SELECT * FROM login_details,emp_det WHERE emp_det.emp_det_id = login_details.emp_det_id AND login_details.admin_id = '$FTCH->admin_id'";

					$QURYp = mysqli_query($connect,$SLCTp);
					$FTCHp = mysqli_fetch_object($QURYp);
					$comp_name = $FTCHp->name;
					$des 	   = str_replace('_',' ',$FTCH->designation);
				}
				else if($FTCH->designation=='admin')
				{
					$SLCTp = "SELECT * FROM login_details,emp_det WHERE emp_det.emp_det_id = login_details.emp_det_id AND login_details.admin_id = '$FTCH->admin_id'";
					$QURYp = mysqli_query($connect,$SLCTp);
					$FTCHp = mysqli_fetch_object($QURYp);
					$comp_name = $FTCHp->name;
					$des 	   = 'Order Followup';
				}
				else if($FTCH->designation=='marketing')
				{
					$SLCTp = "SELECT * FROM marketing_admin,emp_det WHERE emp_det.emp_det_id = marketing_admin.emp_det_id AND marketing_admin.marketing_admin_id = '$FTCH->admin_id'";
					$QURYp = mysqli_query($connect,$SLCTp);
					$FTCHp = mysqli_fetch_object($QURYp);
					$comp_name = $FTCHp->name;
					$des 	   = str_replace('_',' ',$FTCH->designation);
				}

				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
			?>
            <tr <?php echo $bg ?>>
            <td align="center" style="text-align:center; vertical-align:middle;"><?php echo $loop ?></td>
            <td align="center" style="text-align:center; vertical-align:middle;"><?php echo $sts; ?></td>
            <td align="center" style="text-align:center; vertical-align:middle;">
			<?php //echo $comp_name; 
			$cmp_count1 = strlen($comp_name);
			$con_pers1 = substr($comp_name,0,11)."...";
			?>
			<?php if($cmp_count1>11){?>
			<div class="tooltip1">
			<?php echo $con_pers1;?>
				<span class="tooltiptext1"><?php echo $comp_name;?></span>
			</div>
			<?php } else { ?>
			<?php echo $comp_name;?><br>
			<?php } ?>
			</td>
            <?php
			if($log_chk!='employee' && $log_chk!='marketing')
			{
			?>
            	<td align="center" style="text-align:center; vertical-align:middle;"><?php echo $comp_code; ?></td>
            <?php
			}
			?>
            <td align="center" style="text-transform:capitalize; vertical-align:middle;"><?php echo $des; ?></td>
            <td align="center" style="text-align:center; vertical-align:middle;"><?php echo $FTCH->post_dt; ?></td>
            <td class="center" style="text-align:center; vertical-align:middle;"><?php echo $FTCH->update_dt; ?></td>
            <td class="center" style="text-align:center; vertical-align:middle;"><?php echo $FTCH->ip_address; ?></td>
            <td class="center" style="text-align:center; vertical-align:middle;" align="center"><?php if($FTCH->update_dt=="0000-00-00 00:00:00"){ echo "Till Now"; }else{ printf('%d Hrs ,%d Mts', $diff->h, $diff->i); } ?></td>
            </tr>
            <?php
			$loop ++;
			 }
			 }
			 ?>
            </tbody>
          </table> 
        </div>
        </div>
        <div class="fluid"><!-- Media table --></div>
		<?php } else {  echo ACCESS_MSG;} ?>
    </div>
    <!-- Main content ends -->
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
