<?php
    if ( !$user['superAdmin'] ) {
        exit;
    }

    if ( $shareId = $_POST['id'] ) {
        $share = $db->row("SELECT * FROM share WHERE id = ?", $shareId);
        $views = $db->run("SELECT * FROM share_visit WHERE shareId = ? ORDER BY id DESC LIMIT 0,100", $share['id']);
        $count = $db->cell("SELECT COUNT(*) AS count FROM share_visit WHERE shareId = ?", $share['id']);
    }

    if ( $views ) :
?>
        <div id="shareLogsTable" class="table-responsive collapse show">
            <table class="table table-striped table-bordered">
                <thead>
                    <tr class="text-center">
                        <th scope="col">#</th>
                        <th scope="col">Share</th>
                        <th scope="col">URI</th>
                        <th scope="col">UID</th>
                        <th scope="col">IP</th>
                        <th scope="col">UA</th>
                        <th scope="col">Date/Time</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                        $k      = 0;
                        $agents = [];

                        foreach( $views as $view ) :
                            $date = explode(' ', $view['createdAt'])[0];
                            if ( $date !=  explode(' ', $views[$k+1]['createdAt'])[0]) {
                                $border = "2px solid red";
                            } else {
                                $border = '';
                            }
                    ?>
                        <tr class="text-center" style="border-bottom:<?php echo $border; ?>;">
                            <th scope="row"><?php echo $count; ?></th>
                            <td><?php echo $share['note']; ?></td>
                            <td><?php echo $view['uri']; ?></td>
                            <td><?php echo $view['uid']; ?></td>
                            <td><?php echo $view['ip']; ?></td>
                            <td><?php echo $view['ua']; ?></td>
                            <td><?php echo $view['createdAt']; ?></td>
                        </tr>
                    <?php 
                            $count--;
                            $k++;
                        endforeach; 
                    ?>
                </tbody>
            </table>
        </div>
<?php
    else :
?>
    <p>No logs for this share</p>
<?php
    endif;
?>