<?php 
 
  if($_GET['appid']==NULL){
  	 
  	 header('location:verification.php');

  }

include ('../ro_head.php'); ?>

<link href="../assets/admin/layout/css/custom.css" rel="stylesheet" type="text/css"/>
<link href="../assets/css/daterangepicker.css" rel="stylesheet" type="text/css"/>

<!--  Validation jquery  -->

<script type="text/javascript">
 function myFunction(str,app,type) {

        if (confirm("Do you want to delete this item?") == true) {
            //window.location = 'delete.php?id='+str;
            window.location = 'removefile.php?file=' + str+ "&app="+app+ "&type="+type;
        }

    }
function reloadFunction() {
    location.reload();
}        

</script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 <script src="scanner.js" type="text/javascript"></script>

    <script>
        //
        // Please read scanner.js developer's guide at: http://asprise.com/document-scan-upload-image-browser/ie-chrome-firefox-scanner-docs.html
        //

        /** Initiates a scan */
        function scanToJpg() {
            scanner.scan(displayImagesOnPage,
                    {
                        "output_settings": [
                            {
                                "type": "return-base64",
                                "format": "jpg"
                            }
                        ]
                    }
            );
        }

        /** Processes the scan result */
        function displayImagesOnPage(successful, mesg, response) {
            if(!successful) { // On error
                console.error('Failed: ' + mesg);
                return;
            }

            if(successful && mesg != null && mesg.toLowerCase().indexOf('user cancel') >= 0) { // User cancelled.
                console.info('User cancelled');
                return;
            }

            var scannedImages = scanner.getScannedImages(response, true, false); // returns an array of ScannedImage
            for(var i = 0; (scannedImages instanceof Array) && i < scannedImages.length; i++) {
                var scannedImage = scannedImages[i];
                processScannedImage(scannedImage);
            }
        }

        /** Images scanned so far. */
        var imagesScanned = [];

        /** Processes a ScannedImage */
        function processScannedImage(scannedImage) {
            imagesScanned.push(scannedImage);
            var elementImg = scanner.createDomElementFromModel( {
                'name': 'img',
                'attributes': {
                    'class': 'scanned',
                    'src': scannedImage.src
                }
            });
            document.getElementById('images').appendChild(elementImg);
        }

        <!-- Previous lines are same as demo-01, below is new addition to demo-02 -->

        /** Upload scanned images by submitting the form */
        function submitFormWithScannedImages() {
            if (scanner.submitFormWithImages('form1', imagesScanned, function (xhr) {
                if (xhr.readyState == 4) { // 4: request finished and response is ready
                    document.getElementById('server_response').innerHTML = "<h5></h5>" + xhr.responseText;
                    document.getElementById('images').innerHTML = ''; // clear images
                    imagesScanned = [];
                }
            })) {
                document.getElementById('server_response').innerHTML = "Submitting, please stand by ...";
            } else {
                document.getElementById('server_response').innerHTML = "Form submission cancelled. Please scan first.";
            }
        }

    </script>

 
 <script type="text/javascript">
            $(document).ready(function (e) {
                $('#upload').on('click', function () {
                    var form_data = new FormData();
                    var ins = document.getElementById('multiFiles').files.length;
                    for (var x = 0; x < ins; x++) {
                        form_data.append("files[]", document.getElementById('multiFiles').files[x]);
                    }
                    var aid = $('#appid').val();
                    var dtype = $('#doctype').val();
                    
                    $.ajax({
                        url: 'upload-file.php?appid='+ aid+'&dtype='+ dtype, // point to server-side PHP script 
                        dataType: 'text', // what to expect back from the PHP script
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: form_data,
                        type: 'post',
                        success: function (response) {
                            $('#msg').html(response); // display success response from the PHP script
                        },
                        error: function (response) {
                            $('#msg').html(response); // display error response from the PHP script
                        }
                    });
                });
            });
        </script>

<style type="text/css">
	h3{
		background-color: #c6deef;
		padding: 10px 0px 10px 20px;
		font-size: 18px;
	}
.box{	
border: 2px solid #95a5a6;
    padding: 10px 10px;
    margin: 10px;
    }
.uploadbox{
	
    padding: 10px 15px;
    margin: 20px 0px;
    background-color: #f7f7f7;
    }

    
        img.scanned {
            height: 200px; /** Sets the display size */
            margin-right: 12px;
        }

        div#images {
            margin-top: 20px;
        }
    
	
</style>
<!-- END PAGE LEVEL STYLES -->

<!-- BEGIN CONTAINER -->
<div class="page-container">
<?php include_once("../ro_sidebar.php"); ?>
    <!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			
			
			<!-- BEGIN PAGE HEADER-->
			
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box grey-cascade">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-globe"></i>Uploaded Passport copy  
							</div>

						</div>
						<div class="portlet-body">
							<div class="table-toolbar">
								<div class="row">
									<div class="col-md-12">
									<?php
									
										$sqlq = "SELECT * FROM app_docu_table WHERE app_id='".$_GET['appid']."' and doc_type='1'";

										$resultq = mysqli_query($con,$sqlq);

										while($rowq = mysqli_fetch_array($resultq)){
										
											echo "<div class='col-md-2 box'>";
											echo $rowq['doc_name']."<br/><br/><a href='uploads/passportcopy/".$rowq['file']."' class='btn btn-success btn-xs' target='_blank'>View file</a>"; 
											//echo "<br/>";
											?>
											
											<a href="#" class="btn btn-danger btn-xs" onclick="myFunction('<?php echo $rowq['file']."',".$_GET['appid'].", 1 "; ?>)" title="Delete">Delete</a> 
											
											<?php

											echo "</div>";
										}
									?>
									</div>
									
								      
								</div>
									
							</div>
						</div>
							
					</div>
				</div>

				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box grey-cascade">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-globe"></i>Uploaded Visa Application Form  
							</div>

						</div>
						<div class="portlet-body">
							<div class="table-toolbar">
								<div class="row">
									<div class="col-md-12">
									<?php
									
										$sqlq = "SELECT * FROM app_docu_table WHERE app_id='".$_GET['appid']."' and doc_type='2'";

										$resultq = mysqli_query($con,$sqlq);

										while($rowq = mysqli_fetch_array($resultq)){
										
											echo "<div class='col-md-2 box'>";
											echo $rowq['doc_name']."<br/><br/><a href='uploads/visaappform/".$rowq['file']."' class='btn btn-success btn-xs' target='_blank'>View file</a>";
											//echo "<br/>";
											?>
											
											<a href="#" class="btn btn-danger btn-xs" onclick="myFunction('<?php echo $rowq['file']."',".$_GET['appid'].", 2 "; ?>)" title="Delete">Delete</a> 
											
											<?php
											
											echo "</div>";

										}


									?>
									</div>
								      
								</div>
									
							</div>
						</div>
				<?php						
				// $rs = mysqli_query($con,"select pstatus from applicant_table where app_id='$_GET[appid]'");
    //             $row=mysqli_fetch_array($rs);
         		
    //             if($row["pstatus"]==0){
                ?>
						<div class="col-md-12">
							<div class="col-md-6">

									 <div class="uploadbox">
									 	<h4>Add Documents by upload</h4>
									 	<p id="msg"></p>
									 	<input type="hidden" id="appid" value="<?php echo $_GET['appid']; ?>">
									 	<select id="doctype" class="form-control" style="margin-bottom: 15px;" required>
									 		<option value=''>-select-</option>
									 		<option value='1'>Passport Copy</option>
									 		<option value='2'>Visa Application Form</option>
									 	</select>
							        	<input type="file" id="multiFiles" name="files[]" multiple="multiple" accept=".jpg,.jpeg,.pdf,.doc,.docx,.zip" style="display:inline; width:210px;"/>
							        	<button class="btn green" id="upload" >Upload </button>
							        	<br><br>* Each file size should be maximum 3 MB.
							        	</div>
							        	</div>

							        	<div class="col-md-6">
											<div class="uploadbox">
											<h4>Add Documents by Scanning</h4>
											 <button type="button" class="btn blue" onclick="scanToJpg();">Scan</button>
	  										<div id="images"></div>
							        	<form id="form1" action="scan-upload.php?action=dump&appid=<?php echo $_GET['appid']; ?>" method="POST" enctype="multipart/form-data" target="_blank" >
							        	<input type="hidden" name="appid" value="<?php echo $_GET['appid']; ?>">
									 	<select name="doctype" class="form-control" style="margin-bottom: 15px;" required>
									 		<option value=''>-select-</option>
									 		<option value='1'>Passport Copy</option>
									 		<option value='2'>Visa Application Form</option>
									 	</select>
        
        <input type="button" class="btn green" value="Submit" onclick="submitFormWithScannedImages();">
        <br><br>* Each file size should be maximum 3 MB. 
    </form>
    <div id="server_response"></div>	</div>
						
						</div>
					</div>
							
					</div>
				</div>
				<?php //} ?>

					<!-- END EXAMPLE TABLE PORTLET-->
			</div>


		</div>
	</div>
</div>


			<!-- END PAGE CONTENT-->
		</div>
	</div>
	<!-- END CONTENT -->
	
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php include_once("../ro_footer.php"); ?>







<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<?php include_once("../ro_js.php"); ?>

<script type="text/javascript" src="../assets/global/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="../assets/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
<script>
jQuery(document).ready(function() {       
   Metronic.init(); // init metronic core components
Layout.init(); // init current layout
QuickSidebar.init(); // init quick sidebar
Demo.init(); // init demo features
   TableManaged.init();
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>