Implement Menú Comedor sharing between aularios via JSON configuration
Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
@@ -23,7 +23,19 @@ if ($aulario_id === "" || $centro_id === "") {
|
||||
$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";
|
||||
// Check if this aulario shares comedor data from another aulario
|
||||
$source_aulario_id = $aulario_id; // Default to current aulario
|
||||
$is_shared = false;
|
||||
if ($aulario && !empty($aulario["shared_comedor_from"])) {
|
||||
$shared_from = $aulario["shared_comedor_from"];
|
||||
$shared_aulario_path = "/DATA/entreaulas/Centros/$centro_id/Aularios/$shared_from.json";
|
||||
if (file_exists($shared_aulario_path)) {
|
||||
$source_aulario_id = $shared_from;
|
||||
$is_shared = true;
|
||||
}
|
||||
}
|
||||
|
||||
$menuTypesPath = "/DATA/entreaulas/Centros/$centro_id/Aularios/$source_aulario_id/Comedor-MenuTypes.json";
|
||||
$defaultMenuTypes = [
|
||||
["id" => "basal", "label" => "Menú basal", "color" => "#0d6efd"],
|
||||
["id" => "vegetariano", "label" => "Menú vegetariano", "color" => "#198754"],
|
||||
@@ -58,7 +70,7 @@ if (!in_array($menuTypeId, $menuTypeIds, true)) {
|
||||
|
||||
$ym = $dateObj->format("Y-m");
|
||||
$day = $dateObj->format("d");
|
||||
$baseDir = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Comedor/$ym/$day";
|
||||
$baseDir = "/DATA/entreaulas/Centros/$centro_id/Aularios/$source_aulario_id/Comedor/$ym/$day";
|
||||
$dataPath = "$baseDir/_datos.json";
|
||||
|
||||
function blank_menu()
|
||||
@@ -86,7 +98,7 @@ if (!isset($menuData["menus"][$menuTypeId])) {
|
||||
$menuData["menus"][$menuTypeId] = blank_menu();
|
||||
}
|
||||
|
||||
$canEdit = in_array("sysadmin:access", $_SESSION["auth_data"]["permissions"] ?? []);
|
||||
$canEdit = in_array("sysadmin:access", $_SESSION["auth_data"]["permissions"] ?? []) && !$is_shared;
|
||||
$saveNotice = "";
|
||||
$uploadErrors = [];
|
||||
|
||||
@@ -171,7 +183,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && $canEdit) {
|
||||
}
|
||||
|
||||
$menuForType = $menuData["menus"][$menuTypeId] ?? blank_menu();
|
||||
function image_src($value, $centro_id, $aulario_id, $date)
|
||||
function image_src($value, $centro_id, $source_aulario_id, $date)
|
||||
{
|
||||
if (!$value) {
|
||||
return "";
|
||||
@@ -179,7 +191,7 @@ function image_src($value, $centro_id, $aulario_id, $date)
|
||||
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);
|
||||
return "/entreaulas/_filefetch.php?type=comedor_image¢ro=" . urlencode($centro_id) . "&aulario=" . urlencode($source_aulario_id) . "&date=" . urlencode($date) . "&file=" . urlencode($value);
|
||||
}
|
||||
|
||||
$prevDate = (clone $dateObj)->modify("-1 day")->format("Y-m-d");
|
||||
@@ -199,6 +211,12 @@ foreach ($userAulas as $aulaId) {
|
||||
|
||||
|
||||
|
||||
<?php if ($is_shared): ?>
|
||||
<div class="card pad" style="background: #cfe2ff; color: #084298;">
|
||||
<strong>ℹ️ Datos compartidos:</strong> Este aulario está mostrando los menús del aulario origen. Para editar, debes acceder al aulario origen o desactivar el compartir en la configuración.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($saveNotice !== ""): ?>
|
||||
<div class="card pad" style="background: #d1e7dd; color: #0f5132;">
|
||||
<?= htmlspecialchars($saveNotice) ?>
|
||||
@@ -260,7 +278,7 @@ foreach ($userAulas as $aulaId) {
|
||||
];
|
||||
foreach ($plates as $plateKey => $plateLabel):
|
||||
$plate = $menuForType["plates"][$plateKey] ?? ["name" => "", "pictogram" => ""];
|
||||
$pictSrc = image_src($plate["pictogram"] ?? "", $centro_id, $aulario_id, $date);
|
||||
$pictSrc = image_src($plate["pictogram"] ?? "", $centro_id, $source_aulario_id, $date);
|
||||
?>
|
||||
<div class="card pad menu-card">
|
||||
<h3 class="menu-title"><?= htmlspecialchars($plateLabel) ?></h3>
|
||||
|
||||
@@ -20,6 +20,30 @@ switch ($_GET["form"]) {
|
||||
header("Location: ?action=index");
|
||||
exit();
|
||||
break;
|
||||
case "save_edit":
|
||||
$aulario_id = $_POST["aulario_id"];
|
||||
$centro_id = $_POST["centro_id"];
|
||||
$aulario_file = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json";
|
||||
if (!file_exists($aulario_file)) {
|
||||
die("Aulario no encontrado.");
|
||||
}
|
||||
$aulario_data = json_decode(file_get_contents($aulario_file), true);
|
||||
$aulario_data["name"] = $_POST["name"];
|
||||
$aulario_data["icon"] = $_POST["icon"];
|
||||
|
||||
// Handle shared comedor configuration
|
||||
$share_comedor_from = $_POST["share_comedor_from"] ?? "";
|
||||
|
||||
if (!empty($share_comedor_from) && $share_comedor_from !== "none") {
|
||||
$aulario_data["shared_comedor_from"] = $share_comedor_from;
|
||||
} else {
|
||||
unset($aulario_data["shared_comedor_from"]);
|
||||
}
|
||||
|
||||
file_put_contents($aulario_file, json_encode($aulario_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
header("Location: ?action=edit&aulario=" . urlencode($aulario_id) . "¢ro=" . urlencode($centro_id) . "&saved=1");
|
||||
exit();
|
||||
break;
|
||||
}
|
||||
|
||||
require_once "_incl/pre-body.php";
|
||||
@@ -69,7 +93,21 @@ switch ($_GET["action"]) {
|
||||
die("Aulario no encontrado.");
|
||||
}
|
||||
$aulario_data = json_decode(file_get_contents($aulario_file), true);
|
||||
|
||||
// Get all aularios from the same centro for sharing options
|
||||
$available_aularios = [];
|
||||
$aularios_files = glob("/DATA/entreaulas/Centros/$centro_id/Aularios/*.json");
|
||||
foreach ($aularios_files as $aul_file) {
|
||||
$aul_id = basename($aul_file, ".json");
|
||||
if ($aul_id !== $aulario_id) { // Don't allow sharing from itself
|
||||
$aul_data = json_decode(file_get_contents($aul_file), true);
|
||||
$available_aularios[$aul_id] = $aul_data['name'] ?? $aul_id;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if (isset($_GET['saved'])): ?>
|
||||
<div class="alert alert-success">Cambios guardados correctamente.</div>
|
||||
<?php endif; ?>
|
||||
<div class="card pad">
|
||||
<div>
|
||||
<h1 class="card-title">Editar Aulario: <?php echo htmlspecialchars($aulario_data['name'] ?? 'Sin Nombre'); ?></h1>
|
||||
@@ -82,6 +120,24 @@ switch ($_GET["action"]) {
|
||||
<label for="icon" class="form-label">Icono del Aulario (URL):</label>
|
||||
<input type="text" id="icon" name="icon" class="form-control" value="<?php echo htmlspecialchars($aulario_data['icon'] ?? '/static/iconexperience/blackboard.png'); ?>">
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<h3>Compartir Menú Comedor</h3>
|
||||
<p class="text-muted">Configura desde qué aulario compartir los datos del menú comedor. Si se selecciona un aulario origen, este aulario mostrará los menús del aulario seleccionado en lugar de los propios.</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="share_comedor_from" class="form-label">Menú Comedor - Compartir desde:</label>
|
||||
<select id="share_comedor_from" name="share_comedor_from" class="form-select">
|
||||
<option value="none">No compartir (usar datos propios)</option>
|
||||
<?php foreach ($available_aularios as $aul_id => $aul_name): ?>
|
||||
<option value="<?php echo htmlspecialchars($aul_id); ?>"
|
||||
<?php echo ($aulario_data['shared_comedor_from'] ?? '') === $aul_id ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($aul_name); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="aulario_id" value="<?php echo htmlspecialchars($aulario_id); ?>">
|
||||
<input type="hidden" name="centro_id" value="<?php echo htmlspecialchars($centro_id); ?>">
|
||||
<button type="submit" class="btn btn-primary">Guardar Cambios</button>
|
||||
|
||||
Reference in New Issue
Block a user