# Course terms acceptance

Apply `20260928_course_terms_acceptance.sql` to the application's database **before deploying the PHP changes**. The migration only creates `course_terms_acceptance_tb`; it does not modify existing tables or records. It can be run again safely.

With the project's configured database credentials, run from the project root:

```sh
php database/migrate_course_terms.php
```

Alternatively import the SQL file through phpMyAdmin. Do not reimport the full database export.

- `user_id` is `member_tb.id`; `course_id` is the shared slide's `news_tb.id`.
- The popup reads `section_tb` record 26 using `SectionTb::getItem()`.
- `terms_version` is `section-26:` followed by the SHA-256 hash of `detail`. `terms_detail` preserves the accepted HTML as audit evidence.
- Acceptance is permanent for the user/course pair. Editing section 26 does not prompt previously accepted courses again.
- `accepted_at` uses Asia/Ho_Chi_Minh. IP uses `REMOTE_ADDR`, without trusting client-supplied forwarding headers.
- Repeated submissions preserve the first successful acceptance.
- Unaccepted slide URLs render the popup directly in `view.phtml`, without loading or rendering teaching content. Confirmation posts to the same slide URL. Closing the popup returns to the dashboard without saving consent.
- If saving fails, the popup shows an error and does not open teaching content.

Verification:

```sh
php tests/course_terms_test.php
node --check public_html/template/frontend/src/js/page_dashboard.js
```

The PHP tests isolate controller behavior with simulated storage. For deployment validation, sign in with a shared course, check dismissal and an unchecked submission, accept, and verify the new record and subsequent visits. Also test a second course and a second member. Do not manufacture acceptance records for real users during testing.
