# Study Reminder Scheduler - Cron Job Setup Instructions
# For automatic email notifications at scheduled times

# ==================================================
# OPTION 1: Traditional Cron Job (Linux/Unix/macOS)
# ==================================================

# Add this line to your crontab to run every 5 minutes:
# Run: crontab -e
# Add this line:
*/5 * * * * /usr/bin/php /path/to/your/project/config/study_reminder_scheduler.php >/dev/null 2>&1

# Or with logging:
*/5 * * * * /usr/bin/php /path/to/your/project/config/study_reminder_scheduler.php >> /var/log/study_reminders.log 2>&1

# ==================================================
# OPTION 2: Windows Scheduled Task
# ==================================================

# 1. Open Task Scheduler
# 2. Create Basic Task
# 3. Name: "Study Reminder Scheduler"
# 4. Trigger: Daily, repeat every 5 minutes
# 5. Action: Start Program
#    Program: C:\path\to\php.exe
#    Arguments: C:\path\to\your\project\config\study_reminder_scheduler.php

# ==================================================
# OPTION 3: Web-based Scheduler (Alternative)
# ==================================================

# Call via web request every 5 minutes:
# https://yourdomain.com/config/study_reminder_scheduler.php?scheduler_key=panadite_scheduler_2024

# ==================================================
# OPTION 4: AJAX Auto-scheduler (Built into Admin Panel)
# ==================================================

# Add this JavaScript to your admin dashboard to auto-run:
/*
setInterval(function() {
    fetch('/config/study_reminder_scheduler.php', {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({ajax_scheduler: 'true'})
    })
    .then(response => response.json())
    .then(data => {
        if (data.processed > 0) {
            console.log('📧 Study reminders processed:', data.processed);
        }
    })
    .catch(error => console.error('Scheduler error:', error));
}, 5 * 60 * 1000); // Run every 5 minutes
*/

# ==================================================
# TESTING THE SCHEDULER
# ==================================================

# Test manually by visiting:
# http://localhost/config/study_reminder_scheduler.php?scheduler_key=panadite_scheduler_2024

# Or run from command line:
# php /path/to/config/study_reminder_scheduler.php

# ==================================================
# MONITORING & LOGS
# ==================================================

# Check system error log for scheduler activity:
# tail -f /var/log/apache2/error.log (Linux)
# Check Windows Event Viewer (Windows)

# Check email queue processing:
# http://localhost/config/process_emails.php?process_key=panadite_email_2024

# Database logs in reminder_logs table:
# SELECT * FROM reminder_logs ORDER BY logged_at DESC LIMIT 20;

# ==================================================
# SECURITY NOTES
# ==================================================

# 1. Change security keys in production:
#    - panadite_scheduler_2024 (in study_reminder_scheduler.php)
#    - panadite_email_2024 (in process_emails.php)

# 2. Restrict file permissions:
#    chmod 755 study_reminder_scheduler.php
#    chmod 755 process_emails.php

# 3. Monitor logs regularly for failed attempts

# ==================================================
# TROUBLESHOOTING
# ==================================================

# If reminders aren't sending:
# 1. Check SMTP settings in system_settings table
# 2. Verify database connection in db_connect.php  
# 3. Test email service: fast_email_service.php
# 4. Check reminder_logs table for errors
# 5. Verify cron job is running: check system logs
