<?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 Homes extends \Core\Controller
{
    public static function studentlist()
    {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE (`fk_course_id`='1' OR `fk_course_id`='2' OR `fk_course_id`='3') AND (`fromyear`='2020' OR `fromyear`='2021')");
        echo '<table border="1px">';
        for($i=0; $i<sizeof($data); $i++)
        {
            echo '<tr>
            <td>'.$data[$i]['id'].'</td>
            <td>'.$data[$i]['no'].'</td>
            <td>'.$data[$i]['name'].'</td>
            <td>'.$data[$i]['fromyear'].'</td>
            <td>'.static::course($data[$i]['fk_course_id']).'</td>
            <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
            </tr>';
        }
        echo '</table>';
    }
    public static function accountsindex()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        if(static::checkbrower() == 1)
        {
            echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/homes/accountsauth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Login Here</div>
                                            </div>
                                            <div class="form-group">
                                                <select class="form-control" name="orgname" id="orgname" required>
                                                    <option value="">Select College</option>
                                                    <option value="1">Hindu College - Main Campus (Unaided)</option>
                                                    <option value="2">Hindu College (UG & PG Courses)- Amaravathi Road Campus</option>
                                                    <option value="3">Hindu College of Engineering & Technology</option>
                                                    <option value="4">Hindu College -MCA</option>
                                                    <option value="5">Hindu College of Management</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="username" id="username" placeholder="User Name" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="password" id="password" placeholder="Password" required>
                                            </div>
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <input type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit">
                                                </div>
                                                
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        else
        {
                echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/homes/auth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <a>Please use Google Chrome / Microsoft Edge Browser for Best user Experience.</a>
                                                </div> 
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        echo '</body>';
        echo static::script();
    }
    public static function accountsauth()
    {
        if($_POST['username'] != '' && $_POST['password'] != '')
        {
            $_SESSION['org_id'] = $_POST['orgname'];
            $qurey = "SELECT * FROM `user_master` WHERE (`no` = '$_POST[username]' OR `mobile` = '$_POST[username]' OR `email` = '$_POST[username]') AND `password`='$_POST[password]' AND status='1'";
            $data = Homem::getdata($qurey);
            if(sizeof($data) == 1)
            {
                $_SESSION['user_id'] = $data[0]['id'];
                $_SESSION['user_no'] = $data[0]['no'];
                $_SESSION['name'] = $data[0]['name'];
                $_SESSION['org_id'] = $data[0]['org_id'];
                $_SESSION['mobile'] = $data[0]['mobile'];
                $_SESSION['email'] = $data[0]['email'];
                $_SESSION['user_role'] = $data[0]['user_role'];
                if($data[0]['user_role'] == 1)
                {
                    $_SESSION['menu'] = static::usermenu();
                }
                if($data[0]['user_role'] == 2)
                {
                    $_SESSION['menu'] = static::facultymenu();
                }
                if($data[0]['user_role'] == 3)
                {
                    $_SESSION['menu'] = static::studentmenu();
                }
                if($data[0]['user_role'] == 4)
                {
                    $_SESSION['menu'] = static::accountsmainmenu();
                }
                if($data[0]['user_role'] == 5)
                {
                    $_SESSION['menu'] = static::collectionmainmenu();
                }
                if($data[0]['user_role'] == 6)
                {
                    $_SESSION['menu'] = static::adminmainmenu();
                }
                if($data[0]['user_role'] == 7)
                {
                    $_SESSION['menu'] = static::headofthedeptmenu();
                }
                if($data[0]['user_role'] == 8)
                {
                    $_SESSION['menu'] = static::academiccoordinatormenu();
                }
                if($data[0]['user_role'] == 9)
                {
                    $_SESSION['menu'] = static::usermenu();
                }
                echo '<script>window.location="/homes/home";</script>';
            }
            else
            {
                echo '<script>window.location="/homes/index";</script>';
            }
        }
        else
        {
            echo '<script>window.location="/homes/index?status=0";</script>';
        }
            
    }
    public static function testing()
    {
        echo Homem::test();
    }
    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;
        }
    }
    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>
            <link rel="icon" href = "/hindu/assets/img/logo.png" type = "image/x-icon"> 
            <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="/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="/hindu/assets/css/style.css">
            <link rel="stylesheet" href="/hindu/assets/sweetalert2/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="/hindu/assets/word/jquery.min.js" ></script>
                <script src="/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="/hindu/assets/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;
    }
    private static function usermenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home" >Home</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" >
                        Masters
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/bloodgroup" >Blood Group</a>
                        <a class="dropdown-item" href="/Homes/courses">Courses</a>
                        <a class="dropdown-item" href="/Homes/departments">Departments</a>
                        <a class="dropdown-item" href="/Homes/category">Category</a>
                        </div>
                    </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" >
                        Students
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/supload" >Upload Student Details</a>
                        <a class="dropdown-item" href="/Homes/slist" >View List of Students</a>
                        <a class="dropdown-item" href="/Homes/addstudent">Individual Student Entry</a>
                        <a class="dropdown-item" href="/Homes/ssearch" >Search a Student</a>
                        <a class="dropdown-item" href="/Homes/upstdntphotos">Upload Students Photos</a>
                        <a class="dropdown-item" href="/Homes/stdntadditional">Student Additional Details</a>
                        </div>
                    </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" >
                        User
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/ulist">View List of Users</a>
                        <a class="dropdown-item" href="/Homes/adduser">Individual User Entry</a>
                        </div>
                    </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" >
                        Subject
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/searchsub">Search Subjects Available</a>
                        <a class="dropdown-item" href="/Homes/indsubject">Individual Subject Entry</a>
                        <a class="dropdown-item" href="/Homes/bulksubject">Bulk Subject Uploading</a>
                        </div>
                    </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" >
                        Marks Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/uploadmarks" >B.Tech Marks Entry</a>
                        <a class="dropdown-item" href="/Homes/mdipinformat">Diploma Marks (College Format)</a>
                        <a class="dropdown-item" href="/Homes/mindividual" >Individual Marks Entry</a>
                        <a class="dropdown-item" href="/Homes/editindstdmarks"  >Edit Individual Student Marks</a>
                        </div>
                    </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" >
                        Reports 
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/studentresult" >Student Result</a>
                        <!--<a class="dropdown-item" href="/Homes/sattempts" >Student Attempts</a>-->
                        <a class="dropdown-item" href="/Homes/semwiseconmarks" >Sem wise Consolidated Marks Report</a>
                        <a class="dropdown-item" href="/Homes/sbacklogs" >Sem Wise Student Backlogs</a>
                        <a class="dropdown-item" href="/Homes/subwisefailistinsem" >Subject wise Baclogs in Sem</a>
                        <a class="dropdown-item" href="/Homes/subwiseresults" >Subject Wise Results</a>
                        <a class="dropdown-item" href="/Homes/deptwiseresult" >Semester Wise Result Analysis</a>
                        </div>
                    </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" >
                        Fee 
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/allotstdfee" >Allot Fee for Students</a>
                        <a class="dropdown-item" href="/Homes/normalfeecolect" >Normal Fee Collection</a>
                        <a class="dropdown-item" href="/Homes/examfeecollect" >Exam Fee Collection</a>
                        <a class="dropdown-item" href="/Homes/stdntindfee" >Check Student Fees</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/profile" >Profile</a>
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function accountsmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home" >Home</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" >
                        Fee Setting Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/allotstdfee" >Bulk Uploading of Student Fee</a>
                        <a class="dropdown-item" href="/Accounts/allotindstdfee" >Individual Fee Upload</a>
                        <a class="dropdown-item" href="/Accounts/normalfeeconcession" >Concession Fee Details</a>
                        <a class="dropdown-item" href="/Accounts/deptwisefeesettingreport" >Department wise Fee List</a>
                        </div>
                    </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" >
                        Fee Collection Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/normalfeecolect" >Normal Fee Collection</a>
                        <a class="dropdown-item" href="/Accounts/examfeecollect" >Exam Fee Collection</a>
                        <a class="dropdown-item" href="/Accounts/nfeecollectbulk" >Normal Fee Collection (Bulk Upload)</a>
                        </div>
                    </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" >
                        Fee Collection Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/hnowiseconsreport" >Individual Student Fee Report</a>
                        <a class="dropdown-item" href="/Accounts/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Accounts/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Accounts/datewisecon" >Date wise fee collection report</a>
                        <a class="dropdown-item" href="/Accounts/reportbwndates" >Fee Collection betwen two dates</a>
                        </div>
                    </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" >
                        MIS Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/admcmpforfuryer" >Admission Comparison for Four Years</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractbyayyear" >Overall Abstract for Academic Year</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractforallcurses" >Overall Abstract for All Courses</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractdueinacy" >Overall Abstract for Dues in Academic year</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractdueinacylinks" >Detailed Overall Abstract for Dues in Academic year</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function collectionmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home" >Home</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/normalfeecolect" >Normal Fee Collection</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/examfeecollect" >Exam Fee Collection</a>
                    </li>
                    <li class="nav-item active">
                    <a class="nav-link" href="/Accounts/hnowiseconsreport" >Individual Student Fee Report</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" >
                        Fee Collection Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/slist" >List of Students</a>
                        <a class="dropdown-item" href="/Accounts/deptwisefeesettingreport" >Department wise Fee List</a>
                        <a class="dropdown-item" href="/Accounts/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Accounts/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Accounts/datewisecon" >Date wise fee collection report</a>
                        <a class="dropdown-item" href="/Accounts/reportbwndates" >Fee Collection betwen two dates</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function adminmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home" >Home</a>
                        </li>
                        <!--
                        <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/hnowiseconsreport" >Individual Student Fee Report</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" >
                        Academics
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/subjectsyllabus" >Add Syllabus to subjects</a>
                        </div>
                    </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" >
                        Quiz Questions Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/addmcqquestions" >Add MCQ Questions</a>
                        <a class="dropdown-item" href="/Exams/addmcqquestionsupload" >Add MCQ Questions (Images)</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanks" >Add Fill in Blanks</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanksupload" >Add Fill in Blanks (Images)</a>
                        <a class="dropdown-item" href="/Exams/addinterquestions" >Intermediate Answer Questions</a>
                        <a class="dropdown-item" href="/Exams/addinterquestionsupload" >Intermediate Answer Questions(Images)</a>
                        <a class="dropdown-item" href="/Exams/approvalquestions" >Approve Questions</a>
                        <a class="dropdown-item" href="/Exams/questionscount" >Available Questions</a>
                        <a class="dropdown-item" href="/Exams/viewquestions" >View Approved Questions</a>
                        </div>
                    </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" >
                        Quiz Exam
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/singletopicexam" >Single Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/singlechaptexam" >Single Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/multipletopicexam" >Multiple Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/multiplechaptexam" >Multiple Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/examreports" >Completed Exam Reports</a>
                        <a class="dropdown-item" href="/Exams/totalexamreports" >All Exam Details</a>
                        </div>
                    </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" >
                        Accounts Section
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Accounts/allotstdfee" >Bulk Uploading of Student Fee</a>
                        <a class="dropdown-item" href="/Accounts/allotindstdfee" >Individual Fee Upload</a>
                        <a class="dropdown-item" href="/Accounts/normalfeeconcession" >Concession Fee Details</a>
                        <a class="dropdown-item" href="/Accounts/deptwisefeesettingreport" >Department wise Fee List</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Accounts/normalfeecolect" >Normal Fee Collection</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Accounts/hnowiseconsreport" >Individual Student Fee Report</a>
                        <a class="dropdown-item" href="/Accounts/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Accounts/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Accounts/dailyreport" >Operator Entry Report Date Wise</a>
                        <a class="dropdown-item" href="/Accounts/datewisecon" >Date wise Fee Collection</a>
                        <a class="dropdown-item" href="/Accounts/reportbwndates" >Fee Collection Between Two Dates</a>
                        <a class="dropdown-item" href="/Accounts/reportbybook" >Book Wise Fee Reciept Details</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Accounts/admcmpforfuryer" >Admission Comparison for Four Years (MIS)</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractbyayyear" >Overall Abstract for Academic Year (MIS)</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractforallcurses" >Overall Abstract for All Courses (MIS)</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractdueinacy" >Overall Abstract for Dues in Academic year (MIS)</a>
                        <a class="dropdown-item" href="/Accounts/ovabstractdueinacylinks" >Detailed Overall Abstract for Dues in Academic year (MIS)</a>
                        </div>
                    </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" >
                        Extra
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/stdntdetails" >Student Details</a>
                        <a class="dropdown-item" href="/Exams/userdetails" >User Details</a>
                        <a class="dropdown-item" href="/Exams/zeroexam" >Zero Exam Subjects</a>
                        <a class="dropdown-item" href="/Exams/zeroquestion" >Zero Question Subjects</a>
                        <a class="dropdown-item" href="/Exams/texamreports" >Detailed Exam Reports</a>
                        <a class="dropdown-item" href="/Main/uploadstdmarksbulk">Upload Studnet Marks Bulk</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function studentmenu()
    {
        // bg-light
        $menu = '
                <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home">Home <span class="sr-only">(current)</span></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" >
                        Quiz Exam
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/scheduledexams" >Scheduled Exams</a>
                        <a class="dropdown-item" href="/Exams/studentexamreports" >Completed Exams</a>
                        </div>
                    </li>
                    <!--
                    <li class="nav-item">
                        <a class="nav-link" href="/Exams/scheduledexams">Scheduled Exams</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>
                    -->
                    <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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function academiccoordinatormenu()
    {
        // bg-light
        $menu = '
                <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home">Home <span class="sr-only">(current)</span></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" >
                        Subjects Master
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/indsubject" >Add Subject</a>
                        <a class="dropdown-item" href="/Exams/searchsub" >Viw Subjects</a>
                        <a class="dropdown-item" href="/Exams/bulksubject">Bulk Subject Uploading</a>
                        </div>
                    </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" >
                        Faculty
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                    -->
                        <!--
                        <a class="dropdown-item" href="/Exams/indfaculty" >Add Faculty</a>
                        -->
                    <!--
                        <a class="dropdown-item" href="/Exams/viewfaculty" >View Faculty</a>
                        <a class="dropdown-item" href="/Exams/addsubfaculty" >Assign Subject to Faculty</a>
                        </div>
                    </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" >
                        Time Table Master
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/workingdays" >Working Days</a>
                        <a class="dropdown-item" href="/Exams/createshift" >Create Shift</a>
                        <a class="dropdown-item" href="/Exams/createtimetable" >Create Time Table</a>
                        <a class="dropdown-item" href="/Exams/requestanhour" >Ask for Adjustment</a>
                        <a class="dropdown-item" href="/Exams/approveadjustments" >Approve Adjstments</a>
                        </div>
                    </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" >
                        Academics
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/subjectsyllabus" >Add Syllabus to subjects</a>
                        <!--
                        <a class="dropdown-item" href="/Exams/viewfaculty" >View Faculty</a>
                        <a class="dropdown-item" href="/Exams/addsubfaculty" >Assign Subject to Faculty</a>
                        -->
                        </div>
                    </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" >
                        Quiz Questions
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/addmcqquestions" >Add MCQ Questions</a>
                        <a class="dropdown-item" href="/Exams/addmcqquestionsupload" >Add MCQ Questions (Images)</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanks" >Add Fill in Blanks</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanksupload" >Add Fill in Blanks (Images)</a>
                        <a class="dropdown-item" href="/Exams/addinterquestions" >Intermediate Answer Questions</a>
                        <a class="dropdown-item" href="/Exams/addinterquestionsupload" >Intermediate Answer Questions(Images)</a>
                        <a class="dropdown-item" href="/Exams/approvalquestions" >Approve Questions</a>
                        <a class="dropdown-item" href="/Exams/questionscount" >Available Questions</a>
                        <a class="dropdown-item" href="/Exams/viewquestions" >View Approved Questions</a>
                        </div>
                    </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" >
                        Quiz Exam
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/singletopicexam" >Single Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/singlechaptexam" >Single Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/multipletopicexam" >Multiple Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/multiplechaptexam" >Multiple Chapter Exam</a>
                        
                        <a class="dropdown-item" href="/Exams/examreports" >Completed Exam Reports</a>
                        </div>
                    </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" >
                        Extra
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/stdntdetails" >Student Details</a>
                        <a class="dropdown-item" href="/Exams/userdetails" >User Details</a>
                        <a class="dropdown-item" href="/Exams/zeroexam" >Zero Exam Subjects</a>
                        <a class="dropdown-item" href="/Exams/zeroquestion" >Zero Question Subjects</a>
                        <a class="dropdown-item" href="/Exams/totalquestionscount" >Total Question Entered</a>
                        <a class="dropdown-item" href="/Exams/texamreports" >Detailed Exam Reports</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/profile" >Profile</a>
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function facultymenu()
    {
        // bg-light
        $menu = '
                <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">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/home">Home <span class="sr-only">(current)</span></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" >
                        Academics
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/subjectsyllabus" >Add Syllabus to subjects</a>
                        <a class="dropdown-item" href="/Exams/mergesubjectdata" >Merge Similar Subjects Data</a>
                        </div>
                    </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" >
                        Quiz Questions Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/addmcqquestions" >Add MCQ Questions</a>
                        <a class="dropdown-item" href="/Exams/addmcqquestionsupload" >Add MCQ Questions (Images)</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanks" >Add Fill in Blanks</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanksupload" >Add Fill in Blanks (Images)</a>
                        <a class="dropdown-item" href="/Exams/addinterquestions" >Intermediate Answer Questions</a>
                        <a class="dropdown-item" href="/Exams/addinterquestionsupload" >Intermediate Answer Questions(Images)</a>
                        <a class="dropdown-item" href="/Exams/approvalquestions" >Approve Questions</a>
                        <a class="dropdown-item" href="/Exams/questionscount" >Available Questions</a>
                        <a class="dropdown-item" href="/Exams/viewquestions" >View Approved Questions</a>
                        </div>
                    </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" >
                        Quiz Exam
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/singletopicexam" >Single Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/singlechaptexam" >Single Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/multipletopicexam" >Multiple Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/multiplechaptexam" >Multiple Chapter Exam</a>
                        
                        <a class="dropdown-item" href="/Exams/examreports" >Completed Exam Reports</a>
                        </div>
                    </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" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Homes/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    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($id == 3)
                {
                    return 'B.A.';
                }
                if($id == 4)
                {
                    return 'Inter';
                }
                if($id == 5)
                {
                    return 'M.Sc.';
                }
            }
            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($id == 2)
                {
                    return 'M.Com';
                }
            }
            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($id == 6)
                {
                    return 'MPC';
                }
                if($id == 7)
                {
                    return 'BZC';
                }
                if($id == 8)
                {
                    return 'GPC';
                }
                if($id == 9)
                {
                    return 'MiBC';
                }
                if($id == 10)
                {
                    return 'BiMC';
                }
                if($id == 11)
                {
                    return 'HS';
                }
                if($id == 12)
                {
                    return 'BS';
                }
                if($id == 13)
                {
                    return 'HEP';
                }
                if($id == 14)
                {
                    return 'EHP';
                }
                if($id == 15)
                {
                    return 'MES';
                }
                if($id == 16)
                {
                    return 'EPC';
                }
                if($id == 17)
                {
                    return 'MPC';
                }
                if($id == 18)
                {
                    return 'BiPC';
                }
                if($id == 19)
                {
                    return 'MEC';
                }
                if($id == 20)
                {
                    return 'CEC';
                }
                if($id == 21)
                {
                    return 'ABC';
                }
                if($id == 22)
                {
                    return 'HBZ';
                }
                if($id == 23)
                {
                    return 'FTM';
                }
                if($id == 24)
                {
                    return 'PHYSICS';
                }if($id == 25)
                {
                    return 'CHEMISTRY';
                }
                if($id == 26)
                {
                    return 'BOTANY';
                }
                if($id == 27)
                {
                    return 'FOOD PROCESSING';
                }
                if($id == 28)
                {
                    return 'HORTICULTURAL LANDSCAPING';
                }
                if($id == 29)
                {
                    return 'General (Un-aided)';
                }
            }
            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 if($id == 6)
                {
                    return 'Wed Design';
                }
                else
                {
                    return '';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'Computers';
                }
                if($id == 2)
                {
                    return 'Commerce';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    public static function index()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        if(static::checkbrower() == 1)
        {
            echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/homes/auth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Login Here</div>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="username" id="username" placeholder="User Name" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="password" id="password" placeholder="Password" required>
                                            </div>
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <input type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit">
                                                </div>
                                                
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        else
        {
                echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/homes/auth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <a>Please use Google Chrome / Microsoft Edge Browser for Best user Experience.</a>
                                                </div> 
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        echo '</body>';
        echo static::script();
    }
    public static function latest()
    {
        $data = Homem::getdata("SELECT * FROM `latest_news` WHERE `status`='1' ORDER BY id asc");
        $tdata = '';
        if(sizeof($data) > 0)
        {
            for($i=0; $i < sizeof($data); $i++)
            {
                $j=$i+1;
                $tdata .= '<tr><td>'.$j.'</td><td>'.$data[$i]['description'].'</td><td>'.$data[$i]['edate'].'</td></tr>';
            }
        }
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
		<form action="Search.php" method="POST">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-8">                                       
                        <div class="row">
                            <div class="col-md-12">
                                <section class="box" style="margin-top: 30px;">
                                    <header class="panel_header">
                                        <h2 class="title pull-left">LATEST NEWS / INFORMATION</h2>
                                        <div class="actions panel_actions pull-right">
                                            <a class="box_toggle fa fa-chevron-down"></a>
                                        </div>
                                    </header>
                                    <div class="content-body"> 						
                                            <div class="row">
                                                <div class="col-md-12">
                                                <div class="table-responsive">													
                                                    <table class="table table-bordered">
                                                        <thead>
                                                        <tr>
                                                            <th>S. No.</th>
                                                            <th>Description</th>
                                                            <th>Date</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>';
                                                        echo $tdata;
                                                        
                                                echo '</tbody>
                                                    </table>
                                                </div>
                                                </div>
                                            </div>
                                            
                                    </div>  
                                </section>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-2"></div>
                </div>
            </div>
        </form>
        ';
        echo '</body>';
        echo static::script();
    }
    public static function suggestions()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-1"></div>
                <div class="col-lg-10">                                       
                    <div class="row">
                        <div class="col-md-12">
                            <section class="box" style="margin-top: 30px;">
                                <header class="panel_header">
                                    <h2 class="title pull-left">Suggest Us Here</h2>
                                    <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">
									<form action="savesuggestions" method="POST">	
											<div class="row">
												<div class="col-md-12">  
													<div class="form-group">
														Your Suggestions are most valuble in improving our services.
													</div>
												</div>
											</div>
											<div class="row">
												<div class="col-md-12">
													<div class="row">
														<div class="col-md-6">
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="name" class="form-control" placeholder="Name" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="email" class="form-control" placeholder="Email" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="mobile" class="form-control" placeholder="Mobile" required />
																	</div>
																</div>  
															</div>													
														</div>
														<div class="col-md-6">
															<div class="form-group">							
																<textarea name="Suggestions" id="Suggestions" type="text" class="form-control" placeholder="Enter your Suggestions here..." style="height:138px;resize:none;" required /></textarea>
															</div>
														</div>  
													</div>											
												</div>
											</div>										
											<div class="row">
												<div class="col-md-12">  
													<div class="form-group">
														<label id="lbl_msg" class="label label-primary pull-left"></label>
														<button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
														<div id="spinner1" class="pull-right circle-loader ">
															<div class="checkmark draw"></div>
														</div>
													</div>
												</div>
											</div>										

									</form>
                                </div>                        
                            </section>
                        </div>
                    </div>
                </div>
                <div class="col-lg-1"></div>
            </div>
        </div>
        ';
        echo '</body>';
        echo static::script();
        if(isset($_GET['status']))
        {
            if($_GET['status'] == 1)
            {
                echo '<script>swal("Submitted Successfully", "We will contact you regarding your query..", "success");</script>';
            }
            else
            {
                echo '<script>swal("Something Went Wrong..", "Please Tryagain Later", "error");</script>';
            }
        }
    }
    public static function savesuggestions()
    {
        if($_POST['name'] != '' && $_POST['email'] != '' && $_POST['mobile'] != '')
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $today_time =  date('d-m-Y h:i:s A');
            $status = Homem::insert("INSERT INTO `suggestions` (`id`, `name`, `email`, `mobile`, `suggestions`, `endate`, `status`) VALUES ('', '$_POST[name]', '$_POST[email]', '$_POST[mobile]', '$_POST[Suggestions]', '$today_time', '1')");
            echo '<script>window.location="/Homes/suggestions?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Homes/suggestions?status=0";</script>';
        }
    }
    public static function contactus()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">                                       
                    <div class="row">
                        <div class="col-lg-1"> </div>  
                        <div class="col-md-10">
                            <section class="box" style="margin-top: 30px;">
                                <header class="panel_header">
                                    <h2 class="title pull-left">Contact Us</h2>
                                    <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">
									<form action="/Homes/savecontactus" method="POST">	
											<div class="row">
                                                
												<div class="col-md-12">
													<div class="row">
														<div class="col-md-3">
														</div>
														<div class="col-md-6">
															<div class="row">
																<div class="col-md-12">  
																	<div class="form-group">
																		For Any Other Queries:
																	</div>
																</div>
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="name" class="form-control" placeholder="Name" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="email" class="form-control" placeholder="Email" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="mobile" class="form-control" placeholder="Mobile" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="subject" class="form-control" placeholder="Subject" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group">							
																		<textarea name="message" id="Suggestions" type="text" class="form-control" placeholder="Message" style="height:138px;resize:none;" required /></textarea>
																	</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>  
                                                        <div class="col-md-3">
														</div>
													</div>											
												</div>
                                               
											</div>										
									</form>
                                </div>                        
                            </section>
                        </div>
                        <div class="col-lg-1"> </div>  
                    </div>
                </div>
            </div>
        </div>
        ';
        echo '</body>';
        echo static::script();
        if(isset($_GET['status']))
        {
            if($_GET['status'] == 1)
            {
                echo '<script>swal("Submitted Successfully", "We will contact you regarding your query..", "success");</script>';
            }
            else
            {
                echo '<script>swal("Something Went Wrong..", "Please Tryagain Later", "error");</script>';
            }
        }
    }
    public static function savecontactus()
    {
        if($_POST['name'] != '' && $_POST['email'] != '' && $_POST['mobile'] != '')
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $today_time =  date('d-m-Y h:i:s A');
            $status = Homem::insert("INSERT INTO `contactus`(`name`, `email`, `mobile`, `subject`, `message`, `edate`, `status`)  VALUES ('$_POST[name]', '$_POST[email]', '$_POST[mobile]', '$_POST[subject]','$_POST[message]', '$today_time', '1')");
            echo '<script>window.location="/Homes/contactus?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Homes/contactus?status=0";</script>';
        }
    }
    public static function logout()
    {
        $_SESSION['user_role'] = '';
        unset($_SESSION['user_id']);
        unset($_SESSION['user_no']);
        unset($_SESSION['name']);
        unset($_SESSION['org_id']);
        unset($_SESSION['mobile']);
        unset($_SESSION['email']);
        unset($_SESSION['user_role']);
        session_unset();
        session_destroy();
        echo '<script>window.location="/homes/index";</script>';
    }
    public static function auth()
    {
        if($_POST['username'] != '' && $_POST['password'] != '')
        {
            $qurey = "SELECT * FROM `user_master` WHERE (`no` = '$_POST[username]' OR `mobile` = '$_POST[username]' OR `email` = '$_POST[username]') AND `password`='$_POST[password]' AND status='1'";
            $data = Homem::getdata($qurey);
            if(sizeof($data) == 1)
            {
                $_SESSION['user_id'] = $data[0]['id'];
                $_SESSION['user_no'] = $data[0]['no'];
                $_SESSION['name'] = $data[0]['name'];
                $_SESSION['org_id'] = $data[0]['org_id'];
                $_SESSION['mobile'] = $data[0]['mobile'];
                $_SESSION['email'] = $data[0]['email'];
                $_SESSION['user_role'] = $data[0]['user_role'];
                if($data[0]['user_role'] == 1)
                {
                    $_SESSION['menu'] = static::usermenu();
                }
                if($data[0]['user_role'] == 2)
                {
                    $_SESSION['menu'] = static::facultymenu();
                }
                if($data[0]['user_role'] == 3)
                {
                    $_SESSION['menu'] = static::studentmenu();
                }
                if($data[0]['user_role'] == 4)
                {
                    $_SESSION['menu'] = static::accountsmainmenu();
                }
                if($data[0]['user_role'] == 5)
                {
                    $_SESSION['menu'] = static::collectionmainmenu();
                }
                if($data[0]['user_role'] == 6)
                {
                    $_SESSION['menu'] = static::adminmainmenu();
                }
                if($data[0]['user_role'] == 7)
                {
                    $_SESSION['menu'] = static::headofthedeptmenu();
                }
                if($data[0]['user_role'] == 8)
                {
                    $_SESSION['menu'] = static::academiccoordinatormenu();
                }
                if($data[0]['user_role'] == 9)
                {
                    $_SESSION['menu'] = static::usermenu();
                }
                echo '<script>window.location="/homes/home";</script>';
            }
            else
            {
                echo '<script>window.location="/homes/index";</script>';
            }
        }
        else
        {
            echo '<script>window.location="/homes/index";</script>';
        }
    }
    public static function testb()
    {
        // $string = substr(str_shuffle('qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM'), 0, 25);
        // echo Emails::newuseremailverf("name", "email", "avhvjvvgjjg");
        // echo Emails::emailverificationapi('Krishnarjuna New', 's.krishnarjuna@gmail.com', 'token');
    }
    public static function home()
    {
        if($_SESSION['user_role'] != '')
        {
            $a = '';
            $pdata = Homem::getdata("SELECT * FROM user_master um JOIN email_token et ON um.id=et.fk_user_id WHERE um.email!='' AND et.status='1' AND (um.v_email='' OR um.v_email='0') AND um.id='$_SESSION[user_id]' ORDER BY et.e_time DESC");
            if(sizeof($pdata) > 0)
            {
                date_default_timezone_set('Asia/Kolkata'); 
                $today_time =  date('Y-m-d H:i:s');
                $date1 = strtotime($pdata[0]["e_time"]); 
                $date2 = strtotime($today_time); 
                $diff = abs($date2 - $date1); 
                $minutes = $diff/(60);
                if($minutes <= 45)
                {
                    $a = '
                    <div class="card">
                            <div class="card-body">
                                <form action="" method="POST" enctype="multipart/form-data">
                                    <div class="form-group">
                                        <div class="float-right">
                                        An email verification link has been sent to your registered email check INBOX/SPAM. Please click on the link to verify you email. The verification link is active for 45 min.
                                        </div> 
                                    </div>
                                </form>
                            </div>
                        </div>';
                }
            }
            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-4"></div>
                        <div class="col-xl-4">
                        '.$a.'
                        </div>
                        <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
            if($_SESSION['user_role'] != "")
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE ((`no`=`password`) OR (`mobile`=`password`) OR (`email`=`password`)) AND `id`='$_SESSION[user_id]'");
                if(sizeof($data) != 0)
                {
                    echo '<script>window.location="/Homes/changepassword";</script>';
                }
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='' AND `id`='$_SESSION[user_id]'");
                if(sizeof($data) != 0)
                {
                    echo '<script>window.location="/Homes/changemobile";</script>';
                }
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `email`='' AND `id`='$_SESSION[user_id]'");
                if(sizeof($data) != 0)
                {
                    echo '<script>window.location="/Homes/changeemail";</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 changeemail()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangeemail" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Email Here</h4>
                                        <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="email" name="email" id="email" class="form-control" placeholder="Email" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:block;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function userchangeemail()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangeemail" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Email Here</h4>
                                        <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="email" name="email" id="email" class="form-control" placeholder="Email" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:block;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function savechangeemail()
    {
        if($_SESSION['user_role'] != '')
        {
            if(isset($_POST['email']))
            {
                Homem::insert("UPDATE `user_master` SET `email`='', `v_email`='' WHERE `id`='$_SESSION[user_id]'");
                if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `email`=''")) == 1)
                {
                    if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]'")) == 0)
                    {
                        date_default_timezone_set('Asia/Kolkata'); 
                        $today_time =  date('Y-m-d H:i:s');
                        Homem::insert("UPDATE `user_master` SET `email`='$_POST[email]' WHERE `id`='$_SESSION[user_id]'");
                        $token = substr(str_shuffle('qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM'), 0, 25);
                        Homem::insert("INSERT INTO `email_token`(`fk_user_id`, `token`, `email_type`, `e_time`, `status`) VALUES ('$_SESSION[user_id]','$token','1','$today_time','1')");
                        $url= $_SERVER['HTTP_HOST'];
                        $tokenurl = 'http://'.$url.'/Homes/emailverification?token='.$token;
                        if($url != 'localhost' && $url != '192.168.1.193')
                        {
                            $estatus = Emails::newuseremailverf($_SESSION['name'], $_POST['email'], $tokenurl);
                        }
                        else
                        {
                            $estatus = Emails::emailverificationapi($_SESSION['name'], $_POST['email'], $tokenurl);
                        }
                        if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `email`='$_POST[email]'")) == 1)
                        {
                            echo '<script>window.location="/Homes/home?status=1";</script>';
                        }
                        else
                        {
                            echo '<script>window.location="/Homes/home?status=0";</script>';
                        }
                    }
                    else
                    {
                        echo '<script>window.location="/Homes/home?status=0";</script>';
                    }
                }
                else
                {
                    echo '<script>window.location="/Homes/home?status=0";</script>';
                }
            }
        }
    }
    public static function emailverification()
    {
        if(isset($_GET['token']))
        {
            if(strlen($_GET['token']) == 25)
            {
                $t_data = Homem::getdata("SELECT * FROM `email_token` WHERE `token`='$_GET[token]' AND `status`='1'");
                if(sizeof($t_data) == 1)
                { 
                    date_default_timezone_set('Asia/Kolkata'); 
                    $today_time =  date('Y-m-d H:i:s');
                    $date1 = strtotime($t_data[0]["e_time"]); 
                    $date2 = strtotime($today_time); 
                    $diff = abs($date2 - $date1); 
                    $minutes = $diff/(60);
                        if($minutes <= 45)
                        {
                            if($t_data[0]["email_type"] == 1)
                            {
                                echo $minutes;
                                $fk_user_id = $t_data[0]["fk_user_id"];
                                Homem::insert("UPDATE `user_master` SET `v_email`='1' WHERE `id`='$fk_user_id'");
                                Homem::insert("UPDATE `email_token` SET `status`='0' WHERE `token`='$_GET[token]'");
                                $status = "<script>swal('Verification Success', 'Please Login to Continue..', 'success');</script>";
                                echo '<script>window.location="/Homes/index?status=1";</script>';  
                            }
                        }
                        else
                        {
                            $status = "<script>swal('Verification Failed..', 'The link expaired due to time.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                            echo '<script>window.location="/Homes/index?status=0";</script>';
                        }
                }
                else
                {
                    $status = "<script>swal('Verification Failed..', 'Details not found or Expired Details.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                    echo '<script>window.location="/Homes/index?status=0";</script>';
                }
            }
            else
            {
                $status = "<script>swal('Verification Failed..', 'Invalid Detils for verification.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                echo '<script>window.location="/Homes/index?status=0";</script>'; 
            }
        }
        else
        {
            $status = "<script>swal('Verification Failed..', 'Something wrong.. Please try again.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
            echo '<script>window.location="/Homes/index?status=0";</script>';
        }
    }
    public static function userchangemobile()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangemobile" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Mobile Number Here</h4>
                                        <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="number" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:block;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function changemobile()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangemobile" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Mobile Number Here</h4>
                                        <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="number" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:block;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function savechangemobile()
    {
        if($_SESSION['user_role'] != '')
        {
            if(isset($_POST['mobile']))
            {
                Homem::insert("UPDATE `user_master` SET `mobile`='', `v_mobile`='' WHERE `id`='$_SESSION[user_id]'");
                if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `mobile`=''")) == 1)
                {
                    if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]'")) == 0)
                    {
                        Homem::insert("UPDATE `user_master` SET `mobile`='$_POST[mobile]' WHERE `id`='$_SESSION[user_id]'");
                        if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `mobile`='$_POST[mobile]'")) == 1)
                        {
                            echo '<script>window.location="/Homes/home?status=1";</script>';
                        }
                        else
                        {
                            echo '<script>window.location="/Homes/home?status=0";</script>';
                        }
                    }
                    else
                    {
                        echo '<script>window.location="/Homes/home?status=0";</script>';
                    }
                }
                else
                {
                    echo '<script>window.location="/Homes/home?status=0";</script>';
                }
            }
        }
    }
    public static function changepassword()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangepassword" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Password Here</h4>
                                        <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="text" name="oldpassword" id="oldpassword" class="form-control" placeholder="Old Password" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="form-group">                                            
                                                    <input type="text" name="newpassword" id="newpassword" class="form-control" placeholder="New Password" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="form-group">                                            
                                                    <input type="text" name="cnfpassword" id="cnfpassword" class="form-control" placeholder="Confirm New Password" onchange="comaprepass()" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:none;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function comaprepass()
            {
                var pass1 = $("#newpassword").val();
                var pass2 = $("#cnfpassword").val();
                if(pass1 == pass2)
                {
                    $("#btn_reg").show();
                }
                else
                {
                    $("#btn_reg").hide();
                    swal("Password Mismatch", "Please enter same password in the new and confirm password.", "error");
                    setInterval(function () {
                        location.reload();
                    }, 1000);
                }
            }
            </script>';
        }
    }
    public static function userchangepassword()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form id="frm_exam" action="/Homes/savechangepassword" method="POST">                
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <section class="box" style="margin-top: 10px;">
                                    <header class="panel_header">
                                        <h4 class="title pull-left">Change Your Password Here</h4>
                                        <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="text" name="oldpassword" id="oldpassword" class="form-control" placeholder="Old Password" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="form-group">                                            
                                                    <input type="text" name="newpassword" id="newpassword" class="form-control" placeholder="New Password" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="form-group">                                            
                                                    <input type="text" name="cnfpassword" id="cnfpassword" class="form-control" placeholder="Confirm New Password" onchange="comaprepass()" required>
                                                </div>
                                            </div>                              
                                        </div>
                                        <div class="row submitbutton" >
                                            <div class="col-md-12">  
                                                <div class="form-group">
                                                    <button id="btn_reg" style="display:none;" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                        
                                </section>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function comaprepass()
            {
                var pass1 = $("#newpassword").val();
                var pass2 = $("#cnfpassword").val();
                if(pass1 == pass2)
                {
                    $("#btn_reg").show();
                }
                else
                {
                    $("#btn_reg").hide();
                    swal("Password Mismatch", "Please enter same password in the new and confirm password.", "error");
                    setInterval(function () {
                        location.reload();
                    }, 1000);
                }
            }
            </script>';
        }
    }
    public static function savechangepassword()
    {
        if($_SESSION['user_role'] != '')
        {
            if(isset($_POST['oldpassword']))
            {
                if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `password`='$_POST[oldpassword]'")) == 1)
                {
                    Homem::insert("UPDATE `user_master` SET `password`='$_POST[newpassword]' WHERE `id`='$_SESSION[user_id]'");
                    if(sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `password`='$_POST[newpassword]'")) == 1)
                    {
                        echo '<script>window.location="/Homes/home?status=1";</script>';
                    }
                }
                else
                {
                    echo '<script>window.location="/Homes/home?status=0";</script>';
                }
            }
        }
    }
    public static function profile()
    {
        if($_SESSION['user_role'] == 1)
        {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/saveprofile" 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">
                                                <h4 class="title pull-left">Update User Profile</h4>
                                                <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="text" name="hallticket" id="hallticket" class="form-control" placeholder="Reg. Number" readonly>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" class="form-control" placeholder="Student Name">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  
                                                            <input type="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth" required="">                                          
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="gender" id="gender" class="form-control">
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                            <option value="">Select Blood Group</option>
                                                            '; 
                                                            echo $blood;
                                                            echo '</select>
                                                        </div>
                                                    </div> 										
                                                </div>  
                                                <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-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                        </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>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(!isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]' AND `org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#hallticket").val("'.$data[0]['no'].'");
                            $("#name").val("'.$data[0]['name'].'");
                            $("#dob").val("'.$data[0]['dob'].'");
                            $("#gender").val("'.$data[0]['gender'].'");
                            $("#bloodgroup").val("'.$data[0]['blood_group'].'");
                            $("#course").val("'.$data[0]['fk_course_id'].'");
                            $("#department").val("'.$data[0]['fk_dept_id'].'");
                            $("#fromyear").val("'.$data[0]['fromyear'].'");
                            $("#toyear").val("'.$data[0]['toyear'].'");
                            $("#regulation").val("'.$data[0]['regulation'].'");
                            $("#mobile").val("'.$data[0]['mobile'].'");
                            $("#email").val("'.$data[0]['email'].'");
                            $("#edit_id").val("'.$data[0]['id'].'");
                        </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 saveprofile()
    {
        if($_SESSION['user_role'] != '')
        {
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' OR `id`='$_POST[edit_id]'"));
                    if($mdata1 == 1)
                    {
                        $mdata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' AND `id`='$_POST[edit_id]'"));
                        if(($mdata2 == 0) || ($mdata2 == 1))
                        {
                            $mdata = 0;
                        }
                        else
                        {
                            $mdata = 1;
                        }
                    }
                    else
                    {
                        $mdata = 1;
                    }
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `id`='$_POST[edit_id]'"));
                    if($edata1 == 1)
                    {
                        $edata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' AND `id`='$_POST[edit_id]'"));
                        if(($edata2 == 0) || ($edata2 == 1))
                        {
                            $edata = 0;
                        }
                        else
                        {
                            $edata = 1;
                        }
                    }
                    else
                    {
                        $edata = 1;
                    }
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[edit_id]' AND `org_id`='$_SESSION[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 1)
                {
                    $query = "UPDATE `user_master` SET `name`='$_POST[name]', `dob`='$_POST[dob]', `gender`='$_POST[gender]', `blood_group`='$_POST[bloodgroup]', `mobile`='$_POST[mobile]', `email`='$_POST[email]' WHERE `id`='$_POST[edit_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/homes/profile?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/profile?status=0";</script>';
                }
            }
        }
    }
    /**Start of Report master */
    public static function studentresult()
    {
        $a = '';
        if($_SESSION['user_role'] != '')
        {
            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($_SESSION['user_role'] == 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($_SESSION['user_role'] == 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($_SESSION['user_role'] == 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));
                        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>';
                    }     
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/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>
                                                <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($_SESSION['user_role'] == 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="/homes/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($_SESSION['user_role'] == 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="/homes/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: "/homes/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($_SESSION['user_role'] == 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';
                                            }
                                            $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)
                                {
                                    $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>';
                            }
                        }
                        $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($_SESSION['user_role'] == 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');
        }
    }
    /**End of Report master */
    /* Start 0f student master*/
    public static function supload()
    {
        if($_SESSION['user_role'] == 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 Student Details 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="/homes/savesupload" method="POST" enctype="multipart/form-data">							
                                                <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 Student Details 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">
                                                        <a href="/hindu/formats/Stdnt_details_upload.csv" >Download CSV Uploading Format Here.. do not delete header in CSV file.</a>
                                                    </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 savesupload()
    {
        if($_SESSION['user_role'] == 1)
        {
            $filename=$_FILES['file']['name'];
            $exts[0]='csv';
            if($_FILES['file']['name']!=null)
            {
                $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)
                {
                    $admissionno = trim($data[8]);
                    $quota = trim($data[9]);
                    $noyears = trim($data[10]);
                    $hallticket = trim($data[0]);
                    $name = trim($data[1]);
                    $gender = trim($data[2]);
                    $course = trim($data[3]);
                    $dept = trim($data[4]);
                    $startyear = trim($data[5]);
                    $endyear = trim($data[6]);
                    $regulation = trim($data[7]);
                    $test1 = 0;
                    $test2 = 0;
                    if($admissionno != '' && $admissionno != 0)
                    {
                        $udata1 = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$admissionno'");
                        $test1 = sizeof($udata1);
                    }
                    if($hallticket != '' && $hallticket != 0)
                    {
                        $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$hallticket'");
                        $test2 = sizeof($udata);
                    }
                    if($test1 == 0 && $test2 == 0 && (($admissionno != '' && $admissionno != 0) || ($hallticket != '' && $hallticket != 0)))
                    {
                        Homem::insert("INSERT INTO `user_master` (`ano`, `squota`, `noofyears`, `no`, `name`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`) VALUES 
                        ('$admissionno', '$quota', '$noyears', '$hallticket', '$name', '', '$gender', '', '$course', '$dept', '$_SESSION[org_id]', '$startyear', '$endyear', '$regulation', '', '', '$hallticket', '3', '1')");
                        $i++;
                    }
                    // if(sizeof($udata) == 1)
                    // {
                    //     $query = "UPDATE `user_master` SET `no`='$hallticket', `name`='$name', 
                    //     `gender`='$gender', `fk_course_id`='$course', `fk_dept_id`='$dept', `org_id`='$_SESSION[org_id]', `fromyear`='$startyear', 
                    //     `toyear`='$endyear', `regulation`='$regulation', `user_role`='3', `status`='1' WHERE `no`='$hallticket'";
                    //     Homem::insert($query);
                    //     $i++;
                    // }
                }
                echo '<script>window.location = "/homes/supload?status=1&count='.$i.'";</script>';
            }
        }
    }
    public static function slist()
    {
        if($_SESSION['user_role'] == 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']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[department]' AND `org_id`='$_SESSION[org_id]' AND `fromyear`='$_POST[fromyear]' AND `toyear`='$_POST[toyear]' AND `user_role`='3'");
                if(sizeof($data) > 0)
                {
                    $table = Form::dbtableed($data, ['Hall Ticket Number', 'Name', 'Gender'], ['no', 'name', 'gender'], '/homes/addstudent', 'id', '');
                    $a = '
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                '.$table.'
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        ';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/slist" 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">List by Department</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-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 addstudent()
    {
        if($_SESSION['user_role'] == 1)
        {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/saveaddstudent" 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">
                                                <h4 class="title pull-left">ADD NEW STUDENT</h4>
                                                <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="text" name="hallticket" id="hallticket" class="form-control" placeholder="Hall Ticket Number">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" class="form-control" placeholder="Student Name">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  
                                                            <input type="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth" required="">                                          
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="gender" id="gender" class="form-control">
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                            <option value="">Select Blood Group</option>
                                                            '; 
                                                            echo $blood;
                                                            echo '</select>
                                                        </div>
                                                    </div> 										
                                                </div>  
                                                <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-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">
                                                        </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>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_GET[editid]' AND `org_id`='$_SESSION[org_id]' AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#hallticket").val("'.$data[0]['no'].'");
                            $("#name").val("'.$data[0]['name'].'");
                            $("#dob").val("'.$data[0]['dob'].'");
                            $("#gender").val("'.$data[0]['gender'].'");
                            $("#bloodgroup").val("'.$data[0]['blood_group'].'");
                            $("#course").val("'.$data[0]['fk_course_id'].'");
                            $("#department").val("'.$data[0]['fk_dept_id'].'");
                            $("#fromyear").val("'.$data[0]['fromyear'].'");
                            $("#toyear").val("'.$data[0]['toyear'].'");
                            $("#regulation").val("'.$data[0]['regulation'].'");
                            $("#mobile").val("'.$data[0]['mobile'].'");
                            $("#email").val("'.$data[0]['email'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                        </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 saveaddstudent()
    {
        if($_SESSION['user_role'] != '')
        {
            if($_POST['edit_id'] == '')
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]'"));
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]'"));
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[hallticket]' AND `org_id`='$_POST[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 0)
                {
                    $query = "INSERT INTO `user_master`(`no`, `name`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`) VALUES ('$_POST[hallticket]', '$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[bloodgroup]', '$_POST[course]', '$_POST[department]', '$_SESSION[org_id]', '$_POST[fromyear]', '$_POST[toyear]', '$_POST[regulation]', '$_POST[mobile]', '$_POST[email]', '$_POST[hallticket]', '3', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/homes/addstudent?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/addstudent?status=0";</script>';
                }
            }
            else
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' OR `id`='$_POST[edit_id]'"));
                    if($mdata1 == 1)
                    {
                        $mdata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' AND `id`='$_POST[edit_id]'"));
                        if(($mdata2 == 0) || ($mdata2 == 1))
                        {
                            $mdata = 0;
                        }
                        else
                        {
                            $mdata = 1;
                        }
                    }
                    else
                    {
                        $mdata = 1;
                    }
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `id`='$_POST[edit_id]'"));
                    if($edata1 == 1)
                    {
                        $edata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' AND `id`='$_POST[edit_id]'"));
                        if(($edata2 == 0) || ($edata2 == 1))
                        {
                            $edata = 0;
                        }
                        else
                        {
                            $edata = 1;
                        }
                    }
                    else
                    {
                        $edata = 1;
                    }
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[edit_id]' AND `org_id`='$_SESSION[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 1)
                {
                    $query = "UPDATE `user_master` SET `no`='$_POST[hallticket]', `name`='$_POST[name]', `dob`='$_POST[dob]', 
                    `gender`='$_POST[gender]', `blood_group`='$_POST[bloodgroup]', `fk_course_id`='$_POST[course]', 
                    `fk_dept_id`='$_POST[department]', `org_id`='$_SESSION[org_id]', `fromyear`='$_POST[fromyear]', 
                    `toyear`='$_POST[toyear]', `regulation`='$_POST[regulation]', `mobile`='$_POST[mobile]', `email`='$_POST[email]', `password`='$_POST[hallticket]', 
                    `user_role`='3', `status`='1' WHERE `id`='$_POST[edit_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/homes/addstudent?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/addstudent?status=0";</script>';
                }
            }
        }
    }
    public static function ssearch()
    {
        if($_SESSION['user_role'] == 1)
        {
            $a = '';
            if(isset($_POST['htno']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[htno]' AND `org_id`='$_SESSION[org_id]' AND `user_role`='3'");
                if(sizeof($data) > 0)
                {
                    $a = '
                            <div class="row">
                                <div class="col-lg-2"></div>
                                <div class="col-lg-8">
                                    <div class="table-responsive">
                                        <table class="table table-responsive-sm">
                                            <tbody>
                                                <tbody>
                                                    <tr>
                                                        <td>Hallticket Number</td>
                                                        <td>'.$data[0]['no'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Name</td>
                                                        <td>'.$data[0]['name'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Gender</td>
                                                        <td>'.$data[0]['gender'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>DoB</td>
                                                        <td>'.$data[0]['dob'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Email</td>
                                                        <td>'.$data[0]['email'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Mobile</td>
                                                        <td>'.$data[0]['mobile'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Starting Year</td>
                                                        <td>'.$data[0]['fromyear'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Ending Year</td>
                                                        <td>'.$data[0]['toyear'].'</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Password</td>
                                                        <td>'.$data[0]['password'].'</td>
                                                    </tr>
                                                </tbody>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="col-lg-2"></div>
                            </div>
                        ';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/ssearch" 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">Search Student by Hallticket Number</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="text" name="htno" id="ht_no" placeholder="Hallticket Number" 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 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="/homes/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="/homes/upstdntphotos?status=1&count='.$i.'";</script>';
    }
    public static function stdntadditional()
    {
        if($_SESSION['user_role'] == 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']))
            {
                $data = Homem::getdata("SELECT * FROM (SELECT * FROM `user_master` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[department]' AND `org_id`='$_SESSION[org_id]' AND `fromyear`='$_POST[fromyear]' AND `toyear`='$_POST[toyear]' AND `user_role`='3') a JOIN user_addinfo ua ON a.no=ua.no");
                if(sizeof($data) > 0)
                {
                    $table = Form::dbtableed($data, ['Hall Ticket Number', 'Name', 'Mobile', 'Father Name', 'Father Mobile'], ['no', 'name', 'mobile', 'f_name', 'f_mobile'], '/homes/stdntadditional', 'no', '');
                    $a = '
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                '.$table.'
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        ';
                }
            }
            $state = Inputs::select('state', Inputs::optionsdb(Homem::getdata("SELECT * FROM `add_state` WHERE `fk_country_id`='78'"), 'state_id', 'state_name'), Inputs::options([''], ['Select State']), 'onchange="get_addcity(this)"', 'required');
            $city = Homem::getdata("SELECT * FROM `add_city`");
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-4"> 
                                <form action="/homes/savestdntadditional" method="POST">                                      
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Student Additional Details</h4>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                      
                                                            <input type="text" name="hallticket" id="hallticket" class="form-control" placeholder="Hall Ticket Number">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="add_no" id="add_no" class="form-control" placeholder="Admission Number">
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="doj" id="doj" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Joining">                                          
                                                        </div>
                                                    </div>                              
                                                </div> 
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="m_name" id="m_name" class="form-control" placeholder="Mother Name">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="m_mobile" id="m_mobile" class="form-control" placeholder="Mother Mobile Number">
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="f_name" id="f_name" class="form-control" placeholder="Father Name">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="f_mobile" id="f_mobile" class="form-control" placeholder="Father Mobile Number">
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="address" id="address" class="form-control" placeholder="Address" cols=""></textarea>
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            '.$state.'
                                                        </div>
                                                    </div>  	
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="city" name="city" class="form-control">
                                                                <option value="">Select City</option>
                                                            </select>
                                                        </div>
                                                    </div>								
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="pincode" id="pincde" class="form-control" placeholder="Pin Code">
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="alt_mobile" id="alt_mobile" class="form-control" placeholder="Alternate Mobile">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">
                                                        </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-2"></div>
                            <div class="col-lg-4">  
                                <form action="/homes/stdntadditional" method="POST">                                     
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">List by Department</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-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-1"></div>
                        </div>
                        '.$a.'
                    </div>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
                function get_addcity(state)
                {
                    var city = '.json_encode($city).';
                    select = document.getElementById("city");
                    for(i=0; i<city.length; i++)
                    {
                        if(city[i]["fk_state_id"] == state.value)
                        {
                            var opt = document.createElement("option");
                            opt.value = city[i]["city_id"];
                            opt.innerHTML = city[i]["city_name"];
                            select.appendChild(opt);
                        }
                        else
                        {
                            for(j=0; j<select.length; j++)
                            {
                                if (select.options[j].value == city[i]["city_id"])
                                {
                                    select.remove(j);
                                }
                            }
                        }
                    }
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `user_addinfo` WHERE `no`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#hallticket").val("'.$data[0]['no'].'");
                            $("#add_no").val("'.$data[0]['add_no'].'");
                            $("#doj").val("'.$data[0]['doj'].'");
                            $("#alt_mobile").val("'.$data[0]['alt_mobile'].'");
                            $("#m_name").val("'.$data[0]['m_name'].'");
                            $("#m_mobile").val("'.$data[0]['m_mobile'].'");
                            $("#f_name").val("'.$data[0]['f_name'].'");
                            $("#f_mobile").val("'.$data[0]['f_mobile'].'");
                            $("#address").val("'.$data[0]['address'].'");
                            $("#state").val("'.$data[0]['fk_state_id'].'");
                            $("#city").val("'.$data[0]['fk_city_id'].'");
                            $("#pincode").val("'.$data[0]['pincode'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                        </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 savestdntadditional()
    {
        if($_SESSION['user_role'] == 1)
        {
            if(sizeof(Homem::getdata("SELECT * FROM `user_addinfo` WHERE `no`='$_POST[hallticket]' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
            {
                Homem::insert("UPDATE `user_addinfo` SET `no`='$_POST[hallticket]', `add_no`='$_POST[add_no]', `doj`='$_POST[doj]', `alt_mobile`='$_POST[alt_mobile]', `m_name`='$_POST[m_name]', `m_mobile`='$_POST[m_mobile]', `f_name`='$_POST[f_name]', `f_mobile`='$_POST[f_mobile]', `address`='$_POST[address]', `fk_state_id`='$_POST[state]', `fk_city_id`='$_POST[city]', `pincode`='$_POST[pincode]' WHERE `no`='$_POST[hallticket]' AND `fk_org_id`='$_SESSION[org_id]'");
                echo '<script>window.location = "/homes/stdntadditional?status=2";</script>';
            }
            else
            {
                Homem::insert("INSERT INTO `user_addinfo` (`no`, `add_no`, `doj`, `alt_mobile`, `m_name`, `m_mobile`, `f_name`, `f_mobile`, `address`, `fk_state_id`, `fk_city_id`, `pincode`, `fk_org_id`) VALUES ('$_POST[hallticket]', '$_POST[add_no]', '$_POST[doj]', '$_POST[alt_mobile]', '$_POST[m_name]', '$_POST[m_mobile]', '$_POST[f_name]', '$_POST[f_mobile]', '$_POST[address]', '$_POST[state]', '$_POST[city]', '$_POST[pincode]', '$_SESSION[org_id]')");
                echo '<script>window.location = "/homes/stdntadditional?status=1";</script>';
            }
        }
    }
    /* End 0f student master*/
    /* Start 0f user master*/
    public static function ulist()
    {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`!='3' AND `org_id`='$_SESSION[org_id]'");
        $table = Form::dbtableed($data, ['Name', 'Email', 'Mobile'], ['name', 'email', 'mobile'], '/homes/adduser', 'id', '');
        echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/homes/saveadduser" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-8">
                        <h5 style="margin-top: 20px;">Existing User Details</h5>
                        '.$table.'
                        </div>
                        <div class="col-lg-2"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
    }
    public static function adduser()
    {
        if($_SESSION['user_role'] == 1)
        {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $role = Inputs::optionsdb(Homem::getdata("SELECT * FROM `user_roles`"), 'id', 'name');
            // $org = Inputs::optionsdb(Homem::getdata("SELECT * FROM `org_details` WHERE `country`='78' AND `state`='2'"), 'id', 'org_name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/homes/saveadduser" 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: 30px;">
                                        <header class="panel_header">
                                            <h4 class="title pull-left">ADD NEW USER</h4>
                                            <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="text" name="hallticket" id="hallticket" class="form-control" placeholder="Employee ID">
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Employee Name">
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="date" name="dob" id="dob" class="form-control datepicker" data-format="yyyy-mm-dd" data-start-date="-50y" data-end-date="+0w" placeholder="  DoB in YYYY-MM-DD">
                                                    </div>
                                                </div>                 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="userrole" id="userrole" class="form-control">
                                                        <option value="">User Role</option>
                                                        ';
                                                        echo $role;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div>              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="gender" id="gender" class="form-control">
                                                        <option value="">Select Gender</option>
                                                        <option value="M">Male</option>
                                                        <option value="F">Female</option>
                                                        </select>
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                        <option value="">Slect Blood Group</option>
                                                        ';
                                                        echo $blood;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div> 										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <select name="department" id="department" class="form-control">
                                                        <option value="">Slect Department</option>
                                                        ';
                                                        echo $dept;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="joingyear" id="joingyear" class="form-control" placeholder="Joining Year">
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="qualification" id="qualification" class="form-control">
                                                            <option value="">Select Qualification</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                        </select>
                                                    </div>
                                                </div> 										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                    </div>
                                                </div>  									
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="password" id="password" class="form-control" placeholder="Password">
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                    </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>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`!='3' AND `org_id`='$_SESSION[org_id]' AND `id`='$_GET[editid]'");
                if(sizeof($udata) == 1)
                {
                    echo '
                        <script>
                            $("#hallticket").val("'.$udata[0]['no'].'");
                            $("#name").val("'.$udata[0]['name'].'");
                            $("#dob").val("'.$udata[0]['dob'].'");
                            $("#userrole").val("'.$udata[0]['user_role'].'");
                            $("#gender").val("'.$udata[0]['gender'].'");
                            $("#bloodgroup").val("'.$udata[0]['blood_group'].'");
                            $("#department").val("'.$udata[0]['fk_dept_id'].'");
                            $("#joingyear").val("'.$udata[0]['fromyear'].'");
                            $("#qualification").val("'.$udata[0]['fk_course_id'].'");
                            $("#email").val("'.$udata[0]['email'].'");
                            $("#mobile").val("'.$udata[0]['mobile'].'");
                            $("#password").val("'.$udata[0]['password'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                        </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 saveadduser()
    {
        if($_SESSION['user_role'] != '')
        {
            if($_POST['edit_id'] == '')
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `mobile`='$_POST[mobile]'");
                if($data == 0)
                {
                    $query = "INSERT INTO `user_master`(`no`, `name`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`) VALUES 
                    ('$_POST[hallticket]', '$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[bloodgroup]', '$_POST[qualification]', '$_POST[department]', '$_SESSION[org_id]', '$_POST[joingyear]', '', '', '$_POST[mobile]', '$_POST[email]', '$_POST[password]', '$_POST[userrole]', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/homes/adduser?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/adduser?status=0";</script>';
                }
            }
            else
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' OR `id`='$_POST[edit_id]'"));
                    if($mdata1 == 1)
                    {
                        $mdata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' AND `id`='$_POST[edit_id]'"));
                        if(($mdata2 == 0) || ($mdata2 == 1))
                        {
                            $mdata = 0;
                        }
                        else
                        {
                            $mdata = 1;
                        }
                    }
                    else
                    {
                        $mdata = 1;
                    }
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `id`='$_POST[edit_id]'"));
                    if($edata1 == 1)
                    {
                        $edata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' AND `id`='$_POST[edit_id]'"));
                        if(($edata2 == 0) || ($edata2 == 1))
                        {
                            $edata = 0;
                        }
                        else
                        {
                            $edata = 1;
                        }
                    }
                    else
                    {
                        $edata = 1;
                    }
                }
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[edit_id]' AND `org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1 && $edata == 0 && $mdata == 0)
                {
                    $query = "UPDATE `user_master` SET `no`='$_POST[hallticket]', `name`='$_POST[name]', `dob`='$_POST[dob]', 
                    `gender`='$_POST[gender]', `blood_group`='$_POST[bloodgroup]', `fk_course_id`='$_POST[qualification]', 
                    `fk_dept_id`='$_POST[department]', `org_id`='$_SESSION[org_id]', `fromyear`='$_POST[joingyear]', 
                    `user_role`='$_POST[userrole]', `mobile`='$_POST[mobile]', `email`='$_POST[email]', `password`='$_POST[password]', 
                    `status`='1' WHERE `id`='$_POST[edit_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/homes/adduser?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/adduser?status=0";</script>';
                }
            }
        }
    }
    /* End 0f user master*/
    /* Starting Subject Master  */
    public static function bulksubject()
    {
        if($_SESSION['user_role'] == 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 Subject Details Here: (in given format only)</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="/homes/savebulksubject" method="POST" enctype="multipart/form-data">							
                                                <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 Subject Details 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">
                                                        <a href="/hindu/formats/Syllabus_upload_format.csv" >Download CSV Uploading Format Here.. do not delete header in CSV file.</a>
                                                    </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 savebulksubject()
    {
        if($_SESSION['user_role'] == 1)
        {
            $filename=$_FILES['file']['name'];
            $exts[0]='csv';
            if($_FILES['file']['name']!=null)
            {
                $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)
                {
                    $date = date('Y-m-d');
                    $course = trim($data[1]);
                    $dept = trim($data[2]);
                    $regulation = trim($data[3]);
                    $year = trim($data[4]);
                    $type = trim($data[5]);
                    $sem = trim($data[6]);
                    $subcode = trim($data[7]);
                    $subname = trim($data[8]);
                    $int_max = trim($data[9]);
                    $int_pass = trim($data[10]);
                    $int_mand = trim($data[11]);
                    $ext_max = trim($data[12]);
                    $ext_pass = trim($data[13]);
                    $ext_mand = trim($data[14]);
                    $total_max = trim($data[15]);
                    $total_pass = trim($data[16]);
                    $total_mand = trim($data[17]);
                    $resulttype = trim($data[18]);
                    $failgrade = trim($data[19]);
                    $credit = trim($data[20]);
                    $provider = trim($data[21]);
                    if(sizeof(Homem::getdata("SELECT * FROM `subject_data` WHERE `course`='$course' AND `dept`='$dept' AND `regulation`='$regulation' AND `year`='$year' AND `sem`='$sem' AND `subcode`='$subcode' AND `fk_org_id`='$_SESSION[org_id]'")) == 0)
                    {
                        Homem::insert("INSERT INTO `subject_data` (`course`, `dept`, `regulation`, `year`, `type`, `sem`, `subcode`, `subname`, `int_max`, `int_pass`, `int_mand`, `ext_max`, `ext_pass`, `ext_mand`, `total_max`, `total_pass`, `total_mand`, `resulttype`, `failgrade`, `credit`, `provider`, `fk_org_id`, `fk_user_id`, `status`, `regdate`) VALUES ('$course', '$dept', '$regulation', '$year', '$type', '$sem', '$subcode', '$subname', '$int_max', '$int_pass', '$int_mand', '$ext_max', '$ext_pass', '$ext_mand', '$total_max', '$total_pass', '$total_mand', '$resulttype', '$failgrade', '$credit', '$provider', '$_SESSION[org_id]', '$_SESSION[user_id]', '1', '$date')");
                        $i++;
                    }
                    
                }
                echo '<script>window.location = "/homes/bulksubject?status=1&count='.$i.'";</script>';
            }
        }
    }
    public static function indsubject()
    {
        if($_SESSION['user_role'] == 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');
            $provider = Inputs::optionsdb(Homem::getdata("SELECT * FROM `org_affliation` WHERE `fk_org_id`='$_SESSION[org_id]'"), 'provider_code', 'provider_code');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/saveindsubject" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">ADD NEW SUBJECT</h4>
                                            </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="dept" id="dept" 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="year" id="year" class="form-control">
                                                            <option value="">Select Year</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-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="sem" id="sem" class="form-control">
                                                                <option value="">Select Semester</option>
                                                                <option value="1">First Sem</option>
                                                                <option value="2">Second Sem</option>
                                                            </select>
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="type" id="type" class="form-control">
                                                                <option value="">Select Type</option>
                                                                <option value="SUBJECT">SUBJECT</option>
                                                                <option value="LAB">LAB</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subcode" id="subcode" class="form-control" placeholder="Subject Code">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subname" id="subname" class="form-control" placeholder="Subject Name">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="int_max" id="int_max" class="form-control" placeholder="Max Internal MArks">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="int_pass" id="int_pass" class="form-control" placeholder="Internal Pass Marks">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="int_mand" id="int_mand" class="form-control">
                                                                <option value="">Internal Mandatory</option>
                                                                <option value="1">YES</option>
                                                                <option value="0">NO</option>
                                                            </select>
                                                        </div>
                                                    </div> 									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="ext_max" id="ext_max" class="form-control" placeholder="Max External MArks">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="ext_pass" id="ext_pass" class="form-control" placeholder="External Pass Marks">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="ext_mand" id="ext_mand" class="form-control">
                                                                <option value="">External Mandatory</option>
                                                                <option value="1">YES</option>
                                                                <option value="0">NO</option>
                                                            </select>
                                                        </div>
                                                    </div> 									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="total_max" id="total_max" class="form-control" placeholder="Max Total MArks">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="total_pass" id="total_pass" class="form-control" placeholder="Total Pass Marks">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="total_mand" id="total_mand" class="form-control">
                                                                <option value="">Total Marks Mandatory</option>
                                                                <option value="1">YES</option>
                                                                <option value="0">NO</option>
                                                            </select>
                                                        </div>
                                                    </div> 									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-3">
                                                        <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 class="col-lg-3">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="failgrade" id="failgrade" class="form-control" placeholder="Failure Grade">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-3">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="credit" id="credit" class="form-control" placeholder="Credits">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-3">
                                                        <div class="form-group">                                            
                                                            <select name="provider" id="provider" class="form-control">
                                                                <option value="">Syllabus Given by</option>
                                                                '.$provider.'
                                                            </select>
                                                        </div>
                                                    </div> 									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <input id="edit_id" name="edit_id" class="form-control" type="hidden">
                                                        </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-2"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `subject_data` WHERE `sub_id`='$_GET[editid]'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#course").val("'.$data[0]['course'].'");
                            $("#dept").val("'.$data[0]['dept'].'");
                            $("#year").val("'.$data[0]['year'].'");
                            $("#sem").val("'.$data[0]['sem'].'");
                            $("#type").val("'.$data[0]['type'].'");
                            $("#regulation").val("'.$data[0]['regulation'].'");
                            $("#subcode").val("'.$data[0]['subcode'].'");
                            $("#subname").val("'.$data[0]['subname'].'");
                            $("#int_max").val("'.$data[0]['int_max'].'");
                            $("#int_pass").val("'.$data[0]['int_pass'].'");
                            $("#int_mand").val("'.$data[0]['int_mand'].'");
                            $("#ext_max").val("'.$data[0]['ext_max'].'");
                            $("#ext_pass").val("'.$data[0]['ext_pass'].'");
                            $("#ext_mand").val("'.$data[0]['ext_mand'].'");
                            $("#total_max").val("'.$data[0]['total_max'].'");
                            $("#total_pass").val("'.$data[0]['total_pass'].'");
                            $("#total_mand").val("'.$data[0]['total_mand'].'");
                            $("#resulttype").val("'.$data[0]['resulttype'].'");
                            $("#failgrade").val("'.$data[0]['failgrade'].'");
                            $("#credit").val("'.$data[0]['credit'].'");
                            $("#provider").val("'.$data[0]['provider'].'");
                            $("#edit_id").val("'.$data[0]['sub_id'].'");
                        </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 saveindsubject()
    {
        if($_SESSION['user_role'] == 1)
        {
            if($_POST['edit_id'] == '')
            {
                $date = date('Y-m-d');
                Homem::insert("INSERT INTO `subject_data` (`course`, `dept`, `regulation`, `year`, `type`, `sem`, `subcode`, `subname`, `int_max`, `int_pass`, `int_mand`, `ext_max`, `ext_pass`, `ext_mand`, `total_max`, `total_pass`, `total_mand`, `resulttype`, `failgrade`, `credit`, `provider`, `fk_org_id`, `fk_user_id`, `status`, `regdate`) VALUES ('$_POST[course]', '$_POST[dept]', '$_POST[regulation]', '$_POST[year]', '$_POST[type]', '$_POST[sem]', '$_POST[subcode]', '$_POST[subname]', '$_POST[int_max]', '$_POST[int_pass]', '$_POST[int_mand]', '$_POST[ext_max]', '$_POST[ext_pass]', '$_POST[ext_mand]', '$_POST[total_max]', '$_POST[total_pass]', '$_POST[total_mand]', '$_POST[resulttype]', '$_POST[failgrade]', '$_POST[credit]', '$_POST[provider]', '$_SESSION[org_id]', '$_SESSION[user_id]', '1', '$date')");
                echo '<script>window.location = "/homes/indsubject?status=1";</script>';
            }
            else
            {
                if($_POST['provider'] != '')
                {
                    $date = date('Y-m-d');
                    Homem::insert("UPDATE `subject_data` SET `course`='$_POST[course]', `dept`='$_POST[dept]', `regulation`='$_POST[regulation]', `year`='$_POST[year]', `type`='$_POST[type]', `sem`='$_POST[sem]', `subcode`='$_POST[subcode]', `subname`='$_POST[subname]', `int_max`='$_POST[int_max]', `int_pass`='$_POST[int_pass]', `int_mand`='$_POST[int_mand]', `ext_max`='$_POST[ext_max]', `ext_pass`='$_POST[ext_pass]', `ext_mand`='$_POST[ext_mand]', `total_max`='$_POST[total_max]', `total_pass`='$_POST[total_pass]', `total_mand`='$_POST[total_mand]', `resulttype`='$_POST[resulttype]', `failgrade`='$_POST[failgrade]', `credit`='$_POST[credit]', `provider`='$_POST[provider]', `fk_org_id`='$_SESSION[org_id]', `fk_user_id`='$_SESSION[user_id]', `status`='1', `regdate`='$date' WHERE `sub_id`='$_POST[edit_id]'");
                    echo '<script>window.location = "/homes/indsubject?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/indsubject?status=0";</script>';
                }
            }
        }   
    }
    public static function searchsub()
    {
        if($_SESSION['user_role'] == 1)
        {
            $table = '';
            if(isset($_POST['course']))
            {
                $data = Homem::getdata("SELECT * FROM `subject_data` WHERE `course`='$_POST[course]' AND `dept`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `year`='$_POST[year]' AND `sem`='$_POST[sem]' AND `provider`='$_POST[provider]'");
                if($data > 0)
                {
                    $table = Form::dbtableed($data, ['Regulation', 'Subject Code', 'Subject Name', 'Type'], ['regulation', 'subcode', 'subname', 'type'], '/homes/indsubject', 'sub_id', '');
                }
            }
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $provider = Inputs::optionsdb(Homem::getdata("SELECT * FROM `org_affliation` WHERE `fk_org_id`='$_SESSION[org_id]'"), 'provider_code', 'provider_code');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/homes/searchsub" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">SEARCH SUBJECTS</h4>
                                            </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="dept" id="dept" 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="year" id="year" class="form-control">
                                                            <option value="">Select Year</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-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="sem" id="sem" class="form-control">
                                                                <option value="">Select Semester</option>
                                                                <option value="1">First Sem</option>
                                                                <option value="2">Second Sem</option>
                                                            </select>
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="provider" id="provider" class="form-control">
                                                                <option value="">Syllabus Given by</option>
                                                                '.$provider.'
                                                            </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-2"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$table.'
                            </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>';
                }
            }
        }
    }
    /* Ending Subject Master  */
    /* Start of Marks Entry Master */
    public static function uploadmarks()
    {
        if($_SESSION['user_role'] == 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="/homes/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-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-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-6">  
                                                        <div class="form-group">
                                                            <input type="radio" value="G" name="result_type" id="result_type_g" required> <a href="/hindu/formats/Results_Grade_Format.csv" >Grade System</a>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <input type="radio" value="M" name="result_type" id="result_type_m"> <a href="/hindu/formats/Results_marks_format.csv" >Marks System</a>
                                                        </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($_SESSION['user_role'] == 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'] == 'G')
                    {
                        $internal = '';
                        $external = '';
                        $result_type = '0';
                        $grade = trim($data[3]);
                        $credit = trim($data[4]);
                    }
                    if($_POST['result_type'] == 'M')
                    {
                        $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 = "/homes/uploadmarks?status=1&count='.$i.'";</script>';
            }
        }
    }
    public static function mdipinformat()
    {
        if($_SESSION['user_role'] == 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="/homes/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($_SESSION['user_role'] == 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 = "/homes/mdipinformat?status=1&count='.$count.'";</script>';
        }
    }
    public static function mindividual()
    {
        if($_SESSION['user_role'] == 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="/homes/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($_SESSION['user_role'] == 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 = "/homes/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 = "/homes/mindividual?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/homes/mindividual?status=0";</script>';
                }
            }
        }
    }
    public static function editindstdmarks()
    {
        $a = '';
        if($_SESSION['user_role'] != '')
        {
            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="/homes/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 fee section */
    public static function allotstdfee()
    {
        if($_SESSION['user_role'] == 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');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $table = '';
            if(isset($_POST['course']))
            {
                $blood = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.no=sf.no  JOIN fee_types ft ON sf.fk_feetype_id=ft.f_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 um.org_id='$_SESSION[org_id]' AND sf.year='$_POST[years]' AND sf.fk_feetype_id='$_POST[feetypes]'");
                $table = Form::dbtableed($blood, ['Year', 'Fee Type', 'Hallticket Number', 'Name', 'Amount'], ['year', 'f_name', 'no', 'name', 'feeamount'], '/homes/allotstdfee', 'fid', '');
            }
            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"> 
                                <form action="/homes/saveallotstdfee" 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 Fee Setting Entry</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_fee_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">
                                <form action="/homes/saveallotstdfee" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Setting Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Name of the Student" readonly>                                         
                                                    </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 to which fee applicable</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="feetype" id="feetype" class="form-control" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="amount" id="amount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="terms" id="terms" class="form-control" placeholder="No of Terms of Payment">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="type" id="type" class="form-control" value="single" placeholder="type">                                         
                                                    </div>
                                                </div>    
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                                <form action="#" method="POST">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">List by Department</h5>
                                        </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="years" id="years" class="form-control">
                                                            <option value="">Select Year to which fee applicable</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="feetypes" id="feetypes" class="form-control">
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </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>
                                </form>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/homes/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                    </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 saveallotstdfee()
    {
        if($_SESSION['user_role'] == 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)
                    {
                        $no = trim($data[0]);
                        $year = trim($data[1]);
                        $feetype = trim($data[2]);
                        $amount = trim($data[3]);
                        $terms = trim($data[4]);
                        if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$no' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                        {
                            Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$no' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                            $i++;
                        }
                        else
                        {
                            Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$no', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                            $i++;
                        }
                    }
                    echo '<script>window.location = "/homes/allotstdfee?status=1&count='.$i.'";</script>';
                }
            }
            if($_POST['type'] == 'single')
            {
                $no = $_POST['no'];
                $year = $_POST['year'];
                $feetype = $_POST['feetype'];
                $amount = $_POST['amount'];
                $terms = $_POST['terms'];
                if($_POST['edit_id'] == '')
                {   
                    if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$no' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                    {
                        Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$no' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                        echo '<script>window.location = "/homes/allotstdfee?status=2";</script>';
                    }
                    else
                    {
                        Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$no', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                        echo '<script>window.location = "/homes/allotstdfee?status=1";</script>';
                    }
                }
                else
                {
                    if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'")) == 1)
                    {
                        Homem::insert("UPDATE `stdnt_feemaster` SET `no`='$no', `year`='$year', `fk_feetype_id`='$feetype', `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'");
                        echo '<script>window.location = "/homes/allotstdfee?status=2";</script>';
                    }
                }
            }
        }
    }
    public static function normalfeecolect()
    {
        if($_SESSION['user_role'] == 1)
        {
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            {
                $date = date('Y-m-d');
                $blood = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `fk_org_id`='$_SESSION[org_id]'");
                $table = Form::dbtableed($blood, ['Hallticket Number', 'Paid Amount'], ['no', 'amount'], '/homes/normalfeecolect', 'nid', '');
            }
            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="/homes/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </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 to which fee applicable</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="feetype" id="feetype" class="form-control" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date" required="">
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/homes/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </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 savenormalfeecolect()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 1)
        {
            if($_POST['edit_id'] == '')
            {
                Homem::insert("INSERT INTO `stdnt_normalfee` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES 
                ('$_POST[no]', '$_POST[year]', '$_POST[feetype]', '$_POST[paidamount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                echo '<script>window.location = "/homes/normalfeecolect?status=1";</script>';
            }
            else
            {
                Homem::insert("UPDATE `stdnt_normalfee` SET `no`='$_POST[no]', `year`='$_POST[year]', `fk_feetype_id`='$_POST[feetype]', `amount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paid_date`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `nid`='$_POST[edit_id]'");
                echo '<script>window.location = "/homes/normalfeecolect?status=2";</script>';
            }
        }
    }
    public static function examfeecollect()
    {
        if($_SESSION['user_role'] == 1 || $_SESSION['user_role'] == 5)
        {
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $examtype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `examtype`"), 'id', 'name');
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $table = '';
            {
                $date = date('Y-m-d');
                $blood = Homem::getdata("SELECT * FROM `stdnt_examfee` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `status`='1' AND `fk_org_id`='$_SESSION[org_id]'");
                $table = Form::dbtableed($blood, ['Hallticket Number', 'Paid Amount'], ['no', 'paidamount'], '/homes/examfeecollect', 'eid', '');
            }
            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="/homes/saveexamfeecollect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Exam Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </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 to which fee applicable</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" required>
                                                            <option value="">Select Sem</option>
                                                            <option value="1">First Sem</option>
                                                            <option value="2">Second Sem</option>
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="exammonth" id="exammonth" class="form-control">
                                                            <option value="">Select Month of Exam</option>
                                                            '.$month.'
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="examyear" id="examyear" class="form-control" required>
                                                            <option value="">Select Year of Exam</option>
                                                            '.static::year().'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">                            
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date" required="">
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/homes/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_examfee` WHERE `eid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#sem").val("'.$data[0]['sem'].'");
                        $("#exammonth").val("'.$data[0]['exammonth'].'");
                        $("#examyear").val("'.$data[0]['examyear'].'");
                        $("#paidamount").val("'.$data[0]['paidamount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paydate'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </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 saveexamfeecollect()
    {
        if($_SESSION['user_role'] == 1)
        {
            $date = date('Y-m-d');
            if($_SESSION['user_role'] == 1)
            {
                if($_POST['edit_id'] == '')
                {
                    Homem::insert("INSERT INTO `stdnt_examfee` (`no`, `year`, `sem`, `exammonth`, `examyear`, `paidamount`, `recieptno`, `fk_feemode_id`, `paydate`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`, `status`) VALUES 
                    ('$_POST[no]', '$_POST[year]', '$_POST[sem]', '$_POST[exammonth]', '$_POST[examyear]', '$_POST[paidamount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '', '1')");
                    echo '<script>window.location = "/homes/examfeecollect?status=1";</script>';
                }
                else
                {
                    Homem::insert("UPDATE `stdnt_examfee` SET `no`='$_POST[no]', `year`='$_POST[year]', `sem`='$_POST[sem]', `exammonth`='$_POST[exammonth]', `examyear`='$_POST[examyear]', `paidamount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paydate`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `eid`='$_POST[edit_id]'");
                    echo '<script>window.location = "/homes/examfeecollect?status=2";</script>';
                }
            }
        }
    }
    public static function getusername()
    {
        if($_SESSION['user_role'] == 1)
        {
            $data[0]['name']= '';
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[no]'");
            echo $data[0]['name'];
        }
    }
    /* end of fee section */
    public static function testa()
    {
        $data = Homem::getdata("EXPLAIN add_city");
        // print_r($data);
        $data = Homem::getdata("show tables");
        // echo json_encode($data);
        // $sql = "CREATE TABLE persons(
        //     id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        //     first_name VARCHAR(30) NOT NULL,
        //     last_name VARCHAR(30) NOT NULL,
        //     email VARCHAR(70) NOT NULL UNIQUE
        // )";
        // Homem::insert($sql);
        $val = Homem::getdata("DESCRIBE `persons`");

            if($val !== FALSE)
            {
                echo 'exists';
                //DO SOMETHING! IT EXISTS!
            }
            else
            {
                echo 'Not exists';
                //I can't find it...
            }
    }
    public static function student()
    {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            echo static::css();
            echo '<body>';
            echo static::normalmenu();
            echo '
                <div class="clearfix"></div>
                <form action="/homes/saddstudent" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-3"></div>
                            <div class="col-lg-6">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">NEW STUDENT REGISTRATION</h4>
                                                <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="text" name="hallticket" id="hallticket" class="form-control" placeholder="Hall Ticket Number">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" class="form-control" placeholder="Student Name">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  
                                                            <input type="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth" required="">                                          
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="gender" id="gender" class="form-control">
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                            <option value="">Select Blood Group</option>
                                                            '; 
                                                            echo $blood;
                                                            echo '</select>
                                                        </div>
                                                    </div> 										
                                                </div>  
                                                <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-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            
                                                        </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-3"></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 telugutest()
    {
        echo '
        <form action="" method="POST">
            <input type="text" name="name">
            <input type="submit">
        </form>
        ';
        if(isset($_POST['name']))
        {
            Homem::insert("INSERT INTO `testing` (`test`) VALUES ('$_POST[name]')");
        }
        $data = Homem::getdata("SELECT * FROM `testing`");
        print_r($data);
    }
    public static function testc()
    {
        
        echo '';
        //INSERT INTO `subject_merge` (`id`, `fk_user_id`, `fk_subject_id1`, `fk_subject_id2`, `status`) VALUES (NULL, '437', '3', '5', '1');
    }
}