<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
    <h2 class="bd-title" id="content">
        <span>Administration : Tags</span>
    </h2>
</header>
<?php
echo core::filAriane(array(
    "current" => "Tags",
    "arbo" => array(
        "Administration" => NULL,
        "Tags" => "/tags.html"
    )
));

$allTags = tags::getAll(2);

?>

<table class="table">
    <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">Tags</th>
            <th scope="col"></th>
        </tr>
    </thead>
    <tbody>
<?php 
    foreach ($allTags as $value) {
        echo "  <tr>
                    <th scope=\"row\">" . $value["id"] . "</th>
                    <td><input type=\"email\" class=\"form-control form-control-sm\" id=\"tags-".$value["id"]."\" value=\"" . $value["label"] . "\"></td>
                    <td><button type=\"button\" class=\"btn btn-primary btn-sm\" onclick=\"majTags(".$value["id"].");\">Modifier</button></td>
                </tr>";
    }
?>
    </tbody>
</table>

<script>
    function majTags(id){
        $.ajax({
            url: '/submit.php',
            type: 'POST',
            data: {
                from: "tag-change",
                id: id,
                value: $('#tags-'+id).val()
            },
            success: function(response) {
                $("#printToastSuccessTxt").html("Le tag vient d'être mis à jour");
                $("#printToastSuccess").toast('show');
            },
            error: function(xhr, status, error) {
                $("#printToastErrorTxt").html("Le tag n'a pas été mis à jour");
                $("#printToastError").toast('show');
            }
        });
    }
</script>