# Submissions Module Refactor – Summary

## 1) Files changed

| File | Changes |
|------|--------|
| `includes/class-skyflow-forms-db.php` | Added `get_submission()`, `get_submissions_filtered()`, `update_submission_read_status()`, `update_submission_notes()`, `delete_submission()`, `get_form_name()`. Schema already had `submission_data`, `ip_address`, `submitter_user_id`, `user_agent`, `read_status`, `notes`. `add_subscriber()` sets `read_status = 'new'` on insert. |
| `public/class-skyflow-forms-public.php` | Added `push_submission_field()` and `submission_fields` array in `validate_and_sanitize_submission()`; return `submission_fields` in result. In `process_requests()` pass `$extra` (submission_data, ip_address, submitter_user_id, user_agent) to `add_subscriber()`. |
| `admin/class-skyflow-forms-admin.php` | Menu label "Subscriptions" → "Submissions"; added hidden submenu "View Submission". New/updated: `page_subs()` (filters, table, bulk actions), `page_view_submission()`, `handle_submissions_bulk()`, `handle_submission_action()`, `handle_submission_toggle_read()`, `export_submissions_csv()`. Registered admin_post actions for bulk, single action, toggle read. |

## 2) DB impact summary

- **No separate migration script.** Table `wp_skyflow_forms_subscribers` is updated via **dbDelta** when the plugin runs (e.g. load or activation). The CREATE TABLE in `SkyflowForms_DB::setup()` defines:
  - `submission_data LONGTEXT NULL`
  - `ip_address VARCHAR(45) NULL`
  - `submitter_user_id BIGINT UNSIGNED NULL`
  - `user_agent VARCHAR(500) NULL`
  - `read_status VARCHAR(20) NOT NULL DEFAULT 'new'`
  - `notes TEXT NULL`
- **Backward compatibility:** Existing rows remain valid. Rows without `submission_data` still appear in the list and on the view page (email, form, source, dates only). `read_status` defaults to `'new'` for new inserts; existing NULL/empty is treated as non‑trash in filters.
- **Table name unchanged:** Still `skyflow_forms_subscribers`; only UI labels use "Submissions".

## 3) QA checklist

- [ ] **Menu renamed** – Admin sidebar shows "Submissions" (slug `skyflow-forms-subs` unchanged).
- [ ] **List loads** – Submissions list page loads with columns: ID, Form, Email, IP, Submitted, Status, Actions.
- [ ] **Filters work** – Filter by Form, date range (From/To), Status (New/Read/Starred/Trash), Search (email/name/value).
- [ ] **Bulk actions** – Mark as Read, Mark as Unread, Move to Trash, Delete permanently, Export selected (CSV) work with checked rows.
- [ ] **View page** – "View" and Submission ID link open View Submission; header shows form name, ID, date; meta shows Status toggle, IP, User, Page URL, User agent (for users with capability).
- [ ] **View shows all fields** – Submitted data section lists all stored fields in form order; choice fields show labels; uploads as links; legacy submissions show "No field data" and email/source.
- [ ] **Upload links safe** – File fields render as `esc_url()` links with basename text.
- [ ] **Legacy submissions viewable** – Rows with NULL `submission_data` appear in list and open in view with email/source/dates only.
- [ ] **Nonce/capability** – All actions (bulk, trash, delete, toggle read, export) require `manage_options` and use nonces.
- [ ] **i18n** – All new strings use `__()` / `esc_html_e()` with text domain `skyflow-forms`.

## 4) Optional follow-ups (not implemented)

- Notes panel on submission (DB column `notes` exists; UI for edit not added).
- Star/flag (DB supports `read_status = 'starred'`; filter exists; toggle from view not added).
- Export all for a specific form (filter by form + "Export all CSV" could be extended).
- Delete attachments when deleting submission (setting + file cleanup not added).
