<?php
namespace App\Controllers;
SESSION_START();
use \Core\View;
use \Core\Inputs;
use \Core\Userlog;
use \Core\Menu;
use \Core\Form;
use App\Models\Homem;
use App\Email\Emails;
class Main extends \Core\Controller
{
    public static function creditcalculation()
    {
        $data = Homem::getdata("SELECT `no`,`name` FROM `user_master` WHERE `fk_course_id`='2' AND `fromyear`='2022'");
        $d = Homem::getdata("SELECT rd.* FROM user_master um JOIN results_data rd ON um.no=rd.ht_no WHERE um.fk_course_id='2' AND um.fromyear='2022'");
        $a ='';
        $year = 2;
        $sem = 2;
        $a .= '<table border="1px">';
        for($i=0; $i<sizeof($data); $i++)
        {
            $a .= '<tr>';
            $a .= '<td>'.$data[$i]["no"].'</td>';
            $a .= '<td>'.$data[$i]["name"].'</td>';
            for($j=1; $j<=$year; $j++)
            {
                for($k=1; $k<=$sem; $k++)
                {
                    $sum = 0;
                    for($l=0; $l<sizeof($d); $l++)
                    {
                        if($data[$i]["no"] == $d[$l]["ht_no"] && $j == $d[$l]["year"]  && $k == $d[$l]["sem"])
                        {
                            $sum = $sum + (float)$d[$l]["credit"];
                        }
                    }
                    $a .= '<td>'.$sum.'</td>';
                }
            }
            $a .= '</tr>';
        }
        $a .= '</table>';
        echo $a;
    }
    public static function resultsavalable()
    {
        $data = Homem::getdata("SELECT DISTINCT `resultdate`, `year`, `sem`, `exammonth`, `examyear`, `fk_course_id` FROM `results_data`");
        echo json_encode($data);
    }
    public static function creditscount()
    {
        
    }
    public static function testa()
    {
        // header('content-type: text/xml;charset=utf-8');
        $htno = '192x1a0501';
        $orgid = '3';
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => "http://localhost/Main/studentapi",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_POSTFIELDS =>"{\"apikey\":\"s.krishnarjuna@gmail.com\", \"secrectkey\":\"SSRSKJR\", \"htno\":\"$htno\", \"orgid\":\"$orgid\"}",
        CURLOPT_HTTPHEADER => array(
            ": ",
            "Content-Type: application/json"
        ),
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $da = json_decode($response, true);
        if($da['statuscode'] == 200)
        {
            echo base64_decode($da['emailstatus']);
        }
        else
        {
            echo 'test';
        }
    }
    public static function studentapi()
    {
        header('Content-type:application/json;charset=utf-8');
        $data = null;
        $json = file_get_contents('php://input');    
        if(static::isJSON($json))
        {
            $data = json_decode($json);
        }
        if($data != null)
        {
            $apikey = $data->apikey;
            $secretkey = $data->secrectkey;
            $htno = $data->htno;
            $orgid = $data->orgid;
            if($apikey=="s.krishnarjuna@gmail.com" && $secretkey == "SSRSKJR")
            {
                $return["emailstatus"] = static::studentresultfinalapi($htno, $orgid);
                $return["statuscode"] = 200;
                $return["success"] = true;
                $return["message"] = "Data Succesfully Posted..";
                echo json_encode($return);
            } 
            else
            {
                $return["statuscode"] = 400;
                $return["success"] = false;
                $return["message"] = "Credentials are wrong..";
                echo json_encode($return);
            } 
        }
        else
        {
            $return["statuscode"] = 400;
            $return["success"] = false;
            $return["message"] = "Bad Request. Data Missing / Not a valid format.";
            echo json_encode($return);
        } 
    }
    public static function studentresultfinalapi($htno, $orgid)
    {
        $a = '';
        {
            if(isset($htno))
            {
                $_SESSION['org_id'] = $orgid;
                $std = '';
                $data = Homem::getdata("SELECT rd.*, ugg.grade as gradepoint, ugg.failstatus FROM results_data rd JOIN ug_grademarks ugg ON ugg.level=rd.grade WHERE rd.ht_no='$htno' ORDER BY rd.resultdate DESC");
                $sdata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='htno'");
                if(sizeof($sdata) ==1)
                {
                    $std .= '<tr><th colspan="2">Name</th><th colspan="8">'.$sdata[0]['name'].'</th></tr>';
                    $std .= '<tr><th colspan="2">HallTicket Number</th><th colspan="8">'.$sdata[0]['no'].'</th></tr>';
                }
                $crse = array();
                $yer = array();
                $sm = array();
                $subcode = array();
                $subname = array();
                $rdate = array();
                foreach ($data as $h) {
                    $crse[] = $h['fk_course_id'];
                    $yer[] = $h['year'];
                    $sm[] = $h['sem'];
                    $subcode[] = $h['sub_code'];
                    $subname[] = $h['sub_name'];
                    $rdate[] = $h['resultdate'];
                }
                $course = array_values(array_unique($crse));
                sort($course);
                $year = array_values(array_unique($yer));
                sort($year);
                $sem = array_values(array_unique($sm));
                sort($sem);
                $sub_code = array_values(array_unique($subcode));
                sort($sub_code);
                $sub_name = array_values(array_unique($subname));
                sort($sub_name);
                $resultdate = array_values(array_unique($rdate));
                sort($resultdate);
                if(sizeof($course) ==1)
                {
                    if($course[0] == 2)
                    {
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                $sub_code_name[$sub_code[$i]] = $data[$j]['sub_code'];
                            }
                        }
                        for($i=0; $i<sizeof($year); $i++)
                        {
                            for($j=0; $j<sizeof($sem); $j++)
                            {
                                $year_sem_sub[$year[$i]][$sem[$j]] = array();
                                for($k=0; $k<sizeof($sub_code); $k++)
                                {
                                    for($l=0; $l<sizeof($data); $l++)
                                    {
                                        if($data[$l]['year'] == $year[$i] && 
                                        $data[$l]['sem'] == $sem[$j] &&
                                        $data[$l]['sub_code'] == $sub_code[$k])
                                        {
                                            $year_sem_sub[$year[$i]][$sem[$j]][] = $data[$l]['sub_code'];
                                            $year_sem_sub1[$year[$i]][$sem[$j]][$data[$l]['sub_code']] = $data[$l]['sub_code'];
                                            break;
                                        }
                                    }
                                }    
                            }
                        }
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            $a = 0;
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['sub_code'] == $sub_code[$i])
                                {
                                    if($a == 0)
                                    {
                                        $sub_data[$sub_code[$i]]['grade'] = $data[$j]['grade'];
                                        $sub_data[$sub_code[$i]]['gradepoint'] = $data[$j]['gradepoint'];
                                        $sub_data[$sub_code[$i]]['credit'] = $data[$j]['credit'];
                                        $sub_data[$sub_code[$i]]['failstatus'] = $data[$j]['failstatus'];
                                        $sub_data[$sub_code[$i]]['sub_name'] = $data[$j]['sub_name'];
                                        $sub_data[$sub_code[$i]]['resultdate'] = $data[$j]['resultdate'];
                                        $sub_data[$sub_code[$i]]['sub_code'] = $data[$j]['sub_code'];
                                        $sub_data[$sub_code[$i]]['month'] = $data[$j]['exammonth'];
                                        $sub_data[$sub_code[$i]]['year'] = $data[$j]['examyear'];
                                        $sub_data[$sub_code[$i]]['examtype'] = $data[$j]['examtype'];
                                    }
                                    $a++;
                                }
                                if($j == sizeof($data)-1)
                                {
                                    if($a > 0)
                                    {
                                        $sub_data[$sub_code[$i]]['count'] = $a;
                                    }
                                }
                            }
                        }
                        $a = '';
                        $a .= '<div class="table-responsive" id="exporttable">';													
                        $a .= '<table class="table table-responsive-sm print-this" border="1px">';
                        $a .= $std;
                        if(sizeof($course) == 1)
                        {
                            if($course[0] == 2)
                            {
                                for($i=0; $i<sizeof($year); $i++)
                                {
                                    for($j=0; $j<sizeof($sem); $j++)
                                    {
                                        $b = 0;
                                        for($k=0; $k<sizeof($sub_code); $k++)
                                        {
                                            if(sizeof($year_sem_sub[$year[$i]][$sem[$j]])>0)
                                            {
                                                if(isset($year_sem_sub1[$year[$i]][$sem[$j]][$sub_code[$k]]))
                                                {
                                                    if($b == 0)
                                                    {
                                                        $a .= '<tr><th colspan="10">'.static::yearandsem($year[$i], $sem[$j]).'</th></tr>';
                                                        $a .= '<tr><th>Subject Code</th><th>Subject Name</th><th>Grade</th><th>Points</th><th>Credits</th><th>Month</th><th>Year</th><th>Type</th><th>Date</th><th>Status</th></tr>';
                                                    }
                                                    $a .= '<tr>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_code'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_name'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['grade'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['gradepoint'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['credit'].'</td>';
                                                    $a .= '<td>'.static::month($sub_data[$sub_code[$k]]['month']).'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['year'].'</td>';
                                                    $a .= '<td>'.static::resulttype($sub_data[$sub_code[$k]]['examtype'], $sub_data[$sub_code[$k]]['count']).'</td>';
                                                    $a .= '<td>'.static::datem($sub_data[$sub_code[$k]]['resultdate']).'</td>';
                                                    $a .= '<td>'.static::resultstatus($sub_data[$sub_code[$k]]['failstatus'], $course[0]).'</td>';
                                                    $a .= '</tr>';
                                                    $b++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $a .= '</tbody>';
                        $a .= "</table>";
                        $a .= "</div>";
                    }
                }
            }
            return base64_encode($a);
        }
    }
    public static function studentresultfinalapiurl()
    {
        $a = '';
        {
            if(isset($_GET['htno']))
            {
                $_SESSION['org_id'] = $_GET['orgid'];
                $std = '';
                $data = Homem::getdata("SELECT rd.*, ugg.grade as gradepoint, ugg.failstatus FROM results_data rd JOIN ug_grademarks ugg ON ugg.level=rd.grade WHERE rd.ht_no='$_GET[htno]' ORDER BY rd.resultdate DESC");
                $sdata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_GET[htno]'");
                if(sizeof($sdata) ==1)
                {
                    $std .= '<tr><th colspan="2">Name</th><th colspan="8">'.$sdata[0]['name'].'</th></tr>';
                    $std .= '<tr><th colspan="2">HallTicket Number</th><th colspan="8">'.$sdata[0]['no'].'</th></tr>';
                }
                $crse = array();
                $yer = array();
                $sm = array();
                $subcode = array();
                $subname = array();
                $rdate = array();
                foreach ($data as $h) {
                    $crse[] = $h['fk_course_id'];
                    $yer[] = $h['year'];
                    $sm[] = $h['sem'];
                    $subcode[] = $h['sub_code'];
                    $subname[] = $h['sub_name'];
                    $rdate[] = $h['resultdate'];
                }
                $course = array_values(array_unique($crse));
                sort($course);
                $year = array_values(array_unique($yer));
                sort($year);
                $sem = array_values(array_unique($sm));
                sort($sem);
                $sub_code = array_values(array_unique($subcode));
                sort($sub_code);
                $sub_name = array_values(array_unique($subname));
                sort($sub_name);
                $resultdate = array_values(array_unique($rdate));
                sort($resultdate);
                if(sizeof($course) ==1)
                {
                    if($course[0] == 2)
                    {
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                $sub_code_name[$sub_code[$i]] = $data[$j]['sub_code'];
                            }
                        }
                        for($i=0; $i<sizeof($year); $i++)
                        {
                            for($j=0; $j<sizeof($sem); $j++)
                            {
                                $year_sem_sub[$year[$i]][$sem[$j]] = array();
                                for($k=0; $k<sizeof($sub_code); $k++)
                                {
                                    for($l=0; $l<sizeof($data); $l++)
                                    {
                                        if($data[$l]['year'] == $year[$i] && 
                                        $data[$l]['sem'] == $sem[$j] &&
                                        $data[$l]['sub_code'] == $sub_code[$k])
                                        {
                                            $year_sem_sub[$year[$i]][$sem[$j]][] = $data[$l]['sub_code'];
                                            $year_sem_sub1[$year[$i]][$sem[$j]][$data[$l]['sub_code']] = $data[$l]['sub_code'];
                                            break;
                                        }
                                    }
                                }    
                            }
                        }
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            $a = 0;
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['sub_code'] == $sub_code[$i])
                                {
                                    if($a == 0)
                                    {
                                        $sub_data[$sub_code[$i]]['grade'] = $data[$j]['grade'];
                                        $sub_data[$sub_code[$i]]['gradepoint'] = $data[$j]['gradepoint'];
                                        $sub_data[$sub_code[$i]]['credit'] = $data[$j]['credit'];
                                        $sub_data[$sub_code[$i]]['failstatus'] = $data[$j]['failstatus'];
                                        $sub_data[$sub_code[$i]]['sub_name'] = $data[$j]['sub_name'];
                                        $sub_data[$sub_code[$i]]['resultdate'] = $data[$j]['resultdate'];
                                        $sub_data[$sub_code[$i]]['sub_code'] = $data[$j]['sub_code'];
                                        $sub_data[$sub_code[$i]]['month'] = $data[$j]['exammonth'];
                                        $sub_data[$sub_code[$i]]['year'] = $data[$j]['examyear'];
                                        $sub_data[$sub_code[$i]]['examtype'] = $data[$j]['examtype'];
                                    }
                                    $a++;
                                }
                                if($j == sizeof($data)-1)
                                {
                                    if($a > 0)
                                    {
                                        $sub_data[$sub_code[$i]]['count'] = $a;
                                    }
                                }
                            }
                        }
                        $a = '';
                        $a .= '<div class="table-responsive" id="exporttable">';													
                        $a .= '<table class="table table-responsive-sm print-this" border="1px">';
                        $a .= $std;
                        if(sizeof($course) == 1)
                        {
                            if($course[0] == 2)
                            {
                                for($i=0; $i<sizeof($year); $i++)
                                {
                                    for($j=0; $j<sizeof($sem); $j++)
                                    {
                                        $b = 0;
                                        for($k=0; $k<sizeof($sub_code); $k++)
                                        {
                                            if(sizeof($year_sem_sub[$year[$i]][$sem[$j]])>0)
                                            {
                                                if(isset($year_sem_sub1[$year[$i]][$sem[$j]][$sub_code[$k]]))
                                                {
                                                    if($b == 0)
                                                    {
                                                        $a .= '<tr><th colspan="10">'.static::yearandsem($year[$i], $sem[$j]).'</th></tr>';
                                                        $a .= '<tr><th>Subject Code</th><th>Subject Name</th><th>Grade</th><th>Points</th><th>Credits</th><th>Month</th><th>Year</th><th>Type</th><th>Date</th><th>Status</th></tr>';
                                                    }
                                                    $a .= '<tr>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_code'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_name'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['grade'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['gradepoint'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['credit'].'</td>';
                                                    $a .= '<td>'.static::month($sub_data[$sub_code[$k]]['month']).'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['year'].'</td>';
                                                    $a .= '<td>'.static::resulttype($sub_data[$sub_code[$k]]['examtype'], $sub_data[$sub_code[$k]]['count']).'</td>';
                                                    $a .= '<td>'.static::datem($sub_data[$sub_code[$k]]['resultdate']).'</td>';
                                                    $a .= '<td>'.static::resultstatus($sub_data[$sub_code[$k]]['failstatus'], $course[0]).'</td>';
                                                    $a .= '</tr>';
                                                    $b++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $a .= '</tbody>';
                        $a .= "</table>";
                        $a .= "</div>";
                    }
                }
            }
            echo $a;
        }
    }
    public static function isJSON($string)
    {
        return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
    }
    public static function RemoveSpecialChar($str)
    { 
        $res = str_ireplace( array( '\'', 'â', '¦', '€'), '', $str); 
        return $res; 
    } 
    private static function mainsessioncontrol()
    {
        if($_SESSION['org_id'] == 3)
        {
            if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 9)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
    private static function css()
    {
        $css = 
        '<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/style.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.css" >
            <style>
                @media print
                {
                    body * {
                        visibility: hidden;
                    }
                    .print-this, .print-this * {
                        visibility: visible;
                    }
                }
            </style>
            <script>
                function exportTableToExcel(tableID, filename = "")
                {
                    var downloadLink;
                    var dataType = "application/vnd.ms-excel";
                    var tableSelect = document.getElementById(tableID);
                    var tableHTML = tableSelect.outerHTML.replace(/ /g, "%20");
                    
                    // Specify file name
                    filename = filename?filename+".xls":"excel_data.xls";
                    
                    // Create download link element
                    downloadLink = document.createElement("a");
                    
                    document.body.appendChild(downloadLink);
                    
                    if(navigator.msSaveOrOpenBlob){
                        var blob = new Blob(["\ufeff", tableHTML], {
                            type: dataType
                        });
                        navigator.msSaveOrOpenBlob( blob, filename);
                    }else{
                        // Create a link to the file
                        downloadLink.href = "data:" + dataType + ", " + tableHTML;
                    
                        // Setting the file name
                        downloadLink.download = filename;
                        
                        //triggering the function
                        downloadLink.click();
                    }
                }
            </script>
        </head>';
        return $css;  
    }
    private static function script()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/vendor/sweetalert2/dist/sweetalert2.min.js" ></script>';
        return $script;  
    }
    private static function normalmenu()
    {
        // bg-light
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light ">
                <a class="navbar-brand" href="#" >HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ml-auto navbar-right">
                    
                    <li class="nav-item active" >
                        <a class="nav-link" href="/Homes/index" >Home</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/homes/latest" >Latest News</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/homes/suggestions" >Suggestions</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/homes/contactus" >Contact Us</a>
                    </li>
                    <!--
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Dropdown
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="#">Action</a>
                        <a class="dropdown-item" href="#">Another action</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#">Something else here</a>
                        </div>
                    </li>
                    -->
                    </ul>
                    <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
                    </form>
                </div>
            </nav>
        ';
        return $menu;
    }
    public static function home()
    {
        if(static::mainsessioncontrol()==1)
        {  
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">
                            <!--Welcome to HINDU COLLEGE-->
                            <!--
                                <div class="table-responsive">
                                    <table class="table table-responsive-sm">
                                        <thead>
                                            <tr>
                                                <th>Hour Number</th>
                                                <th>From Time</th>
                                                <th>To Time</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div>
                            -->
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    /**
     * Student marks uploading bulk - started
     */
    public static function uploadstdmarksbulk()
    {
        // if(static::mainsessioncontrol() == 1)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Main/saveuploadstdmarksbulk" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Bulk Students Marks</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                <input type="file" name="file" id="file" class="form-control" placeholder="Category Name">
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">   
                                                                <input type="hidden" name="type" id="type" class="form-control" value="bulk" placeholder="Type">                                         
                                                                <a href="/hindu/formats/stdnt_marks_bulkupload_format.csv">Click Here to Download Uploading Format</a>
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Main/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }   
    public static function saveuploadstdmarksbulk()
    {
        // if(static::mainsessioncontrol() == 1)
        {
            $date = date('Y-m-d');
            if($_POST['type'] == 'bulk')
            {
                $filename=$_FILES['file']['name'];
                $exts[0]='csv';
                $filetype1 = explode('.',$filename);
                if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
                {
                    $csv_file=$_FILES['file']['tmp_name'];
                    $size=$_FILES['file']['size'];
                    $handle = fopen($csv_file, "r");
                    $data = fgetcsv($handle, 100000, ",");
                    $i = 0;
                    while (($data = fgetcsv($handle, 100000, ","))!== FALSE)
                    {
                        $course = trim($data[0]);
                        $regulation = trim($data[1]);
                        $year = trim($data[2]);
                        $sem = trim($data[3]);
                        $htno = trim($data[4]);
                        $subcode = trim($data[5]);
                        $subname = trim($data[6]);
                        $grade = trim($data[7]);
                        $credits = trim($data[8]);
                        $resulttype = trim($data[9]);
                        $exammonth = trim($data[10]);
                        $examyear = trim($data[11]);
                        $paid_date = trim($data[12]);
                    $resultdate =static::datemodify($paid_date);
                        // $resultdate = '2022-04-08';
                        if($htno != '' && $subcode !='')
                        {
                            $query = "INSERT INTO `results_data` (`id`, `year`, `sem`, `ht_no`, `sub_code`, `sub_name`, `internal`, `external`, `grade`, `credit`, `exammonth`, `examyear`, `resultdate`, `result_type`, `examtype`, `fk_user_id`, `status`, `fk_org_id`, `fk_course_id`) VALUES (NULL, '$year', '$sem', '$htno', '$subcode', '$subname', '', '', '$grade', '$credits', '$exammonth', '$examyear', '$resultdate', '$resulttype', '$resulttype', '$_SESSION[user_id]', '1', '$_SESSION[org_id]', '$course')";
                            Homem::insert($query);
                            $i++;
                        }
                    }
                    echo '<script>window.location = "/Main/uploadstdmarksbulk?status=1&count='.$i.'";</script>';
                }
            }
        }
    }
    private static function month($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Jan';
            }
            if($id == 2)
            {
                return 'Feb';
            }
            if($id == 3)
            {
                return 'Mar';
            }
            if($id == 4)
            {
                return 'Apr';
            }
            if($id == 5)
            {
                return 'May';
            }
            if($id == 6)
            {
                return 'June';
            }
            if($id == 7)
            {
                return 'July';
            }
            if($id == 8)
            {
                return 'Aug';
            }
            if($id == 9)
            {
                return 'Sept';
            }
            if($id == 10)
            {
                return 'Oct';
            }
            if($id == 11)
            {
                return 'Nov';
            }
            if($id == 12)
            {
                return 'Dec';
            }
        }
    }
    private static function resulttype($id, $count)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($id == 1 && $count == 1)
            {
                return 'REG';
            }
            else if($id == 1 && $count > 1)
            {
                return 'SUP';
            }
            else if($id == 2)
            {
                return 'REV';
            }
            else
            {
                return 'REG/SUP';
            }
        }
    }
    private static function resultstatus($id, $course)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($id == 1 && $course == 2)
            {
                return 'FAIL';
            }
            if($id == 0 && $course == 2)
            {
                return 'PASS';
            }
        }
    }
    private static function yearandsem($year, $sem)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($year == 1 && $sem == 1)
            {
                return 'First Year - First Sem';
            }
            if($year == 1 && $sem == 2)
            {
                return 'First Year - Second Sem';
            }
            if($year == 2 && $sem == 1)
            {
                return 'Second Year - First Sem';
            }
            if($year == 2 && $sem == 2)
            {
                return 'Second Year - Second Sem';
            }
            if($year == 3 && $sem == 1)
            {
                return 'Third Year - First Sem';
            }
            if($year == 3 && $sem == 2)
            {
                return 'Third Year - Second Sem';
            }
            if($year == 4 && $sem == 1)
            {
                return 'Fourth Year - First Sem';
            }
            if($year == 4 && $sem == 2)
            {
                return 'Fourth Year - Second Sem';
            }
        }
    }
    public static function studentresultfinal()
    {
        $a = '';
        // if(static::mainsessioncontrol() == 1)
        {
            if(isset($_POST['htno']))
            {
                $std = '';
                $data = Homem::getdata("SELECT rd.*, ugg.grade as gradepoint, ugg.failstatus FROM results_data rd JOIN ug_grademarks ugg ON ugg.level=rd.grade WHERE rd.ht_no='$_POST[htno]' AND ugg.regulation=rd.regulation ORDER BY rd.resultdate DESC");
                $sdata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[htno]'");
                if(sizeof($sdata) ==1)
                {
                    $std .= '<tr><th colspan="2">Name</th><th colspan="8">'.$sdata[0]['name'].'</th></tr>';
                    $std .= '<tr><th colspan="2">HallTicket Number</th><th colspan="8">'.$sdata[0]['no'].'</th></tr>';
                }
                $crse = array();
                $yer = array();
                $sm = array();
                $subcode = array();
                $subname = array();
                $rdate = array();
                foreach ($data as $h) {
                    $crse[] = $h['fk_course_id'];
                    $yer[] = $h['year'];
                    $sm[] = $h['sem'];
                    $subcode[] = $h['sub_code'];
                    $subname[] = $h['sub_name'];
                    $rdate[] = $h['resultdate'];
                }
                $course = array_values(array_unique($crse));
                sort($course);
                $year = array_values(array_unique($yer));
                sort($year);
                $sem = array_values(array_unique($sm));
                sort($sem);
                $sub_code = array_values(array_unique($subcode));
                sort($sub_code);
                $sub_name = array_values(array_unique($subname));
                sort($sub_name);
                $resultdate = array_values(array_unique($rdate));
                sort($resultdate);
                if(sizeof($course) ==1)
                {
                    if($course[0] == 2)
                    {
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                $sub_code_name[$sub_code[$i]] = $data[$j]['sub_code'];
                            }
                        }
                        for($i=0; $i<sizeof($year); $i++)
                        {
                            for($j=0; $j<sizeof($sem); $j++)
                            {
                                $year_sem_sub[$year[$i]][$sem[$j]] = array();
                                for($k=0; $k<sizeof($sub_code); $k++)
                                {
                                    for($l=0; $l<sizeof($data); $l++)
                                    {
                                        if($data[$l]['year'] == $year[$i] && 
                                        $data[$l]['sem'] == $sem[$j] &&
                                        $data[$l]['sub_code'] == $sub_code[$k])
                                        {
                                            $year_sem_sub[$year[$i]][$sem[$j]][] = $data[$l]['sub_code'];
                                            $year_sem_sub1[$year[$i]][$sem[$j]][$data[$l]['sub_code']] = $data[$l]['sub_code'];
                                            break;
                                        }
                                    }
                                }    
                            }
                        }
                        for($i=0; $i<sizeof($sub_code); $i++)
                        {
                            $a = 0;
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['sub_code'] == $sub_code[$i])
                                {
                                    if($a == 0)
                                    {
                                        $sub_data[$sub_code[$i]]['grade'] = $data[$j]['grade'];
                                        $sub_data[$sub_code[$i]]['gradepoint'] = $data[$j]['gradepoint'];
                                        $sub_data[$sub_code[$i]]['credit'] = $data[$j]['credit'];
                                        $sub_data[$sub_code[$i]]['failstatus'] = $data[$j]['failstatus'];
                                        $sub_data[$sub_code[$i]]['sub_name'] = $data[$j]['sub_name'];
                                        $sub_data[$sub_code[$i]]['resultdate'] = $data[$j]['resultdate'];
                                        $sub_data[$sub_code[$i]]['sub_code'] = $data[$j]['sub_code'];
                                        $sub_data[$sub_code[$i]]['month'] = $data[$j]['exammonth'];
                                        $sub_data[$sub_code[$i]]['year'] = $data[$j]['examyear'];
                                        $sub_data[$sub_code[$i]]['examtype'] = $data[$j]['examtype'];
                                    }
                                    $a++;
                                }
                                if($j == sizeof($data)-1)
                                {
                                    if($a > 0)
                                    {
                                        $sub_data[$sub_code[$i]]['count'] = $a;
                                    }
                                }
                            }
                        }
                        $a = '';
                        $a .= '<div class="table-responsive" id="exporttable">';													
                        $a .= '<table class="table table-responsive-sm print-this" border="1px">';
                        $a .= $std;
                        if(sizeof($course) == 1)
                        {
                            if($course[0] == 2)
                            {
                                for($i=0; $i<sizeof($year); $i++)
                                {
                                    for($j=0; $j<sizeof($sem); $j++)
                                    {
                                        $b = 0;
                                        for($k=0; $k<sizeof($sub_code); $k++)
                                        {
                                            if(sizeof($year_sem_sub[$year[$i]][$sem[$j]])>0)
                                            {
                                                if(isset($year_sem_sub1[$year[$i]][$sem[$j]][$sub_code[$k]]))
                                                {
                                                    if($b == 0)
                                                    {
                                                        $a .= '<tr><th colspan="10">'.static::yearandsem($year[$i], $sem[$j]).'</th></tr>';
                                                        $a .= '<tr><th>Subject Code</th><th>Subject Name</th><th>Grade</th><th>Points</th><th>Credits</th><th>Month</th><th>Year</th><th>Type</th><th>Date</th><th>Status</th></tr>';
                                                    }
                                                    $a .= '<tr>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_code'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_name'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['grade'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['gradepoint'].'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['credit'].'</td>';
                                                    $a .= '<td>'.static::month($sub_data[$sub_code[$k]]['month']).'</td>';
                                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['year'].'</td>';
                                                    $a .= '<td>'.static::resulttype($sub_data[$sub_code[$k]]['examtype'], $sub_data[$sub_code[$k]]['count']).'</td>';
                                                    $a .= '<td>'.static::datem($sub_data[$sub_code[$k]]['resultdate']).'</td>';
                                                    $a .= '<td>'.static::resultstatus($sub_data[$sub_code[$k]]['failstatus'], $course[0]).'</td>';
                                                    $a .= '</tr>';
                                                    $b++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $a .= '</tbody>';
                        $a .= "</table>";
                        $a .= "</div>";
                    }
                    $a .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
        }
        // if(static::mainsessioncontrol() == 1)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-12"> 
                                <form action="" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-4"></div>
                                                            <div class="col-lg-4">                                       
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <section class="box" style="margin-top: 30px;">
                                                                            <header class="panel_header">
                                                                                <h5 class="title pull-left">Student Hall Ticket Number</h5>
                                                                                <div class="actions panel_actions pull-right">
                                                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                                                </div>
                                                                            </header>
                                                                            <div class="content-body">	
                                                                                    <form action="#" method="POST">
                                                                                        <div class="row">
                                                                                            <div class="col-md-12">
                                                                                                <div class="form-group"> 
                                                                                                    <input type="text" class="form-control" name="htno" placeholder="Hall Ticket Number">
                                                                                                </div>
                                                                                            </div>
                                                                                        </div>
                                                                                        <div class="row">
                                                                                            <div class="col-md-12">  
                                                                                                <div class="form-group">
                                                                                                    <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                                                                </div>
                                                                                            </div>
                                                                                        </div>
                                                                                    </form>
                                                                            </div>
                                                                        </section>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        <div class="col-lg-4"></div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                '.$a.'
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    private static function resulttesting()
    {
        $data = Homem::getdata("SELECT * FROM `results_data` ORDER BY `resultdate` DESC");
        $crse = array();
        $yer = array();
        $sm = array();
        $subcode = array();
        $subname = array();
        $rdate = array();
        $exam_year = array();
        $exam_month = array();
        foreach ($data as $h) {
            $crse[] = $h['fk_course_id'];
            $yer[] = $h['year'];
            $sm[] = $h['sem'];
            $subcode[] = $h['result_type'];
            $rdate[] = $h['resultdate'];
            $exam_year[] = $h['examyear'];
            $exam_month[] = $h['exammonth'];
        }
        $course = array_values(array_unique($crse));
        sort($course);
        $year = array_values(array_unique($yer));
        sort($year);
        $sem = array_values(array_unique($sm));
        sort($sem);
        $resulttype = array_values(array_unique($subcode));
        sort($resulttype);
        $resultdate = array_values(array_unique($rdate));
        sort($resultdate);
        $examyear = array_values(array_unique($exam_year));
        sort($examyear);
        $exammonth = array_values(array_unique($exam_month));
        sort($exammonth);
    }
    /**
     * Student marks uploading bulk - ended
     */
    /* Start of Marks Entry Master */
    public static function uploadmarks()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-3"></div>
                        <div class="col-lg-6">                                       
                            <div class="row">
                                <div class="col-md-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Upload Marks Here:</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">
                                            <form action="/main/uploadugmarks" method="POST" enctype="multipart/form-data">							
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="result_type" id="result_type" class="form-control">
                                                                <option value="">Select Result Type</option>
                                                                <option value="1">Garde System with inetrnal marks</option>
                                                                <option value="2">Marks Ssyetm</option>
                                                            </select>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_type" id="exam_type" class="form-control">
                                                                <option value="">Select Exam Type</option>
                                                                <option value="1">REG. / SUP.</option>
                                                                <option value="2">REV</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_month" id="exam_month" class="form-control">
                                                                <option value="">Select Month</option>
                                                                <option value="1">January</option> 
                                                                <option value="2">February</option> 
                                                                <option value="3">March</option> 
                                                                <option value="4">April</option> 
                                                                <option value="5">May</option> 
                                                                <option value="6">June</option> 
                                                                <option value="7">July</option> 
                                                                <option value="8">August</option> 
                                                                <option value="9">September</option> 
                                                                <option value="10">October</option> 
                                                                <option value="11">November</option> 
                                                                <option value="12">December</option> 
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <input name="exam_year" id="exam_year" maxlength="4" placeholder="Examnation Year" type="text" class="form-control" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="form-group">
                                                            <div class="custom-file">
                                                                <input type="file" class="custom-file-input" name="file" id="file" accept=".csv"/><!--accept=".xls,.xlsx"-->
                                                                <label class="custom-file-label" for="customFile">Upload Results in CSV Format</label>
                                                                <input type="hidden" name="brchr_data" id="brchr_data" />
                                                            </div>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="form-group">
                                                        <input type="text" name="reslutdate" id="resultdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Result Release Date" required />
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                            </form>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
            echo '
                <script>
                    $(document).ready(function () {
                        $("#file").change(function() { 
                            var selectedFile = document.getElementById("file").files;
                            if (selectedFile.length > 0) {
                                var fileToLoad = selectedFile[0];
                                var file_name=fileToLoad.name;
                                var fileReader = new FileReader();
                                var base64;
                                fileReader.onload = function(fileLoadedEvent) {
                                    $(".custom-file-label").html(file_name)
                                    base64 = fileLoadedEvent.target.result;
                                    document.getElementById("brchr_data").value=btoa(base64);
                                };
                                fileReader.readAsDataURL(fileToLoad);
                            }
                        });
                    });
                </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function uploadugmarks()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $filename=$_FILES['file']['name'];
            $exts[0]='csv';
            $year = $_POST['year'];
            $sem  = $_POST['sem'];
            $examtype = $_POST['exam_type'];
            $exammonth = $_POST['exam_month'];
            $examyear = $_POST['exam_year'];
            $resultdate = $_POST['reslutdate'];
            $filetype1 = explode('.',$filename);

            if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
            {
                $csv_file=$_FILES['file']['tmp_name'];
                $size=$_FILES['file']['size'];
                $handle = fopen($csv_file, "r");
                $data = fgetcsv($handle, 100000, ",");
                $i = 0;
                while (($data = fgetcsv($handle, 100000,","))!== FALSE)
                {
                    $ht_no = trim($data[0]);
                    $sub_code = trim($data[1]);
                    $sub_name = trim($data[2]);
                    if($_POST['result_type'] == '1')
                    {
                        $internal = '';
                        $external = '';
                        $result_type = '0';
                        $grade = trim($data[3]);
                        $credit = trim($data[4]);
                    }
                    if($_POST['result_type'] == '2')
                    {
                        $internal = trim($data[3]);
                        $external = trim($data[4]);
                        $result_type = '1';
                        $grade = '';
                        $credit = trim($data[5]);
                    }
                    if(sizeof(Homem::getdata("SELECT *  FROM `results_data` WHERE 
                    `year` = '$year' AND `sem` = '$sem' AND `ht_no` = '$ht_no' AND 
                    `sub_code` = '$sub_code' AND `internal` = '$internal' AND `external` = '$external' AND 
                    `grade` = '$grade' AND `credit` = '$credit' AND `exammonth` = '$exammonth' AND `examyear` = '$examyear' AND 
                    `resultdate` = '$resultdate' AND `result_type` = '$result_type' AND `status` = '1'")) == 0)
                    {
                        $query = "INSERT INTO `results_data` (`year`, `sem`, `ht_no`, `sub_code`, `sub_name`, `internal`, `external`, `grade`, `credit`, `exammonth`, `examyear`, `resultdate`, `result_type`, `examtype`, `fk_user_id`, `status`, `fk_org_id`, `fk_course_id`) VALUES 
                        ('$year', '$sem', '$ht_no', '$sub_code', '$sub_name', '$internal', '$external', '$grade', '$credit', '$exammonth', '$examyear', '$resultdate', '$result_type', $examtype, '$_SESSION[user_id]', '1', '$_SESSION[org_id]', '$_POST[course]')";
                        Homem::insert($query);
                        $i++;
                    }
                }
                echo '<script>window.location = "/main/uploadmarks?status=1&count='.$i.'";</script>';
            }
        }
    }
    public static function mdipinformat()
    {
        if(static::mainsessioncontrol() == 1)
        {
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-3"></div>
                        <div class="col-lg-6">                                       
                            <div class="row">
                                <div class="col-md-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Upload Diploma Marks Here (College Format):</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">
                                            <form action="/main/saveuploadmarks" method="POST" enctype="multipart/form-data">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">                                            
                                                        <select name="resulttype" id="resulttype" class="form-control">
                                                            <option value="">Result Type</option>
                                                            <option value="0">Grade System</option>
                                                            <option value="1">Marks System</option>
                                                        </select>												
                                                    </div>
                                                </div> 
                                            </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="stdno" id="stdno" placeholder="No. of Students" class="form-control" required>											
                                                        </div>
                                                    </div> 
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subno" id="subno" placeholder="No. of Subjects" class="form-control" required>											
                                                        </div>
                                                    </div> 	
                                                </div>						
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_type" id="exam_type" class="form-control">
                                                                <option value="">Select Exam Type</option>
                                                                <option value="1">REG. / SUP.</option>
                                                                <option value="2">REV</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_month" id="exam_month" class="form-control">
                                                                <option value="">Select Month</option>
                                                                <option value="1">January</option> 
                                                                <option value="2">February</option> 
                                                                <option value="3">March</option> 
                                                                <option value="4">April</option> 
                                                                <option value="5">May</option> 
                                                                <option value="6">June</option> 
                                                                <option value="7">July</option> 
                                                                <option value="8">August</option> 
                                                                <option value="9">September</option> 
                                                                <option value="10">October</option> 
                                                                <option value="11">November</option> 
                                                                <option value="12">December</option> 
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <input name="exam_year" id="exam_year" maxlength="4" placeholder="Examnation Year" type="text" class="form-control" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="form-group">
                                                            <div class="custom-file">
                                                                <input type="file" class="custom-file-input" name="file" id="file" accept=".csv"/><!--accept=".xls,.xlsx"-->
                                                                <label class="custom-file-label" for="customFile">Upload Results in CSV Format</label>
                                                                <input type="hidden" name="brchr_data" id="brchr_data" />
                                                            </div>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="form-group">
                                                        <input type="text" name="reslutdate" id="resultdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Result Release Date" required />
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <a href="/hindu/formats/Diploma_upload_format.csv" >Download CSV (Results in MARKS FORMAT) Uploading Format Here.. do not delete header in CSV file.</a>
                                                    </div>
                                                </div>
                                                
                                            </form>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
            echo '
                <script>
                    $(document).ready(function () {
                        $("#file").change(function() { 
                            var selectedFile = document.getElementById("file").files;
                            if (selectedFile.length > 0) {
                                var fileToLoad = selectedFile[0];
                                var file_name=fileToLoad.name;
                                var fileReader = new FileReader();
                                var base64;
                                fileReader.onload = function(fileLoadedEvent) {
                                    $(".custom-file-label").html(file_name)
                                    base64 = fileLoadedEvent.target.result;
                                    document.getElementById("brchr_data").value=btoa(base64);
                                };
                                fileReader.readAsDataURL(fileToLoad);
                            }
                        });
                    });
                </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function saveuploadmarks()
    {
        // code for diploma uploaded marks as per result analysis
        if(static::mainsessioncontrol() == 1)
        {
            $filename=$_FILES['file']['name'];
            $exts[0]='csv';
            $year = $_POST['year'];
            $sem  = $_POST['sem'];
            $examtype = $_POST['exam_type'];
            $exammonth = $_POST['exam_month'];
            $examyear = $_POST['exam_year'];
            $resultdate = $_POST['reslutdate'];
            $filetype1 = explode('.',$filename);
            if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
            {
                $csv_file=$_FILES['file']['tmp_name'];
                $size=$_FILES['file']['size'];
                $handle = fopen($csv_file, "r");
                $data = fgetcsv($handle, 100000, ",");
                $i = 0;
                $subcount = $_POST['subno'];
                $noofstudents = $_POST['stdno'];
                $result_type = $_POST['resulttype'];
                $count = 0;
                while (($data = fgetcsv($handle, 100000, ","))!== FALSE)
                {
                    $j = -1;
                    $k = 0;
                    $hallticket = trim($data[1]);
                    if($i == 0)
                    {
                        for($a=0; $a<$subcount; $a++)
                        {
                            $j=3+$j;
                            $subcode[$a] = trim($data[$j]);
                        }
                        $_SESSION['subcode'] = $subcode;
                    }
                    if($i == 1)
                    {
                        $j = -1;
                        for($a=0; $a<$subcount; $a++)
                        {
                            $j=3+$j;
                            $subname[$a] = trim($data[$j]);
                        }
                        $_SESSION['subname'] = $subname;
                    }
                    if($i >= 3 && isset($_SESSION['subname']) && isset($_SESSION['subcode']))
                    {
                        if(trim($data[0]) >= 1)
                        {
                            $hallticket = trim($data[1]);
                            $k = -1;
                            $j = 0;
                            for($i=0; $i<sizeof($_SESSION['subcode']); $i++)
                            {
                                if($_POST['resulttype'] == '1')
                                {
                                    $ht_no = $hallticket;
                                    $sub_code = $_SESSION['subcode'][$i];
                                    $sub_name = $_SESSION['subname'][$i];
                                    $j=3+$j;
                                    $external = trim($data[$j]);
                                    $k=3+$k;
                                    $internal = trim($data[$k]);
                                    
                                    $grade = '';
                                    $credit = '';
                                    if(sizeof(Homem::getdata("SELECT *  FROM `results_data` WHERE 
                                    `year` = '$year' AND `sem` = '$sem' AND `ht_no` = '$ht_no' AND 
                                    `sub_code` = '$sub_code' AND `internal` = '$internal' AND `external` = '$external' AND 
                                    `grade` = '$grade' AND `credit` = '$credit' AND `exammonth` = '$exammonth' AND `examyear` = '$examyear' AND 
                                    `resultdate` = '$resultdate' AND `result_type` = '$result_type' AND `status` = '1'")) == 0 && 
                                    $internal != '' && $external != '')
                                    {
                                        $query = "INSERT INTO `results_data` (`year`, `sem`, `ht_no`, `sub_code`, `sub_name`, `internal`, `external`, `grade`, `credit`, `exammonth`, `examyear`, `resultdate`, `result_type`, `examtype`, `fk_user_id`, `status`, `fk_org_id`, `fk_course_id`) VALUES 
                                        ('$year', '$sem', '$ht_no', '$sub_code', '$sub_name', '$internal', '$external', '$grade', '$credit', '$exammonth', '$examyear', '$resultdate', '$result_type', $examtype, '$_SESSION[user_id]', '1', '$_SESSION[org_id]', '1')";
                                        Homem::insert($query);
                                        $count++;
                                    }
                                }
                            }
                        }
                    }
                    $i++;
                }
                
            }
            echo '<script>window.location = "/main/mdipinformat?status=1&count='.$count.'";</script>';
        }
    }
    public static function mindividual()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-3"></div>
                        <div class="col-lg-6">                                       
                            <div class="row">
                                <div class="col-md-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Enter Individual students marks here: </h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">
                                            <form action="/main/saveindmarks" method="POST" enctype="multipart/form-data">							
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group"> 
                                                            <input type="text" name="htno" id="htno" class="form-control" placeholder="Halticket Number" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_type" id="exam_type" class="form-control">
                                                                <option value="">Select Exam Type</option>
                                                                <option value="1">REG. / SUP.</option>
                                                                <option value="2">REV</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <select name="exam_month" id="exam_month" class="form-control">
                                                                <option value="">Select Month</option>
                                                                <option value="1">January</option> 
                                                                <option value="2">February</option> 
                                                                <option value="3">March</option> 
                                                                <option value="4">April</option> 
                                                                <option value="5">May</option> 
                                                                <option value="6">June</option> 
                                                                <option value="7">July</option> 
                                                                <option value="8">August</option> 
                                                                <option value="9">September</option> 
                                                                <option value="10">October</option> 
                                                                <option value="11">November</option> 
                                                                <option value="12">December</option> 
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <input name="exam_year" id="exam_year" maxlength="4" placeholder="Examnation Year" type="text" class="form-control" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="subcode" id="subcode" placeholder="Subject Code" class="form-control">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="subname" id="subname" placeholder="Subject Name" class="form-control">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="internal" id="internal" placeholder="Internal Marks" class="form-control">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="external" id="external" placeholder="External Marks" class="form-control">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="grade" id="grade" placeholder="Grade" class="form-control">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="text" name="credit" id="credit" placeholder="Credit" class="form-control">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                        <input type="text" name="reslutdate" id="resultdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Result Release Date" required />
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="result_type" id="result_type" class="form-control">
                                                                <option value="">Select Result Type</option>
                                                                <option value="0">Grade System</option>
                                                                <option value="1">Marks System</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control"  placeholder="editid"  />
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                            </form>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `results_data` WHERE `id`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#htno").val("'.$data[0]['ht_no'].'");
                            $("#course").val("'.$data[0]['fk_course_id'].'");
                            $("#year").val("'.$data[0]['year'].'");
                            $("#sem").val("'.$data[0]['sem'].'");
                            $("#exam_type").val("'.$data[0]['examtype'].'");
                            $("#exam_year").val("'.$data[0]['examyear'].'");
                            $("#exam_month").val("'.$data[0]['exammonth'].'");
                            $("#subcode").val("'.$data[0]['sub_code'].'");
                            $("#subname").val("'.$data[0]['sub_name'].'");
                            $("#internal").val("'.$data[0]['internal'].'");
                            $("#external").val("'.$data[0]['external'].'");
                            $("#grade").val("'.$data[0]['grade'].'");
                            $("#credit").val("'.$data[0]['credit'].'");
                            $("#resultdate").val("'.$data[0]['resultdate'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                            $("#result_type").val("'.$data[0]['result_type'].'");
                        </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function saveindmarks()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $ht_no = $_POST['htno'];
            $course = $_POST['course'];
            $result_type = 1;
            $year = $_POST['year'];
            $sem = $_POST['sem'];
            $examtype = $_POST['exam_type'];
            $exammonth = $_POST['exam_month'];
            $examyear = $_POST['exam_year'];
            $sub_code = $_POST['subcode'];
            $sub_name = $_POST['subname'];
            $internal = $_POST['internal'];
            $external = $_POST['external'];
            $grade = $_POST['grade'];
            $credit = $_POST['credit'];
            $resultdate = $_POST['reslutdate'];
            $result_type = $_POST['result_type'];
            if($_POST['edit_id'] == '')
            {
                if(sizeof(Homem::getdata("SELECT *  FROM `results_data` WHERE 
                `year` = '$year' AND `sem` = '$sem' AND `ht_no` = '$ht_no' AND 
                `sub_code` = '$sub_code' AND `internal` = '$internal' AND `external` = '$external' AND 
                `grade` = '$grade' AND `credit` = '$credit' AND `exammonth` = '$exammonth' AND `examyear` = '$examyear' AND 
                `resultdate` = '$resultdate' AND `result_type` = '$result_type' AND `status` = '1'")) == 0)
                {
                    $query = "INSERT INTO `results_data` (`year`, `sem`, `ht_no`, `sub_code`, `sub_name`, `internal`, `external`, `grade`, `credit`, `exammonth`, `examyear`, `resultdate`, `result_type`, `examtype`, `fk_user_id`, `status`, `fk_org_id`, `fk_course_id`) VALUES 
                    ('$year', '$sem', '$ht_no', '$sub_code', '$sub_name', '$internal', '$external', '$grade', '$credit', '$exammonth', '$examyear', '$resultdate', '$result_type', $examtype, '$_SESSION[user_id]', '1', '$_SESSION[org_id]', '$course')";
                    Homem::insert($query);
                }
                echo '<script>window.location = "/main/mindividual?status=1";</script>';
            }
            else
            {   if(sizeof(Homem::getdata("SELECT * FROM `results_data` WHERE `fk_org_id`='$_SESSION[org_id]' AND `id`='$_POST[edit_id]'")) == 1)
                {
                    $query = "UPDATE `results_data` SET `year`='$year', `sem`='$sem', `ht_no`='$ht_no', `sub_code`='$sub_code', `sub_name`='$sub_name', `internal`='$internal', `external`='$external', `grade`='$grade', `credit`='$credit', `exammonth`='$exammonth', `examyear`='$examyear', `resultdate`='$resultdate', `result_type`='$result_type', `examtype`='$examtype', `fk_course_id`='$course' WHERE `id`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/main/mindividual?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/main/mindividual?status=0";</script>';
                }
            }
        }
    }
    public static function editindstdmarks()
    {
        $a = '';
        if(static::mainsessioncontrol() == 1)
        {
            if(isset($_POST['htno']))
            {
                $ht_no = $_POST['htno'];
                $result = ''; $result11 = ''; $result12 = ''; $result21 = ''; $result22 = ''; $result31 = ''; $result32 = ''; $result41 = ''; $result42 = '';							
                $thead ='<div class="table-responsive">													
                        <table class="table table-bordered">
                        <thead>
                            <tr>
                            <th>Subject Code</th>
                            <th>Subject Name</th>
                            <th>Internal</th>
                            <th>External</th>
                            <th>Grade</th>
                            <th>Credit</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Exam Type</th>
                            <th>Date of Result</th>
                            <th>Edit</th>
                            </tr>
                        </thead>';
                $tbodystart = '<tbody>';
                $tbodyend = '</tbody></table></div>';
                $std_data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$ht_no'");
                $sql = "SELECT * from `results_data` rd JOIN `month` m ON rd.exammonth=m.month_id WHERE `ht_no`='$ht_no' AND `fk_org_id`='$_SESSION[org_id]' ORDER BY `sub_code` ASC";
                $data = Homem::getdata($sql);
                if(sizeof($data) > 0)
                {
                    $a = '';
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        if(($data[$i]['credit'] != '0' || ($data[$i]['credit'] == '0' && $data[$i]['grade'] == 'COMPLETED')) || ($data['credit'] == '' && $data['grade'] == '' && $std_data[0]['fk_course_id'] == '1'))
                        {
                            $result = 
                                '<tr style="color:black">'.
                                '<td>'.$data[$i]['sub_code'].'</td>'.
                                '<td>'.$data[$i]['sub_name'].'</td>'.
                                '<td>'.$data[$i]['internal'].'</td>'.
                                '<td>'.$data[$i]['external'].'</td>'.
                                '<td>'.$data[$i]['grade'].'</td>'.
                                '<td>'.$data[$i]['credit'].'</td>'.
                                '<td>'.$data[$i]['month_name'].'</td>'.
                                '<td>'.$data[$i]['examyear'].'</td>'.
                                '<td>'.$data[$i]['examtype'].'</td>'.
                                '<td>'.$data[$i]['resultdate'].'</td>'.
                                '<td><a href="/main/mindividual?editid='.$data[$i]['id'].'"><span class="badge badge-primary">Edit</span></a></td>'.
                                '</tr>';
                        }
                        if($data[$i]['year'] == 1 && $data[$i]['sem'] == 1){$result11 .= $result;}
                        if($data[$i]['year'] == 1 && $data[$i]['sem'] == 2){$result12 .= $result;}
                        if($data[$i]['year'] == 2 && $data[$i]['sem'] == 1){$result21 .= $result;}
                        if($data[$i]['year'] == 2 && $data[$i]['sem'] == 2){$result22 .= $result;}
                        if($data[$i]['year'] == 3 && $data[$i]['sem'] == 1){$result31 .= $result;}
                        if($data[$i]['year'] == 3 && $data[$i]['sem'] == 2){$result32 .= $result;}
                        if($data[$i]['year'] == 4 && $data[$i]['sem'] == 1){$result41 .= $result;}
                        if($data[$i]['year'] == 4 && $data[$i]['sem'] == 2){$result42 .= $result;}
                    }
                    if(isset($std_data[0]['name']))
                    {
                        $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['name']."</strong></span></center><br />";
                        $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['no']."</strong></span></center><br />";
                    }
                    if($result11 != '')
                    {
                        $a .= '<center><span style="font-size:20px;">I - Year I - Semester</span></center><br />';
                        $a .= $thead.$tbodystart.$result11.$tbodyend;
                    }
                    if($result12 != '')
                    {
                        $a .= '<br /><center><span style="font-size:20px;">I - Year II - Semester</span></center><br />';
                        $a .= $thead.$tbodystart.$result12.$tbodyend;
                    }
                    if($result21 != '')
                    {
                        $a .= '<br /><center><span style="font-size:20px;">II - Year I - Semester</span></center><br />';
                        $a .= $thead.$tbodystart.$result21.$tbodyend;
                    }
                    if($result22 != '')
                    {
                        $a .= '<br /><center><span style="font-size:20px;">II - Year II - Semester</span></center><br />';
                        $a .= $thead.$tbodystart.$result22.$tbodyend;
                    }
                    if($result31 != '')
                    {
                        $a .=  '<br /><center><span style="font-size:20px;">III - Year I - Semester</span></center><br />';
                        $a .=  $thead.$tbodystart.$result31.$tbodyend;
                    }
                    if($result32 != '')
                    {
                        $a .=  '<br /><center><span style="font-size:20px;">III - Year II - Semester</span></center><br />';
                        $a .=  $thead.$tbodystart.$result32.$tbodyend;
                    }
                    if($result41 != '')
                    {
                        $a .=  '<br /><center><span style="font-size:20px;">IV - Year I - Semester</span></center><br />';
                        $a .=  $thead.$tbodystart.$result41.$tbodyend;
                    }
                    if($result42 != '')
                    {
                        $a .=  '<br /><center><span style="font-size:20px;">IV - Year II - Semester</span></center><br />';
                        $a .=  $thead.$tbodystart.$result42.$tbodyend;
                    }
                }
            }
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-4"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-md-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Student Hall Ticket Number</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">	
                                                <form action="#" method="POST">
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <div class="form-group"> 
                                                                <input type="text" class="form-control" name="htno" placeholder="Hall Ticket Number">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                        </div>
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4"></div>
                    </div>
                    <div class="row">
                        <div class="col-md-1"></div>
                        <div class="col-md-10">
                        '.$a.'
                        </div>
                        <div class="col-md-1"></div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    /* End  of Marks Entry Master */
    /**Start of Report master */
    public static function studentresult()
    {
        $a = '';
        if(static::mainsessioncontrol() == 1)
        {
            if(isset($_POST['htno']))
            {
                $ht_no = $_POST['htno'];
                $result = ''; $result11 = ''; $result12 = ''; $result21 = ''; $result22 = ''; $result31 = ''; $result32 = ''; $result41 = ''; $result42 = '';							
                $std_data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$ht_no'");
                if(sizeof($std_data) == 1)
                {
                    if($std_data[0]['fk_course_id'] == 1)
                    {
                        $thead ='<div class="table-responsive">													
                                <table class="table table-bordered">
                                <thead>
                                    <tr>
                                    <th>Subject Code</th>
                                    <th>Subject Name</th>
                                    <th>Internal</th>
                                    <th>External</th>
                                    <th>Total</th>
                                    <th>Month</th>
                                    <th>Year</th>
                                    <th>Date of Result</th>
                                    </tr>
                                </thead>';
                        $tbodystart = '<tbody>';
                        $tbodyend = '</tbody></table></div>';
                        $sql="SELECT b. * , a.resultdate, a.count, m.month_name, sc.* 
                            FROM (
                            SELECT DISTINCT sub_code, MAX( resultdate ) resultdate, COUNT( sub_code ) count
                            FROM `results_data`
                            WHERE ht_no = '$ht_no' AND status='1'
                            GROUP BY sub_code
                            )a
                            JOIN `results_data` b ON a.sub_code = b.sub_code
                            JOIN `month` m ON m.month_id = b.exammonth
                            JOIN `subject_data` sc ON b.sub_code=sc.subcode
                            WHERE b.ht_no = '$ht_no' AND a.resultdate = b.resultdate";
                        $data = Homem::getdata($sql);
                        echo sizeof($data);
                        if(sizeof($data) > 0)
                        {
                            for($i=0; $i<sizeof($data); $i++)
                            {
                                $total_status = 0;
                                $data[$i]['total'] = $data[$i]['external']+$data[$i]['internal'];
                                if(($data[$i]['total_mand'] == 1 && $data[$i]['total'] >= $data[$i]['total_pass']) || $data[$i]['total_mand'] == 0)
                                {
                                    $total_status = 1;
                                }
                                $ext_status = 0;
                                if(($data[$i]['ext_mand'] == 1 && $data[$i]['external'] >= $data[$i]['ext_pass']) || $data[$i]['ext_mand'] == 0)
                                {
                                    $ext_status = 1;
                                }
                                $int_status = 0;
                                if(($data[$i]['int_mand'] == 1 && $data[$i]['internal'] >= $data[$i]['int_pass']) || $data[$i]['int_mand'] == 0)
                                {
                                    $int_status = 1;
                                }
                                if($int_status == 1 && $ext_status == 1 && $total_status == 1)
                                {
                                    $result = 
                                        '<tr style="color:green">'.
                                        '<td>'.$data[$i]['sub_code'].'</td>'.
                                        '<td>'.$data[$i]['sub_name'].'</td>'.
                                        '<td>'.$data[$i]['internal'].'</td>'.
                                        '<td>'.$data[$i]['external'].'</td>'.
                                        '<td>'.$data[$i]['total'].'</td>'.
                                        '<td>'.$data[$i]['month_name'].'</td>'.
                                        '<td>'.$data[$i]['examyear'].'</td>'.
                                        '<td>'.$data[$i]['resultdate'].'</td>'.
                                        '</tr>';
                                }
                                else
                                {
                                    $result = 
                                        '<tr style="color:red">'.
                                        '<td>'.$data[$i]['sub_code'].'</td>'.
                                        '<td>'.$data[$i]['sub_name'].'</td>'.
                                        '<td>'.$data[$i]['internal'].'</td>'.
                                        '<td>'.$data[$i]['external'].'</td>'.
                                        '<td>'.$data[$i]['total'].'</td>'.
                                        '<td>'.$data[$i]['month_name'].'</td>'.
                                        '<td>'.$data[$i]['examyear'].'</td>'.
                                        '<td>'.$data[$i]['resultdate'].'</td>'.
                                        '</tr>';
                                }
                                if($data[$i]['year'] == 1 && $data[$i]['sem'] == 1){$result11 .= $result;}
                                if($data[$i]['year'] == 1 && $data[$i]['sem'] == 2){$result12 .= $result;}
                                if($data[$i]['year'] == 2 && $data[$i]['sem'] == 1){$result21 .= $result;}
                                if($data[$i]['year'] == 2 && $data[$i]['sem'] == 2){$result22 .= $result;}
                                if($data[$i]['year'] == 3 && $data[$i]['sem'] == 1){$result31 .= $result;}
                                if($data[$i]['year'] == 3 && $data[$i]['sem'] == 2){$result32 .= $result;}
                                if($data[$i]['year'] == 4 && $data[$i]['sem'] == 1){$result41 .= $result;}
                                if($data[$i]['year'] == 4 && $data[$i]['sem'] == 2){$result42 .= $result;}
                            }
                        }
                        if(sizeof($data) > 0)
                        {
                            $a = '';
                            if(isset($std_data[0]['name']))
                            {
                                $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['name']."</strong></span></center><br />";
                                $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['no']."</strong></span></center><br />";
                            }
                            if($result11 != '')
                            {
                                $a .= '<center><span style="font-size:20px;">I - Year I - Semester</span></center><br />';
                                $a .= $thead.$tbodystart.$result11.$tbodyend;
                            }
                            if($result12 != '')
                            {
                                $a .= '<br /><center><span style="font-size:20px;">I - Year II - Semester</span></center><br />';
                                $a .= $thead.$tbodystart.$result12.$tbodyend;
                            }
                            if($result21 != '')
                            {
                                $a .= '<br /><center><span style="font-size:20px;">II - Year I - Semester</span></center><br />';
                                $a .= $thead.$tbodystart.$result21.$tbodyend;
                            }
                            if($result22 != '')
                            {
                                $a .= '<br /><center><span style="font-size:20px;">II - Year II - Semester</span></center><br />';
                                $a .= $thead.$tbodystart.$result22.$tbodyend;
                            }
                            if($result31 != '')
                            {
                                $a .=  '<br /><center><span style="font-size:20px;">III - Year I - Semester</span></center><br />';
                                $a .=  $thead.$tbodystart.$result31.$tbodyend;
                            }
                            if($result32 != '')
                            {
                                $a .=  '<br /><center><span style="font-size:20px;">III - Year II - Semester</span></center><br />';
                                $a .=  $thead.$tbodystart.$result32.$tbodyend;
                            }
                            if($result41 != '')
                            {
                                $a .=  '<br /><center><span style="font-size:20px;">IV - Year I - Semester</span></center><br />';
                                $a .=  $thead.$tbodystart.$result41.$tbodyend;
                            }
                            if($result42 != '')
                            {
                                $a .=  '<br /><center><span style="font-size:20px;">IV - Year II - Semester</span></center><br />';
                                $a .=  $thead.$tbodystart.$result42.$tbodyend;
                            }
                        }
                    }
                }
                else
                {
                    $thead ='<div class="table-responsive">													
                            <table class="table table-bordered">
                            <thead>
                                <tr>
                                <th>Subject Code</th>
                                <th>Subject Name</th>
                                <th>Internal</th>
                                <th>External</th>
                                <th>Month</th>
                                <th>Year</th>
                                <th>Date of Result</th>
                                </tr>
                            </thead>';
                    $tbodystart = '<tbody>';
                    $tbodyend = '</tbody></table></div>';
                    $std_data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$ht_no'");
                    $sql="SELECT b. * , a.resultdate, a.count, m.month_name
                            FROM (
                            SELECT DISTINCT sub_code, MAX( resultdate ) resultdate, COUNT( sub_code ) count
                            FROM `results_data`
                            WHERE ht_no = '$ht_no' AND status='1'
                            GROUP BY sub_code
                            )a
                            JOIN `results_data` b ON a.sub_code = b.sub_code
                            JOIN `month` m ON m.month_id = b.exammonth
                            AND a.resultdate = b.resultdate
                            WHERE b.ht_no = '$ht_no'";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $a = '';
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            if($data[$i]['count'] == '1'){$data[$i]['examtype'] = "REG";}
                            if($data[$i]['count'] > 1 && $data[$i]['examtype'] == 1){$data[$i]['examtype'] = "SUP";}
                            if($data[$i]['count'] > 1 && $data[$i]['examtype'] == 2){$data[$i]['examtype'] = "REV";}
                            if(($data[$i]['credit'] != '0' || ($data[$i]['credit'] == '0' && $data[$i]['grade'] == 'COMPLETED')) || ($data['credit'] == '' && $data['grade'] == '' && $std_data[0]['fk_course_id'] == '1'))
                            {
                                $result = 
                                    '<tr style="color:green">'.
                                    '<td>'.$data[$i]['sub_code'].'</td>'.
                                    '<td>'.$data[$i]['sub_name'].'</td>'.
                                    '<td>'.$data[$i]['internal'].'</td>'.
                                    '<td>'.$data[$i]['external'].'</td>'.
                                    '<td>'.$data[$i]['month_name'].'</td>'.
                                    '<td>'.$data[$i]['examyear'].'</td>'.
                                    '<td>'.$data[$i]['resultdate'].'</td>'.
                                    '</tr>';
                            }
                            if($data[$i]['credit'] == '0' && $data[$i]['grade'] != 'COMPLETED')
                            {
                                $result = 
                                    '<tr style="color:red">'.
                                    '<td>'.$data[$i]['sub_code'].'</td>'.
                                    '<td>'.$data[$i]['sub_name'].'</td>'.
                                    '<td>'.$data[$i]['internal'].'</td>'.
                                    '<td>'.$data[$i]['external'].'</td>'.
                                    '<td>'.$data[$i]['month_name'].'</td>'.
                                    '<td>'.$data[$i]['examyear'].'</td>'.
                                    '<td>'.$data[$i]['resultdate'].'</td>'.
                                    '</tr>';
                            }
                            if($data[$i]['year'] == 1 && $data[$i]['sem'] == 1){$result11 .= $result;}
                            if($data[$i]['year'] == 1 && $data[$i]['sem'] == 2){$result12 .= $result;}
                            if($data[$i]['year'] == 2 && $data[$i]['sem'] == 1){$result21 .= $result;}
                            if($data[$i]['year'] == 2 && $data[$i]['sem'] == 2){$result22 .= $result;}
                            if($data[$i]['year'] == 3 && $data[$i]['sem'] == 1){$result31 .= $result;}
                            if($data[$i]['year'] == 3 && $data[$i]['sem'] == 2){$result32 .= $result;}
                            if($data[$i]['year'] == 4 && $data[$i]['sem'] == 1){$result41 .= $result;}
                            if($data[$i]['year'] == 4 && $data[$i]['sem'] == 2){$result42 .= $result;}
                        }
                        if(isset($std_data[0]['name']))
                        {
                            $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['name']."</strong></span></center><br />";
                            $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['no']."</strong></span></center><br />";
                        }
                        if($result11 != '')
                        {
                            $a .= '<center><span style="font-size:20px;">I - Year I - Semester</span></center><br />';
                            $a .= $thead.$tbodystart.$result11.$tbodyend;
                        }
                        if($result12 != '')
                        {
                            $a .= '<br /><center><span style="font-size:20px;">I - Year II - Semester</span></center><br />';
                            $a .= $thead.$tbodystart.$result12.$tbodyend;
                        }
                        if($result21 != '')
                        {
                            $a .= '<br /><center><span style="font-size:20px;">II - Year I - Semester</span></center><br />';
                            $a .= $thead.$tbodystart.$result21.$tbodyend;
                        }
                        if($result22 != '')
                        {
                            $a .= '<br /><center><span style="font-size:20px;">II - Year II - Semester</span></center><br />';
                            $a .= $thead.$tbodystart.$result22.$tbodyend;
                        }
                        if($result31 != '')
                        {
                            $a .=  '<br /><center><span style="font-size:20px;">III - Year I - Semester</span></center><br />';
                            $a .=  $thead.$tbodystart.$result31.$tbodyend;
                        }
                        if($result32 != '')
                        {
                            $a .=  '<br /><center><span style="font-size:20px;">III - Year II - Semester</span></center><br />';
                            $a .=  $thead.$tbodystart.$result32.$tbodyend;
                        }
                        if($result41 != '')
                        {
                            $a .=  '<br /><center><span style="font-size:20px;">IV - Year I - Semester</span></center><br />';
                            $a .=  $thead.$tbodystart.$result41.$tbodyend;
                        }
                        if($result42 != '')
                        {
                            $a .=  '<br /><center><span style="font-size:20px;">IV - Year II - Semester</span></center><br />';
                            $a .=  $thead.$tbodystart.$result42.$tbodyend;
                        }
                    }
                }
            }
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-4"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-md-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Student Hall Ticket Number</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">	
                                                <form action="#" method="POST">
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <div class="form-group"> 
                                                                <input type="text" class="form-control" name="htno" placeholder="Hall Ticket Number">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button name="upload" class="btn btn-primary pull-right" type="submit">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                        </div>
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4"></div>
                    </div>
                    <div class="row">
                        <div class="col-md-1"></div>
                        <div class="col-md-10">
                        '.$a.'
                        </div>
                        <div class="col-md-1"></div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    public static function test()
    {
        {
            $ht_no = $_POST['htno'];
            $result = ''; $result11 = ''; $result12 = ''; $result21 = ''; $result22 = ''; $result31 = ''; $result32 = ''; $result41 = ''; $result42 = '';							
            $thead ='<div class="table-responsive">													
                    <table class="table table-bordered">
                    <thead>
                        <tr>
                        <th>Subject Code</th>
                        <th>Subject Name</th>
                        <th>Internal</th>
                        <th>External</th>
                        <th>Grade</th>
                        <th>Credit</th>
                        <th>Month</th>
                        <th>Year</th>
                        <th>Exam Type</th>
                        <th>Date of Result</th>
                        </tr>
                    </thead>';
            $tbodystart = '<tbody>';
            $tbodyend = '</tbody></table></div>';
            $std_data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$ht_no'");
            $sql="SELECT b. * , a.resultdate, a.count, m.month_name
                    FROM (
                    SELECT DISTINCT sub_code, MAX( resultdate ) resultdate, COUNT( sub_code ) count
                    FROM `results_data`
                    WHERE ht_no = '$ht_no' AND status='1'
                    GROUP BY sub_code
                    )a
                    JOIN `results_data` b ON a.sub_code = b.sub_code
                    JOIN `month` m ON m.month_id = b.exammonth
                    AND a.resultdate = b.resultdate
                    WHERE b.ht_no = '$ht_no'";
            $data = Homem::getdata($sql);
            if(sizeof($data) > 0)
            {
                $a = '';
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]['count'] == '1'){$data[$i]['examtype'] = "REG";}
                    if($data[$i]['count'] > 1 && $data[$i]['examtype'] == 1){$data[$i]['examtype'] = "SUP";}
                    if($data[$i]['count'] > 1 && $data[$i]['examtype'] == 2){$data[$i]['examtype'] = "REV";}
                    if(($data[$i]['credit'] != '0' || ($data[$i]['credit'] == '0' && $data[$i]['grade'] == 'COMPLETED')) || ($data['credit'] == '' && $data['grade'] == '' && $std_data[0]['fk_course_id'] == '1'))
                    {
                        $result = 
                            '<tr style="color:green">'.
                            '<td>'.$data[$i]['sub_code'].'</td>'.
                            '<td>'.$data[$i]['sub_name'].'</td>'.
                            '<td>'.$data[$i]['internal'].'</td>'.
                            '<td>'.$data[$i]['external'].'</td>'.
                            '<td>'.$data[$i]['grade'].'</td>'.
                            '<td>'.$data[$i]['credit'].'</td>'.
                            '<td>'.$data[$i]['month_name'].'</td>'.
                            '<td>'.$data[$i]['examyear'].'</td>'.
                            '<td>'.$data[$i]['examtype'].'</td>'.
                            '<td>'.$data[$i]['resultdate'].'</td>'.
                            '</tr>';
                    }
                    if($data[$i]['credit'] == '0' && $data[$i]['grade'] != 'COMPLETED')
                    {
                        $result = 
                            '<tr style="color:red">'.
                            '<td>'.$data[$i]['sub_code'].'</td>'.
                            '<td>'.$data[$i]['sub_name'].'</td>'.
                            '<td>'.$data[$i]['internal'].'</td>'.
                            '<td>'.$data[$i]['external'].'</td>'.
                            '<td>'.$data[$i]['grade'].'</td>'.
                            '<td>'.$data[$i]['credit'].'</td>'.
                            '<td>'.$data[$i]['month_name'].'</td>'.
                            '<td>'.$data[$i]['examyear'].'</td>'.
                            '<td>'.$data[$i]['examtype'].'</td>'.
                            '<td>'.$data[$i]['resultdate'].'</td>'.
                            '</tr>';
                    }
                    if($data[$i]['year'] == 1 && $data[$i]['sem'] == 1){$result11 .= $result;}
                    if($data[$i]['year'] == 1 && $data[$i]['sem'] == 2){$result12 .= $result;}
                    if($data[$i]['year'] == 2 && $data[$i]['sem'] == 1){$result21 .= $result;}
                    if($data[$i]['year'] == 2 && $data[$i]['sem'] == 2){$result22 .= $result;}
                    if($data[$i]['year'] == 3 && $data[$i]['sem'] == 1){$result31 .= $result;}
                    if($data[$i]['year'] == 3 && $data[$i]['sem'] == 2){$result32 .= $result;}
                    if($data[$i]['year'] == 4 && $data[$i]['sem'] == 1){$result41 .= $result;}
                    if($data[$i]['year'] == 4 && $data[$i]['sem'] == 2){$result42 .= $result;}
                }
                if(isset($std_data[0]['name']))
                {
                    $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['name']."</strong></span></center><br />";
                    $a .= "<center><span style='font-size:20px;'><strong>".$std_data[0]['no']."</strong></span></center><br />";
                }
                if($result11 != '')
                {
                    $a .= '<center><span style="font-size:20px;">I - Year I - Semester</span></center><br />';
                    $a .= $thead.$tbodystart.$result11.$tbodyend;
                }
                if($result12 != '')
                {
                    $a .= '<br /><center><span style="font-size:20px;">I - Year II - Semester</span></center><br />';
                    $a .= $thead.$tbodystart.$result12.$tbodyend;
                }
                if($result21 != '')
                {
                    $a .= '<br /><center><span style="font-size:20px;">II - Year I - Semester</span></center><br />';
                    $a .= $thead.$tbodystart.$result21.$tbodyend;
                }
                if($result22 != '')
                {
                    $a .= '<br /><center><span style="font-size:20px;">II - Year II - Semester</span></center><br />';
                    $a .= $thead.$tbodystart.$result22.$tbodyend;
                }
                if($result31 != '')
                {
                    $a .=  '<br /><center><span style="font-size:20px;">III - Year I - Semester</span></center><br />';
                    $a .=  $thead.$tbodystart.$result31.$tbodyend;
                }
                if($result32 != '')
                {
                    $a .=  '<br /><center><span style="font-size:20px;">III - Year II - Semester</span></center><br />';
                    $a .=  $thead.$tbodystart.$result32.$tbodyend;
                }
                if($result41 != '')
                {
                    $a .=  '<br /><center><span style="font-size:20px;">IV - Year I - Semester</span></center><br />';
                    $a .=  $thead.$tbodystart.$result41.$tbodyend;
                }
                if($result42 != '')
                {
                    $a .=  '<br /><center><span style="font-size:20px;">IV - Year II - Semester</span></center><br />';
                    $a .=  $thead.$tbodystart.$result42.$tbodyend;
                }
            }
        }
    }
    public static function sattempts()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $data = Homem::getdata("SELECT um.id, um.no, um.name, um.gender, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON sd.subcode=rd.sub_code WHERE rd.status='1' AND sd.year=rd.year AND sd.sem=rd.sem AND rd.fk_course_id='1' AND um.fk_dept_id='4' AND um.fromyear='2019' AND um.toyear='2022' ORDER BY rd.resultdate ASC");
            $r_year = array();
            $r_sem = array();
            $sub_code = array();
            $ht_no = array();
            $r_date = array();
            foreach ($data as $h) {
                $ht_no[] = $h['no'];
                $r_sem[] = $h['sem'];
                $r_year[] = $h['year'];
                $sub_code[] = $h['sub_code'];
                $r_date[] = $h['resultdate'];
            }
            $no = array_values(array_unique($ht_no));
            sort($no);
            $year = array_values(array_unique($r_year));
            sort($year);
            $sem = array_values(array_unique($r_sem));
            sort($sem);
            $subcode = array_values(array_unique($sub_code));
            sort($subcode);
            $date = array_values(array_unique($r_date));
            sort($date);
            for($a=0; $a<sizeof($year); $a++) // year
            {
                for($b=0; $b<sizeof($sem); $b++) // sem
                {
                    $a_subcode[$year[$a]][$sem[$b]] = array();
                    $a_subname[$year[$a]][$sem[$b]] = array();
                    $a_date[$year[$a]][$sem[$b]] = array();
                    for($c=0; $c<sizeof($data); $c++) // data
                    {
                        for($d=0; $d<sizeof($subcode); $d++) //subcode
                        {
                            if($data[$c]['year'] == $year[$a] && $data[$c]['sem'] == $sem[$b] && $data[$c]['sub_code'] == $subcode[$d])
                            {
                                $a_subcode[$year[$a]][$sem[$b]][$data[$c]['sub_code']] =  $data[$c]['sub_code'];
                                $a_subname[$year[$a]][$sem[$b]][$data[$c]['sub_code']] =  $data[$c]['sub_name'];
                            }
                        }
                        for($f=0; $f<sizeof($date); $f++) //dates
                        {
                            if($data[$c]['year'] == $year[$a] && $data[$c]['sem'] == $sem[$b] && $data[$c]['resultdate'] == $date[$f])
                            {
                                $a_date[$year[$a]][$sem[$b]][$data[$c]['resultdate']] =  $data[$c]['resultdate'];
                            }
                        }
                    }
                }
            }
            // echo json_encode($a_date);
        }
    }
    public static function semwiseconmarks()
    {
        if(static::mainsessioncontrol() == 1)
        {
        
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $subtable = '';
            if(isset($_POST['course']))
            {
                if($_POST['course'] == 1)
                {
                    $sql = "SELECT um.no, um.name, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.exammonth, rd.examyear, rd.resultdate, m.month_name, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON sd.subcode=rd.sub_code JOIN month m ON m.month_id=rd.exammonth WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.org_id='$_SESSION[org_id]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.status='1' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]' AND um.regulation=sd.regulation ORDER BY um.no ASC";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        $sub_code = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                            $sub_code[] = $h['sub_code'];
                        }
                        $no = array_values(array_unique($ht_no));
                        $subcode = array_values(array_unique($sub_code));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    $count = $i+1;
                                    $total_status = 0;
                                        $data[$j]['externalconv']= (int)$data[$j]['external'];
                                        // $details[$data[$j]['no']][$data[$j]['sub_code']]['external'] = (int)$data[$j]['external'];
                                        $data[$j]['total'] = $data[$j]['externalconv']+$data[$j]['internal'];
                                        if(($data[$j]['total_mand'] == 1 && $data[$j]['total'] >= $data[$j]['total_pass']) || $data[$j]['total_mand'] == 0)
                                        {
                                            $total_status = 1;
                                        }
                                        $ext_status = 0;
                                        if(($data[$j]['ext_mand'] == 1 && $data[$j]['external'] >= $data[$j]['ext_pass']) || $data[$j]['ext_mand'] == 0)
                                        {
                                            $ext_status = 1;
                                        }
                                        $int_status = 0;
                                        if(($data[$j]['int_mand'] == 1 && $data[$j]['internal'] >= $data[$j]['int_pass']) || $data[$j]['int_mand'] == 0)
                                        {
                                            $int_status = 1;
                                        }
                                        $absent = 0;
                                        if($data[$j]['external'] == 'A')
                                        {
                                            $absent = 1;
                                        }
                                        
                                    if(($int_status == 1 && $ext_status == 1 && $total_status == 1) && ($absent==0))
                                    {
                                        // passed
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['internal'] = $data[$j]['internal'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['external'] = $data[$j]['external'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['total'] = $data[$j]['internal']+$data[$j]['externalconv'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['total_max'] = $data[$j]['total_max'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['status'] = 0;
                                    }
                                    if(($int_status == 0 || $ext_status == 0 || $total_status == 0) || ($absent==1))
                                    {
                                        //failed
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['internal'] = $data[$j]['internal'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['external'] = $data[$j]['external'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['total'] = $data[$j]['internal']+$data[$j]['externalconv'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['total_max'] = $data[$j]['total_max'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['status'] = 1;
                                    }
                                }
                            }
                        }
                        $a = '';
                        $allpass=0;
                        $sinlesubject = 0;
                        $doublesubject = 0;
                        $triplesubject = 0;
                        $allfail = 0;
                        $sno = 0;
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            $backlog=0;
                            $total = 0;
                            $total_max = 0;                            
                            $k=0;
                            $a .= '<tr>';
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if(isset($details[$no[$i]][$subcode[$j]]))
                                {
                                    $backlog= $backlog+$details[$no[$i]][$subcode[$j]]['status'];
                                    $total= $total+$details[$no[$i]][$subcode[$j]]['total'];
                                    $total_max= $total_max+$details[$no[$i]][$subcode[$j]]['total_max'];
                                    if($j == 0)
                                    {
                                        $sno++;
                                        $a .= '<td>'.$sno.'</td>';
                                        $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                        $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                        $k = 1;
                                    }
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['internal'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['external'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['total'].'</td>';
                                    if($j == (sizeof($subcode)-1))
                                    {
                                        $percentage = ($total/$total_max)*100;
                                        $a .= '<td>'.$backlog.'</td>';
                                        $a .= '<td>'.$total.'</td>';
                                        $a .= '<td>'.$total_max.'</td>';
                                        $a .= '<td>'.number_format($percentage, 2).'</td>';
                                        if($backlog == 0)
                                        {
                                            $allpass++;
                                        }
                                        if($backlog == 1)
                                        {
                                            $sinlesubject++;
                                        }
                                        if($backlog == 2)
                                        {
                                            $doublesubject++;
                                        }
                                        if($backlog == 3)
                                        {
                                            $triplesubject++;
                                        }
                                        if($backlog >= sizeof($subcode))
                                        {
                                            $allfail = 0;
                                        }
                                    }                               
                                }
                            }
                            $a .= '</tr>'; 
                        }
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $paasedcount = 0;
                            $failedcount = 0;
                            $totalcount = 0;
                            for($j=0; $j<sizeof($no); $j++)
                            {
                                if(isset($details[$no[$j]][$subcode[$i]]))
                                {
                                    if($details[$no[$j]][$subcode[$i]]['status'] == 0)
                                    {
                                        $paasedcount++;
                                    }
                                    if($details[$no[$j]][$subcode[$i]]['status'] == 1)
                                    {
                                        $failedcount++;
                                    }
                                    $totalcount++;
                                }
                            }
                            $passedc[$i] = $paasedcount;
                            $failedc[$i] = $failedcount;
                            $totalc[$i] = $totalcount;
                        }
                        $b = '';
                        for($j=0; $j<3; $j++)
                        {
                            if($j == 0)
                            {
                                $status = 'PASSED';
                            }
                            if($j == 1)
                            {
                                $status = 'FAILED';
                            }
                            if($j == 2)
                            {
                                $status = 'PASS (%)';
                            }
                            $b .= '<tr>';
                            $b .= '<td colspan="3">'.$status.'</td>';
                            for($i=0; $i<sizeof($subcode); $i++)
                            {
                                if($j == 0)
                                {
                                    $b .= '<td colspan="3">'.$passedc[$i].'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="3"> All Pass Candidates: </td><td>'.$allpass.'</td>';
                                    }
                                }
                                if($j == 1)
                                {
                                    $b .= '<td colspan="3">'.$failedc[$i].'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="3"> Single Subject Failed Candidates: </td><td>'.$sinlesubject.'</td>';
                                    }
                                }
                                if($j == 2)
                                {
                                    $per = ($passedc[$i]/$totalc[$i])*100;
                                    $b .= '<td colspan="3">'.number_format($per, 2).'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="3"> Double Subject Failed Candidates: </td><td>'.$doublesubject.'</td>';
                                    }
                                }
                            }
                            $b .= '</tr>';
                            
                        }
                        $passpercent = $allpass/sizeof($no)*100;
                        $totalfailed = sizeof($no)-$allpass;
                        $b .= '<tr><td colspan="3">Total Students Appeared</td><td colspan="3">'.sizeof($no).'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Number of Students Passed</td><td colspan="3">'.$allpass.'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Number of failed Students</td><td colspan="3">'.$totalfailed.'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Pass Percentage (%)</td><td colspan="3">'.number_format($passpercent, 2).'</td></tr>';
                        
                        $thead = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead .= '<th colspan="3">'.$subcode[$i].'</th>';
                        }
                        $thead1 = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead1 .= '<th colspan="3">'.$subname[$i].'</th>';
                        }
                        $thead2 = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead2 .= '<th>INT</th><th>EXT</th><th>TOTAL</th>';
                        }
                        $head = '<thead>
                                    <tr>
                                        <th colspan="3">Course: </th><th colspan="6">'.static::course($_POST['course']).'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Department: </th><th colspan="6">'.static::dept($_POST['department']).'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Year: </th><th colspan="6">'.$_POST['year'].'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Sem: </th><th colspan="6">'.$_POST['sem'].'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Academic Year: </th><th colspan="6">'.$_POST['fromyear'].' - '.$_POST['toyear'].'</th>
                                    </tr>
                                    <tr>
                                        <th rowspan="3">S. No.</th>
                                        <th rowspan="3">Hallticket Number</th>
                                        <th rowspan="3">Name of the Candidate</th>
                                        '.$thead.'
                                        <th rowspan="3">Backlogs Count</th>
                                        <th rowspan="3">Total Marks</th>
                                        <th rowspan="3">Maximum Total Marks</th>
                                        <th rowspan="3">Percentage</th>
                                    </tr>
                                    <tr>
                                        '.$thead1.'
                                    </tr>
                                    <tr>
                                        '.$thead2.'
                                    </tr>
                                </thead>';
                        $body = $head.'<tbody>'; 
                        $body .= $a;
                        $body .= $b;
                        $body .= '</tbody>';
                        $table = '
                            <div class="table-responsive" id="exporttable">
                                <table class="table table-responsive-sm" border="1px">
                                '.$body.'
                                </table>
                            </div>
                        ';
                        $subtable .= $table;
                        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                        $subtable1 = '
                            <div class="container">
                                <div class="row">
                                    <div class="col-md-9"></div>
                                    <div class="col-md-2">
                                        <div class="float-right">
                                            <button onclick="window.print();">Print</button>
                                        </div>
                                    </div>
                                    <div class="col-md-1"></div>
                                </div>
                            </div>';
                    }     
                } 
                if($_POST['course'] ==2)
                {
                    $sql = "SELECT um.no, um.name, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.grade, ug.grade points, rd.credit, ug.failstatus, rd.exammonth, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, m.month_name, rd.fk_course_id FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN ug_grademarks ug ON rd.grade=ug.level JOIN month m ON rd.exammonth=m.month_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]'";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        $sub_code = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                            $sub_code[] = $h['sub_code'];
                        }
                        $no = array_values(array_unique($ht_no));
                        sort($no);
                        $subcode = array_values(array_unique($sub_code));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    if($data[$j]['failstatus'] == 0)
                                    {
                                        // passed
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['exammonth'] = $data[$j]['exammonth'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['grade'] = $data[$j]['grade'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['points'] = $data[$j]['points'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['credit'] = $data[$j]['credit'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['status'] = $data[$j]['failstatus'];
                                    }
                                    if($data[$j]['failstatus'] == 1)
                                    {
                                        //failed
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['exammonth'] = $data[$j]['exammonth'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['grade'] = $data[$j]['grade'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['points'] = $data[$j]['points'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['credit'] = $data[$j]['credit'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['status'] = $data[$j]['failstatus'];
                                    }
                                }
                            }
                        }
                        $a = '';
                        $allpass=0;
                        $sinlesubject = 0;
                        $doublesubject = 0;
                        $triplesubject = 0;
                        $allfail = 0;
                        $sno = 0;
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            $backlog=0;
                            $total = 0;
                            $credits = 0;
                            $total_max = 0;
                            $a .= '<tr>';
                            $k = 0;
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if(isset($details[$no[$i]][$subcode[$j]]))
                                {
                                    $backlog= $backlog+$details[$no[$i]][$subcode[$j]]['status'];
                                    $total= $total+$details[$no[$i]][$subcode[$j]]['points'];
                                    $credits = $credits+$details[$no[$i]][$subcode[$j]]['credit'];
                                    if($details[$no[$i]][$subcode[$j]]['grade'] !='COMPLETED')
                                    {
                                        $total_max = $total_max+10;
                                    }
                                    if($k == 0)
                                    {
                                        $sno++;
                                        $a .= '<td>'.$sno.'</td>';
                                        $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                        $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                        $k = 1;
                                    }
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['grade'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['points'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['credit'].'</td>';
                                    if($j == (sizeof($subcode)-1))
                                    {
                                        $percentage = ($total/$total_max)*10;
                                        $a .= '<td>'.$backlog.'</td>';
                                        $a .= '<td>'.$credits.'</td>';
                                        $a .= '<td>'.$total.'</td>';
                                        $a .= '<td>'.$total_max.'</td>';
                                        $a .= '<td>'.number_format($percentage, 1).'</td>';
                                        if($backlog == 0)
                                        {
                                            $allpass++;
                                        }
                                        if($backlog == 1)
                                        {
                                            $sinlesubject++;
                                        }
                                        if($backlog == 2)
                                        {
                                            $doublesubject++;
                                        }
                                        if($backlog == 3)
                                        {
                                            $triplesubject++;
                                        }
                                        if($backlog >= sizeof($subcode))
                                        {
                                            $allfail = 0;
                                        }
                                        if($percentage >= 9)
                                        {
                                            $a .= '<td>O</td>';
                                        }
                                        if($percentage >= 8 && $percentage < 9)
                                        {
                                            $a .= '<td>S</td>';
                                        }
                                        if($percentage >= 7 && $percentage < 8)
                                        {
                                            $a .= '<td>A</td>';
                                        }
                                        if($percentage >= 6 && $percentage < 7)
                                        {
                                            $a .= '<td>B</td>';
                                        }
                                        if($percentage >= 5 && $percentage < 6)
                                        {
                                            $a .= '<td>C</td>';
                                        }
                                        if($percentage >= 4 && $percentage < 5)
                                        {
                                            $a .= '<td>D</td>';
                                        }
                                        if($percentage < 4)
                                        {
                                            $a .= '<td>F</td>';
                                        }
                                    }                               
                                }
                            }
                            $a .= '</tr>'; 
                        }
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $paasedcount = 0;
                            $failedcount = 0;
                            $totalcount = 0;
                            for($j=0; $j<sizeof($no); $j++)
                            {
                                if(isset($details[$no[$j]][$subcode[$i]]))
                                {
                                    if($details[$no[$j]][$subcode[$i]]['status'] == 0)
                                    {
                                        $paasedcount++;
                                    }
                                    if($details[$no[$j]][$subcode[$i]]['status'] == 1)
                                    {
                                        $failedcount++;
                                    }
                                    $totalcount++;
                                }
                            }
                            $passedc[$i] = $paasedcount;
                            $failedc[$i] = $failedcount;
                            $totalc[$i] = $totalcount;
                        }
                        $b = '';
                        for($j=0; $j<3; $j++)
                        {
                            if($j == 0)
                            {
                                $status = 'PASSED';
                            }
                            if($j == 1)
                            {
                                $status = 'FAILED';
                            }
                            if($j == 2)
                            {
                                $status = 'PASS (%)';
                            }
                            $b .= '<tr>';
                            $b .= '<td colspan="3">'.$status.'</td>';
                            for($i=0; $i<sizeof($subcode); $i++)
                            {
                                if($j == 0)
                                {
                                    $b .= '<td colspan="3">'.$passedc[$i].'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="4"> All Pass Candidates: </td><td>'.$allpass.'</td>';
                                    }
                                }
                                if($j == 1)
                                {
                                    $b .= '<td colspan="3">'.$failedc[$i].'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="4"> Single Subject Failed Candidates: </td><td>'.$sinlesubject.'</td>';
                                    }
                                }
                                if($j == 2)
                                {
                                    $per = ($passedc[$i]/$totalc[$i])*100;
                                    $b .= '<td colspan="3">'.number_format($per, 2).'</td>';
                                    if($i == sizeof($subcode)-1)
                                    {
                                        $b .= '<td colspan="4"> Double Subject Failed Candidates: </td><td>'.$doublesubject.'</td>';
                                    }
                                }
                            }
                            $b .= '</tr>';
                        }
                        $passpercent = $allpass/sizeof($no)*100;
                        $totalfailed = sizeof($no)-$allpass;
                        $b .= '<tr><td colspan="3">Total Students Appeared</td><td colspan="3">'.sizeof($no).'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Number of Students Passed</td><td colspan="3">'.$allpass.'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Number of failed Students</td><td colspan="3">'.$totalfailed.'</td></tr>';
                        $b .= '<tr><td colspan="3">Total Pass Percentage (%)</td><td colspan="3">'.number_format($passpercent, 2).'</td></tr>';
                        
                        $thead = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead .= '<th colspan="3">'.$subcode[$i].'</th>';
                        }
                        $thead1 = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead1 .= '<th colspan="3">'.$subname[$i].'</th>';
                        }
                        $thead2 = '';
                        for($i=0; $i<sizeof($subcode); $i++)
                        {
                            $thead2 .= '<th>Grade</th><th>Points</th><th>Credits</th>';
                        }
                        $head = '<thead>
                                    <tr>
                                        <th colspan="3">Course: </th><th colspan="6">'.static::course($_POST['course']).'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Department: </th><th colspan="6">'.static::dept($_POST['department']).'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Year: </th><th colspan="6">'.$_POST['year'].'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Sem: </th><th colspan="6">'.$_POST['sem'].'</th>
                                    </tr>
                                    <tr>
                                        <th colspan="3">Academic Year: </th><th colspan="6">'.$_POST['fromyear'].' - '.$_POST['toyear'].'</th>
                                    </tr>
                                    <tr>
                                        <th rowspan="3">S. No.</th>
                                        <th rowspan="3">Hallticket Number</th>
                                        <th rowspan="3">Name of the Candidate</th>
                                        '.$thead.'
                                        <th rowspan="3">Backlogs Count</th>
                                        <th rowspan="3">Total Credits</th>
                                        <th rowspan="3">Total Points</th>
                                        <th rowspan="3">Maximum Total Points</th>
                                        <th rowspan="3">Average CGPA</th>
                                        <th rowspan="3">Final Grade</th>
                                    </tr>
                                    <tr>
                                        '.$thead1.'
                                    </tr>
                                    <tr>
                                        '.$thead2.'
                                    </tr>
                                </thead>';
                        
                        $body = $head.'<tbody>'; 
                        $body .= $a;
                        $body .= $b;
                        $body .= '</tbody>';
                        $table = '
                            <div class="table-responsive" id="exporttable">
                                <table class="table table-responsive-sm" border="1px">
                                '.$body.'
                                </table>
                            </div>
                        ';
                        $subtable .= $table;
                        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                        
                        // echo json_encode($details);
                    }
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Sem wise Consolidated Marks Analysis</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control" required>
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control"  required>
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control"  required>
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control"  required>
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control"  required>
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()"  required>
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-12">
                            '.$subtable.'
                            </div>
                        </div>
                    </div>
                </form>
                ';

            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }   
    }
    public static function sbacklogs()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $subtable = '';
            if(isset($_POST['course']))
            {
                if($_POST['type'] == '1')
                {
                    if($_POST['course'] == 1)
                    {
                        $sql = "SELECT um.no, um.name, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.exammonth, rd.examyear, rd.resultdate, m.month_name, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON sd.subcode=rd.sub_code JOIN month m ON m.month_id=rd.exammonth WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.org_id='$_SESSION[org_id]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.status='1' AND um.regulation=sd.regulation ORDER BY um.no ASC";
                        $data = Homem::getdata($sql);
                        if(sizeof($data) > 0)
                        {
                            $ht_no = array();
                            $r_date = array();
                            $sub_code = array();
                            foreach ($data as $h) {
                                $ht_no[] = $h['no'];
                                $r_date[] = $h['resultdate'];
                                $sub_code[] = $h['sub_code'];
                            }
                            $no = array_values(array_unique($ht_no));
                            sort($no);
                            $subcode = array_values(array_unique($sub_code));
                            sort($subcode);
                            $date = array_values(array_unique($r_date));
                            sort($date);
                            for($i=0; $i<sizeof($data); $i++)
                            {
                                for($j=0; $j<sizeof($subcode); $j++)
                                {
                                    if($data[$i]['sub_code'] == $subcode[$j])
                                    {
                                        $subname[$j] = $data[$i]['sub_name'];
                                    }
                                }
                            }
                            for($i=0; $i<sizeof($date); $i++)
                            {  
                                for($j=0; $j<sizeof($data); $j++)
                                {
                                    if($data[$j]['resultdate'] == $date[$i])
                                    {
                                        $count = $i+1;
                                        $total_status = 0;
                                        $data[$j]['external'] = (int) $data[$j]['external'];
                                            $data[$j]['total'] = $data[$j]['external']+$data[$j]['internal'];
                                            if(($data[$j]['total_mand'] == 1 && $data[$j]['total'] >= $data[$j]['total_pass']) || $data[$j]['total_mand'] == 0)
                                            {
                                                $total_status = 1;
                                            }
                                            $ext_status = 0;
                                            if(($data[$j]['ext_mand'] == 1 && $data[$j]['external'] >= $data[$j]['ext_pass']) || $data[$j]['ext_mand'] == 0)
                                            {
                                                $ext_status = 1;
                                            }
                                            $int_status = 0;
                                            if(($data[$j]['int_mand'] == 1 && $data[$j]['internal'] >= $data[$j]['int_pass']) || $data[$j]['int_mand'] == 0)
                                            {
                                                $int_status = 1;
                                            }
                                            $absent = 0;
                                            if($data[$j]['external'] == 'A')
                                            {
                                                $absent = 1;
                                            }
                                        if(($int_status == 0 || $ext_status == 0 || $total_status == 0) && ($absent==1 || $absent==0))
                                        {
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['internal'] = $data[$j]['internal'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['external'] = $data[$j]['external'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['total'] = $data[$j]['internal']+$data[$j]['external'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                        }
                                    }
                                }
                            }
                            $a = '';
                            $sno = 1;
                            for($i=0; $i<sizeof($no); $i++)
                            {
                                $k=0;
                                for($j=0; $j<sizeof($subcode); $j++)
                                {
                                    if(isset($details[$no[$i]][$subcode[$j]]))
                                    {
                                        if(sizeof($details[$no[$i]]) == 1)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td>'.$sno.'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.sizeof($details[$no[$i]]).'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                            $sno++;
                                        }
                                        if(sizeof($details[$no[$i]]) > 1 && $k==1)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                        }
                                        if(sizeof($details[$no[$i]]) > 1 && $k==0)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$sno.'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.sizeof($details[$no[$i]]).'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                            $k = 1;
                                            $sno++;
                                        }
                                        
                                    }
                                }
                            }
                            $head = '<thead>
                                        <tr>
                                            <th colspan="1">
                                                Diploma
                                            </th>
                                            <th colspan="2">
                                                '.static::dept($_POST['department']).'
                                            </th>
                                            <th colspan="1">
                                                Year : '.$_POST['year'].'
                                            </th>
                                            <th colspan="1">
                                                Sem : '.$_POST['sem'].'
                                            </th>
                                            <th colspan="1">
                                                Batch : '.$_POST['fromyear'].'-'.$_POST['toyear'].'
                                            </th>
                                        </tr>
                                        <tr>
                                            <th>S. No.</th>
                                            <th>Hallticket Number</th>
                                            <th>Name of the Candidate</th>
                                            <th>Number of Backlogs</th>
                                            <th>Subject Code</th>
                                            <th>Subject Name</th>
                                        </tr>
                                    </thead>';
                            $body = '<tbody>'; 
                            $body .= $a;
                            $body .= '</tbody>';
                            $table = '
                                <div class="table-responsive" id="exporttable">
                                    <table class="table table-responsive-sm" border="1px">'.$head.'
                                    '.$body.'
                                    </table>
                                </div>
                            ';
                            $subtable .= $table;
                            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                            
                            $subtable1 = '
                                <div class="container">
                                    <div class="row">
                                        <div class="col-md-9"></div>
                                        <div class="col-md-2">
                                            <div class="float-right">
                                                <button onclick="window.print();">Print</button>
                                            </div>
                                        </div>
                                        <div class="col-md-1"></div>
                                    </div>
                                </div>';
                        }     
                    } 
                    if($_POST['course'] == 2)
                    {
                        $sql = "SELECT um.no, um.name, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.grade, ug.grade points, rd.credit, ug.failstatus, rd.exammonth, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, m.month_name, rd.fk_course_id FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN ug_grademarks ug ON rd.grade=ug.level JOIN month m ON rd.exammonth=m.month_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]'";
                        $data = Homem::getdata($sql);
                        if(sizeof($data) > 0)
                        {
                            $ht_no = array();
                            $r_date = array();
                            $sub_code = array();
                            foreach ($data as $h) {
                                $ht_no[] = $h['no'];
                                $r_date[] = $h['resultdate'];
                                $sub_code[] = $h['sub_code'];
                            }
                            $no = array_values(array_unique($ht_no));
                            sort($no);
                            $subcode = array_values(array_unique($sub_code));
                            sort($subcode);
                            $date = array_values(array_unique($r_date));
                            sort($date);
                            for($i=0; $i<sizeof($data); $i++)
                            {
                                for($j=0; $j<sizeof($subcode); $j++)
                                {
                                    if($data[$i]['sub_code'] == $subcode[$j])
                                    {
                                        $subname[$j] = $data[$i]['sub_name'];
                                    }
                                }
                            }
                            for($i=0; $i<sizeof($date); $i++)
                            {  
                                for($j=0; $j<sizeof($data); $j++)
                                {
                                    if($data[$j]['resultdate'] == $date[$i])
                                    {
                                        $count = $i+1;
                                        $total_status = 0;
                                        if($data[$j]['failstatus'] == 1)
                                        {
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                            $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                        }
                                    }
                                }
                            }
                            $a = '';
                            $sno = 1;
                            for($i=0; $i<sizeof($no); $i++)
                            {
                                $k=0;
                                for($j=0; $j<sizeof($subcode); $j++)
                                {
                                    if(isset($details[$no[$i]][$subcode[$j]]))
                                    {
                                        if(sizeof($details[$no[$i]]) == 1)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td>'.$sno.'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.sizeof($details[$no[$i]]).'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                            $sno++;
                                        }
                                        if(sizeof($details[$no[$i]]) > 1 && $k==1)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                        }
                                        if(sizeof($details[$no[$i]]) > 1 && $k==0)
                                        {
                                            $a .= '<tr>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$sno.'</td>';
                                            
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                            $a .= '<td rowspan="'.sizeof($details[$no[$i]]).'">'.sizeof($details[$no[$i]]).'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                            $a .= '</tr>';
                                            $k = 1;
                                            $sno++;
                                        }
                                        
                                    }
                                }
                            }
                            $head = '<thead>
                                        <tr>
                                            <th colspan="1">
                                                B.Tech
                                            </th>
                                            <th colspan="2">
                                                '.static::dept($_POST['department']).'
                                            </th>
                                            <th colspan="1">
                                                Year : '.$_POST['year'].'
                                            </th>
                                            <th colspan="1">
                                                Sem : '.$_POST['sem'].'
                                            </th>
                                            <th colspan="1">
                                                Batch : '.$_POST['fromyear'].'-'.$_POST['toyear'].'
                                            </th>
                                        </tr>
                                        <tr>
                                            <th>S. No.</th>
                                            <th>Hallticket Number</th>
                                            <th>Name of the Candidate</th>
                                            <th>Number of Backlogs</th>
                                            <th>Subject Code</th>
                                            <th>Subject Name</th>
                                        </tr>
                                    </thead>';
                            $body = '<tbody>'; 
                            $body .= $a;
                            $body .= '</tbody>';
                            $table = '
                                <div class="table-responsive" id="exporttable">
                                    <table class="table table-responsive-sm" border="1px">'.$head.'
                                    '.$body.'
                                    </table>
                                </div>
                            ';
                            $subtable .= $table;
                            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                            
                            $subtable1 = '
                                <div class="container">
                                    <div class="row">
                                        <div class="col-md-9"></div>
                                        <div class="col-md-2">
                                            <div class="float-right">
                                                <button onclick="window.print();">Print</button>
                                            </div>
                                        </div>
                                        <div class="col-md-1"></div>
                                    </div>
                                </div>';
                        }     
                    }
                }
                if($_POST['type'] == '2')
                {
                   $data = Homem::getdata("SELECT um.no, um.name, rd.sub_code, rd.sub_name, rd.grade, rd.resultdate FROM results_data rd JOIN user_master um ON um.no=rd.ht_no WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]' AND um.regulation='$_POST[regulation]' AND rd.grade!='No Change'");
                   if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        $sub_code = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                            $sub_code[] = $h['sub_code'];
                        }
                        $no = array_values(array_unique($ht_no));
                        sort($no);
                        $subcode = array_values(array_unique($sub_code));
                        sort($subcode);
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $subname[$subcode[$j]] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        $a='';
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                $status=0;
                                for($k=0; $k<sizeof($data); $k++)
                                {
                                    if($no[$i] == $data[$k]["no"] && $subcode[$j]==$data[$k]["sub_code"])
                                    {
                                        if($data[$k]["grade"] != "F" && $data[$k]["grade"] != "No Change" && $data[$k]["grade"] != "AB")
                                        {
                                            $status = 1;
                                        }
                                    }
                                }
                                if($status==0)
                                {
                                    $deatils[$no[$i]][$subcode[$j]]="FAIL";
                                    $a .= '<tr><td>'.$no[$i].'</td><td>'.$subcode[$j].'</td><td>'.$subname[$subcode[$j]].'</td></tr>';
                                }
                            }
                        }
                        // echo json_encode($deatils);
                        
                        $head = '<thead>
                                        <tr>
                                            <th colspan="1">
                                                B.Tech
                                            </th>
                                            <th colspan="2">
                                                '.static::dept($_POST['department']).'
                                            </th>
                                            <th colspan="1">
                                                Year : '.$_POST['year'].'
                                            </th>
                                            <th colspan="1">
                                                Sem : '.$_POST['sem'].'
                                            </th>
                                            <th colspan="1">
                                                Batch : '.$_POST['fromyear'].'-'.$_POST['toyear'].'
                                            </th>
                                        </tr>
                                        <tr>
                                            <th>S. No.</th>
                                            <th>Hallticket Number</th>
                                            <th>Name of the Candidate</th>
                                            <th>Number of Backlogs</th>
                                            <th>Subject Code</th>
                                            <th>Subject Name</th>
                                        </tr>
                                    </thead>';
                            $body = '<tbody>'; 
                            $body .= $a;
                            $body .= '</tbody>';
                            $table = '
                                <div class="table-responsive" id="exporttable">
                                    <table class="table table-responsive-sm" border="1px">'.$head.'
                                    '.$body.'
                                    </table>
                                </div>
                            ';
                            $subtable .= $table;
                            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                            
                            $subtable1 = '
                                <div class="container">
                                    <div class="row">
                                        <div class="col-md-9"></div>
                                        <div class="col-md-2">
                                            <div class="float-right">
                                                <button onclick="window.print();">Print</button>
                                            </div>
                                        </div>
                                        <div class="col-md-1"></div>
                                    </div>
                                </div>';
                        
                    }
                    
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/main/sbacklogs" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Sem wise Backlogs</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="type" id="type" class="form-control">
                                                                <option value="">Select Type of Result</option>
                                                                <option value="1">Marks System</option>
                                                                <option value="2">Grade System</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="regulation" id="regulation" class="form-control">
                                                                <option value="">Select Regulation</option>
                                                                <option value="R20">R20</option>
                                                                <option value="R19">R19</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';

            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }   
    }
    public static function subwisefailistinsem()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $subtable = '';
            if(isset($_POST['course']))
            {
                if($_POST['course'] == 1)
                {
                    $sql = "SELECT um.no, um.name, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.exammonth, rd.examyear, rd.resultdate, m.month_name, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON sd.subcode=rd.sub_code JOIN month m ON m.month_id=rd.exammonth WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.org_id='$_SESSION[org_id]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.status='1' AND um.regulation=sd.regulation ORDER BY um.no ASC";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        $sub_code = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                            $sub_code[] = $h['sub_code'];
                        }
                        $no = array_values(array_unique($ht_no));
                        $subcode = array_values(array_unique($sub_code));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    $count = $i+1;
                                    $total_status = 0;
                                    $data[$j]['external'] = (int) $data[$j]['external'];
                                        $data[$j]['total'] = $data[$j]['external']+$data[$j]['internal'];
                                        if(($data[$j]['total_mand'] == 1 && $data[$j]['total'] >= $data[$j]['total_pass']) || $data[$j]['total_mand'] == 0)
                                        {
                                            $total_status = 1;
                                        }
                                        $ext_status = 0;
                                        if(($data[$j]['ext_mand'] == 1 && $data[$j]['external'] >= $data[$j]['ext_pass']) || $data[$j]['ext_mand'] == 0)
                                        {
                                            $ext_status = 1;
                                        }
                                        $int_status = 0;
                                        if(($data[$j]['int_mand'] == 1 && $data[$j]['internal'] >= $data[$j]['int_pass']) || $data[$j]['int_mand'] == 0)
                                        {
                                            $int_status = 1;
                                        }
                                        $absent = 0;
                                        if($data[$j]['external'] == 'A')
                                        {
                                            $absent = 1;
                                        }
                                    if(($int_status == 0 || $ext_status == 0 || $total_status == 0) && ($absent==1 || $absent==0))
                                    {
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['internal'] = $data[$j]['internal'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['external'] = $data[$j]['external'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['total'] = $data[$j]['internal']+$data[$j]['external'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $data[$j]['resultdate'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                    }
                                }
                            }
                        }
                        $a = '';
                        for($j=0; $j<sizeof($subcode); $j++)
                        {
                            $k = 0;
                            for($i=0; $i<sizeof($no); $i++)
                            {
                                if(isset($details[$no[$i]][$subcode[$j]]['sub_code']))
                                {
                                    $k++;
                                    if($k == 1)
                                    {
                                        $a .= '<tr>';
                                        $a .= '<td colspan="3">Subject Code:-'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                        $a .= '<td colspan="6">Subject Name:-'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                        $a .= '</tr>';
                                    }
                                    $a .= '<tr>';
                                    $a .= '<td>'.$k.'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['internal'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['external'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['month'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['examyear'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['count'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['resultdate'].'</td>';
                                    $a .= '</tr>';
                                }
                            }
                        }
                        $head = '<thead>
                                    <tr>
                                        <th colspan="2">
                                            Diploma
                                        </th>
                                        <th colspan="3">
                                            Batch : '.$_POST['fromyear'].'-'.$_POST['toyear'].'
                                        </th>
                                        <th colspan="2">
                                            Year : '.$_POST['year'].'
                                        </th>
                                        <th colspan="2">
                                            Sem : '.$_POST['sem'].'
                                        </th>
                                    </tr>
                                    <tr>
                                        <th>S. No.</th>
                                        <th>Hallticket Number</th>
                                        <th>Name of the Candidate</th>
                                        <th>Internal</th>
                                        <th>External</th>
                                        <th>Month</th>
                                        <th>Year</th>
                                        <th>Attempts</th>
                                        <th>Result Date</th>
                                    </tr>
                                </thead>';
                        $body = '<tbody>'; 
                        $body .= $a;
                        $body .= '</tbody>';
                        $table = '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm" border="1px">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';
                        $subtable .= $table;
                        $subtable1 = '
                            <div class="container">
                                <div class="row">
                                    <div class="col-md-9"></div>
                                    <div class="col-md-2">
                                        <div class="float-right">
                                            <button onclick="window.print();">Print</button>
                                        </div>
                                    </div>
                                    <div class="col-md-1"></div>
                                </div>
                            </div>';
                    }     
                } 
                if($_POST['course'] == 2)
                {
                    $sql = "SELECT um.no, um.name, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.grade, ug.grade points, rd.credit, ug.failstatus, rd.exammonth, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, m.month_name, rd.fk_course_id FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN ug_grademarks ug ON rd.grade=ug.level JOIN month m ON rd.exammonth=m.month_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]'";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        $sub_code = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                            $sub_code[] = $h['sub_code'];
                        }
                        $no = array_values(array_unique($ht_no));
                        $subcode = array_values(array_unique($sub_code));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    $count = $i+1;
                                    $total_status = 0;
                                    if($data[$j]['failstatus'] == 1)
                                    {
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['resultdate'] = $date[$i];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['no'] = $data[$j]['no'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['name'] = $data[$j]['name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_code'] = $data[$j]['sub_code'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['sub_name'] = $data[$j]['sub_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['month'] = $data[$j]['month_name'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['examyear'] = $data[$j]['examyear'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['count'] = $count;
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['grade'] = $data[$j]['grade'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['points'] = $data[$j]['points'];
                                        $details[$data[$j]['no']][$data[$j]['sub_code']]['credit'] = $data[$j]['credit'];
                                    }
                                }
                            }
                        }
                        $a = '';
                        for($j=0; $j<sizeof($subcode); $j++)
                        {
                            $k = 0;
                            for($i=0; $i<sizeof($no); $i++)
                            {
                                if(isset($details[$no[$i]][$subcode[$j]]['sub_code']))
                                {
                                    $k++;
                                    if($k == 1)
                                    {
                                        $a .= '<tr>';
                                        $a .= '<td colspan="3">Subject Code:-'.$details[$no[$i]][$subcode[$j]]['sub_code'].'</td>';
                                        $a .= '<td colspan="6">Subject Name:-'.$details[$no[$i]][$subcode[$j]]['sub_name'].'</td>';
                                        $a .= '</tr>';
                                    }
                                    $a .= '<tr>';
                                    $a .= '<td>'.$k.'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['no'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['name'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['grade'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['points'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['month'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['examyear'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['count'].'</td>';
                                    $a .= '<td>'.$details[$no[$i]][$subcode[$j]]['resultdate'].'</td>';
                                    $a .= '</tr>';
                                }
                            }
                        }
                        $head = '<thead>
                                    <tr>
                                        <th colspan="1">
                                            B.Tech
                                        </th>
                                        <th colspan="2">
                                            Batch : '.$_POST['fromyear'].'-'.$_POST['toyear'].'
                                        </th>
                                        <th colspan="3">
                                            Year : '.$_POST['year'].'
                                        </th>
                                        <th colspan="3">
                                            Sem : '.$_POST['sem'].'
                                        </th>
                                    </tr>
                                    <tr>
                                        <th>S. No.</th>
                                        <th>Regd. No.</th>
                                        <th>Name of the Candidate</th>
                                        <th>Grade</th>
                                        <th>Credits</th>
                                        <th>Month</th>
                                        <th>Year</th>
                                        <th>Attempts</th>
                                        <th>Result Date</th>
                                    </tr>
                                </thead>';
                        $body = '<tbody>'; 
                        $body .= $a;
                        $body .= '</tbody>';
                        $table = '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm" border="1px">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';
                        $subtable .= $table;
                        $subtable1 = '
                            <div class="container">
                                <div class="row">
                                    <div class="col-md-9"></div>
                                    <div class="col-md-2">
                                        <div class="float-right">
                                            <button onclick="window.print();">Print</button>
                                        </div>
                                    </div>
                                    <div class="col-md-1"></div>
                                </div>
                            </div>';
                    }     
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/main/subwisefailistinsem" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Sem wise Backlogs</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';

            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }   
    }
    public static function subwiseresults()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $subtable = '';
            if(isset($_POST['course']))
            {
                if($_POST['course'] == 1)
                {
                    $sql = "SELECT um.no, um.name, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.exammonth, rd.examyear, rd.resultdate, m.month_name, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON sd.subcode=rd.sub_code JOIN month m ON m.month_id=rd.exammonth WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.org_id='$_SESSION[org_id]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.sub_code='$_POST[subject]' AND um.regulation=sd.regulation ORDER BY um.no ASC";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                        }
                        $no = array_values(array_unique($ht_no));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    $count = $i+1;
                                    $details[$data[$j]['no']]['resultdate'] = $date[$i];
                                    $details[$data[$j]['no']]['no'] = $data[$j]['no'];
                                    $details[$data[$j]['no']]['count'] = $count;
                                }
                            }
                        }
                        $a = '';
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            if(isset($details[$no[$i]]['no']))
                            {
                                for($j=0; $j<sizeof($data); $j++)
                                {
                                    if($data[$j]['no'] == $details[$no[$i]]['no'] && $data[$j]['resultdate'] == $details[$no[$i]]['resultdate'])
                                    {
                                        $total_status = 0;
                                        $data[$j]['externalint'] = (int) $data[$j]['external'];
                                        $data[$j]['total'] = $data[$j]['externalint']+$data[$j]['internal'];
                                        if(($data[$j]['total_mand'] == 1 && $data[$j]['total'] >= $data[$j]['total_pass']) || $data[$j]['total_mand'] == 0)
                                        {
                                            $total_status = 1;
                                        }
                                        $ext_status = 0;
                                        if(($data[$j]['ext_mand'] == 1 && $data[$j]['external'] >= $data[$j]['ext_pass']) || $data[$j]['ext_mand'] == 0)
                                        {
                                            $ext_status = 1;
                                        }
                                        $int_status = 0;
                                        if(($data[$j]['int_mand'] == 1 && $data[$j]['internal'] >= $data[$j]['int_pass']) || $data[$j]['int_mand'] == 0)
                                        {
                                            $int_status = 1;
                                        }
                                        $absent = 0;
                                        if($data[$j]['external'] == 'A')
                                        {
                                            $absent = 1;
                                        }
                                        if($int_status == 1 && $ext_status == 1 && $total_status == 1 && $absent==0)
                                        {
                                            $a .= '<tr style="color:green">';
                                            $a .= '<td>'.$data[$j]['no'].'</td>';
                                            $a .= '<td>'.$data[$j]['name'].'</td>';
                                            $a .= '<td>'.$data[$j]['internal'].'</td>';
                                            $a .= '<td>'.$data[$j]['external'].'</td>';
                                            $a .= '<td>'.$data[$j]['resultdate'].'</td>';
                                            $a .= '<td>'.$data[$j]['month_name'].'</td>';
                                            $a .= '<td>'.$data[$j]['examyear'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]]['count'].'</td>';
                                            $a .= '</tr>';
                                        }
                                        if(($int_status == 0 || $ext_status == 0 || $total_status == 0) && ($absent==0 || $absent==1))
                                        {
                                            $a .= '<tr style="color:red">';
                                            $a .= '<td>'.$data[$j]['no'].'</td>';
                                            $a .= '<td>'.$data[$j]['name'].'</td>';
                                            $a .= '<td>'.$data[$j]['internal'].'</td>';
                                            $a .= '<td>'.$data[$j]['external'].'</td>';
                                            $a .= '<td>'.$data[$j]['resultdate'].'</td>';
                                            $a .= '<td>'.$data[$j]['month_name'].'</td>';
                                            $a .= '<td>'.$data[$j]['examyear'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]]['count'].'</td>';
                                            $a .= '</tr>';
                                        }
                                    }
                                }
                            }
                        }
                        $head = '<thead>
                        <tr>
                            <th>Hallticket Number</th>
                            <th>Name</th>
                            <th>Internal</th>
                            <th>External</th>
                            <th>Date of Result</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Attempts</th>
                        </tr>
                        </thead>';
                        $body = '<tbody>'; 
                        $body .= $a;
                        $body .= '</tbody>';
                        $subtable = '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm" border="1px">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';      
                    }
                } 
                if($_POST['course'] == 2)
                {
                    $sql = "SELECT um.no, um.name, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.grade, ug.grade points, rd.credit, ug.failstatus, rd.exammonth, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, m.month_name, rd.fk_course_id FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN ug_grademarks ug ON rd.grade=ug.level JOIN month m ON rd.exammonth=m.month_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]' AND rd.sub_code='$_POST[subject]'";$data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $ht_no = array();
                        $r_date = array();
                        foreach ($data as $h) {
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                        }
                        $no = array_values(array_unique($ht_no));
                        $date = array_values(array_unique($r_date));
                        sort($date);
                        for($i=0; $i<sizeof($date); $i++)
                        {  
                            for($j=0; $j<sizeof($data); $j++)
                            {
                                if($data[$j]['resultdate'] == $date[$i])
                                {
                                    $count = $i+1;
                                    $details[$data[$j]['no']]['resultdate'] = $date[$i];
                                    $details[$data[$j]['no']]['no'] = $data[$j]['no'];
                                    $details[$data[$j]['no']]['count'] = $count;
                                }
                            }
                        }
                        $a = '';
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            if(isset($details[$no[$i]]['no']))
                            {
                                for($j=0; $j<sizeof($data); $j++)
                                {
                                    if($data[$j]['no'] == $details[$no[$i]]['no'] && $data[$j]['resultdate'] == $details[$no[$i]]['resultdate'])
                                    {
                                        $total_status = 0;
                                        
                                        if($data[$j]['failstatus'] == 0)
                                        {
                                            $a .= '<tr style="color:green">';
                                            $a .= '<td>'.$data[$j]['no'].'</td>';
                                            $a .= '<td>'.$data[$j]['name'].'</td>';
                                            $a .= '<td>'.$data[$j]['grade'].'</td>';
                                            $a .= '<td>'.$data[$j]['points'].'</td>';
                                            $a .= '<td>'.$data[$j]['resultdate'].'</td>';
                                            $a .= '<td>'.$data[$j]['month_name'].'</td>';
                                            $a .= '<td>'.$data[$j]['examyear'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]]['count'].'</td>';
                                            $a .= '</tr>';
                                        }
                                        if($data[$j]['failstatus'] == 1)
                                        {
                                            $a .= '<tr style="color:red">';
                                            $a .= '<td>'.$data[$j]['no'].'</td>';
                                            $a .= '<td>'.$data[$j]['name'].'</td>';
                                            $a .= '<td>'.$data[$j]['grade'].'</td>';
                                            $a .= '<td>'.$data[$j]['points'].'</td>';
                                            $a .= '<td>'.$data[$j]['resultdate'].'</td>';
                                            $a .= '<td>'.$data[$j]['month_name'].'</td>';
                                            $a .= '<td>'.$data[$j]['examyear'].'</td>';
                                            $a .= '<td>'.$details[$no[$i]]['count'].'</td>';
                                            $a .= '</tr>';
                                        }
                                    }
                                }
                            }
                        }
                        $head = '<thead>
                        <tr>
                            <th>Hallticket Number</th>
                            <th>Name</th>
                            <th>Grade</th>
                            <th>Points</th>
                            <th>Date of Result</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Attempts</th>
                        </tr>
                        </thead>';
                        $body = '<tbody>'; 
                        $body .= $a;
                        $body .= '</tbody>';
                        $subtable = '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm" border="1px">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';      
                    }
                } 
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/main/subwiseresults" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Subject wise Results</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Subject</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            $test = '<div class="container">
                <div class="row">
                    <div class="col-md-9"></div>
                    <div class="col-md-2">
                        <div class="float-right">
                            <button onclick="window.print();">Print</button>
                        </div>
                    </div>
                    <div class="col-md-1"></div>
                </div>
            </div>';
            echo '</body>';
            echo static::script();
            echo '
                <script>
                function getsubjects()
                {
                    var course = $("#course").val();
                    var dept = $("#department").val();
                    var fy = $("#fromyear").val();
                    var ty = $("#toyear").val();
                    var year = $("#year").val();
                    var sem = $("#sem").val();
                    $.ajax({
                        url: "/main/getsubdetails",
                        type: "post",
                        data: {course: course, dept: dept, fromyear: fy, toyear: ty, year: year, sem: sem},
                        success: function(d) {
                            $("#subject").append(d);
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function deptwiseresult()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $a = '';
            if(isset($_POST['course']))
            {
                if($_POST['course'] == 1)
                {
                    $data = Homem::getdata("SELECT um.no, um.name, um.regulation, um.fk_course_id, rd.sub_code, rd.sub_name, rd.internal, rd.external, rd.grade, rd.credit credits, rd.exammonth, rd.examyear, rd.resultdate, rd.result_type, rd.examtype, sd.int_max, sd.int_pass, sd.int_mand, sd.ext_max, sd.ext_pass, sd.ext_mand, sd.total_max, sd.total_pass, sd.total_mand, sd.resulttype, sd.failgrade, sd.credit, m.month_name FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN subject_data sd ON rd.sub_code=sd.subcode JOIN month m ON m.month_id=rd.exammonth WHERE um.regulation=sd.regulation AND um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.org_id='$_SESSION[org_id]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]' AND rd.status='1' ORDER BY rd.sub_code, rd.resultdate ASC");
                    if(sizeof($data) > 0)
                    {
                        $sub_code = array();
                        $ht_no = array();
                        $r_date = array();
                        foreach ($data as $h) {
                            $sub_code[] = $h['sub_code'];
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                        }
                        $subcode = array_values(array_unique($sub_code));
                        $no = array_values(array_unique($ht_no));
                        $date = array_values(array_unique($r_date));
                        $indsubdata = array();
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $indsubdata[$j][] = $data[$i];
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        $b = array();
                        $month = array();
                        $monthstatus = 0;
                        for($i=0; $i<sizeof($date); $i++)
                        {   
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                $appeared = 0;
                                $passed = 0;
                                $failed = 0;
                                $absent = 0;
                                $absenta = 0;
                                for($k=0; $k<sizeof($indsubdata[$j]); $k++)
                                {
                                    if($date[$i] == $indsubdata[$j][$k]['resultdate'])
                                    {
                                        if(sizeof($month) < sizeof($date) && sizeof($month)<=$i)
                                        {
                                            if($indsubdata[$j][$k]['examtype'] == 1 && $i==0)
                                            {
                                                $resulttype[] = 'REGULAR';
                                            }
                                            if($indsubdata[$j][$k]['examtype'] == 1 && $i!=0)
                                            {
                                                $resulttype[] = 'SUPPLY';
                                            }
                                            if($indsubdata[$j][$k]['examtype'] == 2 && $i!=0)
                                            {
                                                $resulttype[] = 'REVALUATION';
                                            }
                                            $month[] = $indsubdata[$j][$k]['month_name'];
                                            $year[] = $indsubdata[$j][$k]['examyear'];
                                            $monthstatus++;
                                        }
                                        $appeared++;
                                        $total_status = 0;
                                        $indsubdata[$j][$k]['externalint'] = (int) $indsubdata[$j][$k]['external'];
                                        $indsubdata[$j][$k]['total'] = $indsubdata[$j][$k]['externalint']+$indsubdata[$j][$k]['internal'];
                                        if(($indsubdata[$j][$k]['total_mand'] == 1 && $indsubdata[$j][$k]['total'] >= $indsubdata[$j][$k]['total_pass']) || $indsubdata[$j][$k]['total_mand'] == 0)
                                        {
                                            $total_status = 1;
                                        }
                                        $ext_status = 0;
                                        if(($indsubdata[$j][$k]['ext_mand'] == 1 && $indsubdata[$j][$k]['external'] >= $indsubdata[$j][$k]['ext_pass']) || $indsubdata[$j][$k]['ext_mand'] == 0)
                                        {
                                            $ext_status = 1;
                                        }
                                        $int_status = 0;
                                        if(($indsubdata[$j][$k]['int_mand'] == 1 && $indsubdata[$j][$k]['internal'] >= $indsubdata[$j][$k]['int_pass']) || $indsubdata[$j][$k]['int_mand'] == 0)
                                        {
                                            $int_status = 1;
                                        }
                                        $absent = 0;
                                        if($indsubdata[$j][$k]['external'] == 'A')
                                        {
                                            $absent = 1;
                                            $absenta++;
                                            // $absenta[] = 1;
                                        }
                                        if($int_status == 1 && $ext_status == 1 && $total_status == 1 && $absent==0)
                                        {
                                            $passed++;
                                        }
                                        if(($int_status == 0 || $ext_status == 0 || $total_status == 0) && $absent==0)
                                        {
                                            $failed++;
                                        }
                                    }
                                }
                                $b[$i]['appeared'][$j] = $appeared;
                                $b[$i]['passed'][$j] = $passed;
                                $b[$i]['failed'][$j] = $failed;
                                $b[$i]['absent'][$j] = $absenta;
                            }
                        }
                        $head = '
                        <thead>
                            <tr>
                                <th>S. No.</th>
                                <th>Subject Code</th>
                                <th>Subject Name</th>
                                <th>Appeared</th>
                                <th>Passed</th>
                                <th>Failed</th>
                                <th>Absent</th>
                            </tr>
                        </thead>
                        ';
                        $body = '<tbody>';
                        for($i=0; $i<sizeof($date); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                $k = $j+1;
                                if($j == 0)
                                {
                                    $body .= '<tr><td colspan="7"> Result Released on Date: '.$date[$i].' - '.$resulttype[$i].'-'.$month[$i].'-'.$year[$i].'</td></tr>';
                                }
                                $body .= '<tr>';
                                $body .= '<td>'.$k.'</td>';
                                $body .= '<td>'.$subcode[$j].'</td>';
                                $body .= '<td>'.$subname[$j].'</td>';
                                $body .= '<td>'.$b[$i]['appeared'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['passed'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['failed'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['absent'][$j].'</td>';
                                $body .= '</tr>';
                            }
                        }
                        // echo json_encode($indsubdata);
                        $body .= '</tbody>';
                        $a= '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';
                    }
                }
                if($_POST['course'] == 2)
                {
                    $sql = "SELECT um.no, um.name, rd.year, rd.sem, rd.sub_code, rd.sub_name, rd.grade, ug.grade points, rd.credit, ug.failstatus, rd.exammonth, rd.exammonth, rd.examyear, rd.resultdate, rd.examtype, m.month_name, rd.fk_course_id FROM user_master um JOIN results_data rd ON um.no=rd.ht_no JOIN ug_grademarks ug ON rd.grade=ug.level JOIN month m ON rd.exammonth=m.month_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND rd.year='$_POST[year]' AND rd.sem='$_POST[sem]'";
                    $data = Homem::getdata($sql);
                    if(sizeof($data) > 0)
                    {
                        $sub_code = array();
                        $ht_no = array();
                        $r_date = array();
                        foreach ($data as $h) {
                            $sub_code[] = $h['sub_code'];
                            $ht_no[] = $h['no'];
                            $r_date[] = $h['resultdate'];
                        }
                        $subcode = array_values(array_unique($sub_code));
                        $no = array_values(array_unique($ht_no));
                        $date = array_values(array_unique($r_date));
                        $indsubdata = array();
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                if($data[$i]['sub_code'] == $subcode[$j])
                                {
                                    $indsubdata[$j][] = $data[$i];
                                    $subname[$j] = $data[$i]['sub_name'];
                                }
                            }
                        }
                        $b = array();
                        $month = array();
                        $monthstatus = 0;
                        for($i=0; $i<sizeof($date); $i++)
                        {   
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                $appeared = 0;
                                $passed = 0;
                                $failed = 0;
                                $absent = 0;
                                $absenta = 0;
                                for($k=0; $k<sizeof($indsubdata[$j]); $k++)
                                {
                                    if($date[$i] == $indsubdata[$j][$k]['resultdate'])
                                    {
                                        if(sizeof($month) < sizeof($date) && sizeof($month)<=$i)
                                        {
                                            if($indsubdata[$j][$k]['examtype'] == 1 && $i==0)
                                            {
                                                $resulttype[] = 'REGULAR';
                                            }
                                            if($indsubdata[$j][$k]['examtype'] == 1 && $i!=0)
                                            {
                                                $resulttype[] = 'SUPPLY';
                                            }
                                            if($indsubdata[$j][$k]['examtype'] == 2 && $i!=0)
                                            {
                                                $resulttype[] = 'REVALUATION';
                                            }
                                            if($indsubdata[$j][$k]['examtype'] == 3 && $i!=0)
                                            {
                                                $resulttype[] = 'ADV. REVALUATION';
                                            }
                                            $month[] = $indsubdata[$j][$k]['month_name'];
                                            $year[] = $indsubdata[$j][$k]['examyear'];
                                            $monthstatus++;
                                        }
                                        $appeared++;
                                        $total_status = 0;
                                        $absent = 0;
                                        if($indsubdata[$j][$k]['grade'] == 'ABSENT')
                                        {
                                            $absent = 1;
                                            $absenta++;
                                        }
                                        if($indsubdata[$j][$k]['failstatus'] == 0)
                                        {
                                            $passed++;
                                        }
                                        if($indsubdata[$j][$k]['failstatus'] == 1)
                                        {
                                            $failed++;
                                        }
                                    }
                                }
                                $b[$i]['appeared'][$j] = $appeared;
                                $b[$i]['passed'][$j] = $passed;
                                $b[$i]['failed'][$j] = $failed;
                                $b[$i]['absent'][$j] = $absenta;
                            }
                        }
                        $head = '
                        <thead>
                            <tr>
                                <th>S. No.</th>
                                <th>Subject Code</th>
                                <th>Subject Name</th>
                                <th>Appeared</th>
                                <th>Passed</th>
                                <th>Failed</th>
                                <th>Absent</th>
                            </tr>
                        </thead>
                        ';
                        $body = '<tbody>';
                        for($i=0; $i<sizeof($date); $i++)
                        {
                            for($j=0; $j<sizeof($subcode); $j++)
                            {
                                $k = $j+1;
                                if($j == 0)
                                {
                                    //'.$resulttype[$i].'
                                    $body .= '<tr><td colspan="7"> Result Released on Date: '.$date[$i].' -'.$month[$i].'-'.$year[$i].'</td></tr>';
                                }
                                $body .= '<tr>';
                                $body .= '<td>'.$k.'</td>';
                                $body .= '<td>'.$subcode[$j].'</td>';
                                $body .= '<td>'.$subname[$j].'</td>';
                                $body .= '<td>'.$b[$i]['appeared'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['passed'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['failed'][$j].'</td>';
                                $body .= '<td>'.$b[$i]['absent'][$j].'</td>';
                                $body .= '</tr>';
                            }
                        }
                        $body .= '</tbody>';
                        $a= '
                            <div class="table-responsive">
                                <table class="table table-responsive-sm">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';
                    }
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Semester Wise Result Analysis</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Semester of Course</option>
                                                                <option value="1">First Semseter</option>
                                                                <option value="2">Second Semester</option>
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$a.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function getsubdetails()
    {
        if(static::mainsessioncontrol() == 1)
        {
            $data = Homem::getdata("SELECT DISTINCT sub_code, sub_name from (SELECT um.no, um.name, um.regulation, rd.* FROM user_master um join results_data rd on rd.ht_no = um.no WHERE um.org_id='$_SESSION[org_id]' AND um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[dept]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND um.user_role='3') a WHERE `year`='$_POST[year]' AND `sem`='$_POST[sem]'");
            echo Inputs::optionsdb($data, 'sub_code', 'sub_name');
        }
    }
    public static function upstdntphotos()
    {
        if($_SESSION['user_role'] == 1 || $_SESSION['user_role'] == 6)
        {
            $a = '';
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/main/saveupstdntphotos" method="POST" enctype="multipart/form-data">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Upload Student Photos with Halltciket number as file name</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="file" name="file[]" id="file[]" placeholder="Upload Files" multiple class="form-control">
                                                        </div>
                                                    </div>    
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>'.$a.'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function saveupstdntphotos()
    {
        $extension=array("jpeg","jpg","png","gif");
        extract($_POST);
        $i = 0;
        foreach($_FILES["file"]["tmp_name"] as $key=>$tmp_name) 
        {
            $file_name=$_FILES["file"]["name"][$key];
            $file_tmp=$_FILES["file"]["tmp_name"][$key];
            $ext=pathinfo($file_name,PATHINFO_EXTENSION);
            if(in_array($ext,$extension)) 
            {
                $file_ext1 = explode('.', $file_name);
                $file_ext = $file_ext1[sizeof($file_ext1)-1];
                $type = pathinfo($file_tmp, PATHINFO_EXTENSION);
                $data = file_get_contents($file_tmp);
                $htno = $file_ext1[0];
                $base64 = 'data:image/' . $file_ext . ';base64,' . base64_encode($data);
                $pdata = Homem::getdata("SELECT * FROM `stdent_photos` WHERE `no`='$htno' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($pdata) == 0)
                {
                    Homem::insert("INSERT INTO `stdent_photos`(`no`, `fk_org_id`, `upload_by`, `photo`) VALUES ('$htno', '$_SESSION[org_id]', '$_SESSION[user_id]', '$base64')");
                    $i++;
                }
                else
                {
                    Homem::insert("UPDATE `stdent_photos` SET `upload_by`='$_SESSION[user_id]',`photo`='$base64' WHERE `no`='' AND `fk_org_id`=''");
                    $i++;
                }
            }
        }
        echo '<script>window.location="/main/upstdntphotos?status=1&count='.$i.'";</script>';
    }
    /**End of Report master */

    /* Modify date started*/
    public static function dtest() // testing for date conversion
    {
        $date = '34/35/36';
        echo static::datemodify($date);
    }
    private static function datemodify($date)
    {
        $ar = static::datesplit($date);
        if(is_array($ar))
        {
            return static::datesort($ar);
        }
    }
    private static function datesplit($date)
    {
        if(isset($date))
        {
            $d = explode("-", $date);
            if(is_array($d))
            {
                if(sizeof($d) == 3)
                {
                    return $d;
                }
                else
                {
                    $e = explode("/", $date);
                    if(is_array($e))
                    {
                        if(sizeof($e) == 3)
                        {
                            return $e;
                        }
                        else
                        {
                            $f = explode(".", $date);
                            if(is_array($f))
                            {
                                if(sizeof($f) == 3)
                                {
                                    return $f;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    private static function datesort($a)
    {
        if(strlen($a[0]) == 4)
        {
            return $a[0].'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[2]);
        }
        if(strlen($a[2]) == 4)
        {
            return $a[2].'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[0]);
        }
        if(strlen($a[2]) <= 2 && strlen($a[1]) <= 2 && strlen($a[0]) <= 2)
        {
            return static::apendyearfront($a[2]).'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[0]);
        }
    }
    private static function appendzeromonth($m)
    {
        if($m >=1 && $m <=12)
        {
            if(strlen($m) == 2)
            {
                return $m;
            }
            else
            {
                return '0'.$m;
            }
        }
        else
        {
            return '01';
        }
    }
    private static function appendzerodate($m)
    {
        if($m >=1 && $m <=31)
        {
            if(strlen($m) == 2)
            {
                return $m;
            }
            else
            {
                return '0'.$m;
            }
        }
        else
        {
            return '01';
        }
    }
    private static function apendyearfront($a)
    {
        if(strlen($a) == 2)
        {
            if(date('y') >=$a)
            {
                return '20'.$a;
            }
            else
            {
                return date('Y');
            }
        }
    }
    /* Modify date Ended*/

    /** Browser Checking code started */
    private static function checkbrower()
    {
        $mystring = $_SERVER['HTTP_USER_AGENT'];
        $word = 'Chrome';
        if(strpos($mystring, $word) !== false)
        {
            if(strpos($mystring, 'Mozilla') !== false)
            {
                return "1";
            } 
        }
        else if(strpos($mystring, 'Mozilla') !== false)
        {
            return "1";
        } 
        else
        {
            return "0";
        }
    }
    private static function checkiphone()
    {
        $iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
        $iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
        $iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
        $Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
        $webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
        if($iPod || $iPhone || $iPad || $Android || $webOS)
        {
            echo 1;
        }
        else
        {
            echo 0;
        }
    }
    /** Browser Checking code Ended */


    /**Default functions to support the main functions starting*/
    private static function year()
    {
        $year = date('Y')+5;
        $a = '';
        for($i=0; $i<=40; $i++)
        {
            $y = $year-$i;
            $a .= '<option value="'.$y.'">'.$y.'</option>';
        }
        return $a;
    }
    private static function course($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'B.Com.';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'M.Sc.';
                }
                if($id == 3)
                {
                    return 'M.Sc. (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'MCA';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'MPCS';
                }
                if($id == 2)
                {
                    return 'MSCS';
                }
                if($id == 3)
                {
                    return 'MECS';
                }
                if($id == 4)
                {
                    return 'General';
                }
                if($id == 5)
                {
                    return 'Computers';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'Agriculture';
                }
                if($id == 2)
                {
                    return 'Horticulture';
                }
                if($id == 3)
                {
                    return 'Food Technology';
                }
                if($id == 4)
                {
                    return 'Physics';
                }
                if($id == 5)
                {
                    return 'Chemistry';
                }
                if($id == 6)
                {
                    return 'Botany';
                }
                if($id == 7)
                {
                    return 'Food Processing (Vocational)';
                }
                if($id == 8)
                {
                    return 'Horticultural Landscaping (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Civil Engineering';
                }
                else if($id == 2)
                {
                    return 'Electrical & Electronics Engineering';
                }
                else if($id == 3)
                {
                    return 'Mechanical Engineering';
                }
                else if($id == 4)
                {
                    return 'Electronics & Communication Engineering';
                }
                else if($id == 5)
                {
                    return 'Computer Science Engineering';
                }
                else
                {
                    return '';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'Computers';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'Andhra Bank<br> Tution Fee';
                }
                if($id == 2)
                {
                    return 'Baroda Bank<br> Tution Fee';
                }
            }
            else if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Service Fee';
                }
            }
            else
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Bus Fee';
                }
            }
        }
    }
    private static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    private static function squota($id, $course)
    {
        if($id != '')
        {
            if($id == 'M' && $course==1)
            {
                return 'SPOT Admission';
            }
            if($id == 'M' && $course==2)
            {
                return 'Management Quota';
            }
            if($id == 'C' && ($course==1 || $course==2))
            {
                return 'Convenor Quota';
            }
            if($id == 'S')
            {
                return 'Spot Admission';
            }
        }
    }
    private static function nyear($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'First Year';
            }
            if($id == 2)
            {
                return 'Second Year';
            }
            if($id == 3)
            {
                return 'Third Year';
            }
            if($id == 4)
            {
                return 'Fourth Year';
            }
            if($id == 5)
            {
                return 'Fifth Year';
            }
        }
    }
    public static function numtotext($number)
    {
        $decimal = round($number - ($no = floor($number)), 2) * 100;
        $hundred = null;
        $digits_length = strlen($no);
        $i = 0;
        $str = array();
        $words = array(0 => '', 1 => 'one', 2 => 'two',
            3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
            7 => 'seven', 8 => 'eight', 9 => 'nine',
            10 => 'ten', 11 => 'eleven', 12 => 'twelve',
            13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
            16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
            19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
            40 => 'forty', 50 => 'fifty', 60 => 'sixty',
            70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
        $digits = array('', 'hundred','thousand','lakh', 'crore');
        while( $i < $digits_length ) {
            $divider = ($i == 2) ? 10 : 100;
            $number = floor($no % $divider);
            $no = floor($no / $divider);
            $i += $divider == 10 ? 1 : 2;
            if ($number) {
                $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
                $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
                $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
            } else $str[] = null;
        }
        $Rupees = implode('', array_reverse($str));
        $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
        return ($Rupees ? $Rupees . 'Rupees Only' : '') . $paise;
    }
    /**Default functions to support the main functions ending*/
    /**
     * Main Campus result analysis code started
     */
    public static function resetsembysubcode()// Sem change
    {
        $data = Homem::getdata("SELECT * FROM `maincampus_results`");
        for($i=0; $i<sizeof($data); $i++)
        {
            $id = $data[$i]['sno'];
            $sem = $data[$i]['sem'];
            $sub_code = $data[$i]['sub_code'];
            $b = explode("-", $sub_code);
            $c = str_split($b[0]);
            for($j=0; $j<sizeof($c); $j++)
            {
                $a = (int) $c[$j];
                if(is_numeric($a))
                {
                    if($a > 0)
                    {
                        if($a!=$sem)
                        {
                            Homem::update("UPDATE `maincampus_results` SET `sem`='$a' WHERE `sno`='$id'");
                        }
                    }   
                }
            }
        }
    }
    public static function tsem()
    {
        $data = Homem::getdata("SELECT * FROM `maincampus_results` WHERE `join_year`='2019' AND `sem`='3'");
        $ht_no = array();
        $_crse = array();
        $_dept = array();
        $_subcode = array();
        foreach ($data as $h) {
            $ht_no[] = $h['ht_no'];
            $_crse[] = $h['course'];
            $_dept[] = $h['dept'];
            $_subcode[] = $h['sub_code'];
        }
        $no = array_values(array_unique($ht_no));
        sort($no);
        $course = array_values(array_unique($_crse));
        sort($course);
        $dept = array_values(array_unique($_dept));
        sort($dept);
        $subcode = array_values(array_unique($_subcode));
        sort($subcode);
        for($a=0; $a<sizeof($subcode); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['sub_code'] == $subcode[$a])
                {
                    $subname[$subcode[$a]] = $data[$b]['sub_name'];
                }
            }
        }
        for($a=0; $a<sizeof($course); $a++)
        {
            $cdepts = array();
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($data); $c++)
                {
                    if($data[$c]['course'] == $course[$a] && 
                        $data[$c]['dept'] == $dept[$b])
                    {
                        $cdepts[] = $b;
                    }
                }
            }
            $cdept = array_values(array_unique($cdepts));
            sort($cdept);
            $cr_deptrel[$a] = $cdept;
            for($b=0; $b<sizeof($dept); $b++)
            {
                $cdeptsub = array();
                for($c=0; $c<sizeof($subcode); $c++)
                {
                    for($d=0; $d<sizeof($data); $d++)
                    {
                        if($data[$d]['course'] == $course[$a] && 
                            $data[$d]['dept'] == $dept[$b] && 
                            $data[$d]['sub_code'] == $subcode[$c])
                        {
                            $cdeptsub[] = $data[$d]['sub_code'];
                        }
                    }
                }
                if(sizeof($cdeptsub) > 0)
                {
                    $cdeptsubdata = array_values(array_unique($cdeptsub));
                    sort($cdeptsubdata);
                    $cwisesub[$a][$b] = $cdeptsubdata;
                }
            }
        }
        for($i=0; $i<sizeof($course); $i++)
        {
            for($a=0; $a<sizeof($dept); $a++)
            {
                for($b=0; $b<sizeof($subcode); $b++)
                {
                    $count = 0;
                    $eabsent = 0;
                    $epass = 0;
                    $efail = 0;
                    $eblank = 0;
                    for($c=0; $c<sizeof($data); $c++)
                    {
                        if($course[$i] == $data[$c]['course'] &&
                            $dept[$a] == $data[$c]['dept'] && 
                            $subcode[$b] == $data[$c]['sub_code'])
                        {
                            $count++;
                            if($data[$c]['ext_marks'] == 'A')
                            {
                                $eabsent++;
                            }
                            if($data[$c]['ext_status'] == 'P')
                            {
                                $epass++;
                            }
                            if($data[$c]['ext_status'] == 'F')
                            {
                                $efail++;
                            }
                            if($data[$c]['ext_marks'] == '')
                            {
                                $eblank++;
                            }
                        }
                    }
                    if($count>0)
                    {
                        $cwisesubdet[$i][$a][$subcode[$b]]['count'] = $count;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eabsent'] = $eabsent;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epass'] = $epass;
                        $cwisesubdet[$i][$a][$subcode[$b]]['efail'] = $efail;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eblank'] = $eblank;
                    }
                }
            }
        }
        $tbody = '';
        $i = 1;
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                {
                    $tbody .= '<tr>
                                <td>'.$i.'</td>
                                <td>'.$course[$a].'</td>
                                <td>'.$dept[$cr_deptrel[$a][$b]].'</td>
                                <td>'.$cwisesub[$a][$cr_deptrel[$a][$b]][$c].'</td>
                                <td>'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['count'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['eabsent'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['efail'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['eblank'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['epass'].'</td>
                                <td>'.number_format(((int) $cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['epass']/ (int) $cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['count'])*100).'</td>
                                </tr>';
                    $i++;
                }
            }
        }
        $a= 
            static::css().'
            <body>
                '.$_SESSION['menu'].'
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">
                            Third Sem
                <div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr>
                                <th>S. No.</th>
                                <th>Course</th>
                                <th>Department</th>
                                <th>Subject Code</th>
                                <th>Subject Name</th>
                                <th>Total Count</th>
                                <th>Absent</th>
                                <th>Fail</th>
                                <th>Blank</th>
                                <th>Pass</th>
                                <th>Pass (%)</th>
                            </tr>
                        </thead>
                        <tbody>
                        '.$tbody.'
                        </tbody>
                    </table>
                </div>
                </div>
                        </div>
                    </div>
                </div>
            </body>'.
            static::script();
        echo $a;
        // echo json_encode($cwisesub);
    }
    public static function fsem()
    {
        $data = Homem::getdata("SELECT * FROM `maincampus_results` WHERE `join_year`='2018' AND `sem`='5'");
        $ht_no = array();
        $_crse = array();
        $_dept = array();
        $_subcode = array();
        foreach ($data as $h) {
            $ht_no[] = $h['ht_no'];
            $_crse[] = $h['course'];
            $_dept[] = $h['dept'];
            $_subcode[] = $h['sub_code'];
        }
        $no = array_values(array_unique($ht_no));
        sort($no);
        $course = array_values(array_unique($_crse));
        sort($course);
        $dept = array_values(array_unique($_dept));
        sort($dept);
        $subcode = array_values(array_unique($_subcode));
        sort($subcode);
        for($a=0; $a<sizeof($subcode); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['sub_code'] == $subcode[$a])
                {
                    $subname[$subcode[$a]] = $data[$b]['sub_name'];
                }
            }
        }
        for($a=0; $a<sizeof($course); $a++)
        {
            $cdepts = array();
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($data); $c++)
                {
                    if($data[$c]['course'] == $course[$a] && 
                        $data[$c]['dept'] == $dept[$b])
                    {
                        $cdepts[] = $b;
                    }
                }
            }
            $cdept = array_values(array_unique($cdepts));
            sort($cdept);
            $cr_deptrel[$a] = $cdept;
            for($b=0; $b<sizeof($dept); $b++)
            {
                $cdeptsub = array();
                for($c=0; $c<sizeof($subcode); $c++)
                {
                    for($d=0; $d<sizeof($data); $d++)
                    {
                        if($data[$d]['course'] == $course[$a] && 
                            $data[$d]['dept'] == $dept[$b] && 
                            $data[$d]['sub_code'] == $subcode[$c])
                        {
                            $cdeptsub[] = $data[$d]['sub_code'];
                        }
                    }
                }
                if(sizeof($cdeptsub) > 0)
                {
                    $cdeptsubdata = array_values(array_unique($cdeptsub));
                    sort($cdeptsubdata);
                    $cwisesub[$a][$b] = $cdeptsubdata;
                }
            }
        }
        for($i=0; $i<sizeof($course); $i++)
        {
            for($a=0; $a<sizeof($dept); $a++)
            {
                for($b=0; $b<sizeof($subcode); $b++)
                {
                    $count = 0;
                    $eabsent = 0;
                    $epass = 0;
                    $efail = 0;
                    $eblank = 0;
                    for($c=0; $c<sizeof($data); $c++)
                    {
                        if($course[$i] == $data[$c]['course'] &&
                            $dept[$a] == $data[$c]['dept'] && 
                            $subcode[$b] == $data[$c]['sub_code'])
                        {
                            $count++;
                            if($data[$c]['ext_marks'] == 'A')
                            {
                                $eabsent++;
                            }
                            if($data[$c]['ext_status'] == 'P')
                            {
                                $epass++;
                            }
                            if($data[$c]['ext_status'] == 'F')
                            {
                                $efail++;
                            }
                            if($data[$c]['ext_marks'] == '')
                            {
                                $eblank++;
                            }
                        }
                    }
                    if($count>0)
                    {
                        $cwisesubdet[$i][$a][$subcode[$b]]['count'] = $count;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eabsent'] = $eabsent;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epass'] = $epass;
                        $cwisesubdet[$i][$a][$subcode[$b]]['efail'] = $efail;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eblank'] = $eblank;
                    }
                }
            }
        }
        $tbody = '';
        $i = 1;
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                {
                    $tbody .= '<tr>
                                <td>'.$i.'</td>
                                <td>'.$course[$a].'</td>
                                <td>'.$dept[$cr_deptrel[$a][$b]].'</td>
                                <td>'.$cwisesub[$a][$cr_deptrel[$a][$b]][$c].'</td>
                                <td>'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['count'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['eabsent'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['efail'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['eblank'].'</td>
                                <td>'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['epass'].'</td>
                                <td>'.number_format(((int) $cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['epass']/ (int) $cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$c]]['count'])*100).'</td>
                                </tr>';
                    $i++;
                }
            }
        }
        $a= 
            static::css().'
            <body>
                '.$_SESSION['menu'].'
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">
                            Fifth Sem
                <div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr>
                                <th>S. No.</th>
                                <th>Course</th>
                                <th>Department</th>
                                <th>Subject Code</th>
                                <th>Subject Name</th>
                                <th>Total Count</th>
                                <th>Absent</th>
                                <th>Fail</th>
                                <th>Blank</th>
                                <th>Pass</th>
                                <th>Pass (%)</th>
                            </tr>
                        </thead>
                        <tbody>
                        '.$tbody.'
                        </tbody>
                    </table>
                </div>
                </div>
                        </div>
                    </div>
                </div>
            </body>'.
            static::script();
        echo $a;
        // echo json_encode($cwisesub);
    }
    public static function tsemind()
    {
        $data = Homem::getdata("SELECT * FROM `maincampus_results` WHERE `join_year`='2019' AND `sem`='3'");
        $ht_no = array();
        $_crse = array();
        $_dept = array();
        $_subcode = array();
        foreach ($data as $h) {
            $ht_no[] = $h['ht_no'];
            $_crse[] = $h['course'];
            $_dept[] = $h['dept'];
            $_subcode[] = $h['sub_code'];
        }
        $no = array_values(array_unique($ht_no));
        sort($no);
        $course = array_values(array_unique($_crse));
        sort($course);
        $dept = array_values(array_unique($_dept));
        sort($dept);
        $subcode = array_values(array_unique($_subcode));
        sort($subcode);
        // code for subject names
        for($a=0; $a<sizeof($subcode); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['sub_code'] == $subcode[$a])
                {
                    $subname[$subcode[$a]] = $data[$b]['sub_name'];
                }
            }
        }
        // code for student names
        for($a=0; $a<sizeof($no); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['ht_no'] == $no[$a])
                {
                    $name[$no[$a]] = $data[$b]['st_name'];
                }
            }
        }
        // code for subject and student relation
        for($b=0; $b<sizeof($data); $b++)
        {
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_marks'] = $data[$b]['ext_marks'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_status'] = $data[$b]['ext_status'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_marks'] = $data[$b]['int_marks'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_status'] = $data[$b]['int_status'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_max'] = $data[$b]['int_max'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_pass'] = $data[$b]['int_pass'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_max'] = $data[$b]['ext_max'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_pass'] = $data[$b]['ext_pass'];
        }
        // Code for course dept relation, course dept stdnt relation, course dept subject relation
        for($a=0; $a<sizeof($course); $a++)
        {
            $cdepts = array();
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($data); $c++)
                {
                    if($data[$c]['course'] == $course[$a] && 
                        $data[$c]['dept'] == $dept[$b])
                    {
                        $cdepts[] = $b;
                    }
                }
            }
            $cdept = array_values(array_unique($cdepts));
            sort($cdept);
            $cr_deptrel[$a] = $cdept;
            for($b=0; $b<sizeof($dept); $b++)
            {
                $cdeptno = array();
                for($d=0; $d<sizeof($data); $d++)
                {
                    if($data[$d]['course'] == $course[$a] && 
                        $data[$d]['dept'] == $dept[$b])
                    {
                        $cdeptno[] = $data[$d]['ht_no'];
                    }
                }
                $cdepthtno = array_values(array_unique($cdeptno));
                sort($cdepthtno);
                if(sizeof($cdepthtno)>0)
                {
                    $cdepthtnos[$a][$b] = $cdepthtno;
                }
                $cdeptsub = array();
                for($c=0; $c<sizeof($subcode); $c++)
                {
                    for($d=0; $d<sizeof($data); $d++)
                    {
                        if($data[$d]['course'] == $course[$a] && 
                            $data[$d]['dept'] == $dept[$b] && 
                            $data[$d]['sub_code'] == $subcode[$c])
                        {
                            $cdeptsub[] = $data[$d]['sub_code'];
                        }
                    }
                }
                if(sizeof($cdeptsub) > 0)
                {
                    $cdeptsubdata = array_values(array_unique($cdeptsub));
                    sort($cdeptsubdata);
                    $cwisesub[$a][$b] = $cdeptsubdata;
                }
            }
        }
        for($i=0; $i<sizeof($course); $i++)
        {
            for($a=0; $a<sizeof($dept); $a++)
            {
                for($b=0; $b<sizeof($subcode); $b++)
                {
                    $count = 0;
                    $eabsent = 0;
                    $epass = 0;
                    $efail = 0;
                    $eblank = 0;
                    for($c=0; $c<sizeof($data); $c++)
                    {
                        if($course[$i] == $data[$c]['course'] &&
                            $dept[$a] == $data[$c]['dept'] && 
                            $subcode[$b] == $data[$c]['sub_code'])
                        {
                            $count++;
                            if($data[$c]['ext_marks'] == 'A')
                            {
                                $eabsent++;
                            }
                            if($data[$c]['ext_status'] == 'P')
                            {
                                $epass++;
                            }
                            if($data[$c]['ext_status'] == 'F')
                            {
                                $efail++;
                            }
                            if($data[$c]['ext_marks'] == '')
                            {
                                $eblank++;
                            }
                        }
                    }
                    if($count>0)
                    {
                        $cwisesubdet[$i][$a][$subcode[$b]]['count'] = $count;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eabsent'] = $eabsent;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epass'] = $epass;
                        $cwisesubdet[$i][$a][$subcode[$b]]['efail'] = $efail;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eblank'] = $eblank;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epassper'] = number_format(((int)$epass/(int)$count)*100);
                    }
                }
            }
        }
        $i = 1;
        // Creating Table Head
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                {
                    $thead[$a][$cr_deptrel[$a][$b]] = '';
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>
                                    <th rowspan="3">S. No</th>
                                    <th rowspan="3">HallTicket Number</th>
                                    <th rowspan="3">Name</th>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th colspan="4">'.$cwisesub[$a][$cr_deptrel[$a][$b]][$c].'</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<th rowspan="3">Total</th>';
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<th rowspan="3">Total Max</th>';
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<th rowspan="3">Percentag</th>';
                    $thead[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
                {
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th colspan="4">'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
                {
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th>External Marks</th><th>External Status</th>
                                    <th>Internal Marks</th><th>Internal Status</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
            }
        }
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                $tbody[$a][$cr_deptrel[$a][$b]] = '';
                for($c=0; $c<sizeof($cdepthtnos[$a][$cr_deptrel[$a][$b]]); $c++)
                {
                    $i = $c+1;
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$i.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c].'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$name[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]].'</td>';
                    $total = 0;
                    $total_max = 0;
                    $ext_passcount = 0;
                    $int_passcount = 0;
                    for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                    {
                        if(isset($htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks']))
                        {
                            $total = $total+(int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks'] + (int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_marks'];
                            $total_max = $total_max+(int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_max'] + (int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_max'];
                            if((int)$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks'] >= (int)$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_pass'])
                            {
                                $ext_passcount = $ext_passcount+1;
                            }  
                            if((int)$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_marks'] >= (int)$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_pass'])
                            {
                                $int_passcount = $int_passcount+1;
                            }   
                            $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_status'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_marks'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_status'].'</td>';
                        }
                        else
                        {
                            $tbody[$a][$cr_deptrel[$a][$b]] .= '<td></td><td></td><td></td><td></td>';
                        }
                    }
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$total.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$total_max.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.number_format(($total/$total_max)*100).'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$ext_passcount.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Attanded</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['count'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Absent</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['eabsent'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Faild</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['efail'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Passed</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['epass'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Pass Percentage</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['epassper'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
            }
        }
        $c = '';
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                {
                    $c .= '<div class="table-responsive"><table class="table table-responsive-sm" border="1px"><thead>'.$thead[$a][$cr_deptrel[$a][$b]].'</thead><tbody>'.$tbody[$a][$cr_deptrel[$a][$b]].'</tbody></table></div>';
                }
            }
        }
        
        $tbody = '';
        $a= 
            static::css().'
            <body>
                '.$_SESSION['menu'].'
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">
                            '.$c.'
                            </div>
                        </div>
                    </div>
                </div>
            </body>'.
            static::script();
        echo $a;
        // echo json_encode($htnowisesub);
        // $cdepthtnos[$a][$b]
        // <td colspan="4">'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</td>
    }
    public static function fsemind()
    {
        $data = Homem::getdata("SELECT * FROM `maincampus_results` WHERE `join_year`='2018' AND `sem`='5'");
        $ht_no = array();
        $_crse = array();
        $_dept = array();
        $_subcode = array();
        foreach ($data as $h) {
            $ht_no[] = $h['ht_no'];
            $_crse[] = $h['course'];
            $_dept[] = $h['dept'];
            $_subcode[] = $h['sub_code'];
        }
        $no = array_values(array_unique($ht_no));
        sort($no);
        $course = array_values(array_unique($_crse));
        sort($course);
        $dept = array_values(array_unique($_dept));
        sort($dept);
        $subcode = array_values(array_unique($_subcode));
        sort($subcode);
        // code for subject names
        for($a=0; $a<sizeof($subcode); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['sub_code'] == $subcode[$a])
                {
                    $subname[$subcode[$a]] = $data[$b]['sub_name'];
                }
            }
        }
        // code for student names
        for($a=0; $a<sizeof($no); $a++)
        {
            for($b=0; $b<sizeof($data); $b++)
            {
                if($data[$b]['ht_no'] == $no[$a])
                {
                    $name[$no[$a]] = $data[$b]['st_name'];
                }
            }
        }
        // code for subject and student relation
        for($b=0; $b<sizeof($data); $b++)
        {
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_marks'] = $data[$b]['ext_marks'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['ext_status'] = $data[$b]['ext_status'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_marks'] = $data[$b]['int_marks'];
            $htnowisesub[$data[$b]['ht_no']][$data[$b]['sub_code']]['int_status'] = $data[$b]['int_status'];
        }
        // Code for course dept relation, course dept stdnt relation, course dept subject relation
        for($a=0; $a<sizeof($course); $a++)
        {
            $cdepts = array();
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($data); $c++)
                {
                    if($data[$c]['course'] == $course[$a] && 
                        $data[$c]['dept'] == $dept[$b])
                    {
                        $cdepts[] = $b;
                    }
                }
            }
            $cdept = array_values(array_unique($cdepts));
            sort($cdept);
            $cr_deptrel[$a] = $cdept;
            for($b=0; $b<sizeof($dept); $b++)
            {
                $cdeptno = array();
                for($d=0; $d<sizeof($data); $d++)
                {
                    if($data[$d]['course'] == $course[$a] && 
                        $data[$d]['dept'] == $dept[$b])
                    {
                        $cdeptno[] = $data[$d]['ht_no'];
                    }
                }
                $cdepthtno = array_values(array_unique($cdeptno));
                sort($cdepthtno);
                if(sizeof($cdepthtno)>0)
                {
                    $cdepthtnos[$a][$b] = $cdepthtno;
                }
                $cdeptsub = array();
                for($c=0; $c<sizeof($subcode); $c++)
                {
                    for($d=0; $d<sizeof($data); $d++)
                    {
                        if($data[$d]['course'] == $course[$a] && 
                            $data[$d]['dept'] == $dept[$b] && 
                            $data[$d]['sub_code'] == $subcode[$c])
                        {
                            $cdeptsub[] = $data[$d]['sub_code'];
                        }
                    }
                }
                if(sizeof($cdeptsub) > 0)
                {
                    $cdeptsubdata = array_values(array_unique($cdeptsub));
                    sort($cdeptsubdata);
                    $cwisesub[$a][$b] = $cdeptsubdata;
                }
            }
        }
        for($i=0; $i<sizeof($course); $i++)
        {
            for($a=0; $a<sizeof($dept); $a++)
            {
                for($b=0; $b<sizeof($subcode); $b++)
                {
                    $count = 0;
                    $eabsent = 0;
                    $epass = 0;
                    $efail = 0;
                    $eblank = 0;
                    for($c=0; $c<sizeof($data); $c++)
                    {
                        if($course[$i] == $data[$c]['course'] &&
                            $dept[$a] == $data[$c]['dept'] && 
                            $subcode[$b] == $data[$c]['sub_code'])
                        {
                            $count++;
                            if($data[$c]['ext_marks'] == 'A')
                            {
                                $eabsent++;
                            }
                            if($data[$c]['ext_status'] == 'P')
                            {
                                $epass++;
                            }
                            if($data[$c]['ext_status'] == 'F')
                            {
                                $efail++;
                            }
                            if($data[$c]['ext_marks'] == '')
                            {
                                $eblank++;
                            }
                        }
                    }
                    if($count>0)
                    {
                        $cwisesubdet[$i][$a][$subcode[$b]]['count'] = $count;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eabsent'] = $eabsent;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epass'] = $epass;
                        $cwisesubdet[$i][$a][$subcode[$b]]['efail'] = $efail;
                        $cwisesubdet[$i][$a][$subcode[$b]]['eblank'] = $eblank;
                        $cwisesubdet[$i][$a][$subcode[$b]]['epassper'] = number_format(((int)$epass/(int)$count)*100);
                    }
                }
            }
        }
        $i = 1;
        // Creating Table Head
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                {
                    $thead[$a][$cr_deptrel[$a][$b]] = '';
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>
                                    <th rowspan="3">S. No</th>
                                    <th rowspan="3">HallTicket Number</th>
                                    <th rowspan="3">Name</th>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th colspan="4">'.$cwisesub[$a][$cr_deptrel[$a][$b]][$c].'</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<th rowspan="3">Total</th></tr>';
                }
                {
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th colspan="4">'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
                {
                    $thead[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    for($c=0; $c<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $c++)
                    {
                        $thead[$a][$cr_deptrel[$a][$b]] .= '
                                    <th>External Marks</th><th>External Status</th>
                                    <th>Internal Marks</th><th>Internal Status</th>';
                    }
                    $thead[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
            }
        }
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                $tbody[$a][$cr_deptrel[$a][$b]] = '';
                for($c=0; $c<sizeof($cdepthtnos[$a][$cr_deptrel[$a][$b]]); $c++)
                {
                    $i = $c+1;
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$i.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c].'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$name[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]].'</td>';
                    $total = 0;
                    for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                    {
                        if(isset($htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks']))
                        {
                            $total = $total+(int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks'] + (int) $htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_marks'];
                            $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_marks'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['ext_status'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_marks'].'</td>
                            <td>'.$htnowisesub[$cdepthtnos[$a][$cr_deptrel[$a][$b]][$c]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['int_status'].'</td>';
                        }
                        else
                        {
                            $tbody[$a][$cr_deptrel[$a][$b]] .= '<td></td><td></td><td></td><td></td>';
                        }
                    }
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td>'.$total.'</td>';
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Attanded</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['count'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Absent</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['eabsent'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Faild</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['efail'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Total Passed</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['epass'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
                $tbody[$a][$cr_deptrel[$a][$b]] .= '<tr><td colspan="3">Pass Percentage</td>';
                for($d=0; $d<sizeof($cwisesub[$a][$cr_deptrel[$a][$b]]); $d++)
                {
                    $tbody[$a][$cr_deptrel[$a][$b]] .= '<td colspan="4">'.$cwisesubdet[$a][$cr_deptrel[$a][$b]][$cwisesub[$a][$cr_deptrel[$a][$b]][$d]]['epassper'].'</td>';    
                }
                $tbody[$a][$cr_deptrel[$a][$b]] .= '</tr>';
            }
        }
        $c = '';
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($cr_deptrel[$a]); $b++)
            {
                {
                    $c .= '<div class="table-responsive"><table class="table table-responsive-sm" border="1px"><thead>'.$thead[$a][$cr_deptrel[$a][$b]].'</thead><tbody>'.$tbody[$a][$cr_deptrel[$a][$b]].'</tbody></table></div>';
                }
            }
        }
        
        $tbody = '';
        $a= 
            static::css().'
            <body>
                '.$_SESSION['menu'].'
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">

                        '.$c.'
                            </div>
                        </div>
                    </div>
                </div>
            </body>'.
            static::script();
        echo $a;
        // echo json_encode($htnowisesub);
        // $cdepthtnos[$a][$b]
        // <td colspan="4">'.$subname[$cwisesub[$a][$cr_deptrel[$a][$b]][$c]].'</td>
    }
    /**
     * Main Campus result analysis code started
     */
}