<?php 
use App\Models\UserModel;
$user = new UserModel();
?>
<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 Course</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 Course</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 Course</h3>
          <div class="card-tools">
             <a href="<?php echo base_url()?>/admin/admission/add_new_course" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Course</a>
          </div>
        </div>
        <div class="card-body">
           <table id="example1" class="table table-bordered table-striped">
             <thead>
                <tr>
                   <th>id</th>
                   <th>Course Name</th>
                   <th>Course Duration</th>
                   <th>Course 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_course as $key => $course):
                $added_by = $user->get_user_by_id($course->course_added_by);?>
                <tr>
                   <td><?php echo $i ?></td>
                   <td><?php echo $course->course_name; ?></td>
                   <td><?php echo $course->course_duration; ?> Months</td>
                   <td>
                      <?php if($course->course_added_by == 2): ?>
                        Added By : <b>Admin</b>
                     <?php else: ?>
                        Added By : <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_course/<?php echo $course->course_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_course/<?php echo $course->course_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>
