iltuomenu/funzioni.php

613 lines
15 KiB
PHP
Raw Permalink Normal View History

2024-01-25 16:16:59 +01:00
<?php
function visualizzapdfcorrente($wpdb,$etichetta) {
$query = "SELECT * FROM {$wpdb->prefix}listapdf";
$datacorrenteunix = strtotime(date('Y-m-d'));
$query = "SELECT * FROM {$wpdb->prefix}listapdf";
$results = $wpdb->get_results($query);
$controllo = false;
2024-01-29 10:45:34 +01:00
$selezionesenzafine = false;
2024-01-25 16:16:59 +01:00
foreach ($results as $result) {
2024-01-29 10:45:34 +01:00
2024-01-25 16:16:59 +01:00
$dataconfrontoiniziounix = strtotime($result->data_partenza);
$dataconfrontofineunix = strtotime($result->data_fine);
2024-01-29 10:45:34 +01:00
$hafine = $result->hafine;
2024-01-25 16:16:59 +01:00
2024-01-29 10:45:34 +01:00
if ($hafine){
if (!$selezionesenzafine){
2024-01-25 16:16:59 +01:00
if ($datacorrenteunix <= $dataconfrontofineunix){
if ($datacorrenteunix >= $dataconfrontoiniziounix){
$controllo = true;
$nomefileprescelto = $result->nome_file;
$urlfileprescelto = $result->url_completo;
}
}
2024-01-29 10:45:34 +01:00
}
} else {
$controllo = true;
$selezionesenzafine = true;
$nomefileprescelto = $result->nome_file;
$urlfileprescelto = $result->url_completo;
}
2024-01-25 16:16:59 +01:00
}
if ($controllo){
2024-01-29 10:45:34 +01:00
$cartelle = dirname(__FILE__);
$ultimacartella = basename($cartelle);
2024-01-25 16:16:59 +01:00
2024-02-14 10:52:12 +01:00
$urlcomp = site_url().'/wp-content/plugins/'.$ultimacartella.'/menu/';
2024-01-25 16:16:59 +01:00
$finalurl = $urlcomp.$urlfileprescelto;
if (!is_string($etichetta)){
$contenutohtml = generahtmlmodal($finalurl);
} else {
$contenutohtml = generahtmlmodalridotto($finalurl,$etichetta);
}
return array("nome"=>$nomefileprescelto, "url"=>$finalurl,'html'=>$contenutohtml,'controllo'=>$controllo);
} else {
return array ('controllo'=>$controllo);
}
}
function generacssmodal (){
return '<style>
2024-02-15 09:36:15 +01:00
2024-01-25 16:16:59 +01:00
2024-02-14 15:28:13 +01:00
.menu-pdf-container {
2024-02-14 14:37:05 +01:00
max-height: 100%;
2024-01-25 16:16:59 +01:00
width: 100%;
margin-bottom: 20px;
2024-02-14 14:37:05 +01:00
text-align:center;
2024-01-25 16:16:59 +01:00
}
2024-02-15 09:28:02 +01:00
@media only screen and (max-width: 600px) {
2024-01-25 16:16:59 +01:00
canvas {
margin-top:50px;
}
2024-02-15 09:28:02 +01:00
.button-container {
2024-01-25 16:16:59 +01:00
display: flex;
justify-content: space-between;
padding: 10px;
2024-02-14 14:37:05 +01:00
2024-01-25 16:16:59 +01:00
}
}
@media only screen and (min-width: 601px) {
.button-container {
text-align:center;
2024-02-14 14:37:05 +01:00
margin-top:15px;
2024-01-25 16:16:59 +01:00
}
}
2024-02-14 15:28:13 +01:00
.menu-modal {
2024-02-15 09:36:15 +01:00
z-index:200;
2024-01-25 16:16:59 +01:00
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
justify-content: center;
align-items: center;
}
2024-02-15 09:28:02 +01:00
@media only screen and (max-width: 600px) {
.menu-modal-content {
width:100%;
}
}
@media only screen and (min-width: 600px) {
.menu-modal-content {
width:80%;
}
}
2024-01-25 16:16:59 +01:00
/* Contenuto modal */
2024-02-14 15:28:13 +01:00
.menu-modal-content {
2024-01-25 16:16:59 +01:00
background-color: #fff;
height: 100%;
position: relative;
2024-02-14 14:37:05 +01:00
2024-01-25 16:16:59 +01:00
}
/* Tasto chiudi */
.close {
background-color:black;
padding:10px;
position: absolute;
top: 10px;
2024-02-14 15:28:13 +01:00
right: 0px;
2024-01-25 16:16:59 +01:00
font-size: 20px;
cursor: pointer;
color: white;
}
.bottonebello {
background-color: #04AA6D; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
#prev {
padding: 10px;
background-color: #04AA6D; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
#next {
padding: 10px;
background-color: #04AA6D; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
.bottonebello:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
';
}
function generajsmodal() {
return '
<script>
// Open the modal
function openModal() {
document.getElementById("pdfModal").style.display = "flex";
}
// Close the modal
function closeModal() {
document.getElementById("pdfModal").style.display = "none";
}
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
var elements = document.querySelectorAll(".is-layout-constrained");
elements.forEach(function(element) {
element.classList.remove("is-layout-constrained");
});
});
</script>
<script>
function stopScrollPropagation(event) {
// Questo evita che lo scroll sul modale vada sulla pagina
event.stopPropagation();
}
</script>
';
}
function generahtmlmodal($filepdf){
if (controllamenu()) {
2024-01-29 10:45:34 +01:00
$cartelle = dirname(__FILE__);
$ultimacartella = basename($cartelle);
2024-02-14 10:52:12 +01:00
$urlcomp = site_url().'/wp-content/plugins/'.$ultimacartella.'/';
2024-01-25 16:16:59 +01:00
return '
2024-02-14 18:03:30 +01:00
<div style="text-align:center;z-index:100;">
2024-01-25 16:16:59 +01:00
<button class="bottonebello" onclick="openModal()">Apri il Menu</button>
</div>
<!-- Modale PDF -->
2024-02-14 15:28:13 +01:00
<div style="background-color:white;" id="pdfModal" class="menu-modal" onscroll="stopScrollPropagation(event)">
<div class="menu-modal-content">
2024-01-25 16:16:59 +01:00
<!-- Close button -->
<span class="close" onclick="closeModal()">&times;</span>
<!-- METTERE QUI IL VISUALIZZATORE -->
<script src="'.$urlcomp.'pdf.js" type="module"></script>
<script type="module">
// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = "'.$filepdf.'";
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var { pdfjsLib } = globalThis;
// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = "'.$urlcomp.'pdf.worker.js";
var pdfDoc = null,
pageNum = 1,
pageRendering = false,
pageNumPending = null,
scale = 3.0,
canvas = document.getElementById("the-canvas"),
ctx = canvas.getContext("2d");
/**
* Get page info from document, resize canvas accordingly, and render page.
* @param num Page number.
*/
function renderPage(num) {
pageRendering = true;
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport({scale: scale});
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
var renderTask = page.render(renderContext);
// Wait for rendering to finish
renderTask.promise.then(function() {
pageRendering = false;
if (pageNumPending !== null) {
// New page rendering is pending
renderPage(pageNumPending);
pageNumPending = null;
}
});
});
// Update page counters
document.getElementById("page_num").textContent = num;
}
/**
* If another page rendering in progress, waits until the rendering is
* finised. Otherwise, executes rendering immediately.
*/
function queueRenderPage(num) {
if (pageRendering) {
pageNumPending = num;
} else {
renderPage(num);
}
}
/**
* Displays previous page.
*/
function onPrevPage() {
if (pageNum <= 1) {
return;
}
pageNum--;
queueRenderPage(pageNum);
}
document.getElementById("prev").addEventListener("click", onPrevPage);
/**
* Displays next page.
*/
function onNextPage() {
if (pageNum >= pdfDoc.numPages) {
return;
}
pageNum++;
queueRenderPage(pageNum);
}
document.getElementById("next").addEventListener("click", onNextPage);
/**
* Asynchronously downloads PDF.
*/
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
pdfDoc = pdfDoc_;
document.getElementById("page_count").textContent = pdfDoc.numPages;
// Initial/first page rendering
renderPage(pageNum);
});
</script>
2024-02-14 15:28:13 +01:00
<div class="menu-pdf-container" style="overflow:scroll;">
2024-01-25 16:16:59 +01:00
<canvas style="width:100%;" id="the-canvas"></canvas>
<div class="button-container">
<button id="prev">Indietro</button>
<button id="next">Avanti</button>
</div>
<br>
<div style="text-align:center;">
<span>Pagina: <span id="page_num"></span> / <span id="page_count"></span></span>
</div>
</div> <!-- FINE VISUALIZZATORE -->
</div>
</div>
';
} else {
return '<div id="menudisattivato"></div>';
}
2024-01-25 16:16:59 +01:00
}
function generahtmlmodalridotto($filepdf,$etichetta){
if (controllamenu()) {
2024-01-29 10:45:34 +01:00
$cartelle = dirname(__FILE__);
$ultimacartella = basename($cartelle);
2024-02-14 11:06:27 +01:00
$urlcomp = site_url().'/wp-content/plugins/'.$ultimacartella.'/';
2024-01-25 16:16:59 +01:00
return '
2024-02-15 09:36:15 +01:00
<div>
2024-01-25 16:16:59 +01:00
<div style="text-align:center;margin-bottom:12px;"><a style="font-size:20px;text-transform: uppercase;cursor: pointer;" onclick="openModal()">'.$etichetta.'</a></div>
<!-- Modale PDF -->
2024-02-14 15:28:13 +01:00
<div style="background-color:white;" id="pdfModal" class="menu-modal" onscroll="stopScrollPropagation(event)">
<div class="menu-modal-content">
2024-01-25 16:16:59 +01:00
<!-- Close button -->
<span class="close" onclick="closeModal()">&times;</span>
<!-- METTERE QUI IL VISUALIZZATORE -->
<script src="'.$urlcomp.'pdf.js" type="module"></script>
<script type="module">
// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = "'.$filepdf.'";
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var { pdfjsLib } = globalThis;
// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = "'.$urlcomp.'pdf.worker.js";
var pdfDoc = null,
pageNum = 1,
pageRendering = false,
pageNumPending = null,
scale = 3.0,
canvas = document.getElementById("the-canvas"),
ctx = canvas.getContext("2d");
/**
* Get page info from document, resize canvas accordingly, and render page.
* @param num Page number.
*/
function renderPage(num) {
pageRendering = true;
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport({scale: scale});
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
var renderTask = page.render(renderContext);
// Wait for rendering to finish
renderTask.promise.then(function() {
pageRendering = false;
if (pageNumPending !== null) {
// New page rendering is pending
renderPage(pageNumPending);
pageNumPending = null;
}
});
});
// Update page counters
document.getElementById("page_num").textContent = num;
}
/**
* If another page rendering in progress, waits until the rendering is
* finised. Otherwise, executes rendering immediately.
*/
function queueRenderPage(num) {
if (pageRendering) {
pageNumPending = num;
} else {
renderPage(num);
}
}
/**
* Displays previous page.
*/
function onPrevPage() {
if (pageNum <= 1) {
return;
}
pageNum--;
queueRenderPage(pageNum);
}
document.getElementById("prev").addEventListener("click", onPrevPage);
/**
* Displays next page.
*/
function onNextPage() {
if (pageNum >= pdfDoc.numPages) {
return;
}
pageNum++;
queueRenderPage(pageNum);
}
document.getElementById("next").addEventListener("click", onNextPage);
/**
* Asynchronously downloads PDF.
*/
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
pdfDoc = pdfDoc_;
document.getElementById("page_count").textContent = pdfDoc.numPages;
// Initial/first page rendering
renderPage(pageNum);
});
</script>
2024-02-14 18:03:30 +01:00
<div class="menu-pdf-container" style="overflow-y:scroll;overflow-z:hidden;">
2024-01-25 16:16:59 +01:00
<canvas style="width:100%;" id="the-canvas"></canvas>
<div class="button-container">
<button id="prev">Indietro</button>
<button id="next">Avanti</button>
</div>
<br>
<div style="text-align:center;">
<span>Pagina: <span id="page_num"></span> / <span id="page_count"></span></span>
</div>
</div> <!-- FINE VISUALIZZATORE -->
</div>
</div>
</div>
';
} else {
return '<div id="menudisattivato"></div>';
}
}
function controllamenu() {
$cartelle = dirname(__FILE__);
$ultimacartella = basename($cartelle);
$target_dir = $_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/".$ultimacartella."/";
$json_data = file_get_contents($target_dir.'settings.json');
// Decode the JSON data into a PHP associative array
$settings = json_decode($json_data, true);
$statomenu = false;
// Controllo su stato "active"
if (isset($settings['active']) && $settings['active'] === 'yes') {
$statomenu= true;
}
return $statomenu;
}
function scrivisujson ($dato) {
$cartelle = dirname(__FILE__);
$ultimacartella = basename($cartelle);
$target_dir = $_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/".$ultimacartella."/";
$json_data = file_get_contents($target_dir.'settings.json');
// Decode the JSON data into a PHP associative array
$settings = json_decode($json_data, true);
if ($settings !== null) {
$settings['active'] = $dato;
// Encode the modified settings array back to JSON format
$new_json_data = json_encode($settings, JSON_PRETTY_PRINT);
// Write the updated JSON data back to the settings.json file
file_put_contents($target_dir . 'settings.json', $new_json_data);
}
2024-01-29 10:45:34 +01:00
}