<?php

include "../../root.class.php";

$html = new html();
$html->add_styles_page();

$client_name = new input();
$client_name->id("client_name");
$client_name->name("client_name");
$client_name->type("text");
$client_name->placeholder("Client Name");
$client_name->class();
$client_name->value_from_db("clients", "client_name", "record_id = {$_GET['record_id']}");
$client_name->required();

$client_email = new input();
$client_email->id("client_email");
$client_email->name("client_email");
$client_email->type("email");
$client_email->placeholder("Client Email");
$client_email->class();
$client_email->value_from_db("clients", "client_email", "record_id = {$_GET['record_id']}");
$client_email->required();

$client_address = new input();
$client_address->id("client_address");
$client_address->name("client_address");
$client_address->type("text");
$client_address->placeholder("Client Address");
$client_address->class();
$client_address->value_from_db("clients", "client_address", "record_id = {$_GET['record_id']}");
$client_address->required();

$client_contact = new input();
$client_contact->id("client_contact");
$client_contact->name("client_contact");
$client_contact->type("text");
$client_contact->placeholder("Client Contact");
$client_contact->class();
$client_contact->value_from_db("clients", "client_contact", "record_id = {$_GET['record_id']}");
$client_contact->required();

$price = new input();
$price->id("price");
$price->name("price");
$price->type("text");
$price->placeholder("Client Contact");
$price->class();
$price->value_from_db("clients", "price", "record_id = {$_GET['record_id']}");
$price->required();


$client_status = new select();
$client_status->id("client_status");
$client_status->name("client_status");
$client_status->class();
$client_status->add_option("", "STATUS");
$client_status->add_option("1", "Active");
$client_status->add_option("0", "Inactive");
$client_status->value_from_db("clients", "client_status", "record_id = {$_GET['record_id']}");
$client_status->required();

$company_id = new input();
$company_id->id("company_id");
$company_id->name("company_id");
$company_id->type("hidden");
$company_id->value($_SESSION['company_id']);
$company_id->class();

$record_id = new input();
$record_id->id("record_id");
$record_id->name("record_id");
$record_id->type("hidden");
$record_id->value($_GET['record_id']);
$record_id->class();

$rfid = new input();
$rfid->id("client_rfid_tag");
$rfid->name("client_rfid_tag");
$rfid->type("text");
$rfid->value_from_db("clients", "client_rfid_tag", "record_id = {$_GET['record_id']}");
$rfid->class();

$register_rfid = new button();
$register_rfid->id("register_rfid");
$register_rfid->name("register_rfid");
$register_rfid->value("CLICK TO REGISTER RFID");
$register_rfid->class();
$register_rfid->onclick("register_rfid()");

$add_client = new button();
$add_client->id("add_client");
$add_client->name("add_client");
$add_client->value("Edit Client");
$add_client->class();
$add_client->onclick("update_client()");


?>

<div class="form_down">
    <?php
    $record_id->add();
    echo "<label>Client Name</label>";
    $client_name->add();
    echo "<label>Client Email</label>";
    $client_email->add();
    echo "<label>Client Address</label>";
    $client_address->add();
    echo "<label>Client Contact</label>";
    $client_contact->add();
    echo "<label>Client Status</label>";
    $client_status->add();
    echo "<label>Rand Per Liter</label>";
    $price->add();
    echo "<label>RFID Tag</label>";
    $rfid->add();
    echo "<br>";
    $register_rfid->add();
    $company_id->add();
    echo "<br>";

    $add_client->add();
    ?>
</div>
<script>
    function register_rfid() {
        window.location.href = "register_rfid.php?record_id=<?php echo $_GET['record_id']; ?>";
    }
</script>
<?php



$ajax = new js_ajax();
$ajax->function_name("update_client");
$ajax->update("clients");
$ajax->on_success("CLIENT UPDATED SUCCESSFULLY");
$ajax->redirect("home.php");