<?php
require_once('../assets/constants/config.php');
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


    $stmt = $conn->prepare("SELECT * FROM tbl_school_info");
    $stmt->execute();
    $result = $stmt->fetchAll();

    foreach($result as $row) {

        $currency = $row[6];
        date_default_timezone_set($row[5]);

    }

    }catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
require_once('constants/check-login.php');
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>OES - Exams</title>
    <link rel="icon" href="../assets/images/favicon.ico">
    <link href="../assets/google-fonts/nunito.css" rel="stylesheet">
    <link type="text/css" rel="stylesheet" href="../assets/loader/waitMe.css"><link rel="stylesheet" href="../assets/styles/css/themes/lite-purple.min.css">
    <link rel="stylesheet" href="../assets/styles/vendor/perfect-scrollbar.css">
    <link rel="stylesheet" href="../assets/styles/vendor/datatables.min.css">
    <link rel="stylesheet" href="../assets/styles/vendor/pickadate/classic.css">
    <link rel="stylesheet" href="../assets/styles/vendor/pickadate/classic.date.css">


</head>

<style>


</style>

<body>
    <div class="app-admin-wrap">
        <div class="main-header">
            <div class="logo">
                <img src="../assets/images/logo.png" alt="">
            </div>

            <div class="menu-toggle">
                <div></div>
                <div></div>
                <div></div>
            </div>



            <div style="margin: auto"></div>

            <div class="header-part-right">

                <i class="i-Full-Screen header-icon d-none d-sm-inline-block" data-fullscreen></i>


                <div class="dropdown">
                    <div class="user colalign-self-end">
                        <?php
                        if ($myvataor == null) {

                        print ' <img class="img-crop" src="../assets/images/blank_avatar.png" id="userDropdown" alt="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';

                        }else{

                        print ' <img class="img-crop" src="../assets/uploads/avatar/'.$myvataor.'" id="userDropdown" alt="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';

                        }

                        ?>


                        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
                            <div class="dropdown-header">
                                <i class="i-Lock-User mr-1"></i> <?php echo $myemail; ?>
                            </div>
                            <a class="dropdown-item" href="account">Account settings</a>
                            <a class="dropdown-item" href="../logout">Sign out</a>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <div class="side-content-wrap">
            <div class="sidebar-left open" data-perfect-scrollbar data-suppress-scroll-x="true">
                <ul class="navigation-left">
                    <li class="nav-item" >
                        <a class="nav-item-hold" href="./">
                            <i class="nav-icon i-Bar-Chart"></i>
                            <span class="nav-text">Dashboard</span>
                        </a>
                        <div class="triangle"></div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item-hold" href="subjects">
                            <i class="nav-icon i-Library"></i>
                            <span class="nav-text">Subjects</span>
                        </a>
                        <div class="triangle"></div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item-hold" href="students">
                            <i class="nav-icon i-Administrator"></i>
                            <span class="nav-text">Students</span>
                        </a>
                        <div class="triangle"></div>
                    </li>
                    <li class="nav-item  active">
                        <a class="nav-item-hold" href="exams">
                            <i class="nav-icon i-File-Horizontal-Text"></i>
                            <span class="nav-text">Examinations</span>
                        </a>
                        <div class="triangle"></div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item-hold" href="notice">
                            <i class="nav-icon i-Bell"></i>
                            <span class="nav-text">Notice</span>
                        </a>
                        <div class="triangle"></div>
                    </li>

                    <li class="nav-item">
                        <a class="nav-item-hold" href="assessments">
                            <i class="nav-icon i-Data"></i>
                            <span class="nav-text">Assessment Records</span>
                        </a>
                        <div class="triangle"></div>
                    </li>

                </ul>
            </div>


            <div class="sidebar-overlay"></div>
        </div>


        <div class="main-content-wrap sidenav-open d-flex flex-column">
            <div class="breadcrumb">
                <h1>Exams</h1>
                <p id="app_data"></p>

            </div>
            <div class="separator-breadcrumb border-top"></div>
             <div class="row mb-4">
                <div class="col-md-12 mb-4">
                    <div class="card text-left">
                        <div class="card-body">

                                <div class="table-responsive">
                                <table id="zero_configuration_table" class="display table table-striped table-bordered" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>Name</th>
                                            <th>Type</th>
                                            <th>Exam Fee</th>
                                            <th>Department</th>
                                            <th>Class</th>
                                            <th>Subject</th>
                                            <th>Deadline</th>
                                            <th style="width:90px;">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        try {
                                    $conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
                                    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                    $mid = 1;


                                    $stmt = $conn->prepare("SELECT a.*, b.*, c.*, d.* FROM tbl_exams a LEFT JOIN tbl_departments b ON a.department = b.id LEFT JOIN tbl_classes c ON a.class = c.id LEFT JOIN tbl_subjects d ON a.subject = d.id WHERE a.class = :myclass AND a.status = 'ACTIVE'");
                                    $stmt->bindParam(':myclass', $_SESSION['class']);
                                    $stmt->execute();
                                    $result = $stmt->fetchAll();

                                    foreach($result as $row)
                                    {
                                        if ($row['fee'] == "") {
                                            $fee = "-NIL-";
                                        }else{
                                            $fee = ''.number_format($row['fee']).' '.$currency.'';
                                        }
                                        ?>
                                        <tr>
                                            <td><a data-container="body" data-toggle="popover" data-placement="right"
                                           data-content="Exam ID : <?php echo $row[0]; ?> , Duration : <?php echo $row[2]; ?> Minutes , Passmark : <?php echo $row[3]; ?>% , Re-take exam after <?php echo $row[4]; ?> Days" data-original-title="" title=""><?php echo $row[1]; ?></a>
                                            </td>
                                            <td><?php echo $row[9]; ?></td>
                                            <td><?php echo $fee; ?></td>
                                            <td><?php echo $row[16]; ?></td>

                                            <td><?php echo $row[19]; ?></td>
                                            <td><?php echo $row[23]; ?></td>
                                            <td><?php echo $row[5]; ?></td>
                                            <td><center>
                                            <select onchange="javascript:location.href = this.value;">
                                            <option selected disabled>Select</option>
                                            <option value="view-exam?node=<?php echo $row[0]; ?>">Take Exam</option>
                                            </select>
                                            </center>

                                            </td>
                                        </tr>

                                        <?php
                                         $mid++;


                                    }

                                    }catch(PDOException $e)
                                    {
                                    echo "Connection failed: " . $e->getMessage();
                                    }
                                    ?>


                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>Name</th>
                                            <th>Type</th>
                                            <th>Exam Fee</th>
                                            <th>Department</th>
                                            <th>Class</th>
                                            <th>Subject</th>
                                            <th>Deadline</th>
                                            <th>Action</th>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>


                        </div>


                    </div>
                </div>


            </div>

            <div class="flex-grow-1"></div>


        </div>

    </div>
    <div class="search-ui">
        <div class="search-header">
            <img src="assets/images/logo.png" alt="" class="logo">
            <button class="search-close btn btn-icon bg-transparent float-right mt-2">
                <i class="i-Close-Window text-22 text-muted"></i>
            </button>
        </div>
        <form class="app_form"  action="search" method="GET" autocomplete="OFF">
        <input type="text" name="keyword" required  placeholder="Enter student name.." class="search-input" autofocus>
        </form>

    </div>

    <script src="../assets/js/vendor/jquery-3.3.1.min.js"></script>
    <script src="../assets/js/vendor/bootstrap.bundle.min.js"></script>
    <script src="../assets/js/vendor/perfect-scrollbar.min.js"></script>

    <script src="../assets/js/vendor/pickadate/picker.js"></script>
    <script src="../assets/js/vendor/pickadate/picker.date.js"></script>

    <script src="../assets/js/vendor/datatables.min.js"></script>
    <script src="../assets/loader/waitMe.js"></script><script src="../assets/js/es5/script.min.js"></script>
    <script src="../assets/js/datatables.script.js"></script>
    <script src="../assets/js/form.basic.script.js"></script>

        <script>
        $("[data-toggle=popover]").popover();
    </script>


</body>


</html>
