<?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 Camp</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 Camp</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 Camp</h3>
          <div class="card-tools">
             <a href="<?php echo base_url()?>/admin/sharnarthi/add_new_camp" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Camp</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_camp as $key => $camp):
                $added_by = $user->get_user_by_id($camp->camp_added_by);
                ?>
                <tr>
                   <td><?php echo $i ?></td>
                   <td>
                     <?php echo $camp->camp_name; ?>
                   </td>
                   <td>
                     Head Name : <b><?php echo $camp->camp_head_name; ?></b>

                     <?php if($camp->camp_pin_code): ?>
                     <br/>
                     Address : <b><?php echo $camp->camp_address; ?>, <?php echo $camp->camp_post_office; ?>, <?php echo $camp->camp_dist; ?>, <br/><?php echo $camp->camp_state; ?> - <?php echo $camp->camp_pin_code; ?></b>
                     <?php endif; ?>
                     <?php if($camp->camp_rating > 0): ?>
                        <br/>
                        Rating : 
                        <?php 
                        $rating = $camp->camp_rating; // Example rating value
                           $stars = "";
                           for ($i = 1; $i <= 5; $i++) {
                               if ($i <= $rating) {
                                   $stars .= '<span class="fa fa-star"></span>';
                               } elseif ($i - $rating <= 0.5) {
                                   $stars .= '<span class="fa fa-star-half-o"></span>';
                               } else {
                                   $stars .= '<span class="fa fa-star-o"></span>';
                               }
                           }

                           echo $stars;
                        ?>
                     <?php endif;?>
                     <?php if($camp->camp_review): ?>
                        <br/>
                        Review : <?php echo $camp->camp_review; ?>
                     <?php endif; ?>
                   </td>
                   <td>
                     <?php if($camp->camp_added_by == 2 || $camp->camp_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>
                        <a href="javascript:void(0)" onclick="rating_modal_open(<?php echo $camp->camp_id; ?>)" class="btn btn-dark btn-sm"><i class="fa fa-star" aria-hidden="true"></i></a>
                        <?php if(check_user_permission('edit')): ?>
                           <a href="<?php echo base_url()?>/admin/sharnarthi/edit_camp/<?php echo $camp->camp_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/sharnarthi/delete_camp/<?php echo $camp->camp_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>
<script type="text/javascript">
function rating_modal_open(e) 
{
   $('#rating_modal').modal('show');
   $('#id_camp').val(e);

}
</script>
<div class="modal fade" id="rating_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Camp Rating (शिविर मूल्यांकन)</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      <?php echo form_open_multipart('admin/sharnarthi/add_camp_review'); ?>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Rating (मूल्यांकन) <span class="required">*</span></label>
            <select type="text" class="form-control" name="camp_rating" required>
                <option value="">Select</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
            </select>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Review (समीक्षा)</label>
            <textarea class="form-control" id="message-text" name="camp_review"></textarea>
          </div>
          <div class="form-group">
            <label for="inputName" class="col-sm-12 col-form-label">Image 1 (छवि 1)</label>
            <div class="col-sm-12">
               <input type="file" name="camp_image_1" class="form-control" placeholder="Camp State" >
            </div>
         </div>
         <div class="form-group">
            <label for="inputName" class="col-sm-12 col-form-label">Image 2 (छवि 2)</label>
            <div class="col-sm-12">
               <input type="file" name="camp_image_2" class="form-control" placeholder="Camp State" >
            </div>
         </div>
         <div class="form-group">
            <label for="inputName" class="col-sm-12 col-form-label">Image 3 (छवि 3)</label>
            <div class="col-sm-12">
               <input type="file" name="camp_image_3" class="form-control" placeholder="Camp State" >
            </div>
         </div>
         </div>
         <input type="hidden" name="camp_id" id="id_camp">
         <div class="modal-footer">
           <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
           <button type="submit" class="btn btn-primary">Submit</button>
         </div>
      <?php echo form_close();?>
    </div>
  </div>
</div>
<style type="text/css">
.fa-star
{
   color: orange;
}
.fa-star-o
{
   color: #000;
}
</style>