<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();

$user_record_id = new input();
$user_record_id->type("hidden");
$user_record_id->name("record_id");
$user_record_id->id("record_id");
$user_record_id->value($_GET['record_id']);
// HTML FORM ELEMENTS
$username = new input();
$username->class("inputs");
$username->type("text");
$username->placeholder("username");
$username->name("username");
$username->required();
$username->id("username");
$username->value_from_db("users", "username", "record_id = {$_GET['record_id']}");

$password = new input();
$password->class("inputs");
$password->type("text");
$password->placeholder("password");
$password->name("password");
$password->id("password");

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

$user_type = new select();
$user_type->class("inputs");
$user_type->name("access_type");
$user_type->id("access_type");
$user_type->add_option("", "ACCESS LEVEL");
$user_type->add_option("ALL", "MANAGMENT");
$user_type->add_option("OPERATOR", "FUEL OPERATOR");
$user_type->required();
$user_type->value_from_db("users", "access_type", "record_id = {$_GET['record_id']}");


$status = new select();
$status->class("inputs");
$status->name("status");
$status->id("status");
$status->add_option("", "STATUS");
$status->add_option("1", "ACTIVE");
$status->add_option("0", "INACTIVE");
$status->value_from_db("users", "status", "record_id = {$_GET['record_id']}");

$submit_btn = new button();
$submit_btn->value("UPDATE");
$submit_btn->onclick("edit_user()");

?>

<div class="form_down">
    <h1>EDIT USER</h1>
    <?php
    $company_id->add();
    $user_record_id->add();
    echo "<label for='username'>Username</label>";
    $username->add();

    echo "<label for='password'>Password</label>";
    $password->add();

    echo "<label for='status'>Status</label>";
    $status->add();

    echo "<label for='user_type'>Access Level</label>";
    $user_type->add();
    
    $submit_btn->add();
    ?>

</div>

<?php
$ajax = new js_ajax();
$ajax->function_name("edit_user");
$ajax->submit_btn_id("submit");
$ajax->update("users");
$ajax->on_success("SUCCESSFULLY UPDATED THE USER");
?>