added rate&go

This commit is contained in:
2024-11-20 11:53:04 +01:00
parent f9f9d45f08
commit f9c4d4f77b
47 changed files with 2193 additions and 7 deletions
+240
View File
@@ -0,0 +1,240 @@
<?php
require '../../vendor/autoload.php';
include '../include/headscript.php';
include '../../Connections/repnew.php';
header('Content-Type: application/json');
use Dompdf\Dompdf;
use Dompdf\Options;
$currentDate = date('d-m-Y');
$title = $_POST['title'];
$content = $_POST['content'];
$filterStart = $_POST['filterStart'];
$filterEnd = $_POST['filterEnd'];
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die(json_encode(["error" => "Connection failed: " . $conn->connect_error]));
}
$stmt = $conn->prepare("SELECT * from company");
$stmt->execute();
$result = $stmt->get_result();
$logoname = $result->fetch_all(MYSQLI_ASSOC);
$stmt = $conn->prepare("DELETE from reportsections");
$stmt->execute();
$stmt = $conn->prepare("INSERT INTO reportsections (
cover_title, cover_subtitle, instructionsdetails_title, instructiondetails_text,
overviewstatistic_title, overviewstatistic_text, supplieristatistic_title, supplieristatistic_text,
analysisstatistic_title, analysisstatistic_text, analytscompounds_title, analytscompounds_text,
finalevaluation_title, finalevaluation_text
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if ($stmt === false) {
die(json_encode(["error" => "Prepare statement failed: " . $conn->error]));
}
$stmt->bind_param(
'ssssssssssssss',
$title[0],
$content[0],
$title[1],
$content[1],
$title[2],
$content[2],
$title[3],
$content[3],
$title[4],
$content[4],
$title[5],
$content[5],
$title[6],
$content[6]
);
if (!$stmt->execute()) {
die(json_encode(["error" => "Execute statement failed: " . $stmt->error]));
}
$stmt->close();
$conn->close();
$chartdata0 = file_get_contents('../../../resources/charts/chart0.ch');
$chartdata1 = file_get_contents('../../../resources/charts/chart1.ch');
$chartdata2 = file_get_contents('../../../resources/charts/chart2.ch');
$chartdata3 = file_get_contents('../../../resources/charts/chart3.ch');
$chartdata4 = file_get_contents('../../../resources/charts/chart4.ch');
$chartdata5 = file_get_contents('../../../resources/charts/chart5.ch');
$tmplogo = file_get_contents('../uploadlogo/' . $logoname[0]['logocompany']);
$base64logo = base64_encode($tmplogo);
$logodata = 'data:image/jpeg;base64,' . $base64logo;
$page =
'<html>
<head>
<title>Financial Report</title>
<style>
body {
font-family: DejaVu Sans;
}
#headerdate {
font-family: DejaVu Sans;
display: inline-block;
width: 450px;
text-align: right;
}
footer {
display: "inline-block";
margin-top:500px;
}
div > h3 {
font-family: DejaVu Sans;
font-size: 30px;
}
#filter{
font-family: DejaVu Sans;
font-size: 20px;
margin-left: 50px;
}
#content {
font-family: DejaVu Sans;
font-size: 20px;
}
.page-break { page-break-before: always; }
</style>
</head>
<body>
<div id="page1">
<div>
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<div id="headerdate" style="font-family: Dejavu Sans;">Date:&nbsp;' . $currentDate . '</div>
</div>
<div>
<div style="text-align: center; font-size: 70px; margin-top: 200px; font-family: Dejavu Sans;">' . $title[0] . ' </div>
<div style="margin-left: 20px; text-align: center; font-size: 30px; font-family: Dejavu Sans;">' . $content[0] . '</div>
</div>
<div style="margin-top: 500px;">
<div style="margin-left: 50px;display: inline-block;width: 40%;font-size: 15px; font-family: Dejavu Sans;"> Created by: ' . $nameuser . '</div>
<div style="margin-left: 50px;display: inline-block;width: 40%;font-size: 15px; font-family: Dejavu Sans;"> Date ' . $currentDate . '</div>
</div>
</div>
<div style="page-break-before: always;" ></div>
<div id="page2">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[1] . '</h3>
<hr />
<p id = "content" style="font-family: Dejavu Sans; font-size: 20px;">' . $content[1] . '</p>
<div>
<p id="filtertitle" style="margin-top: 450px; font-family: Dejavu Sans;">FILTERS APPLIED</p>
<p id="filterdata" style="font-family: Dejavu Sans;">From Date ' . $filterStart . ' to Date ' . $filterEnd . '</p>
<p id="filterdata" style="font-family: Dejavu Sans;">Other Filters</p>
</div>
</div>
<div style="page-break-before: always;"> </div>
<div id="page3">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[2] . '</h3>
<hr />
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">
' . $content[2] . '
</p>
<div id="chart">
<img src=' . $chartdata0 . ' width="700px" />
<img src=' . $chartdata1 . ' width="700px" />
</div>
</div>
<div style="page-break-before: always;" ></div>
<div id="page4">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[3] . '</h3>
<hr />
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">' . $content[3] . '</p>
<div id="chart">
<img src=' . $chartdata2 . ' width="700px" />
<img src=' . $chartdata3 . ' width="700px" />
</div>
</div>
<div style="page-break-before: always;"> </div>
<div id="page4">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[4] . '</h3>
<hr />
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">' . $content[4] . '</p>
<div id="chart">
<img src=' . $chartdata4 . ' width="700px" />
</div>
</div>
<div style="page-break-before: always;" > </div>
<div id="page6">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[5] . '</h3>
<hr />
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;">' . $content[5] . '</p>
<div id="chart">
<img src=' . $chartdata5 . ' width="700px" />
</div>
</div>
<div style="page-break-before: always;" > </div>
<div id="page7">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[6] . '</h3>
<hr />
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;">' . $content[6] . '</p>
</div>
</body>
</html>';
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($page);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$filePath = "../../download/";
$filename = "Report" . date('d-m-Y-H-i') . ".pdf";
if (!is_dir('../../download/')) {
mkdir('../../download/', 0777, true);
}
file_put_contents($filePath . $filename, $dompdf->output());
if (file_exists($filePath . $filename)) {
$response['status'] = 'success';
$response['message'] = 'http://127.0.0.1/reportifynew/public/download/';
$response['file'] = $filename;
} else {
$response['status'] = 'error';
$response['message'] = 'PDF download fail';
}
echo json_encode($response);
+229
View File
@@ -0,0 +1,229 @@
<?php
require '../../vendor/autoload.php';
include '../include/headscript.php';
include '../../Connections/repnew.php';
header('Content-Type: application/json');
$currentDate = date('d-m-Y');
$title = $_POST['title'];
$content = $_POST['content'];
$filterStart = $_POST['filterStart'];
$filterEnd = $_POST['filterEnd'];
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die(json_encode(["error" => "Connection failed: " . $conn->connect_error]));
}
$stmt = $conn->prepare("SELECT * from company");
$stmt->execute();
$result = $stmt->get_result();
$logoname = $result->fetch_all(MYSQLI_ASSOC);
$stmt = $conn->prepare("DELETE from reportsections");
$stmt->execute();
$stmt = $conn->prepare("INSERT INTO reportsections (
cover_title, cover_subtitle, instructionsdetails_title, instructiondetails_text,
overviewstatistic_title, overviewstatistic_text, supplieristatistic_title, supplieristatistic_text,
analysisstatistic_title, analysisstatistic_text, analytscompounds_title, analytscompounds_text,
finalevaluation_title, finalevaluation_text
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if ($stmt === false) {
die(json_encode(["error" => "Prepare statement failed: " . $conn->error]));
}
$stmt->bind_param(
'ssssssssssssss',
$title[0],
$content[0],
$title[1],
$content[1],
$title[2],
$content[2],
$title[3],
$content[3],
$title[4],
$content[4],
$title[5],
$content[5],
$title[6],
$content[6]
);
if (!$stmt->execute()) {
die(json_encode(["error" => "Execute statement failed: " . $stmt->error]));
}
$stmt->close();
$conn->close();
$chartdata0 = file_get_contents('../../../resources/charts/chart0.ch');
$chartdata1 = file_get_contents('../../../resources/charts/chart1.ch');
$chartdata2 = file_get_contents('../../../resources/charts/chart2.ch');
$chartdata3 = file_get_contents('../../../resources/charts/chart3.ch');
$chartdata4 = file_get_contents('../../../resources/charts/chart4.ch');
$chartdata5 = file_get_contents('../../../resources/charts/chart5.ch');
$tmplogo = file_get_contents('../uploadlogo/' . $logoname[0]['logocompany']);
$base64logo = base64_encode($tmplogo);
$logodata = 'data:image/jpeg;base64,' . $base64logo;
$page =
'<html>
<head>
<title>Financial Report</title>
<style>
body {
font-family: DejaVu Sans;
}
#headerdate {
font-family: DejaVu Sans;
display: inline-block;
width: 450px;
text-align: right;
}
footer {
display: "inline-block";
margin-top:500px;
}
div > h3 {
font-family: DejaVu Sans;
font-size: 30px;
}
#filter{
font-family: DejaVu Sans;
font-size: 20px;
margin-left: 50px;
}
#content {
font-family: DejaVu Sans;
font-size: 20px;
}
</style>
</head>
<body>
<div id="page1">
<div>
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<div id="headerdate" style="font-family: Dejavu Sans;">Date:&nbsp;' . $currentDate . '</div>
</div>
<div>
<div style="text-align: center; font-size: 70px; margin-top: 200px; font-family: Dejavu Sans;">' . $title[0] . ' </div>
<div style="margin-left: 20px; text-align: center; font-size: 30px; font-family: Dejavu Sans;">' . $content[0] . '</div>
</div>
<div style="margin-top: 500px;margin-left: 50px;display: inline-block;width: 40%;font-size: 15px; font-family: Dejavu Sans;"> Created by: ' . $nameuser . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date ' . $currentDate . '</div>
</div>
<br style="page-break-before: always;" />
<div id="page2">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[1] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style="font-family: Dejavu Sans; font-size: 20px;">' . $content[1] . '</p>
<div>
<p id="filtertitle" style="margin-top: 650px; font-family: Dejavu Sans;">FILTERS APPLIED</p>
<p id="filterdata" style="font-family: Dejavu Sans;">From Date ' . $filterStart . ' to Date ' . $filterEnd . '</p>
<p id="filterdata" style="font-family: Dejavu Sans;">Other Filters</p>
</div>
</div>
<br style="page-break-before: always;" />
<div id="page3">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[2] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">
' . $content[2] . '
</p>
<div id="chart">
<img src=' . $chartdata0 . ' width="700px" />
<img src=' . $chartdata1 . ' width="700px" />
</div>
</div>
<br style="page-break-before: always;" />
<div id="page4">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[3] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">' . $content[3] . '</p>
<div id="chart">
<img src=' . $chartdata2 . ' width="700px" />
<img src=' . $chartdata3 . ' width="700px" />
</div>
</div>
<br style="page-break-before: always;" />
<div id="page4">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[4] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;"">' . $content[4] . '</p>
<div id="chart">
<img src=' . $chartdata4 . ' width="700px" />
</div>
</div>
<br style="page-break-before: always;" />
<div id="page6">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[5] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;">' . $content[5] . '</p>
<div id="chart">
<img src=' . $chartdata5 . ' width="700px" />
</div>
</div>
<br style="page-break-before: always;" />
<div id="page7">
<img
src=' . $logodata . '
alt="Brand Logo" class="logo" width="150px" height="40px"
/>
<h3 style="font-family: Dejavu Sans; font-size: 30px;">' . $title[6] . '</h3>
<p style="font-size: 20px; font-weight: bolder; font-family: Dejavu Sans;">---------------------------------------------------------------------------------</p>
<p id = "content" style = "font-family: Dejavu Sans; font-size: 20px;">' . $content[6] . '</p>
</div>
</body>
</html>';
$filePath = "../../download/";
$filename = "Report" . date('d-m-Y-H-i') . ".docx";
if (!is_dir('../../download/')) {
mkdir('../../download/', 0777, true);
}
file_put_contents('../../download/report.html', $page);
$command = 'soffice --headless --convert-to docx:"MS Word 2007 XML" ../../download/report.html --outdir "../../download/"';
$output = shell_exec($command);
if (rename('../../download/report.docx', '../../download/Report' . date('d-m-Y-H-i') . '.docx')) {
$response['status'] = 'success';
$response['message'] = 'http://127.0.0.1/reportifynew/public/download/';
$response['file'] = $filename;
} else {
$response['status'] = 'error';
$response['message'] = 'WORD download fail';
}
echo json_encode($response);
unlink('../../download/report.html');
+24
View File
@@ -0,0 +1,24 @@
<?php
if (isset($_POST['chartfile'])) {
$uploadDir = '../../../resources/charts/';
$responses = [];
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
foreach ($_POST['chartfile'] as $key => $base64Image) {
$fileName = 'chart' . $key . '.ch';
$filePath = $uploadDir . $fileName;
if (file_put_contents($filePath, $base64Image)) {
$responses[] = "File uploaded successfully";
} else {
$responses[] = "Failed to save file";
}
}
echo json_encode($responses);
} else {
echo json_encode(["error" => "No images uploaded."]);
}
+441
View File
@@ -0,0 +1,441 @@
<?php
// Attiva errori PHP per debug
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Connessione al database e query
include '../../Connections/repnew.php';
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT * FROM reportsections LIMIT 1");
if (!$stmt) {
die("Statement preparation failed: " . $conn->error);
}
$stmt->execute();
$result = $stmt->get_result();
$insertdata = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$conn->close();
// Verifica dei dati
if (empty($insertdata)) {
die("No data found in reportsections.");
}
$jsonData = json_encode($insertdata[0], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
?>
<!DOCTYPE html>
<html lang="en">
<style>
.modal-dialog {
max-width: none !important;
width: auto !important;
}
.custom-modal-dialog {
max-width: 70vw !important;
width: 70vw !important;
height: 85vh !important;
margin: 50px auto !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
}
.modal-content {
width: 100% !important;
height: 100% !important;
}
.pagetitle {
font-size: 1.5vw !important;
}
.custom-textarea {
font-size: 1vw !important;
width: 100% !important;
height: 20vh !important;
padding: 10px !important;
border-radius: 10px !important;
}
.modal-body {
overflow-y: auto !important;
height: 60vh !important;
padding: 20px !important;
box-sizing: border-box !important;
}
.modalspinner {
border: 8px solid #f3f3f3;
border-top: 8px solid #3498db;
border-radius: 50%;
width: 60px;
height: 60px;
animation: spin 1s linear infinite;
position: fixed;
top: 40%;
left: 50%;
transform: translate(-90%, -50%);
z-index: 9999;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<!-- Modale -->
<div class="modal fade" id="documentModal" tabindex="-1" aria-labelledby="documentModalLabel" aria-hidden="true"
role="dialog" data-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog custom-modal-dialog custom-modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="pagetitle">Finalcial Report</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="false" id="btn-close">
<span>&times</span>
</button>
</div>
<div class="modal-body">
<div id="modalspinner" class="modalspinner" style="display: none;"></div>
<div class="mb-3 row">
<label for="title" class="col-sm-1 col-form-label">Title</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="title" value="<?php echo ($insertdata[0]['cover_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<label for="subtitle" class="col-sm-1 col-form-label">Subtitle</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="subtitle" value="<?php echo ($insertdata[0]['cover_subtitle']) ?>">
</div>
</div>
<div class="page1">
<div class="mb-3 row">
<label for="section1" class="col-sm-1 col-form-label">Section1</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section1" placeholder="section1" value="<?php echo ($insertdata[0]['instructionsdetails_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content1"><?php echo ($insertdata[0]['instructiondetails_text']) ?></div>
</div>
</div>
</div>
<div class="page2">
<div class="mb-3 row">
<label for="section2" class="col-sm-1 col-form-label">Section2</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section2" placeholder="section2" value="<?php echo ($insertdata[0]['overviewstatistic_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content2"><?php echo ($insertdata[0]['overviewstatistic_text']) ?></div>
</div>
</div>
</div>
<div class="page3">
<div class="mb-3 row">
<label for="section3" class="col-sm-1 col-form-label">Section3</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section3" placeholder="section3" value="<?php echo ($insertdata[0]['supplieristatistic_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content3"><?php echo ($insertdata[0]['supplieristatistic_text']) ?></div>
</div>
</div>
</div>
<div class="page4">
<div class="mb-3 row">
<label for="section4" class="col-sm-1 col-form-label">Section4</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section4" placeholder="section4" value="<?php echo ($insertdata[0]['analysisstatistic_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content4"><?php echo ($insertdata[0]['analysisstatistic_text']) ?></div>
</div>
</div>
</div>
<div class="page5">
<div class="mb-3 row">
<label for="section5" class="col-sm-1 col-form-label">Section5</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section5" placeholder="section5" value="<?php echo ($insertdata[0]['analytscompounds_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content5"><?php echo ($insertdata[0]['analytscompounds_text']) ?></div>
</div>
</div>
</div>
<div class="page6">
<div class="mb-3 row">
<label for="section6" class="col-sm-1 col-form-label">Section6</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="section6" placeholder="section6" value="<?php echo ($insertdata[0]['finalevaluation_title']) ?>">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-12">
<div type="text" class="content" id="content6"><?php echo ($insertdata[0]['finalevaluation_text']) ?></div>
</div>
</div>
</div>
</div>
<div class="modal-footer mb-3">
<button type="button" class="btn btn-danger" id="createPdf">PDF</button>
<button type="button" class="btn btn-success" id="createWord">Word</button>
</div>
</div>
</div>
</div>
<!-- Bootstrap, jQuery, CKEditor e html2canvas -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<script>
let titles = [];
let contents = [];
let chartdata = [];
const editors = [];
const spinner = document.getElementById('modalspinner');
for (let i = 1; i < 7; i++) {
ClassicEditor
.create(document.querySelector('#content' + i), {
toolbar: [
'bold', 'italic', 'bulletedList', 'numberedList', 'alignment', 'undo', 'redo'
]
})
.then(editor => {
editors[i - 1] = editor;
})
.catch(error => {
console.error('Error initializing CKEditor for content' + i + ':', error);
});
}
function disableModal(flag) {
document.getElementById('btn-close').disabled = flag;
document.getElementById('title').disabled = flag;
document.getElementById('subtitle').disabled = flag;
document.getElementById('section1').disabled = flag;
document.getElementById('content1').disabled = flag;
document.getElementById('section2').disabled = flag;
document.getElementById('content2').disabled = flag;
document.getElementById('section3').disabled = flag;
document.getElementById('content3').disabled = flag;
document.getElementById('section4').disabled = flag;
document.getElementById('content4').disabled = flag;
document.getElementById('section5').disabled = flag;
document.getElementById('content5').disabled = flag;
document.getElementById('section6').disabled = flag;
document.getElementById('content6').disabled = flag;
}
document.getElementById('createPdf').addEventListener('click', function() {
disableModal(true);
spinner.style.display = 'block';
contents = [];
contents.push(document.getElementById('subtitle').value);
editors.forEach((editor, index) => {
const data = editor.getData();
const selectedElement = editor.model.document.selection.getSelectedElement();
const styles = selectedElement ? selectedElement.getAttribute('style') || 'No style applied' : 'No style applied';
contents.push(data);
});
getTitleData();
createChart('pdf');
});
document.getElementById('createWord').addEventListener('click', function() {
disableModal(true);
spinner.style.display = 'block';
contents = [];
contents.push(document.getElementById('subtitle').value);
editors.forEach((editor, index) => {
const data = editor.getData();
const selectedElement = editor.model.document.selection.getSelectedElement();
const styles = selectedElement ? selectedElement.getAttribute('style') || 'No style applied' : 'No style applied';
contents.push(data);
});
getTitleData();
createChart('word');
});
function getTitleData() {
titles = [];
titles.push(document.getElementById('title').value);
for (let i = 1; i < 7; i++) {
titles.push(document.getElementById('section' + i).value);
}
}
function createPdf() {
filterStart = document.getElementById('startDate').value;
filterEnd = document.getElementById('endDate').value;
try {
$.ajax({
url: 'createPdf.php',
type: 'POST',
data: {
title: titles,
content: contents,
filterStart: filterStart,
filterEnd: filterEnd
},
dataType: 'json',
success: function(response) {
const fileurl = response['message'] + response['file'];
const filename = response['file'];
fetch(fileurl)
.then((response) => response.blob())
.then((blob) => {
console.log("blob", blob);
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
console.log('second - ', url);
console.log(filename);
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch((error) => console.error("error downloading file", error));
console.log('success', response);
},
error: function(response) {
alert('PDF download fail');
console.log('error', response);
}
});
} catch (error) {
alert(error);
} finally {
disableModal(false);
spinner.style.display = 'none';
}
}
const chartIds = [1, 2, 3, 4, 5, 6];
async function createChart(flag) {
var formData = new FormData();
for (const chartId of chartIds) {
try {
let chartElement = document.getElementById('chart' + chartId);
const canvas = await html2canvas(chartElement, {
backgroundColor: 'ffffff',
scale: 5
});
const chartImg = canvas.toDataURL('image/png');
formData.append('chartfile[]', chartImg);
} catch (error) {
console.log('Capture error:', error);
}
}
try {
const response = await fetch('create_chart.php', {
method: 'POST',
body: formData
});
if (!response.ok) {
const errorText = await response.text();
console.error('Error creating images:', errorText);
} else {
const result = await response.text();
if (flag == 'pdf') createPdf();
if (flag == 'word') createWord();
}
} catch (error) {
console.error('Fetch error:', error);
}
}
function createWord() {
filterStart = document.getElementById('startDate').value;
filterEnd = document.getElementById('endDate').value;
createChart();
try {
$.ajax({
url: 'createWord.php',
type: 'POST',
data: {
title: titles,
content: contents,
filterStart: filterStart,
filterEnd: filterEnd,
},
dataType: 'json',
success: function(response) {
const url = response['message'] + response['file'];
const filename = response['file'];
console.log(url, "----", filename);
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const url = window.URL.createObjectURL(blob);
console.log(url);
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch((error) => console.error("error downloading file", error));
console.log('success', response);
},
error: function(response) {
alert('WORD download fail');
console.log('error', response);
}
});
} catch (error) {
alert(error);
} finally {
disableModal(false);
spinner.style.display = 'none';
}
}
</script>
</body>
</html>
+10 -1
View File
@@ -1,6 +1,7 @@
<?php include('../include/headscript.php'); ?>
<?php include("../class/company.php");
include('parsedatachart.php');
//include('documentModal.php');
?>
<!DOCTYPE html>
<html lang="en">
@@ -219,6 +220,10 @@ include('parsedatachart.php');
justify-content: center;
align-items: center;
}
.card-body {
background-color: white;
}
</style>
</head>
@@ -305,7 +310,7 @@ include('parsedatachart.php');
<!-- end page title end breadcrumb -->
<button id="toggleFilters" class="btn btn-primary">Toggle Filters</button>
<button id="createPDF" class="btn btn-primary">Report</button>
<!-- Right Sidebar -->
<div class="filter-sidebar" id="filterSidebar">
<?php
@@ -380,6 +385,10 @@ include('parsedatachart.php');
$('#main-content').toggleClass('collapsed');
});
$('#createPDF').on('click', function() {
$('#documentModal').modal('show');
});
$('.select2').on('change', function() {
updateActiveFilters();
});