diff --git a/public_html/entreaulas/comedor.php b/public_html/entreaulas/comedor.php index 41d7ccd..afa5b41 100644 --- a/public_html/entreaulas/comedor.php +++ b/public_html/entreaulas/comedor.php @@ -155,6 +155,47 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && $canEdit) { } } + if ($action === "delete_type") { + $deleteId = trim($_POST["delete_type_id"] ?? ""); + if ($deleteId !== "") { + $newMenuTypes = []; + foreach ($menuTypes as $t) { + if (($t["id"] ?? "") !== $deleteId) { + $newMenuTypes[] = $t; + } + } + if (count($newMenuTypes) < count($menuTypes)) { + $menuTypes = $newMenuTypes; + file_put_contents($menuTypesPath, json_encode($menuTypes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + // Redirect to the first available menu type or default + $redirectMenuId = !empty($menuTypes) ? $menuTypes[0]["id"] : "basal"; + header("Location: /entreaulas/comedor.php?aulario=" . urlencode($aulario_id) . "&date=" . urlencode($date) . "&menu=" . urlencode($redirectMenuId)); + exit; + } + } + } + + if ($action === "rename_type") { + $renameId = trim($_POST["rename_type_id"] ?? ""); + $newLabel = trim($_POST["rename_type_label"] ?? ""); + $newColor = trim($_POST["rename_type_color"] ?? ""); + if ($renameId !== "" && $newLabel !== "") { + foreach ($menuTypes as &$t) { + if (($t["id"] ?? "") === $renameId) { + $t["label"] = $newLabel; + if ($newColor !== "") { + $t["color"] = $newColor; + } + break; + } + } + unset($t); + 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($renameId)); + exit; + } + } + if ($action === "save") { $menuTypeId = $_POST["menu_type"] ?? $menuTypeId; if (!isset($menuData["menus"][$menuTypeId])) { @@ -325,25 +366,89 @@ foreach ($userAulas as $aulaId) {
Administrar tipos de menú -
- -
-
- - + + +
+

Añadir nuevo tipo de menú

+ + +
+
+ + +
+
+ + +
+
+ + +
-
- - + + +
+ + +
+

Tipos de menú existentes

+ +
;"> +
+
+ +
+ ID: +
+ Color: ; border-radius: 3px; vertical-align: middle;"> +
+
+ + + + +
+ + "> + +
+
+
+ +
" style="display: none; margin-top: 15px; padding-top: 15px; border-top: 1px solid #ddd;"> +
+ + "> +
+
+ + " required> +
+
+ + "> +
+
+
+ + +
+
+
-
- - -
-
- - + +
+ +