# Setup notes

## 1. Upload

Upload this folder to something like:

```text
public_html/google-test/
```

or put it behind a subdomain such as:

```text
https://reminders.wildfoto.au/
```

## 2. Database

Create an empty MySQL database in cPanel, then import:

```text
sql/install.sql
```

## 3. Config

Copy:

```text
config.example.php
```

to:

```text
config.php
```

Then set:

- `base_url`
- database credentials
- Google OAuth client ID and secret
- `admin_export_token`

## 4. Google Cloud setup

In Google Cloud Console:

1. Create/select a project.
2. Enable **Google Calendar API**.
3. Configure OAuth consent screen.
4. Add yourself as a test user while the app is in testing mode.
5. Create OAuth Client ID: **Web application**.
6. Add this exact redirect URI:

```text
https://YOUR-DOMAIN-HERE/google-test/google-callback.php
```

The test uses this scope:

```text
https://www.googleapis.com/auth/calendar
```

Google's own create-event guide documents using `events.insert()` with `calendarId` and an event body, and says `calendarId` can be `primary`. It also states that inserting events needs the calendar edit scope.

## 5. Test flow

1. Open `index.php`.
2. Click **Connect Google Calendar**.
3. Approve access in Google.
4. Create a local test reminder.
5. Click **Sync/create**.
6. Check Google Calendar / iPhone.
7. Click **Move +1 day** and check it updates.
8. Try editing the event in Google Calendar manually, then click **Read back**.
9. Click **Delete both**.

## 6. Export package

Open the home page and use the export form, or visit:

```text
admin/export.php?token=YOUR_ADMIN_EXPORT_TOKEN
```

The export excludes `config.php` and redacts live OAuth tokens from the database dump.

## Microsoft / Outlook Calendar test setup

Patch v4 adds a Microsoft Graph connector beside the Google connector.

### 1. Run the SQL patch

In phpMyAdmin, run:

```sql
source sql/patch_v4_microsoft_outlook.sql
```

Or open `sql/patch_v4_microsoft_outlook.sql`, copy the SQL, and run it in the `appswild_cronremindersdb` database.

### 2. Add Microsoft settings to config.php

Add this top-level block beside the existing `google` block:

```php
'microsoft' => [
    'tenant' => 'common',
    'client_id' => 'PASTE_MICROSOFT_APPLICATION_CLIENT_ID_HERE',
    'client_secret' => 'PASTE_MICROSOFT_CLIENT_SECRET_VALUE_HERE',
    'scope' => 'offline_access User.Read Calendars.ReadWrite',
],
```

Keep `tenant` as `common` for this test so personal Outlook.com and Microsoft work/school accounts can try the connection.

### 3. Create the Microsoft app registration

Go to Microsoft Azure / Entra admin centre:

- App registrations
- New registration
- Name: `cronreminders-test`
- Supported account types: use personal Microsoft accounts too if you want to test Outlook.com
- Redirect URI type: Web
- Redirect URI:

```text
https://apps.wildfoto.au/cronreminders/microsoft-callback.php
```

### 4. Add a client secret

In the app registration:

- Certificates & secrets
- New client secret
- Copy the **Value** immediately and paste it into `config.php` as `client_secret`.

### 5. API permissions

Add delegated Microsoft Graph permissions:

```text
offline_access
User.Read
Calendars.ReadWrite
```

Then use the app page button: **Connect Outlook/Microsoft Calendar**.
