$aulario_data) {
$aulario_name = $aulario_data['name'] ?? $aulario_id;
$alumnos_path = "$aularios_dir/$aulario_id/Alumnos";
if (!is_dir($alumnos_path)) {
continue;
}
foreach (glob("$alumnos_path/*/", GLOB_ONLYDIR) ?: [] as $alumno_dir) {
$alumno_name = basename($alumno_dir);
$key = $aulario_id . ':' . $alumno_name;
$personas[$key] = [
'Nombre' => $alumno_name,
'Region' => $aulario_name,
'AularioID' => $aulario_id,
'HasPhoto' => file_exists("$alumno_dir/photo.jpg"),
];
}
}
return $personas;
}
/**
* Return a human-readable label for a persona key.
* Falls back to showing the raw stored value for legacy orders.
*/
function sc_persona_label($persona_key, $personas)
{
if (isset($personas[$persona_key])) {
$p = $personas[$persona_key];
return $p['Nombre'] . ' (' . $p['Region'] . ')';
}
return $persona_key;
}
$tenant_data = $_SESSION['auth_data']['aulatek'] ?? ($_SESSION['auth_data']['entreaulas'] ?? []);
$centro_id = safe_organization_id($tenant_data['organizacion'] ?? ($tenant_data['centro'] ?? ''));
if ($centro_id === '') {
require_once "_incl/pre-body.php";
echo '
SuperCafe
No tienes una organizacion asignada.
';
require_once "_incl/post-body.php";
exit;
}
define('SC_MAX_DEBTS', 3);
$estados_colores = [
'Pedido' => '#FFFFFF',
'En preparación' => '#FFCCCB',
'Listo' => 'gold',
'Entregado' => 'lightgreen',
'Deuda' => '#f5d3ff',
];
$can_edit = in_array('supercafe:edit', $_SESSION['auth_data']['permissions'] ?? []);
$personas = sc_load_personas_from_alumnos($centro_id);
// Handle POST actions (requires edit permission)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $can_edit) {
$action = $_POST['action'] ?? '';
if ($action === 'change_status') {
$order_id = safe_id($_POST['order_id'] ?? '');
$new_status = $_POST['status'] ?? '';
if ($order_id !== '' && array_key_exists($new_status, $estados_colores)) {
$row = db_get_supercafe_order($centro_id, $order_id);
if ($row) {
db_upsert_supercafe_order(
$centro_id, $order_id,
$row['fecha'], $row['persona'], $row['comanda'], $row['notas'], $new_status
);
}
}
header('Location: /aulatek/supercafe.php');
exit;
}
if ($action === 'delete') {
$order_id = safe_id($_POST['order_id'] ?? '');
if ($order_id !== '') {
db()->prepare('DELETE FROM supercafe_orders WHERE org_id = ? AND order_ref = ?')
->execute([$centro_id, $order_id]);
}
header('Location: /aulatek/supercafe.php');
exit;
}
}
// Load all orders from DB
$db_orders = db_get_supercafe_orders($centro_id);
$orders = [];
foreach ($db_orders as $row) {
$orders[] = [
'_id' => $row['order_ref'],
'Fecha' => $row['fecha'],
'Persona'=> $row['persona'],
'Comanda'=> $row['comanda'],
'Notas' => $row['notas'],
'Estado' => $row['estado'],
];
}
// Sort newest first (by Fecha desc)
usort($orders, fn($a, $b) => strcmp($b['Fecha'] ?? '', $a['Fecha'] ?? ''));
$orders_active = array_filter($orders, fn($o) => ($o['Estado'] ?? '') !== 'Deuda');
$orders_deuda = array_filter($orders, fn($o) => ($o['Estado'] ?? '') === 'Deuda');
require_once "_incl/pre-body.php";
?>
Todas las comandas (= count($orders_active) ?>)
No hay comandas activas.
| Fecha |
Persona |
Comanda |
Notas |
Estado |
Acciones |
| = htmlspecialchars($order['Fecha'] ?? '') ?> |
= htmlspecialchars(sc_persona_label($order['Persona'] ?? '', $personas)) ?> |
= htmlspecialchars($order['Comanda'] ?? '') ?> |
= htmlspecialchars($order['Notas'] ?? '') ?> |
= htmlspecialchars($estado) ?> |
Editar
|
Deudas (= count($orders_deuda) ?>)
No hay comandas en deuda.
| Fecha |
Persona |
Comanda |
Notas |
Acciones |
| = htmlspecialchars($order['Fecha'] ?? '') ?> |
= htmlspecialchars(sc_persona_label($order['Persona'] ?? '', $personas)) ?> |
= htmlspecialchars($order['Comanda'] ?? '') ?> |
= htmlspecialchars($order['Notas'] ?? '') ?> |
Editar
|