<?php

include "../../root.class.php";
include "../../html.class.php";
include "../../classes/db.class.php";

$html = new html();

$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();


$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();

$reports = new select();
$reports->id("exclude_from_reports");
$reports->name("exclude_from_reports");
$reports->class();
$reports->add_option("", "");
$reports->add_option("1", "YES");
$reports->add_option("0", "NO");
$reports->value_from_db("clients", "exclude_from_reports", "record_id = {$_GET['record_id']}");
$reports->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("app_buttons");
$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("app_buttons");
$add_client->onclick("update_client()");

$delete_client = new button();
$delete_client->id("add_client");
$delete_client->name("add_client");
$delete_client->value("DELETE");
$delete_client->class("app_buttons");
$delete_client->onclick("delete_client()");
?>
< <div class=" tank_item_container 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>RFID Tag</label>";
    $rfid->add();
    echo "<label>Exclude From Reports</label>";
    $reports->add();
    echo "<br>";
    // $register_rfid->add();
    $company_id->add();
    echo "<br>";
    $add_client->add();
    echo "<br>";
    $delete_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");


    $ajax_delete = new js_ajax();
    $ajax_delete->function_name("delete_client");
    $ajax_delete->delete("clients");
    $ajax_delete->on_success("CLIENT DELETED SUCCESSFULLY");
    $ajax_delete->redirect("home.php");