<?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>All Pages</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">All Pages</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">
                <h3 class="card-title">View All Pages</h3>
                <div class="card-tools">
                  <a href="<?php echo base_url()?>admin/live_class_page/add_new_page"><button type="button" class="btn btn-success btn-sm">Add New Page</button></a>
               </div>
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Page Name</th>
                      <th>Page Link</th>
                      <th>Show Popup</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($all_pages as $key => $data):?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo  $data->live_class_heading; ?></td>

                      <td><a href="<?php echo base_url(); ?>trail/<?php echo  $data->live_class_slug; ?>" target="_blank">Go To Page</a></td>
                      <td>
                        <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                            <input onchange="update_specials_status(this)" type="checkbox" name="status<?php echo $i?>" class="custom-control-input" id="customSwitch1<?php echo $i?>" <?php if($data->live_class_popup == 1){echo 'checked';} ?> value="<?php echo $data->live_class_id ?>">
                            <label class="custom-control-label" for="customSwitch1<?php echo $i?>"></label>
                         </div>
                      </td>
                      <td><a href="<?php echo base_url() ?>admin/live_class_page/update_page/<?php echo $data->live_class_id ?>" class="btn btn-info btn-sm"><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/live_class_page/delete_page/<?php echo $data->live_class_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>
<script type="text/javascript">
function update_specials_status(el)
   {
      if(el.checked){
           var status = 1;
       }
       else{
           var status = 0;
       }
       $.post('<?php echo base_url(); ?>/admin/live_class_page/update_specials_status', 
         {id:el.value,status:status
         }, 
         function(data){
           if(data == 1){
               location.reload();
           }
           else{
               alert(data);
           }
       });
   }
</script>