# 📡 SmartPR Kiosk API Reference

> API Documentation สำหรับระบบ SmartPR Kiosk - วิทยาลัยการอาชีพปราสาท

**Base URL:** `https://ict.prasat.ac.th` หรือ `http://localhost/pr_web`

---

## 📋 Table of Contents

1. [Slideshow API](#slideshow-api)
2. [Contents API](#contents-api)
3. [Courses API](#courses-api)
4. [Events API](#events-api)
5. [Settings API](#settings-api)
6. [Upload API](#upload-api)

---

## 🖼️ Slideshow API

### GET `/api/slideshow.php`

ดึงรายการรูปภาพ Slideshow

**Query Parameters:**
- `id` (optional) - ดึงข้อมูล 1 รายการ
- `include_inactive` (optional) - รวมรายการที่ไม่ active (default: false)

**Response:**
```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "title": "ยินดีต้อนรับสู่วิทยาลัย",
      "description": "ภาพหน้าปกวิทยาลัย",
      "image_url": "https://ict.prasat.ac.th/uploads/slideshow/img1.jpg",
      "link_url": "https://prasat.ac.th",
      "display_order": 0,
      "status": "active",
      "created_at": "2025-01-15 10:00:00",
      "updated_at": "2025-01-15 10:00:00"
    }
  ],
  "message": "Slideshow retrieved successfully"
}
```

**Field Descriptions:**
- `title` - ชื่อรูปภาพ (สำหรับจัดการ)
- `description` - คำอธิบายเพิ่มเติม
- `image_url` - URL ของรูปภาพ (รองรับ HTTPS)
- `link_url` - ลิงก์เมื่อคลิกที่รูป (optional)
- `display_order` - ลำดับการแสดง (เลขน้อยแสดงก่อน)
- `status` - สถานะ: `active`, `inactive`

---

## 📰 Contents API

### GET `/api/contents.php`

ดึงรายการเนื้อหา/ข่าวสาร

**Query Parameters:**
- `id` (optional) - ดึงข้อมูล 1 รายการ
- `category` (optional) - กรองตามหมวดหมู่: `news`, `announcement`, `event`, `achievement`
- `status` (optional) - กรองตามสถานะ: `published`, `draft`, `archived` (default: published)
- `is_pinned` (optional) - กรองตามการปักหมุด: 0 หรือ 1
- `search` (optional) - ค้นหาในชื่อและคำอธิบาย
- `limit` (optional) - จำนวนรายการต่อหน้า (default: 20)
- `offset` (optional) - เริ่มต้นที่รายการที่ (default: 0)

**Response:**
```json
{
  "success": true,
  "data": {
    "items": [
      {
        "id": 1,
        "title": "เปิดรับสมัครนักศึกษาใหม่",
        "description": "เปิดรับสมัครนักศึกษาใหม่ ปีการศึกษา 2568",
        "content": "<p>รายละเอียดเพิ่มเติม...</p>",
        "category": "news",
        "status": "published",
        "image_url": "https://ict.prasat.ac.th/uploads/contents/img1.jpg",
        "video_url": null,
        "is_pinned": 1,
        "view_count": 150,
        "author_id": 1,
        "author_name": "ผู้ดูแลระบบ",
        "created_at": "2025-01-15 10:00:00",
        "updated_at": "2025-01-15 10:00:00",
        "published_at": "2025-01-15 10:00:00"
      }
    ],
    "pagination": {
      "total": 50,
      "page": 1,
      "limit": 20,
      "total_pages": 3
    }
  }
}
```

### POST `/api/contents.php?action=increment_view`

เพิ่มจำนวนการดู

**Request Body:**
```json
{
  "id": 1
}
```

---

## 🎓 Courses API

### GET `/api/courses.php`

ดึงรายการหลักสูตร

**Query Parameters:**
- `id` (optional) - ดึงข้อมูล 1 รายการพร้อม qualifications และ careers
- `level` (optional) - กรองตามระดับ: `ปวช.`, `ปวส.`
- `department` (optional) - กรองตามแผนก
- `search` (optional) - ค้นหา
- `limit` (optional) - จำนวนรายการต่อหน้า (default: 20)
- `offset` (optional) - เริ่มต้นที่รายการที่ (default: 0)

**Response (List):**
```json
{
  "success": true,
  "data": {
    "items": [
      {
        "id": 1,
        "code": "ICT001",
        "name": "เทคโนโลยีสารสนเทศ",
        "short_name": "ไอที",
        "level": "ปวส.",
        "department": "คอมพิวเตอร์",
        "description": "หลักสูตรด้านคอมพิวเตอร์และเทคโนโลยีสารสนเทศ",
        "image_url": "https://ict.prasat.ac.th/uploads/courses/ict.jpg",
        "duration": 2,
        "total_seats": 40,
        "available_seats": 15,
        "curriculum_year": "2566",
        "is_active": 1,
        "created_at": "2025-01-15 10:00:00",
        "updated_at": "2025-01-15 10:00:00"
      }
    ],
    "pagination": {
      "total": 10,
      "page": 1,
      "limit": 20,
      "total_pages": 1
    }
  }
}
```

**Response (Single with Details):**
```json
{
  "success": true,
  "data": {
    "id": 1,
    "code": "ICT001",
    "name": "เทคโนโลยีสารสนเทศ",
    "qualifications": [
      {
        "qualification": "จบ ม.6 หรือเทียบเท่า",
        "sort_order": 1
      },
      {
        "qualification": "GPA ไม่ต่ำกว่า 2.00",
        "sort_order": 2
      }
    ],
    "careers": [
      {
        "career_name": "โปรแกรมเมอร์",
        "sort_order": 1
      },
      {
        "career_name": "ผู้ดูแลระบบเครือข่าย",
        "sort_order": 2
      }
    ]
  }
}
```

---

## 📅 Events API

### GET `/api/events.php`

ดึงรายการกิจกรรม

**Query Parameters:**
- `id` (optional) - ดึงข้อมูล 1 รายการ
- `event_type` (optional) - กรองตามประเภท: `academic`, `sports`, `cultural`, `general`, `other`
- `status` (optional) - กรองตามสถานะ: `upcoming`, `ongoing`, `completed`, `cancelled` (default: upcoming, ongoing)
- `month` (optional) - กรองตามเดือน (format: YYYY-MM)
- `start_date` (optional) - วันที่เริ่มต้น (format: YYYY-MM-DD)
- `end_date` (optional) - วันที่สิ้นสุด (format: YYYY-MM-DD)
- `search` (optional) - ค้นหา
- `limit` (optional) - จำนวนรายการต่อหน้า (default: 20)
- `offset` (optional) - เริ่มต้นที่รายการที่ (default: 0)

**Response:**
```json
{
  "success": true,
  "data": {
    "items": [
      {
        "id": 1,
        "title": "งานวันไหว้ครู",
        "description": "กิจกรรมวันไหว้ครูประจำปี 2568",
        "event_type": "cultural",
        "start_date": "2025-06-16",
        "end_date": "2025-06-16",
        "start_time": "08:00:00",
        "end_time": "12:00:00",
        "location": "หอประชุมวิทยาลัย",
        "image_url": "https://ict.prasat.ac.th/uploads/events/event1.jpg",
        "organizer_name": "วิทยาลัยการอาชีพปราสาท",
        "contact_info": "044-xxx-xxx",
        "max_participants": 500,
        "current_participants": 0,
        "status": "upcoming",
        "created_at": "2025-01-15 10:00:00",
        "updated_at": "2025-01-15 10:00:00"
      }
    ],
    "pagination": {
      "total": 20,
      "page": 1,
      "limit": 20,
      "total_pages": 1
    }
  }
}
```

**Field Descriptions:**
- `event_type` - ประเภทกิจกรรม
  - `academic` - วิชาการ
  - `sports` - กีฬา
  - `cultural` - วัฒนธรรม
  - `general` - ทั่วไป
  - `other` - อื่นๆ
- `start_date`, `end_date` - วันที่เริ่มต้นและสิ้นสุด
- `start_time`, `end_time` - เวลาเริ่มต้นและสิ้นสุด (optional)
- `max_participants` - จำนวนผู้เข้าร่วมสูงสุด (null = ไม่จำกัด)
- `current_participants` - จำนวนผู้ลงทะเบียนปัจจุบัน
- `status` - สถานะ
  - `upcoming` - กำลังจะมาถึง
  - `ongoing` - กำลังดำเนินการ
  - `completed` - เสร็จสิ้น
  - `cancelled` - ยกเลิก

---

## ⚙️ Settings API

### GET `/api/settings.php`

ดึงการตั้งค่าระบบ

**Query Parameters:**
- `key` (optional) - ดึงค่าตั้งค่าเดียว

**Response (All):**
```json
{
  "success": true,
  "data": [
    {
      "setting_key": "school_name",
      "setting_value": "วิทยาลัยการอาชีพปราสาท",
      "description": "ชื่อสถานศึกษา",
      "updated_at": "2025-01-15 10:00:00"
    },
    {
      "setting_key": "slideshow_interval",
      "setting_value": "5",
      "description": "ระยะเวลาแสดง Slideshow (วินาที)",
      "updated_at": "2025-01-15 10:00:00"
    }
  ]
}
```

**Response (Single Key):**
```json
{
  "success": true,
  "data": {
    "setting_key": "school_name",
    "setting_value": "วิทยาลัยการอาชีพปราสาท",
    "description": "ชื่อสถานศึกษา",
    "updated_at": "2025-01-15 10:00:00"
  }
}
```

---

## 📤 Upload API

### POST `/api/upload.php`

อัพโหลดรูปภาพ

**Request (multipart/form-data):**
- `image` - ไฟล์รูปภาพ (required)
- `folder` - โฟลเดอร์ปลายทาง: `images`, `slideshow`, `contents`, `courses`, `events` (default: images)

**Response:**
```json
{
  "success": true,
  "data": {
    "url": "https://ict.prasat.ac.th/uploads/slideshow/20250115_100000_abc123.jpg",
    "path": "/uploads/slideshow/20250115_100000_abc123.jpg",
    "filename": "20250115_100000_abc123.jpg",
    "size": 245678
  },
  "message": "Upload successful"
}
```

**Supported Formats:**
- Image: JPG, JPEG, PNG, GIF, WebP
- Max Size: 10MB

---

## 🔒 Error Responses

**Standard Error Format:**
```json
{
  "success": false,
  "error": "Error message here",
  "code": 400
}
```

**HTTP Status Codes:**
- `200` - Success
- `400` - Bad Request (ข้อมูลไม่ครบหรือไม่ถูกต้อง)
- `404` - Not Found (ไม่พบข้อมูล)
- `405` - Method Not Allowed
- `500` - Internal Server Error

---

## 📝 Notes

### CORS Support
API รองรับ CORS สำหรับการเรียกใช้จาก Domain อื่น

### Authentication (Coming Soon)
ปัจจุบัน API ยังไม่ต้องใช้ Authentication สำหรับ GET requests  
แต่ POST/PUT/DELETE จะต้องใช้ token ในอนาคต

### Rate Limiting
ยังไม่มีการจำกัดจำนวน requests ต่อนาที

### Caching
แนะนำให้ใช้ cache ในฝั่ง client สำหรับข้อมูลที่ไม่เปลี่ยนแปลงบ่อย เช่น:
- Settings (cache 1 ชั่วโมง)
- Courses (cache 30 นาที)
- Slideshow (cache 10 นาที)

---

## 🚀 Quick Start

### ทดสอบ API ด้วย cURL

```bash
# Get Slideshow
curl "https://ict.prasat.ac.th/api/slideshow.php"

# Get News
curl "https://ict.prasat.ac.th/api/contents.php?category=news&limit=10"

# Get Courses
curl "https://ict.prasat.ac.th/api/courses.php?level=ปวส."

# Get Upcoming Events
curl "https://ict.prasat.ac.th/api/events.php?status=upcoming"

# Get Settings
curl "https://ict.prasat.ac.th/api/settings.php"
```

### ทดสอบ API ด้วย JavaScript

```javascript
// Fetch Slideshow
const response = await fetch('https://ict.prasat.ac.th/api/slideshow.php');
const data = await response.json();

if (data.success) {
  console.log('Slideshow:', data.data);
}
```

---

**เอกสารนี้อัพเดทล่าสุด:** 8 พฤศจิกายน 2568  
**เวอร์ชัน API:** 1.0.0  
**สถานะ:** ✅ ใช้งานได้

**ติดต่อสอบถาม:**
- Email: admin@prasat.ac.th
- Website: https://prasat.ac.th
