<?
session_start();
include("../../../include/startup.php");
/* echo '<pre>';
print_r($_REQUEST);
die; */
if($_REQUEST['hide_add'] == 1){
	$hidedivhere = 'none';
} 
?>
<html lang="en">
  <head>
    <!-- Force latest IE rendering engine or ChromeFrame if installed -->
    <!--[if IE]>
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <![endif]-->
    <meta charset="utf-8" />
    <title>File Upload</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!-- Bootstrap styles -->
    <link
      rel="stylesheet"
      href="<?=$config->siteURL;?>/css/bootstrap.v3.3.7.min.css"
      integrity=""
      crossorigin=""
    />
    <!-- Generic page styles -->
    <style>
	  body{
		font-family: 'Source Sans Pro',sans-serif;
	  }
	  label{
		margin:10px 0;
	  }
	  .boxzindexset{
		float: left;
		width: 100%;
		z-index: 9;
	  }
	  .setpositioncss{
		position: relative;
        top: 5px;
	  }	
	  .no-padding{
		padding-left: 0;
		padding-right: 0;
	  }
      #navigation {
        margin: 10px 0;
      }
      @media (max-width: 767px) {
        #title,
        #description {
          display: none;
        }
      }
    </style>
    <!-- blueimp Gallery styles -->
    <link
      rel="stylesheet"
      href="<?=$config->siteURL;?>/css/blueimp-gallery.min.css"
    />
    <!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
    <link rel="stylesheet" href="<?=$config->siteURL;?>/css/jquery.fileupload.css" />
    <link rel="stylesheet" href="<?=$config->siteURL;?>/css/jquery.fileupload-ui.css" />
    <!-- CSS adjustments for browsers with JavaScript disabled -->
    <noscript
      ><link rel="stylesheet" href="<?=$config->siteURL;?>/css/jquery.fileupload-noscript.css"
    /></noscript>
    <noscript
      ><link rel="stylesheet" href="<?=$config->siteURL;?>/css/jquery.fileupload-ui-noscript.css"
    /></noscript>
  </head>
  <body>
    <div class="container">
      
      <h1 id="title" class="hide">Upload files</h1><br/>
      
      <!-- The file upload form used as target for the file upload widget -->
      <form
        id="fileupload"
        action=""
        method="POST"
        enctype="multipart/form-data"
      >
        <!-- Redirect browsers with JavaScript disabled to the origin page -->
        <noscript
          ><input
            type="hidden"
            name="redirect"
            value="https://blueimp.github.io/jQuery-File-Upload/"
        /></noscript>
        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div style="display:<?=$hidedivhere;?>;">
        <div class="row fileupload-buttonbar">
          <div class="col-lg-7">
            <!-- The fileinput-button span is used to style the file input field as button -->
            <span class="btn btn-success fileinput-button">
              <i class="glyphicon glyphicon-plus"></i>
              <span>Add files...</span>
              <input type="file" name="files[]" multiple />
            </span>
            <button type="submit" class="btn btn-primary start">
              <i class="glyphicon glyphicon-upload"></i>
              <span>Start upload</span>
            </button>
            <button type="reset" class="btn btn-warning cancel">
              <i class="glyphicon glyphicon-ban-circle"></i>
              <span>Cancel upload</span>
            </button>
            <button type="button" class="btn btn-danger delete">
              <i class="glyphicon glyphicon-trash"></i>
              <span>Delete selected</span>
            </button>
            <input type="checkbox" class="toggle setpositioncss" />
            <!-- The global file processing state -->
            <span class="fileupload-process"></span>
          </div>
		  <div class="col-lg-12 no-padding boxzindexset">
		  <div class="col-lg-7 col-md-7 col-sm-12">
			<label for="Description" class="control-label">Description</label>
			<textarea class="form-control" rows="4" id="document_text" name="document_text" required><?php echo stripslashes($document_text);?></textarea>
		  </div>
		  <div class="col-lg-5 col-md-5 col-sm-12">
			<!--<label for="Note" class="control-label">Document Date</label>
			<input type="text" class="form-control" id="document_date" name="document_date" value="<?php (isset($document_date) && $document_date !="") ? utility::getFormatedDate($document_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>-->
			
			<label for="Type" class="control-label">Type</label>
			<? echo Keycode::getKeycodeListValue("document_type", $document_type, $width = 250, "Document Type", "id", "code", "document_type","","form-control select2"); ?>
			
			<div style="clear:both;margin-top:23px;"></div>			
			<input type="hidden" id="job_id" name="job_id" value="<?php echo $_REQUEST['id'];?>">
			<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
			<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
			</div>
		
		
		  </div>
		  
		  
          <!-- The global progress state -->
          <div class="col-lg-5 fileupload-progress fade">
            <!-- The global progress bar -->
            <div
              class="progress progress-striped active"
              role="progressbar"
              aria-valuemin="0"
              aria-valuemax="100"
            >
              <div
                class="progress-bar progress-bar-success"
                style="width: 0%;"
              ></div>
            </div>
            <!-- The extended global progress state -->
            <div class="progress-extended">&nbsp;</div>
          </div>
        </div>
        </div>
        <!-- The table listing the files available for upload/download -->
        <table role="presentation" class="table table-striped">
          <tbody class="files"></tbody>
        </table>
      </form>
    </div>
    <!-- The blueimp Gallery widget -->
    <div
      id="blueimp-gallery"
      class="blueimp-gallery blueimp-gallery-controls"
      data-filter=":even"
    >
      <div class="slides"></div>
      <h3 class="title"></h3>
      <a class="prev">‹</a>
      <a class="next">›</a>
      <a class="close">×</a>
      <a class="play-pause"></a>
      <ol class="indicator"></ol>
    </div>
    <!-- The template to display files available for upload -->
    <script id="template-upload" type="text/x-tmpl">
      {% for (var i=0, file; file=o.files[i]; i++) { %}
          <tr class="template-upload fade">
              <td>
                  <span class="preview"></span>
              </td>
              <td>
                  {% if (window.innerWidth > 480 || !o.options.loadImageFileTypes.test(file.type)) { %}
                      <p class="name">{%=file.name%}</p>
                  {% } %}
                  <strong class="error text-danger"></strong>
              </td>
              <td>
                  <p class="size">Processing...</p>
                  <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
              </td>
              <td>
                  {% if (!o.options.autoUpload && o.options.edit && o.options.loadImageFileTypes.test(file.type)) { %}
                    <button class="btn btn-success edit" data-index="{%=i%}" disabled>
                        <i class="glyphicon glyphicon-edit"></i>
                        <span>Edit</span>
                    </button>
                  {% } %}
                  {% if (!i && !o.options.autoUpload) { %}
                      <button class="btn btn-primary start" disabled>
                          <i class="glyphicon glyphicon-upload"></i>
                          <span>Start</span>
                      </button>
                  {% } %}
                  {% if (!i) { %}
                      <button class="btn btn-warning cancel">
                          <i class="glyphicon glyphicon-ban-circle"></i>
                          <span>Cancel</span>
                      </button>
                  {% } %}
              </td>
          </tr>
      {% } %}
    </script>
    <!-- The template to display files available for download -->
    <script id="template-download" type="text/x-tmpl">
     
	<?
	$query = "SELECT * FROM documents WHERE job_id = ".$_REQUEST['id']." ORDER BY document_date DESC ";
	$sql=mysqli_query($conn,$query);
	$result=mysqli_num_rows($sql);
	?>
	  <?
				while($row = mysqli_fetch_array($sql)){
				
				$file_path = "/server/php/files/".$row['document_name'];
				$ext = pathinfo($file_path, PATHINFO_EXTENSION);
				$ext = strtolower($ext);
				if($ext == "jpg" || $ext == "jpeg" || $ext == "png"){
					$data_gallery = 'data-gallery=""';	
					$preview = '1';	
				}else{
					$data_gallery = '';	
					$preview = '0';	
				}
				
				?>
				<!-- Start data -->
				<tr class="template-download fade">
					<td>
						<? if($preview){ ?>
						<span class="preview">                      
                          <a href="<?=$config->siteURL;?>/server/php/files/<?php echo $row['document_name']; ?>" title="<?php echo $row['document_name']; ?>" download="<?php echo $row['document_name']; ?>" data-gallery=""><img src="<?=$config->siteURL;?>/server/php/files/thumbnail/<?php echo $row['document_name']; ?>"></a>                      
						</span>
						<? } ?>
					</td>
					<td>
                  
                      <p class="name">
                          
                              <a href="<?=$config->siteURL;?>/server/php/files/<?php echo $row['document_name']; ?>" title="<?php echo $row['document_name']; ?>" download="<?php echo $row['document_name']; ?>" <?=$data_gallery;?> ><?php echo $row['document_name']; ?></a>
                          
                      </p>
                 </td> 
               <td>
                  <span class="size"><?php echo $row['document_text']; ?></span>
              </td>
              <td>                  
                      <button class="btn btn-danger delete" data-type="DELETE" data-url="<?=$config->siteURL;?>/server/php/index-upload.php?file=<?php echo $row['document_name'];?>&id=<?php echo $row['id']; ?>">
                          <i class="glyphicon glyphicon-trash"></i>
                          <span>Delete</span>
                      </button>
                      <input type="checkbox" name="delete" value="1" class="toggle">
                  
              </td>    
              
	  </tr>
	  		  <?}?>
              
    </script>
    <script
      src="<?=$config->siteURL;?>/js/jquery.v3.4.1.min.js"
      integrity=""
      crossorigin=""
    ></script>
    <!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
    <script src="<?=$config->siteURL;?>/js/vendor/jquery.ui.widget.js"></script>
    <!-- The Templates plugin is included to render the upload/download listings -->
    <script src="<?=$config->siteURL;?>/js/tmpl.min.js"></script>
    <!-- The Load Image plugin is included for the preview images and image resizing functionality -->
    <script src="<?=$config->siteURL;?>/js/load-image.all.min.js"></script>
    <!-- The Canvas to Blob plugin is included for image resizing functionality -->
    <script src="<?=$config->siteURL;?>/js/canvas-to-blob.min.js"></script>
    <!-- blueimp Gallery script -->
    <script src="<?=$config->siteURL;?>/js/jquery.blueimp-gallery.min.js"></script>
    <!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
    <script src="<?=$config->siteURL;?>/js/jquery.iframe-transport.js"></script>
    <!-- The basic File Upload plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload.js"></script>
    <!-- The File Upload processing plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-process.js"></script>
    <!-- The File Upload image preview & resize plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-image.js"></script>
    <!-- The File Upload audio preview plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-audio.js"></script>
    <!-- The File Upload video preview plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-video.js"></script>
    <!-- The File Upload validation plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-validate.js"></script>
    <!-- The File Upload user interface plugin -->
    <script src="<?=$config->siteURL;?>/js/jquery.fileupload-ui.js"></script>
    <!-- The main application script -->
    
    <!-- The XDomainRequest Transport is included for cross-domain file deletion for IE 8 and IE 9 -->
    <!--[if (gte IE 8)&(lt IE 10)]>
      <script src="js/cors/jquery.xdr-transport.js"></script>
    <![endif]-->
  </body>
</html>
<script>
/*
 * jQuery File Upload Demo
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * https://opensource.org/licenses/MIT
 */

/* global $ */

$(function () {
  'use strict';

  // Initialize the jQuery File Upload widget:
  $('#fileupload').fileupload({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: 'server/php/index-upload.php',
	disableImageResize: /Android(?!.*Chrome)|Opera/
        .test(window.navigator && navigator.userAgent),
    imageMaxWidth: 800,
    imageMaxHeight: 800,
    imageCrop: true // Force cropped images
  }).on('fileuploaddone', function (e, data) {
  
	location.reload();

  });

  // Enable iframe cross-domain access via redirect option:
  $('#fileupload').fileupload(
    'option',
    'redirect',
    window.location.href.replace(/\/[^/]*$/, '/cors/result.html?%s')
  );

  if (window.location.hostname === 'blueimp.github.io') {
    // Demo settings:
    $('#fileupload').fileupload('option', {
      url: '//jquery-file-upload.appspot.com/',
      // Enable image resizing, except for Android and Opera,
      // which actually support image resizing, but fail to
      // send Blob objects via XHR requests:
      disableImageResize: /Android(?!.*Chrome)|Opera/.test(
        window.navigator.userAgent
      ),
      maxFileSize: 999000,
      acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
    });
    // Upload server status check for browsers with CORS support:
    if ($.support.cors) {
      $.ajax({
        url: '//jquery-file-upload.appspot.com/',
        type: 'HEAD'
      }).fail(function () {
        $('<div class="alert alert-danger"></div>')
          .text('Upload server currently unavailable - ' + new Date())
          .appendTo('#fileupload');
      });
    }
  } else {
    // Load existing files:
    $('#fileupload').addClass('fileupload-processing');
    $.ajax({
      // Uncomment the following to send cross-domain cookies:
      //xhrFields: {withCredentials: true},
      url: $('#fileupload').fileupload('option', 'url'),
      dataType: 'json',
      context: $('#fileupload')[0]
    })
      .always(function () {
        $(this).removeClass('fileupload-processing');
      })
      .done(function (result) {
        $(this)
          .fileupload('option', 'done')
          // eslint-disable-next-line new-cap
          .call(this, $.Event('done'), { result: result });
      });
  }
 


$('#fileupload').on('fileuploaddestroy', function (e, data) {
      var filename = data.url.substring(data.url.indexOf("=") + 1,data.url.indexOf("&"))
      var delconf = confirm("Delete the file \"" + decodeURIComponent(filename) + "\"?");
      if(!delconf) {
          e.preventDefault;
          return false;
      }
});

  
});

</script>
