<?php
/**
 * ADMIN DASHBOARD SETUP GUIDE
 * 
 * This file provides instructions for setting up and configuring
 * the Restaurant Admin Dashboard
 */

// This is a guide file - no PHP execution needed
// Read this as a text/documentation file

?>

# ADMIN DASHBOARD - QUICK START GUIDE

## 🎯 What's New?

A complete admin dashboard has been created in `/admin/` folder with the following features:

1. ✅ Admin Login System
2. ✅ Menu Management (Category-wise)
3. ✅ Reservation Handling
4. ✅ Contact Messages Management
5. ✅ Online Order/Delivery Tracking
6. ✅ Complete Database Operations (Create, Read, Update, Delete)
7. ✅ Professional UI/UX with Dashboard

## 📋 Files Created

```
/admin/
├── admin_login.php              (Login page)
├── index.php                    (Dashboard home)
├── menu.php                     (Menu management)
├── reservations.php             (Reservation management)
├── contact.php                  (Contact messages)
├── orders.php                   (Online orders)
├── logout.php                   (Logout functionality)
├── check_admin.php              (Auth verification)
├── db_connect.php               (Database connection)
├── database_setup.sql           (SQL tables schema)
├── assets/css/admin-style.css   (Styling)
└── README.md                    (Full documentation)
```

## 🔧 INSTALLATION STEPS

### Step 1: Database Setup (IMPORTANT!)

1. Open phpMyAdmin: http://localhost/phpmyadmin
2. Make sure you're using `bermiz_db` database
3. Open the `database_setup.sql` file in `/admin/` folder
4. Copy all the SQL code
5. Paste into phpMyAdmin "SQL" tab
6. Click "Execute"

This creates:
- `admins` table (for admin login)
- `menu_items` table
- `reservations` table
- `contact_messages` table
- `orders` table
- `catering_bookings` table
- `users` table
- Sample data

### Step 2: Set Admin Password

Default admin email: `admin@restaurant.com`

To set a custom password:

1. In phpMyAdmin, go to `bermiz_db` → `admins` table
2. Click "Edit" on the admin record
3. To generate a password hash, use any online bcrypt generator or PHP:

```php
// In terminal or PHP file:
php -r "echo password_hash('your_password', PASSWORD_BCRYPT);"
```

4. Paste the hash into the password field
5. Update the record

### Step 3: Access Admin Panel

Navigate to: **http://localhost/Restaurant/admin/admin_login.php**

Login with:
- Email: `admin@restaurant.com`
- Password: `admin123` (or your custom password)

## 📊 Dashboard Modules

### 1. Menu Management
- **Location:** `/admin/menu.php`
- **Features:**
  - Add new menu items with category, price, description
  - View all items in table format
  - Edit menu items
  - Delete items with confirmation
  - Filter by category
  - Display availability status
  - Show category breakdown statistics

- **Database Operations:**
  - CREATE: Add new menu items
  - READ: View all items with filters
  - UPDATE: Modify item details
  - DELETE: Remove items

### 2. Reservation Management
- **Location:** `/admin/reservations.php`
- **Features:**
  - View all reservations
  - Filter by status (pending, approved, rejected)
  - Approve reservations
  - Reject reservations
  - View detailed reservation info
  - Delete reservations
  - Statistics for each status

- **Database Operations:**
  - READ: View all reservations
  - UPDATE: Change reservation status
  - DELETE: Remove reservations

### 3. Contact Messages
- **Location:** `/admin/contact.php`
- **Features:**
  - View all contact form submissions
  - Filter by read/unread
  - Mark as read
  - View full message details
  - Delete messages
  - Message statistics

- **Database Operations:**
  - READ: View messages
  - UPDATE: Mark as read
  - DELETE: Remove messages

### 4. Online Orders
- **Location:** `/admin/orders.php`
- **Features:**
  - Track all online delivery orders
  - Update order status (pending → processing → completed → cancelled)
  - View order items and details
  - Filter by status
  - Track revenue from completed orders
  - Delivery address and customer info
  - Special instructions tracking

- **Database Operations:**
  - READ: View all orders
  - UPDATE: Change order status
  - DELETE: Cancel/remove orders

### 5. Dashboard Home
- **Location:** `/admin/index.php`
- **Features:**
  - Overview statistics
  - Quick links to all modules
  - System information
  - Total counts for each module

## 🔐 Security Notes

1. **Session Management:** Admin sessions are managed via PHP $_SESSION
2. **Authentication:** `check_admin.php` verifies login on protected pages
3. **Database Security:** All queries use prepared statements to prevent SQL injection
4. **Password Storage:** Admin passwords hashed with bcrypt
5. **Logout:** Destroys session and redirects to login

## 📊 Database Tables Reference

### admins
```sql
id (INT)
email (VARCHAR)
password (VARCHAR - hashed)
name (VARCHAR)
created_at (TIMESTAMP)
updated_at (TIMESTAMP)
```

### menu_items
```sql
id (INT)
name (VARCHAR)
category (VARCHAR)
description (TEXT)
price (DECIMAL)
availability (TINYINT)
image_url (VARCHAR)
created_at (TIMESTAMP)
updated_at (TIMESTAMP)
```

### reservations
```sql
id (INT)
name (VARCHAR)
email (VARCHAR)
phone (VARCHAR)
reservation_date (DATE)
reservation_time (TIME)
number_of_guests (INT)
special_requests (TEXT)
status (ENUM: pending, approved, rejected, completed)
created_at (TIMESTAMP)
```

### contact_messages
```sql
id (INT)
user_id (INT)
name (VARCHAR)
email (VARCHAR)
phone (VARCHAR)
message (TEXT)
is_read (TINYINT)
created_at (TIMESTAMP)
```

### orders
```sql
id (INT)
customer_name (VARCHAR)
customer_email (VARCHAR)
customer_phone (VARCHAR)
delivery_address (TEXT)
delivery_city (VARCHAR)
delivery_zip (VARCHAR)
items (JSON - array of items)
subtotal (DECIMAL)
delivery_fee (DECIMAL)
total_amount (DECIMAL)
special_instructions (TEXT)
status (ENUM: pending, processing, completed, cancelled)
created_at (TIMESTAMP)
```

## 🎨 UI Features

- **Responsive Design:** Works on desktop, tablet, and mobile
- **Modern Colors:** Purple gradient theme
- **Icons:** Font Awesome icons for better UX
- **Bootstrap 5:** For grid and components
- **Status Badges:** Color-coded status indicators
- **Interactive Modals:** For viewing detailed information
- **Smooth Animations:** Hover effects and transitions
- **Dark Sidebar:** Easy navigation
- **Quick Stats:** Overview cards with statistics

## ⚙️ Configuration

All configurations are in the respective PHP files:

### Database Connection
Edit `db_connect.php`:
```php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bermiz_db";
```

### Admin Session Check
Automatic via `check_admin.php` which:
1. Starts session
2. Checks if `$_SESSION['admin_id']` is set
3. Redirects to login if not authenticated

## 🧪 Testing the System

### Test 1: Login
1. Go to admin_login.php
2. Try login with wrong credentials (should fail)
3. Login with correct credentials
4. Should redirect to index.php

### Test 2: Add Menu Item
1. Go to Menu Management
2. Click "Add New Menu Item"
3. Fill form and submit
4. Item should appear in table
5. Check database: item in menu_items table

### Test 3: Manage Reservations
1. Go to Reservations (sample data included)
2. Click approve/reject buttons
3. Status should update
4. Click view to see details

### Test 4: Contact Messages
1. Create a contact submission from main site
2. Check Contact Messages in admin
3. Should see the message
4. Mark as read - badge changes

### Test 5: Orders
1. Create an online order from main site
2. Go to Orders in admin
3. See the order with items
4. Update status through dropdown
5. Status should change

## 🚀 Integration with Main Site

The admin panel automatically integrates with your main restaurant site because:

1. **Same Database:** Uses `bermiz_db`
2. **Same Tables:** Uses existing and new tables
3. **PHP Compatible:** Uses same PHP version
4. **Session Aware:** Can detect customer login vs admin login

## 📱 Responsive Breakpoints

- Desktop: 1024px and above (full sidebar visible)
- Tablet: 768px - 1023px (optimized layout)
- Mobile: Below 768px (collapsed sidebar)

## 🐛 Troubleshooting

### Login Not Working
- Check if `admins` table has data
- Verify password hash format
- Check database connection in db_connect.php
- Clear browser cookies/session

### Tables Not Showing
- Run database_setup.sql again
- Check table names in PHP queries
- Verify database connection
- Check browser console for errors

### Styling Not Applied
- Check admin-style.css file exists
- Clear browser cache (Ctrl+Shift+Delete)
- Check Bootstrap CDN is accessible
- Verify file paths are correct

### Status Not Updating
- Check if update queries are correct
- Verify form method is POST
- Check if status value matches database ENUM
- Check database for permission errors

## 📞 Support Checklist

Before asking for help:
- [ ] Database setup completed
- [ ] Admin account created
- [ ] Can login to admin panel
- [ ] CSS styling loads properly
- [ ] Can add menu items
- [ ] Can view reservations
- [ ] Can manage orders
- [ ] Logout works

## 🎓 Learning Resources

- Bootstrap 5: https://getbootstrap.com/docs/5.0/
- Font Awesome: https://fontawesome.com/icons
- PHP MySQLi: https://www.php.net/manual/en/book.mysqli.php
- SQL Tutorial: https://www.w3schools.com/sql/

## 📝 Next Steps

After setup, you can:

1. **Customize Menu:** Add your actual menu items
2. **Brand Colors:** Modify admin-style.css gradient colors
3. **Logo:** Add restaurant logo to sidebar
4. **Email Integration:** Set up email notifications
5. **Additional Features:** Add staff management, analytics, etc.

## 🎉 You're All Set!

The admin dashboard is ready to use. Start managing your restaurant operations efficiently!

---

**Created:** December 18, 2025
**Version:** 1.0
**Status:** Production Ready
