MINI MINI MANI MO

Path : /home/auto2501/www/mainimg/
File Upload :
Current File : /home/auto2501/www/mainimg/skrc.php

<?php

// 1. إعدادات عرض الأخطاء
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// ضبط ترويسة الصفحة
header('Content-Type: text/html; charset=utf-8');

// 2. بيانات الاتصال (skrcauto)
$servername = "localhost";
$username = "auto2501";
$password = "q1w2e3r4";
$dbname = "auto2501";

// إنشاء الاتصال
$conn = new mysqli($servername, $username, $password, $dbname);

// التحقق من الاتصال
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// ضبط الترميز
$conn->set_charset("euckr");

$filter_date = '';

// 3. بناء الاستعلام (تمت إضافة wc_age هنا لنتمكن من استخدامه)
$sql_columns = "wc_regdate, wc_acc_date, wc_age, wc_model2, wc_damage";

// حلقة لإضافة الأعمدة من 1 إلى 120
for ($i = 1; $i <= 120; $i++) {
    $sql_columns .= ", wc_img_" . $i;
}

$sql = "SELECT " . $sql_columns . " FROM woojung_car WHERE 1=1";

// --- التعديل الجوهري هنا ---
// تم تغيير الفلترة لتعتمد على wc_age بدلاً من wc_acc_date
// نفترض أن wc_age تبدأ بالسنة (مثل 2019...) لذا نأخذ أول 4 خانات
$sql .= " AND SUBSTRING(wc_age, 1, 4) >= '2018'";

// شرط فلتر التاريخ (إذا تم اختياره)
if (isset($_GET['filter_date']) && !empty($_GET['filter_date'])) {
    $filter_date = $_GET['filter_date'];
    $sanitized_date = $conn->real_escape_string($filter_date);
    $sql .= " AND DATE(wc_regdate) = '" . $sanitized_date . "'";
}

// تنفيذ الاستعلام
$result = $conn->query($sql);

// التحقق من الأخطاء
if (!$result) {
    die("<div style='color:red; background:#fff0f0; padding:20px; border:1px solid red; margin:20px;'>
            <strong>SQL Error:</strong> " . $conn->error . "<br><br>
            تأكد من أن العمود <strong>wc_age</strong> موجود في قاعدة البيانات.<br>
            وتأكد من وجود أعمدة الصور حتى 120.
         </div>");
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SKRC Auto Listings (By Age)</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body { font-family: 'Inter', sans-serif; background-color: #f3f4f6; padding: 20px; }
        .container { max-width: 1200px; margin: 0 auto; background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); overflow: hidden; }
        table { width: 100%; border-collapse: collapse; table-layout: fixed; }
        th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #e5e7eb; word-wrap: break-word; }
        th { background-color: #1f2937; color: #ffffff; font-weight: 600; text-transform: uppercase; font-size: 0.85rem; }
        tr:nth-child(even) { background-color: #f9fafb; }
        tr:hover { background-color: #eef2ff; }
        .image-link { color: #3b82f6; text-decoration: none; word-break: break-all; display: block; margin-bottom: 4px; font-size: 0.8rem;}
        .image-link:hover { text-decoration: underline; }
        .details-cell { white-space: pre-wrap; }
        .filter-form { padding: 20px; background-color: #f9fafb; border-bottom: 1px solid #e5e7eb; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
        th:nth-child(4), td:nth-child(4) { width: 40%; }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="text-2xl font-bold text-gray-800 p-6 border-b border-gray-200">SKRC Auto Listings (2018+)</h1>

        <div class="filter-form">
            <form action="" method="GET">
                <label for="filter_date" class="mr-2">Filter by Publish Date:</label>
                <input type="date" id="filter_date" name="filter_date" value="<?php echo htmlspecialchars($filter_date); ?>" class="p-2 border rounded">
                <button type="submit" class="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">Apply</button>
                <button type="reset" onclick="window.location.href='<?php echo basename($_SERVER['PHP_SELF']); ?>'" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">Clear</button>
            </form>
        </div>

        <?php
        if ($result && $result->num_rows > 0) {
            echo "<table id='carTable'>";
            echo "<thead>";
            echo "<tr>";
            echo "<th style='width: 10%'>Publish Date</th>";
            echo "<th style='width: 10%'>Model Year (Age)</th>"; // تحديث العنوان
            echo "<th style='width: 15%'>Model Name</th>";
            echo "<th style='width: 40%'>Photos</th>";
            echo "<th style='width: 25%'>Details</th>";
            echo "</tr>";
            echo "</thead>";
            echo "<tbody>";

            while($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>" . htmlspecialchars(mb_convert_encoding($row["wc_regdate"], 'UTF-8', 'EUC-KR')) . "</td>";
                
                // هنا نعرض wc_age بدلاً من wc_acc_date
                echo "<td>" . htmlspecialchars(mb_convert_encoding($row["wc_age"], 'UTF-8', 'EUC-KR')) . "</td>";
                
                echo "<td class='model-name-cell'>" . htmlspecialchars(mb_convert_encoding($row["wc_model2"], 'UTF-8', 'EUC-KR')) . "</td>";
                echo "<td>";
                
                $image_base_url = "https://autobidkorea.co.kr//data/";
                
                for ($i = 1; $i <= 120; $i++) {
                    $img_col = "wc_img_" . $i;
                    
                    if (!empty($row[$img_col])) {
                        $converted_filename = mb_convert_encoding($row[$img_col], 'UTF-8', 'EUC-KR');
                        $image_url = $image_base_url . $converted_filename;
                        
                        echo "<a href='" . htmlspecialchars($image_url) . "' target='_blank' class='image-link'>";
                        echo "Image $i: " . htmlspecialchars($converted_filename);
                        echo "</a>";
                    } else {
                        break; 
                    }
                }
                echo "</td>";
                echo "<td class='details-cell'>" . nl2br(htmlspecialchars(mb_convert_encoding($row["wc_damage"], 'UTF-8', 'EUC-KR'))) . "</td>";
                echo "</tr>";
            }
            echo "</tbody>";
            echo "</table>";
        } else {
            echo "<p class='p-6 text-gray-600'>No cars found for the selected criteria (wc_age >= 2018).</p>";
            if ($result) {
                 echo "<p class='px-6 text-sm text-gray-400'>Query executed successfully but returned 0 rows.</p>";
            }
        }

        $conn->close();
        ?>
    </div>
</body>
</html>

OHA YOOOO