<?php
$type = $_GET['type'] ?? 1;
$sex = $_GET['sex'] ?? 'all';
include '../vendor/autoload.php';
if (!isset($_GET['session']) or is_null($_GET['session'])) {
    echo '403';
    die();
}
use Database\{Settings,Question};
$session = $_GET['session'];
if (Settings::getSettings('sesionWeb') == null){
    echo '403';
    die();

}
if (Settings::getSettings('sesionWeb') != $session or $session == '') {
    echo '403';
    die();
}


if ($_GET['action']){
    if ($_GET['action'] == 'delete'){
        Question::removeById($_GET['id']);
        \inc\fileStorage::removeFile('question');
    }
}
?>

<html>

<head>
    <style>
        * {
            margin: 0;
            direction: rtl
        }

    </style>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

</head>
<body>
<div style="margin: 20px auto;width: 60%" class="">
    <p> نوع : <?php
        if ($type == 1) {
            echo 'حقیقت';
        }
        if ($type == 2) {
            echo 'جرعت';
        }
        if ($type == 3) {
            echo 'حقیقت +18';
        }
        if ($type == 4) {
            echo 'جرعت +18';
        }

        ?></p>
    <p> جنسیت : <?php
        if ($sex == 'all') {
            echo 'همه';
        }
        if ($sex == 'male') {
            echo 'مرد';
        }
        if ($sex == 'female') {
            echo 'زن';
        }


        ?></p>
</div>
<div class="d-flex text-center" style="margin: 20px auto;width: 60%">

    <table class="table table-responsive">
        <tr>
            <td>#</td>
            <td>شناسه</td>
            <td>متن</td>
            <td>عملیات</td>
        </tr>
        <?php


        $a = Question::getBygenderAndType($type, $sex);

        $i = 1;
        foreach ($a as $qus) {
            ?>
            <tr>

                <td>  <?php echo $i; ?>  </td>


                <td>  <?php echo $qus->id; ?>  </td>


                <td>  <?php echo $qus->question; ?>  </td>


                <td>
                    <a href="./viewqus.php?session=<?php echo $session; ?>&id=<?php echo $qus->id; ?>&action=delete&type=<?php echo $type; ?>&sex=<?php echo $sex; ?>">حذف</a>
                </td>


            </tr>

            <?php
            $i++;
        }
        ?>
    </table>
</div>
</body>
</html>
