<!-- /.content-wrapper -->
<footer class="main-footer">
  <strong>Copyright &copy; 2014-2020 <a href="https://adminlte.io">AdminLTE.io</a>.</strong>
  All rights reserved.
  <div class="float-right d-none d-sm-inline-block">
    <b>Version</b> 3.1.0-rc
  </div>
</footer>

<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
  <!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<!-- jQuery -->
<script src="<?php echo admin_css() ?>plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="<?php echo admin_css() ?>plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="<?php echo admin_css() ?>plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ChartJS -->
<script src="<?php echo admin_css() ?>plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="<?php echo admin_css() ?>plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="<?php echo admin_css() ?>plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="<?php echo admin_css() ?>plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="<?php echo admin_css() ?>plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="<?php echo admin_css() ?>plugins/moment/moment.min.js"></script>
<script src="<?php echo admin_css() ?>plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="<?php echo admin_css() ?>plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="<?php echo admin_css() ?>plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="<?php echo admin_css() ?>plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="<?php echo admin_css() ?>js/adminlte.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?php echo admin_css() ?>js/demo.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="<?php echo admin_css() ?>js/pages/dashboard.js"></script>
<script src="<?php echo admin_css() ?>plugins/summernote/summernote-bs4.min.js"></script>

<script src="<?php echo admin_css() ?>plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo admin_css() ?>plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="<?php echo admin_css() ?>plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>

<script src="<?php echo admin_css() ?>plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<script src="<?php echo admin_css() ?>ck/ckeditor.js"></script>
<script src="<?php echo admin_css() ?>ck/sample.js"></script>
<!-- Select2 -->

<?php if($this->uri->segment(3) == "edit_course"): ?>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha512-YUkaLm+KJ5lQXDBdqBqk7EVhJAdxRnVdT2vtCzwPHSweCzyMgYV/tgGF4/dCyqtCC2eCphz0lRQgatGVdfR0ww==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  <?php endif; ?>

<script src="<?php echo admin_css() ?>plugins/select2/js/select2.full.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.0.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/2.0.1/js/buttons.html5.min.js"></script>
</body>

</html>
<script type="text/javascript">
  $('form').submit(function() {
    $('button[type="submit"]').html('Processing....');
    $('button[type="submit"]').attr('disabled', true);
  });
  initSample();
  CKEditor_loaded(false);
  CKEDITOR.on('instanceReady', function() {
    CKEditor_loaded(true);
  });

  function CKEditor_loaded(e) {
    var loaded = e;
    if (loaded == false) {
      $("#loader").html('<img class="mx-auto d-block" src="<?php echo base_url() ?>assets/spin.gif" >')
    } else {
      $("#loader").hide()
    }
  }
</script>
<script>
  $(function() {
    // Summernote
    $('.text-editor').summernote({
      toolbar: [
        ['style', ['style']],
        ['font', ['bold', 'underline', 'clear']],
        ['font', ['fontsize', 'color']],
        ['fontname', ['fontname']],
        ['colors', ['#10244E', '#E52D2D']],
        ['para', ['ul', 'ol', 'paragraph']],
        ['table', ['table']],
        ['insert', ['link', 'picture', 'video']],
        ['view', ['fullscreen', 'codeview', 'help']],
      ],
    })
  })
  $(function() {
    //Initialize Select2 Elements
    $('.select2').select2()
  });


  $(function() {
    $('.partial_view').DataTable({
      "paging": false,
      dom: 'Bflrtip',
      buttons: [
        ''
      ],
      "searching": false,
      "ordering": false,
      "info": false,
      "autoWidth": false,
      "responsive": true,
    });
    $('#example').DataTable({
      "paging": true,
      dom: 'Bflrtip',
      buttons: [
        'copyHtml5', 'excelHtml5', 'csvHtml5', 'pdfHtml5', 'print'
      ],

      language: {
        buttons: {
          copyTitle: 'Copy to clipboard',
          copySuccess: {
            _: ' Copied %d rows to clipboard',
            1: '1 Line Copy'
          }
        }
      },
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
  $(function() {
    $('.datatable').DataTable({
      "paging": true,
      dom: 'Bflrtip',
      buttons: [
        'copyHtml5', 'excelHtml5', 'csvHtml5', 'pdfHtml5', 'print'
      ],

      language: {
        buttons: {
          copyTitle: 'Copy to clipboard',
          copySuccess: {
            _: ' Copied %d rows to clipboard',
            1: '1 Line Copy'
          }
        }
      },
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
  $(document).ready(function() {
    var course_table = $('#course_table').DataTable({
      "responsive": true,
      "autoWidth": false,
      "lengthChange": true,
      "paging": true,
      dom: 'Bfrtip',
      buttons: [
        'copyHtml5',
        'excelHtml5',
        'csvHtml5',
        'pdfHtml5',
        'pageLength'
      ]

    });
    $('#table-filter-course').on('change', function() {
      course_table.search(this.value).draw();
    });
  });

  function actionTo(url, type = "get", event) {
    //Start prepare get url to post value
    var jsonFormate = '{}';
    if (type == 'post') {
      let pieces = url.split(/[\s?]+/);
      let lastString = pieces[pieces.length - 1];
      jsonFormate = '{"' + lastString.replace('=', '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","').replace("=", '":"').replace("&", '","') + '"}';
    }
    jsonFormate = JSON.parse(jsonFormate);
    //End prepare get url to post value
    $.ajax({
      type: type,
      url: url,
      data: jsonFormate,
      success: function(response) {
        distributeServerResponse(response);
      }
    });

  }
  //Server response distribute
  function distributeServerResponse(response) {
    try {
      JSON.parse(response);
      var isValidJson = true;
    } catch (error) {
      var isValidJson = false;
    }
    if (isValidJson) {
      response = JSON.parse(response);
      //For reload after submission
      if (typeof response.reload != "undefined" && response.reload != 0) {
        location.reload();
      }

      //For redirect to another url
      if (typeof response.redirectTo != "undefined" && response.redirectTo != 0) {
        $(location).attr('href', response.redirectTo);
      }

      //for show a element
      if (typeof response.show != "undefined" && response.show != 0 && $(response.show).length) {
        $(response.show).css('display', 'inline-block');
      }
      //for hide a element
      if (typeof response.hide != "undefined" && response.hide != 0 && $(response.hide).length) {
        $(response.hide).hide();
      }
      //for fade in a element
      if (typeof response.fadeIn != "undefined" && response.fadeIn != 0 && $(response.fadeIn).length) {
        $(response.fadeIn).fadeIn();
      }
      //for fade out a element
      if (typeof response.fadeOut != "undefined" && response.fadeOut != 0 && $(response.fadeOut).length) {
        $(response.fadeOut).fadeOut();
      }

      //For adding a class
      if (typeof response.addClass != "undefined" && response.addClass != 0 && $(response.addClass.elem).length) {
        $(response.addClass.elem).addClass(response.addClass.content);
      }
      //For remove a class
      if (typeof response.removeClass != "undefined" && response.removeClass != 0 && $(response.removeClass.elem).length) {
        $(response.removeClass.elem).removeClass(response.removeClass.content);
      }
      //For toggle a class
      if (typeof response.toggleClass != "undefined" && response.toggleClass != 0 && $(response.toggleClass.elem).length) {
        $(response.toggleClass.elem).toggleClass(response.toggleClass.content);
      }

      //For showing error message
      if (typeof response.error != "undefined" && response.error != 0) {
        error_notify(response.error);
      }
      //For showing success message
      if (typeof response.success != "undefined" && response.success != 0) {
        success_notify(response.success);
      }

      //For replace texts in a specific element
      if (typeof response.text != "undefined" && response.text != 0 && $(response.text.elem).length) {
        $(response.text.elem).text(response.text.content);
      }
      //For replace elements in a specific element
      if (typeof response.html != "undefined" && response.html != 0 && $(response.html.elem).length) {
        $(response.html.elem).html(response.html.content);
      }
      //For replace elements in a specific element
      if (typeof response.load != "undefined" && response.load != 0 && $(response.load.elem).length) {
        $(response.load.elem).html(response.load.content);
      }
      //For replace elements with the selected DOM
      if (typeof response.replace != "undefined" && response.replace != 0 && $(response.replace.elem).length) {
        $(response.replace.elem).html(response.replace.content);
        $(response.replace.elem).replaceWith(response.replace.content);
      }
      //For appending elements
      if (typeof response.append != "undefined" && response.append != 0 && $(response.append.elem).length) {
        $(response.append.elem).append(response.append.content);
      }
      //Fo prepending elements
      if (typeof response.prepend != "undefined" && response.prepend != 0 && $(response.prepend.elem).length) {
        $(response.prepend.elem).prepend(response.prepend.content);
      }
      //For appending elements after a element
      if (typeof response.after != "undefined" && response.after != 0 && $(response.after.elem).length) {
        $(response.after.elem).after(response.after.content);
      }

      // Update the browser URL and add a new entry to the history
      if (typeof response.pushState != "undefined" && response.pushState != 0) {
        //history.pushState({}, response.pushState.title, response.pushState.url);
        const {
          title,
          url
        } = response.pushState;
        history.pushState({}, title, url);
      }

      if (typeof response.script != "undefined" && response.script != 0) {
        script
      }

      if (typeof response.run_function != "undefined" && response.run_function != 0) {
        window[response.run_function]();
      }
    }
  }

  function success_notify() {
    swal({
      title: "Done!",
      text: "Data Successfully Saved",
      icon: "success",
    });
  }

  function error_notify(e)
  {
    swal({
      title: "Oops!",
      text: e,
      icon: "error",
    });
  }
</script>

<style>
  .font-awsom {
    font-family: fontAwesome
  }
</style>