<?php
include "../../classes/db.class.php";

$db = new DBMain();

$where_data = [];

$name = $_GET['name'];
if (strlen($name) >= 1) {
    $where_data[] = "name LIKE '%" . $name . "%'";
}

$username = $_GET['username'];
if (strlen($username) >= 1) {
    $where_data[] = "username LIKE '%" . $username . "%'";
}

$status = $_GET['status'];
if (strlen($status) >= 1 && $status != "STATUS") {
    $where_data[] = "status = " . $status;
}

$user_type = $_GET['user_type'];
if (strlen($user_type) >= 1 && $user_type != "USER TYPE") {
    $where_data[] = "user_type = " . $user_type;
}

if (count($where_data) > 0) {
    $where = " WHERE " . implode(" AND ", $where_data);
} else {
    $where = " WHERE 1";
}

$result = $db->conn->query("SELECT * FROM `users` $where ORDER BY record_id DESC");
if ($result->num_rows > 0) {
    while ($data = $result->fetch_assoc()) {
        echo "

        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
        <div class='flex_container'>
            <div class='flex_container_content'>
                <input type='text' readonly value='$data[name]' />
                <input type='text' readonly value='$data[username]' />
            </div>
            <div class='flex_container_content'>
                <input type='text' readonly value='$data[status]' />
                <input type='text' readonly value='$data[user_type]' />
                <input type='text' readonly value='$data[date_added]' />    
            </div>
            </div>
            <button onclick='edit_user($data[record_id])' style='width:100%; background-color: white;' class='font_size_2vw'>SELECT</button>
        </div>
        
        ";
    }
} else {

    echo "        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
        <h1> NO RESULTS </h1>
        </div>";
}
