# Publication Status Feature

## Overview
This feature allows admins to control what participants see when viewing an event's participant list. It prevents participants from seeing the draw while it's being finalized.

## Database Changes
A new column `publicationStatus` has been added to the `Events` table:
- Type: `ENUM('Enrolled', 'Published')`
- Default: `'Enrolled'`

To add this column, run:
```bash
php add_publication_status_field.php
```

## Two View Modes

### 1. Enrolled (Default)
- **Who sees it**: All non-admin users
- **What they see**: 
  - All participants in the event
  - Sorted alphabetically by name
  - Flight and Tee columns show `0`
  - All other fields (handicap, slope, federation, etc.) are visible
- **Purpose**: Show enrollment list without revealing flight/tee assignments

### 2. Published
- **Who sees it**: Non-admin users (only their own entries)
- **What they see**:
  - Only their own participants (where UserId matches their session)
  - Sorted by flight and tee order
  - Actual flight and tee numbers displayed
  - All fields visible
- **Purpose**: Show finalized draw with actual flight/tee assignments

### Admin View
- **Always**: Admins see the full participant list regardless of publication status
- **Full access**: All participants, all fields, normal flight/tee order
- **Can toggle**: Admins can switch between Enrolled/Published status using the toggle button

## Implementation Details

### Files Modified

1. **event-member-form.php**
   - Added publication status toggle button in admin section
   - Button shows current status (Enrolled = yellow, Published = green)
   - JavaScript function to toggle status via AJAX

2. **event-table.php**
   - Reads publication status from Events table
   - Applies different query logic based on status and user role
   - Enrolled view: alphabetical sorting, flight/tee=0 display
   - Published view: flight/tee sorting, filtered to user's own participants

3. **event-publication-status-update.php**
   - New handler script to update publication status
   - Admin-only access
   - Returns JSON response for AJAX calls

4. **add_publication_status_field.php**
   - Migration script to add the database column
   - Safe to run multiple times (checks if column exists)

## Usage

1. **Admin creates event and populates participants**
2. **Admin uses Autogroup** to create preliminary flights
3. **While working on the draw** (1-3 days):
   - Status remains "Enrolled" (default)
   - Participants see alphabetical list with flight/tee=0
4. **When draw is finalized**:
   - Admin clicks the publication status button to switch to "Published"
   - Participants now see their own entries with actual flight/tee numbers

## Admin Controls

The publication status toggle button appears in the admin section alongside other admin buttons (Add, Refresh, Email, Print, etc.).

- **Yellow button** = Enrolled status
- **Green button** = Published status
- Click to toggle between states
- Page automatically refreshes after status change

## Technical Notes

- The publication status is stored per event in the `Events` table
- Default status for new events is "Enrolled"
- Admins always see the full view regardless of status
- Non-admin users are filtered by their UserId in Published view
- Flight and tee values are only displayed as 0 in Enrolled view (actual database values are not modified)

