# Koha Subscription Management System

Tested and working. Yeh 42 clients ke saath ready hai. Deploy karne ke steps neeche hain.

## Files

| File | Kya karta hai |
|---|---|
| `schema.sql` | Database + table + 42 clients + default admin login |
| `db.php` | Database connection (isme apna DB username/password daalna hai) |
| `api.php` | Public API — Koha se yahi call hoga subscription check karne ke liye |
| `admin/login.php` | Tumhara login page |
| `admin/dashboard.php` | Tumhara management dashboard (dates, price, status update) |
| `admin/logout.php` | Logout |

## Deploy karne ke steps (apne server pe)

### 1. Database banao
```bash
mysql -u root -p < schema.sql
```
Ye `koha_clients_db` database bana dega, `clients` table (42 rows ke saath), aur `admin_users` table.

### 2. `db.php` mein apni real DB credentials daalo
```php
$db_username = "your_actual_db_user";
$db_password = "your_actual_db_password";
```

### 3. Files upload karo apne web server pe
Poora `koha_subscription_system` folder apne server ke web-accessible directory mein daal do
(e.g. `/var/www/subscription-manager/`), taaki ye accessible ho jaye:
```
https://yourdomain.com/subscription-manager/api.php
https://yourdomain.com/subscription-manager/admin/login.php
```

### 4. Admin login
- URL: `https://yourdomain.com/subscription-manager/admin/login.php`
- Username: `admin`
- Password: `admin123`

**⚠️ IMPORTANT: Pehle login ke baad password zaroor badlo.** Naya hash generate karne ke liye:
```bash
php -r "echo password_hash('YOUR_NEW_PASSWORD', PASSWORD_BCRYPT);"
```
Phir dashboard se ya seedha SQL se `admin_users` table mein `password_hash` update kar do:
```sql
UPDATE admin_users SET password_hash='NAYA_HASH_YAHAN' WHERE username='admin';
```

### 5. Test karo API
```
https://yourdomain.com/subscription-manager/api.php?client_key=naavustaff.bestbookbuddies.com
```
Response aana chahiye:
```json
{"library_name":"Naavu School Bengaluru, Karnataka 560066","start_date":"2027-01-01","end_date":"2027-01-01","days_left":169,"status":"active"}
```

### 6. Dates aur price bharo
Dashboard mein login karke har client ki:
- Start Date (calendar picker)
- End Date (calendar picker)
- Price
- Status (active/expired/suspended)

update kar do. "Add New Client" button se naya client bhi add kar sakte ho.

## Koha side integration (agla step)

Ab jab API ready hai, Koha ke `header.inc` (ya `IntranetUserJS`) mein ye JS daalna hai jo
`window.location.hostname` se apna client_key detect karega aur API se check karega — agar
expired hai to poori screen block ho jayegi "please renew" message ke saath.

Yeh JS code humne pehle discuss kiya hai — agla step mein isko final version mein de dunga,
jisme dropdown notification + full-page block + login-page block teeno shaamil honge.

## Security notes

- `admin/` folder ko `.htaccess` se protect karna (extra layer) recommended hai
- `api.php` sirf GET/read-only hai — koi write endpoint publicly expose nahi kiya
- Production mein `Access-Control-Allow-Origin: *` ko apne Koha domains tak limit karo
