Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JAQA20/LaComanda/llms.txt

Use this file to discover all available pages before exploring further.

The Sessions API gives administrators a live view of who is currently logged in to La Comanda. Rather than querying MySQL, the system persists session state to flat JSON files managed by the session controller. This approach keeps session tracking lightweight and avoids adding database load during high-activity service periods. Sessions that have been inactive for more than 30 minutes are automatically pruned the next time the active-sessions list is read.

Get Connected Users

GET /public/api/usuariosConectados.php Returns an array of session objects representing every user who has been active within the last 30 minutes. Only accessible to accounts with rol_id = 1 (Admin).

Response Fields

usuario_id
integer
The user’s database ID, matching the id column in the usuarios table.
nombre
string
The user’s full name (first and last name concatenated).
email
string
The user’s registered email address.
rol
string
Human-readable role name: Admin, Mesero, Cocina, or Barista.
login_at
string
Timestamp of the user’s most recent login, formatted as DD/MM/YYYY HH:MM AM/PM.
ultima_actividad
string
Timestamp of the user’s most recent page request, used to compute the activity status label.
dispositivo
string
Detected device category and browser string, e.g. "Desktop / Chrome" or "Mobile / Safari".
pagina_actual
string
Full URL of the last page the user navigated to, updated on every authenticated request.
ip
string
IP address from which the user’s session originated.
logout_at
string
Timestamp of the user’s last explicit logout, or the string "Sin logout registrado" if the user has never clicked the logout button.
estado_label
string
Human-readable activity label based on time since ultima_actividad. See Activity Status Thresholds.
estado_class
string
Bootstrap CSS utility classes applied to the status badge in the admin dashboard (e.g. "badge bg-success", "badge bg-warning text-dark").

Example Response

[
  {
    "usuario_id": 3,
    "nombre": "Carlos Mendoza",
    "email": "carlos@example.com",
    "rol": "Mesero",
    "login_at": "15/06/2025 08:30 AM",
    "ultima_actividad": "15/06/2025 08:47 AM",
    "dispositivo": "Desktop / Chrome",
    "pagina_actual": "http://localhost:8080/views/mesero/nueva_orden.php",
    "ip": "192.168.1.42",
    "logout_at": "Sin logout registrado",
    "estado_label": "Activo ahora",
    "estado_class": "badge bg-success"
  }
]

Example Request

curl -b 'PHPSESSID=...' \
  'http://localhost:8080/public/api/usuariosConectados.php'

Activity Status Thresholds

The estado_label and estado_class fields are computed at read time by comparing ultima_actividad against the current server clock.
LabelConditionBootstrap Class
Activo ahoraLast activity ≤ 120 seconds agobadge bg-success
Inactivo recienteLast activity 121 – 600 seconds agobadge bg-warning text-dark
InactivoLast activity > 600 seconds agobadge bg-secondary
Sessions with last activity older than 1 800 seconds (30 minutes) are not returned by this endpoint at all — they are pruned from the active-sessions store before the response is built.

Session Storage

Sessions are persisted to JSON files on the server filesystem, not in MySQL. This keeps the database schema simple and avoids locking issues during simultaneous order activity.
FilePurpose
controller/sesiones_activas.jsonCanonical store of currently active sessions. Keyed by PHP session ID.
controller/sesiones_historial.jsonAppend-only log of all historical sessions including logged-out and pruned entries.
Pruning behaviour: Each time listarActivas() is called (which happens on every request to usuariosConectados.php), any entry whose ultima_actividad is more than 1 800 seconds in the past is removed from sesiones_activas.json and written to sesiones_historial.json.
If the web server process does not have write permission to the controller/ directory, session tracking will silently fail. Verify that the directory is writable by the PHP user after deployment.
sesiones_historial.json can grow large on busy systems. Consider adding a scheduled task (cron) to archive or truncate entries older than your retention window.

Build docs developers (and LLMs) love