<?php 
    session_start();
    if(!$_SESSION['id']){
        header('location:index.php');
    }
    require_once '../system/conn.php';
?>
<!doctype html>
<html lang="en" class="semi-dark">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="assets/css/pace.min.css" rel="stylesheet" />
	<script src="assets/js/pace.min.js"></script>
    <link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
    <link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
    <link href="assets/plugins/datatable/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/bootstrap-extended.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/icons.css" rel="stylesheet">
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <link href="assets/css/dark-theme.css" rel="stylesheet" />
    <link href="assets/css/semi-dark.css" rel="stylesheet" />
    <link href="assets/css/header-colors.css" rel="stylesheet" />
    <title>Multi Site Attendance</title>
  </head>
  <body>
    <div class="wrapper">
    <?php include'system/header.php'?>
	    <div class="page-content-wrapper">
         <div class="page-content">
          <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
            <div class="breadcrumb-title pe-3">Multi Site Attendance</div>
            <div class="ms-auto">
                <a href="excel-multi-attendance.php"><button type="button" class="btn btn-primary px-5">Excel Download</button></a>
            </div>
          </div>
		  <hr/>
		  <div class="card">
			<div class="card-body">
			  <div class="table-responsive">
				<table id="example2" class="table table-striped table-bordered">
					<thead>
					  <tr>
						<th>SR No</th>
            			<th>Id No</th>
                        <th>Employee Name</th>
                        <th>Designation</th>
                        <th>Month</th>
                        <th>Year</th>
                        <th>Site</th>
                        <th>Attendance</th>
					  </tr>
					</thead>
					<tbody>
					  <?php
                        $date=date('m-d-Y', strtotime(date('Y-m')." -1 month"));
                        $date=explode('-',$date);
                        $month=$date[0];
                        $year=$date[2];
                        //print_r($month);exit;
                        $cnt = 1;
                        $stmt = $conn->prepare(" SELECT * FROM `prv_attendance` ");
                        $stmt->execute();
                        $sql = $stmt->fetchAll();
                        foreach($sql as $row) 
                        { ?>
                        <tr>
                            <td><?php echo $cnt;?></td>
                            <?php
                              $sth = $conn->prepare(" SELECT * FROM `emp_details` where `e_id`='".$row['emp_id']."' ");
                              $sth->execute();
                              $row1 = $sth->fetch(PDO::FETCH_ASSOC); 
                            ?>
                            <td>
                                <a href="view-details-all-emp.php?id=<?php echo $row1['sn'];?>"><?php echo $row['emp_id'];?></a>
                            </td>
                            <td><?php echo $row1['e_name']; ?></td>
                            <td><?php echo $row1['designation']; ?></td>
                            <td>
                              <?php 
                              $monthNum  = $row['month'];
                              $dateObj   = DateTime::createFromFormat('!m', $monthNum);
                              echo $monthName = $dateObj->format('F');
                              ?>
                            </td>
                            <td><?php echo $row['year'];?></td>
                            <td>
                                <?php 
                                    $sth1 = $conn->prepare(" SELECT * FROM `site` where `id`='".$row['site']."' ");
                                    //print_r($sth1);exit;
                                    $sth1->execute();
                                    $row2 = $sth1->fetch(PDO::FETCH_ASSOC);
                                ?>
                                <?php echo $row2['name']; ?>
                            </td>
                            <td><?php echo $row['prv_attendance'];?></td>
                        </tr>
                        <?php  $cnt=$cnt+1; }?>
					</tbody>
					<tfoot>
					    <tr>
						    <th>SR No</th>
            				<th>Id No</th>
                            <th>Employee Name</th>
                            <th>Designation</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Site</th>
                            <th>Attendance</th>
						</tr>
					</tfoot>
				</table>
			  </div>
			</div>
		  </div>
             
        </div>
    </div>
<?php include'system/footer.php'?>