<?

include $_SERVER['DOCUMENT_ROOT'] . "/WebBuilder/WebApp.class.php";
$db = new DBMain();

$WebApp->pageHeading('EDIT CLIENT');

$clients_res = $db->exec_query('clients', ['*'], '', '', '', '', "record_id = {$_GET['record_id']}");
$client_data = $clients_res->fetch_assoc();

$provinces_res = $db->exec_query('provinces', ['*'], '', '', '', '', "1", "ORDER BY provinces_name ASC");

$provinces_data = "<option value=''></option>";
while ($provinces_all = $provinces_res->fetch_assoc()) {
    $selected = ($provinces_all['record_id'] == $client_data['provinces_id']) ? 'selected' : '';
    $provinces_data = $provinces_data . "<option $selected value='{$provinces_all['record_id']}'>{$provinces_all['provinces_name']}</option>";
}

// $WebApp->form_input_edit_single('clients', $_GET['record_id'], 'search_client.php');
?>


<div class="form_container">
    <form action="update_client.ajax.php" method="post" enctype="multipart/form-data">
        <div style="display: flex; flex-direction: column;">
            <input type="text" id="record_id" name="record_id" value="<?php echo $_GET['record_id'] ?>" hidden>
            <label for="" class="label">CLIENTS NAME</label>
            <input type="text" name="clients_name" id="clients_name" class="input"
                value="<?php echo $client_data['clients_name']; ?>" />
        </div>
        <div style="display: flex; flex-direction: column;">
            <label for="" class="label">PROVINCES</label>
            <select aria-labelledby='my-select-label' name="provinces_id" id="provinces_id" class="select">
                <?php echo $provinces_data; ?>
            </select>
        </div>
        <div style="display: flex; flex-direction: column;">
            <label for="email" class="label">EMAIL</label>
            <input type="text" name="email" id="email" class="input" value="<?php echo $client_data['email']; ?>" />
        </div>
        <div style="display: flex; flex-direction: column;">
            <label for="" class="label">PHONE</label>
            <input type="" name="phone" id="phone" class="input" value="<?php echo $client_data['phone']; ?>" />
        </div>
        <div style="display: flex; flex-direction: column;">
            <label for="" class="label">ADDRESS</label>
            <input type="text" name="address" id="address" class="input"
                value="<?php echo $client_data['address']; ?>" />
        </div>
        <div style="display: flex; flex-direction: column;">
            <label for="client_code_label" class="label">CLIENT CODE</label>
            <input type="text" name="client_code" id="client_code" class="input"
                value="<?php echo $client_data['client_code']; ?>" />
        </div>

        <div style='display:flex; flex-direction:column'>
            <label class='label'>CLIENT LOGO</label>
            <input class='input' type='file' name='client_logo' id='client_logo'>
        </div>
        <div>
            <button class="button">UPDATE</button>
        </div>

    </form>
</div>