# CrimeSafe - HTML+PHP Version

## 📋 Overview
Complete HTML+PHP conversion of the CrimeSafe Bangladesh safety navigation application with dual authentication system (Citizens + Law Enforcement Agencies).

## 🚀 Features

### For Citizens (Users):
- ✅ Real-time crime map viewing
- ✅ Submit crime reports with evidence
- ✅ Safe route planning
- ✅ Crime analytics for all 64 districts
- ✅ Community feed and safety groups
- ✅ Credibility score system
- ✅ Leaderboard and gamification

### For Agencies (Police/RAB/Gov):
- ✅ Pending reports queue with accept/reject
- ✅ Evidence verification system
- ✅ Case management and tracking
- ✅ User credibility viewing
- ✅ Team member management
- ✅ Performance statistics
- ✅ Priority alerts system

## 📦 Installation

### Requirements:
- PHP 7.4 or higher
- MySQL 5.7 or higher
- Apache/Nginx web server
- phpMyAdmin (optional, for database management)

### Step 1: Database Setup

1. Create a MySQL database:
```sql
CREATE DATABASE crimesafe;
```

2. Import the database schema:
```bash
mysql -u root -p crimesafe < database.sql
```

Or use phpMyAdmin:
- Open phpMyAdmin
- Create database "crimesafe"
- Import `database.sql` file

### Step 2: Configuration

1. Open `config.php` and update database credentials:
```php
define('DB_HOST', 'localhost');
define('DB_USER', 'your_username');    // Change this
define('DB_PASS', 'your_password');    // Change this
define('DB_NAME', 'crimesafe');
```

2. Update site URL if needed:
```php
define('SITE_URL', 'http://localhost/crimesafe');
```

### Step 3: File Upload Directory

Create an `uploads` directory for evidence files:
```bash
mkdir uploads
chmod 755 uploads
```

### Step 4: Access the Application

1. Move all files to your web server directory:
   - XAMPP: `C:\xampp\htdocs\crimesafe\`
   - WAMP: `C:\wamp64\www\crimesafe\`
   - Linux: `/var/www/html/crimesafe/`

2. Access in browser:
   - Local: `http://localhost/crimesafe/`
   - Production: `http://yourdomain.com/`

## 🔑 Test Accounts

### Citizen Account:
- **Email:** rafiq@example.com
- **Password:** password
- **Type:** Citizen (User)

### Agency Account:
- **Email:** kamal@police.gov.bd
- **Password:** password
- **Type:** Agency (Police/RAB/Gov)

## 📁 File Structure

```
crimesafe/
│
├── index.php              # Landing page
├── auth.php               # Login/Sign Up page
├── user-dashboard.php     # Citizen dashboard
├── agency-dashboard.php   # Agency dashboard
├── config.php             # Database config & helper functions
├── logout.php             # Logout handler
├── database.sql           # Database schema with sample data
├── README.md              # This file
│
└── uploads/              # Evidence files directory (create this)
```

## 🎨 Pages Overview

### 1. Landing Page (`index.php`)
- Hero section with CTA
- Features showcase
- How it works section
- Statistics
- Footer with links

### 2. Authentication (`auth.php`)
- **Login Form:**
  - User Type selector (Citizen/Agency)
  - Email + Password
  - Remember me
  - Social login buttons (Google, Facebook)

- **Sign Up Form:**
  - Citizen fields: Name, Phone, District
  - Agency fields: Organization, Badge ID, Department, Officer details
  - Email + Password + Confirm Password
  - Terms & Conditions

### 3. User Dashboard (`user-dashboard.php`)
- Welcome section with user stats
- Quick stats cards (Reports, Points, Alerts)
- My reports table
- Active alerts in user's district
- Navigation to report crime

### 4. Agency Dashboard (`agency-dashboard.php`)
- Welcome section with agency info
- Quick stats (Pending, Verified, Active, Resolved)
- **Pending Reports Queue:**
  - Full report details
  - Reporter credibility score
  - Evidence count
  - Accept/Reject buttons
- Active investigations list
- Real-time updates

## 🔧 Customization

### Change Colors:
Replace Tailwind color classes:
- Green (Primary): `from-green-500 to-green-600`
- Blue (Agency): `from-blue-600 to-blue-800`

### Add Pages:
1. Create new PHP file
2. Include `config.php` at top
3. Use `requireLogin()` or `requireCitizen()` or `requireAgency()`

Example:
```php
<?php
require_once 'config.php';
requireCitizen();

// Your page code here
?>
```

### Add Database Tables:
Add table schema to `database.sql` and create migration:
```sql
CREATE TABLE IF NOT EXISTS new_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    -- your columns
);
```

## 🔐 Security Features

✅ Password hashing with `password_hash()`
✅ SQL injection prevention with PDO prepared statements
✅ XSS protection with `htmlspecialchars()`
✅ Session management
✅ CSRF protection (add tokens for production)
✅ Input sanitization

## 📊 Database Tables

1. **users** - Citizen accounts
2. **agencies** - Law enforcement accounts
3. **crime_reports** - All crime reports
4. **evidence_files** - Evidence attachments
5. **notifications** - User/Agency notifications
6. **community_posts** - Community feed posts
7. **safety_alerts** - District-wide alerts

## 🚀 Next Steps (Optional Enhancements)

### For Production:
1. **Add HTTPS** - Use SSL certificate
2. **Email Verification** - PHPMailer integration
3. **Password Reset** - Forgot password functionality
4. **File Upload** - Evidence upload system
5. **Google Maps Integration** - Live map with Leaflet.js or Google Maps API
6. **Real-time Notifications** - WebSockets or Pusher
7. **Export Reports** - PDF generation with TCPDF
8. **Advanced Search** - Filter reports by date, severity, location
9. **Admin Panel** - Manage users, agencies, reports
10. **API Endpoints** - RESTful API for mobile apps

### Map Integration:
Add Leaflet.js for interactive maps:
```html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
```

### Chart Integration:
Add Chart.js for analytics:
```html
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
```

## 🐛 Troubleshooting

### Database Connection Error:
- Check MySQL is running
- Verify credentials in `config.php`
- Ensure database exists

### Session Error:
- Check `session_start()` at top of files
- Verify write permissions on session directory

### Login Not Working:
- Check test account credentials
- Verify users/agencies table has data
- Check password hashing

### Redirect Issues:
- Update `SITE_URL` in `config.php`
- Check `.htaccess` configuration

## 📞 Support

For issues or questions:
- Check database.sql for sample data
- Verify all files are in correct directory
- Ensure PHP and MySQL versions meet requirements

## 📝 License

This project is provided as-is for educational purposes.

## 🎯 Credits

Developed for CrimeSafe Bangladesh - Making Bangladesh safer through community collaboration and technology.

---

**Made with ❤️ for Bangladesh**
