# Scorecard PDF Generator

This PHP script generates professional golf scorecards in PDF format, optimized for A4 printing on Brother printers.

## Features

- **3 scorecards per A4 page**: Each page contains exactly 3 equally sized scorecards
- **Brother printer optimized**: Layout designed specifically for Brother printer compatibility
- **Dynamic content**: Automatically populates based on event data
- **Flexible player count**: Supports 1-4 players per flight
- **Dual event support**: Works with both regular events and Roll Up events

## File Structure

- `scorecard-pdf.php` - Main PDF generator script
- `test-scorecard-pdf.php` - Simple web interface for testing
- `fpdf185/` - FPDF library (required for PDF generation)

## Usage

### Method 1: Direct URL
```
http://yoursite.com/EP/scorecard-pdf.php?EventId=123
```

### Method 2: Web Interface
1. Navigate to `test-scorecard-pdf.php`
2. Enter the Event ID
3. Click "Generate PDF Scorecards"

### Method 3: Programmatic
```php
include "event-session-check.php";
$pdf = new ScorecardPDF($eventId, $conn);
$pdf->generateScorecards();
$pdf->Output('scorecards.pdf', 'I');
```

## Scorecard Layout

Each scorecard contains:

### Table 1: Header (2 columns, 4 lines)
- Left column: Competition descriptions
- Right column: Flight info, tee, time, and signature lines

### Table 2: Scorecard Grid
- **Line 1**: Hole numbers (1-18)
- **Lines 2-5**: Teebox data (1-4 lines based on criteria)
  - Shows teebox distances for each hole
  - If criteria shows 1 line, other 3 lines are blank
- **Line 6**: Par values (fixed)
- **Line 7**: Index/Slope values (fixed)
- **Lines 8-11**: Player rows (fixed position and size)
  - Populated by Event users in that event and flight
  - Shows player name, slope shots, and player info
- **Line 12**: Marcador (fixed)

## Database Requirements

The script requires these database tables:
- `el_paraiso.Events` - Event information
- `el_paraiso.EventUsers` - Player assignments
- `EventUsersExtra` - Additional player data (for regular events)
- `InviteEventGroupsText` - Competition descriptions
- `epholes` - Course data (par, index, teebox distances)
- `slopeshots` - Slope rating shot allocations
- `Users` - Player information (for Roll Up events)

## Technical Details

### Page Layout
- **Page size**: A4 (210mm × 297mm)
- **Orientation**: Portrait
- **Margins**: 5mm on all sides
- **Card dimensions**: 200mm × 90mm per card
- **Card spacing**: 95mm vertical spacing between cards

### Font Sizes
- Header text: 8pt
- Table headers: 6pt bold
- Table data: 6pt regular
- Player names: 6pt regular

### Color Scheme
- Black text on white background
- Gray borders for tables
- No background colors (printer-friendly)

## Error Handling

The script includes error handling for:
- Missing Event ID parameter
- Event not found in database
- Missing database connection
- Missing FPDF library

## Browser Compatibility

The PDF output is compatible with:
- All modern browsers
- PDF viewers (Adobe Reader, etc.)
- Brother printer drivers

## Troubleshooting

### Common Issues

1. **PDF doesn't generate**
   - Check that EventId parameter is provided
   - Verify database connection
   - Ensure FPDF library is installed

2. **Layout issues**
   - Check printer settings (A4, portrait)
   - Verify Brother printer driver is up to date
   - Test with different browsers

3. **Missing data**
   - Verify event exists in database
   - Check that players are assigned to flights
   - Ensure course data is populated

### Debug Mode

To enable debug mode, add this before creating the PDF object:
```php
error_reporting(E_ALL);
ini_set('display_errors', 1);
```

## Customization

### Modifying Layout
Edit the `generateSingleScorecard()` method in `scorecard-pdf.php` to adjust:
- Card dimensions
- Font sizes
- Spacing
- Colors

### Adding Fields
To add new fields to the scorecard:
1. Modify the database queries
2. Update the table generation code
3. Adjust spacing calculations

## Support

For issues or questions:
1. Check the error logs
2. Verify database connectivity
3. Test with a known working Event ID
4. Ensure all required tables exist and have data 