# Job Application Platform - Setup Guide

## 🚀 Quick Start Guide

Follow these steps to set up and run the job application platform on your XAMPP server.

---

## 📋 Prerequisites

- XAMPP (with Apache and MySQL running)
- PHP 8.0 or higher
- MySQL 5.7+ or MariaDB 10.3+
- Web browser (Chrome, Firefox, Edge, etc.)

---

## 🔧 Installation Steps

### Step 1: Database Setup

1. Start XAMPP Control Panel
2. Start **Apache** and **MySQL** services
3. Open phpMyAdmin: http://localhost/phpmyadmin
4. Click **Import** tab
5. Choose file: `c:\xampp\htdocs\job-application\database.sql`
6. Click **Go** to import

This will create:
- Database: `job_application_db`
- Tables: users, admins, jobs, applications, education, employment_history, references
- Default admin account

### Step 2: Configure Database Connection

Open: `config/database.php`

Verify these settings match your XAMPP configuration:
```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'job_application_db');
define('DB_USER', 'root');
define('DB_PASS', '');
```

### Step 3: Configure Site Settings

Open: `config/constants.php`

Update the following:

```php
// Site URL - Change if needed
define('SITE_URL', 'http://localhost/job-application');

// SMTP Email Configuration (for sending emails)
define('SMTP_HOST', 'smtp.gmail.com');
define('SMTP_PORT', 587);
define('SMTP_USERNAME', 'your-email@gmail.com');  // ← CHANGE THIS
define('SMTP_PASSWORD', 'your-app-password');     // ← CHANGE THIS
define('FROM_EMAIL', 'noreply@jobapplication.com');
define('ADMIN_EMAIL', 'admin@jobapplication.com');
```

**For Gmail SMTP:**
1. Enable 2-Step Verification on your Google account
2. Generate an App Password: https://myaccount.google.com/apppasswords
3. Use the App Password (not your regular password)

### Step 4: Download PHPMailer

The email system requires PHPMailer. Download it:

**Option A: Using Composer (Recommended)**
```bash
cd c:\xampp\htdocs\job-application
composer require phpmailer/phpmailer
```

**Option B: Manual Download**
1. Download from: https://github.com/PHPMailer/PHPMailer
2. Extract to: `c:\xampp\htdocs\job-application\vendor\phpmailer\`
3. Ensure these files exist:
   - `vendor/phpmailer/Exception.php`
   - `vendor/phpmailer/PHPMailer.php`
   - `vendor/phpmailer/SMTP.php`

### Step 5: Download TinyMCE (Optional but Recommended)

For the rich text editor in admin job creation:

1. Download TinyMCE: https://www.tiny.cloud/get-tiny/self-hosted/
2. Extract to: `c:\xampp\htdocs\job-application\assets\tinymce\`
3. Ensure `tinymce.min.js` exists in that folder

**Alternative:** The system will work without TinyMCE using regular textareas.

### Step 6: Set File Permissions (Windows)

Ensure these folders are writable:
- `uploads/` (if you add file uploads later)
- `vendor/`

No special permissions needed on Windows with XAMPP.

---

## 🔐 Default Login Credentials

### Admin Access
- **URL:** http://localhost/job-application/admin/login.php
- **Email:** admin@jobapplication.com
- **Password:** password

**⚠️ IMPORTANT:** Change this password immediately after first login!

### Applicant Access
- **URL:** http://localhost/job-application/public/login.php
- Create a new account via: http://localhost/job-application/public/register.php

---

## 🌐 Access the Application

### Public Pages (Applicants)
- **Homepage/Jobs:** http://localhost/job-application/public/index.php
- **Register:** http://localhost/job-application/public/register.php
- **Login:** http://localhost/job-application/public/login.php

### Admin Portal
- **Admin Login:** http://localhost/job-application/admin/login.php
- **Dashboard:** http://localhost/job-application/admin/index.php

---

## 📁 Project Structure

```
job-application/
├── config/                 # Configuration files
│   ├── database.php       # Database connection
│   ├── constants.php      # Site constants & settings
│   └── functions.php      # Helper functions
├── includes/              # Reusable HTML components
│   ├── header.php         # Public header
│   ├── footer.php         # Public footer
│   ├── admin-header.php   # Admin header
│   └── admin-footer.php   # Admin footer
├── assets/                # Frontend assets
│   ├── css/style.css      # Custom styles
│   └── js/main.js         # JavaScript functionality
├── public/                # Public-facing pages
│   ├── index.php          # Job listings homepage
│   ├── job-details.php    # Job detail page
│   ├── login.php          # Applicant login
│   ├── register.php       # Applicant registration
│   ├── verify-email.php   # Email verification
│   ├── forgot-password.php
│   ├── reset-password.php
│   ├── application-form.php  # (To be created)
│   ├── application-success.php
│   └── logout.php
├── admin/                 # Admin backend
│   ├── login.php          # Admin login
│   ├── index.php          # Dashboard
│   ├── jobs.php           # Job management
│   ├── job-create.php     # Create job
│   ├── job-edit.php       # Edit job
│   ├── job-delete.php     # Delete job
│   ├── applications.php   # View applications
│   ├── application-view.php
│   └── logout.php
├── ajax/                  # AJAX handlers
├── emails/                # Email templates
├── vendor/                # Third-party libraries (PHPMailer)
├── uploads/               # File uploads
├── .htaccess              # Security configuration
├── database.sql           # Database schema
└── SETUP.md               # This file
```

---

## ✅ Features Implemented

### Public Features
✅ Job listing page with search & filters  
✅ Job details page with full information  
✅ Applicant registration with email verification  
✅ Secure login system  
✅ Password reset functionality  
✅ Responsive, mobile-friendly design  

### Admin Features
✅ Secure admin login  
✅ Dashboard with statistics  
✅ Create, edit, delete jobs  
✅ TinyMCE rich text editor for job descriptions  
✅ View and manage applications (structure ready)  
✅ Filter and search capabilities  

### Security Features
✅ Password hashing (bcrypt)  
✅ CSRF token protection  
✅ SQL injection prevention (prepared statements)  
✅ XSS prevention (input sanitization & output escaping)  
✅ Session security (regeneration, timeout)  
✅ Brute force protection  
✅ Secure .htaccess configuration  

---

## 🔧 Configuration Tips

### Enable Error Logging (Production)

In `config/constants.php`, change:
```php
error_reporting(0);
ini_set('display_errors', 0);
```

### Email Testing

For local testing without SMTP, you can use tools like:
- **Mailtrap:** https://mailtrap.io/ (free for testing)
- **Papercut:** Local mail catcher

### Session Timeout

Adjust session timeout in `config/constants.php`:
```php
ini_set('session.gc_maxlifetime', 1800); // 30 minutes
```

---

## 🐛 Troubleshooting

### Database Connection Failed
- Ensure MySQL is running in XAMPP
- Check database credentials in `config/database.php`
- Verify database `job_application_db` exists

### Emails Not Sending
- Verify SMTP credentials in `config/constants.php`
- Check if PHPMailer is downloaded to `vendor/` folder
- Check error logs for SMTP errors

### Page Not Found (404)
- Ensure Apache is running
- Check SITE_URL in `config/constants.php`
- Verify files are in correct locations

### Admin Login Not Working
- Ensure database was imported successfully
- Check that admin record exists in `admins` table
- Default password is: `password`

### Session Issues
- Clear browser cookies
- Ensure `session_start()` is being called
- Check PHP session configuration

---

## 📝 Next Steps (Remaining Features)

The following features still need to be implemented:

1. **Application Form** (public/application-form.php)
   - Multi-section form with conditional fields
   - Personal information, right to work
   - Education & employment history (dynamic rows)
   - Supporting information & references
   - Draft auto-save functionality

2. **Admin Application Management**
   - View all applications
   - Filter by job and status
   - Update application status
   - View full application details

3. **Email Templates**
   - Application confirmation email
   - Admin notification for new applications

4. **AJAX Draft Save/Load**
   - Auto-save application drafts
   - Load saved drafts

---

## 🛡️ Security Best Practices

### For Production Deployment

1. **Change all default passwords**
2. **Enable HTTPS**
3. **Update SITE_URL** to your domain
4. **Disable error display**
5. **Set strong SMTP credentials**
6. **Regular database backups**
7. **Keep PHP and MySQL updated**
8. **Monitor error logs**
9. **Implement rate limiting on forms**
10. **Use strong password policies**

---

## 📞 Support

If you encounter issues:
1. Check this guide first
2. Review error logs in `c:\xampp\apache\logs\error.log`
3. Check PHP error logs
4. Verify all prerequisites are met
5. Ensure database is properly imported

---

## 🎉 You're All Set!

Once you've completed the setup:

1. Import the database
2. Configure SMTP (optional but recommended)
3. Login to admin panel
4. Create your first job listing
5. Test the applicant registration flow
6. Start accepting applications!

**Happy Recruiting!** 🚀
