<?php 
use App\Models\UserModel;
use App\Models\AdmissionModel;
$user = new UserModel();
$adm = new AdmissionModel();
?>
<div class="content-wrapper">
  <div class="content-header">
     <div class="container-fluid">
        <div class="row mb-2">
           <div class="col-sm-6">
              <h1 class="m-0 text-dark">All Admission</h1>
           </div>
           <div class="col-sm-6">
              <ol class="breadcrumb float-sm-right">
                 <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
                 <li class="breadcrumb-item"><a href="#">Admission</a></li>
                 <li class="breadcrumb-item active">All Admission</li>
              </ol>
           </div>
        </div>
     </div>
  </div>

  <section class="content">
    <div class="container-fluid">
      <div class="card card-default">
        <div class="card-header">
          <h3 class="card-title">View All Admission</h3>
          <div class="card-tools">
             <a href="<?php echo base_url()?>/admin/admission/add_new_admission" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Admission</a>
          </div>
        </div>
        <div class="card-body">
           <table id="example1" class="table table-bordered table-striped">
             <thead>
                <tr>
                   <th>id</th>
                   <th>Name & Photo</th>
                   <th>Details</th>
                   <th>Course</th>
                   <th>Added By</th>
                   <?php if(check_user_permission('delete') || check_user_permission('edit')): ?>
                     <th></th>
                  <?php endif;?>
                </tr>
             </thead>
             <tbody>
                <?php $i=1; foreach ($all_admission as $key => $admission):
                $added_by = $user->get_user_by_id($admission->user_added_by);
                $all_course = $adm->get_all_course_by_student_id($admission->user_id);
                ?>
                <tr>
                   <td><?php echo $i ?></td>
                   <td>
                     <?php echo $admission->user_name; ?>
                      <br/>
                      <br/>
                      <?php if(file_exists(substr($admission->user_image, 1))): ?>
                        <img src="<?php echo base_url(); ?><?php echo $admission->user_image; ?>" width="70px">
                     <?php endif;?>
                   </td>
                   <td>
                     Guardian : <b><?php echo $admission->guardian_name ?></b>
                     <br/>
                     Mob. : <b><?php echo $admission->user_mobile ?></b>
                    <?php if($admission->user_email): ?>
                      <br/>
                      Email : <b><?php echo $admission->user_email ?></b>
                    <?php endif;?>
                    <br/>
                    Gender : <b><?php echo $admission->user_gender ?></b>
                    <?php if($admission->user_dob): ?>
                      <br/>
                      DOB : <b><?php echo date('d-m-Y', strtotime($admission->user_dob)); ?></b>
                    <?php endif; ?>
                    <?php if($admission->user_education): ?>
                      <br/>
                      Qulification : <b><?php echo $admission->user_education ?></b>
                    <?php endif; ?>
                    <?php if($admission->user_pin_code): ?>
                      <br/>
                      Address : <b>
                      <?php echo $admission->user_address ?>, <?php echo $admission->user_post ?>, <br/><?php echo $admission->user_dist ?>, <br/><?php echo $admission->user_state ?> - <?php echo $admission->user_pin_code ?></b>
                    <?php endif;?>
                   </td>
                   <td>
                      <?php foreach ($all_course as $key => $course) 
                      {
                         echo '<span class="badge badge-success">'.$course->course_name.'</span><br/>';
                      }?>
                   </td>
                   <td>
                     <?php if($admission->user_added_by == 2): ?>
                        <b>Admin</b>
                     <?php else: ?>
                        <b><?php echo $added_by->user_name; ?></b>
                     <?php endif;?>
                   </td>

                   <?php if(check_user_permission('delete') || check_user_permission('edit')): ?>
                      <td>
                        <?php if(check_user_permission('edit')): ?>
                           <a href="<?php echo base_url()?>/admin/admission/edit_admission/<?php echo $admission->user_rand_code; ?>" class="btn btn-info btn-sm"><i class="fa fa-edit" aria-hidden="true"></i></a>
                        <?php endif; ?>
                        <?php if(check_user_permission('delete')): ?>
                           <a class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')" href="<?php   echo base_url() ?>/admin/admission/delete_admission/<?php echo $admission->user_rand_code ?>"><i class="fa fa-trash" aria-hidden="true"></i></a>
                        <?php endif; ?>
                      </td>
                  <?php endif;?>
                </tr>
                <?php $i++; ?>
                <?php endforeach; ?>
             </tbody>
          </table>
        </div>
      </div>
    </div>
  </section>
</div>
