<?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 staffID ='$staffID' AND 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
                    FROM (
                        SELECT MAX(resultsID) AS resultsID,category,code,total,added,unitID,
                                            unit,course,faculty,year,sem
                        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
                    FROM (
                        SELECT MAX(resultsID) AS resultsID,category,code,total,added,unitID,
                                            unit,course,faculty,year,sem
                        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 a.staffID='$staffID'
                            AND 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>Exams Results | Lecturer | 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+Slab:300,400|Roboto:300,400,700">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.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/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="../../../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-Fixed-Side1.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/Data-Table.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table1.css">
    
    <script>
        function PrintElem(elem)
        {
            Popup($(elem).html());
        }

        function Popup(data) 
        {

            var mywindow = window.open('', 'printReport', 'height=500,width=700');
            mywindow.document.write('<html><head><title></title>');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,700"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Roboto:300,400,700"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Romanesco"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css"  media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css"  media="print">');
            
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/Data-Table.css" media="print">');
            mywindow.document.write('<link rel="stylesheet" href="../../../assets/css/Data-Table1.css" media="print">');
            
            mywindow.document.write('</head><body >');
            mywindow.document.write(data);
            mywindow.document.write('</body></html>');

            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10

            mywindow.print();
            mywindow.close();

            return true;
        }
    </script>
</head>

<body style="background-color:rgb(252,252,252);">
    <div></div>
    <div id="wrapper">
        <div id="sidebar-wrapper" style="background-color:rgb(62,140,228);">
            <ul class="sidebar-nav">
                <li class="sidebar-brand" style="color:rgb(255,255,255);"> 
                    <a href="#" style="font-weight:bold;color:rgb(254,254,254);">Lecturer | WAKA CMEC</a>
                </li>
                <li style="color:rgb(252,253,254);"> 
                    <a href="index.php" style="color:rgb(255,255,255);">Home</a>
                    <a href="course-work.php" style="color:rgb(255,255,255);">Course Work</a>
                    <a href="view-assignments.php" style="color:rgb(255,255,255);">View Assignments</a>
                    <a href="exam.php" style="color:rgb(255,255,255);">View Exam</a>
                    <a href="assigned-units.php" style="color:rgb(255,255,255);">View Units</a>
                </li>
            </ul>
        </div>
        <div class="page-content-wrapper">
            <div class="container-fluid"><a class="btn btn-link" role="button" href="#menu-toggle" id="menu-toggle"><i class="fa fa-bars"></i></a>
                <div class="dropdown" style="width:150px;float:right;margin-top:5px;">
                    <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" type="button" style="width:150px;background-color:rgb(252,252,252);color:rgb(20,19,19);border:1px solid rgb(252,252,252);text-align:right;"><i class="fa fa-user"></i> &nbsp; <?php echo $lec;?> <span class="caret"></span></button>
                    <ul role="menu" class="dropdown-menu dropdown-menu-right">
                        <li role="presentation"><a href="settings.php"><i class="fa fa-wrench"></i> &nbsp;Settings</a></li>
                        <li role="presentation"><a href="../validate/logout.php"><i class="fa fa-power-off"></i> &nbsp; Logout</a></li>
                    </ul>
                </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">
                                        <div class="panel-heading">
                                            <div class="row">
                                              <div class="col col-xs-12">
                                                <h3 class="panel-title">
                                                    <em class="fa fa-book"></em> 
                                                    <b>View Exam Results</b>
                                                 </h3>
                                              </div>
                                            </div>
                                        </div>
                                        
                                    <?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 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"); ?></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['total']; ?></td>
                                                                            </tr>
                                                                          <?php }}?>  
                                                                      </tbody>
                                                                  </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>   
                                    </div>
                                    <?php }?>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>
            <?php } ?>
        </div>
    </div>
    <script src="../../../assets/js/jquery.min.js"></script>
    <script src="../../../assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../../assets/js/ebs-simple-login-form.js"></script>
    <script src="../../../assets/js/Profile-Edit.js"></script>
    <script src="../../../assets/js/Sidebar-Menu.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="ajax.js"></script>
    <script>
        $(document).ready(function(){
            $('#myTable').dataTable();
        });
    </script>
</body>
</html>