<?php
    if (isset($_GET['delete'])){
        $use->delete($_GET['delete']);
        echo "<script>location='./?page=articles'</script>";
    }
?>
<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-transparent">
                <div class="row align-items-center">
                    <div class="col">
                        <h6 class="text-uppercase text-muted ls-1 mb-1">List Audio | <a class="btn btn-primary"
                                                                                           href="./?page=article-new">New</a>
                        </h6>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-striped" id="myTable">
                    <thead>
                    <tr>
                        <th width="50">#</th>
                        <th>Title</th>
                        <th>Audio</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($use->getAllArticles() as $article): 
                        $ext = pathinfo($article['image'], PATHINFO_EXTENSION);
                        $type = '';
                        if($ext == 'mp4' || $ext == 'mp3' || $ext == 'mpeg' || $ext == 'ogg'){
                            $type = '<audio controls>  <source src="../images/thumb/'.$article['image'].'" type="audio/'.$ext.'"></audio>';
                        }
                    ?>
                        <tr>
                            <td>#</td>
                            <td><?= $article['title'] ?></td>
                            <td width="150">
                                <?= $type; ?>
                            </td>
                            <td width="150">
                                <a href="./?page=articles&delete=<?= $article['id'] ?>" class="btn btn-danger btn-sm">Delete</a>
                                <a href="./?page=articles-edit&id=<?= $article['id'] ?>" class="btn btn-info btn-sm">Edit</a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>