<?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 Sharnarthi</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="#">Sharnarthi</a></li>
                 <li class="breadcrumb-item active">All Sharnarthi</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 Sharnarthi</h3>
          <div class="card-tools">
             <a href="<?php echo base_url()?>/admin/sharnarthi/add_new_sharnarthi" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Sharnarthi</a>
          </div>
        </div>
        <div class="card-body">
           <table id="example1" class="table table-bordered table-striped">
             <thead>
                <tr>
                   <th>id</th>
                   <th>Name</th>
                   <th>Details</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_sharnarthi as $key => $sharnarthi):
                $added_by = $user->get_user_by_id($sharnarthi->sharnarthi_added_by);
                ?>
                <tr>
                   <td><?php echo $i ?></td>
                   <td>
                     <?php echo $sharnarthi->sharnarthi_name; ?>
                   </td>
                   <td>
                     Gender : <b><?php echo $sharnarthi->sharnarthi_gender; ?></b>
                     <br/>
                     Age : <b><?php echo $sharnarthi->sharnarthi_age; ?></b>
                     <br/>
                     Migrated From : <b><?php echo $sharnarthi->sharnarthi_migrated_from; ?></b>
                     <br/>
                     Religion : <b><?php echo $sharnarthi->sharnarthi_religion; ?></b>
                     <br/>
                     Living Since : <b><?php echo $sharnarthi->sharnarthi_living_since; ?></b>
                   </td>
                   <td>
                     <?php if($sharnarthi->sharnarthi_added_by == 2 || $sharnarthi->sharnarthi_added_by == 3): ?>
                        <b><?php echo $added_by->user_name; ?> (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="#" 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/sharnarthi/delete_sharnarthi/<?php echo $sharnarthi->sharnarthi_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>
