<!--main-container-part-->
<div id="content">
    <!--breadcrumbs-->
    <div id="content-header">
        <div id="breadcrumb"> <a href="<?php echo site_url('admin'); ?>" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> Home</a></div>
    </div>
    <!--End-breadcrumbs-->

    <!--Action boxes-->
    <div class="container-fluid">
        <div>
            <h3>Monitoring Pelaksanaan</h3>
        </div>
        <div class="row-fluid">
            <?php
            $peserta = $this->db->from('ujian_dilaksanakan')
                ->join('siswa', 'peserta = id_peserta', 'LEFT')
                ->where('detail_jadwal_ujian', $jadwal->id_detail_jadwal_ujian)
                ->get()->result();
            if ($peserta) {
                foreach ($peserta as $p) {
            ?>
                    <div class="span6">
                        <div class="widget-box">
                            <div class="widget-title"> <span class="icon"> <i class="icon-list"></i> </span>
                                <h5><?= $p->nama_lengkap . ' (' . $p->jenis_kelamin . ')'; ?></h5>
                            </div>
                            <div class="widget-content">
                                <div class="row" style="margin-left: 0 !important;">
                                    <div class="span6">
                                        <strong>Snapshoots:</strong>
                                        <?php
                                        $jumlah_file = 0;
                                        $folder = 'assets/snapshoots/' . ($p->id_ujian_dilaksanakan . '' . $p->peserta);

                                        // Jika folder ada, ambil gambar pertama dari folder
                                        if (file_exists($folder) && is_dir($folder)) {
                                            $files = array_values(array_diff(scandir($folder), ['.', '..'])); // Ambil semua file kecuali '.' dan '..'
                                            $jumlah_file = count($files);

                                            // Ambil file pertama jika ada file
                                            if ($jumlah_file > 0) {
                                                $file = $files[0];
                                                $path = base_url($folder . '/' . $file);
                                            } else {
                                                // Jika folder ada tapi kosong
                                                $path = base_url('assets/no_image.jpg');
                                            }
                                        } else {
                                            // Jika folder tidak ada
                                            $path = base_url('assets/no_image.jpg');
                                        }

                                        // Tampilkan gambar
                                        echo '<img src="' . $path . '" style="width: 180px; height: 115px;">';

                                        // Tampilkan tombol jika ada file
                                        if ($jumlah_file > 0) {
                                            echo '<div style="margin-top: 10px;"><a href="' . base_url($folder . '/') . '" target="_blank" class="btn btn-success">Lihat</a> <a href="' . site_url('admin/download_snapshoot/' . ($p->id_ujian_dilaksanakan . '' . $p->peserta)) . '" target="_blank" class="btn btn-primary">Download</a></div>';
                                        }
                                        ?>

                                    </div>
                                    <div class="span6">
                                        <p>
                                            <strong>No Peserta: <?= $p->no_peserta; ?></strong><br>
                                            Mulai Ujian: <?= strftime('%H:%M:%S', strtotime($p->mulai_ujian)); ?><br>
                                            Status: <strong><?php echo $p->status_ujian; ?></strong>
                                        </p>
                                        Info Detail: <?php echo $p->keterangan_paket_soal; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
            <?php
                }
            } else {
                echo "Belum Ada Peserta yang melaksanakan ujian ini";
            }
            ?>

        </div>
    </div>
</div>
