# GlowSpace - Premium eCommerce Platform

A modern, professional, and scalable eCommerce solution built with PHP and MySQL/MariaDB. GlowSpace provides a complete shopping experience with user authentication, order management, and admin panel features.

## Features

### For Customers
- **User Authentication**: Secure registration, login, password reset
- **User Dashboard**: Order history, statistics, quick actions
- **User Profile**: Profile picture, cover banner, address management
- **Cart System**: Persistent cart with user synchronization
- **Wishlist**: Save favorite products for later
- **Order Tracking**: Real-time order status updates
- **Responsive Design**: Works seamlessly on all devices
- **Premium UI**: Modern, attractive interface with smooth animations

### For Administrators
- **Product Management**: Add, edit, delete products with images
- **Category Management**: Organize products by categories
- **Order Management**: View and update order statuses
- **Banner Management**: Manage promotional banners
- **Coupon System**: Create discount codes
- **Review Management**: Approve or delete customer reviews
- **Settings**: Customize site colors, currency, social links
- **Steadfast Integration**: Automatic courier tracking

### Technical Features
- **MySQL/MariaDB Database**: Scalable and efficient data storage
- **PDO with Prepared Statements**: SQL injection prevention
- **CSRF Protection**: Secure form submissions
- **Password Hashing**: Bcrypt with cost factor 10
- **Session Management**: Secure user sessions
- **HTML Entity Decoding**: Proper text encoding
- **Image Processing**: Automatic image optimization
- **Activity Logging**: Track all admin actions

## Requirements

- **PHP 7.4+** with extensions:
  - PDO MySQL
  - GD (optional, for image processing)
  - JSON
  - mbstring
  - curl
- **MySQL/MariaDB 5.7+**
- **Web Server**: Apache, Nginx, or any PHP-compatible server
- **File Permissions**: Write access to `/uploads` and `/data` folders

## Installation

### 1. Clone or Download

Download the GlowSpace files to your web server directory.

### 2. Configure Database

Edit `config.php` and update your database credentials:

```php
// Database Configuration
define('DB_HOST', 'localhost');        // Your database host
define('DB_NAME', 'glowspace');        // Your database name
define('DB_USER', 'root');             // Your database username
define('DB_PASS', '');                 // Your database password
```

### 3. Create Database Schema

**Option 1: Using phpMyAdmin**
1. Open phpMyAdmin
2. Create a new database named `glowspace`
3. Import the `database/schema.sql` file

**Option 2: Using Command Line**
```bash
mysql -u root -p < database/schema.sql
```

### 4. Run Migration (If Upgrading from JSON)

If you're upgrading from the JSON-based version:

```bash
php database/migrate.php
```

This will:
- Backup all JSON files
- Migrate data to MySQL
- Verify data integrity
- Generate migration log

### 5. Configure Courier API

Update Steadfast courier credentials in `config.php`:

```php
// Steadfast Courier API
define('STEADFAST_API_URL', 'https://portal.packzy.com/api/v1/create_order');
define('STEADFAST_API_KEY', 'your_api_key');
define('STEADFAST_SECRET_KEY', 'your_secret_key');
```

### 6. Set File Permissions

Ensure the web server can write to these directories:

```bash
chmod 755 uploads
chmod 755 data
```

## Directory Structure

```
glowspace/
├── config.php              # Configuration file
├── index.php               # Main storefront
├── landing.php             # Product landing pages
├── admin.php               # Admin panel
├── login.php               # User login
├── register.php            # User registration
├── profile.php             # User profile
├── dashboard.php           # User dashboard
├── database/
│   ├── schema.sql          # Database schema
│   └── migrate.php         # Migration script
├── includes/
│   ├── db.php              # Database helper functions
│   └── auth.php            # Authentication system
├── data/                   # Data storage (JSON backup)
├── uploads/                # Product images
│   ├── products/
│   ├── banners/
│   └── settings/
├── MIGRATION_GUIDE.md      # Migration instructions
└── README.md               # This file
```

## Default Credentials

### Admin Panel
- **Username**: admin
- **Password**: password
- **URL**: `/admin.php`

### Database
- **Host**: localhost
- **Database**: glowspace
- **User**: root
- **Password**: (empty by default)

⚠️ **Important**: Change default passwords immediately after installation!

## Usage

### For Customers

1. **Browse Products**: Visit the homepage to view products
2. **Register**: Create an account at `/register.php`
3. **Login**: Sign in at `/login.php`
4. **Add to Cart**: Click "Add to Cart" on any product
5. **Checkout**: Proceed to checkout and place order
6. **Track Orders**: View order history in dashboard
7. **Manage Profile**: Update profile at `/profile.php`

### For Administrators

1. **Access Admin Panel**: Visit `/admin.php`
2. **Add Products**: Create new products with images
3. **Manage Categories**: Organize product categories
4. **Process Orders**: Update order statuses
5. **Manage Banners**: Add promotional banners
6. **Create Coupons**: Generate discount codes
7. **Approve Reviews**: Moderate customer reviews
8. **Configure Settings**: Customize site appearance

## Migration from JSON to MySQL

If you're upgrading from the JSON-based version, follow the detailed migration guide in `MIGRATION_GUIDE.md`.

**Quick Summary**:
1. Configure database in `config.php`
2. Create database schema
3. Run `php database/migrate.php`
4. Verify migration
5. Test the website

## Security Features

- **Password Hashing**: Bcrypt with cost factor 10
- **CSRF Protection**: Tokens on all forms
- **SQL Injection Prevention**: Prepared statements
- **XSS Protection**: Output encoding
- **Session Security**: Secure session management
- **Input Validation**: Sanitization of all inputs
- **Rate Limiting**: Protection against brute force

## Performance Optimizations

- **Database Indexing**: Optimized queries
- **Connection Pooling**: PDO persistent connections
- **Image Optimization**: Automatic resizing
- **Lazy Loading**: On-demand data loading
- **Caching**: Session-based caching
- **Minified Assets**: Optimized CSS/JS

## Troubleshooting

### Database Connection Error
- Check MySQL service is running
- Verify database credentials in `config.php`
- Ensure database exists and user has permissions

### Images Not Loading
- Verify `/uploads` folder exists
- Check file permissions
- Ensure image paths are correct in database

### Login Issues
- Clear browser cookies
- Check session configuration
- Verify database user table

### Migration Errors
- Check PHP error logs
- Verify database table structure
- Ensure file permissions on `/data` folder

## Support

For detailed migration instructions, see `MIGRATION_GUIDE.md`.

For issues or questions:
1. Check the migration guide
2. Review PHP error logs
3. Verify database configuration
4. Test database connection independently

## License

This project is proprietary software. All rights reserved.

## Credits

- **Developed by**: GlowSpace Team
- **Version**: 2.0
- **Last Updated**: 2026-07-29

## Changelog

### Version 2.0 (2026-07-29)
- ✅ Migrated from JSON to MySQL/MariaDB
- ✅ Added user authentication system
- ✅ Implemented user dashboard and profiles
- ✅ Added cart and wishlist synchronization
- ✅ Upgraded security with CSRF and password hashing
- ✅ Improved performance with database indexing
- ✅ Added premium UI with sky blue gradient buttons
- ✅ Fixed HTML entity decoding issues
- ✅ Created comprehensive migration system

### Version 1.0
- Initial JSON-based release
- Basic product management
- Order system
- Admin panel
