<?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 Course</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 Course</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 Course</h4>
              
              <?php 
              $course_id      = user()->course;
              $course_last_id = user()->course_pay_last_id;
              $this->db->select('a.title, a.image, a.duration, a.course_adv_payment, a.online_training_price, a.online_training_discount, a.special_fb_group, a.special_whatsapp_group, b.*');
              $this->db->from('course a');
              $this->db->join('course_inquery b', 'b.course_inq_course_id = a.id', 'left');
              $this->db->where('a.id', $course_id);
              $this->db->where('b.course_inq_id', $course_last_id);
              $course = $this->db->get()->row();
              ?>  
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                           <th>Image</th>
                           <th>Name</th>
                           <th>Pay Amount</th>
                           <th>Due</th>
                            <th>Join Community</th>
                           <th></th>
                          
                        </tr>
                     </thead>
                     <tbody>
                      <?php if($course): ?>
                        <tr>
                           <td>
                              <img src="<?php echo base_url() ?><?php echo $course->image ?>" alt="Product 1" class="img-size-32 mr-2">
                           </td>
                           <td><?php echo $course->title; ?></td>
                           <td>&#x20B9;<?php echo $course->course_inq_pay_amount; ?></td>
                           <td>&#x20B9;<?php if($course->online_training_discount)
                            {
                              $main_p =  $course->online_training_discount;
                            }
                            else
                            {
                              $main_p = $course->online_training_price;
                            }; 

                            echo $ppt =  $main_p - $course->course_inq_pay_amount; ?>
                              
                            </td>
                             <td>
                                <?php if($product->special_fb_group): ?>
                                  <a href="<?php echo $course->special_fb_group ?>" target="_blank" class="nav-link btn btn-xs" style="background-color: #4267B2;color: #fff;border-color:#4267B2;"> <i class="fa fa-facebook"></i> Facebook Community</a>
                                <?php endif; ?>
                                <?php if($product->special_whatsapp_group): ?>
                                  <a href="<?php echo $course->special_whatsapp_group ?>" target="_blank" class="nav-link btn btn-xs" style=" background-color: #25D366;color: #fff; border-color:#25D366;"><i class="fa fa-whatsapp"></i> WhatsAppp Community</a>
                                <?php endif; ?>
                              </td>
                            <td>
                              <?php if($ppt == 0):?>
                                <span class="badge badge-success">Paid</span>
                              <?php else: ?>
                                <a href="<?php echo base_url()?>admin/course/pay_due_amount/<?php echo $course->course_inq_id ?>" class="btn btn-success btn-xs">Pay Due Amount</a>
                              <?php endif;?>
                            </td>
                            
                        </tr>
                        <?php else:?>
                          <tr>
                            <td class="text-center" colspan="6">No Course Found</td>
                          </tr>
                        <?php endif;?>
                     </tbody>
                    
                  </table>
                </div>
              </div>
            </div>
          </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
