<?php

include "../../classes/autoload.php";

$html = new html("");

$app = new inner_app();
$app->quick_bar();
$app->app_start();

$res = $db->query("excluded_file_identifiers", "SELECT * FROM excluded_file_identifiers WHERE record_id = '" . $_GET['record_id'] . "'");
$data = $res->fetch_assoc();
?>

<div class="column width_80 background_1 border_radius">

    <h1>NEW EXCLUDED FILE IDENIFIER</h1>
    <div class="row width_80">
        <div class="column width_50">
            <label>TEXT</label>
            <input type="text" class="width_80" id='text' name='text' value="<?php echo $data['text']; ?>"/>
            <input type="text" hidden class="width_80" id='record_id' name='record_id' value="<?php echo $data['record_id']; ?>"/>
        </div>
    </div>
    <br>
    <button class="width_90" onclick="save('update_excluded_files.php')">SAVE</button>
    <br>

</div>


<script>
    function save(url) {
        var elements = document.getElementsByTagName('input');
        var payload = {};
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            if (element.type === 'text' || element.type === 'date' || element.type === 'email') {
                payload[element.name] = element.value;
            }
        }

        var elements = document.getElementsByTagName('select');
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];

            payload[element.name] = element.value;

        }

        var form = document.createElement('form');
        form.method = 'POST';
        form.action = url;

        for (var key in payload) {
            if (payload.hasOwnProperty(key)) {
                var input = document.createElement('input');
                input.type = 'hidden';
                input.name = key;
                input.value = payload[key];

                form.appendChild(input);
            }
        }

        document.body.appendChild(form);
        form.submit();
    }
</script>