<?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 Batches</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 Batches</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>Add New Batches</h4>
                
              </div>
              <!-- /.card-header -->
              <?php echo form_open(base_url().'admin/frontend_setting/add_new_batch'); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-8">
                    <div class="form-group">
                      <label>Select Course<span class="required">*</span></label>
                      <select name="batches_course" class="form-control" placeholder="Enter Title" required="">
                        <option value="">Select</option>
                        <?php foreach ($all_course as $course):?>
                          <option value="<?php echo $course->id ?>"><?php echo $course->title ?></option>
                        <?php endforeach;?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Select Category<span class="required">*</span></label>
                      <select name="batches_category" class="form-control" placeholder="Enter Title" required="">
                        <option value="">Select</option>
                        <option value="1">Self Paced Video Course</option>
                        <option value="2">Live Online Classroom </option>
                        <option value="3">Live Face2Face Class</option>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Batch Description<span class="required">*</span></label>
                      <textarea name="batches_description" class="form-control" placeholder="Enter Description"></textarea>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Batch Start date</label>
                      <input type="date" name="batches_start_date" class="form-control" placeholder="Enter Tag" required>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Batch Tag</label>
                      <input type="text" name="batches_tag" class="form-control" placeholder="Enter Tag" >
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Batch Color</label>
                      <input type="color" name="batches_color" class="form-control" placeholder="Enter Tag" >
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                    <label for="inputEmail" class="col-sm-12 col-form-label">Batch Option<span class="required">*</span></label>
                    <div class="table-responsive">
                       <table class="table table-bordered" id="dynamic_field">
                          <tr>
                             <td><input type="text" name="batches_options[]" class="form-control name_list" placeholder="Enter Content" required="" /></td>
                             <td><button type="button" name="add" id="add" class="btn btn-primary">+</button></td>
                          </tr>
                       </table>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                    <label for="inputEmail" class="col-sm-12 col-form-label">Self-Paced Program<span class="required">*</span></label>
                    <div class="table-responsive">
                       <table class="table table-bordered" id="programme_field">
                          <tr>
                             <td><input type="date" name="programme_date[]" class="form-control name_list" placeholder="Enter Content" required="" /></td>
                             <td><input type="text" name="programme_mode[]" class="form-control name_list" placeholder="Enter Mode (eg. Online, Offline)" required="" /></td>
                             <td><button type="button" name="add" id="add-programme" class="btn btn-primary">+</button></td>
                          </tr>
                       </table>
                    </div>
                  </div>
                </div>
                <script type="text/javascript">
                    $(document).ready(function(){  
                          var i=1;  
                          $('#add-programme').click(function(){  
                               i++;  
                               $('#programme_field').append('<tr id="row-prg'+i+'"><td><input type="date" name="programme_date[]" class="form-control name_list" placeholder="Enter Content"/></td><td><input type="text" name="programme_mode[]" class="form-control name_list" placeholder="Enter Mode (eg. Online, Offline)"/></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove_programme">X</button></td></tr>');  
                          });  
                          $(document).on('click', '.btn_remove_programme', function(){  
                               var button_id = $(this).attr("id");   
                               $('#row-prg'+button_id+'').remove();  
                          });  
                     });  
                  </script>  
                  <div class="col-md-12">
                    <div class="form-group">
                      <button class="btn btn-info" type="submit" style="float: right">Add</button>
                    </div>
                  </div>
                  <?php echo form_close(); ?>
                </div>
              </div>
            </div>
          </div>
      </div>
    </section>
<script type="text/javascript">
  $(document).ready(function(){  
        var i=1;  
        $('#add').click(function(){  
             i++;  
             $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="batches_options[]" class="form-control name_list" placeholder="Enter Content"/></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
        });  
        $(document).on('click', '.btn_remove', function(){  
             var button_id = $(this).attr("id");   
             $('#row'+button_id+'').remove();  
        });  
   });  
</script>

    <!-- 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>View All Batch</h4>
                
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Course</th>  
                      <th>Slug</th>  
                      <th>Category</th>                                    
                      <th>Description</th>
                      <th>Start Date</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($all_upcoming_batches as $key => $batch):?>
                    <tr>
                      <td><?php echo $i ?></td>

                      <td><?php echo $batch->title ?></td>
                      <td><a href="<?php echo base_url(); ?>asb/<?php echo $batch->slug; ?>/<?php echo $batch->batches_id?>">Link</a></td>
                      <td><?php 
                      if($batch->batches_category == 1)
                      {
                        echo 'Self Paced Video Course';
                      }
                      elseif($batch->batches_category == 2)
                      {
                        echo 'Live Online Classroom';
                      }
                      else
                      {
                        echo 'Live Face2Face Class';
                      }
                      ?></td>
                      <td><?php echo $batch->batches_description ?></td>
                      <td><?php echo $batch->batches_start_date ?></td>
                      <td><a href="" class="btn btn-info btn-sm" data-toggle="modal" data-target="#update-lession<?php echo $batch->batches_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/frontend_setting/delete_upcoming_batch/<?php echo $batch->batches_id ?>"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
            </div>
          </div>
      </div>
    </section>

    <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>View All Contact</h4>
                
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table class="table table-bordered table-striped datatable">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Course</th>  
                      <th>Batch</th>  
                      <th>Name</th>                                    
                      <th>Mobile</th>
                      <th>Email</th>
                      <th>date</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($all_upcoming_contact as $key => $contact):?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo $contact->title ?></td>
                      <td><?php 
                        if($contact->batches_category == 1) 
                        {
                          echo 'Self Paced Video Course';
                        }
                        elseif($contact->batches_category == 2)
                        {
                          echo 'Live Online Classroom';
                        }
                        else
                        {
                          echo 'Face2Face Class';
                        }
                      ?></td>
                      <td><?php echo $contact->details_name ?></td>
                      <td><?php echo $contact->details_mobile ?></td>
                      <td><?php echo $contact->details_email ?></td>
                      <td><?php echo $contact->details_date ?></td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
            </div>
          </div>
      </div>
    </section>

    <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>View All Demo Class Request</h4>
                
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table class="table table-bordered table-striped datatable">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Course</th>  
                      <th>Batch</th>  
                      <th>Name</th>                                    
                      <th>Mobile</th>
                      <th>Email</th>
                      <th>date</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($all_upcoming_demo_class as $key => $demo_class):?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo $demo_class->title ?></td>
                      <td><?php 
                        if($demo_class->batches_category == 1) 
                        {
                          echo 'Self Paced Video Course';
                        }
                        elseif($demo_class->batches_category == 2)
                        {
                          echo 'Live Online Classroom';
                        }
                        else
                        {
                          echo 'Face2Face Class';
                        }
                      ?></td>
                      <td><?php echo $demo_class->details_name ?></td>
                      <td><?php echo $demo_class->details_mobile ?></td>
                      <td><?php echo $demo_class->details_email ?></td>
                      <td><?php echo $demo_class->details_date ?></td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
            </div>
          </div>
      </div>
    </section>
    <!-- /.content -->
  </div>

<?php $i=1; foreach ($all_upcoming_batches as $key => $batch):?>
<div class="modal fade" id="update-lession<?php echo $batch->batches_id ?>" 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">Update Lession</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(base_url().'admin/frontend_setting/update_batch_details'); ?>
        <div class="row">
         <div class="col-md-8">
            <div class="form-group">
              <label>Select Course<span class="required">*</span></label>
              <select name="batches_course" class="form-control" placeholder="Enter Title" required="">
                <option value="">Select</option>
                <?php foreach ($all_course as $course):?>
                  <option <?php if($course->id == $batch->batches_course){echo 'selected';}?> value="<?php echo $course->id ?>"><?php echo $course->title ?></option>
                <?php endforeach;?>
              </select>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label>Select Category<span class="required">*</span></label>
              <select name="batches_category" class="form-control" placeholder="Enter Title" required="">
                <option value="">Select</option>
                <option <?php if($batch->batches_category == 1){echo 'selected';}?> value="1">Self Paced Video Course</option>
                <option <?php if($batch->batches_category == 2){echo 'selected';}?> value="2">Live Online Classroom </option>
                <option <?php if($batch->batches_category == 3){echo 'selected';}?> value="3">Live Face2Face Class</option>
              </select>
            </div>
          </div>
          <div class="col-md-12">
            <div class="form-group">
              <label>Batch Description<span class="required">*</span></label>
              <textarea name="batches_description" class="form-control" placeholder="Enter Description"><?php echo $batch->batches_description ?></textarea>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label>Batch Start date</label>
              <input type="date" name="batches_start_date" class="form-control" placeholder="Enter Tag" required value="<?php echo $batch->batches_start_date ?>">
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label>Batch Tag</label>
              <input type="text" name="batches_tag" class="form-control" placeholder="Enter Tag" value="<?php echo $batch->batches_tag ?>">
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label>Batch Color</label>
              <input type="color" name="batches_color" class="form-control" placeholder="Enter Tag" value="<?php echo $batch->batches_color ?>">
            </div>
          </div>


          <div class="col-md-12">
            <div class="form-group">
              <label for="inputEmail" class="col-sm-12 col-form-label">Add Options</label>
              <div class="table-responsive">
                 <table class="table table-bordered" id="dynamic_field<?php echo $batch->batches_id ?>">
                  <?php foreach (json_decode($batch->batches_options) as $key => $content):?>
                    <tr>
                       <td width="90%"><input type="text" name="batches_options[]" class="form-control name_list" placeholder="Enter Content" value="<?php echo $content ?>" /></td>
                       <td><button type="button" name="remove" id="old_<?php echo $i?>" class="btn btn-danger btn_remove_<?php echo $i?>" onclick="removeRequirement(this)">X</button></td>
                    </tr>
                  <?php endforeach; ?>
                  <tr>
                       <td width="90%"></td>
                       <td><button type="button" name="add" class="add<?php echo $batch->batches_id ?>" class="btn btn-success">+</button></td>
                    </tr>
                 </table>
              </div>
            </div>

            <div class="col-md-12">
              <div class="form-group">
              <label for="inputEmail" class="col-sm-12 col-form-label">Self-Paced Program<span class="required">*</span></label>
              <div class="table-responsive">
                 <table class="table table-bordered" id="programme_field_<?php echo $batch->batches_id ?>">
                  <?php foreach (json_decode($batch->programme_date) as $keys => $programme_date):?>
                    <tr>
                       <td><input type="date" name="programme_date[]" class="form-control name_list" placeholder="Enter Content" required="" value="<?php echo $programme_date; ?>" /></td>
                       <td><input type="text" name="programme_mode[]" class="form-control name_list" placeholder="Enter Mode (eg. Online, Offline)" required="" value="<?php echo json_decode($batch->programme_mode)[$keys]; ?>"/></td>
                       <td><button type="button" name="remove" id="oldd_<?php echo $i?>" class="btn btn-danger btn_remove_<?php echo $i?>" onclick="removeProgramme(this)">X</button></td>
                    </tr>
                  <?php endforeach; ?>
                    <tr>
                      <!-- <td width="90%"></td> -->
                      <td><button type="button" name="add" id="add-programme-<?php echo $batch->batches_id ?>" class="btn btn-primary">+</button></td>
                    </tr>
                 </table>
              </div>
            </div>
          </div>
          </div>
            <input type="hidden" name="id" class="form-control" value="<?php echo $batch->batches_id ?>">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Update</button>
      </div>
      <?php echo form_close(); ?>
    </div>
  </div>
</div>
</div>
  <script type="text/javascript">
  $(document).ready(function(){  
        var i=1;  
        $('.add<?php echo $batch->batches_id ?>').click(function(){  
             i++;  
             $('#dynamic_field<?php echo $batch->batches_id ?>').append('<tr id="row'+i+'"><td><input type="text" name="batches_options[]" class="form-control name_list" placeholder="Enter Scontent"/></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
        });  
        $(document).on('click', '.btn_remove', function(){  
             var button_id = $(this).attr("id");   
             $('#row'+button_id+'').remove();  
        });  

        var a=1;  
        $('#add-programme-<?php echo $batch->batches_id ?>').click(function(){  
             a++;  
             $('#programme_field_<?php echo $batch->batches_id ?>').append('<tr id="row-prg'+a+'"><td><input type="date" name="programme_date[]" class="form-control name_list" placeholder="Enter Content" required="" /></td><td><input type="text" name="programme_mode[]" class="form-control name_list" placeholder="Enter Mode (eg. Online, Offline)" required=""/></td><td><button type="button" name="remove" id="'+a+'" class="btn btn-danger row-prg">X</button></td></tr>');  
        });  
        $(document).on('click', '.row-prg', function(){  
             var button_id = $(this).attr("id");   
             $('#row-prg'+button_id+'').remove();  
        });  
       
   });  
</script>
<?php $i++; ?>
<?php endforeach; ?>
<script type="text/javascript">
function removeRequirement(requirementElem) {
  jQuery(requirementElem).parent().parent().remove();
}
function removeProgramme(requirementElem) {
  jQuery(requirementElem).parent().parent().remove();
}
</script>