<?php
include "db.class.php";

$db = new DBMain();

$where_data = [];

if (strlen($_POST['jobccard']) >= 1) {
    $where_data[] = "jobcard_number = '" . $_POST['jobccard']."'";
}

if (strlen($_POST['artist']) >= 1) {
    $where_data[] = "artist_name LIKE '%" . $_POST['artist'] . "%'";
}

if (strlen($_POST['sculpture']) >= 1) {
    $where_data[] = "sculpture_name LIKE '%" . $_POST['sculpture'] . "%'";
}

if (strlen($_POST['account_number']) >= 1) {
    $where_data[] = "account_no LIKE '%" . $_POST['account_number'] . "%'";
}

if (strlen($_POST['date']) >= 1) {
    $where_data[] = "jobcard_date LIKE '%" . $_POST['date'] . "%'";
}   

if (count($where_data) > 0) {
    $where = implode(" OR ", $where_data);
}else{
    $where = '1';
}

$results = $db->exec_query('jobcards', ['*'], '', '', '', '', $where , 'ORDER BY record_id DESC LIMIT 100');

?>
<style>
    .apple-form {
        display: flex;
        flex-direction: column;
        align-items: center;
        font-family: 'Arial', sans-serif;
        width: 80%;
        border: #007AFF 1px solid;
        border-radius: 25px;
        margin-left: auto;
        padding: 5vw;
        margin-right: auto;
    }

    .form-group {
        display: flex;
        flex-direction: column;
        margin-bottom: 10px;
        width: 700px;
        margin-left: auto;
        margin-right: auto;
        flex-wrap: wrap;
        background-color: whitesmoke;
        border-radius: 10px;
        padding: 10px;
    }

    .form-group label {
        margin-bottom: 5px;
    }

    .form-group input {
        padding: 10px 20px;
        border: none;
        border-radius: 5px;
        background-color: #007AFF;
        color: #fff;
        cursor: pointer;
        margin-top: 10px;
        width: 100%;
    }

    .form-group select {
        padding: 5px;
        border: 1px solid #ccc;
        border-radius: 5px;
        width: 100%;
        max-width: 300px;
    }

    .form-group textarea {
        padding: 5px;
        border: 1px solid #ccc;
        border-radius: 5px;
        width: 100%;
        max-width: 300px;
    }

    .form-group button {
        padding: 10px 20px;
        border: none;
        border-radius: 5px;
        background-color: #007AFF;
        color: #fff;
        cursor: pointer;
        margin-top: 10px;
    }

    h1 {
        display: flex;
        justify-content: center;
        font-size: 50px;
    }

    h2 {
        font-size: 30px;
    }

    .apple-form input[type=submit] {
        padding: 10px 20px;
        border: none;
        border-radius: 5px;
        background-color: #007AFF;
        color: #fff;
        cursor: pointer;
        margin-top: 10px;
    }

    @media (max-width: 480px) {
        .apple-form {
            flex-direction: column;
        }

        .form-group {
            margin-bottom: 5px;
        }
    }
</style>
<br>
<style>
    .back_btn {
        position: absolute;
        left: 1%;
        top: 1%;
        width: 25%;
        height: fit-content;
        background-color: #007AFF;
        color: #fff;
        border-radius: 10px;
        padding: 1%;
        text-align: center;
    }
</style>
<a href='search_jobcard.php'>
    <div class='back_btn'>
        BACK
    </div>
</a>
<h1>RESULTS</h1>
<?php while ($jobcards = $results->fetch_assoc()) { ?>
    <div class="form-group" style="border: #007AFF 1px solid;">
        <form action="edit_jobcard.php" method="POST">
            <h2>JOBCARD NUMBER : <?php echo $jobcards['jobcard_number']; ?></h2>
            <h2>SCULPTURE NAME : <?php echo $jobcards['sculpture_name']; ?></h>
                <h2>ARTIST NAME : <?php echo $jobcards['artist_name']; ?></h2>
                <input type='text' name='record_id' value='<?php echo $jobcards['record_id']; ?>' hidden>
                <input type='submit' value='OPEN'>
        </form>

    </div>
    <br>

<?php } ?>