<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="shortcut icon" href="<?= $logo ?>" type="image/x-icon">
    <script language="JavaScript">
        document.addEventListener("contextmenu", function(e) {
            e.preventDefault();
        }, false);
    </script>

    <title> Print Soal</title>
    <style>
        * {
            margin: auto;
            padding: 0;
            line-height: 100%;
        }

        td {
            padding: 1px 3px 1px 3px;
        }

        .garis {
            border: 1px solid #000;
            border-left: 0px;
            border-right: 0px;
            padding: 1px;
            margin-top: 5px;
            margin-bottom: 5px;
        }

        @media print {
            .pgi {
                page-break-inside: avoid;
            }
        }
    </style>
</head>

<body onload="window.print();setTimeout(()=>window.close(),500)">

    <!-- <body> -->
    <!-- <body onload="window.print()"> -->
    <div>
        <table>
            <tbody>
                <tr>
                    <td rowspan="5">
                        <img src="<?= $logo ?>" width="90px">
                    </td>
                    <td width="200"></td>
                    <td width="500"> </td>
                    <td rowspan="5" width="100"></td>
                </tr>
                <tr>
                    <td>Pembuat Soal</td>
                    <td>: <?= $creator ?></td>
                </tr>
                <?php if (!empty(options('nama_sekolah'))) : ?>
                    <tr>
                        <td>Satuan Pendidikan</td>
                        <td>: <?= options('nama_sekolah') ?></td>
                    </tr>
                <?php endif ?>
            </tbody>
        </table>

        <div class="garis"></div>
        <br>
        <?php if (count($pg) > 0) : ?>
            <h3 class="panel-title">
                <b><?= $index['text'][$index['num']++] ?>. Soal Pilihan Ganda</b>
            </h3>
            <br>
            <?php foreach ($pg as $k => $p) : ?>
                <div class="pgi">
                    <table width="100%" border="0">
                        <tbody>
                            <tr>
                                <td width="30px" valign="top">
                                    <p><?= $k + 1 ?></p>
                                </td>
                                <td valign="top">
                                    <?= str_replace("../../../", "../../../../", $p['question']) ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <?php if ($p['jenis_soal'] == 4) : ?>
                        <table width="100%" border="0">
                            <tbody>
                                <tr>
                                    <td width="2%">&nbsp;</td>
                                    <!-- Start Question -->
                                    <td width="49%">
                                        <?php if (isset($couples[$p['id']])) : ?>
                                            <?php foreach ($couples[$p['id']] as $sck => $o) : ?>
                                                <div class="pgi">
                                                    <?= $index['text'][$sck] ?>.<?= str_replace("../../../", "../../../../", $couples[$p['id']][$sck]['body']) ?>
                                                </div>
                                                <br>
                                            <?php endforeach ?>
                                        <?php endif; ?>
                                    </td>
                                    <!-- End Question -->
                                    <!-- Start Option -->
                                    <td width="49%">
                                        <?php if (isset($opsi[$p['id']])) : ?>
                                            <?php foreach ($opsi[$p['id']] as $sck => $o) : ?>
                                                <div class="pgi">
                                                    <?= $index['text'][$sck] ?>.<?= str_replace("../../../", "../../../../", $opsi[$p['id']][$sck]['body']) ?>
                                                </div>
                                                <br>
                                            <?php endforeach ?>
                                        <?php endif; ?>
                                    </td>
                                    <!-- End Option -->
                                </tr>
                                <?php if (($_GET['wk'] ?? '') == 'true') : ?>
                                    <tr>
                                        <td width="30px">&nbsp;</td>
                                        <td>JAWABAN : <?= implode(',',  $p['coupled']) ?></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>

                    <?php else : ?>
                        <?php if (isset($opsi[$p['id']])) : ?>

                            <table width="100%" border="0">
                                <tbody>
                                    <tr>
                                        <?php if (isset($opsi[$p['id']][0])) : ?>
                                            <td width="30px">&nbsp;</td>
                                            <td width="4px" valign="top">A.&nbsp;</td>
                                            <td width="300px" colspan="2">
                                                <?= str_replace("../../../", "../../../../", $opsi[$p['id']][0]['body']) ?>
                                            <?php endif ?>
                                            <?php if (isset($opsi[$p['id']][2])) : ?>
                                            <td width="30px">&nbsp;</td>
                                            <td width="4px" valign="top">C.&nbsp;</td>
                                            <td width="300px" colspan="2">
                                                <?= str_replace("../../../", "../../../../", $opsi[$p['id']][2]['body']) ?>
                                            <?php endif ?>
                                            <?php if (isset($opsi[$p['id']][4])) : ?>
                                            <td width="30px">&nbsp;</td>
                                            <td width="4px" valign="top">E.&nbsp;</td>
                                            <td width="300px" colspan="2">
                                                <?= str_replace("../../../", "../../../../", $opsi[$p['id']][4]['body']) ?>
                                            <?php endif ?>
                                    </tr>
                                    <?php if (isset($opsi[$p['id']][1]) || isset($opsi[$p['id']][3])) : ?>
                                        <tr>
                                            <?php if (isset($opsi[$p['id']][1])) : ?>
                                                <td width="30px">&nbsp;</td>
                                                <td width="4px" valign="top">B.&nbsp;</td>
                                                <td width="300px" colspan="2">
                                                    <?= str_replace("../../../", "../../../../", $opsi[$p['id']][1]['body']) ?>
                                                <?php endif ?>
                                                <?php if (isset($opsi[$p['id']][3])) : ?>
                                                <td width="30px">&nbsp;</td>
                                                <td width="4px" valign="top">D.&nbsp;</td>
                                                <td width="300px" colspan="2">
                                                    <?= str_replace("../../../", "../../../../", $opsi[$p['id']][3]['body']) ?>
                                                <?php endif ?>
                                        </tr>
                                    <?php endif ?>
                                    <?php if (isset($_GET['wk'])) : ?>
                                        <?php if ($p['jenis_soal'] == 6) : ?>
                                            <tr>
                                                <?php
                                                $pgkeys = [];
                                                if (isset($opsi[$p['id']][0])) {
                                                    $pgkeys[] = "A- " . ($opsi[$p['id']][0]['is_key'] == 1 ? 1 : 0);
                                                }
                                                if (isset($opsi[$p['id']][1])) {
                                                    $pgkeys[] = "B- " . ($opsi[$p['id']][1]['is_key'] == 1 ? 1 : 0);
                                                }
                                                if (isset($opsi[$p['id']][2])) {
                                                    $pgkeys[] = "C- " . ($opsi[$p['id']][2]['is_key'] == 1 ? 1 : 0);
                                                }
                                                if (isset($opsi[$p['id']][3])) {
                                                    $pgkeys[] = "D- " . ($opsi[$p['id']][3]['is_key'] == 1 ? 1 : 0);
                                                }
                                                if (isset($opsi[$p['id']][4])) {
                                                    $pgkeys[] = "E- " . ($opsi[$p['id']][4]['is_key'] == 1 ? 1 : 0);
                                                }
                                                ?>

                                                <td width="30px">&nbsp;</td>
                                                <td></td>
                                                <td>JAWABAN : <?= implode(',',  $pgkeys) ?></td>
                                            </tr>

                                        <?php else : ?>
                                            <tr>
                                                <?php
                                                $pgkeys = [];
                                                if (isset($opsi[$p['id']][0])) {
                                                    if ($opsi[$p['id']][0]['is_key'] == 1) {
                                                        $pgkeys[] = 'A';
                                                    }
                                                }
                                                if (isset($opsi[$p['id']][1])) {
                                                    if ($opsi[$p['id']][1]['is_key'] == 1) {
                                                        $pgkeys[] = 'B';
                                                    }
                                                }
                                                if (isset($opsi[$p['id']][2])) {
                                                    if ($opsi[$p['id']][2]['is_key'] == 1) {
                                                        $pgkeys[] = 'C';
                                                    }
                                                }
                                                if (isset($opsi[$p['id']][3])) {
                                                    if ($opsi[$p['id']][3]['is_key'] == 1) {
                                                        $pgkeys[] = 'D';
                                                    }
                                                }
                                                if (isset($opsi[$p['id']][4])) {
                                                    if ($opsi[$p['id']][4]['is_key'] == 1) {
                                                        $pgkeys[] = 'E';
                                                    }
                                                }
                                                ?>

                                                <td width="30px">&nbsp;</td>
                                                <td></td>
                                                <td>JAWABAN : <?= implode(',',  $pgkeys) ?></td>
                                            </tr>
                                        <?php endif; ?>
                                    <?php endif; ?>

                                </tbody>
                            </table>
                        <?php endif ?>


                    <?php endif ?>
                </div>
            <?php endforeach ?>
            <br>
        <?php endif; ?>

        <?php if (count($shortentry) > 0) : ?>
            <h3 class="panel-title">
                <b><?= $index['text'][$index['num']++] ?>. Soal Isian Singkat</b>
            </h3>
            <?php foreach ($shortentry as $k => $p) : ?>
                <div class="pgi">
                    <table width="100%" border="0">
                        <tbody>
                            <tr>
                                <td width="30px" valign="top">
                                    <p><?= $k + 1 ?></p>
                                </td>
                                <td valign="top">
                                    <?= str_replace("../../../", "../../../../", $p['question']) ?>
                                </td>
                            </tr>
                            <?php if (($_GET['wk'] ?? '') == 'true') : ?>
                                <tr>

                                    <td width="30px">&nbsp;</td>
                                    <td>JAWABAN : <?= $p['shortentry'] ?></td>
                                </tr>
                            <?php endif ?>
                        </tbody>
                    </table>
                </div>
            <?php endforeach ?>
            <br>
        <?php endif; ?>

        <?php if (count($esai) > 0) : ?>
            <h3 class="panel-title">
                <b><?= $index['text'][$index['num']++] ?>. Soal Esai</b>
            </h3>
            <?php foreach ($esai as $k => $p) : ?>
                <div class="pgi">
                    <table width="100%" border="0">
                        <tbody>
                            <tr>
                                <td width="30px" valign="top">
                                    <p><?= $k + 1 ?></p>
                                </td>
                                <td valign="top">
                                    <?= str_replace("../../../", "../../../../", $p['question']) ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            <?php endforeach ?>
            <br>
        <?php endif; ?>


    </div>
</body>

</html>