<?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 Batch</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 Batch</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 Batch</h3>
          <div class="card-tools">
             <a href="<?php echo base_url()?>/admin/admission/add_new_batch" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Batch</a>
          </div>
        </div>
        <div class="card-body">
           <table id="example1" class="table table-bordered table-striped">
             <thead>
                <tr>
                   <th>id</th>
                   <th>Batch Name</th>
                   <th>Batch Details</th>
                   <th>Batch Timing</th>
                   <?php if(check_user_permission('delete') || check_user_permission('edit')): ?>
                     <th></th>
                  <?php endif;?>
                </tr>
             </thead>
             <tbody>
                <?php $i=1; foreach ($all_batch as $key => $batch):
                $added_by = $user->get_user_by_id($batch->batch_added_by);?>
                <tr>
                   <td><?php echo $i ?></td>
                   <td><?php echo $batch->batch_name; ?></td>
                   <td>
                     Size : <b><?php echo $batch->batch_size; ?></b>
                     <br/>
                     Start : <b><?php echo date('d-m-Y', strtotime($batch->batch_start_date)); ?></b>
                     <br/>
                     Course : <b><?php echo $batch->course_name; ?></b>
                     <br/>
                     Teacher : <b><?php echo $batch->user_name; ?></b>
                     <br/>
                     Room No. : <b><?php echo $batch->batch_room_no; ?></b>
                     <br/>
                     <?php if($batch->batch_added_by == 2): ?>
                        Added By : <b>Admin</b>
                     <?php else: ?>
                        Added By : <b><?php echo $added_by->user_name; ?></b>
                     <?php endif;?>
                   </td>
                   <td>
                      <?php foreach (json_decode($batch->batch_timing_details) as $day => $time): ?>
                         <?php if (!empty($time->start) || !empty($time->end)): ?>
                             <span><?php echo $day; ?> : <b><?php echo date('h:i a', strtotime($time->start)); ?></b> to <b><?php echo date('h:i a', strtotime($time->end)); ?></b></span><br/>
                         <?php endif; ?>
                       <?php endforeach; ?>
                   </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_batch/<?php echo $batch->batch_id; ?>" 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_batch/<?php echo $batch->batch_id ?>"><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>
