<?PHP
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Attendance</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Attendance
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->
<br />

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->
                                
<script type="text/javascript" src="bootstrap/jquery.js"></script>      
                <link rel="stylesheet" href="css/colorbox.css" />
		<script src="lib/jquery.colorbox.js"></script>
		<script>
			$(document).ready(function(){
				//Examples of how to assign the Colorbox event to elements
				$(".group1").colorbox({rel:'group1', width:"50%", height:"75%"});
				});
		</script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#register').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:11px;color:#ff0000;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
	});
	
});	

</script>

<script type="text/javascript">
				          $(document).ready( function() {
				        	  // Select all
				              $("A[href='#select_all']").click( function() {
				                  $("#" + $(this).attr('rel') + " INPUT[type='checkbox']").attr('checked', true);
				                  return false;
				              });

				              // Select none
				              $("A[href='#select_none']").click( function() {
				                  $("#" + $(this).attr('rel') + " INPUT[type='checkbox']").attr('checked', false);
				                  return false;
				              });

				              // Invert selection
				              $("A[href='#invert_selection']").click( function() {
				                  $("#" + $(this).attr('rel') + " INPUT[type='checkbox']").each( function() {
				                      $(this).attr('checked', !$(this).attr('checked'));
				                  });
				                  return false;
				              });
					           
						   });
			    </script>

        
<?php

if($_GET['id'])
{
	
	$id=$_GET['id'];
	
	$sel=mysql_query("select * from attendance where entryno='$id'");
	$sel1=mysql_fetch_array($sel);
	
	echo"<center><table>
	<tr><td>Entry No.</td><td>: ".$sel1['entryno']."</td><td style='width:350px;'></td><td>Date</td><td>: ".date('d-m-Y',strtotime($sel1['date']))."</td></tr>
	</table><br />";
	
	echo"<table class='table table-bordered table-condensed' style='width:75%; margin:auto;'>
	
	<thead><tr><th>Emp ID</th><th>Name</th><th>Department</th><th>Time In</th><th>Time Out</th></tr></thead>";
	
	$gsel=mysql_query("select * from attendance where entryno='$id' order by empid asc");
	while($gsel1=mysql_fetch_array($gsel))
	{
		
		$emp=mysql_query("select * from employee where empid='$gsel1[empid]'");
		$emp1=mysql_fetch_array($emp);
		
		$dept=mysql_query("select * from department where ID='$emp1[department]'");
		$dept1=mysql_fetch_array($dept);
		
		echo"<tr><td>".$emp1['empid']."</td><td>".$emp1['name']."</td><td>".$dept1['department']."</td>
		<td>".date('g:i A', strtotime($gsel1['timein']))."</td>
		<td>".date('g:i A', strtotime($gsel1['timeout']))."</td></tr>";
		
	}
	
	echo"</table><br /><br />";
	
	
	echo"<b style='color:red;'>Absentees</b><br />
	
	<table class='table table-bordered table-condensed' style='width:75%; margin:auto;'>
	
	<thead><tr><th style='width:15%;'>Emp.ID</th><th style='width:30%;'>Name</th><th style='width:20%;'>Department</th></tr></thead>";
	
	$emab=mysql_query("select * from employee where (status='' or dor>'$sel1[date]') order by ID asc");
	while($emab1=mysql_fetch_array($emab))
	{
		
		$lm=mysql_query("select * from attendance where entryno='$id' and empid='$emab1[ID]'");
		$lm1=mysql_num_rows($lm);
		
		$dept=mysql_query("select * from department where ID='$emab1[department]'");
		$dept1=mysql_fetch_array($dept);
		
		if($lm1==0)
		{
		echo"<tr><td>".$emab1['empid']."</td><td>".$emab1['name']."</td><td>".$dept1['department']."</td></tr>";
		}
		
	}
	
	echo"</table><br />";
	
	
	echo"<center><a href='viewattendance.php'>Back</a></center>";
	
}
else
{

if (isset($_GET['s'])) 
	
	{
	 $status=$_GET['s'];
	 
	 	if($status=='1')
		 {
           echo'<div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <span style="text-align:left;">Attendance Time in Added Successfully.</span>
                </div>';
		}
		 
		elseif($status=='2')
		{
           echo'<div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                Time Out Added Successfully.
                </div>';
		}
		
		elseif($status=='3')
		{
           echo'<div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                Time Out Added Successfully.
                </div>';
		}
		
		elseif($status=='4')
		{
           echo'<div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                Values Edited Successfully.
                </div>';
		}
		
	}


echo"<br />
<a href='attendance.php' style='margin-left:14%;'>Add Time In</a>
<center><table style='width:75%; margin:auto;'><tr><td>
<table id='dynamic-table' class='table table-striped table-bordered table-condensed'>
<thead><tr><th width='10%'>Date</th><th width='15%'>Entry No</th>
<th style='width:12%;'>No.of Present</th><th style='width:12%;'>No.Of Absent</th><th width='15%'>Actions</th></tr></thead><tbody>";

$g=mysql_query("select * from attendance group by entryno");
$csk=mysql_num_rows($g);

if($csk>0)
{

while($g1=mysql_fetch_array($g))
{        

	$tem=mysql_query("select * from employee where (status='' or (status!='' and dor>'$g1[date]'))");
	$tem1=mysql_num_rows($tem);
	
	$pre=mysql_query("select * from attendance where entryno='$g1[entryno]'");
	$pre1=mysql_num_rows($pre);
	
	$abs=$tem1-$pre1;

echo"<tr><td>".date('d-m-Y',strtotime($g1['date']))."</td><td>".$g1['entryno']."</td>

<td>".$pre1."</td><td>".$abs."</td>

<td>";

if($g1['timeout']=='00:00:00')
{
echo"<a href='editattendance.php?id=".$g1['entryno']."'>Time Out</a> &nbsp; ";
}

echo"<a href='viewattendance.php?id=".$g1['entryno']."'><i class='fa fa-search-plus'></i></a> &nbsp; 
<a href='editattendance1.php?id=".$g1['entryno']."'><i class='fa fa-pencil'></i></a> &nbsp; 
<a href='del.php?id=".$g1['entryno']."&desc=attendance' title='Delete'><i class='fa fa-trash-o'></i></a></td></tr>";
}

}

else
{
echo"<tr><td colspan='5' height='35' style='text-align:center; padding:25px 0 10px 0;'>No Records Found</td></tr>";
}

echo"</tbody></table></td></tr></table><br />";

}

?>

 </div>
 </div>
 
 <link rel="stylesheet" href="bootstrap/dataTables.tableTools.css">
    
    <link rel="stylesheet" href="css/datepicker.css">

<script src="bootstrap/jquery-1.7.2.min.js"></script>
        <script src="bootstrap/bootstrap-datepicker.js"></script>

    <script>
         
    
	$('.datepicker').datepicker();
	
</script>

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					

</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->


<?php

include 'bottom.php';

}
else
{

 header("location:login.php");
}

?>