# Rockview University — Student Studios backend package

This package contains only the backend files required for the Student Studios features found in the supplied archive: News Studio and Forms Studio.

## Deployment location

Deploy the contents of this package into:

    public_html/students/

The original archive contained these files under `skill_end/`. The copied Student Studios files have been adjusted so public news routes, image URLs and links use `/students/`, not `/skill_end/`.

## Files included

- `api/hr_news.php` — authenticated News Studio management API.
- `api/public_news.php` — public newsroom page and article renderer.
- `api/hr_forms.php` — authenticated Forms Studio management API and public form submissions.
- `api/hr_form.php` — public form response page.
- `api/hr_form_upload.php` — public form file-upload handler.
- `api/hr_form_file.php` — protected download handler for submitted form attachments.
- `api/hr_workspace_common.php` and `api/session_auth.php` — shared authentication, permission and audit dependencies used by the Studio APIs.
- `database/student_studios_schema.sql` — PostgreSQL schema for the two studios and their supporting audit/access tables.
- `config/database.php.example` — safe configuration template; it contains no production credentials.
- `.htaccess` — routes `/students/news/` and `/students/news/{slug}/` to the public newsroom.

## API routes

All routes below assume the deployment base URL `https://YOUR-DOMAIN/students`.

### News Studio

- `GET /api/hr_news.php?action=bootstrap` — articles, statistics, categories and campus list.
- `GET /api/hr_news.php?action=get&id={id}` — load one article.
- `POST /api/hr_news.php?action=upload` — upload an article image (`multipart/form-data`, field `image`).
- `POST /api/hr_news.php?action=save` — create/update an article (JSON).
- `POST /api/hr_news.php?action=status` — change draft/published/archived status (JSON).
- `DELETE /api/hr_news.php` — delete an article (JSON body containing `id`).
- `GET /news/` and `GET /news/{slug}/` — public newsroom and article pages.

### Forms Studio

- `GET /api/hr_forms.php?action=bootstrap` (or `list`) — list forms and summary.
- `GET /api/hr_forms.php?action=get&id={id}` — load a form.
- `GET /api/hr_forms.php?action=responses&id={id}` — retrieve responses.
- `POST /api/hr_forms.php?action=save` — create/update a draft (JSON).
- `POST /api/hr_forms.php?action=publish` — publish a form (JSON).
- `POST /api/hr_forms.php?action=close` — close a published form (JSON).
- `POST /api/hr_forms.php?action=reopen` — reopen a closed form (JSON).
- `POST /api/hr_forms.php?action=delete` — delete a draft/closed form (JSON).
- `GET /api/hr_forms.php?action=public_form&token={token}` — fetch a public form.
- `POST /api/hr_forms.php?action=public_submit` — submit a public response (JSON).
- `GET /api/hr_forms.php?action=public_edit_get&edit_token={token}` — retrieve an editable response.
- `POST /api/hr_forms.php?action=public_edit_submit` — update an editable response (JSON).
- `POST /api/hr_form_upload.php` — upload a public form attachment (`multipart/form-data`).
- `GET /api/hr_form_file.php?id={id}` — download an authorised submitted attachment.

Authenticated management requests use the existing Bearer-token session authentication.

## Database prerequisites and installation

1. Back up the PostgreSQL database.
2. Confirm that the existing `public.users(id)` and `public.campuses(id)` tables exist.
3. Apply `database/student_studios_schema.sql` as the database owner in staging first.
4. Review the application role name in the SQL grants section. It is currently set to the database role used by the supplied archive; change it if your deployment uses a different role.
5. Put your real database connection settings in `students/config/database.php`. Start from `config/database.php.example`; do not upload the example unchanged.
6. Ensure PHP has the PDO PostgreSQL driver and fileinfo enabled, and configure PHP upload limits for the News Studio image limit (12 MB).
7. The Forms Studio stores uploaded response files outside the public web root by default in `private_uploads/hr_forms`. Ensure PHP can create/write that directory. Set `HR_FORMS_PRIVATE_UPLOAD_DIR` if you use a different private storage location.
8. The API permission layer expects the existing HR user roles/permissions and campus access assignments to be configured. The SQL creates the minimal campus access table only if it does not already exist; it does not assign access to any user.

## Important scope notes

- The supplied ZIP is a backend `skill_end/` directory. It does not contain the Flutter `lib/features/admin/tabs/student_studios/` source files, so this package does not include or modify the Flutter UI/service files.
- The News Studio code is institution-wide in the supplied PHP implementation; the `campus_id` input is deliberately set to `NULL` by that implementation.
- The public news renderer may use university logo assets if present under `students/api/assets/`. Those image assets were not included because the supplied archive did not establish a dedicated Student Studios asset set.
- The shared HR authorization helper depends on the existing user/session schema. Do not remove the helper files from this package.

## Security action required

The uploaded archive contains live-looking database credentials and an API key in a server configuration file. They are intentionally excluded from this package. Rotate the database password and revoke/replace the exposed API key before deploying or continuing to use the archive. Do not share the original archive publicly.
