<!DOCTYPE html>
<html>

<?php

	$sel_uid = 1874;

//$sel_uid	=	$_REQUEST['sel_uid'];

?>

<head>
    <!--Bootstrap-->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
        crossorigin="anonymous"></script>

    <!--JQuery-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <!--Custom css file-->
    <link rel="stylesheet" href="./style.css">
</head>

<body>
    <div class="form-container container">
      
            <div class="row">



       </div>
	   <div class="row">

					dave	<input  type="text" id="sel_uid" value="<?php echo htmlspecialchars($sel_uid)?>">

                    
                <div class="col-sm-10">
                    <div class="mb-3" class="custom-file-upload">
				Upload Product Image 
					                    <div class="custom-file-upload" style="height: 100px">
                        <input type="file" id="filedisc" accept="image/*, .pdf">
                        <label for="filedisc">
                            <span>
                                <strong>
                                    <ion-icon name="cloud-upload-outline"></ion-icon>
                                    <i>Select file or take photo, <br>then click "Upload" button.</i>
                                </strong>
                            </span>
                        </label>
                    </div>
                       
                    </div>
            
         

            <div style="display: none" class="alert alert-success" role="alert" id="success-alertdisc"></div>
            <div style="display: none"  class="alert alert-danger" role="alert" id="error-alertdisc"></div>

            <div class="row">
			<br>
                <button onclick="upload_image(<?php echo htmlspecialchars($sel_uid)?>)" type="submit" class="btn btn-primary">Upload Image Now</button>
            </div>
			   </div>
			       </div>
    
    </div>
   <!-- Passport for person 1 -->
    <script>
        
		$("#file-form-disc").submit(function (event) {
			
			
		
	//		console.log($('#file').prop('files')[0]['name']);
//			alert ($("#file-type option:selected").text());

			
            event.preventDefault();
			
			let successAlert = $("#success-alertdisc");
				successAlert.css("display", "block");
                successAlert.html("<p>Loading ...</p>");
						
            let errorAlert = $("#error-alertdisc").css("display", "none");
                errorAlert.css("display", "none");
			
			
		//	$file_name_sel = $('#file').prop('files')[0]['name'];
			
		//	if ($file_name_sel == "ZZ"){
		//		alert ("Please select a file ");
		//		return false;
			
		//	}
			
		//	alert ($('#file').prop('files')[0]));

            let formData = new FormData();
            formData.append('file', $('#filedisc').prop('files')[0]);
            formData.append('sel_uid', document.getElementById("sel_uid").value);



            $.ajax({
                accepts: "aplication/json",
                url: "uploadFiledisc.php",
                type: "post",
                processData: false,
                contentType: false,
                data: formData,
                success: function (response) {
                    console.log(response);
                    if (response.isSuccess === true) {
                        let successAlert = $("#success-alertdisc");
                        successAlert.css("display", "block");
                        successAlert.html("<p>" + response.message + "</p>");
						location.reload();
                    } else {
                        let errorAlert = $("#error-alertdisc").css("display", "none");
                        errorAlert.css("display", "block");
                        errorAlert.html("<p> Error message: " + response.message + "</p>");
						
						let successAlert = $("#success-alertdisc");
                        successAlert.css("display", "none");
                        successAlert.html("");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    let errorAlert = $("#error-alertdisc").css("display", "none");
                    errorAlert.css("display", "block");
                    errorAlert.html("<p>Unexpected error occurred</p>");
                }
            });
        });
    
	function upload_image(sel_uid){
		alert ("upload"+sel_uid);
		

            $.ajax({
                accepts: "aplication/json",
                url: "uploadFiledisc.php",
                type: "post",
                processData: false,
                contentType: false,
               data: {"sel_uid" : sel_uid},
                success: function (response) {
					
					alert (response);
                    console.log(response);
                    if (response.isSuccess === true) {
                        let successAlert = $("#success-alertdisc");
                        successAlert.css("display", "block");
                        successAlert.html("<p>" + response.message + "</p>");
						location.reload();
                    } else {
                        let errorAlert = $("#error-alertdisc").css("display", "none");
                        errorAlert.css("display", "block");
                        errorAlert.html("<p> Error message: " + response.message + "</p>");
						
						let successAlert = $("#success-alertdisc");
                        successAlert.css("display", "none");
                        successAlert.html("");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    let errorAlert = $("#error-alertdisc").css("display", "none");
                    errorAlert.css("display", "block");
                    errorAlert.html("<p>Unexpected error occurred</p>");
                }
            });
		
	}
	
	
	</script>
</body>

</html>