# BIS Campaign

A slimmed-down extract of the Ensembler UC2000 platform containing **only**:

- **Login** — staff authentication
- **Customer management** — list, search, view, and edit customers
- **User management** — create, edit, and manage CRM users
- **Email campaign management** — bulk email campaigns, templates, and reports
- **Email backend** — outbound dispatch and inbound IMAP processing (cron scripts)

**Not included:** helpdesk, ticketing, SMS/WhatsApp/social omnichannel UI, telephony, WFM, or dashboards.

## Directory layout

```
bis-campaign/
├── index.php                 → redirects to login
├── apiSendmail.php           → API: queue OTP / transactional email
├── apiUpdatesurveyStatus.php → API: mark survey request as sent
├── web_login.php             → login page
├── dashboard_login.php       → completes session after login
├── web_logout.php
├── config/                   → database and app settings
├── function/                 → login and multi-tenant helpers
├── public/                   → CSS, JS, images, bootstrap
├── vendor/                   → Composer (PHPMailer, mPDF)
├── script/
│   ├── email_status_handler.php
│   └── api_dashboard.php     → dashboard metrics API (optional)
└── CRM/
    ├── customer_index.php    → customer module router
    ├── user_index.php        → user module router
    ├── bulkcampaign_index.php→ email campaign router
    ├── admin_index.php       → email templates & SMTP/IMAP settings
    ├── Customer/             → customer pages
    ├── User/                 → user pages
    ├── admin/                → admin master data
    ├── omnichannel_config/   → bulk campaign logic + email scripts
    │   └── email/
    │       ├── dispatch_email.php      → SEND (run via cron)
    │       ├── imap_script_gmail.php   → RECEIVE (run via cron)
    │       └── web_email_in_script.php → legacy IMAP receive script
    └── includes/
        ├── sidebar.php       → slim navigation (4 modules only)
        └── head.php / web_footer.php
```

## Configuration

1. Edit `config/common-constants.php` — set database host, credentials, and `$SiteURL` for your deployment path.
2. On the server, set environment variable if web root differs from default:
   ```
   BIS_CAMPAIGN_WEB_ROOT=/var/www/html/bis-campaign
   ```
3. Uses the same MySQL databases as Ensembler (`CampaignTracker` for multi-tenant registry, per-company CRM DB).

## Cron jobs (email send & receive)

Run these on a schedule (e.g. every 1–5 minutes):

```bash
# Outbound — sends queued campaign and transactional emails
php /var/www/html/bis-campaign/CRM/omnichannel_config/email/dispatch_email.php

# Inbound — fetches new emails via IMAP for all tenants
php /var/www/html/bis-campaign/CRM/omnichannel_config/email/imap_script_gmail.php
```

## API endpoints

| File | Method | Parameters | Purpose |
|------|--------|------------|---------|
| `apiSendmail.php` | GET/POST | `emailid`, `otp` | Queues an OTP email to `web_email_information_out` |
| `apiUpdatesurveyStatus.php` | GET/POST | `campainid` | Sets `sent_flag=1` on `tbl_survey_request` |
| `script/api_dashboard.php` | varies | date filters | Dashboard resolution-rate metrics (requires `CRM/web_function.php`) |

Example:
```
POST /bis-campaign/apiSendmail.php?emailid=user@example.com&otp=123456
```

Outbound emails queued via `apiSendmail.php` are sent by the `dispatch_email.php` cron job.

## Entry URLs (after deployment)

| Page | URL |
|------|-----|
| Login | `/bis-campaign/web_login.php` |
| Customers | `/bis-campaign/CRM/customer_index.php?token=...` |
| Users | `/bis-campaign/CRM/user_index.php?token=...` |
| Email Campaign | `/bis-campaign/CRM/bulkcampaign_index.php?token=...&campaign=Email` |
| Campaign Templates | `/bis-campaign/CRM/admin_index.php?token=...` |

After login you are redirected to the Customers page.

## Notes

- This extract shares the Ensembler database schema; no schema migration is included.
- `CRM/omnichannel_config/` is **email-only** (bulk campaigns, queue reports, send/receive scripts). SMS, WhatsApp, social, and chat channels have been removed.
- Run `composer install` in this folder on deploy if `vendor/` is not copied; PHPMailer is required for email send/receive.
- Optional env var: `BIS_CAMPAIGN_WEB_ROOT` (default in `config/app_paths.php`).
- Licence checking is disabled — users can be created and logged in without licence limits.
- The parent `ensembler/` folder is unchanged; all BIS Campaign code lives in `bis-campaign/`.
