<?php
include '../connect.php';
$id = $_POST['id'];
$program_id = $_POST['program_id'];
$sql = "SELECT I.fullName, I.email, I.major, I.university, I.graduationDate,PI.status
FROM intern I
INNER JOIN program_intern PI ON I.id = PI.intern_id
INNER JOIN program P ON PI.program_id = P.id
WHERE P.instructor_id = $id
AND P.id = $program_id";
$_result = mysqli_query($con, $sql);
$count=mysqli_num_rows($_result);
if($_result){

?>
<table class="table">
<?php
if($count){
    ?>
  <thead>
                  <tr>
                  <th>Name</th>
                  <th>Email</th>
                  <th>Uni</th>
                  <th>Major</th>
                  <th>Status</th>
                  <th>Graduation Date</th>
                  </tr>
                  <?php } else{
                    echo "Sorry, No Interns Enrolled in this Program for the Selected Instructor.";
                  } ?>
                </thead>
                <tbody>
            <?php
                     while ($row = mysqli_fetch_assoc($_result)) {
            ?>
              <tr>
                  <td><?php echo $row['fullName']?></td>
                  <td><?php echo $row['email']?></td>
                  <td><?php echo $row['major']?></td>
                  <td><?php echo $row['university']?></td>
                  <?php 
                  if($row['status']=='pending'){ ?>
                   <td class="align-middle  text-sm">
                        <span class="badge badge-sm bg-gradient-warning"><?php echo $row['status']?></span>
                      </td>
                 <?php } ?>
                 <?php 
                  if($row['status']=='accepted'){ ?>
                   <td class="align-middle  text-sm">
                        <span class="badge badge-sm bg-gradient-success"><?php echo $row['status']?></span>
                      </td>
                 <?php } ?>
                 <?php 
                  if($row['status']=='rejected'){ ?>
                   <td class="align-middle  text-sm">
                        <span class="badge badge-sm bg-gradient-danger"><?php echo $row['status']?></span>
                      </td>
                 <?php } ?>
                  <td><?php echo $row['graduationDate']?></td>
                  </tr>
                  <?php } ?>
                </tbody>
</table>
<?php 
}else{
    echo mysqli_error($con);
}
?>