# 🎨 คู่มือการใช้งาน AdminLTE Theme สำหรับ PHP 5.6.40

## 📋 ภาพรวม

AdminLTE Theme ที่ใช้ในระบบ STKT ได้รับการปรับให้รองรับ **PHP 5.6.40** และเบราว์เซอร์สมัยใหม่ โดยใช้:

- **AdminLTE 3.x** - Admin dashboard template
- **Bootstrap 4.6** - CSS framework  
- **jQuery 3.5.1+** - JavaScript library
- **FontAwesome 5** - Icon library
- **Sarabun Font** - ฟอนต์ไทยที่สวยงาม

---

## 📁 โครงสร้างไฟล์ Theme

```
theme/
├── dist/                    # ไฟล์ที่ compile แล้ว
│   ├── css/
│   │   └── adminlte.min.css    # Main CSS file ⭐
│   └── js/
│       └── adminlte.js         # Main JS file ⭐
├── plugins/                 # External plugins
│   ├── jquery/
│   ├── bootstrap/
│   ├── fontawesome-free/
│   ├── datatables/
│   ├── chart.js/
│   ├── daterangepicker/
│   ├── summernote/
│   ├── select2/
│   └── sweetalert2/
├── fonts/                   # ฟอนต์ไทย
│   ├── Sarabun.css         # Sarabun font CSS ⭐
│   └── tawan.css           # Alternative Thai font
└── docs/                   # เอกสารประกอบ
```

---

## 🔧 การ Setup Theme

### 1. การ Include CSS ในหน้า HTML

```php
<!-- includes/header.php -->
<!DOCTYPE html>
<html lang="th">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  
  <!-- FontAwesome -->
  <link rel="stylesheet" href="../theme/plugins/fontawesome-free/css/all.min.css">
  
  <!-- AdminLTE CSS -->
  <link rel="stylesheet" href="../theme/dist/css/adminlte.min.css">
  
  <!-- DataTables -->
  <link rel="stylesheet" href="../theme/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  
  <!-- Thai Font -->
  <link rel="stylesheet" href="../theme/fonts/Sarabun.css">
  
  <style>
    body {
      font-family: 'Sarabun', sans-serif;
    }
  </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
```

### 2. การ Include JavaScript ในหน้า HTML

```php
<!-- includes/footer.php -->

<!-- jQuery -->
<script src="../theme/plugins/jquery/jquery.min.js"></script>

<!-- Bootstrap 4 -->
<script src="../theme/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- DataTables -->
<script src="../theme/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../theme/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>

<!-- AdminLTE -->
<script src="../theme/dist/js/adminlte.js"></script>

<script>
$(function () {
  // DataTables with Thai language
  $('.table').DataTable({
    "responsive": true,
    "lengthChange": false,
    "autoWidth": false,
    "language": {
      "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Thai.json"
    }
  });
});
</script>

</body>
</html>
```

---

## 🎨 การใช้งาน Components

### 1. Layout Structure

```html
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
  
  <!-- Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- Navbar content -->
  </nav>
  
  <!-- Main Sidebar -->
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Sidebar content -->
  </aside>
  
  <!-- Content Wrapper -->
  <div class="content-wrapper">
    <!-- Page header -->
    <div class="content-header">
      <div class="container-fluid">
        <h1 class="m-0">หน้าหลัก</h1>
      </div>
    </div>
    
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Your content here -->
      </div>
    </section>
  </div>
  
  <!-- Footer -->
  <footer class="main-footer">
    <!-- Footer content -->
  </footer>
  
</div>
</body>
```

### 2. Cards (การ์ด)

```html
<!-- Info Box -->
<div class="info-box">
  <span class="info-box-icon bg-info"><i class="far fa-envelope"></i></span>
  <div class="info-box-content">
    <span class="info-box-text">จำนวนผู้สมัคร</span>
    <span class="info-box-number">1,410</span>
  </div>
</div>

<!-- Card -->
<div class="card">
  <div class="card-header">
    <h3 class="card-title">ข้อมูลผู้สมัคร</h3>
  </div>
  <div class="card-body">
    <!-- Card content -->
  </div>
</div>
```

### 3. DataTables

```html
<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>ชื่อ</th>
      <th>นามสกุล</th>
      <th>โรงเรียน</th>
      <th>สถานะ</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($applicants as $applicant): ?>
    <tr>
      <td><?php echo sanitize($applicant['first_name']); ?></td>
      <td><?php echo sanitize($applicant['last_name']); ?></td>
      <td><?php echo sanitize($applicant['school_name']); ?></td>
      <td>
        <span class="badge badge-success">อนุมัติแล้ว</span>
      </td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<script>
$(function () {
  $('.table').DataTable({
    "responsive": true,
    "pageLength": 25,
    "language": {
      "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Thai.json"
    }
  });
});
</script>
```

### 4. Forms

```html
<form method="POST">
  <div class="form-group">
    <label for="first_name">ชื่อ</label>
    <input type="text" class="form-control" id="first_name" name="first_name" required>
  </div>
  
  <div class="form-group">
    <label for="school_name">โรงเรียน</label>
    <select class="form-control select2" id="school_name" name="school_name">
      <option value="">เลือกโรงเรียน</option>
      <option value="school1">โรงเรียนตัวอย่าง 1</option>
    </select>
  </div>
  
  <div class="form-group">
    <button type="submit" class="btn btn-primary">
      <i class="fas fa-save"></i> บันทึก
    </button>
  </div>
</form>

<script>
$(function () {
  // Initialize Select2
  $('.select2').select2({
    theme: 'bootstrap4'
  });
});
</script>
```

### 5. Alerts และ Notifications

```html
<!-- Alert Messages -->
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <i class="icon fas fa-check"></i>
  <?php echo $_SESSION['message']; ?>
</div>
<?php unset($_SESSION['message'], $_SESSION['message_type']); ?>
<?php endif; ?>

<!-- SweetAlert2 -->
<script>
function showSuccess(message) {
  Swal.fire({
    icon: 'success',
    title: 'สำเร็จ!',
    text: message,
    confirmButtonText: 'ตกลง'
  });
}

function showError(message) {
  Swal.fire({
    icon: 'error',
    title: 'เกิดข้อผิดพลาด!',
    text: message,
    confirmButtonText: 'ตกลง'
  });
}
</script>
```

---

## 🎨 การปรับแต่ง CSS

### 1. ฟอนต์ไทย

```css
/* ใน header หรือ custom CSS */
<style>
body {
  font-family: 'Sarabun', sans-serif;
}

.thai-text {
  font-family: 'Sarabun', sans-serif;
  font-weight: 400;
}

.thai-header {
  font-family: 'Sarabun', sans-serif;
  font-weight: 600;
}
</style>
```

### 2. สีและธีมที่กำหนดเอง

```css
/* Custom colors */
.bg-primary-custom {
  background-color: #1e3a8a !important;
}

.text-primary-custom {
  color: #1e3a8a !important;
}

/* Custom card styles */
.card-custom {
  border-left: 4px solid #1e3a8a;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
```

### 3. Responsive Design

```css
/* Mobile optimizations */
@media (max-width: 768px) {
  .content-wrapper {
    margin-left: 0;
  }
  
  .main-sidebar {
    margin-left: -250px;
  }
  
  .table-responsive {
    font-size: 0.9em;
  }
}
```

---

## 🔌 การใช้งาน Plugins

### 1. Chart.js สำหรับกราฟ

```html
<!-- Include Chart.js -->
<script src="../theme/plugins/chart.js/Chart.min.js"></script>

<div class="card">
  <div class="card-header">
    <h3 class="card-title">สถิติการสมัคร</h3>
  </div>
  <div class="card-body">
    <canvas id="applicantsChart" width="400" height="200"></canvas>
  </div>
</div>

<script>
$(function () {
  var ctx = document.getElementById('applicantsChart').getContext('2d');
  var chart = new Chart(ctx, {
    type: 'bar',
    data: {
      labels: ['ม.1', 'ม.2', 'ม.3', 'ม.4', 'ม.5', 'ม.6'],
      datasets: [{
        label: 'จำนวนผู้สมัคร',
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: 'rgba(54, 162, 235, 0.5)',
        borderColor: 'rgba(54, 162, 235, 1)',
        borderWidth: 1
      }]
    },
    options: {
      responsive: true,
      scales: {
        y: {
          beginAtZero: true
        }
      }
    }
  });
});
</script>
```

### 2. DateRangePicker สำหรับเลือกวันที่

```html
<!-- Include DateRangePicker -->
<link rel="stylesheet" href="../theme/plugins/daterangepicker/daterangepicker.css">
<script src="../theme/plugins/moment/moment.min.js"></script>
<script src="../theme/plugins/daterangepicker/daterangepicker.js"></script>

<div class="form-group">
  <label>ช่วงวันที่สมัคร</label>
  <input type="text" class="form-control" id="daterange">
</div>

<script>
$(function () {
  $('#daterange').daterangepicker({
    locale: {
      format: 'DD/MM/YYYY',
      separator: ' - ',
      applyLabel: 'ยืนยัน',
      cancelLabel: 'ยกเลิก',
      fromLabel: 'จาก',
      toLabel: 'ถึง',
      daysOfWeek: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],
      monthNames: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน',
                   'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม']
    }
  });
});
</script>
```

### 3. Summernote สำหรับ Rich Text Editor

```html
<!-- Include Summernote -->
<link rel="stylesheet" href="../theme/plugins/summernote/summernote-bs4.min.css">
<script src="../theme/plugins/summernote/summernote-bs4.min.js"></script>

<div class="form-group">
  <label>รายละเอียด</label>
  <textarea class="form-control summernote" name="description"></textarea>
</div>

<script>
$(function () {
  $('.summernote').summernote({
    height: 200,
    lang: 'th-TH',
    toolbar: [
      ['style', ['style']],
      ['font', ['bold', 'underline', 'clear']],
      ['color', ['color']],
      ['para', ['ul', 'ol', 'paragraph']],
      ['table', ['table']],
      ['insert', ['link']],
      ['view', ['fullscreen', 'codeview', 'help']]
    ]
  });
});
</script>
```

---

## 📱 Responsive Design

### Breakpoints
- **xs**: < 576px (มือถือ)
- **sm**: ≥ 576px (มือถือขนาดใหญ่)
- **md**: ≥ 768px (แท็บเล็ต)
- **lg**: ≥ 992px (เดสก์ท็อป)
- **xl**: ≥ 1200px (หน้าจอใหญ่)

### การใช้งาน Classes
```html
<!-- Responsive columns -->
<div class="row">
  <div class="col-12 col-md-6 col-lg-4">
    <!-- Column 1 -->
  </div>
  <div class="col-12 col-md-6 col-lg-8">
    <!-- Column 2 -->
  </div>
</div>

<!-- Responsive utilities -->
<div class="d-none d-md-block">แสดงเฉพาะใน tablet+</div>
<div class="d-block d-md-none">แสดงเฉพาะใน mobile</div>
```

---

## 🔧 การแก้ไขปัญหาที่พบบ่อย

### 1. ฟอนต์ไทยไม่แสดง
```css
/* ตรวจสอบการ include ฟอนต์ */
<link rel="stylesheet" href="../theme/fonts/Sarabun.css">

/* กำหนดฟอนต์สำรอง */
body {
  font-family: 'Sarabun', 'Tahoma', sans-serif;
}
```

### 2. DataTables ไม่แสดงภาษาไทย
```javascript
$('.table').DataTable({
  "language": {
    "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Thai.json"
  }
});
```

### 3. Icons ไม่แสดง
```html
<!-- ตรวจสอบการ include FontAwesome -->
<link rel="stylesheet" href="../theme/plugins/fontawesome-free/css/all.min.css">

<!-- ใช้ class ที่ถูกต้อง -->
<i class="fas fa-user"></i> <!-- Solid -->
<i class="far fa-envelope"></i> <!-- Regular -->
<i class="fab fa-facebook"></i> <!-- Brands -->
```

### 4. JavaScript ไม่ทำงาน
```javascript
// ตรวจสอบว่า jQuery load ก่อน
$(document).ready(function() {
  // Your code here
});

// หรือใช้
$(function () {
  // Your code here
});
```

---

## 📊 Performance Tips

### 1. การโหลด CSS/JS
```html
<!-- โหลด critical CSS ก่อน -->
<link rel="stylesheet" href="../theme/dist/css/adminlte.min.css">

<!-- โหลด JavaScript ที่ท้ายหน้า -->
<script src="../theme/plugins/jquery/jquery.min.js"></script>
```

### 2. การใช้ CDN (ไม่บังคับ)
```html
<!-- jQuery CDN fallback -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
  document.write('<script src="../theme/plugins/jquery/jquery.min.js"><\/script>');
}
</script>
```

### 3. การ Minify และ Optimize
- ใช้ไฟล์ `.min.css` และ `.min.js`
- รวม CSS/JS หลายไฟล์เป็นไฟล์เดียว (ถ้าจำเป็น)
- ใช้ browser caching

---

## ✅ Checklist การใช้งาน

- [ ] Include jQuery ก่อน plugins อื่นๆ
- [ ] Include Bootstrap ก่อน AdminLTE
- [ ] กำหนดฟอนต์ไทย Sarabun
- [ ] ใช้ responsive classes สำหรับ mobile
- [ ] ตรวจสอบ console ใน browser สำหรับ errors
- [ ] ทดสอบใน mobile devices
- [ ] ตรวจสอบการทำงานของ DataTables
- [ ] ทดสอบ forms และ validation

---

## 📚 Resources

### เอกสารอ้างอิง
- [AdminLTE Documentation](https://adminlte.io/docs)
- [Bootstrap 4 Documentation](https://getbootstrap.com/docs/4.6/)
- [jQuery Documentation](https://api.jquery.com/)
- [FontAwesome Icons](https://fontawesome.com/icons)

### การตรวจสอบ
```
# ตรวจสอบ Theme compatibility
http://localhost/stkt/theme/check_theme_compatibility.php

# ตรวจสอบระบบทั้งหมด
http://localhost/stkt/check_compatibility.php
```

---

**สถานะ**: ✅ พร้อมใช้งานกับ PHP 5.6.40  
**ธีม**: AdminLTE 3.x  
**การรองรับ**: Responsive, Multi-browser, Thai fonts