<?php defined('BASEPATH') or die("ip anda sudah tercatat oleh sistem kami") ?>
<div class="section-header">
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-danger m-b-5" data-toggle="modal" data-target="#importdata">
        Unggah Foto
    </button>&nbsp;
    <div class="alert alert-danger" role="alert">
        <strong>Gunaka Tool ini <a class='btn btn-sm btn-success' href='https://www.bricelam.net/ImageResizer/' target='_blank'>Image Resizer</a> sebelum foto di compres ke zip</strong>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="importdata" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form method="POST" enctype="multipart/form-data">
                    <div class="modal-header">
                        <h5 class="modal-title">Import Data</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                        <label>Pilih Zip File</label>
                        <input type="file" name="zip_file" class="form-control" required/>
                        <input type="submit" name="btn_zip" class="btn btn-info mt-5" value="Unggah" />
                        <small id="helpfile" class="form-text text-muted">Format Nama file harus NISN.JPG dan di compres dengan format  .zip</small>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php  
        if(isset($_POST["btn_zip"])){
        $output = '';
        if($_FILES['zip_file']['name'] != ''){
            $file_name = $_FILES['zip_file']['name'];
            $array = explode(".", $file_name);
            $name = $array[0];
            $ext = $array[1];
            if($ext == 'zip'){
                $path = 'upload/';
                if (!file_exists($path))
                mkdir($path);
                
                $location = $path . $file_name;
                if(move_uploaded_file($_FILES['zip_file']['tmp_name'], $location)){
                $zip = new ZipArchive;
                if($zip->open($location)){
                    $zip->extractTo($path);
                    $zip->close();
                }
                unlink($location);
        
                echo "<script>alert('Suksess Unggah Foto'); location='?pg=foto';</script>";
                }
            } else {
                echo "<script>alert('Hanya .zip yang diperbolehkan'); location='?pg=foto';</script>";
            }
        }
        }
        ?>


</div>

<div class="row">
<div class='container'>
 <div class="gallery">
 
  <?php 
  // Image extensions
  $image_extensions = array("png","jpg","jpeg","gif");

  // Target directory
  $dir = 'upload/';
  if (is_dir($dir)){
 
   if ($dh = opendir($dir)){
    $count = 1;

    // Read files
    while (($file = readdir($dh)) !== false){

     if($file != '' && $file != '.' && $file != '..'){
 
      // Thumbnail image path
      $thumbnail_path = "upload/".$file;

      // Image path
      $image_path = "upload/".$file;
 
      $thumbnail_ext = pathinfo($thumbnail_path, PATHINFO_EXTENSION);
      $image_ext = pathinfo($image_path, PATHINFO_EXTENSION);

      // Check its not folder and it is image file
      if(!is_dir($image_path) && 
         in_array($thumbnail_ext,$image_extensions) && 
         in_array($image_ext,$image_extensions)){
   ?>

       <!-- Image -->
       <a href="<?php echo $image_path; ?>">
        <img src="<?php echo $thumbnail_path; ?>" alt="" title=""/>
       </a>
       <!-- --- -->
       <?php

       // Break
       
      }
     }
 
    }
    closedir($dh);
   }
  }
 ?>
 </div>
</div>
</div>
<style>
.container .gallery a img {
  float: left;
  width: 10%;
  height: auto;
  border: 2px solid #fff;
  -webkit-transition: -webkit-transform .15s ease;
  -moz-transition: -moz-transform .15s ease;
  -o-transition: -o-transform .15s ease;
  -ms-transition: -ms-transform .15s ease;
  transition: transform .15s ease;
  position: relative;
}

.container .gallery a:hover img {
  -webkit-transform: scale(2);
  -moz-transform: scale(2);
  -o-transform: scale(2);
  -ms-transform: scale(2);
  transform: scale(2);
  z-index: 5;
}

.clear {
  clear: both;
  float: none;
  width: 100%;
}
</style>
<script type='text/javascript'>
$(document).ready(function(){

 // Intialize gallery
 var gallery = $('.gallery a').simpleLightbox();

});
</script>