# KADSB ICT Solutions Website

Modern, SEO-optimized, lead-generation website for KADSB ICT System Integrator.

## 🎯 Features

- **Modern SPA Architecture**: Single Page Application with smooth navigation
- **Black & Yellow Theme**: Technology-focused corporate design
- **SEO Optimized**: Meta tags, Schema markup, Sitemap
- **Lead Generation**: Contact forms, RFQ system, Careers module
- **M365 SMTP**: Microsoft 365 email integration
- **Security**: CSRF protection, XSS filtering, reCAPTCHA, Rate limiting
- **PostgreSQL**: Robust database with prepared statements
- **Mobile-First**: Fully responsive design

## 🧱 Tech Stack

### Backend
- PHP 8+
- PostgreSQL 12+
- PDO with prepared statements
- PHPMailer for email
- RESTful API architecture

### Frontend
- HTML5 / CSS3
- Vanilla JavaScript (SPA)
- Font Awesome icons
- Google Fonts (Inter)
- reCAPTCHA v2

## 📁 Project Structure

```
kadsb-website/
├── app/
│   ├── config/
│   │   ├── config.php          # Application configuration
│   │   └── database.php        # Database connection
│   ├── controllers/
│   │   ├── ApiController.php   # Base API controller
│   │   ├── ContactController.php
│   │   ├── RFQController.php
│   │   ├── CareerController.php
│   │   └── ServiceController.php
│   ├── models/
│   │   ├── Contact.php
│   │   ├── RFQ.php
│   │   ├── Career.php
│   │   ├── JobApplication.php
│   │   └── Service.php
│   ├── helpers/
│   │   ├── EmailHelper.php     # M365 SMTP integration
│   │   ├── SecurityHelper.php  # Security functions
│   │   └── ValidationHelper.php
│   └── views/
├── database/
│   ├── schema.sql              # Database schema
│   └── seed_services.sql       # Sample data
├── public/
│   ├── assets/
│   │   ├── css/
│   │   │   └── styles.css
│   │   ├── js/
│   │   │   ├── app.js          # Main SPA logic
│   │   │   ├── pages.js        # Page templates
│   │   │   └── forms.js        # Form handlers
│   │   └── images/
│   ├── uploads/
│   ├── api.php                 # API router
│   ├── index.html              # Main entry point
│   ├── .htaccess              # Apache config
│   ├── robots.txt
│   ├── sitemap.xml
│   ├── 404.html
│   └── 500.html
├── logs/
├── .env                        # Environment variables
├── .env.example               # Environment template
├── composer.json
└── README.md
```

## 🚀 Installation

### Prerequisites

- PHP 8.0 or higher
- PostgreSQL 12 or higher
- Composer
- Apache or Nginx
- SSL Certificate (for production)

### Step 1: Clone & Setup

```bash
# Navigate to your web directory
cd /var/www/html

# Copy project files
cp -r kadsb-website /var/www/html/kadsb

# Set permissions
cd /var/www/html/kadsb
chown -R www-data:www-data .
chmod -R 755 .
chmod -R 775 public/uploads
chmod -R 775 logs
```

### Step 2: Install Dependencies

```bash
# Install Composer dependencies
composer install --no-dev --optimize-autoloader
```

### Step 3: Configure Environment

```bash
# Copy environment file
cp .env.example .env

# Edit configuration
nano .env
```

Update these values in `.env`:

```ini
# Database
DB_HOST=localhost
DB_NAME=kadsb_website
DB_USER=kadsb_user
DB_PASS=your_secure_password

# Microsoft 365 SMTP
SMTP_USERNAME=noreply@kadsb.com.my
SMTP_PASSWORD=your_email_password

# Admin Emails
ADMIN_EMAIL=admin@kadsb.com.my
HR_EMAIL=hr@kadsb.com.my
SALES_EMAIL=sales@kadsb.com.my

# reCAPTCHA (get from https://www.google.com/recaptcha/)
RECAPTCHA_SITE_KEY=your_site_key
RECAPTCHA_SECRET_KEY=your_secret_key
```

### Step 4: Setup Database

```bash
# Login to PostgreSQL
sudo -u postgres psql

# Create database and user
CREATE DATABASE kadsb_website;
CREATE USER kadsb_user WITH ENCRYPTED PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE kadsb_website TO kadsb_user;

# Exit PostgreSQL
\q

# Import schema
psql -U kadsb_user -d kadsb_website -f database/schema.sql

# Import sample services data
psql -U kadsb_user -d kadsb_website -f database/seed_services.sql
```

### Step 5: Configure Web Server

#### Apache

Already configured via `.htaccess` in public directory.

Ensure mod_rewrite is enabled:
```bash
sudo a2enmod rewrite
sudo systemctl restart apache2
```

Configure virtual host:
```apache
<VirtualHost *:80>
    ServerName www.kadsb.com.my
    ServerAlias kadsb.com.my
    DocumentRoot /var/www/html/kadsb/public

    <Directory /var/www/html/kadsb/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/kadsb_error.log
    CustomLog ${APACHE_LOG_DIR}/kadsb_access.log combined
</VirtualHost>
```

#### Nginx

See `DEPLOYMENT.md` for Nginx configuration.

### Step 6: SSL Certificate (Production)

```bash
# Install Certbot
sudo apt install certbot python3-certbot-apache

# Get SSL certificate
sudo certbot --apache -d www.kadsb.com.my -d kadsb.com.my
```

## 🔐 Security Checklist

- [ ] Change default admin password in database
- [ ] Configure reCAPTCHA keys
- [ ] Set strong database password
- [ ] Configure M365 SMTP credentials
- [ ] Enable HTTPS with SSL certificate
- [ ] Set appropriate file permissions
- [ ] Configure firewall rules
- [ ] Enable rate limiting
- [ ] Review CORS settings
- [ ] Set secure session cookies

## 📧 Email Configuration

### Microsoft 365 SMTP Setup

1. Login to Microsoft 365 Admin Center
2. Create a shared mailbox or use existing account
3. Enable SMTP AUTH
4. Use these settings:
   - Host: smtp.office365.com
   - Port: 587
   - Encryption: TLS
   - Username: full email address
   - Password: account password or app password

### Email Types

- **Contact Form**: Auto-reply + Admin notification
- **RFQ Request**: Auto-reply + Sales notification
- **Job Application**: Auto-reply + HR notification with CV attachment

## 🎨 Customization

### Branding

1. Update logo in `public/assets/images/`
2. Modify colors in `public/assets/css/styles.css` (CSS variables)
3. Update company information in `.env`
4. Replace favicon and OG images

### Content

- Update services in database or via `database/seed_services.sql`
- Modify page content in `public/assets/js/pages.js`
- Update footer links in `public/index.html`

## 📊 Analytics

### Google Analytics Setup

1. Get tracking ID from Google Analytics
2. Update GA_TRACKING_ID in `.env`
3. Uncomment GA script in `public/index.html`

### Google Tag Manager

1. Get GTM container ID
2. Update GTM_ID in `.env`
3. Add GTM snippets to `public/index.html`

## 🔧 API Endpoints

### Public Endpoints

```
GET  /api.php?route=csrf                      # Get CSRF token
GET  /api.php?route=service&action=all        # Get all services
GET  /api.php?route=service&action=details&slug={slug}
GET  /api.php?route=career&action=jobs        # Get all jobs
GET  /api.php?route=career&action=details&id={id}

POST /api.php?route=contact&action=submit     # Submit contact form
POST /api.php?route=rfq&action=submit         # Submit RFQ
POST /api.php?route=career&action=apply       # Submit job application
```

## 🧪 Testing

### Test Contact Form
```bash
curl -X POST https://www.kadsb.com.my/api.php?route=contact&action=submit \
  -H "Content-Type: application/json" \
  -d '{"name":"Test User","email":"test@example.com","message":"Test message"}'
```

## 📈 Performance Optimization

- Gzip compression enabled
- Browser caching configured
- Image lazy loading
- Minified assets recommended for production
- CDN integration recommended

## 🐛 Troubleshooting

### Database Connection Issues
```bash
# Check PostgreSQL status
sudo systemctl status postgresql

# Check database connection
psql -U kadsb_user -d kadsb_website -h localhost
```

### Email Not Sending
- Check SMTP credentials in `.env`
- Verify port 587 is not blocked
- Check `logs/error.log` for details
- Test SMTP connection manually

### File Upload Issues
- Check `uploads/` directory permissions
- Verify `upload_max_filesize` in `php.ini`
- Check `MAX_FILE_SIZE` in `.env`

## 📞 Support

For technical support, contact: dev@kadsb.com.my

## 📝 License

Proprietary - KADSB ICT Solutions Sdn Bhd

## 👨‍💻 Development

```bash
# Enable debug mode
APP_DEBUG=true in .env

# View logs
tail -f logs/error.log

# Database migrations
psql -U kadsb_user -d kadsb_website -f database/migration_name.sql
```

---

**Built with ❤️ for KADSB ICT Solutions**
