
<!-- 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 Lession</h1>
         </div>
         <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
               <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin">Home</a></li>
               <li class="breadcrumb-item"><a href="#">Course</a></li>
               <li class="breadcrumb-item active">All Lession</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">Add New Lession</h3>
            </div>
            <!-- /.card-header -->
            <?php echo form_open_multipart(base_url().'admin/course/add_new_lession'); ?>
            <div class="card-body">
               <div class="row">
                  <div class="col-md-12">
                     <div class="form-group">
                        <label>Select Course<span class="required">*</span></label>
                        <select type="text" name="course" class="form-control" placeholder="Enter Title" required="">
                           <option value="">Select</option>
                           <?php foreach ($get_all_course as $key => $course): ?>
                           <option value="<?php echo $course->id; ?>"><?php echo $course->title; ?></option>
                           <?php endforeach ?>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label>Module Name<span class="required">*</span></label>
                        <input type="text" name="title" class="form-control" placeholder="Enter Module Name" required="">
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label>Description<span class="required">*</span></label>
                        <textarea type="text" name="description" class="form-control" placeholder="Enter  Description" required=""></textarea>
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label>Order<span class="required">*</span></label>
                        <input type="number" name="order_by" class="form-control" placeholder="Enter Order" required="" value="1">
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Lession & Topic Content<span class="required">*</span></label>
                        <div class="table-responsive">
                           <table class="table table-bordered" id="dynamic_field">
                              <tr>
                                 <td><input type="text" name="section[]" class="form-control name_list" placeholder="Enter Lession"/></td>
                                 <td><input type="text" name="content[]" class="form-control name_list" placeholder="Enter Topics Saparate By Comma" required="" /></td>
                                 <td><button type="button" name="add" id="add" class="btn btn-primary">+</button></td>
                              </tr>
                           </table>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Upload Assignment PDF</label>
                        <div class="table-responsive">
                           <table class="table table-bordered" id="assigment_field">
                              <tr>
                                 <td><input type="file" name="assignments_pdf[]" class="form-control name_list" placeholder="Enter Lession"/></td>
                                 <td><button type="button" name="add" id="add_assigment" class="btn btn-primary">+</button></td>
                              </tr>
                           </table>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Upload Mini Project PDF</label>
                        <div class="table-responsive">
                           <table class="table table-bordered" id="project_field">
                              <tr>
                                 <td><input type="file" name="project_pdf[]" class="form-control name_list" placeholder="Enter Lession"/></td>
                                 <td><button type="button" name="add" id="add_project" class="btn btn-primary">+</button></td>
                              </tr>
                           </table>
                        </div>
                     </div>
                  </div>
                  <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="section[]" class="form-control name_list" placeholder="Enter Section" /></td><td><input type="text" name="content[]" class="form-control name_list" placeholder="Enter Content Comma Saparate"/></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_assigment').click(function(){  
              a++;  
              $('#assigment_field').append('<tr id="row_assigment'+a+'"><td><input type="file" name="assignments_pdf[]" class="form-control name_list" placeholder="Enter Lession"/></td><td><button type="button" name="remove" id="'+a+'" class="btn btn-danger btn_remove_assigment">X</button></td></tr>');  
         });  
         $(document).on('click', '.btn_remove_assigment', function(){  
              var button_id = $(this).attr("id");   
              $('#row_assigment'+button_id+'').remove();  
         });  
         var b=1;  
         $('#add_project').click(function(){  
              b++;  
              $('#project_field').append('<tr id="row_project'+b+'"><td><input type="file" name="project_pdf[]" class="form-control name_list" placeholder="Enter Lession"/></td><td><button type="button" name="remove" id="'+b+'" class="btn btn-danger btn_remove_project">X</button></td></tr>');  
         });  
         $(document).on('click', '.btn_remove_project', function(){  
              var button_id = $(this).attr("id");   
              $('#row_project'+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">
                  <h3 class="card-title">View All Lession</h3>
                  <div class="card-tools">
                     <div style="display: inline-block;">
                        <label> Filter Data By Course : </label>
                     </div>
                     <?php foreach ($get_all_course as $key => $course)
                        {
                          $ar[] = $course->title;
                        }
                            
                            sort($ar);
                            foreach ($ar as $k => $v) {
                                 if (isset($check)) {
                                    if ($check === $v) {
                                        unset($ar[$k]);
                                    }
                                 }
                                 $check = $v;
                            }
                            $noDuplicate = array_values($ar);
                        ?>
                     <div style="display: inline-block;">
                        <select  class="form-control" id="table-filter-course">
                           <?php foreach ($noDuplicate as $key => $cour):?>
                           <option value="<?php echo $cour ?>"><?php echo $cour ?></option>
                           <?php endforeach; ?>
                        </select>
                     </div>
                  </div>
               </div>
               <!-- /.card-header -->
               <div class="card-body">
                  <table id="example1" class="table table-bordered table-striped">
                     <thead>
                        <tr>
                           <th>id</th>
                           <th>Title</th>
                           <th>Description</th>
                           <th>Course</th>
                           <th>Order</th>
                           <th></th>
                        </tr>
                     </thead>
                     <tbody>
                        <?php $i=1; foreach ($get_all_lession as $key => $lession):
                           $course_n = $this->course_model->get_course_name_for_view_all($lession->course);
                           ?>
                        <tr>
                           <td><?php echo $i ?></td>
                           <td><?php echo $lession->l_title ?></td>
                           <td><?php echo $lession->l_description ?></td>
                           <td><?php echo $course_n->title ?></td>
                           <td><?php echo $lession->order_by ?></td>
                           <td><a href="" class="btn btn-info btn-sm" data-toggle="modal" data-target="#update-lession<?php echo $lession->l_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/course/delete_lession/<?php echo $lession->l_id ?>"><i class="fa fa-trash" aria-hidden="true"></i></a>
                           </td>
                        </tr>
                        <?php $i++; ?>
                        <?php endforeach; ?>
                     </tbody>
                  </table>
               </div>
            </div>
         </div>
      </div>
</section>
<!-- /.content -->
</div>
<?php $i=1; $b=1; foreach ($get_all_lession as $key => $lession):?>
<div class="modal fade" id="update-lession<?php echo $lession->l_id ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-xl" 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_multipart(base_url().'admin/course/update_lession'); ?>
            <div class="col-md-12">
               <div class="form-group">
                  <label>Select Course<span class="required">*</span></label>
                  <select type="text" name="course" class="form-control" placeholder="Enter Title" required="">
                     <option value="">Select</option>
                     <?php foreach ($get_all_course as $key => $course): ?>
                     <option <?php if($lession->course == $course->id){echo 'selected';}?> value="<?php echo $course->id; ?>"><?php echo $course->title; ?></option>
                     <?php endforeach ?>
                  </select>
               </div>
            </div>
            <div class="col-md-12">
               <div class="form-group">
                  <label>Module Name<span class="required">*</span></label>
                  <input type="text" name="title" class="form-control" placeholder="Enter Module Name" required="" value="<?php echo $lession->l_title; ?>">
               </div>
            </div>
            <div class="col-md-12">
               <div class="form-group">
                  <label>Description<span class="required">*</span></label>
                  <textarea type="text" name="description" class="form-control" placeholder="Enter  Description" required=""><?php echo $lession->l_description; ?></textarea>
               </div>
            </div>
            <div class="col-md-12">
               <div class="form-group">
                  <label>Order<span class="required">*</span></label>
                  <input type="number" name="order_by" class="form-control" placeholder="Enter Order" required="" value="<?php echo $lession->order_by; ?>">
               </div>
            </div>
            <div class="col-md-12">
               <div class="form-group">
                  <label for="inputEmail" class="col-sm-12 col-form-label">Add Lession & Topic Content</label>
                  <div class="table-responsive">
                     <table class="table table-bordered" id="dynamic_field<?php echo $lession->l_id ?>" style="table-layout: fixed;">
                        <?php foreach (json_decode($lession->content) as $key => $content):?>
                        <tr>
                           <td width="20%"><input type="text" name="section[]" class="form-control" placeholder="Enter Lession" value="<?php echo json_decode($lession->section)[$key]; ?>" /></td>
                           <td width="70%"><input type="text" name="content[]" class="form-control name_list" placeholder="Enter Topics Saparate By Comma" value="<?php echo $content ?>" /></td>
                           <td width="10%"><button type="button" name="remove" id="<?php echo $i?>" class="btn btn-danger btn_remove" onclick="removeRequirement(this)">X</button></td>
                        </tr>
                        <?php endforeach; ?>
                        <tr>
                           <td width="90%"></td>
                           <td><button type="button" name="add" class="add<?php echo $lession->l_id ?>" class="btn btn-success">+</button></td>
                        </tr>
                     </table>
                  </div>
               </div>
            </div>

            <div class="col-md-12">
              <div class="form-group">
                 <label for="inputEmail" class="col-sm-12 col-form-label">Upload Assignment PDF</label>
                 <div class="table-responsive">

                    <table class="table table-bordered" id="front_image_field_<?php echo $b; ?>">
                       <?php 
                      $all_ass_pdf = $this->course_model->get_ass_pdf_by_c_id_and_lession_id($lession->course, $lession->l_id);
                        foreach ($all_ass_pdf as $key => $ass_pdf):?>
                         <tr>
                            <td width="80%"></td>
                             <td><iframe src="<?php echo base_url(); ?><?php echo $ass_pdf->clp_pdf ?>" width="100" height="70"></iframe></td>
                            <td><a onclick="delete_ass_pdf(<?php echo $ass_pdf->clp_id ?>, 'front_image_field_<?php echo $b; ?>')"><button type="button" class="btn btn-danger">X</button></a></td>
                         </tr>
                       <?php endforeach; ?>
                       <tr>
                          <td width="80%" colspan="2"><input type="file" name="assignments_pdf[]" class="form-control name_list image" /></td>
                          <td><button type="button" name="add" id="add_front_image_<?php echo $b; ?>" class="btn btn-primary">+</button></td>
                       </tr>
                    </table>
                 </div>
              </div>
            </div>
            <script type="text/javascript">
               $(document).ready(function(){  
                    var i=1;  
                    $('#add_front_image_<?php echo $b; ?>').click(function(){  
                         i++;  
                         $('#front_image_field_<?php echo $b; ?>').append('<tr id="row'+i+'"><td colspan="2"><input type="file" name="assignments_pdf[]" class="form-control name_list image" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove_front_image">X</button></td></tr>');  
                    });  
                    $(document).on('click', '.btn_remove_front_image', function(){  
                         var button_id = $(this).attr("id");   
                         $('#row'+button_id+'').remove();  
                    });  
                });   
            </script>

            <div class="col-md-12">
              <div class="form-group">
                 <label for="inputEmail" class="col-sm-12 col-form-label">Upload Mini Project PDF</label>
                 <div class="table-responsive">

                    <table class="table table-bordered" id="front_image_field_1_<?php echo $b; ?>">
                       <?php 
                      $all_mini_pdf = $this->course_model->get_mini_pdf_by_c_id_and_lession_id($lession->course, $lession->l_id);
                        foreach ($all_mini_pdf as $key => $all_mini_pdf):?>
                         <tr>
                            <td width="80%"></td>
                             <td><iframe src="<?php echo base_url(); ?><?php echo $all_mini_pdf->clpm_pdf ?>" width="100" height="70"></iframe></td>
                            <td><a onclick="delete_mini_pdf(<?php echo $all_mini_pdf->clpm_id ?>, 'front_image_field_1_<?php echo $b; ?>')"><button type="button" class="btn btn-danger">X</button></a></td>
                         </tr>
                       <?php endforeach; ?>
                       <tr>
                          <td width="80%" colspan="2"><input type="file" name="project_pdf[]" class="form-control name_list image" /></td>
                          <td><button type="button" name="add" id="add_front_image_1_<?php echo $b; ?>" class="btn btn-primary">+</button></td>
                       </tr>
                    </table>
                 </div>
              </div>
            </div>
            <script type="text/javascript">
               $(document).ready(function(){  
                    var i=1;  
                    $('#add_front_image_1_<?php echo $b; ?>').click(function(){  
                         i++;  
                         $('#front_image_field_1_<?php echo $b; ?>').append('<tr id="row'+i+'"><td colspan="2"><input type="file" name="project_pdf[]" class="form-control name_list image" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove_front_image">X</button></td></tr>');  
                    });  
                    $(document).on('click', '.btn_remove_front_image', function(){  
                         var button_id = $(this).attr("id");   
                         $('#row'+button_id+'').remove();  
                    });  
                });   
            </script>


            <input type="hidden" name="id" class="form-control" value="<?php echo $lession->l_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>
<script type="text/javascript">
   $(document).ready(function(){  
         var i=1;  
         $('.add<?php echo $lession->l_id ?>').click(function(){  
              i++;  
              $('#dynamic_field<?php echo $lession->l_id ?>').append('<tr id="row'+i+'"><td width="20%"><input type="text" name="section[]" class="form-control name_list" placeholder="Enter Lession"/></td><td width="70%"><input type="text" name="content[]" class="form-control name_list" placeholder="Enter Topics Saparate By Comma"/></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>
<?php $i++; $b++; ?>
<?php endforeach; ?>
<script type="text/javascript">
   function removeRequirement(requirementElem) {
   jQuery(requirementElem).parent().parent().remove();
   }
</script>
<style type="text/css">
   #course_table_length, #course_table_filter
   {
   display: none!important;
   }
</style>
<script type="text/javascript">
function delete_ass_pdf(ass_id, modal_id) 
{
  if (confirm("Do you REALLY want this?")){
    $.ajax({
        type: "GET",
        url: "<?php echo base_url(); ?>admin/course/delete_ass_pdf/"+ass_id,
        success: function(data) {

          if(data)
          {
            $("#"+modal_id).load(window.location.href + " #"+modal_id );
          }
          else
          {
            alert("Error occured !!");
          }
       },
       error : function(data){
         alert("Error occured !!");
       }
     });    
  }
}
function delete_mini_pdf(ass_id, modal_id) 
{
  if (confirm("Do you REALLY want this?")){
    $.ajax({
        type: "GET",
        url: "<?php echo base_url(); ?>admin/course/delete_mini_pdf/"+ass_id,
        success: function(data) {

          if(data)
          {
            $("#"+modal_id).load(window.location.href + " #"+modal_id );
          }
          else
          {
            alert("Error occured !!");
          }
       },
       error : function(data){
         alert("Error occured !!");
       }
     });    
  }
}
</script>