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

$email_server = new select();
$email_server->class();
$email_server->add_option("", "EMAIL SERVER");
$email_server->fill_from_db("email_servers", 'record_id', 'server_address');
$email_server->id("email_server_id");
$email_server->name("email_server_id");
$email_server->required();


$email = new input();
$email->class();
$email->name("email");
$email->id("email");
$email->placeholder("EMAIL ADDRESS");
$email->required();

$client_id = new input();
$client_id->type("hidden");
$client_id->name("client_id");
$client_id->value($_SESSION['selected_client']);
$client_id->id("client_id");
$client_id->readonly();
$client_id->required();

$webmail_link = new input();
$webmail_link->class();
$webmail_link->value("https://reseller141.aserv.co.za:2096/");
$webmail_link->name("webmail_link");
$webmail_link->id("webmail_link");
$webmail_link->placeholder("EMAIL ADDRESS");
$webmail_link->required();

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

$submit = new button();
$submit->value("ADD");
$submit->class();
$submit->onclick("add_email()");
?>

<div class="form_down">
    <h1>ADD EMAIL</h1>
    <?php
    $email_server->add();
    $client_id->add();
    $webmail_link->add();
    $email->add();
    $password->add(); ?>
    <button onclick="generate_password()" class="submit_btn">Generate Password</button>
    <script>
        function generate_password() {
            event.preventDefault();
            var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*";
            var password = "";
            for (var x = 0; x < 15; x++) {
                var i = Math.floor(Math.random() * chars.length);
                password += chars.charAt(i);
            }
            document.getElementById("password").value = password;
        }
    </script><?php
    $submit->add();

    ?>

</div>

<?php
// $html->html_form_ajax("add_asset_type", "INSERT", "asset_types", '', false, [], '', ['description']);
$ajax = new js_ajax();
$ajax->function_name("add_email");
$ajax->insert("emails");
$ajax->on_success("EMAIL ADDED SUCCESSFULLY");
$ajax->redirect("home.php");
?>