<?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 Exams extends \Core\Controller
{
    public static function stdntdetails()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $query = "SELECT * FROM `user_master` WHERE `user_role`='3' AND `status`='1'";
            $data = Homem::getdata($query);
            $a ='';
            for($i=0; $i<sizeof($data); $i++)
            {
                $a .= '<tr><td>'.$data[$i]['id'].'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i]['mobile'].'</td><td>'.$data[$i]['email'].'</td><td>'.$data[$i]['password'].'</td><td>'.$data[$i]['v_email'].'</td></tr>';
            }
            
            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-1"></div>
                        <div class="col-lg-10">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                    ';
                                    echo '
                                        <div class="panel panel-default">
                                            <div class="panel-body">
                                            <div class="table-responsive">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>ID</th>
                                                            <th>Hallticket Number</th>
                                                            <th>Student</th>
                                                            <th>Mobile</th>
                                                            <th>Email</th>
                                                            <th>Password</th>
                                                            <th>Email Status</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    '.$a.'
                                                    </tbody>
                                                </table>
                                            </div>';
                                    echo '
                                            </div>
                                        </div>';
                                    echo '                
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </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 userdetails()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
            $query = "SELECT * FROM `user_master` WHERE `user_role`!='3' AND `status`='1'";
            $data = Homem::getdata($query);
            $a ='';
            for($i=0; $i<sizeof($data); $i++)
            {
                $a .= '<tr><td>'.$data[$i]['id'].'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i]['mobile'].'</td><td>'.$data[$i]['email'].'</td><td>'.$data[$i]['password'].'</td><td>'.$data[$i]['v_email'].'</td><td>'.$data[$i]['user_role'].'</td></tr>';
            }
            
            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-1"></div>
                        <div class="col-lg-10">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                    ';
                                    echo '
                                        <div class="panel panel-default">
                                            <div class="panel-body">
                                            <div class="table-responsive">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>ID</th>
                                                            <th>Hallticket Number</th>
                                                            <th>Student</th>
                                                            <th>Mobile</th>
                                                            <th>Email</th>
                                                            <th>Password</th>
                                                            <th>Email Status</th>
                                                            <th>User Role</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    '.$a.'
                                                    </tbody>
                                                </table>
                                            </div>';
                                    echo '
                                            </div>
                                        </div>';
                                    echo '                
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </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 home()
    {
        if($_SESSION['user_role'] != '')
        {
            $a = '';
            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(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }


    private static function 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 = "https://assets.hinduengg.com/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="https://assets.hinduengg.com/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/style.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/sweetalert2/sweetalert2.min.css" >
            <style>
                @media print
                {
                    body * {
                        visibility: hidden;
                    }
                    .print-this, .print-this * {
                        visibility: visible;
                    }
                }
            </style>
            <script>
                function exportTableToExcel(tableID, filename = "")
                {
                    var downloadLink;
                    var dataType = "application/vnd.ms-excel";
                    var tableSelect = document.getElementById(tableID);
                    var tableHTML = tableSelect.outerHTML.replace(/ /g, "%20");
                    
                    // Specify file name
                    filename = filename?filename+".xls":"excel_data.xls";
                    
                    // Create download link element
                    downloadLink = document.createElement("a");
                    
                    document.body.appendChild(downloadLink);
                    
                    if(navigator.msSaveOrOpenBlob){
                        var blob = new Blob(["\ufeff", tableHTML], {
                            type: dataType
                        });
                        navigator.msSaveOrOpenBlob( blob, filename);
                    }else{
                        // Create a link to the file
                        downloadLink.href = "data:" + dataType + ", " + tableHTML;
                    
                        // Setting the file name
                        downloadLink.download = filename;
                        
                        //triggering the function
                        downloadLink.click();
                    }
                }
            </script>
        </head>';
        return $css;  
    }
    private static function script()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.js" ></script>
                <!-- Script to stop mouse right click start-->
            <script>
                //Disable right click script
                var message = "";
                ///////////////////////////////////
                function clickIE() {
                    if (document.all) {
                        (message);
                        return false;
                    }
                }

                function clickNS(e) {
                    if (document.layers || (document.getElementById && !document.all)) {
                        if (e.which == 2 || e.which == 3) {
                            (message);
                            return false;
                        }
                    }
                }
                if (document.layers) {
                    document.captureEvents(Event.MOUSEDOWN);
                    document.onmousedown = clickNS;
                } else {
                    document.onmouseup = clickNS;
                    document.oncontextmenu = clickIE;
                }

                document.oncontextmenu = new Function("return false")
            </script>
            <!-- Script to stop mouse right click end-->

            <!-- Script to prevent selection start-->
            <script>
                $(document).ready(function () {
                    $("body").bind("cut copy", function (e) {
                        e.preventDefault();
                    });
                });
            </script>
            <!-- Script to prevent selection end-->
                ';
        return $script;  
    }
    private static function sscript()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.js" ></script>
                ';
        return $script;  
    }
    
    
    public static function indsubject()
    {
        if($_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            $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="/Exams/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-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subcode" id="subcode" class="form-control" placeholder="Subject Code">
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subname" id="subname" class="form-control" placeholder="Subject Name">
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="subunits" id="subunits" class="form-control" placeholder="No of Chapters">
                                                        </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'].'");
                            $("#subunits").val("'.$data[0]['noofunits'].'");
                            $("#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'] == 2 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            if($_POST['edit_id'] == '')
            {
                $date = date('Y-m-d');
                Homem::insert("INSERT INTO `subject_data` (`course`, `dept`, `regulation`, `year`, `type`, `sem`, `subcode`, `subname`, `noofunits`, `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[subunits]', '$_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 = "/Exams/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]', `noofunits`='$_POST[subunits]', `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 = "/Exams/indsubject?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/indsubject?status=0";</script>';
                }
            }
        }   
    }
    
    
    public static function searchsub()
    {
        if($_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            $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'], '/Exams/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="/Exams/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>';
                }
            }
        }
    }
    
    
    public static function bulksubject()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            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="/Exams/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'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            $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]);
                    $noofunits = trim($data[22]);
                    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`, `noofunits`, `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', '$noofunits', '$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 = "/Exams/bulksubject?status=1&count='.$i.'";</script>';
            }
        }
    }
    
    
    public static function indfaculty()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveindfaculty" 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="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth" required="">
                                                    </div>
                                                </div>                 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="userrole" id="userrole" class="form-control">
                                                        <option value="">User Role</option>
                                                        <option value="2">Faculty Memeber</option>
                                                        </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-6">
                                                    <div class="form-group">                                            
                                                        <select name="course" id="course" class="form-control">
                                                            <option value="">Select 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="">Slect Department</option>
                                                        ';
                                                        echo $dept;
                                                        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 saveindfaculty()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            if($_POST['edit_id'] == '')
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `mobile`='$_POST[mobile]'");
                if(sizeof($data) == 0)
                {
                    $query = "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 
                    ('', '', '', '$_POST[hallticket]', '$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[bloodgroup]', '$_POST[course]', '$_POST[department]', '$_SESSION[org_id]', '', '', '', '$_POST[mobile]', '$_POST[email]', '$_POST[password]', '$_POST[userrole]', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/indfaculty?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/indfaculty?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[course]', 
                    `fk_dept_id`='$_POST[department]', `org_id`='$_SESSION[org_id]',  
                    `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 = "/Exams/indfaculty?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/indfaculty?status=0";</script>';
                }
            }
        }
    }
    public static function viewfaculty()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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'], '/Exams/indfaculty', '', '');
            echo static::css();
                echo '<body>';
                    echo $_SESSION['menu'];
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/indfaculty" 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 addsubfaculty()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $table = '';
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $fdept = Inputs::optionsdb($data = Homem::getdata("SELECT * FROM (SELECT DISTINCT `fk_dept_id` FROM `user_master` WHERE `user_role`!='3' AND `fk_dept_id`!='' AND `org_id`='$_SESSION[org_id]') a JOIN degree_dept_master ddm ON a.fk_dept_id=ddm.id"), 'id', 'name');
            $data = Homem::getdata("SELECT sd.*, sf.student_year as syear, sf.add_date, um.name as fname FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id JOIN user_master um ON sf.fk_user_id=um.id WHERE sf.status='1' ORDER BY sf.sf_id ASC");
            if($data > 0)
            {
                $table = Form::dbtableed($data, ['Regulation', 'Subject Code', 'Subject Name', 'Type', 'Faculty Name', 'Join Year'], ['regulation', 'subcode', 'subname', 'type', 'fname', 'syear'], '', '', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddsubfaculty" 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">ASSIGN SUBJECT TO FACULTY</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <h6>Select Subject</h6>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control" onchange="getstdjoinyear()">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="dept" id="dept" class="form-control" onchange="getregulation()">
                                                            <option value="">Select Department</option>
                                                            </select>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="regulation" id="regulation" class="form-control" >
                                                            <option value="">Select Regulation</option>
                                                            </select>
                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <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-4">
                                                        <div class="form-group">                                            
                                                            <select name="sem" id="sem" class="form-control" onchange="getsubjects()">
                                                                <option value="">Select Semester</option>
                                                                <option value="1">First Sem</option>
                                                                <option value="2">Second Sem</option>
                                                            </select>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" >
                                                            <option value="">Select Subject</option>
                                                            </select>
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fdept" id="fdept" class="form-control" onchange="getfaculty()">
                                                            <option value="">Select Faculty Department</option>
                                                            '.$fdept.'
                                                            </select>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="faculty" id="faculty" class="form-control" onchange="getstudentyear()">
                                                            <option value="">Select Faculty Name</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="syear" id="syear" class="form-control" onchange="getstudentdetails()">
                                                            <option value="">Select Students Joining Year</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div id="students" class="students">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="sdate" id="sdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Start Date" required="">
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="edate" id="edate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="End Date" required="">
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="noofclasses" id="noofclasses" class="form-control" placeholder="No of Classes">
                                                            <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-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();
            echo '
            <script>
                function getstdjoinyear()
                {
                    var course = document.getElementById("course").value;
                    var dept = document.getElementById("dept").value;
                    $.ajax({
                        type: "POST",
                        data : {course: course},
                        url: "/Exams/getstdjoinyear",
                        success: function(d){
                            $("#dept").html(d);
                            
                        }
                    });
                }
                function getregulation()
                {
                    var course = document.getElementById("course").value;
                    var dept = document.getElementById("dept").value;
                    $.ajax({
                        type: "POST",
                        data : {course: course, dept: dept},
                        url: "/Exams/getregulation",
                        success: function(d){
                            $("#regulation").html(d);
                            
                        }
                    });
                }
                function getsubjects()
                {
                    var course = document.getElementById("course").value;
                    var dept = document.getElementById("dept").value;
                    var regulation = document.getElementById("regulation").value;
                    var year = document.getElementById("year").value;
                    var sem = document.getElementById("sem").value;
                    $.ajax({
                        type: "POST",
                        data : {course: course, dept: dept, regulation: regulation, year: year, sem: sem},
                        url: "/Exams/getsubjects",
                        success: function(d){
                            $("#subject").html(d);
                            
                        }
                    });
                }
                function getfaculty()
                {
                    var fdept = document.getElementById("fdept").value;
                    $.ajax({
                        type: "POST",
                        data : {fdept: fdept},
                        url: "/Exams/getfaculty",
                        success: function(d){
                            $("#faculty").html(d);
                            
                        }
                    });
                }
                function getstudentyear()
                {
                    var course = document.getElementById("course").value;
                    var dept = document.getElementById("dept").value;
                    var regulation = document.getElementById("regulation").value;
                    $.ajax({
                        type: "POST",
                        data : {course: course, dept: dept, regulation: regulation},
                        url: "/Exams/getstudentyear",
                        success: function(d){
                            $("#syear").html(d);
                        }
                    });
                }
                function getstudentdetails()
                {
                    var course = document.getElementById("course").value;
                    var dept = document.getElementById("dept").value;
                    var regulation = document.getElementById("regulation").value;
                    var syear = document.getElementById("syear").value;
                    $.ajax({
                        type: "POST",
                        data : {course: course, dept: dept, regulation: regulation, syear: syear},
                        url: "/Exams/getstudentdetails",
                        success: function(d){
                            $("#students").html(d);
                            // alert(course+dept+regulation+syear);
                        }
                    });
                }
            </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 saveaddsubfaculty()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            if($_POST['edit_id'] == '')
            {
                $data = Homem::getdata("SELECT * FROM `subject_faculty` WHERE `fk_sub_id`='$_POST[subject]' AND `student_year`='$_POST[syear]' AND `status`='1'");
                if(sizeof($data) == 0)
                {
                    $date = date('Y-m-d');
                    $query = "INSERT INTO `subject_faculty` (`fk_sub_id`, `fk_user_id`, `student_year`, `sdate`, `edate`, `noofclasses`, `status`, `completed`, `present_status`, `add_by`, `add_date`, `remarks`) VALUES 
                    ('$_POST[subject]', '$_POST[faculty]', '$_POST[syear]', '$_POST[sdate]', '$_POST[edate]', '$_POST[noofclasses]', '1', '0', '0', '$_SESSION[user_id]', '$date', '')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addsubfaculty?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addsubfaculty?status=0";</script>';
                }
            }
        }
    }
    
    
    /*Supporting for addsubfaculty() start*/
    public static function getstdjoinyear()
    {
        if(isset($_POST['course']))
        {
            $data = Homem::getdata("SELECT ddr.dept_id, ddm.name FROM degree_name_master dnm JOIN degree_dept_relation ddr ON dnm.id=ddr.course_id JOIN degree_dept_master ddm ON ddr.dept_id=ddm.id WHERE ddr.course_id='$_POST[course]'");
            echo '<option value="">Select Department</option>';
            echo Inputs::optionsdb($data, 'dept_id', 'name');
        }
    }
    public static function getregulation()
    {
        if(isset($_POST['course']) && isset($_POST['dept']))
        {
            $data = Homem::getdata("SELECT DISTINCT regulation FROM `subject_data` WHERE `course`='$_POST[course]' AND `dept`='$_POST[dept]'");
            echo '<option value="">Select Regulation</option>';
            echo Inputs::optionsdb($data, 'regulation', 'regulation');
        }
    }
    public static function getsubjects()
    {
        if(isset($_POST['course']) && isset($_POST['dept']) && isset($_POST['year']) && isset($_POST['sem']))
        {
            $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]'");
            echo '<option value="">Select Subject</option>';
            echo Inputs::optionsdb($data, 'sub_id', 'subname');
        }
    }
    public static function getfaculty()
    {
        if(isset($_POST['fdept']))
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE (`user_role`!='3') AND `fk_dept_id`='$_POST[fdept]' AND `org_id`='$_SESSION[org_id]' AND `status`='1'");
            echo '<option value="">Select Faculty Name</option>';
            echo Inputs::optionsdb($data, 'id', 'name');
        }
    }
    public static function getstudentyear()
    {
        if(isset($_POST['course']) && isset($_POST['dept']))
        {
            $data = Homem::getdata("SELECT DISTINCT `fromyear` FROM `user_master` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[dept]' AND `org_id`='$_SESSION[org_id]' AND `user_role`='3' AND `regulation`='$_POST[regulation]' ORDER BY `fromyear` ASC");
            echo '<option value="">Select Students Joining Year</option>';
            echo Inputs::optionsdb($data, 'fromyear', 'fromyear');
        }
    }
    public static function getstudentdetails()
    {
        if(isset($_POST['course']) && isset($_POST['dept']))
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `org_id`='$_SESSION[org_id]' AND `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `fromyear`='$_POST[syear]' ORDER BY `no` ASC");
            echo '<h6>List of students in the class: (Number of students: '.sizeof($data).')</h6>';
            echo Form::dbtableed($data, ['Hall Ticket Number', 'Name', 'Gender'], ['no', 'name', 'gender'], '', '', '');
        }
    }
    /*Supporting for addsubfaculty() end*/
    
    
    public static function subjectsyllabus()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $data = Inputs::optionsdb(Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0'"), 'sub_id', 'subname');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/savesubjectsyllabus" 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 SYLLABUS TO THE SUBJECT</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">                                      
                                                        <select id="subject" name="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                            <option value="">Select Subject</option>
                                                            '.$data.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <div class="form-group">                                      
                                                            <select id="chapter" name="chapter" class="form-control" required>
                                                                <option value="">Select Chapter / Unit Number</option>
                                                                
                                                            </select>
                                                        </div>
                                                    </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="Chapter Name">
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea type="text" name="syllabus" id="syllabus" class="form-control" placeholder="Chapter Syllabus"></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea type="text" name="topics" id="topics" class="form-control" placeholder="Chapter Topics (Enter each topic seperatred by (coma ,))"></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="theory" id="theory" class="form-control" placeholder="% of Theory">
                                                    </div>
                                                </div>  		
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="derivation" id="derivation" class="form-control" placeholder="% of Derivations">
                                                    </div>
                                                </div>  
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="problems" id="problems" class="form-control" placeholder="% of Problems">
                                                    </div>
                                                </div> 								
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="hours" id="hours" class="form-control" placeholder="Number of Hours Required for Teaching">
                                                    </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::sscript();
            echo '
            <script>
                function getsubjectchapters()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsubjectchapters",
                        success: function(d){
                            $("#chapter").html(d);
                            
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                echo '';
            }
            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 savesubjectsyllabus()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if($_POST['edit_id'] == '')
            {
                $data = Homem::getdata("SELECT * FROM `subject_syllabus` WHERE `fk_sub_id`='$_POST[subject]' AND `chapt_no`='$_POST[chapter]' AND `add_by`='$_SESSION[user_id]' AND `status`='1'");
                if(sizeof($data) == 0)
                {
                    $date = date('Y-m-d');
                    $query = "INSERT INTO `subject_syllabus` (`fk_sub_id`, `chapt_no`, `chapt_name`, `chapt_syllabus`, `chapt_topics`, `theory`, `derivation`, `problems`, `noofhours`, `add_by`, `add_date`, `status`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[name]', '$_POST[syllabus]', '$_POST[topics]', '$_POST[theory]', '$_POST[derivation]', '$_POST[problems]', '$_POST[hours]', '$_SESSION[user_id]', '$date', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/subjectsyllabus?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/subjectsyllabus?status=0";</script>';
                }
            }
        }
    }
    /*Supporting for subjectsyllabus() start*/
    public static function getsubjectchapters()
    {
        if(isset($_POST['subject']))
        {
            $data = Homem::getdata("SELECT * FROM `subject_data` WHERE `sub_id`='$_POST[subject]'");
            echo '<option value="">Select Chapter / Unit Number</option>';
            for($i=1; $i<=$data[0]['noofunits']; $i++)
            {
                echo '<option value="'.$i.'">Chapter - '.$i.'</option>';
            }
        }
    }
    /*Supporting for subjectsyllabus() end*/
    
    
    
    /* Posting Attendance to singel subject*/
    public static function singlesubjectattendance()
    { 
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4)
        {
            
            {
                $data = Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0'");
                if($data > 0)
                {
                    $table = Form::dbtableed($data, ['Regulation', 'Subject Code', 'Subject Name', 'Type'], ['regulation', 'subcode', 'subname', 'type'], '/Exams/indsubject', 'sub_id', '');
                }
            }
            $data = Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0'");
            $a = '';
            for($i=0; $i<sizeof($data); $i++)
            {
                $a .= '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].' ('.$data[$i]['subcode'].')</option>';
            }
            $data = $a;
            $hour = Homem::getdata("SELECT * FROM `tt_slottime`");
            $a = '';
            for($i=0; $i<sizeof($hour); $i++)
            {
                $a .= '<option value="'.$hour[$i]['hour_no'].'">'.$hour[$i]['f_time'].' - '.$hour[$i]['t_time'].' ('.$hour[$i]['hour_no'].' - Hour)</option>';
            }
            $hour = $a;
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                {
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/savesinglesubjectattendance" 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: 30px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Subject Attendance</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-6">
                                                        <div class="form-group">                                      
                                                            <select id="subject" name="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$data.'
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-6">
                                                        <select id="hour" name="hour" class="form-control" required>
                                                            <option value="">Select Hour</option>
                                                            '.$hour.'
                                                        </select>
                                                    </div>                               
                                                </div>
                                                <div class="row" style="display:none;">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select id="topic" name="topic" class="form-control">
                                                                <option value="">Select Topic</option>
                                                            </select>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            
                                                            <div class="form-group">                                            
                                                                <input name="atopic" id="atopic" class="form-control" placeholder="Topic" >
                                                            </div>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                                                                
                                                            <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" >
                                                                <option value="">Select Chapter / Unit Number</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <div class="row" style="display:none;">
                                                      	
                                                    <div class="col-lg-6">
                                                        <input name="remarks" id="remarks" class="form-control" placeholder="Remarks">
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                
                                                            <input type="hidden" name="course" id="course" class="form-control" placeholder="Course" required>      
                                                            <input type="hidden" name="dept" id="dept" class="form-control" placeholder="Dept" required>    
                                                            <input type="hidden" name="year" id="year" class="form-control" placeholder="Year" required>    
                                                            <input type="hidden" name="sem" id="sem" class="form-control" placeholder="Sem" required>    
                                                            <input type="hidden" name="syear" id="syear" class="form-control" placeholder="Studnet Year" required>    
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div id="students" class="students">
                                                        </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 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::sscript();
            echo '
            <script>
                function getsubjectchapters()
                {
                    getstudentdetails();
                    getstudentyearandcourse();
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsubjectchapters",
                        success: function(d){
                            $("#chapter").html(d);
                        }
                    });
                }
                function getsubchaptopics()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = document.getElementById("chapter").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter},
                        url: "/Exams/getsubchaptopics",
                        success: function(d){
                            $("#topic").html(d);
                        }
                    });
                }
                function getstudentdetails()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subid: subject},
                        url: "/Exams/getstudentdetailsforattendance",
                        success: function(d){
                            $("#students").html(d);
                        }
                    });
                }
                function getstudentyearandcourse()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subid: subject},
                        url: "/Exams/getstudentyearandcourse",
                        success: function(d){
                            // $("#students").html(d);
                            // console.log(d);
                            // setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            const a = JSON.parse(d);
                            // console.log(a[0]["syear"]);
                            $("#course").val(a[0]["course"]);
                            $("#dept").val(a[0]["dept"]);
                            $("#year").val(a[0]["year"]);
                            $("#sem").val(a[0]["sem"]);
                            $("#syear").val(a[0]["syear"]);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </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 savesinglesubjectattendance()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4)
        {
            
        $date = date('Y-m-d');
        $query = "SELECT * FROM `subject_attedancemaster` WHERE `hourid`='$_POST[hour]' AND`subid`='$_POST[subject]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `edate`='$date' AND `syear`='$_POST[syear]' AND `dept`='$_POST[dept]' ORDER BY `id` DESC";
        $data = Homem::getdata($query);
        if(sizeof($data) == 0)
        {
            $work = array();
            $work = $_POST['work'];
            $sid = array();
            $sid = $_POST['sid'];
            date_default_timezone_set('Asia/Kolkata');
            $date = date('Y-m-d');
            $time = date('Y-m-d H:i:s A');
            $present = 0;
            for($i=0; $i<sizeof($_POST['work']); $i++)
            {
                $present = (int) $work[$i] + (int) $present;
            }
            $total = sizeof($_POST['work']);
            $absent = (int) $total-(int) $present;
            
            $query = "INSERT INTO `subject_attedancemaster` (`id`, `subid`, `chapter`, `topicid`, `atopic`, `hourid`, `remarks`, `course`, `dept`, `year`, `sem`, `syear`, `total`, `absents`, `presents`, `edate`, `etime`, `fk_user_id`, `status`, `locks`) VALUES 
            (NULL, '$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[atopic]', '$_POST[hour]', '$_POST[remarks]', '$_POST[course]', '$_POST[dept]', '$_POST[year]', '$_POST[sem]', '$_POST[syear]', '$total', '$absent', '$present', '$date', '$time', '$_SESSION[user_id]', '1', '');";
            Homem::insert($query);
            $query = "SELECT * FROM `subject_attedancemaster` WHERE `subid`='$_POST[subject]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `edate`='$date' AND `syear`='$_POST[syear]' AND `dept`='$_POST[dept]' ORDER BY `id` DESC";
            $data = Homem::getdata($query);
            $id = $data[0]['id'];
            for($i=0; $i<sizeof($_POST['work']); $i++)
            {
                $sid1 = $sid[$i];
                $att1 = $work[$i];
                $query = "INSERT INTO `subject_attedancestudents` (`master_id`, `user_id`, `attendance`) VALUES ('$id', '$sid1', '$att1')";
                Homem::insert($query);
            }
            echo '<script>window.location = "/Exams/singlesubjectattendance?status=1";</script>';
        }
        else
        {
            echo '<script>window.location = "/Exams/singlesubjectattendance?status=0";</script>';
        }
        }
    }
    /*Supporting for singlesubjectattendance() start*/
    public static function getstudentdetailsforattendance()
    {
        if(isset($_POST['subid']))
        {
            $data = Homem::getdata("SELECT um.id, um.no, um.name, um.gender FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id JOIN user_master um ON um.fk_course_id=sd.course AND um.fk_dept_id=sd.dept AND um.fromyear=sf.student_year AND sf.status='1' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.sub_id='$_POST[subid]'");
            echo '<h6>List of students in the class: (Number of students: '.sizeof($data).')</h6>';
            echo '<input type="hidden" name="dcount" id="dcount" placeholder="Count" value="'.sizeof($data).'">';
            $data1 = '
            <div class="table-responsive">
                <table class="table table-responsive-sm">
                    <thead>
                        <tr>
                            <th><input type="checkbox" name="allworking" id="allworking" onchange="setallpresent()">Present</th>
                            <th>Hallticket</th>
                            <th>Name</th>
                            <th>Gender</th>
                        </tr>
                    </thead>
                    <tbody>';
            for($i=0; $i<sizeof($data); $i++)
            {
                $data1 .= '<tr><td><input type="hidden" name="work['.$i.']" id="work['.$i.']" value="0"> <input type="checkbox" name="work['.$i.']" id="work['.$i.']" value="1"></td>';
                $data1 .= '<td><input type="hidden" name="sid['.$i.']" id="sid['.$i.']" value="'.$data[$i]['id'].'">'.$data[$i]['no'].'</td>';
                $data1 .= '<td><input type="hidden" name="name['.$i.']" id="name['.$i.']" value="'.$data[$i]['name'].'">'.$data[$i]['name'].'</td>';
                $data1 .= '<td>'.$data[$i]['gender'].'</td>';
                // $data1 .= '<td><input type="hidden" name="mobile['.$i.']" id="mobile['.$i.']" value="'.$data[$i]['fmobile'].'">'.$data[$i]['fmobile'].'</td>';
                $data1 .= '</tr>';
            }
            $data1 .= '</tbody></table>';
            echo $data1;
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });
                function setallpresent()
                {
                    var present = document.getElementById("allworking");
                    if(present.checked == true)
                    {
                        selects();
                    }
                    else
                    {
                        deselects();
                    }
                }
                function selects()
                {  
                    var scount = document.getElementById("dcount");
                    for(var i=0; i<scount.value; i++)
                    { 
                        var a = "work["+i+"]";
                        var ele=document.getElementsByName(a);
                        for(var j=0; j<ele.length; j++)
                        {  
                            if(ele[j].type=="checkbox")  
                            {
                                ele[j].checked=true;
                            }
                        }
                    }
                }   
                function deselects()
                {  
                    var scount = document.getElementById("dcount");
                    for(var i=0; i<scount.value; i++)
                    { 
                        var a = "work["+i+"]";
                        var ele=document.getElementsByName(a);
                        for(var j=0; j<ele.length; j++)
                        {  
                            if(ele[j].type=="checkbox")  
                            {
                                ele[j].checked=false;
                            }
                        }
                    }
                }          
            </script>  
            ';
        }
    }
    public static function getsubchaptopics()
    {
        if(isset($_POST['chapter']))
        {
            $data = Homem::getdata("SELECT * FROM `subject_syllabus` WHERE `fk_sub_id`='$_POST[subject]' AND `chapt_no`='$_POST[chapter]' AND `add_by`='$_SESSION[user_id]'");
            
            if(sizeof($data) > 0)
            {
                $topics = $data[0]['chapt_topics'];
                $daa = explode("," , $topics);
                echo '<option value="">Select Topic</option>';
                for($i=0; $i<sizeof($daa); $i++)
                {
                    $j = $i+1;
                    echo '<option value="'.$j.'">'.$daa[$i].'</option>';
                }
            }
            else
            {
                echo '<option value="">Please ADD Topic in The Syllabus Section</option>';
            }
        }
    }
    public static function getstudentyearandcourse()
    {
        if(isset($_POST['subid']))
        {
            // echo $_POST['subid'];
            $data = Homem::getdata("SELECT sd.course, sd.dept, sd.year, sd.sem, sf.student_year as syear FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.fk_sub_id='$_POST[subid]' AND sf.status='1'");
            echo json_encode($data);
        }
    }
    /*Supporting for singlesubjectattendance() end*/
    
    
    // Attendacne Reports started() 
    public static function singlesubjectattendancebydate()
    { 
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4)
        {
            $a = '';
            $table = '';
            if(isset($_POST['subject']))
            {
                $data = Homem::getdata("SELECT sa.hourid, um.no, um.name, sas.attendance FROM subject_attedancemaster sa JOIN subject_attedancestudents sas ON sa.id=sas.master_id  JOIN user_master um ON um.id=sas.user_id WHERE sa.edate='$_POST[date]' AND sa.status='1' AND sa.subid='$_POST[subject]'");
                $htno = array();
                $hor = array();
                foreach ($data as $h) 
                {
                    $htno[] = $h['no'];
                    $hor[] = $h['hourid'];
                }
                $no = array_values(array_unique($htno));
                sort($no);
                $hour = array_values(array_unique($hor));
                sort($hour);
                if(sizeof($data) > 0)
                {
                    if(sizeof($hour) == 1)
                    {
                        $table = Form::dbtableed($data, ['PIN', 'Name', 'Attendance'], ['no', 'name', 'attendance'], '', '', '');
                    }
                    else
                    {
                        $a = '';
                        
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            $b = 0;
                            $a .= '<tr>';
                            $a .= '<td>'.$no[$i].'</td>';
                            
                            for($j=0; $j<sizeof($hour); $j++)
                            {
                                for($k=0; $k<sizeof($data); $k++)
                                {
                                    
                                    if($data[$k]['no'] == $no[$i] && $data[$k]['hourid'] == $hour[$j])
                                    {
                                        if($b==0)
                                        {
                                            $a .= '<td>'.$data[$k]['name'].'</td>';
                                        }
                                        $b = 1;
                                        if($b == 1)
                                        {
                                            $a .= '<td>'.$data[$k]['attendance'].'</td>';
                                        }
                                        
                                    }
                                    
                                }
                            }
                            $a .= '</tr>';
                        }
                    }
                }
                $table=$table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px">
                    '.$a.'
                    </table>
                </div>';
            }
            $data = Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0'");
            $a = '';
            for($i=0; $i<sizeof($data); $i++)
            {
                $a .= '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].' ('.$data[$i]['subcode'].')</option>';
            }
            $data = $a;
            $a = '';

            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                {
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/singlesubjectattendancebydate" 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: 30px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Subject Attendance</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-6">
                                                        <div class="form-group">                                      
                                                            <select id="subject" name="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$data.'
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-6">
                                                        <input type="text" name="date" id="date" class="form-control" placeholder="Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                                    </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-3"></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::sscript();
            echo '
            <script>
                function getsubjectchapters()
                {
                    getstudentdetails();
                    getstudentyearandcourse();
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsubjectchapters",
                        success: function(d){
                            $("#chapter").html(d);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </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 singlesubjectattendancereportbetweentwodates()
    { 
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4)
        {
            $table = '';
            if(isset($_POST['subject']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                $data = Homem::getdata("SELECT sa.hourid, sa.edate, um.no, um.name, sas.attendance FROM subject_attedancemaster sa JOIN subject_attedancestudents sas ON sa.id=sas.master_id  JOIN user_master um ON um.id=sas.user_id WHERE sa.status='1' AND sa.subid='$_POST[subject]' AND DATE(sa.edate) BETWEEN '$date1' AND '$date2'");
                $htno = array();
                $hor = array();
                $edate = array();
                foreach ($data as $h) 
                {
                    $htno[] = $h['no'];
                    $hor[] = $h['hourid'];
                    $edate[] = $h['edate'];
                }
                $no = array_values(array_unique($htno));
                sort($no);
                $hour = array_values(array_unique($hor));
                sort($hour);
                $date = array_values(array_unique($edate));
                sort($date);
                if(sizeof($data) > 0)
                {
                    if(sizeof($date) == 1 && sizeof($hour) == 1)
                    {
                        $table = Form::dbtableed($data, ['PIN', 'Name', 'Attendance'], ['no', 'name', 'attendance'], '', '', '');
                    }
                    if(sizeof($date) == 1 && sizeof($hour) > 1)
                    {
                        $a = '';
                        
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            $b = 0;
                            $a .= '<tr>';
                            $a .= '<td>'.$no[$i].'</td>';
                            
                            for($j=0; $j<sizeof($hour); $j++)
                            {
                                for($k=0; $k<sizeof($data); $k++)
                                {
                                    
                                    if($data[$k]['no'] == $no[$i] && $data[$k]['hourid'] == $hour[$j])
                                    {
                                        if($b==0)
                                        {
                                            $a .= '<td>'.$data[$k]['name'].'</td>';
                                        }
                                        $b = 1;
                                        if($b == 1)
                                        {
                                            $a .= '<td>'.$data[$k]['attendance'].'</td>';
                                        }
                                        
                                    }
                                    
                                }
                            }
                            $a .= '</tr>';
                        }
                    }
                    if(sizeof($date) > 1)
                    {
                        $a = '';
                        
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            $b = 0;
                            $a .= '<tr>';
                            $a .= '<td>'.$no[$i].'</td>';
                            for($j=0; $j<sizeof($date); $j++)
                            {
                                for($k=0; $k<sizeof($hour); $k++)
                                {
                                    for($l=0; $l<sizeof($data); $l++)
                                    {
                                        if($data[$l]['no'] == $no[$i] && $data[$l]['hourid'] == $hour[$k] && $data[$l]['edate'] == $date[$j])
                                        {
                                            if($b==0)
                                            {
                                                $a .= '<td>'.$data[$l]['name'].'</td>';
                                                $b = 1;
                                            }
                                            $a .= '<td>'.$data[$l]['attendance'].'</td>';
                                        }
                                    }
                                }
                            }
                            $a .= '</tr>';
                        }
                    }
                }
                $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px">
                    '.$a.'
                    </table>
                </div>';
            }
            $data = Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0'");
            $a = '';
            for($i=0; $i<sizeof($data); $i++)
            {
                $a .= '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].' ('.$data[$i]['subcode'].')</option>';
            }
            $data = $a;
            $a = '';

            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-3"></div>
                            <div class="col-lg-6">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 30px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Subject Attendance</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-4">
                                                        <div class="form-group">                                      
                                                            <select id="subject" name="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$data.'
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <input type="text" name="fromdate" id="fromdate" class="form-control" placeholder="From Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <input type="text" name="todate" id="todate" class="form-control" placeholder="To Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                                    </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-3"></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::sscript();
            echo '
            <script>

            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </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 datewiseattendancesummary()
    {
        if($_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 8)
        {
            $table = '';
            if(isset($_POST['course']))
            {
                $query = "SELECT sa.*, sd.subcode, sd.subname, um.name FROM subject_attedancemaster sa JOIN subject_data sd ON sa.subid=sd.sub_id JOIN user_master um ON sa.fk_user_id=um.id WHERE sa.course='$_POST[course]' AND sa.dept='$_POST[dept]' AND sa.year='$_POST[year]' AND sa.sem='$_POST[sem]' AND sa.edate='$_POST[date]'";
                $data = Homem::getdata($query);
                if($data > 0)
                {
                    $table = Form::dbtableed($data, ['Subject Code', 'Subject Name', 'Faculty Name', 'Hour', 'Total', 'Absents', 'Presents'], ['subcode', 'subname', 'name', 'hourid', 'total', 'absents', 'presents'], '', '', '');
                }
            }
            $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="/Exams/datewiseattendancesummary" 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-4">
                                                        <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-4">
                                                        <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 class="col-md-4">  
                                                        <div class="form-group">
                                                            <input id="date" name="date" class="form-control" type="text" onfocus="this.type=`date`" onblur="this.type=`text`" placeholder="Date">
                                                        </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 class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">'.$table.'</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'].'");
                            $("#subunits").val("'.$data[0]['noofunits'].'");
                            $("#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 testing()
    {
        $_SESSION['org_id'] = 3;
        $_POST['course'] = 1;
        $_POST['dept'] = 5;
        $_POST['year'] = 1;
        $_POST['sem'] = 1;
        $date1 = $_POST['fromdate'] = '2022-02-10';
        $date2 = $_POST['todate'] = '2022-02-28';
        $query = "SELECT u.no, u.name, sa.*, sd.subcode, sd.subname, um.name as fname, sa.hourid, sas.master_id, sas.attendance FROM subject_attedancemaster sa JOIN subject_data sd ON sa.subid=sd.sub_id JOIN user_master um ON sa.fk_user_id=um.id JOIN subject_attedancestudents sas ON sas.master_id=sa.id JOIN user_master u ON u.id=sas.user_id
        WHERE sa.course='$_POST[course]' AND sa.dept='$_POST[dept]' AND sa.year='$_POST[year]' AND sa.sem='$_POST[sem]' AND DATE(sa.edate) BETWEEN '$date1' AND '$date2'";
        $data = Homem::getdata($query);
        if($data > 0)
        {
            $table = Form::dbtableed($data, ['Subject Code', 'Subject Name', 'Faculty Name', 'Hour', 'Total', 'Absents', 'Presents', 'date'], ['subcode', 'subname', 'name', 'hourid', 'total', 'absents', 'presents', 'edate'], '', '', '');
        }
        $htno = array();
        $scode = array();
        $edate = array();
        $hrno = array();
        foreach ($data as $h) 
        {
            $htno[] = $h['no'];
            $scode[] = $h['subcode'];
            $edate[] = $h['edate'];
            $hrno[] = $h['master_id'];
        }
        $no = array_values(array_unique($htno));
        sort($no);
        $subcode = array_values(array_unique($scode));
        sort($subcode);
        $date = array_values(array_unique($edate));
        sort($date);
        $masterid = array_values(array_unique($hrno));
        sort($masterid);
        for($i=0; $i<sizeof($data); $i++)
        {
            for($j=0; $j<sizeof($no); $j++)
            {
                if($no[$j] == $data[$i]['no'])
                {
                    $name[$no[$j]] = $data[$i]['name'];
                }
            }
            for($j=0; $j<sizeof($subcode); $j++)
            {
                if($subcode[$j] == $data[$i]['subcode'])
                {
                    $subname[$subcode[$j]] = $data[$i]['subname'];
                }
            }
        }
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $mastercount[$subcode[$j]] = array();
            for($i=0; $i<sizeof($masterid); $i++)
            {
                $b = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($subcode[$j] == $data[$k]['subcode'] && $masterid[$i] == $data[$k]['master_id'])
                    {
                        $b = 1;
                    }
                    if($k == sizeof($data)-1)
                    {
                        if($b == 1)
                        {
                            $mastercount[$subcode[$j]][]= $masterid[$i];
                        }
                    }
                }
            }
        }
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $subcount[$subcode[$j]] = sizeof($mastercount[$subcode[$j]]);
        }
        $total = 0;
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $total = $total + $subcount[$subcode[$j]];
        }
        for($i=0; $i<sizeof($no); $i++)
        {
            for($j=0; $j<sizeof($subcode); $j++)
            {
                $actualdata[$no[$i]][$subcode[$j]] = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($no[$i] == $data[$k]['no'] && $subcode[$j] == $data[$k]['subcode'])
                    {
                        $actualdata[$no[$i]][$subcode[$j]] = $actualdata[$no[$i]][$subcode[$j]] + (int)$data[$k]['attendance'];
                    }
                }
            }
        }
        $a = '';
        $a .= '<thead>';
        $a .= '<tr>'; 
        $a .= '<th rowspan="3">S. No.</th>';
        $a .= '<th rowspan="3">PIN</th>';
        $a .= '<th rowspan="3">Name</th>';
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $a .= '<th>'.$subcode[$j].'</th>';
        }
        $a .= '<th rowspan="3">Total</th>';
        $a .= '<th rowspan="3">Percnetage</th>';
        $a .='</tr>';
        $a .= '<tr>';
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $a .= '<td>'.$subname[$subcode[$j]].'</td>';
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($j=0; $j<sizeof($subcode); $j++)
        {
            $a .= '<td>('.$subcount[$subcode[$j]].')</td>';
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $a .= '<tbody>';
        for($i=0; $i<sizeof($no); $i++)
        {
            $b = $i+1;
            $c = 0;
            $a .= '<tr>';
            $a .= '<td>'.$b.'</td>';
            $a .= '<td>'.$no[$i].'</td>';
            $a .= '<td>'.$name[$no[$i]].'</td>';
            for($j=0; $j<sizeof($subcode); $j++)
            {
                $a .= '<td>'.$actualdata[$no[$i]][$subcode[$j]].'</td>';
                $c = $c+$actualdata[$no[$i]][$subcode[$j]];
            }
            $attend[$no[$i]] = $c;
            $per = round(($c/$total)*100,2);
            $a .= '<td>'.$attend[$no[$i]].'</td>';
            $a .= '<td>'.$per.'</td>';
            $a .= '</tr>';

            
        }
        $a .= '</tbody>';
        // echo json_encode($actualdata);
        echo '<div class="table-responsive">
                <table class="table table-responsive-sm"  border="1px">
                '.$a.'
                </table>
            </div>';
    }

    // Supporting Scripts for every page common
    public static function checkbrower()
    {
        $mystring = $_SERVER['HTTP_USER_AGENT'];
        $word = 'Chrome';
        if(strpos($mystring, $word) !== false)
        {
            echo "1";
        }
        else
        {
            echo "0";
        }
    }
    public static function checkurl()
    {
        $url= $_SERVER['HTTP_HOST'];   
        return $url;
    }


    // Non used function
    public static function blockingscripts()
    {
        $a .= '
            <!--Script to confirm refresh start-->
            <script type="text/javascript">
                window.onbeforeunload = function () {
                    return "The Data in this page may lost. Do you want to refresh this page now.?";
                }
            </script>
            <!--Script to confirm refresh end-->
            <!--Script to Disable keyboard start-->
            <!--
                <script  type="text/javascript">
                    document.onkeydown = function (e) {	return false;}
                    $(function() {
                        $(this).bind("contextmenu", function(e) {
                            e.preventDefault();
                        });
                    });	
                </script>
            -->
            <!--Script to Disable keyboard end-->

            <!--Script to stop mouse move up and down start-->
            <script  type="text/javascript">
                $(document).ready(function () {
                        addEvent(document, "mouseout", function(e) {
                            e = e ? e : window.event;
                            var from = e.relatedTarget || e.toElement;
                            if (!from || from.nodeName == "HTML") {
                                console.log("Out of zone");
                                // swal("Sorry! Not Permitted to enter this area..", "You are not permitted to enter in to this area...", "error");
                            }
                        });
                });
                    function addEvent(obj, evt, fn) {
                        if (obj.addEventListener) {
                            obj.addEventListener(evt, fn, false);
                        }
                        else if (obj.attachEvent) {
                            obj.attachEvent("on" + evt, fn);
                        }
                    }
            </script>
            <!--Script to stop mouse move up and down end-->

            <!-- Script to prevent back button start-->
            <script>
                (function (global) {
                    if (typeof (global) === "undefined") {
                        throw new Error("window is undefined");
                    }
                    var _hash = "!";
                    var noBackPlease = function () {
                        global.location.href += "#";
                
                        // making sure we have the fruit available for juice....
                        // 50 milliseconds for just once do not cost much (^__^)
                        global.setTimeout(function () {
                            global.location.href += "!";
                        }, 50);
                    };
                    // Earlier we had setInerval here....
                    global.onhashchange = function () {
                        if (global.location.hash !== _hash) {
                            global.location.hash = _hash;
                        }
                    };
                    global.onload = function () {
                        noBackPlease();
                        // disables backspace on page except on input fields and textarea..
                        document.body.onkeydown = function (e) {
                            var elm = e.target.nodeName.toLowerCase();
                            if (e.which === 8 && (elm !== "input" && elm !== "textarea")) {
                                e.preventDefault();
                            }
                            // stopping event bubbling up the DOM tree..
                            e.stopPropagation();
                        };
                    };
                })(window);
                
            </script>
            <!-- Script to prevent back button end-->

            <!-- Script to stop mouse right click start-->
            <script>
                //Disable right click script
                var message = "";
                ///////////////////////////////////
                function clickIE() {
                    if (document.all) {
                        (message);
                        return false;
                    }
                }

                function clickNS(e) {
                    if (document.layers || (document.getElementById && !document.all)) {
                        if (e.which == 2 || e.which == 3) {
                            (message);
                            return false;
                        }
                    }
                }
                if (document.layers) {
                    document.captureEvents(Event.MOUSEDOWN);
                    document.onmousedown = clickNS;
                } else {
                    document.onmouseup = clickNS;
                    document.oncontextmenu = clickIE;
                }

                document.oncontextmenu = new Function("return false")
            </script>
            <!-- Script to stop mouse right click end-->

            <!-- Script to prevent selection start-->
            <script>
                $(document).ready(function () {
                    $("body").bind("cut copy", function (e) {
                        e.preventDefault();
                    });
                });
            </script>
            <!-- Script to prevent selection end-->
            ';
    }
    public static function jscripttime()
    {
        echo '
        <p id="demo"></p>
        <script>
        function presentdatetime()
        {
            var d = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
            var d = new Date(d);
            var y = d.getFullYear()+"-";
            var m = parseInt(d.getMonth())+1;
            var da = "-"+d.getDate();
            var h = " "+d.getHours();
            var min = ":"+d.getMinutes();
            var s = ":"+d.getSeconds();
            var total = y+m+da+h+min+s;
            return total;
        }
            document.getElementById("demo").innerHTML = presentdatetime();
        </script>
        ';
    }
    public static function emailverificationapi()
    {
        // header('content-type: text/xml;charset=utf-8');
        $name = "Fianl Test";
        $email = "s.krishnarjuna@gmail.com";
        $token = "1234567890qwertyui";
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => "http://apie.mycvmaker.com/email/index.php",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS =>"{\"apikey\":\"s.krishnarjuna@gmail.com\", \"secrectkey\":\"SSRSKJR\", \"toemail\":\"$email\", \"toname\":\"$name\", \"token\":\"$token\"}",
        CURLOPT_HTTPHEADER => array(
            ": ",
            "Content-Type: application/json"
        ),
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $data = json_decode($response, true);
        if($data['statuscode'] == 200)
        {
            echo "1";
        }
        else
        {
            echo "0";
        }
    }
}
// HYDH01094C TAN NUMBER hindu college
// AAABH0044H HC&HS PAN - CHAKRAVARTHY SIR..
// HC&HS REG. COPY - SUBBA RAO..
// GST NUMBER HC&HS - CHAKRAVARTHY SIR..