<?php 
    include'include/session.php';
    
    $tableName="faculty";
    $tableName1="course";
    $tableName2="course";
    $tableName3="student";
    $tableName4="exam_results";
    
    $sql = "SELECT * FROM $tableName";
    $query = mysql_query($sql);
    $rowcount=  mysql_num_rows($query);
    
    if(isset($_GET['id'])){
        $id  = mysql_escape_string($_GET['id']);
        
        $sql1 = "SELECT * FROM $tableName WHERE assignmentID ='$id'";
        $query1 = mysql_query($sql1);
        $rowcount1=  mysql_num_rows($query1);
    }
    
    if(isset($_GET['status'])){
        $status = mysql_escape_string($_GET['status']);
        if($status == 1){
            $stat  = $status;
            $c  = mysql_escape_string($_GET['c']);
            $y  = mysql_escape_string($_GET['y']);
            $s  = mysql_escape_string($_GET['s']);
            $ee  = mysql_escape_string($_GET['e']);
            $e=str_replace("_"," ",$ee);

            /*$sqlx = "SELECT * FROM $tableName4 WHERE courseID ='$c' AND year ='$y' AND sem='$s' AND category='$e'";*/
            $sqlx = "SELECT resultsID,category,code,total,added,unit,course,faculty,year,sem,added_by
                    FROM (
                        SELECT MAX(resultsID) AS resultsID,category,code,total,added,unitID,
                                            unit,course,faculty,year,sem,added_by
                        FROM $tableName4
                            WHERE courseID ='$c' AND year ='$y' AND sem='$s' AND category='$e'
                        GROUP BY code) as results
                    ORDER BY resultsID DESC";
            $queryx = mysql_query($sqlx);
            $rowcountx=  mysql_num_rows($queryx);
        }else
        if($status==2){
            $stat1  = $status;
            $c1  = mysql_escape_string($_GET['c']);
            $y1  = mysql_escape_string($_GET['y']);
            $s1  = mysql_escape_string($_GET['s']);
            $ee  = mysql_escape_string($_GET['e']);
            $e1=str_replace("_"," ",$ee);

            //$sqlx = "SELECT * FROM $tableName4 WHERE courseID ='$c1' AND yosID ='$y1' AND semisterID='$s1' AND category='$e1'";
            $sqlx = "SELECT resultsID,category,code,total,added,unit,course,faculty,year,sem
                    FROM (
                        SELECT MAX(resultsID) AS resultsID,category,code,total,added,unitID,
                                            unit,course,faculty,year,sem
                        FROM $tableName4
                            WHERE  courseID ='$c1' AND yosID ='$y1' AND semisterID='$s1' AND category='$e1'
                        GROUP BY code) as results
                    ORDER BY resultsID DESC";
            $queryx = mysql_query($sqlx);
            $rowcountx=  mysql_num_rows($queryx);
        }
    }else{
        $sqlx = "SELECT resultsID,category,code,total,added,unit,course,faculty,year,sem,added_by
                    FROM (
                        SELECT MAX(resultsID) AS resultsID,category,code,total,added,unitID,
                                            unit,course,faculty,year,sem,added_by
                        FROM $tableName4
                        GROUP BY code) as results
                    ORDER BY resultsID DESC";
        $queryx = mysql_query($sqlx);
        $rowcountx=  mysql_num_rows($queryx);
    }
    
    if(isset($_POST['c_id'])) {
        $sql = mysql_query("select years from `course` where `courseID`=".mysql_real_escape_string($_POST['c_id']));
        $res = mysql_fetch_array($sql);
        $years = $res['years'];
        echo "<option value='' style='cursor:pointer;'>- Class Year -</option>";
        for($y=1;$y<=$years;$y++){
            echo "<option value='$y' style='cursor:pointer;'>Year $y</option>";
        }
        exit();
    }
    
    if(isset($_POST['yoss'])) {
        $y = mysql_real_escape_string($_POST['yoss']);
        $c = mysql_real_escape_string($_POST['cos']);
        
        echo "<option value='' style='cursor:pointer;'>- Select Unit -</option>";
        for($p=1;$p<=3;$p++){
            $sqlx = mysql_query("SELECT u.unitID,u.name,u.semisterID
                            FROM staffunit a 
                            LEFT JOIN unit u 
                            ON a.unitID=u.unitID  
                            WHERE u.courseID='$c' 
                            AND u.yosID='$y'
                            AND semisterID='$p'
                            ORDER BY name ASC");
            $rowsx=  mysql_num_rows($sqlx);
            
            echo "<optgroup label='Block $p'>";
            if($rowsx <= 0){
                echo "<option value='' class='bg-danger text-danger' style='cursor:pointer;'>No Units Found</option>";
            }else
            {
                while($rowx = mysql_fetch_array($sqlx)) {
                    echo "<option value='".$rowx['unitID']."' style='cursor:pointer;'>".$rowx['name']."</option>";
                }            
            }
            echo "</optgroup>";
        }
        exit();
    }
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Exam Results - Lecturer | Administrator | WAKA CMEC</title>
    <link rel="shortcut icon" href="../../../assets/img/logo.png" />
    <link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,700">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Roboto:300,400,700">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Romanesco">
    <link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="../../../assets/fonts/material-icons.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form1.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form2.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table1.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables1.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table1.css">
    <link rel="stylesheet" href="../../../assets/css/nav.css">
    <link rel="stylesheet" href="../../../assets/css/Navbar---App-Toolbar--LG--MD---Mobile-Nav--SM--XS.css">
    <link rel="stylesheet" href="../../../assets/css/JLX-Fixed-Nav-on-Scroll.css">
    <link rel="stylesheet" href="../../../assets/css/Navbar---App-Toolbar--LG--MD---Mobile-Nav--SM--XS1.css">
    <link rel="stylesheet" href="../../../assets/css/Navbar-Fixed-Side1.css">
    <link rel="stylesheet" href="../../../assets/css/Pretty-Table.css">
    <link rel="stylesheet" href="../../../assets/css/Pretty-Table1.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit1.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form1.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu1.css">
    <link rel="stylesheet" href="../../../assets/css/styles.css">
    <link rel="stylesheet" href="../../../assets/css/tabela-mloureiro1973.css">
    <link rel="stylesheet" href="../../../assets/css/Team-Clean.css">
</head>

<body style="background-color:rgba(42,63,84,0);">
    <nav class="navbar navbar-default" style="background-color:rgb(62,140,228);">
        <div class="container-fluid">
            <div class="navbar-header"><a class="navbar-brand navbar-link" href="#" style="font-weight:bold;background-color:rgb(62,140,228);">Administrator | Waka CMEC Training Institute</a>
                <button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcol-2" style="background-color:rgb(62,140,228);color:rgb(255,255,255);"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
            </div>
            <div class="collapse navbar-collapse" id="navcol-2">
                <ul class="nav navbar-nav hidden-xs hidden-sm navbar-right" id="desktop-toolbar">
                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#"> <i class="fa fa-user"></i> &nbsp; <?php echo $pro;?>  <i class="fa fa-chevron-down fa-fw"></i></a>
                        <ul class="dropdown-menu" role="menu" style="background-color:rgb(249,249,249);">
                            <li role="presentation"><a href="settings.php"><i class="fa fa-user fa-fw"></i> Profile </a></li>
                            <li role="presentation"><a href="password.php"><i class="fa fa-lock fa-fw"></i> Password</a></li>
                            <li role="presentation"><a href="../validate/logout.php"><i class="fa fa-power-off fa-fw"></i>Logout </a></li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav visible-xs-block visible-sm-block" id="mobile-nav">
                    
                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#"> <i class="fa fa-user"></i> &nbsp; <?php echo $pro;?> </i> <i class="fa fa-chevron-down fa-fw"></i></a>
                        <ul class="dropdown-menu" role="menu" style="background-color:rgb(249,249,249);">
                            <li role="presentation"><a href="settings.php"><i class="fa fa-user fa-fw"></i> Profile </a></li>
                            <li role="presentation"><a href="password.php"><i class="fa fa-lock fa-fw"></i> Password</a></li>
                            <li role="presentation"><a href="../validate/logout.php"><i class="fa fa-power-off fa-fw"></i>Logout </a></li>
                        </ul>
                    </li>
                    <li role="presentation"><a>&nbsp;</a></li>
                    <li role="presentation"><a>&nbsp;</a></li>
                    
                </ul>
            </div>
        </div>
    </nav>
    <div class="top">
        <nav class="navbar navbar-default" id="navbar-main">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand hidden navbar-link" href="#" style="padding:0px;"> </a>
                    <button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
                </div>
                <div class="collapse navbar-collapse" id="navcol-1">
                    <ul class="nav navbar-nav">
                        <li role="presentation">
                            <a href="index.php">
                                <i class="fa fa-table" style="margin-right:5px;"></i>
                                Dashboard
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="staff.php">
                                <i class="fa fa-users" style="margin-right:5px;"></i>
                                Staff 
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="faculty.php">Faculty</a>
                        </li>
                        <li role="presentation">
                            <a href="course.php">Course</a>
                        </li>
                        <li role="presentation">
                            <a href="class.php">Class</a>
                        </li>
                        <li role="presentation">
                            <a href="unit.php">Unit</a>
                        </li>
                        <li role="presentation">
                            <a href="assigned-unit.php">
                                <i class="fa fa-bookmark" style="margin-right:5px;"></i>
                                Assigned Units
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="period.php">Block Period</a>
                        </li>
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#">
                                Others <span class="badge bg-red" id="notificationCounter"></span>
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu" role="menu">
                                <li role="presentation"><a href="pass-request.php">Gate Pass Request <span class="badge bg-red" id="requestCounter"></span></a></li>
                                <li role="presentation"><a href="expired-pass.php">Expired Gate Pass &nbsp;<span class="badge bg-red" id="expiredCounter"></span></a></li>
                                <li role="presentation"><a href="leave-request.php">Staff Leave Request <span class="badge bg-red" id="requestLeaveCounter"></span></a></li>
                                <li role="presentation"><a href="expired-leave.php">Expired Staff Leave &nbsp;<span class="badge bg-red" id="expiredLeaveCounter"></span></a></li>
                                <li role="presentation"><a href="pass.php">Gate Pass</a></li>
                                <li role="presentation"><a href="leave.php">Leave Type</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="row" style="width:98%;margin-right:auto;margin-left:auto;-webkit-box-shadow:0px 4px 4px 0px rgba(0,0,0,1);-moz-box-shadow:0px 4px 4px 0px rgba(0,0,0,1);box-shadow:0px 4px 4px 0px rgba(0,0,0,1);margin-bottom:5%;overflow:hidden;">
            <div class="col-md-12" style="margin-bottom:1%;padding-top:2px;padding-bottom:2px;background-color:rgb(239,239,239);">
                <div class="col-md-10">
                    <p style="margin-left:1%;padding-top:5px;padding-bottom:5px;font-size:14px;color:rgb(1,1,1);">
                        <b><i class="fa fa-info-circle"></i> You are Here:</b> 
                        <em>Lecturer > Exam Results</em>
                    </p>
                </div>
                <div class="col-md-2">
                </div>
            </div>
            
            <?php
                    if (empty($query)) { // add this check.
                        echo'<div class="alert alert-danger absolue center text-center" role="alert">
                                <span class="text-danger">Server side error occured</span>
                            </div>';
                    }else{
                    
                ?>
                <div class="row">
                    <div class="col-md-12">
                        <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'>

                        <div class="container">
                            <div class="row">

                                <div class="col-md-12 ">

                                    <div class="panel panel-default panel-table">
                                        
                                    <?php 
                                        if($rowcount<=0){
                                            echo'<div class="alert alert-danger absolue center text-center">
                                                    <strong class="text-danger">No faculty records found</strong>
                                                </div>';
                                        }else{
                                            
                                    ?>
                                        
                                        <div class="row" style="margin:0px;padding:0px;">
                                        <form method="POST">
                                            <div class="col col-md-12" style="margin:0px;padding:0px;">
                                                <?php include'validate/search.php'; ?>
                                            </div>
                                            <div class="col col-md-12" style="margin:0px;padding:0px;">
                                                <div class="col col-md-3">
                                                    <label>Course: <a class="text-danger">*</a></label>
                                                    <select class="form-control" required id="course" name="course">
                                                        <option value="" style='cursor:pointer;'>- Select Course -</option>
                                                        <?php 
                                                            if(empty($query)){
                                                                echo '<option class="bg-danger text-danger" value="">No faculty found</option>';
                                                            }else
                                                            {
                                                                while($row = mysql_fetch_array($query)) {
                                                        ?>
                                                        <optgroup label="<?php echo $row['name'];?>">
                                                            <?php 
                                                                $sqlx = "select * from `course` where `facultyID`=".mysql_real_escape_string($row['facultyID']);
                                                                $res = mysql_query($sqlx);
                                                                if(empty($res)){
                                                                    echo '<option class="bg-danger text-danger" value="">No course found</option>';
                                                                }else
                                                                if(mysql_num_rows($res) < 1) {
                                                                    echo '<option class="bg-danger text-danger" value="">No course found</option>';
                                                                }else{
                                                                    while($rw = mysql_fetch_array($res)) {
                                                            ?>
                                                            <option value="<?php echo $rw['courseID'];?>" 
                                                                <?php 
                                                                    if(isset($c) && isset($stat)=='1'){
                                                                        $cid = $c;

                                                                        if($cid==$rw['courseID']){
                                                                            echo "selected=selected";   
                                                                        }
                                                                    }
                                                                ?> 
                                                            style='cursor:pointer;'>
                                                                <?php echo $rw['name'];?>
                                                            </option>
                                                            <?php }} ?>
                                                        </optgroup>
                                                        <?php }} ?>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>Year of Study: <a class="text-danger">*</a></label>
                                                    <select class="form-control" required id="yos" name="yos">
                                                        <option value="" style='cursor:pointer;'>- Select YoS -</option>
                                                        <?php
                                                            if(isset($c)){
                                                                $sqli = mysql_query("select years from `course` where `courseID`=".$c);
                                                                $resi = mysql_fetch_array($sqli);
                                                                $yr = $resi['years'];
                                                                for($z=1;$z<=$yr;$z++){
                                                                    if($z == $y){
                                                                        echo "<option value='$z' selected='selected' style='cursor:pointer;'>Year $z</option>";
                                                                    }else{
                                                                        echo "<option value='$z' style='cursor:pointer;'>Year $z</option>";
                                                                    }
                                                                    
                                                                }
                                                               
                                                            }             
                                                        ?>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>Block: <a class="text-danger">*</a></label>
                                                    <select class="form-control" required name="block">
                                                        <option value="" style='cursor:pointer;'>- Select Block -</option>
                                                        <option value="1" style='cursor:pointer;' <?php if(isset($s)==1 && isset($stat)==1){echo 'selected';}?> >Block 1</option>
                                                        <option value="2" style='cursor:pointer;' <?php if(isset($s)==2 && isset($stat)==1){echo 'selected';}?> >Block 2</option>
                                                        <option value="3" style='cursor:pointer;' <?php if(isset($s)==3 && isset($stat)==1){echo 'selected';}?> >Block 3</option>
                                                    </select>
                                                </div>
                                                <div class="col col-md-3">
                                                    <label>Exam Category: <a class="text-danger">*</a></label>
                                                    <select class="form-control" id="exam" required name="exam">
                                                        <option value="" style='cursor:pointer;'>- Select Exam Category -</option>
                                                        <option value="CAT 1" <?php if(isset($e)=="CAT 1" && isset($stat)==1){echo 'selected';}?> style='cursor:pointer;'>CAT 1</option>
                                                        <option value="CAT 2" <?php if(isset($ee)=="CAT 2" && isset($stat)==1){echo 'selected';}?> style='cursor:pointer;'>CAT 2</option>
                                                        <option value="CAT 3" <?php if(isset($e)=="CAT 3" && isset($stat)==1){echo 'selected';}?> style='cursor:pointer;'>CAT 3</option>
                                                        <option value="Main Exam" <?php if(isset($e)=="Main Exam" && isset($stat)==1){echo 'selected';}?> style='cursor:pointer;'>Main Exam</option>
                                                        <option value="Practicals" <?php if(isset($e)=="Practicals" && isset($stat)==1){echo 'selected';}?> style='cursor:pointer;'>Practicals</option>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>&nbsp;</label>
                                                    <button class="form-control btn btn-primary" name="search1"><i class="fa fa-search"></i>&nbsp;Search</button>
                                                </div>
                                            </div>
                                        </form>
                                        <form method="POST">
                                            <div class="col col-md-12" style="margin:0px;padding:0px;">
                                                <?php include'validate/search_1.php'; ?>
                                            </div>
                                            <div class="col col-md-12" style="margin:10px 0px 0px 0px;padding:0px;background-color:#f6f6f6;">
                                                <div class="col col-md-3">
                                                    <label>Course: <a class="text-danger">*</a></label>
                                                    <select class="form-control" id="course1" name="course1">
                                                        <option value="" style='cursor:pointer;'>- Select Course -</option>
                                                        <?php 
                                                            if(empty($query)){
                                                                echo '<option class="bg-danger text-danger" value="">No faculty found</option>';
                                                            }else
                                                            {
                                                                mysql_data_seek($query,0);
                                                                while($row = mysql_fetch_array($query)) {
                                                        ?>
                                                        <optgroup label="<?php echo $row['name'];?>">
                                                            <?php 
                                                                $sqlx = "select * from `course` where `facultyID`=".mysql_real_escape_string($row['facultyID']);
                                                                $res = mysql_query($sqlx);
                                                                if(empty($res)){
                                                                    echo '<option class="bg-danger text-danger" value="">No course found</option>';
                                                                }else
                                                                if(mysql_num_rows($res) < 1) {
                                                                    echo '<option class="bg-danger text-danger" value="">No course found</option>';
                                                                }else{
                                                                    while($rw = mysql_fetch_array($res)) {
                                                            ?>
                                                            <option value="<?php echo $rw['courseID'];?>" 
                                                                <?php 
                                                                    if(isset($c1) && isset($stat1)==2){
                                                                        $cid = $c1;

                                                                        if($cid==$rw['courseID']){
                                                                            echo "selected=selected";   
                                                                        }
                                                                    }
                                                                ?> 
                                                            style='cursor:pointer;'>
                                                                <?php echo $rw['name'];?>
                                                            </option>
                                                            <?php }} ?>
                                                        </optgroup>
                                                        <?php }} ?>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>Current Class Year: <a class="text-danger">*</a></label>
                                                    <select class="form-control" required id="classYear" name="classYoS">
                                                        <option value="" style='cursor:pointer;'>- Class Year -</option>
                                                        <?php
                                                            if(isset($c1)){
                                                                $sqli = mysql_query("select years from `course` where `courseID`=".$c1);
                                                                mysql_data_seek($sqli, 0);
                                                                $resi = mysql_fetch_array($sqli);
                                                                $yr = $resi['years'];
                                                                for($z=1;$z<=$yr;$z++){
                                                                    if($z == $y1){
                                                                        echo "<option value='$z' selected='selected' style='cursor:pointer;'>Year $z</option>";
                                                                    }else{
                                                                        echo "<option value='$z' style='cursor:pointer;'>Year $z</option>";
                                                                    }
                                                                    
                                                                }
                                                               
                                                            }             
                                                        ?>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>Current Class Block: <a class="text-danger">*</a></label>
                                                    <select class="form-control" required id="classSem" name="classSem">
                                                        <option value="" style='cursor:pointer;'>- Class Block -</option>
                                                        <option value="1" <?php if(isset($s1)=='1' && isset($stat1)=='2'){echo 'selected';}?> style='cursor:pointer;'>Block 1</option>
                                                        <option value="2" <?php if(isset($s1)=='2' && isset($stat1)=='2'){echo 'selected';}?> style='cursor:pointer;'>Block 2</option>
                                                        <option value="3" <?php if(isset($s1)=='3' && isset($stat1)=='2'){echo 'selected';}?> style='cursor:pointer;'>Block 3</option>
                                                    </select>
                                                </div>
                                                <div class="col col-md-3">
                                                    <label>Exam Category: <a class="text-danger">*</a></label>
                                                    <select class="form-control" id="exam" required name="exam1">
                                                        <option value="" style='cursor:pointer;'>- Select Exam Category -</option>
                                                        <option value="CAT 1" <?php if(isset($e1)=="CAT 1" && isset($stat1)==2){echo 'selected';}?> style='cursor:pointer;'>CAT 1</option>
                                                        <option value="CAT 2" <?php if(isset($e1)=="CAT 2" && isset($stat1)==2){echo 'selected';}?> style='cursor:pointer;'>CAT 2</option>
                                                        <option value="CAT 3" <?php if(isset($e1)=="CAT 3" && isset($stat1)==2){echo 'selected';}?> style='cursor:pointer;'>CAT 3</option>
                                                        <option value="Main Exam" <?php if(isset($e1)=="Main Exam" && isset($stat1)==2){echo 'selected';}?> style='cursor:pointer;'>Main Exam</option>
                                                        <option value="Practicals" <?php if(isset($e1)=="Practicals" && isset($stat1)==2){echo 'selected';}?> style='cursor:pointer;'>Practicals</option>
                                                    </select>
                                                </div>
                                                <div class="col col-md-2">
                                                    <label>&nbsp;</label>
                                                    <button class="form-control btn-success" name="search2" style="color:white;"><i class="fa fa-search"></i>&nbsp;Search</button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                    <?php
                                        }
                                        if(empty($queryx)){
                                            echo'<div class="alert alert-danger absolue center text-center">
                                                    <strong class="text-danger">Error occured while trying to fetch exam results</strong>
                                                </div>';
                                        }else{
                                    ?>
                                        <div class="container">
                                            <div>
                                                <form method="POST" enctype="multipart/form-data">
                                                    <div class="form-group" style="margin-top:30px;">
                                                        <div class="row" style="margin-right:0px;margin-left:0px;padding-top:10px;">
                                                            <div class="col-md-12">
                                                                <table class="table table-striped" id="myTable">
                                                                    <thead style="background-color:rgb(62,140,228);color:rgb(252,254,255);">
                                                                      <tr>
                                                                          <th>#</th>
                                                                          <th>Code</th>
                                                                          <th>Category</th>
                                                                          <th>Faculty</th>
                                                                          <th>Course</th>
                                                                          <th>Unit</th>
                                                                          <th>YOS / Block</th>
                                                                          <th>Added</th>
                                                                          <th>Added by</th>
                                                                          <th align="center">Marks</th>
                                                                      </tr> 
                                                                    </thead>
                                                                    <tbody>
                                                                          <?php 
                                                                              if($rowcountx<=0){
                                                                                  echo'<tr>
                                                                                          <td colspan="12">
                                                                                              <div class="alert alert-danger absolue center text-center">
                                                                                                  <strong class="text-danger">No records found</strong>
                                                                                              </div>
                                                                                          </td>
                                                                                      </tr>';
                                                                              }else{
                                                                                  $i=$p=$s=$q=$r=$a=$b=$t=$x=$m=$n=$y=$c=$d=$z=1;
                                                                                  while ($row = mysql_fetch_array($queryx)) {

                                                                              ?>
                                                                            <tr>
                                                                              <td align="center"><?php echo $r++; ?></td>
                                                                              <td>
                                                                                    <a href="#myModal<?php echo $x++;?>" data-toggle="modal" class="text-info" role="button" style="cursor:pointer;" title="View students score">
                                                                                        <?php echo $row['code']; ?>
                                                                                    </a>
                                                                                    
                                                                                    <div role="dialog" tabindex="-1" class="modal fade" id="myModal<?php echo $t++;?>">
                                                                                    <div class="modal-dialog modal-lg" role="document">
                                                                                        <div class="modal-content">
                                                                                            <div class="modal-header">
                                                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                                                                <button type="submit" class="print" onclick="PrintElem('#printReport')" style="padding:5px 20px;color:rgb(1,1,1);">
                                                                                                    <i class="fa fa-print"></i> Print
                                                                                                </button>
                                                                                            </div>
                                                                                            <div id="printReport">
                                                                                                <div class="modal-body">
                                                                                                    <div class="row" style="width:100%;color:black;">
                                                                                                        <div class="col-md-12 text-center" style="text-align:center;width:100%;">
                                                                                                            <img src="../../../assets/img/logo.png" style="width:100px;" align="center">
                                                                                                        </div>
                                                                                                        <div class="col-md-12 text-center" style="text-align:center;width:100%;">
                                                                                                            <h2 style="font-weight:bold;;">WAKA CMEC SCHOOL OF <?php echo strtoupper($row['faculty']);?>, STUDENTS' <?php echo strtoupper($row['category']);?> RESULTS</h2>
                                                                                                        </div>
                                                                                                        
                                                                                                        <div class="col-md-12 text-center" style="width:100%;font-size:14px;">
                                                                                                            <p><b>Course:</b> <?php echo $row['course'];?> <b>Unit:</b> <?php echo $row['unit'];?>
                                                                                                                <br>
                                                                                                                <b>Year:</b> <?php echo $row['year'];?>  <b>Block:</b> <?php echo $row['sem'];?> <b>Total Marks:</b>&nbsp;<?php echo $row['total'];?>
                                                                                                            </p>
                                                                                                        </div>
                                                                                                        <div class="col-md-12 text-center" style="width:100%;font-size:14px;">
                                                                                                            <p><?php echo date_format(date_create($row['added']),"D d M. Y"); ?>  &nbsp; | <em>Admin print</em></p>
                                                                                                        </div>
                                                                                                        <div class="col-md-12" style="width:100%;">
                                                                                                            <table border="1" style="width:100%;font-size:12px;color:black;">
                                                                                                                <thead style="background-color:#f1f1f1;">
                                                                                                                    <tr>
                                                                                                                        <th style="text-align:center;font-weight:bold;">#</th>
                                                                                                                        <th style="text-align:center;font-weight:bold;">Student</th>
                                                                                                                        <th style="text-align:center;font-weight:bold;">Score</th>
                                                                                                                        <th style="text-align:center;font-weight:bold;">Percentage %</th> 
                                                                                                                    </tr>
                                                                                                                </thead>

                                                                                                                <tbody>
                                                                                                                    <?php 
                                                                                                                        $s=1;

                                                                                                                        $querys = mysql_query("SELECT adm,marks,percentage FROM $tableName4 WHERE code='". $row['code']."' ORDER BY `percentage` DESC");
                                                                                                                        $rowcounts=  mysql_num_rows($querys);
                                                                                                                        while($rows = mysql_fetch_array($querys)) { 
                                                                                                                    ?>
                                                                                                                        <tr>
                                                                                                                            <td style="text-align:center;"><?php echo $s++;?></td>
                                                                                                                            <td style="text-align:center;"><?php echo $rows['adm'];?></td> 
                                                                                                                            <td style="text-align:center;"><?php echo $rows['marks'];?></td>
                                                                                                                            <td style="text-align:center;"><?php echo round($rows['percentage']); ?></td>
                                                                                                                        </tr>
                                                                                                                    <?php } ?>
                                                                                                                <tbody>    
                                                                                                            </table>
                                                                                                        </div>

                                                                                                        <div class="col-md-12" style="width:100%;text-align:center;margin-top:10px;font-size:12px;">
                                                                                                            <hr>
                                                                                                            <p>WAKA Continuing Medical Education Center (CMEC) - P.O Box 188-10100, Nyeri Kenya.</p>
                                                                                                            <p><b>Email:</b> <a style="text-decoration:none;">wakacmec@gmail.com</a></p>
                                                                                                            <p><b>Tel:</b> <a style="text-decoration:none;">0707472152</a> / <a style="text-decoration:none;">0788307979</a> / <a style="text-decoration:none;">0722963213</a></p>
                                                                                                        </div>
                                                                                                    </div>
                                                                                                </div>
                                                                                            </div>
                                                                                            <div class="modal-footer">
                                                                                                <button type="button" data-dismiss="modal" style="padding:5px 20px;color:rgb(1,1,1);">Close</button>
                                                                                            </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                              </td>
                                                                              <td><?php echo $row['category']; ?></td>
                                                                              <td><?php echo $row['faculty']; ?></td>
                                                                              <td><?php echo $row['course']; ?></td>
                                                                              <td><?php echo $row['unit']; ?></td>
                                                                              <td><?php echo "Yr.".$row['year'].", Block ".$row['sem']; ?></td>
                                                                              <td><?php echo date_format(date_create($row['added']),"D d,M. Y"); ?></td>
                                                                              <td><?php echo $row['added_by']; ?></td>
                                                                              <td><?php echo $row['total']; ?></td>
                                                                            </tr>
                                                                          <?php }}?>  
                                                                      </tbody>
                                                                  </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>   
                                    </div>
                                    <?php }?>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
    <script src="../../../assets/js/jquery.min.js"></script>
    <script src="../../../assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
    <script src="../../../assets/js/ebs-simple-login-form.js"></script>
    <script src="../../../assets/js/JLX-Fixed-Nav-on-Scroll.js"></script>
    <script src="../../../assets/js/Profile-Edit.js"></script>
    <script src="../../../assets/js/Sidebar-Menu.js"></script>
    
    <script type="text/javascript">
            $(document).ready(function(){
            setInterval(function(){
                $("#notificationCounter").load("include/counter_3.php");
                $("#requestCounter").load("include/counter.php");
                $("#expiredCounter").load("include/counter_2.php");
                $("#expiredLeaveCounter").load("include/counter_2_1.php");
                $("#requestLeaveCounter").load("include/counter_4.php");
            }, 500); /* time in milliseconds (ie 2 seconds)*/
        });
    </script>
</body>
    <script>
        $(document).ready(function(){
            $('#myTable').dataTable();
        });
    </script>
</html>