# API Notices Endpoint Setup

## Summary

Created an API endpoint that returns notices in JSON format for the WordPress frontend website.

## Files Created

### 1. `api/notices/index.php` (Created)
This file is accessible at: `https://eportal.kkcp.gov.bd/api/notices`

### 2. `api/notices.php` (Created - Backup)
This file is accessible at: `https://eportal.kkcp.gov.bd/api/notices.php`

Both files query the `notices` table and return JSON data with the fields expected by WordPress:
- `name` - Notice title
- `createdDate` - Creation date
- `attachmentUrl` - Full URL to the attachment file

## How It Works

1. **WordPress Request**: The WordPress site calls `wp_remote_get('https://eportal.kkcp.gov.bd/api/notices')`
2. **Directory Index**: The server serves `api/notices/index.php` when accessing the `api/notices` directory
3. **Database Query**: The PHP file queries the `notices` table for active notices
4. **JSON Response**: Returns an array of notice objects in the expected format

## JSON Response Format

```json
[
  {
    "name": "Notice Title",
    "createdDate": "2025-01-15 10:30:00",
    "attachmentUrl": "https://eportal.kkcp.gov.bd/uploads/notices/file.pdf"
  },
  {
    "name": "Another Notice",
    "createdDate": "2025-01-10 14:20:00",
    "attachmentUrl": ""
  }
]
```

## Deployment Instructions

To deploy this to the production server:

1. **Upload the `api` directory** to the root directory of the production server
2. **Test the endpoint** by visiting: `https://eportal.kkcp.gov.bd/api/notices`

## Troubleshooting

### If you get a 404 error on `https://eportal.kkcp.gov.bd/api/notices`:

1. **Check directory structure**: Ensure the `api/notices/index.php` file exists on the server
2. **Check file permissions**: Ensure the directory and files are readable by the web server
3. **Use the backup URL**: `https://eportal.kkcp.gov.bd/api/notices.php`

### If you get a 500 error:

1. **Check database connection**: Ensure the database credentials in `php/includes/db.php` are correct
2. **Check error logs**: Review the server error logs for more details

### If you see PHP code instead of JSON:

1. **Check PHP is enabled**: Ensure PHP is properly configured on the server
2. **Check file extension**: Ensure the file has the `.php` extension
3. **Use the backup URL**: `https://eportal.kkcp.gov.bd/api/notices.php`

## Database Query

The API uses this SQL query to fetch notices:
```sql
SELECT Id, Name, Description, CreatedDate, AttachmentUrl, Important
FROM notices
WHERE (IsActive IS NULL OR IsActive = 1)
ORDER BY CreatedDate DESC
```

This returns only active notices, ordered by creation date (newest first).

## Alternative Solutions

If the primary URL doesn't work, you can:

1. **Use the backup endpoint**: `https://eportal.kkcp.gov.bd/api/notices.php`
2. **Use the existing endpoint**: `https://eportal.kkcp.gov.bd/php/api/notices.php`
3. **Update WordPress code**:
   ```php
   $request = wp_remote_get( 'https://eportal.kkcp.gov.bd/php/api/notices.php' );
   ```
