<?= $this->extend("templates/hod_base"); ?>

<?= $this->section("content"); ?>
                <?php $page_session = \Config\Services::session(); $pg='vca';?>
<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4>Departmental Examinations Officers</h4>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?= base_url()?>/hod/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item active">Examinations Officers</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

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

              if($page_session->getTempdata('saveSuccess')):       
                                ?>
                                <div class = "alert alert-success alert-dismissible">
                                  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                     <?= $page_session->getTempdata('saveSuccess'); ?>
                                </div>
                                <?php 
                                endif;
                                ?>
              
                              <?php
              
                              if($page_session->getTempdata('saveError')):       
                              ?>
                              <div class = "alert alert-danger alert-dismissible">
                                  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                  <?= $page_session->getTempdata('saveError'); ?>
                              </div>
                              <?php 
                              endif;
                              ?> 
        <div class="row">
            <div class="col-12">
            <div class="card">
              <div class="card-header">
                <div class="row">
                  <div class="col-12">
                    <div id="accordion">
                      <button class="btn btn-primary btn-sm pull-right" id="add_eo" name="add_eo" data-toggle="collapse" href="#addEO"><i class="fa fa-plus"></i>  Assign Exam Officer</button>
                      <div id="addEO" class="collapse" data-parent="#accordion">
                        <hr/>
                        <span class="badge badge-danger">Default Exam officer password is 123456</span>
                        <form method="POST" action="<?= base_url('hod/exam_officers_action') ?>" id="eo_form">
                          <input type="hidden" name="action" value="add"/>
                          <div class="row">
                            <div class="col-md-4">
                              <div class="form-group">
                                <label>Session:</label>
                                <select name="session" id="session" class="form-control select2" required>
                                  <option value="" disabled selected>Select Session</option>              
                                  <option <?php if($page_session->get('current_session')=='2020/2021') echo 'selected'; ?> value = "2020/2021">2020/2021</option>
                                  <option <?php if($page_session->get('current_session')=='2021/2022') echo 'selected'; ?> value = "2021/2022">2021/2022</option>
                                  <option <?php if($page_session->get('current_session')=='2022/2023') echo 'selected'; ?> value = "2022/2023">2022/2023</option>
                                  <option <?php if($page_session->get('current_session')=='2023/2024') echo 'selected'; ?> value = "2023/2024">2023/2024</option>
                                  <option <?php if($page_session->get('current_session')=='2024/2025') echo 'selected'; ?> value = "2024/2025">2024/2025</option>
                                  <option <?php if($page_session->get('current_session')=='2025/2026') echo 'selected'; ?> value = "2025/2026">2025/2026</option>
                                  <option <?php if($page_session->get('current_session')=='2026/2027') echo 'selected'; ?> value = "2026/2027">2026/2027</option>
                                  <option <?php if($page_session->get('current_session')=='2027/2028') echo 'selected'; ?> value = "2027/2028">2027/2028</option>
                                  <option <?php if($page_session->get('current_session')=='2028/2029') echo 'selected'; ?> value = "2028/2029">2028/2029</option>
                                  <option <?php if($page_session->get('current_session')=='2029/2030') echo 'selected'; ?> value = "2029/2030">2029/2030</option>
                                  <option <?php if($page_session->get('current_session')=='2030/2031') echo 'selected'; ?> value = "2030/2031">2030/2031</option>
                                  <option <?php if($page_session->get('current_session')=='2031/2032') echo 'selected'; ?> value = "2031/2032">2031/2032</option>
                                  <option <?php if($page_session->get('current_session')=='2032/2033') echo 'selected'; ?> value = "2032/2033">2032/2033</option>
                                  <option <?php if($page_session->get('current_session')=='2033/2034') echo 'selected'; ?> value = "2033/2034">2033/2034</option>
                                  <option <?php if($page_session->get('current_session')=='2034/2035') echo 'selected'; ?> value = "2034/2035">2034/2035</option>
                                  <option <?php if($page_session->get('current_session')=='2035/2036') echo 'selected'; ?> value = "2035/2036">2035/2036</option>
                                </select>
                              </div>
                            </div>
                            <div class="col-md-4">
                              <div class="form-group">
                                <label>Staff</label>
                                <select name="staff" id="staff" class="form-control select2" required>
                                  <option value="" disabled selected>Select Staff</option>
                                  <?php foreach($staff as $st): ?>
                                  <option value='<?= $st->id ?>'><?= $st->first_name ?> <?= $st->last_name ?> <?= $st->middle_name ?></option>
                                  <?php endforeach; ?>
                                </select>
                              </div>
                            </div>
                            <div class="col-md-4">
                              <!-- <div id = "checkBoxesArea"></div> -->
                              <div class="form-group">
                                <label>Programme</label>
                                <div class="select2-primary">
                                <select name="programmes[]" id="programmes" multiple="multiple" data-placeholder="Select Programme" class="form-control select2 select2-multiple" required>
                                  <?php foreach($programmes as $prog): ?>
                                  <option value='<?= $prog->id ?>'><?= $prog->title ?></option>
                                  <?php endforeach; ?>
                                </select>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="row" align="right">
                            <div class="col-12">
                              <input type="submit" name="submit" id="submit_button" value="Submit" class="btn btn-primary pull-right">
                            </div>
                          </div>
                        </form>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <div class="table-responsive">
                  <table id="eo_tbl" class="table table-bordered table-hover table-striped medium" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                          <th>#</th>
                          <th>Staff Name</th>
                          <th>Programme(s)</th>
                          <th>Session</th>
                          <th>Created On</th>
                          <th class="text-center">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                      <?php 
                      if(is_array($eos)){
                        $i=1;
                        foreach($eos as $eo):
                       ?>
                        <tr>
                          <td><?= $i++?></td>
                          <td><?= $eo->name?></td>
                          <td>
                            <ul>
                            <?php
                              $program = explode(',',$eo->programme_id);
                              foreach($program as $prog){
                                $pdetail = $model->get_program_details($prog);
                            ?>
                                <li><?=$pdetail[0]->title?></li>
                            <?php
                              }
                            ?>
                              </ul>
                            </td>
                          <td><?= $eo->session?></td>
                          <td><?= date('h:i a - d M, Y', strtotime($eo->created_at))?></td>
                          <td class="text-center"><button class="btn btn-danger btn-xs delete_btn" data-id="<?= $eo->id?>"><i class="fas fa-trash"></i></button></td>
                        </tr>
                      <?php endforeach; 
                      }
                      ?>
                    </tbody>
                  </table>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
            </div>
        </div>

        </div><!-- /.container-fluid -->
    </section>
<!-- /.content -->
</div>

<?= $this->endSection(); ?>