<?php
    $errors = $this->session->userdata('errors');
    if (isset($errors)) {
        ?>
        <script>
            swal ( "Oops" ,  "<?php echo $errors ?>" ,  "error" )
        </script>
        <?php echo $errors ?>
        <?php
        $this->session->unset_userdata('errors');
    }
    $error = $this->session->userdata('error');
    if (isset($error)) {
        ?>
         <script>
            swal ( "Oops" ,  "<?php echo $error ?>" ,  "error" )
        </script>
        <?php
        $this->session->unset_userdata('error');
    }
    $success = $this->session->userdata('success');
    if (isset($success)) {
        ?>
         <script>
            swal({
          title: "Done!",
          text: "<?php echo $success ?>",
          icon: "success",
        });
        </script>
        <?php
        $this->session->unset_userdata('success');
    }
    ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>View All Branch Shedule</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo admin_url() ?>admin">Home</a></li>
              <li class="breadcrumb-item active">View All  Branch Shedule</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">

          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h4>All Branch Shedule</h4>
                
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Branch</th>
                      <th>Date</th>
                      <th>Days</th>
                      <th>Class Time</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($get_all_branch_shedule as $key => $shedule):
                    $branch = $this->branch->get_branch_by_id_id($shedule->branch);?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo $branch->name ?></td>
                      <td><?php echo $shedule->date ?></td>
                      <td><?php echo $shedule->days ?></td>
                      <td><?php echo $shedule->time ?> <br/>
                        <i style="font-size: 12px;"><?php echo $shedule->time_sub ?></i></td>
                      <td>
                        <a class="btn btn-success btn-sm"  data-toggle="modal" data-target="#update-category<?php echo $shedule->id ?>"><i class="fa fa-edit" aria-hidden="true"></i></a>
                        <a class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>admin/branch/delete_shedule/<?php echo $shedule->id ?>"><i class="fa fa-trash" aria-hidden="true"></i></a>
                      </td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
              </div>
            </div>
          </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
<?php $i=1; foreach ($get_all_branch_shedule as $key => $shedule):?>
<div class="modal fade" id="update-category<?php echo $shedule->id ?>">
  <div class="modal-dialog">
    <div class="modal-content bg-primary">
      <div class="modal-header">
        <h4 class="modal-title">Update Schedule</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span></button>
      </div>
      <?php echo form_open('admin/branch/update_shedule'); ?>
      <div class="modal-body">
          <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Select Branch</label>
                   <div class="col-sm-12">
                      <select id="showing" class="form-control"  name="branch" required="">
                        <option value="">Select Cateory</option>
                          <?php foreach ($all_branch as $key => $branch):?>
                            <option <?php if($branch->id == $shedule->branch){echo 'selected';}?> value="<?php echo $branch->id ?>"><?php echo $branch->name ?></option>
                          <?php endforeach; ?>
                      </select>
                   </div>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Date <span class="required">*</span></label>
                   <div class="col-sm-12">
                      <input class="form-control"  name="date" placeholder="Enter Category Name" required="required" type="date" value="<?php echo date('Y-m-d', strtotime($shedule->date));?>">
                   </div>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Days <span class="required">*</span></label>
                   <div class="col-sm-12">
                      <input class="form-control"  name="days" placeholder="Enter Days Ex - Mon to Fri" required="required" type="text" value="<?php echo $shedule->days ?>">
                      <input class="form-control"  name="id" placeholder="Enter Days Ex - Mon to Fri" required="required" type="hidden" value="<?php echo $shedule->id ?>">
                   </div>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Is Weekdays Batch <span class="required">*</span></label>
                   <div class="col-sm-12">
                      <select class="form-control"  name="is_weekdays" placeholder="Enter Days Ex - Mon to Fri" required="required" type="text">
                       <option <?php if($shedule->is_weekdays == 1){echo 'selected';}?> value="1">Yes</option>
                       <option <?php if($shedule->is_weekdays == 0){echo 'selected';}?> value="0">No</option>
                      </select>
                   </div>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Time <span class="required">*</span></label>
                   <div class="col-sm-12">
                      <input class="form-control"  name="time" placeholder="Enter 8:00 AM " required="required" type="text" value="<?php echo $shedule->time ?>">
                   </div>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                   <label for="inputEmail" class="col-sm-12 col-form-label">Time Sub Heading<span class="required">*</span></label>
                   <div class="col-sm-12">
                      <input class="form-control"  name="time_sub" placeholder="Ex. (Class 1Hr - 3Hr) / Per Session" required="required" type="text"  value="<?php echo $shedule->time_sub ?>">
                   </div>
                </div>
              </div>

            
          </div>
      </div>
      
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-outline-light" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-outline-light">Save changes</button>
      </div>
      <?php echo form_close() ?>
    </div>

  </div>
  <!-- /.modal-dialog -->
</div>

<?php endforeach; ?>
