Plan:
1.  **Fix 500 Error:** I identified and fixed a critical syntax error in `includes/actions.php` (a missing quote in the SQL query) that was crashing the application.
2.  **Restore Token Logic:** I carefully re-implemented the token generation code in `includes/actions.php` to ensure it works correctly without breaking the visit recording process.
3.  **Add Missing UI:** I added the **"Issue Token"** checkbox to the "Details" tab of the "Add Visit" modal in `includes/layout/footer.php`, which was missing from the previous attempt.
4.  **Verify Integrity:** I confirmed that the `patient_queue` database table exists and that all new files (`queue.php`, `api/queue.php`, `queue_display.php`) have valid syntax.

Changed:
*   `includes/actions.php`: Fixed a syntax error and correctly implemented the token generation logic.
*   `includes/layout/footer.php`: Added the "Issue Token" checkbox to the "Details" tab of the `recordVisitModal`.

Notes:
*   The application should now load correctly without the 500 error.
*   To use the token system:
    1.  **Receptionist:** When adding a new visit, check the **"Issue Token"** box in the "Details" tab.
    2.  **Queue Management:** Go to **"Queue Management"** in the sidebar to manage the queue (Call, Finish).
    3.  **Display:** Click **"Open TV Display"** to open the public waiting list on a separate screen.
*   Reminder: click Save in the editor to sync changes.

Next: Please refresh your browser and try adding a visit with the "Issue Token" checkbox checked. Let me know if everything works as expected!