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


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

$name = new input();
$name->name("name");
$name->id("name");
$name->class("inputs");
$name->placeholder("JOB CARD ACCOUNT NAME");
$name->type("text");
$name->value_from_db("job_card_accounts", "name", "record_id = {$_GET['record_id']}");
$name->required();

$description = new input();
$description->name("description");
$description->id("description");
$description->class("inputs");
$description->placeholder("DESCRIPTION");
$description->type("text");
$description->value_from_db("job_card_accounts", "description", "record_id = {$_GET['record_id']}");
$description->required();


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


$account_manager_id = new select();
$account_manager_id->name("account_manager_id");
$account_manager_id->id("account_manager_id");
$account_manager_id->class("inputs");
$account_manager_id->add_option("", "ACCOUNT MANAGER");
$account_manager_id->fill_from_db("users", "record_id", "username");
$account_manager_id->required();
$account_manager_id->value_from_db("job_card_accounts", "account_manager_id", "record_id = {$_GET['record_id']}");

$submit = new button();
$submit->name("submit");
$submit->id("submit");
$submit->class("submit_btn");
$submit->value("EDIT");
$submit->onclick("add_jobcard_account()");

$report = new button();
$report->class("submit_btn");
$report->value("PDF");
$report->onclick("open_report()");
?>

<div class="form_down">
    <h2>EDIT JOB CARD ACCOUNT</h2>
    <?php
    $record_id->add();
    $name->add();
    $description->add();
    $status->add();
    $account_manager_id->add();
    $submit->add();
    echo "<br>";
    $report->add();
    ?>
</div>

<script>
    function open_report() {
        window.open("job_card_account.pdf.php?record_id=<?php echo $_GET['record_id']; ?>");
    }
</script>

<?php
$ajax = new js_ajax();
$ajax->function_name("add_jobcard_account");
$ajax->submit_btn_id("submit");
$ajax->update("job_card_accounts");
$ajax->on_success("SUCCESSFULLY UPDATED THE ACCOUNT");
$ajax->redirect("jobcard_accounts_home.php");
?>