# Trump Portal - Setup Instructions

## 🚀 Complete Trump Portal System with CodeIgniter 3.1.2

### System Features
- ✅ Role-based access control (Admin & User)
- ✅ Campaign management with multiple types
- ✅ Master data management with CSV upload
- ✅ Automatic fail percentage logic
- ✅ Real-time fail refill mechanism
- ✅ Data masking for security
- ✅ Fake message sending simulation
- ✅ Comprehensive logging system
- ✅ Dashboard analytics and reports

---

## 📋 Installation Steps

### 1. Database Setup

1. Open phpMyAdmin (http://localhost/phpmyadmin)
2. Import the database schema:
   ```sql
   Run the database_schema.sql file
   ```
3. The database `marketing_portal` will be created with sample users

### 2. Configuration

The system is already configured for:
- **Base URL**: http://localhost:8096/
- **Database**: marketing_portal (username: root, no password)
- **Session**: Enabled
- **Helpers**: URL, Form, Security, Date, Marketing (custom)

### 3. Start Apache and MySQL

```bash
# Start XAMPP services
Start Apache on port 8096
Start MySQL
```

### 4. Access the Application

Navigate to: **http://localhost:8096/**

---

## 👤 Default Login Credentials

### Admin Account
- **Username**: admin
- **Password**: admin123
- **Role**: Super Admin (Full Access)

### User Account
- **Username**: testuser  
- **Password**: user123
- **Role**: User (Restricted Access)

---

## 📁 Directory Structure

```
affix_marketing_portal/
├── application/
│   ├── controllers/
│   │   ├── Auth.php          # Authentication
│   │   ├── Admin.php         # Admin panel
│   │   └── User.php          # User panel
│   ├── models/
│   │   ├── User_model.php
│   │   ├── Campaign_model.php
│   │   ├── Data_model.php
│   │   ├── Send_model.php
│   │   └── Log_model.php
│   ├── views/
│   │   ├── auth/             # Login page
│   │   ├── admin/            # Admin views
│   │   └── user/             # User views
│   ├── helpers/
│   │   └── marketing_helper.php  # Data masking functions
│   └── config/               # Configuration files
├── uploads/                  # CSV upload directory
├── .htaccess                 # Clean URL rewrite
└── database_schema.sql       # Database structure
```

---

## 🎯 Key Features

### Admin Panel Features

1. **Dashboard**
   - Total campaigns, users, and data statistics
   - Performance charts (Sent vs Failed)
   - Recent login activity
   - Today's activity summary

2. **User Management**
   - Create, edit, delete users
   - Activate/deactivate accounts
   - View user activity logs

3. **Campaign Management**
   - Create campaigns with types: SMS, WhatsApp, WhatsApp Image, Status Messaging, Custom
   - Set fail percentage (1% - 1.5%)
   - Assign users to campaigns
   - Assign data to users
   - Start/Stop/Pause/Resume campaigns
   - Real-time status updates

4. **Master Data Management**
   - Upload CSV/Excel files
   - Automatic duplicate removal
   - View assigned/unassigned data
   - Search and filter

5. **Reports & Logs**
   - Campaign-wise reports
   - User-wise activity
   - Login logs with IP, browser, device
   - Audit trail for all actions

### User Panel Features

1. **Dashboard**
   - Personal statistics
   - Assigned campaigns overview
   - Today's activity chart
   - Hourly performance graph

2. **My Campaigns**
   - View assigned campaigns
   - See masked data only
   - Send messages (simulation)
   - View send logs

3. **Campaign Detail Page**
   - **Masked Data Display**:
     - Mobile: `98*****210`
     - Name: `R****`
     - Email: `a**@gmail.com`
     - Address: `Andh****`
   - Message sending interface
   - Real-time status updates
   - Auto-load next pending data

4. **Send Logs**
   - View message history
   - Status: Sent/Failed
   - Timestamp for each message

5. **Reports**
   - Campaign-wise breakdown
   - Success rate statistics
   - **No Download/Export** allowed

---

## 🔒 Data Masking Rules

| Field   | Original         | Masked            |
|---------|------------------|-------------------|
| Mobile  | 9876543210       | 98*****210        |
| Name    | Rohit            | R****             |
| Email   | abc@gmail.com    | a**@gmail.com     |
| Address | Andheri West     | Andh****          |

---

## ⚙️ Auto-Fail Logic

### Stage 1: Assignment Time
When assigning 200 records with 1% fail rate:
- System adds 2 extra records automatically
- **Total Assigned: 202**

### Stage 2: Real-Time Refill
During message sending:
- If a message FAILS → system auto-adds 1 new data row
- Counters update: Sent / Failed / Remaining / Total
- Creates realistic simulation environment

---

## 📊 Database Tables

- `users` - User accounts
- `campaigns` - Campaign definitions
- `master_data` - Contact database
- `campaign_users` - User-campaign assignment
- `campaign_user_data` - Data assignment with status
- `send_logs` - Message sending logs
- `fail_auto_add` - Auto-refill history
- `login_logs` - Authentication logs
- `audit_logs` - Activity tracking

---

## 🛠 Troubleshooting

### Issue: Page not found
**Solution**: Enable mod_rewrite in Apache
1. Open `httpd.conf`
2. Uncomment: `LoadModule rewrite_module modules/mod_rewrite.so`
3. Change `AllowOverride None` to `AllowOverride All`
4. Restart Apache

### Issue: Database connection error
**Solution**: 
1. Check MySQL is running
2. Verify database name: `marketing_portal`
3. Check credentials in `application/config/database.php`

### Issue: Port 8096 not working
**Solution**:
1. Open XAMPP Control Panel
2. Click Apache Config → httpd.conf
3. Change `Listen 80` to `Listen 8096`
4. Change `ServerName localhost:80` to `ServerName localhost:8096`
5. Restart Apache

### Issue: Upload folder permission
**Solution**:
```bash
mkdir uploads
chmod 777 uploads
```

---

## 📝 CSV Upload Format

Create a CSV file with the following columns:

| Column | Field Name    | Required |
|--------|---------------|----------|
| 1      | Mobile        | Yes      |
| 2      | Name          | No       |
| 3      | Email         | No       |
| 4      | Address       | No       |
| 5-7    | Custom Fields | No       |

**Example CSV:**
```csv
9876543210,John Doe,john@example.com,123 Main Street
9876543211,Jane Smith,jane@example.com,456 Oak Avenue
```

---

## 🎨 Technology Stack

- **Backend**: CodeIgniter 3.1.2 (PHP Framework)
- **Database**: MySQL
- **Frontend**: Bootstrap 5.3
- **Icons**: Bootstrap Icons
- **Charts**: Chart.js
- **DataTables**: jQuery DataTables

---

## 🔐 Security Features

- Password hashing with BCrypt
- Session-based authentication
- CSRF protection (CodeIgniter built-in)
- XSS filtering enabled
- Data masking on user views
- No data export for regular users
- IP and device tracking
- Failed login attempt tracking

---

## 📈 Usage Workflow

### Admin Workflow:
1. Login as admin
2. Create users
3. Upload master data (CSV)
4. Create campaign
5. Assign users to campaign
6. Assign data to users (with fail percentage)
7. Monitor performance
8. View logs and reports

### User Workflow:
1. Login as user
2. View assigned campaigns
3. Open campaign detail page
4. See masked contact data
5. Write and send message
6. System simulates send (success/fail)
7. Auto-load next pending contact
8. View send logs and reports

---

## 🎯 Testing the System

1. **Login as Admin**
   - Create a new campaign
   - Upload master data CSV
   - Assign testuser to campaign
   - Assign 10 data records with 1% fail

2. **Login as User**
   - View the campaign
   - Send messages one by one
   - Watch counters update
   - Check for failed messages (auto-refill will trigger)

3. **Verify Logs**
   - Login logs show all attempts
   - Audit logs track all actions
   - Send logs show message history

---

## 📞 Support

For issues or questions:
- Check database connection
- Verify XAMPP services are running
- Check error logs in `application/logs/`
- Ensure port 8096 is available

---

## 🎉 Congratulations!

Your Trump Portal is now ready to use. The system provides a complete, realistic marketing campaign simulation with:
- Secure data handling
- Role-based access
- Automatic fail logic
- Comprehensive logging
- Beautiful dashboard analytics

**Happy Testing!** 🚀
