<?php
session_start();
include "../../html.class.php";
include "../../root.class.php";
include "../../classes/db.class.php";
$html = new html();
$functions = new functions();


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

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

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


$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();


$add_site = new button();
$add_site->id("");
$add_site->name("");
$add_site->value("UPDATE");
$add_site->class("app_buttons");
$add_site->onclick("update_email()");

$delete_site = new button();
$delete_site->id("");
$delete_site->name("");
$delete_site->value("DELETE");
$delete_site->class("app_buttons_small");
$delete_site->onclick("delete_email()");

?>

<div class="tank_item_container form_down">
    <h2>ADD EMAIL</h2>
    <?php
    $name->add();
    $record_id->add();
    echo "<br>";
    $email->add();
    $company_id->add();
    echo "<br>";
    $add_site->add();
    echo "<br>";
    $delete_site->add();
    ?>
</div>

<?php

$ajax = new js_ajax();
$ajax->function_name("update_email");
$ajax->update("email_notifications");
$ajax->on_success("EMAIL ADDED SUCCESSFULLY");
$ajax->redirect("home.php");

$ajax_delete = new js_ajax();
$ajax_delete->function_name("delete_email");
$ajax_delete->delete("email_notifications");
$ajax_delete->on_success("EMAIL DELETED SUCCESSFULLY");
$ajax_delete->redirect("home.php");