update
This commit is contained in:
@@ -182,7 +182,7 @@ if (!isset($APP_CODE)) {
|
||||
|
||||
</ul>
|
||||
<?php if ($APP_CODE != "ax4") { ?>
|
||||
<a href="/" class="btn btn-secondary pseudo" style="background: #9013FE; color: white;">Salir a Axia4</a>
|
||||
<a href="/" class="btn btn-dark pseudo" style="background: #9013FE; color: white;">Salir a Axia4</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,7 +19,7 @@ switch ($_GET['form'] ?? '') {
|
||||
'password_hash' => $password_hash
|
||||
];
|
||||
if (!is_dir("/DATA/Usuarios")) {
|
||||
mkdir("/DATA/Usuarios", 0755, true);
|
||||
mkdir("/DATA/Usuarios", 0777, true);
|
||||
}
|
||||
file_put_contents("/DATA/Usuarios/$admin_user.json", json_encode($admin_userdata, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
file_put_contents("/DATA/SISTEMA_INSTALADO.txt", "Sistema instalado el ".date("Y-m-d H:i:s")."\n");
|
||||
|
||||
@@ -27,7 +27,7 @@ for ($i = 0; $i < $file_count; $i++) {
|
||||
$folder = $_GET["folder"];
|
||||
$location = "/DATA/club$folder" . $file_name;
|
||||
if (!is_dir("/DATA/club$folder")) {
|
||||
mkdir("/DATA/club$folder", recursive: true);
|
||||
mkdir("/DATA/club$folder", 777, recursive: true);
|
||||
}
|
||||
if (move_uploaded_file($_FILES["file"]["tmp_name"][$i], $location)) {
|
||||
// Generate thumbnail
|
||||
|
||||
@@ -11,6 +11,19 @@ switch ($_GET["type"]) {
|
||||
$activity = str_replace('..', '_', $_GET["activity"] ?? '');
|
||||
$relpath = "entreaulas/Centros/$centro/Panel/Actividades/$activity/photo.jpg";
|
||||
break;
|
||||
case "comedor_image":
|
||||
$centro = str_replace('..', '_', $_GET["centro"] ?? '');
|
||||
$aulario = str_replace('..', '_', $_GET["aulario"] ?? '');
|
||||
$date = preg_replace('/[^0-9-]/', '', $_GET["date"] ?? '');
|
||||
$file = basename($_GET["file"] ?? '');
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
die("Invalid date");
|
||||
}
|
||||
$ym = substr($date, 0, 7);
|
||||
$day = substr($date, 8, 2);
|
||||
$relpath = "entreaulas/Centros/$centro/Aularios/$aulario/Comedor/$ym/$day/$file";
|
||||
break;
|
||||
}
|
||||
$path = "/DATA/$relpath";
|
||||
$uripath = "/$relpath";
|
||||
|
||||
@@ -16,7 +16,7 @@ $aulario = json_decode(file_get_contents("/DATA/entreaulas/Centros/$centro_id/Au
|
||||
|
||||
<div id="grid">
|
||||
<a href="/entreaulas/paneldiario.php?aulario=<?= urlencode($aulario_id) ?>" class="btn btn-primary grid-item">
|
||||
<img src="/static/iconexperience/calendar_preferences.png" height="125">
|
||||
<img src="/static/arasaac/pdi.png" height="125">
|
||||
</br>
|
||||
Panel Diario
|
||||
</a>
|
||||
@@ -24,9 +24,15 @@ $aulario = json_decode(file_get_contents("/DATA/entreaulas/Centros/$centro_id/Au
|
||||
<a href="/sysadmin/aularios.php?action=edit&aulario=<?= urlencode($aulario_id) ?>" class="btn btn-secondary grid-item">
|
||||
<img src="/static/iconexperience/gear_edit.png" height="125">
|
||||
<br>
|
||||
Administración del Aulario
|
||||
Cambiar Ajustes
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<!-- Menú del comedor -->
|
||||
<a href="/entreaulas/comedor.php?aulario=<?= urlencode($aulario_id) ?>" class="btn btn-success grid-item">
|
||||
<img src="/static/arasaac/comedor.png" height="125" style="background: white; padding: 5px; border-radius: 10px;">
|
||||
<br>
|
||||
Menú del Comedor
|
||||
</a>
|
||||
</div>
|
||||
<style>
|
||||
.grid-item {
|
||||
|
||||
415
public_html/entreaulas/comedor.php
Normal file
415
public_html/entreaulas/comedor.php
Normal file
@@ -0,0 +1,415 @@
|
||||
<?php
|
||||
require_once "_incl/auth_redir.php";
|
||||
if (in_array("entreaulas:docente", $_SESSION["auth_data"]["permissions"] ?? []) === false) {
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
die("Access denied");
|
||||
}
|
||||
require_once "_incl/pre-body.php";
|
||||
|
||||
$aulario_id = $_GET["aulario"] ?? "";
|
||||
$centro_id = $_SESSION["auth_data"]["entreaulas"]["centro"] ?? "";
|
||||
|
||||
if ($aulario_id === "" || $centro_id === "") {
|
||||
?>
|
||||
<div class="card pad">
|
||||
<h1>Menú del Comedor</h1>
|
||||
<p>No se ha indicado un aulario válido.</p>
|
||||
</div>
|
||||
<?php
|
||||
require_once "_incl/post-body.php";
|
||||
exit;
|
||||
}
|
||||
|
||||
$aulario_path = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json";
|
||||
$aulario = file_exists($aulario_path) ? json_decode(file_get_contents($aulario_path), true) : null;
|
||||
|
||||
$menuTypesPath = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Comedor-MenuTypes.json";
|
||||
$defaultMenuTypes = [
|
||||
["id" => "basal", "label" => "Menú basal", "color" => "#0d6efd"],
|
||||
["id" => "vegetariano", "label" => "Menú vegetariano", "color" => "#198754"],
|
||||
["id" => "alergias", "label" => "Menú alergias", "color" => "#dc3545"],
|
||||
];
|
||||
if (!file_exists($menuTypesPath)) {
|
||||
if (!is_dir(dirname($menuTypesPath))) {
|
||||
mkdir(dirname($menuTypesPath), 0777, true);
|
||||
}
|
||||
file_put_contents($menuTypesPath, json_encode($defaultMenuTypes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$menuTypes = json_decode(@file_get_contents($menuTypesPath), true);
|
||||
if (!is_array($menuTypes) || count($menuTypes) === 0) {
|
||||
$menuTypes = $defaultMenuTypes;
|
||||
}
|
||||
|
||||
$menuTypeIds = [];
|
||||
foreach ($menuTypes as $t) {
|
||||
if (!empty($t["id"])) {
|
||||
$menuTypeIds[] = $t["id"];
|
||||
}
|
||||
}
|
||||
|
||||
$dateParam = $_GET["date"] ?? date("Y-m-d");
|
||||
$dateObj = DateTime::createFromFormat("Y-m-d", $dateParam) ?: new DateTime();
|
||||
$date = $dateObj->format("Y-m-d");
|
||||
$menuTypeId = $_GET["menu"] ?? ($menuTypeIds[0] ?? "basal");
|
||||
if (!in_array($menuTypeId, $menuTypeIds, true)) {
|
||||
$menuTypeId = $menuTypeIds[0] ?? "basal";
|
||||
}
|
||||
|
||||
$ym = $dateObj->format("Y-m");
|
||||
$day = $dateObj->format("d");
|
||||
$baseDir = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Comedor/$ym/$day";
|
||||
$dataPath = "$baseDir/_datos.json";
|
||||
|
||||
function blank_menu()
|
||||
{
|
||||
return [
|
||||
"plates" => [
|
||||
"primero" => ["name" => "", "pictogram" => ""],
|
||||
"segundo" => ["name" => "", "pictogram" => ""],
|
||||
"postre" => ["name" => "", "pictogram" => ""],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$menuData = [
|
||||
"date" => $date,
|
||||
"menus" => []
|
||||
];
|
||||
if (file_exists($dataPath)) {
|
||||
$existing = json_decode(file_get_contents($dataPath), true);
|
||||
if (is_array($existing)) {
|
||||
$menuData = array_merge($menuData, $existing);
|
||||
}
|
||||
}
|
||||
if (!isset($menuData["menus"][$menuTypeId])) {
|
||||
$menuData["menus"][$menuTypeId] = blank_menu();
|
||||
}
|
||||
|
||||
$canEdit = in_array("sysadmin:access", $_SESSION["auth_data"]["permissions"] ?? []);
|
||||
$saveNotice = "";
|
||||
$uploadErrors = [];
|
||||
|
||||
function safe_filename($name)
|
||||
{
|
||||
$name = basename($name);
|
||||
return preg_replace("/[^a-zA-Z0-9._-]/", "_", $name);
|
||||
}
|
||||
|
||||
function handle_image_upload($fieldName, $targetBaseName, $baseDir, &$uploadErrors)
|
||||
{
|
||||
if (!isset($_FILES[$fieldName]) || $_FILES[$fieldName]["error"] !== UPLOAD_ERR_OK) {
|
||||
return null;
|
||||
}
|
||||
$ext = strtolower(pathinfo($_FILES[$fieldName]["name"], PATHINFO_EXTENSION));
|
||||
$allowed = ["jpg", "jpeg", "png", "webp", "gif"];
|
||||
if (!in_array($ext, $allowed, true)) {
|
||||
$uploadErrors[] = "El archivo " . htmlspecialchars($_FILES[$fieldName]["name"]) . " no es una imagen válida.";
|
||||
return null;
|
||||
}
|
||||
if (!is_dir($baseDir)) {
|
||||
mkdir($baseDir, 0777, true);
|
||||
}
|
||||
$target = "$targetBaseName.$ext";
|
||||
$targetPath = $baseDir . "/" . safe_filename($target);
|
||||
if (move_uploaded_file($_FILES[$fieldName]["tmp_name"], $targetPath)) {
|
||||
return basename($targetPath);
|
||||
}
|
||||
$uploadErrors[] = "No se pudo guardar " . htmlspecialchars($_FILES[$fieldName]["name"]) . ".";
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" && $canEdit) {
|
||||
$action = $_POST["action"] ?? "";
|
||||
|
||||
if ($action === "add_type") {
|
||||
$newId = strtolower(trim($_POST["new_type_id"] ?? ""));
|
||||
$newLabel = trim($_POST["new_type_label"] ?? "");
|
||||
$newColor = trim($_POST["new_type_color"] ?? "#0d6efd");
|
||||
if ($newId !== "" && $newLabel !== "") {
|
||||
$exists = false;
|
||||
foreach ($menuTypes as $t) {
|
||||
if (($t["id"] ?? "") === $newId) {
|
||||
$exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$exists) {
|
||||
$menuTypes[] = ["id" => $newId, "label" => $newLabel, "color" => $newColor];
|
||||
file_put_contents($menuTypesPath, json_encode($menuTypes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
header("Location: /entreaulas/comedor.php?aulario=" . urlencode($aulario_id) . "&date=" . urlencode($date) . "&menu=" . urlencode($newId));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === "save") {
|
||||
$menuTypeId = $_POST["menu_type"] ?? $menuTypeId;
|
||||
if (!isset($menuData["menus"][$menuTypeId])) {
|
||||
$menuData["menus"][$menuTypeId] = blank_menu();
|
||||
}
|
||||
|
||||
$plates = ["primero", "segundo", "postre"];
|
||||
foreach ($plates as $plate) {
|
||||
$name = trim($_POST["name_" . $plate] ?? "");
|
||||
$menuData["menus"][$menuTypeId]["plates"][$plate]["name"] = $name;
|
||||
|
||||
$pictUpload = handle_image_upload("pictogram_file_" . $plate, $menuTypeId . "_" . $plate . "_pict", $baseDir, $uploadErrors);
|
||||
|
||||
if ($pictUpload !== null) {
|
||||
$menuData["menus"][$menuTypeId]["plates"][$plate]["pictogram"] = $pictUpload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!is_dir($baseDir)) {
|
||||
mkdir($baseDir, 0777, true);
|
||||
}
|
||||
file_put_contents($dataPath, json_encode($menuData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
$saveNotice = "Menú guardado correctamente.";
|
||||
}
|
||||
}
|
||||
|
||||
$menuForType = $menuData["menus"][$menuTypeId] ?? blank_menu();
|
||||
function image_src($value, $centro_id, $aulario_id, $date)
|
||||
{
|
||||
if (!$value) {
|
||||
return "";
|
||||
}
|
||||
if (filter_var($value, FILTER_VALIDATE_URL)) {
|
||||
return $value;
|
||||
}
|
||||
return "/entreaulas/_filefetch.php?type=comedor_image¢ro=" . urlencode($centro_id) . "&aulario=" . urlencode($aulario_id) . "&date=" . urlencode($date) . "&file=" . urlencode($value);
|
||||
}
|
||||
|
||||
$prevDate = (clone $dateObj)->modify("-1 day")->format("Y-m-d");
|
||||
$nextDate = (clone $dateObj)->modify("+1 day")->format("Y-m-d");
|
||||
|
||||
$userAulas = $_SESSION["auth_data"]["entreaulas"]["aulas"] ?? [];
|
||||
$aulaOptions = [];
|
||||
foreach ($userAulas as $aulaId) {
|
||||
$aulaPath = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulaId.json";
|
||||
$aulaData = file_exists($aulaPath) ? json_decode(file_get_contents($aulaPath), true) : null;
|
||||
$aulaOptions[] = [
|
||||
"id" => $aulaId,
|
||||
"name" => $aulaData["name"] ?? $aulaId
|
||||
];
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<?php if ($saveNotice !== ""): ?>
|
||||
<div class="card pad" style="background: #d1e7dd; color: #0f5132;">
|
||||
<?= htmlspecialchars($saveNotice) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (count($uploadErrors) > 0): ?>
|
||||
<div class="card pad" style="background: #f8d7da; color: #842029;">
|
||||
<ul style="margin: 0;">
|
||||
<?php foreach ($uploadErrors as $err): ?>
|
||||
<li><?= $err ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Navigation Buttons - Single row -->
|
||||
<div class="card pad">
|
||||
<div style="display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center; flex-direction: row;">
|
||||
<a class="btn btn-outline-dark" href="/entreaulas/comedor.php?aulario=<?= urlencode($aulario_id) ?>&date=<?= urlencode($prevDate) ?>&menu=<?= urlencode($menuTypeId) ?>">⟵ Día anterior</a>
|
||||
<input type="date" id="datePicker" class="form-control form-control-lg" value="<?= htmlspecialchars($date) ?>" style="max-width: 200px;">
|
||||
<a class="btn btn-outline-dark" href="/entreaulas/comedor.php?aulario=<?= urlencode($aulario_id) ?>&date=<?= urlencode($nextDate) ?>&menu=<?= urlencode($menuTypeId) ?>">Día siguiente ⟶</a>
|
||||
</div>
|
||||
<div style="margin-top: 10px; text-align: center;">
|
||||
<label for="aularioPicker" class="form-label" style="margin-right: 10px;">Aulario:</label>
|
||||
<select id="aularioPicker" class="form-select form-select-lg" style="max-width: 300px; display: inline-block;">
|
||||
<?php foreach ($aulaOptions as $option):
|
||||
$isSelected = ($option["id"] ?? "") === $aulario_id;
|
||||
?>
|
||||
<option value="<?= htmlspecialchars($option["id"] ?? "") ?>" <?= $isSelected ? "selected" : "" ?>>
|
||||
<?= htmlspecialchars($option["name"] ?? $option["id"]) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card pad">
|
||||
<h2 style="margin-bottom: 10px;">Tipos de menú</h2>
|
||||
<div style="display: flex; gap: 10px; flex-wrap: wrap;">
|
||||
<?php foreach ($menuTypes as $type):
|
||||
$isActive = ($type["id"] ?? "") === $menuTypeId;
|
||||
$color = $type["color"] ?? "#0d6efd";
|
||||
?>
|
||||
<a href="/entreaulas/comedor.php?aulario=<?= urlencode($aulario_id) ?>&date=<?= urlencode($date) ?>&menu=<?= urlencode($type["id"]) ?>"
|
||||
class="btn btn-lg" style="background: <?= htmlspecialchars($color) ?>; color: white; border: 3px solid <?= $isActive ? "#000" : "transparent" ?>;">
|
||||
<?= htmlspecialchars($type["label"] ?? $type["id"]) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="menu-grid">
|
||||
<?php
|
||||
$plates = [
|
||||
"primero" => "Primer plato",
|
||||
"segundo" => "Segundo plato",
|
||||
"postre" => "Postre"
|
||||
];
|
||||
foreach ($plates as $plateKey => $plateLabel):
|
||||
$plate = $menuForType["plates"][$plateKey] ?? ["name" => "", "pictogram" => ""];
|
||||
$pictSrc = image_src($plate["pictogram"] ?? "", $centro_id, $aulario_id, $date);
|
||||
?>
|
||||
<div class="card pad menu-card">
|
||||
<h3 class="menu-title"><?= htmlspecialchars($plateLabel) ?></h3>
|
||||
<div class="menu-images">
|
||||
<div class="menu-img-block">
|
||||
<div class="menu-img-label">Pictograma</div>
|
||||
<?php if ($pictSrc !== ""): ?>
|
||||
<img class="menu-img" src="<?= htmlspecialchars($pictSrc) ?>" alt="Pictograma de <?= htmlspecialchars($plateLabel) ?>">
|
||||
<?php else: ?>
|
||||
<div class="menu-placeholder">Sin pictograma</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu-name">
|
||||
<?= $plate["name"] !== "" ? htmlspecialchars($plate["name"]) : "Sin nombre" ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($canEdit): ?>
|
||||
<details class="card pad" open>
|
||||
<summary><strong>Editar menú</strong></summary>
|
||||
<form method="post" enctype="multipart/form-data" style="margin-top: 10px;">
|
||||
<input type="hidden" name="action" value="save">
|
||||
<input type="hidden" name="menu_type" value="<?= htmlspecialchars($menuTypeId) ?>">
|
||||
<div class="edit-grid">
|
||||
<?php foreach ($plates as $plateKey => $plateLabel):
|
||||
$plate = $menuForType["plates"][$plateKey] ?? ["name" => "", "pictogram" => ""];
|
||||
?>
|
||||
<div class="card pad" style="background: #f8f9fa;">
|
||||
<h4><?= htmlspecialchars($plateLabel) ?></h4>
|
||||
<label class="form-label">Nombre del plato</label>
|
||||
<input type="text" class="form-control form-control-lg" name="name_<?= $plateKey ?>" value="<?= htmlspecialchars($plate["name"] ?? "") ?>" placeholder="Ej. Lentejas">
|
||||
|
||||
<label class="form-label" style="margin-top: 10px;">Pictograma (archivo)</label>
|
||||
<input type="file" class="form-control form-control-lg" name="pictogram_file_<?= $plateKey ?>" accept="image/*">
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success btn-lg" style="margin-top: 10px;">Guardar menú</button>
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<details class="card pad">
|
||||
<summary><strong>Administrar tipos de menú</strong></summary>
|
||||
<form method="post" style="margin-top: 10px;">
|
||||
<input type="hidden" name="action" value="add_type">
|
||||
<div class="row g-2">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">ID</label>
|
||||
<input type="text" name="new_type_id" class="form-control form-control-lg" placeholder="basal">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label class="form-label">Nombre</label>
|
||||
<input type="text" name="new_type_label" class="form-control form-control-lg" placeholder="Menú basal">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Color</label>
|
||||
<input type="color" name="new_type_color" class="form-control form-control-lg" value="#0d6efd">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-lg" style="margin-top: 10px;">Añadir tipo</button>
|
||||
</form>
|
||||
</details>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.menu-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
.menu-card {
|
||||
min-height: 320px;
|
||||
}
|
||||
.menu-title {
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
.menu-images {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.menu-img-block {
|
||||
text-align: center;
|
||||
}
|
||||
.menu-img-label {
|
||||
font-weight: bold;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.menu-img {
|
||||
max-width: 100%;
|
||||
height: 140px;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
padding: 6px;
|
||||
border: 2px solid #ddd;
|
||||
}
|
||||
.menu-placeholder {
|
||||
height: 140px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f1f1f1;
|
||||
border-radius: 12px;
|
||||
border: 2px dashed #aaa;
|
||||
color: #666;
|
||||
font-weight: bold;
|
||||
}
|
||||
.menu-name {
|
||||
font-size: 1.4rem;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
padding: 6px;
|
||||
background: #fff3cd;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.edit-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
.form-control-lg {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
const datePicker = document.getElementById("datePicker");
|
||||
const aularioPicker = document.getElementById("aularioPicker");
|
||||
function goToSelection() {
|
||||
const dateValue = datePicker ? datePicker.value : "";
|
||||
const aularioValue = aularioPicker ? aularioPicker.value : "";
|
||||
if (!dateValue || !aularioValue) return;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
params.set("date", dateValue);
|
||||
params.set("aulario", aularioValue);
|
||||
params.set("menu", "<?= htmlspecialchars($menuTypeId) ?>");
|
||||
window.location.href = "/entreaulas/comedor.php?" + params.toString();
|
||||
}
|
||||
if (datePicker) {
|
||||
datePicker.addEventListener("change", goToSelection);
|
||||
}
|
||||
if (aularioPicker) {
|
||||
aularioPicker.addEventListener("change", goToSelection);
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php require_once "_incl/post-body.php"; ?>
|
||||
@@ -152,165 +152,197 @@ switch ($_GET["action"]) {
|
||||
<?php
|
||||
break;
|
||||
case "menu":
|
||||
// Menú del comedor
|
||||
// Menú del comedor (nuevo sistema, vista simplificada)
|
||||
$aulario_id = $_GET["aulario"] ?? "";
|
||||
$centro_id = $_SESSION["auth_data"]["entreaulas"]["centro"] ?? "";
|
||||
|
||||
$months = [
|
||||
1 => "Enero",
|
||||
2 => "Febrero",
|
||||
3 => "Marzo",
|
||||
4 => "Abril",
|
||||
5 => "Mayo",
|
||||
6 => "Junio",
|
||||
7 => "Julio",
|
||||
8 => "Agosto",
|
||||
9 => "Septiembre",
|
||||
10 => "Octubre",
|
||||
11 => "Noviembre",
|
||||
12 => "Diciembre"
|
||||
$dateParam = $_GET["date"] ?? date("Y-m-d");
|
||||
$dateObj = DateTime::createFromFormat("Y-m-d", $dateParam) ?: new DateTime();
|
||||
$date = $dateObj->format("Y-m-d");
|
||||
|
||||
$menuTypesPath = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Comedor-MenuTypes.json";
|
||||
$defaultMenuTypes = [
|
||||
["id" => "basal", "label" => "Menú basal", "color" => "#0d6efd"],
|
||||
["id" => "vegetariano", "label" => "Menú vegetariano", "color" => "#198754"],
|
||||
["id" => "alergias", "label" => "Menú alergias", "color" => "#dc3545"],
|
||||
];
|
||||
|
||||
$dow = [
|
||||
1 => "Lunes",
|
||||
2 => "Martes",
|
||||
3 => "Miércoles",
|
||||
4 => "Jueves",
|
||||
5 => "Viernes",
|
||||
6 => "Sábado",
|
||||
7 => "Domingo"
|
||||
];
|
||||
|
||||
$month = $_GET['month'] ?? date('n');
|
||||
$year = $_GET['year'] ?? date('Y');
|
||||
$MENUTY = $_GET['menu'] ?? "basal";
|
||||
|
||||
$parsedTable = null;
|
||||
function getMenuForDay(string $pageText, string $day)
|
||||
{
|
||||
global $parsedTable;
|
||||
|
||||
// ---------------------------------------------
|
||||
// 1. Parse table only once
|
||||
// ---------------------------------------------
|
||||
if ($parsedTable === null) {
|
||||
|
||||
$lines = preg_split("/\R/", $pageText);
|
||||
$rows = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$trim = trim($line);
|
||||
|
||||
// Only lines that start with "|" and are table rows
|
||||
if (strpos($trim, "|") === 0 && substr($trim, -1) === "|") {
|
||||
|
||||
// Remove leading and trailing |, then split
|
||||
$cols = explode("|", trim($trim, "|"));
|
||||
$cols = array_map("trim", $cols);
|
||||
|
||||
if (count($cols) >= 4) {
|
||||
$rows[] = [
|
||||
"fecha" => $cols[0],
|
||||
"plato1" => $cols[1],
|
||||
"plato2" => $cols[2],
|
||||
"postre" => $cols[3]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$parsedTable = $rows; // store result (parsed only once)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// 2. Look for the requested date
|
||||
// ---------------------------------------------
|
||||
foreach ($parsedTable as $row) {
|
||||
if ($row["fecha"] === $day) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
return null; // not found
|
||||
$menuTypes = json_decode(@file_get_contents($menuTypesPath), true);
|
||||
if (!is_array($menuTypes) || count($menuTypes) === 0) {
|
||||
$menuTypes = $defaultMenuTypes;
|
||||
}
|
||||
|
||||
$MENUDATA = file_get_contents("https://aularios.tech.eus/aldamiz_ortuella/menu_comedor/tabla/$MENUTY?do=export_raw");
|
||||
// Solo semana actual, botones. cuando se pulse el botón del dia actual, se enviara un POST ?form=menu con los valores del menu
|
||||
$weeknow = date('W');
|
||||
$menuTypeIds = [];
|
||||
foreach ($menuTypes as $t) {
|
||||
if (!empty($t["id"])) {
|
||||
$menuTypeIds[] = $t["id"];
|
||||
}
|
||||
}
|
||||
$menuTypeId = $_GET["menu"] ?? ($menuTypeIds[0] ?? "basal");
|
||||
if (!in_array($menuTypeId, $menuTypeIds, true)) {
|
||||
$menuTypeId = $menuTypeIds[0] ?? "basal";
|
||||
}
|
||||
|
||||
$ym = $dateObj->format("Y-m");
|
||||
$day = $dateObj->format("d");
|
||||
$dataPath = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Comedor/$ym/$day/_datos.json";
|
||||
|
||||
$menuData = [
|
||||
"date" => $date,
|
||||
"menus" => []
|
||||
];
|
||||
if (file_exists($dataPath)) {
|
||||
$existing = json_decode(file_get_contents($dataPath), true);
|
||||
if (is_array($existing)) {
|
||||
$menuData = array_merge($menuData, $existing);
|
||||
}
|
||||
}
|
||||
$menuForType = $menuData["menus"][$menuTypeId] ?? null;
|
||||
|
||||
function image_src_simple($value, $centro_id, $aulario_id, $date)
|
||||
{
|
||||
if (!$value) {
|
||||
return "";
|
||||
}
|
||||
return "/entreaulas/_filefetch.php?type=comedor_image¢ro=" . urlencode($centro_id) . "&aulario=" . urlencode($aulario_id) . "&date=" . urlencode($date) . "&file=" . urlencode($value);
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
function seleccionarMenuDia(element, dia) {
|
||||
// Si es dia correcto
|
||||
var today = new Date();
|
||||
var currentDay = today.getDate();
|
||||
if (dia == currentDay) {
|
||||
function seleccionarMenuTipo(element, hasData) {
|
||||
if (hasData) {
|
||||
element.style.backgroundColor = "#9cff9f"; // Verde
|
||||
document.getElementById('win-sound').play();
|
||||
setTimeout(() => {
|
||||
location.href = "?aulario=<?php echo urlencode($_GET['aulario'] ?? ''); ?>";
|
||||
window.location.href = "/entreaulas/paneldiario.php?aulario=<?php echo urlencode($_GET['aulario'] ?? ''); ?>";
|
||||
}, 2000);
|
||||
} else {
|
||||
element.style.backgroundColor = "#ff9088"; // Rojo
|
||||
document.getElementById('lose-sound').play();
|
||||
setTimeout(() => {
|
||||
element.style.backgroundColor = ""; // Volver al color anterior
|
||||
element.style.backgroundColor = "";
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div class="card pad">
|
||||
<h1>¿Que vamos a comer?</h1>
|
||||
<h1>¿Qué vamos a comer?</h1>
|
||||
<div class="text-muted"><?= htmlspecialchars($date) ?></div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<?php for ($d = 1; $d <= 31; $d++) {
|
||||
$dateStr = sprintf("%04d-%02d-%02d", $year, $month, $d);
|
||||
$dayOfWeek = date('N', strtotime($dateStr));
|
||||
$weekofmonth = date('W', strtotime($dateStr));
|
||||
if ($dayOfWeek > 5) {
|
||||
continue; // Skip weekends
|
||||
}
|
||||
if ($weekofmonth != $weeknow) {
|
||||
continue; // Only current week
|
||||
}
|
||||
$menuForDay = getMenuForDay($MENUDATA, $dateStr);
|
||||
if ($menuForDay === null) {
|
||||
continue; // No menu for this day
|
||||
|
||||
<div class="menu-grid">
|
||||
<?php
|
||||
$plates = [
|
||||
"primero" => "Primer plato",
|
||||
"segundo" => "Segundo plato",
|
||||
"postre" => "Postre"
|
||||
];
|
||||
foreach ($menuTypes as $type):
|
||||
$typeId = $type["id"] ?? "";
|
||||
$typeLabel = $type["label"] ?? $typeId;
|
||||
$typeColor = $type["color"] ?? "#0d6efd";
|
||||
$menuItem = $menuData["menus"][$typeId] ?? null;
|
||||
$hasData = false;
|
||||
if (is_array($menuItem)) {
|
||||
foreach ($plates as $plateKey => $plateLabel) {
|
||||
$plate = $menuItem["plates"][$plateKey] ?? [];
|
||||
if (!empty($plate["name"]) || !empty($plate["pictogram"]) || !empty($plate["photo"])) {
|
||||
$hasData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<a class="card grid-item" style="width: 250px; height: 250px; color: black;" onclick="seleccionarMenuDia(this, <?php echo $d; ?>);">
|
||||
<h3><?php echo $dow[$dayOfWeek] . " " . $d ?></h3>
|
||||
<ol style="text-align: left; padding-left: 15px;">
|
||||
<li><?php echo htmlspecialchars($menuForDay["plato1"]); ?></li>
|
||||
<li><?php echo htmlspecialchars($menuForDay["plato2"]); ?></li>
|
||||
<li><?php echo htmlspecialchars($menuForDay["postre"]); ?></li>
|
||||
</ol>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<div class="card pad menu-card" onclick="seleccionarMenuTipo(this, <?php echo $hasData ? 'true' : 'false'; ?>);" style="cursor: pointer; border: 4px solid <?= htmlspecialchars($typeColor) ?>;">
|
||||
<h3 class="menu-title" style="color: <?= htmlspecialchars($typeColor) ?>;">
|
||||
<?= htmlspecialchars($typeLabel) ?>
|
||||
</h3>
|
||||
<?php if (!$hasData): ?>
|
||||
<div class="menu-placeholder">Menú no disponible</div>
|
||||
<?php else: ?>
|
||||
<div class="menu-lines">
|
||||
<?php foreach ($plates as $plateKey => $plateLabel):
|
||||
$plate = $menuItem["plates"][$plateKey] ?? ["name" => "", "pictogram" => "", "photo" => ""];
|
||||
$pictSrc = image_src_simple($plate["pictogram"] ?? "", $centro_id, $aulario_id, $date);
|
||||
?>
|
||||
<div class="menu-line">
|
||||
<?php if ($pictSrc !== ""): ?>
|
||||
<img class="menu-line-img" src="<?= htmlspecialchars($pictSrc) ?>" alt="<?= htmlspecialchars($plateLabel) ?>">
|
||||
<?php else: ?>
|
||||
<div class="menu-line-img placeholder">—</div>
|
||||
<?php endif; ?>
|
||||
<div class="menu-line-name">
|
||||
<?= $plate["name"] !== "" ? htmlspecialchars($plate["name"]) : "Sin nombre" ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<style>
|
||||
.grid-item {
|
||||
margin-bottom: 10px !important;
|
||||
padding: 15px;
|
||||
width: 250px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.grid-item img {
|
||||
margin: 0 auto;
|
||||
height: 125px;
|
||||
<style>
|
||||
.menu-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
.menu-card {
|
||||
min-height: 260px;
|
||||
}
|
||||
.menu-title {
|
||||
font-size: 1.6rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.menu-lines {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
.menu-line {
|
||||
display: grid;
|
||||
grid-template-columns: 100px 2fr;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
padding: 6px 8px;
|
||||
border: 2px solid #eee;
|
||||
}
|
||||
.menu-line-title {
|
||||
font-weight: bold;
|
||||
}
|
||||
.menu-line-img {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
border: 2px solid #ddd;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
.menu-line-img.placeholder {
|
||||
background: #f1f1f1;
|
||||
border-style: dashed;
|
||||
color: #777;
|
||||
}
|
||||
.menu-line-name {
|
||||
font-size: 1.1rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
.menu-placeholder {
|
||||
height: 160px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f1f1f1;
|
||||
border-radius: 12px;
|
||||
border: 2px dashed #aaa;
|
||||
color: #666;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var msnry = new Masonry('.grid', {
|
||||
"columnWidth": 250,
|
||||
"itemSelector": ".grid-item",
|
||||
"gutter": 10,
|
||||
"transitionDuration": 0
|
||||
});
|
||||
setTimeout(() => {
|
||||
msnry.layout()
|
||||
}, 250); window.onresize = () => {msnry.layout()}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
break;
|
||||
case "calendar":
|
||||
|
||||
BIN
public_html/static/arasaac/pdi.png
Normal file
BIN
public_html/static/arasaac/pdi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
@@ -79,6 +79,12 @@ switch ($_GET['action'] ?? '') {
|
||||
Acceso
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="permissions[]" value="entreaulas:docente" id="entreaulas-docente">
|
||||
<label class="form-check-label" for="entreaulas-docente">
|
||||
Docente
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -140,6 +146,12 @@ switch ($_GET['action'] ?? '') {
|
||||
Acceso
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="permissions[]" value="entreaulas:docente" id="entreaulas-docente" <?php if (in_array('entreaulas:docente', $userdata['permissions'] ?? [])) echo 'checked'; ?>>
|
||||
<label class="form-check-label" for="entreaulas-docente">
|
||||
Docente
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user