<?php $pageno = 6; ?>
<!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>
	<?php include('template/head.php'); ?>
	<!--DATA TABLE --> 
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/data_table/js/jquery.dataTables.js"></script>
    <link href="<?php echo base_url(); ?>assets/data_table/css/demo_table_jui.css" rel="stylesheet" type="text/css"/>
    <link href="<?php echo base_url(); ?>assets/data_table/css/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
    <!--DATA TABLE -->   
    <script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		$('#datatables').dataTable({
			"sPaginationType":"full_numbers",
			"iDisplayLength": 100,
			"aaSorting":[[0, "asc"]],
			"bJQueryUI":true
		});
	});
	function chkConfirm()
	{
		var chk=confirm('Are you sure to delete Vander Details');
		if(chk==true)
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
    </script> 
</head>
<body>
<?php include('template/header.php'); ?> 
<div class="grid_16" id="navheader">
	<?php include('template/topnav.php'); ?>
</div>
<div class="grid_16" id="tabs">
	<div class="container">
		<ul>
			<li><a href="<?php echo base_url(); ?>index.php/Administrator/logSearch/" class="current"><span>Log Details</span></a></li> 
		</ul>
	</div>   
</div>
<div class="container_16" id="wrapper">	
    <div class="grid_16" id="content"> 
		<div class="grid_9">
			<h1 class="user">Log Details</h1>
		</div>
		<div class="grid_15" id="textcontent">
			<table style="float: right;">
				<tr> 			
					<td align="right" colspan="9">
						<a style="float:left;margin-top: -5px;margin-left: 5px;" class="button" href="<?php echo base_url(); ?>index.php/Administrator/AddLog/"><span>Add New Entry</span></a>
					</td>
				</tr>
			</table>
			<div id="table">
				<div id="user_profile_main_div">
					<div id="message">
					<?php 
					if($this->session->flashdata('flsh_msg')) {
						?><p id="success" class="info"><span class="info_inner"><?php echo $this->session->flashdata('flsh_msg'); ?></span></p> <?php
					} 
					if($this->session->flashdata('flsh_msg1')) {
						?><p id="error" class="info"><span class="info_inner"><?php echo $this->session->flashdata('flsh_msg1'); ?></span></p> <?php
					} 
					?>
					</div>
					<div class="clear"></div>
					<form action="#" method="post" enctype="multipart/form-data" name="frmUsers" id="frmTransaction" >
					<table id="datatables" class="display">
						<thead>
							<tr>
								<th>Sno</th>
								<th>Tag No</th>
								<th>Time In</th>
								<th>Time Out</th> 
								<th>Edit</th>
								<th>Delete</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$i=0;
							if(($this->session->flashdata('flsh_msg')) || ($this->session->flashdata('flsh_msg1'))){
								$tag_no = $this->uri->segment(4);
								$from = $this->uri->segment(5);
								$to = $this->uri->segment(6);
								$VehicleNumber = $this->uri->segment(7);
							} else {
								$tag_no = $data['0'];
								$VehicleNumber = $data['1'];
								$from = $data['2'];
								$todate = $data['3'];
								if($todate != ""){
									$to = $data['3'];
								}
								else{
									$to = date('Y-m-d');
								}
							}
							
							
							$ci =& get_instance();
							$ci->load->database();
							
							$query = $ci->db->query("select tag_no, tag_id, alias_tag from tbl_vehicle_master where tag_no='".$tag_no."' OR vehicle_number='".$vehicle_number."'");
							$sqlresult = $query->row_array();
							$tttag_no = $sqlresult['tag_no'];
							
							$query = $ci->db->query("select * from tbl_relationship where ntag_id='".$sqlresult['tag_id']."'");
							$fatchresult = $query->result();
							$totalrow = $query->num_rows();
							if($totalrow != 0){
								foreach ($fatchresult as $fatchrow){
									$tag = $fatchrow->tag;
									$change_date = $fatchrow->time_stamp;
									$sql = "SELECT * FROM log where tag_id = '".$fatchrow->tag_id."' AND (DATE_FORMAT( time_in, '%Y-%m-%d' ) BETWEEN '".trim($from)."' and '".trim($change_date)."')";
									$query = $ci->db->query($sql);
									$result = $query->result();
									foreach($result as $datarow){
										$i++;
										?>
										<tr>
											<td><?php echo $i;?></td>
											<td><?php echo $tag; ?></td>
											<td><?php echo $datarow->time_in; ?></td>
											<td><?php echo $datarow->time_out; ?></td>
											<td><a href="<?php echo base_url(); ?>index.php/Administrator/EditLogDetails/<?php echo $datarow->id; ?>" title="Edit" class="edit_icon"></a></td>
											<td><a href="<?php echo base_url(); ?>index.php/Administrator/DeleteLog/<?php echo $datarow->id; ?>" onclick="return chkConfirm();"title="Delete" class="delete_icon"></a></td>
										</tr>
										<?php
									}
								}
							}
							$sql = "SELECT * FROM log where (tag_id = '".$sqlresult['tag_id']."' OR tag_id = '".$sqlresult['alias_tag']."') AND (DATE_FORMAT( time_in, '%Y-%m-%d' ) BETWEEN '".trim($from)."' and '".trim($to)."')";
							$query = $ci->db->query($sql);
							$sqlresult = $query->result();
							foreach($sqlresult as $datarow){
								$i++;
								?>
								<tr>
									<td><?php echo $i;?></td>
									<td><?php echo $tttag_no; ?></td>
									<td><?php echo $datarow->time_in; ?></td>
									<td><?php echo $datarow->time_out; ?></td>
									<td><a href="<?php echo base_url(); ?>index.php/Administrator/EditLogDetails/<?php echo $datarow->id; ?>/<?php echo $tag_no; ?>/<?php echo $from; ?>/<?php echo $to; ?>/<?php echo $VehicleNumber; ?>" title="Edit" class="edit_icon"></a></td>
									<td><a href="<?php echo base_url(); ?>index.php/Administrator/DeleteLog/<?php echo $datarow->id; ?>/<?php echo $tag_no; ?>/<?php echo $from; ?>/<?php echo $to; ?>/<?php echo $VehicleNumber; ?>" onclick="return chkConfirm();"title="Delete" class="delete_icon"></a></td>
								</tr>
								<?php
							}
						 ?>
							
						</tbody>
					</table>
					</form>	
				</div>
			</div>
		</div>
		<div class="clear"> </div>		
	</div>
</div>
<?php include('template/footer.php'); ?>
</body>
</html>
		