# Testing the File Transfer Page

## Prerequisites Checklist

- [x] Domain-wide delegation authorized in Google Workspace Admin
- [x] Google Drive API enabled in Google Cloud Console
- [x] Credentials file in place: `/var/www/html/wordpress6/secure/google-drive-credentials.json`
- [x] Google API client installed: `composer require google/apiclient`
- [x] Folder ID stored in database for the volunteer role

## Step-by-Step Testing

### Step 1: Log in as a Volunteer
1. Log in to the system as user **8022** (secretary) or **199** (greens)
2. You should see the "My Volunteer Email" button in the dashboard

### Step 2: Access File Transfer Page
1. Click on **"My Volunteer Email"** dropdown
2. Click on **"File Transfer (Upload to Roles/Secretary)"** or **"File Transfer (Upload to Roles/Greens)"**
3. Or go directly to: `https://elparaisoeventreg.scala4.com/event-drive-file-transfer.php`

### Step 3: Verify Setup Status
On the file transfer page, you should see:
- ✅ **"API Configured"** message (green alert) - means credentials found
- ✅ **"Target folder ID configured"** - means folder ID is in database
- If you see warnings, check the setup

### Step 4: Create Upload Folder in Google Drive
1. Open your personal Google Drive:
   - For secretary: `secretary@elparaisogolf.com`
   - For greens: `greens@elparaisogolf.com`
2. Create a folder named exactly **"Upload"** (case-sensitive)
3. Upload a test file to this folder (any file will work - PDF, image, document, etc.)

### Step 5: Refresh File Transfer Page
1. Go back to the file transfer page
2. Refresh the page (F5 or Ctrl+R)
3. Your uploaded file should appear in the "Files Ready to Transfer" section

### Step 6: Transfer a File
1. Click the **"📤 Transfer"** button next to a file
2. Confirm the transfer when prompted
3. You should see a success message: "✓ File '[filename]' successfully transferred to Roles/[Role] folder!"

### Step 7: Verify Transfer
1. Open the target folder in Business Google Drive:
   - Go to: `Roles/Secretary` or `Roles/Greens`
   - Or use the "Open Target Folder" button on the page
2. Verify the file appears in the target folder

## Expected Behavior

### If Everything Works:
- Files from your Upload folder appear in the list
- Transfer button works
- Success message appears
- File appears in target folder

### If There Are Issues:

**"API Not Configured" warning:**
- Check credentials file exists and is readable
- Verify path in code matches actual file location
- Check file permissions (should be 600)

**"Upload Folder Not Found":**
- Make sure folder is named exactly "Upload" (case-sensitive)
- Folder must be in your personal drive, not shared drive
- Refresh the page after creating the folder

**"Error transferring file" messages:**
- Check error message for details
- Verify domain-wide delegation is authorized
- Check that service account has access to both folders
- Verify target folder ID is correct in database

**No files appear:**
- Make sure files are in the "Upload" folder
- Check that files aren't in trash
- Verify you're logged in as the correct volunteer user

## Troubleshooting

### Check PHP Error Log
```bash
tail -f /var/log/php/error.log
# Or check Apache error log
tail -f /var/log/apache2/error.log
```

### Test API Connection
Create a test file to verify API works:
```php
<?php
require 'vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('/var/www/html/wordpress6/secure/google-drive-credentials.json');
$client->addScope(Google_Service_Drive::DRIVE);
$client->setSubject('secretary@elparaisogolf.com');
$service = new Google_Service_Drive($client);
$files = $service->files->listFiles(['pageSize' => 1]);
echo "API connection successful!";
?>
```

### Common Issues

**"Insufficient authentication scopes":**
- Domain-wide delegation not fully authorized
- Wrong OAuth scope in Google Workspace Admin
- Should be: `https://www.googleapis.com/auth/drive`

**"Insufficient permissions":**
- Service account needs access to folders
- Share Upload folder with service account email
- Share target Roles folder with service account email

**"File not found":**
- Upload folder doesn't exist or has wrong name
- File was deleted or moved
- Check folder name is exactly "Upload"

## Next Steps After Testing

Once testing is successful:
1. Train volunteers on how to use the system
2. Document the workflow
3. Monitor for any errors
4. Consider adding more features (bulk transfer, file preview, etc.)

