1143 lines
30 KiB
HTML
1143 lines
30 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title id="dynamicTitle"></title>
|
|
|
|
<meta name="description" content="">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<!-- Favicon -->
|
|
<link rel="icon" type="image/png" sizes="56x56" href="assets/images/fav-icon/v.png">
|
|
<!-- bootstrap CSS -->
|
|
<link rel="stylesheet" href="./assets/css/bootstrap.min.css" type="text/css" media="all" />
|
|
<!-- carousel CSS -->
|
|
<link rel="stylesheet" href="assets/css/owl.carousel.min.css" type="text/css" media="all"/>
|
|
<!-- nivo-slider CSS -->
|
|
<link rel="stylesheet" href="assets/css/nivo-slider.css" type="text/css" media="all" />
|
|
<!-- animate CSS -->
|
|
<link rel="stylesheet" href="assets/css/animate.css" type="text/css" media="all" />
|
|
<!-- animated-text CSS -->
|
|
<link rel="stylesheet" href="assets/css/animated-text.css" type="text/css" media="all" />
|
|
<!-- font-awesome CSS -->
|
|
<link rel="stylesheet" href="assets/css/all.min.css" type="text/css" media="all" />
|
|
<!-- font-flaticon CSS -->
|
|
<link rel="stylesheet" href="assets/css/flaticon.css" type="text/css" media="all" />
|
|
<!-- theme-default CSS -->
|
|
<link rel="stylesheet" href="assets/css/theme-default.css" type="text/css" media="all" />
|
|
<!-- meanmenu CSS -->
|
|
<link rel="stylesheet" href="assets/css/meanmenu.min.css" type="text/css" media="all" />
|
|
<link rel="stylesheet" href="assets/css/font-awesome.min.css" type="text/css" media="all" />
|
|
<!-- Main Style CSS -->
|
|
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
|
|
<!-- transitions CSS -->
|
|
<link rel="stylesheet" href="assets/css/owl.transitions.css" type="text/css" media="all" />
|
|
<!-- venobox CSS -->
|
|
<link rel="stylesheet" href="venobox/venobox.css" type="text/css" media="all" />
|
|
<!-- widget CSS -->
|
|
<link rel="stylesheet" href="assets/css/widget.css" type="text/css" media="all" />
|
|
<!-- responsive CSS -->
|
|
<link rel="stylesheet" href="assets/css/responsive.css" type="text/css" media="all" />
|
|
<!-- modernizr js -->
|
|
<script src="assets/js/vendor/modernizr-3.5.0.min.js"></script>
|
|
<link rel="stylesheet" href="./assets/css/titillium.css" type="text/css">
|
|
<!-- <link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,600' rel='stylesheet' type='text/css'> -->
|
|
<link rel="stylesheet" href="./node_modules/bootstrap-icons/font/bootstrap-icons.css">
|
|
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css"> -->
|
|
|
|
<style>
|
|
|
|
.switch-label {
|
|
width: 20px !important;
|
|
/* width: -webkit-fill-available; */
|
|
display: inline-block;
|
|
position: relative;
|
|
margin-right: 10px;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.option {
|
|
display: none;
|
|
}
|
|
|
|
.option + .switch-label {
|
|
padding-left: 40px;
|
|
}
|
|
|
|
.option + .switch-label::before {
|
|
content: '';
|
|
position: absolute;
|
|
left: 0;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
width: 30px;
|
|
height: 15px;
|
|
background-color: #ccc;
|
|
border-radius: 15px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
|
|
.option + .switch-label::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: 7px;
|
|
top: 50%;
|
|
transform: translate(-50%, -50%); /* Center vertically and horizontally */
|
|
width: 10px;
|
|
height: 10px;
|
|
background-color: white;
|
|
border-radius: 50%;
|
|
transition: left 0.3s;
|
|
}
|
|
|
|
.option:checked + .switch-label::before {
|
|
background-color: #BF303B;
|
|
}
|
|
|
|
.option:checked + .switch-label::after {
|
|
left: calc(93% - 16px); /* Adjusted for circle size */
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
<style>
|
|
|
|
#popupTitleId{
|
|
text-align: center;
|
|
font-size: 30px;
|
|
/* color: black; */
|
|
font-weight: bold;
|
|
margin-top: 48px;
|
|
}
|
|
|
|
.popup {
|
|
width: 379px;
|
|
height: 420px;
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
/* width: 300px; */
|
|
background-color: white;
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
|
z-index: 9999;
|
|
}
|
|
|
|
.popup-content {
|
|
padding: 20px;
|
|
margin-top: 25px;
|
|
margin-left: 57px;
|
|
}
|
|
|
|
.blur-background {
|
|
filter: blur(5px);
|
|
}
|
|
|
|
|
|
/* The Modal (background) */
|
|
.modal {
|
|
display: none; /* Hidden by default */
|
|
position: fixed; /* Stay in place */
|
|
z-index: 1; /* Sit on top */
|
|
padding-top: 100px; /* Location of the box */
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%; /* Full width */
|
|
height: 100%; /* Full height */
|
|
overflow: auto; /* Enable scroll if needed */
|
|
background-color: rgb(0,0,0); /* Fallback color */
|
|
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
|
}
|
|
|
|
/* Modal Content */
|
|
.modal-content {
|
|
background-color: #fefefe;
|
|
margin: auto;.loaded .loader {
|
|
top: -100%;
|
|
opacity: 0;
|
|
}
|
|
padding: 20px;
|
|
border: 1px solid #888;
|
|
width: 80%;
|
|
}
|
|
|
|
/* The Close Button */
|
|
.close {
|
|
color: #aaaaaa;
|
|
float: right;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.close:hover,
|
|
.close:focus {
|
|
color: #000;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Style for the Choose File button */
|
|
.file-input {
|
|
background-color: #533dfd;
|
|
color: #fff;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Style for the Submit button */
|
|
.submit-button {
|
|
background-color: #2ecc71;
|
|
color: #fff;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
height: 55px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
body {
|
|
background-image: url('assets/images/bg1-1.png');
|
|
background-size: cover; /* Adjust as needed */
|
|
background-repeat: no-repeat;
|
|
background-attachment: fixed;
|
|
background-color: #00000073;
|
|
|
|
}
|
|
|
|
h1.title{
|
|
font-size: 20px;
|
|
margin-top: 100px;
|
|
text-align: center;
|
|
font-weight: 500;
|
|
}
|
|
.landing-icons{
|
|
width: 100%;
|
|
text-align: right;
|
|
margin-bottom: -32px;
|
|
margin-left: -16px;
|
|
}
|
|
|
|
|
|
.list-box {
|
|
/* width: 85%; */
|
|
margin-left: 23px;
|
|
/* margin-top: 10%; */
|
|
padding-bottom: 75px;
|
|
margin-top: 35px;
|
|
color: #1d3557
|
|
}
|
|
|
|
.main-header {
|
|
position: fixed!important;
|
|
top: 0!important;
|
|
width: 100%!important;
|
|
background-color: #fff!important;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1)!important;
|
|
z-index: 999!important;
|
|
border-bottom: 2px solid #A8DADC !important;
|
|
}
|
|
|
|
.nav-menu {
|
|
margin-top: -9px!important;
|
|
}
|
|
|
|
.logo-d{
|
|
width: 150px!important;
|
|
padding-top: 10px !important;
|
|
}
|
|
|
|
.heder-menu ul li a {
|
|
font-weight: 400 !important;
|
|
color: #1d3557 !important;
|
|
}
|
|
.heder-menu ul li a:hover {
|
|
filter: invert(23%) sepia(67%) saturate(2476%) hue-rotate(335deg) brightness(89%) contrast(89%);
|
|
}
|
|
|
|
.resent-post-single-box {
|
|
border-bottom: 1px solid #E8E8E8 !important;
|
|
padding-top: 10px !important;
|
|
}
|
|
|
|
.landing-icons a {
|
|
margin-right: 25px;
|
|
}
|
|
|
|
/* .icons i {
|
|
background-color: transparent;
|
|
border: none;
|
|
border-radius: 50%;
|
|
width: 80px;
|
|
height: 80px;
|
|
padding: 10px;
|
|
}
|
|
|
|
.icons i:hover {
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0);
|
|
background-color: #e4d3f8b4;
|
|
} */
|
|
|
|
.icons img:hover{
|
|
|
|
filter: invert(3%) sepia(5%) saturate(5916%) hue-rotate(172deg) brightness(103%) contrast(98%);
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<!-- loder -->
|
|
<!-- <div class="loader-wrapper">
|
|
<div class="loader"></div>
|
|
<div class="loder-section left-section"></div>
|
|
<div class="loder-section right-section"></div>
|
|
</div> -->
|
|
|
|
<div id="overlay">
|
|
<div class="cv-spinner">
|
|
<span class="spinner"></span>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- main-header -->
|
|
<div class="main-header">
|
|
<div class="container">
|
|
<div class="col-lg-12">
|
|
<div class="nav-menu">
|
|
<div class="header-logo">
|
|
<a href="dashboard.html"><img class="logo-d" src="assets/images/Nexa_Author Logo.png" alt=""></a>
|
|
</div>
|
|
<div class="heder-menu">
|
|
<ul>
|
|
<li><a href="addform.html"><img class="addPageMenu" src="assets/images/new.svg" alt="">New</a></li>
|
|
<li><a href="#" id="myBtn"><img class="addPageMenu" src="assets/images/open.svg" alt="">Open</a></li>
|
|
<li><a href="#" id="settingButton"><img class="addPageMenu" src="assets/images/settings.png" alt="" style="width: 19px;">Settings</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h1 class="title">Question Papers</h1>
|
|
|
|
<div class="container">
|
|
<div class="sideber-box list-box">
|
|
<div class="sideber-content">
|
|
<div class="sideber-title">
|
|
</div>
|
|
</div>
|
|
<div id="list"></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- The Modal -->
|
|
<div id="myModal" class="modal">
|
|
<!-- Modal content -->
|
|
<div class="modal-content" style="width: 600px; height: 200px;">
|
|
<span class="close" style="margin-left: 530px;">×</span>
|
|
<span style="margin-top: -13px; font-size: 18px;color: black;font-weight: 500;">Select File To Upload:</span>
|
|
|
|
<div class = "modal_form_box">
|
|
<input type="file" id="fileInput" accept="application/xml,text/xml" onchange="validateFile(this)" style="margin-top: 15px; border: 3px solid #EEECFE;">
|
|
</div>
|
|
<div class="modal_form_button" style="margin-top: 5px; margin-left: 0px;">
|
|
<button onclick="uploadFile()">Upload</button><span id="Message" style="color: rgb(243, 21, 21);"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="copy-right-area">
|
|
<div class="copy-left">
|
|
<span id="copyright" style="color: #1D3557;"></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- jquery js -->
|
|
<script src="assets/js/vendor/jquery-3.2.1.min.js" onload="window.$ = window.jQuery = module.exports;"></script>
|
|
<!-- <script src="./node_modules/jquery/dist/jquery.min.js" onload="window.$ = window.jQuery = module.exports;"></script> -->
|
|
<!-- bootstrap js -->
|
|
<script src="assets/js/bootstrap.min.js"></script>
|
|
<!-- carousel js -->
|
|
<script src="assets/js/owl.carousel.min.js"></script>
|
|
<!-- counterup js -->
|
|
<script src="assets/js/jquery.counterup.min.js"></script>
|
|
<!-- waypoints js -->
|
|
<script src="assets/js/waypoints.min.js"></script>
|
|
<!-- wow js -->
|
|
<script src="assets/js/wow.js"></script>
|
|
<!-- imagesloaded js -->
|
|
<script src="assets/js/imagesloaded.pkgd.min.js"></script>
|
|
<!-- venobox js -->
|
|
<script src="venobox/venobox.js"></script>
|
|
<!-- ajax mail js -->
|
|
<!-- <script src="assets/js/ajax-mail.js"></script> -->
|
|
<!-- animated-text js -->
|
|
<script src="assets/js/animated-text.js"></script>
|
|
<!-- venobox min js -->
|
|
<script src="venobox/venobox.min.js"></script>
|
|
<!-- isotope js -->
|
|
<!-- <script src="assets/js/isotope.pkgd.min.js"></script> -->
|
|
<!-- jquery nivo slider pack js -->
|
|
<script src="assets/js/jquery.nivo.slider.pack.js"></script>
|
|
<!-- jquery meanmenu js -->
|
|
<script src="assets/js/jquery.meanmenu.js"></script>
|
|
<script src="assets/js/popper.min.js"></script>
|
|
<!-- jquery scrollup js -->
|
|
|
|
<script src="assets/js/jquery.scrollUp.js"></script>
|
|
<!-- theme js -->
|
|
<script src="assets/js/theme.js"></script>
|
|
<script src="assets/js/jquery.barfiller.js"></script>
|
|
<script src="index.js"></script>
|
|
|
|
<script src="encode.js"></script>
|
|
<script src="decode.js"></script>
|
|
<script src="envConvertBasetoString.js"></script>
|
|
|
|
|
|
<!-- jquery js -->
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var currentYear = new Date().getFullYear();
|
|
var copyrightElement = document.getElementById('copyright');
|
|
|
|
if (copyrightElement) {
|
|
// Update the year in the copyright notice
|
|
var notice = "© " + currentYear + " Nexa Author. All rights reserved.";
|
|
copyrightElement.innerHTML = notice;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
var configObject = convertBaseToString();
|
|
// configObject.DOWNLOAD_XML_FILE_PATH = homeDirectory+configObject.DOWNLOAD_XML_FILE_PATH;
|
|
|
|
console.log(configObject);
|
|
const Swal = require('sweetalert2');
|
|
|
|
function uploadFile() {
|
|
console.log("file upload");
|
|
const fileInput = document.getElementById('fileInput');
|
|
const selectedFile = fileInput.files[0];
|
|
console.log(selectedFile)
|
|
|
|
fileupload(selectedFile)
|
|
}
|
|
|
|
var msgDiv = document.getElementById('Message');
|
|
var modal = document.getElementById('myModal');
|
|
var fileInput = document.getElementById('fileInput');
|
|
// require('dotenv').config();
|
|
//XmlPath get from .env
|
|
|
|
// const xmlPathenv=process.env.XML_FILE_PATH;
|
|
// const xmlPath = path.join(__dirname,xmlPathenv);
|
|
|
|
const xmlPathenv=configObject.XML_FILE_PATH.trim();
|
|
const xmlPath = path.join(__dirname,xmlPathenv);
|
|
|
|
|
|
function fileupload(filePaths) {
|
|
|
|
console.log('File path:', filePaths);
|
|
|
|
// Handle the selected folder path here
|
|
// You can specify the destination folder path where you want to copy/move the files
|
|
const destinationFolderPath = `${xmlPath}`;
|
|
|
|
// Use fs to copy or move the file
|
|
const fileName =filePaths.name;
|
|
|
|
var getfilepath =filePaths.path;
|
|
console.log(getfilepath)
|
|
const sourceStream = fs.createReadStream(getfilepath);
|
|
console.log(sourceStream)
|
|
const destinationStream = fs.createWriteStream(path.join(destinationFolderPath, fileName));
|
|
|
|
sourceStream.pipe(destinationStream);
|
|
|
|
sourceStream.on('end', () => {
|
|
console.log('File Uploaded successfully');
|
|
modal.style.display = 'none';
|
|
fileInput.value = "";
|
|
Swal.fire({
|
|
title: 'File Uploaded Successfully',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
location.reload();
|
|
}
|
|
});
|
|
});
|
|
|
|
sourceStream.on('error', (err) => {
|
|
console.error('File Upload error:', err);
|
|
modal.style.display = 'none';
|
|
fileInput.value = "";
|
|
Swal.fire('<i class="fa fa-ban" style="color:red"></i>File Upload error:', err)
|
|
});
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const encode = require('./encode');
|
|
|
|
// Get the modal
|
|
var modal = document.getElementById("myModal");
|
|
|
|
// Get the button that opens the modal
|
|
var btn = document.getElementById("myBtn");
|
|
|
|
// Get the <span> element that closes the modal
|
|
var span = document.getElementsByClassName("close")[0];
|
|
|
|
// When the user clicks the button, open the modal
|
|
btn.onclick = function() {
|
|
modal.style.display = "block";
|
|
}
|
|
|
|
// When the user clicks on <span> (x), close the modal
|
|
span.onclick = function() {
|
|
modal.style.display = "none";
|
|
}
|
|
|
|
// When the user clicks anywhere outside of the modal, close it
|
|
window.onclick = function(event) {
|
|
if (event.target == modal) {
|
|
modal.style.display = "none";
|
|
}
|
|
}
|
|
|
|
|
|
//Function for validate the File Type is only XML
|
|
function validateFile(input) {
|
|
const file = input.files[0];
|
|
const allowedExtensions = ["xml"];
|
|
const fileExtension = file.name.split(".").pop().toLowerCase();
|
|
if (!allowedExtensions.includes(fileExtension)) {
|
|
alert('Invalid file type. Only xml files are allowed.')
|
|
input.value = "";
|
|
return;
|
|
}
|
|
}
|
|
|
|
// // Function to download a file by filename
|
|
// function downloadFile(filename) {
|
|
|
|
// const fileURL = `${xmlPath}${filename}`;
|
|
// console.log(fileURL)
|
|
|
|
// // Create a hidden anchor element to trigger the download
|
|
// const a = document.createElement('a');
|
|
// a.style.display = 'none';
|
|
// a.href = fileURL;
|
|
// a.download = filename;
|
|
|
|
// // Append the anchor to the body and click it to trigger the download
|
|
// document.body.appendChild(a);
|
|
// a.click();
|
|
|
|
// // Remove the anchor element
|
|
// document.body.removeChild(a);
|
|
// }
|
|
|
|
function downloadFile(filename) {
|
|
|
|
// console.log(xmlPath);
|
|
|
|
const xmlFilePath = `${xmlPath}${filename}`;
|
|
// console.log(xmlFilePath)
|
|
|
|
const xmlFileNameParts = filename.split('.xml');
|
|
const xmlBaseName = xmlFileNameParts[0];
|
|
const jsonFileName = `${xmlBaseName}_answer.json`;
|
|
const jsonFilePath = `${xmlPath}${jsonFileName}`;
|
|
// console.log(jsonFilePath);
|
|
|
|
|
|
var fileList = findFile(jsonFilePath);
|
|
// console.log(fileList)
|
|
|
|
|
|
// const downloadsPath = process.env.DOWNLOAD_XML_FILE_PATH;
|
|
// const downloadsPath = '/varr/www/html';
|
|
// const isEncrypted = process.env.ENCRYPTED;
|
|
const os = require('os')
|
|
var homeDirectory = os.homedir();
|
|
// console.log(configObject);
|
|
|
|
const downloadsPathTemp = configObject.DOWNLOAD_XML_FILE_PATH.trim();
|
|
const homeDir = require('os').homedir();
|
|
const downloadsPath = `${homeDir}/${downloadsPathTemp}`;
|
|
console.log(downloadsPath);
|
|
|
|
|
|
|
|
// console.log(downloadsPath,'downloadpath');
|
|
const isEncrypted = configObject.ENCRYPTED.trim();
|
|
|
|
const filePathToSave = path.join(downloadsPath, filename);
|
|
const jsonFilePathToSave = path.join(downloadsPath, jsonFileName);
|
|
// console.log(filePathToSave);
|
|
// console.log(jsonFilePathToSave);
|
|
|
|
|
|
if(isEncrypted == 'YES'){
|
|
|
|
// console.log('isEncrypted');
|
|
|
|
// XML File
|
|
|
|
const decodeData = decode(xmlFilePath);
|
|
const encodeData = encode(decodeData, filePathToSave);
|
|
|
|
|
|
// JSON File
|
|
if(fileList !== false)
|
|
{
|
|
const jsonDecodeData = decode(jsonFilePath);
|
|
const jsonEncodeData = encode(jsonDecodeData, jsonFilePathToSave);
|
|
}
|
|
|
|
|
|
}
|
|
else{
|
|
|
|
// console.log('isEncrypted NOT');
|
|
|
|
// //Download XML FIle
|
|
// console.log(xmlFilePath);
|
|
// fs.writeFile(filePathToSave, xmlFilePath, 'utf-8', (err) => {
|
|
|
|
// var errorMessage = "";
|
|
// if (err) {
|
|
// // console.log(err.code);
|
|
// if(err.code == 'EACCES'){
|
|
|
|
|
|
// Download XML File
|
|
try {
|
|
|
|
const content = fs.readFileSync(xmlFilePath, 'utf-8');
|
|
// console.log('xml', content);
|
|
console.log(filePathToSave);
|
|
fs.writeFileSync(filePathToSave, content, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Downloaded",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${filePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${filePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${filePathToSave}`;
|
|
}
|
|
|
|
Swal.fire({
|
|
title: "File Download Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
|
|
// Download JSON File
|
|
if (fileList !== false) {
|
|
try {
|
|
const content = fs.readFileSync(jsonFilePath, 'utf-8');
|
|
console.log('json', content);
|
|
fs.writeFileSync(jsonFilePathToSave, content, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Downloaded",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${jsonFilePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${jsonFilePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${jsonFilePathToSave}`;
|
|
}
|
|
|
|
Swal.fire({
|
|
title: "File Download Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function duplicateFile(oldfilename) {
|
|
|
|
var filename ='';
|
|
|
|
Swal.fire({
|
|
title: 'Enter Filename',
|
|
input: 'text',
|
|
inputValue: '',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Submit',
|
|
cancelButtonText: 'Cancel',
|
|
inputValidator: (value) => {
|
|
// console.log(value);
|
|
|
|
|
|
function removeXmlExtension(value) {
|
|
if (value.endsWith('.xml')) {
|
|
return value.slice(0, -4);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
const entervalue = removeXmlExtension(value);
|
|
|
|
if (value == '') {
|
|
return 'You need to enter Filename!'
|
|
}
|
|
else if (value){
|
|
|
|
const xmlFilePath = `${xmlPath}`;
|
|
const xmlFileNameParts = oldfilename.split('.xml');
|
|
const xmlBaseName = xmlFileNameParts[0];
|
|
const jsonFileName = `${xmlBaseName}_answer.json`;
|
|
const jsonFilePath = `${xmlPath}${jsonFileName}`;
|
|
|
|
|
|
const newXmlFileNameParts = entervalue;
|
|
// const newXmlBaseName = newXmlFileNameParts[0];
|
|
const newJsonFileName = `${newXmlFileNameParts}_answer.json`;
|
|
|
|
var fileList = findFile(jsonFilePath);
|
|
|
|
const downloadsPath = xmlPath;
|
|
|
|
|
|
const isEncrypted = configObject.ENCRYPTED.trim();
|
|
|
|
const filePathToSave = path.join(downloadsPath);
|
|
const jsonFilePathToSave = path.join(downloadsPath);
|
|
|
|
|
|
|
|
if(isEncrypted == 'YES'){
|
|
// const content = fs.readFileSync(`${xmlFilePath}${oldfilename}`, 'utf-8');
|
|
const content =decode(`${xmlFilePath}${oldfilename}`);
|
|
const encrypt = encode(content);
|
|
try {
|
|
fs.writeFileSync(`${xmlFilePath}${entervalue}.xml`, encrypt, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Duplicated",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${filePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${filePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${filePathToSave}`;
|
|
}
|
|
Swal.fire({
|
|
title: "File Duplicate Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
|
|
if (fileList !== false)
|
|
{
|
|
try {
|
|
const content =decode(jsonFilePath);
|
|
const encrypt = encode(content);
|
|
// console.log('json', content);
|
|
fs.writeFileSync(`${jsonFilePathToSave}${newJsonFileName}`, encrypt, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Duplicated",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${jsonFilePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${jsonFilePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${jsonFilePathToSave}`;
|
|
}
|
|
Swal.fire({
|
|
title: "File Duplicate Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
}
|
|
|
|
}else{
|
|
try {
|
|
const content = fs.readFileSync(`${xmlFilePath}${oldfilename}`, 'utf-8');
|
|
fs.writeFileSync(`${xmlFilePath}${entervalue}.xml`, content, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Duplicated",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${filePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${filePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${filePathToSave}`;
|
|
}
|
|
Swal.fire({
|
|
title: "File Duplicate Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
|
|
// Duplicate JSON File
|
|
if (fileList !== false)
|
|
{
|
|
try {
|
|
const content = fs.readFileSync(jsonFilePath, 'utf-8');
|
|
// console.log('json', content);
|
|
fs.writeFileSync(`${jsonFilePathToSave}${newJsonFileName}`, content, 'utf-8');
|
|
Swal.fire({
|
|
title: "File Duplicated",
|
|
icon: "success"
|
|
});
|
|
} catch (err) {
|
|
let errorMessage = "";
|
|
if (err.code === 'EACCES') {
|
|
errorMessage = `Permission Denied.<br> Path: ${jsonFilePathToSave}`;
|
|
} else if (err.code === 'ENOENT') {
|
|
errorMessage = `No Such File Directory. <br> Path: ${jsonFilePathToSave}`;
|
|
} else {
|
|
errorMessage = `Unknown Error. <br> Path: ${jsonFilePathToSave}`;
|
|
}
|
|
Swal.fire({
|
|
title: "File Duplicate Failed",
|
|
html: errorMessage,
|
|
icon: "error"
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
const inputValue = result.value
|
|
savexml(inputValue)
|
|
}else if(result.isDenied){
|
|
savexml(RawFileName)
|
|
}
|
|
window.location.reload();
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function for Finding the JSON File in the folder
|
|
function findFile(filePath) {
|
|
try {
|
|
const stats = fs.statSync(filePath);
|
|
|
|
if (stats.isFile()) {
|
|
|
|
// File exists
|
|
// console.log(`File found at: ${filePath}`);
|
|
return true;
|
|
} else {
|
|
// console.error(`Path is not a file: ${filePath}`);
|
|
return false;
|
|
}
|
|
} catch (err) {
|
|
// console.error(`File not found: ${filePath}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function copyFile(sourceFilePath, destinationFilePath) {
|
|
// Resolve absolute paths
|
|
const sourcePath = path.resolve(sourceFilePath);
|
|
const destinationPath = path.resolve(destinationFilePath);
|
|
|
|
// Read the content of the source file
|
|
fs.readFile(sourcePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(`Error reading file: ${err.message}`);
|
|
return;
|
|
}
|
|
|
|
// Write the content to the destination file
|
|
fs.writeFile(destinationPath, data, 'utf8', (err) => {
|
|
if (err) {
|
|
console.error(`Error writing file: ${err.message}`);
|
|
return;
|
|
}
|
|
|
|
console.log(`File copied from ${sourcePath} to ${destinationPath}`);
|
|
});
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- Start this is Add TItle Dynamic -->
|
|
<script>
|
|
var dynamicTitleValue = 'Nexa Author';
|
|
document.getElementById("dynamicTitle").innerText = dynamicTitleValue;
|
|
</script>
|
|
<!-- End this is Add TItle Dynamic -->
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const settingBtn = document.getElementById('settingButton');
|
|
const overlay = document.getElementById('overlay');
|
|
|
|
settingBtn.onclick = function() {
|
|
openPopup();
|
|
};
|
|
|
|
function openPopup() {
|
|
var headermenu = document.querySelector('.heder-menu')
|
|
|
|
headermenu.style.display= 'none';
|
|
|
|
const popup = document.createElement('div');
|
|
popup.className = 'popup';
|
|
|
|
const iconElement = document.createElement('i');
|
|
iconElement.className = 'fas fa-icon-class';
|
|
iconElement.style = "margin-right: 15px; margin-top: 15px;float: right;";
|
|
iconElement.onclick = closePopup;
|
|
|
|
const iconimage = document.createElement('img');
|
|
iconimage.src= "assets/images/close.svg";
|
|
iconimage.style="width: 25px";
|
|
iconElement.appendChild(iconimage)
|
|
|
|
const popupTitle = document.createElement('p');
|
|
popupTitle.id='popupTitleId';
|
|
popupTitle.textContent = 'App Settings';
|
|
|
|
const popupContent = document.createElement('div');
|
|
popupContent.className = 'popup-content';
|
|
|
|
const radioOptions = [
|
|
{value: 'WorkArea', label: 'Work Area'},
|
|
{value: 'SubTitle', label: 'Sub Title'},
|
|
{value: 'MathCheckbox', label: 'Math'},
|
|
{value: 'TextQuestionButton', label: 'Text Question'},
|
|
{value: 'MCQQuestionButton', label: 'MCQ Question '}
|
|
];
|
|
|
|
radioOptions.forEach(option => {
|
|
const checkboxInput = document.createElement('input');
|
|
checkboxInput.type = 'checkbox';
|
|
checkboxInput.name = option.value; // Set name attribute if needed
|
|
checkboxInput.value = option.value; // Set value attribute if needed
|
|
checkboxInput.id = `switch-${option.value}`; // Set unique id for each checkbox
|
|
checkboxInput.className = 'option'; // Add class name if needed
|
|
popupContent.appendChild(checkboxInput);
|
|
|
|
// Create label for the checkbox
|
|
const label = document.createElement('label');
|
|
// label.textContent = option.label; // Set label text
|
|
label.setAttribute('for', `switch-${option.value}`); // Set for attribute to match the checkbox's id attribute
|
|
label.className = 'switch-label'; // Add class name if needed
|
|
popupContent.appendChild(label);
|
|
|
|
const label2 = document.createElement('label');
|
|
label2.textContent = option.label;
|
|
popupContent.appendChild(label2);
|
|
|
|
|
|
popupContent.appendChild(document.createElement('br'));
|
|
});
|
|
|
|
// Add submit button
|
|
const submitButton = document.createElement('button');
|
|
submitButton.style=style="width: 142px; border-radius: 10px; margin-left: 41px; margin-top: 28px; border-color: #BF303B; /* color: #BF3054; */ /* background-color: #BF303B; */";
|
|
submitButton.textContent = 'Submit';
|
|
submitButton.type = 'button'; // Set type to button to prevent form submission
|
|
submitButton.addEventListener('click', () => {
|
|
submitValues();
|
|
closePopup();
|
|
});
|
|
popupContent.appendChild(submitButton);
|
|
|
|
popup.appendChild(iconElement);
|
|
popup.appendChild(popupTitle)
|
|
popup.appendChild(popupContent);
|
|
document.body.appendChild(popup);
|
|
|
|
// Show overlay
|
|
overlay.style.display = 'block';
|
|
}
|
|
|
|
// Function to close popup and hide overlay
|
|
function closePopup() {
|
|
var headermenu = document.querySelector('.heder-menu')
|
|
|
|
headermenu.style.display= 'block';
|
|
|
|
const popup = document.querySelector('.popup');
|
|
if (popup) {
|
|
popup.parentNode.removeChild(popup);
|
|
}
|
|
// Hide overlay
|
|
overlay.style.display = 'none';
|
|
}
|
|
|
|
// Function to submit selected values to server
|
|
function submitValues() {
|
|
var headermenu = document.querySelector('.heder-menu')
|
|
|
|
headermenu.style.display= 'block';
|
|
|
|
// const selectedValues = Array.from(document.querySelectorAll('input[class=option]:checked')).map(input => input.value);
|
|
|
|
const allOptions = Array.from(document.querySelectorAll('input[class=option]'));
|
|
|
|
const uncheckedValues = allOptions.filter(input => !input.checked).map(input => input.value);
|
|
|
|
const checkedValues = allOptions.filter(input => input.checked).map(input => input.value);
|
|
|
|
|
|
|
|
const array = checkedValues;
|
|
const string = array.join(',');
|
|
const jsonString = JSON.stringify(string);
|
|
const wrappedJsonString = `{"AppSetting":[${jsonString}]}`;
|
|
|
|
|
|
//ForUnchecked
|
|
const string2 = uncheckedValues.join(',')
|
|
const jsonString2 = JSON.stringify(string2);
|
|
const wrappedJsonString2 = `{"AppSetting":[${jsonString2}]}`;
|
|
|
|
|
|
const newPath = xmlPath.replace(/\\xml\\/i, '\\');
|
|
|
|
const savexmlpath = path.join(__dirname, `./assets/appSetting/AppSetting.json`);
|
|
const savexmlpath2 = path.join(__dirname, `./assets/appSetting/AppSettingUnchecked.json`);
|
|
|
|
|
|
fs.writeFileSync(savexmlpath, wrappedJsonString, 'utf-8');
|
|
fs.writeFileSync(savexmlpath2, wrappedJsonString2, 'utf-8');
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
function popupCheck() {
|
|
const filePath = path.join(__dirname, `./assets/appSetting/AppSetting.json`);
|
|
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error('Error reading file:', err);
|
|
return;
|
|
}
|
|
const jsonObject = JSON.parse(data);
|
|
|
|
var aa= jsonObject.AppSetting;
|
|
const inputString = aa[0];
|
|
|
|
const valuesArray = inputString.split(',');
|
|
valuesArray.forEach(value => {
|
|
|
|
if(value === 'WorkArea'){
|
|
var elements = document.querySelector('[name="WorkArea"]');
|
|
if (elements) {
|
|
elements.checked = true;
|
|
}
|
|
|
|
}else if( value === 'SubTitle'){
|
|
var elements = document.querySelector('[name="SubTitle"]');
|
|
if (elements) {
|
|
elements.checked = true;
|
|
}
|
|
|
|
}else if(value === 'MathCheckbox'){
|
|
var elements = document.querySelector('[name="MathCheckbox"]');
|
|
if (elements) {
|
|
elements.checked = true;
|
|
}
|
|
}else if(value === 'TextQuestionButton'){
|
|
var elements = document.querySelector('[name="TextQuestionButton"]');
|
|
if (elements) {
|
|
elements.checked = true;
|
|
}
|
|
}else if(value === 'MCQQuestionButton'){
|
|
var elements = document.querySelector('[name="MCQQuestionButton"]');
|
|
if (elements) {
|
|
elements.checked = true;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
var settingButtonParent = document.getElementById('settingButton').parentElement;
|
|
|
|
if (settingButtonParent) {
|
|
settingButtonParent.addEventListener('click', function(event) {
|
|
popupCheck();
|
|
});
|
|
}
|
|
|
|
|
|
// popupCheck();
|
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html>
|