
<!DOCTYPE html>
<html lang="en">

<head>
<?php ob_start(); ?>
<?php   require_once 'head_link.php'; ?> 

</head>

<body>
 
<?php   require_once 'header1.php'; ?> 

 

<?php 

	if(isset($_POST['btnsave']))
	{
		$UserId = $_POST['UserId']; 
		$BatchNo = $_POST['BatchNo'];
		$Date = $_POST['Date'];
		
				
		if(empty($UserId)){
			$errMSG = "Please Enter Product Id.";
		}
		
		else if(empty($BatchNo)){
			$errMSG = "Please Enter Details .";
		}
		
		// if no error occured, continue ....
		if(!isset($errMSG))
		{
			$stmt = $DB_con->prepare('INSERT INTO attendance (user_id,student_id,batch_id,status,atnd_date) 
			                                   SELECT member_id, customer_id , batch_no,status,join_date FROM customer 
											   WHERE customer.batch_no=:BatchNo  ');
			
			$stmt->bindParam(':UserId',$UserId);			 
			$stmt->bindParam(':BatchNo',$BatchNo);
			$stmt->bindParam(':Date',$Date);
			
			if($stmt->execute())
			{
				?>
                <script>
				alert('Atendance Add Successfully.');
				window.location.href='atendance'; 
				</script>
                <?php
			}
			else
			{
				$errMSG = "error while inserting....";
			}
		}
	}
?>

<?php  require_once 'sidebar.php'; ?>

  <main id="main" class="main">

    <div class="pagetitle bg-light rounded p-2">
      <h1>Add New Course |  <span> <a href="product-list">    <i class="bi bi-table"></i> </a> </span> </h1> 
    </div> 
	
    <section class="section">
      <div class="row">
        <div class="col-lg-8">

          <div class="card">
            <div class="card-body">
              <h5 class="card-title">
			  <?php
	if(isset($errMSG)){
			?>
            <div class="alert alert-danger">
            	<span class="glyphicon glyphicon-info-sign"></span> <strong><?php echo $errMSG; ?></strong>
            </div>
            <?php
	}
	else if(isset($successMSG)){
		?>
        <div class="alert alert-success">
              <strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
        </div>
        <?php
	}
	?>  
			  
</h5>
			  
<form method="post" enctype="multipart/form-data" class="form-horizontal" >
	    
	<table class="table table-hover table-responsive">
	
 <tr>
    	
		<?php
				   $pq=mysqli_query($con,"select * from stuff left join `user` on user.userid=stuff.userid where stuff.userid='".$_SESSION['id']."'");
				   while($pqrow=mysqli_fetch_array($pq)){
				?>
        
        <input class="form-control" type="hidden" name="UserId"  value="<?php echo $pqrow['userid']; ?>" />
		<?php }?>
    </tr>
	 
   
  <tr>
     <td><label class="control-label">Batch Name  </label></td>
     <td>
	 <select style="width:100%;" class="form-select chosen-select" Id="BatchNo" name="BatchNo">
							<option value="#">Select Batch</option>

							<?php
							$sql = "SELECT id,batch_name FROM batch where user_id='".$_SESSION['id']."'  order by id asc";
							$result = $con->query($sql);

							while ($row = $result->fetch_array()) {
								echo "<option value='" . $row[0] . "'>" . $row[1] . " - " . $row[0] . "</option>";
							}
							?>
						</select>
	 </td>
  </tr>
  
  
    
	<tr>
    	<td><label class="control-label">Date</label></td>
        <td><input class="form-control" type="text" name="Date" placeholder="Date" value="<?php echo date("Y/m/d") ;?>" /></td>
    </tr>
	
    
    </table>
	
	 <button type="submit" name="btnsave" class="btn btn-primary">
        <span class="glyphicon glyphicon-save"></span> &nbsp; save
        </button>
	
</form>

            </div>
          </div>

          
        </div>

       
    </section>

  </main> 
  
   


    <?php  require_once 'footer1.php'; ?>
	
	
<script src = "js/chosen.js"></script>
 