<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel</title>
    <script src="lib/js/libs/jquery.min.js"></script>


	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
	<!-- <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script> -->
	<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>



	<style>

	.spinner {
	width: 40px;
	height: 40px;
	border: 5px solid rgba(0, 0, 0, 0.1);
	border-top-color: #3498db;
	border-radius: 50%;
	animation: spin 1s infinite linear;
	}

	@keyframes spin {
	to {
	transition: 2s;	
	transform: rotate(360deg);
	}

	}

	</style>


</head>
<body>

	<br>
		
	<div class="container">


	<div id="loader" style="display: none;">
	<div class="spinner"></div>
	</div>




	<h5><i><b>Upload PDF & Store Information:-</b></i></h5>
	<br>

	<label>Website Name:</label>
	<input type="text" id="websiteName" required>

	<label>Upload PDF:</label>
	<input type="file" id="pdfUpload" accept="application/pdf">

	<button onclick="uploadPdf()" class="btn btn-danger">Upload</button>



	<br><br>

	<h5><i><b>Uploaded Files:-</b></i></h5>
	<br>
	<table border="1" width="100%" class="table table-bordered">
	<thead >

	<tr> 
	<th>#</th>
	<th>Website Name</th>
	<th>PDF</th>
	<th>Unique URL</th>
	</tr>


	</thead>
	<tbody id="fileList"></tbody>
	</table>

	<script>

	function uploadPdf() {
	var fileInput = document.getElementById("pdfUpload");
	var websiteName = document.getElementById("websiteName").value;

	if (fileInput.files.length === 0 || websiteName === "") {
	alert("Please enter a website name and select a PDF file.");
	return;
	}

	var formData = new FormData();
	formData.append("website_name", websiteName);
	formData.append("pdfFile", fileInput.files[0]);

	$("#loader").show(); // Show loader before upload starts

	$.ajax({
	url: "upload.php",
	type: "POST",
	data: formData,
	contentType: false,
	processData: false,
	success: function (response) {
	var result = JSON.parse(response);
	$("#loader").hide(); // Hide loader after upload

	if (result.status === "success") {
	alert("Upload successful!");
	loadFiles();
	window.location.href = "http://localhost/flip_pdf/admin.php"; // Redirect to admin panel
	} else {
	alert("Upload failed: " + result.message);
	}
	},
	error: function () {
	$("#loader").hide(); // Hide loader on error
	alert("Something went wrong!");
	}
	});
	}


	function loadFiles() {
	$.ajax({
	url: "fetch_files.php",
	type: "GET",
	success: function (response) {
	$("#fileList").html(response);
	}
	});
	}

	loadFiles();
	</script>




	</div>



</body>
</html>
