<?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
{
    private static function course($id)
    {
        if($id != '')
        {
            $url = $_SERVER['HTTP_HOST'];
            if($url == "localhost")
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($url == "scholarexams.com")
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($url == "exams.hcg.ac.in")
            {
                if($id == 1)
                {
                    return 'B. Sc.';
                }
                if($id == 2)
                {
                    return 'B. Com.';
                }
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            $url = $_SERVER['HTTP_HOST'];
            if($url == "localhost")
            {
                if($id == 1)
                {
                    return 'Civil';
                }
                else if($id == 2)
                {
                    return 'EEE';
                }
                else if($id == 3)
                {
                    return 'Mech';
                }
                else if($id == 4)
                {
                    return 'ECE';
                }
                else if($id == 5)
                {
                    return 'CSE';
                }
                else
                {
                    return '';
                }
            }
            if($url == "scholarexams.com")
            {
                if($id == 1)
                {
                    return 'Civil';
                }
                else if($id == 2)
                {
                    return 'EEE';
                }
                else if($id == 3)
                {
                    return 'Mech';
                }
                else if($id == 4)
                {
                    return 'ECE';
                }
                else if($id == 5)
                {
                    return 'CSE';
                }
                else
                {
                    return '';
                }
            }
            if($url == "exams.hcg.ac.in")
            {
                if($id == 1)
                {
                    return 'MPCS';
                }
                else if($id == 2)
                {
                    return 'MSCS';
                }
                else if($id == 3)
                {
                    return 'MECS';
                }
                else if($id == 4)
                {
                    return 'Gen-EM';
                }
                else if($id == 5)
                {
                    return 'Gen-TM';
                }
                else if($id == 6)
                {
                    return 'Computers';
                }
                else if($id == 7)
                {
                    return 'Commerce';
                }
                else
                {
                    return '';
                }
            }
        }
    }
    public static function texamreports()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
        $data = Homem::getdata("SELECT um.id, um.no, um.name, um.gender, um.fk_course_id, um.fk_dept_id, qea.fk_suject_id, sd.subname, sd.year, sd.sem, qea.fk_exam_id, qet.q_count, qea.marks FROM user_master um JOIN quiz_exam_answers qea ON um.id=qea.fk_student_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN subject_data sd ON sd.sub_id=qea.fk_suject_id WHERE qea.fk_suject_id=qet.fk_sub_id AND qea.fk_faculty_id=qet.fk_user_id AND um.id=qea.fk_student_id AND qea.completed='1' AND qea.marks != '' AND qet.completed='1'");
        $sub_id = array();
        $exam_id = array();
        $stdnt_no = array();
        $crse = array();
        $depts = array();
        $yer = array();
        $se = array();
        foreach ($data as $h) {
            $sub_id[] = $h['fk_suject_id'];
            $exam_id[] = $h['fk_exam_id'];
            $stdnt_no[] = $h['no'];
            $crse[] = $h['fk_course_id'];
            $depts[] = $h['fk_dept_id'];
            $yer[] = $h['year'];
            $se[] = $h['sem'];
        }
        $subid = array_values(array_unique($sub_id));
        sort($subid);
        $examid = array_values(array_unique($exam_id));
        sort($examid);
        $no = array_values(array_unique($stdnt_no));
        sort($no);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($depts));
        sort($dept);
        $year = array_values(array_unique($yer));
        sort($year);
        $sem = array_values(array_unique($se));
        sort($sem);
        for($i=0; $i<sizeof($subid); $i++)
        {
            for($j=0; $j<sizeof($data); $j++)
            {
                if($data[$j]['fk_suject_id'] == $subid[$i])
                {
                    $subname[$subid[$i]] = $data[$j]['subname'];
                    $subyear[$subid[$i]] = $data[$j]['year'];
                    $subyear[$subid[$i]] = $data[$j]['sem'];
                    $subcourse[$subid[$i]] = $data[$j]['fk_course_id'];
                    $subdept[$subid[$i]] = $data[$j]['fk_dept_id'];
                }
            }
        }
        for($i=0; $i<sizeof($subid); $i++)
        {
            $count = 0;
            for($j=0; $j<sizeof($examid); $j++)
            {
                $tcount = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($data[$k]['fk_suject_id'] == $subid[$i] && 
                        $data[$k]['fk_exam_id'] == $examid[$j])
                    {
                        $subexams[$examid[$j]] = $data[$k]['fk_suject_id'];
                        $examssub[$subid[$i]] = $data[$k]['fk_exam_id'];
                        $maxmarksexams[$examid[$j]] = $data[$k]['q_count'];
                        if($tcount==0)
                        {
                            $count++;
                        }
                    }
                    if($data[$k]['fk_exam_id'] == $examid[$j])
                    {
                        $tcount++;
                    }
                    if($k == sizeof($data)-1)
                    {
                        $indsubexamcount[$subid[$i]] = $count;
                        $stdntsubexamcount[$examid[$j]] = $tcount;
                    }
                }
            }
        }
        for($i=0; $i<sizeof($no); $i++)
        {
            $count = 0;
            for($j=0; $j<sizeof($subid); $j++)
            {
                $tcount = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($data[$k]['no'] == $no[$i] && 
                        $data[$k]['fk_suject_id'] == $subid[$j])
                    {
                        if(isset($stdntsubemarks[$no[$i]][$subid[$j]]))
                        {
                            $stdntsubemarks[$no[$i]][$subid[$j]] = (int) $stdntsubemarks[$no[$i]][$subid[$j]]+(int) $data[$k]['marks'];
                            $stdntsubemaxmarks[$no[$i]][$subid[$j]] = (int) $stdntsubemaxmarks[$no[$i]][$subid[$j]]+(int) $data[$k]['q_count'];
                        }
                        else
                        {
                            $stdntsubemarks[$no[$i]][$subid[$j]] = $data[$k]['marks'];
                            $stdntsubemaxmarks[$no[$i]][$subid[$j]] = $data[$k]['q_count'];
                        }
                        $tcount++;
                        $stdntsubecount[$no[$i]][$subid[$j]] = $tcount;
                    }
                    if(isset($stdntsubemarks[$no[$i]][$subid[$j]]) && 
                        $k == sizeof($data)-1)
                    {
                        $stdntsubemarkspercentage[$no[$i]][$subid[$j]] = round(((int) $stdntsubemarks[$no[$i]][$subid[$j]]/(int)  $stdntsubemaxmarks[$no[$i]][$subid[$j]])*100);
                    }
                }
            }
        }
        $f ='';
        $g = 0;
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($year); $c++)
                {
                    for($d=0; $d<sizeof($sem); $d++)
                    {
                        $eams =array();
                        $count = 0;
                        for($e=0; $e<sizeof($data); $e++)
                        {
                            if($data[$e]['fk_course_id'] == $course[$a] && 
                            $data[$e]['fk_dept_id'] == $dept[$b] && 
                            $data[$e]['year'] == $year[$c] && 
                            $data[$e]['sem'] == $sem[$d])
                            {
                                $count++;
                                $eams[] =  $data[$e]['fk_exam_id'];
                            }
                            if($e == sizeof($data)-1 && $count>0)
                            {
                                $examsids = array_values(array_unique($eams));
                                sort($examsids);
                                $texams = sizeof($examsids);
                                $g = $g+$texams;
                                $ydata[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]] = $count;
                                $indyeardata = Homem::getdata("SELECT um.id, um.name, um.fk_course_id, um.fk_dept_id, sd.year, sd.sem, qet.fk_sub_id, qet.e_id FROM user_master um JOIN quiz_exam_paper qep ON qep.fk_stdnt_id=um.id JOIN quiz_examtt qet ON qet.e_id=qep.fk_qett_id JOIN subject_data sd ON qet.fk_sub_id=sd.sub_id WHERE um.fk_course_id='$course[$a]' AND um.fk_dept_id='$dept[$b]' AND sd.year='$year[$c]' AND sd.sem='$sem[$d]' AND qet.completed='1' AND qep.completed='1'");
                                $indy =array();
                                for($i=0; $i<sizeof($indyeardata); $i++)
                                {
                                    $indy[] = $indyeardata[$i]['e_id'];
                                }
                                $indyexamsids = array_values(array_unique($indy));
                                sort($indyexamsids);
                                $indtexams = sizeof($indyexamsids);
                                $ydatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]] = sizeof($indyeardata);
                                $stddatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]] = round(sizeof($indyeardata)/(int)$indtexams);
                                $f .= '<tr><td>'.static::course($course[$a]).'</td>
                                        <td>'.static::dept($dept[$b]).'</td>
                                        <td>'.($year[$c]).'</td>
                                        <td>'.($sem[$d]).'</td>
                                        <td>'.round(sizeof($indyeardata)/(int)$indtexams).'</td>
                                        <td>'.$texams.'</td><td>'.$indtexams.'</td>
                                        <td>'.$ydata[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]].'</td>
                                        <td>'.$ydatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]].'</td>
                                        <td>'.round(($ydata[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]]/$ydatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]])*100).'</td>
                                        </tr>';
                            }
                        }
                    }
                }
            }
        }
        $h = '';
        for($i=0; $i<sizeof($subid); $i++)
        {
            $count = 0;
            $less50 = 0;
            $greater50 =0 ;
            for($j=0; $j<sizeof($examid); $j++)
            {
                $tcount = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($data[$k]['fk_suject_id'] == $subid[$i] && 
                        $data[$k]['fk_exam_id'] == $examid[$j])
                    {
                        $per = round(((int)$data[$k]['marks']/(int)$data[$k]['q_count'])*100);
                        if($per<50)
                        {
                            $less50++;
                        }
                        else
                        {
                            $greater50++;
                        }
                        $count++;
                    }
                }
            }
            $subtcount[$subid[$i]] = $count;
            $subless50[$subid[$i]] = $less50;
            $subgreater50[$subid[$i]] = $greater50;
        }
        for($a=0; $a<sizeof($course); $a++)
        {
            for($b=0; $b<sizeof($dept); $b++)
            {
                for($c=0; $c<sizeof($year); $c++)
                {
                    for($d=0; $d<sizeof($sem); $d++)
                    {
                        for($g=0; $g<sizeof($subid); $g++)
                        {
                            $subexid = array();
                            for($e=0; $e<sizeof($data); $e++)
                            {
                                if($data[$e]['fk_course_id'] == $course[$a] && 
                                $data[$e]['fk_dept_id'] == $dept[$b] && 
                                $data[$e]['year'] == $year[$c] && 
                                $data[$e]['sem'] == $sem[$d] && 
                                $data[$e]['fk_suject_id'] == $subid[$g])
                                {
                                    $subexid[] = $data[$e]['fk_exam_id'];
                                }
                                if($e==sizeof($data)-1 && sizeof($subexid)>0)
                                {
                                    $subexid1 = array_values(array_unique($subexid));
                                    sort($subexid1);
                                    $h .= '<tr>
                                    <td>'.static::course($course[$a]).'</td>
                                    <td>'.static::dept($dept[$b]).'</td>
                                    <td>'.$year[$c].'</td><td>'.$sem[$d].'</td>
                                    <td>'.$stddatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]].'</td>
                                    <td><a href="/Exams/aindsubexamcount?subid='.$subid[$g].'&total='.$stddatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]].'">'.$subname[$subid[$g]].'</a></td>
                                    <td>'.sizeof($subexid1).'</td>
                                    <td>'.round(((int)$subtcount[$subid[$g]]/((int)$stddatacount[$course[$a]][$dept[$b]][$year[$c]][$sem[$d]]*(int)sizeof($subexid1)))*100).'</td>
                                    <td>'.$subtcount[$subid[$g]].'</td>
                                    <td>'.$subless50[$subid[$g]].'</td>
                                    <td>'.$subgreater50[$subid[$g]].'</td>
                                    </tr>';
                                }
                            }
                        }
                    }
                }
            }
        }
        $m = '';
        $m .= '<div class="table-responsive" id="exporttable2"><table class="table" border="1px">';
        $m .= '<thead><tr><th>Course</th><th>Department</th>
        <th>Year</th><th>Sem</th><th>Strength</th><th>Subject Exams</th><th>Number of Exams</th><th>Attendance %</th>
        <th>Attempted</th><th>Lessthan 50%</th><th>Graterthan 50%</th></tr></thead>';
        $m .= '<tbody>'.$h.'</tbody>';
        $m .= '</table></div>';
        $a = '<div class="table-responsive" id="exporttable1"><table class="table" border="1px">';
        $a .= '<thead>
        <tr><th colspan="10">OVER ALL CONSOLIDATED REPORT</th></tr>
        <tr>
        <th>Course</th><th>Department</th>
        <th>Year</th><th>Sem</th>
        <th>Student Count</th><th>Exams Evaluated</th><th>Exams Conducted</th>
        <th>Appeared</th><th>Created</th><th>Percentage</th>
        </tr></thead>';
        $a .= '<tbody>'.$f;
        $a .= '</tbody>';
        $a .= '</table></div>';
        echo static::css();
        echo '<body>';
        echo $_SESSION['menu'];
        echo '
            <div class="clearfix"></div>
            <form action="" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-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">OVER ALL REPORTS</h4>
                                        </header>                  
                                    </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">
                        '.$a.'
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                    <div class="row">
                    <div class="col-lg-1"></div>
                    <div class="col-lg-10">
                        <button class="btn btn-primary" onclick="exportTableToExcel(`exporttable1`, `results-data`)">Export</button>
                    </div>
                    <div class="col-lg-1"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                        '.$m.'
                        </div>
                        <div class="col-lg-1">
                        </div>
                    </div>
                    <div class="row">
                    <div class="col-lg-1"></div>
                    <div class="col-lg-10">
                        <button class="btn btn-primary" onclick="exportTableToExcel(`exporttable2`, `results-data`)">Export</button>
                    </div>
                    <div class="col-lg-1"></div>
                    </div>
                </div>
            </form>
            ';
        echo '</body>';
        echo static::script();
        echo '
        <script>
        </script>
        ';
        if(isset($_GET['status']))
        {
            if($_GET['status'] == 1)
            {
                echo '<script>swal("", "Inserted Successfully", "success");</script>';
            }
            else if($_GET['status'] == 2)
            {
                echo '<script>swal("", "Updated Successfully", "success");</script>';
            }
            else
            {
                echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
            }
        }
        }
    }
    public static function aindsubexamcount()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
            $f ='';
            $data = Homem::getdata("SELECT um.id, um.no, um.name, qea.fk_exam_id, qet.e_id, qet.q_count, qea.marks, qet.fk_sub_id, sd.subname, qet.ttime  FROM user_master um JOIN quiz_exam_answers qea ON qea.fk_student_id=um.id JOIN subject_data sd ON sd.sub_id=qea.fk_suject_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id WHERE qea.completed='1' AND qea.marks!='' AND qea.fk_suject_id='$_GET[subid]'");
            $exam_id = array();
            $sub_name = array();
            foreach ($data as $h) {
                $exam_id[] = $h['e_id'];
                $sub_name[] = $h['subname'];
            }
            $examid = array_values(array_unique($exam_id));
            sort($examid);
            $subname = array_values(array_unique($sub_name));
            sort($subname);
            for($i=0; $i<sizeof($examid); $i++)
            {
                $count = 0;
                $less50 = 0;
                $less70 = 0;
                $less100 = 0;
                for($j=0; $j<sizeof($data); $j++)
                {
                    if($data[$j]['e_id'] == $examid[$i])
                    {
                        $per = round(((int)$data[$j]['marks']/(int)$data[$j]['q_count'])*100);
                        if($per<50)
                        {
                            $less50++;
                        }
                        else if($per>=50 && $per<70)
                        {
                            $less70++;
                        }
                        else
                        {
                            $less100++;
                        }
                        $maxmarks[$examid[$i]] = $data[$j]['q_count'];
                        $ttime[$examid[$i]] = $data[$j]['ttime'];
                        $count++;
                    }
                }
                $examdata[$i]['less50'] = $less50;
                $examdata[$i]['less70'] = $less70;
                $examdata[$i]['less100'] = $less100;
                $examdata[$i]['count'] = $count;
                $j = $i+1;
                $f .= '<tr>
                        <td>'.$j.'</td>
                        <td>'.$subname[0].'</td>
                        <td>'.$maxmarks[$examid[$i]].'</td>
                        <td>'.$_GET['total'].'</td>
                        <td>'.$examdata[$i]['count'].'</td>
                        <td>'.$examdata[$i]['less50'].'</td>
                        <td>'.$examdata[$i]['less70'].'</td>
                        <td>'.$examdata[$i]['less100'].'</td>
                        <td>'.$ttime[$examid[$i]].'</td>
                        <td><a href="/exams/aindexamreprt?examid='.$examid[$i].'">View</a></td>
                        </tr>';
            }
            $m = '';
            
            $a = '<div class="table-responsive" id="exporttable1"><table class="table" border="1px">';
            $a .= '<thead>
            <tr><th>S. No.</th>
            <th>Subject Name</th><th>Max Marks</th><th>Class Strength</th><th>Attended</th><th>Lessthan 50%</th>
            <th>Between 50 - 70%</th><th>Greaterthan 70%</th><th>Date of Completion</th>
            <th>View</th></tr></thead>';
            $a .= '<tbody>'.$f;
            $a .= '</tbody>';
            $a .= '</table></div>';
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-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">OVER ALL INDIVIDUAL SUBJECT REPORTS</h4>
                                            </header>                  
                                        </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">
                            '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                        <div class="row">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                            <button class="btn btn-primary" onclick="exportTableToExcel(`exporttable1`, `results-data`)">Export</button>
                        </div>
                        <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function aindexamreprt()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
            $f ='';
            $data = Homem::getdata("SELECT qea.fk_paper_id, um.id, um.no, um.name, qea.fk_exam_id, qet.e_id, qet.q_count, qea.marks, qet.fk_sub_id, sd.subname, qet.ttime  FROM user_master um JOIN quiz_exam_answers qea ON qea.fk_student_id=um.id JOIN subject_data sd ON sd.sub_id=qea.fk_suject_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id WHERE qea.completed='1' AND qea.marks!='' AND qet.e_id='$_GET[examid]' ORDER BY um.no ASC");
            $exam_id = array();
            $sub_name = array();
            foreach ($data as $h) {
                $exam_id[] = $h['e_id'];
                $sub_name[] = $h['subname'];
            }
            $examid = array_values(array_unique($exam_id));
            sort($examid);
            $subname = array_values(array_unique($sub_name));
            sort($subname);
            for($i=0; $i<sizeof($examid); $i++)
            {
                $count = 0;
                $less50 = 0;
                $less70 = 0;
                $less100 = 0;
                for($j=0; $j<sizeof($data); $j++)
                {
                    if($data[$j]['e_id'] == $examid[$i])
                    {
                        $per = round(((int)$data[$j]['marks']/(int)$data[$j]['q_count'])*100);
                        if($per<50)
                        {
                            $less50++;
                        }
                        else if($per>=50 && $per<70)
                        {
                            $less70++;
                        }
                        else
                        {
                            $less100++;
                        }
                        $maxmarks[$examid[$i]] = $data[$j]['q_count'];
                        $ttime[$examid[$i]] = $data[$j]['ttime'];
                        $count++;
                    }
                }
                $examdata[$i]['less50'] = $less50;
                $examdata[$i]['less70'] = $less70;
                $examdata[$i]['less100'] = $less100;
                $examdata[$i]['count'] = $count;
                $j = $i+1;
                $f .= '<tr>
                        <td>'.$j.'</td>
                        <td>'.$subname[0].'</td>
                        <td>'.$maxmarks[$examid[$i]].'</td>
                        <td>'.$_GET['examid'].'</td>
                        <td>'.$examdata[$i]['count'].'</td>
                        <td>'.$examdata[$i]['less50'].'</td>
                        <td>'.$examdata[$i]['less70'].'</td>
                        <td>'.$examdata[$i]['less100'].'</td>
                        <td>'.$ttime[$examid[$i]].'</td>
                        <td><a href="/exam/aindexamreprt?examid='.$examid[$i].'">View</a></td>
                        </tr>';
            }
            $m = '';
            for($i=0; $i<sizeof($data); $i++)
            {
                $j=$i+1;
                $per = round(((int)$data[$i]['marks']/(int)$data[$i]['q_count'])*100);
                $m .= '<tr><td>'.$j.'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i]['marks'].'</td><td>'.$per.'</td>
                <td><a href="/exams/aindsubindstexpap?paperid='.$data[$i]['fk_paper_id'].'">'.'View'.'</a></td>
                </tr>';
            }
            $n = '<div class="table-responsive" id="exporttable2"><table class="table" border="1px">
            <thead><tr><th>S. No.</th><th>Hallticket No.</th><th>Name</th><th>Marks</th><th>Percentage</th><th>View</th></tr></thead>
            <tbody>'.$m.'</tbody></table></div>';
            $a = '<div class="table-responsive" id="exporttable1"><table class="table" border="1px">';
            $a .= '<thead>
            <tr><th>S. No.</th>
            <th>Subject Name</th><th>Max Marks</th><th>Class Strength</th><th>Attended</th><th>Lessthan 50%</th>
            <th>Between 50 - 70%</th><th>Greaterthan 70%</th><th>Date of Completion</th>
            <th>View</th></tr></thead>';
            $a .= '<tbody>'.$f;
            $a .= '</tbody>';
            $a .= '</table></div>';
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-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">OVER ALL INDIVIDUAL SUBJECT SINGLE EXAM REPORT</h4>
                                            </header>                  
                                        </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">
                            '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                        <div class="row">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                            <button class="btn btn-primary" onclick="exportTableToExcel(`exporttable1`, `results-data`)">Export</button>
                        </div>
                        <div class="col-lg-1"></div>
                        </div>
                    <div class="row">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                        '.$n.'
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                    <div class="row">
                    <div class="col-lg-1"></div>
                    <div class="col-lg-10">
                        <button class="btn btn-primary" onclick="exportTableToExcel(`exporttable2`, `results-data`)">Export</button>
                    </div>
                    <div class="col-lg-1"></div>
                    </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function aindsubindstexpap()
    {
        $a ='';
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            if(isset($_GET['paperid']))
            {
                $data = Homem::getdata("SELECT qea.qa_id, qep.q_shuffle, qea.answers, qep.ep_id, qep.q_id, qep.q_ans, qep.q_type, qea.marks, qea.fk_student_id, um.id, um.no, um.name FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN user_master um ON um.id=qea.fk_student_id WHERE qea.fk_exam_id=qep.fk_qett_id AND qep.fk_stdnt_id=qea.fk_student_id AND qep.ep_id='$_GET[paperid]'");
                if(sizeof($data) == 1)
                {
                    $qus = json_decode($data['0']['q_id'], true);
                    $qtype = json_decode($data['0']['q_type'], true);
                    $qans = json_decode($data['0']['answers'], true);
                    $qcrct = json_decode($data['0']['q_ans'], true);
                    $qshuffle = json_decode($data['0']['q_shuffle'], true);
                    if(is_array($qans))
                    {
                        if(sizeof($qcrct) != sizeof($qans))
                        {
                            $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                        }
                    }
                    else
                    {
                        $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                    }
                    $que = json_decode(static::anspaperquestionquery($qus), true);
                    $marks = static::answercheckindqpaper($data[0]['answers'], $data[0]['q_ans'], $data[0]['q_type']);
                    for($i=0; $i<sizeof($qus); $i++)
                    {
                        for($j=0; $j<sizeof($que); $j++)
                        {
                            if($qus[$i] == $que[$j]['id'])
                            {
                                if($marks[$i] == 1)
                                {
                                    $ans = 'correct';
                                }
                                else
                                {
                                    $ans = 'wrong';
                                }
                                $a .= '
                                    <div class="shadow-lg p-3 mb-5 bg-white rounded">
                                        <div class="row">
                                            <div class="col-lg-1 col-centered">
                                                <div style="width: 25px; height: 25px;"><center><img src="/hindu/eimages/'.$ans.'.png" height="25px" width="25px"></center></div>
                                            </div>
                                            <div class="col-lg-10">
                                                '.$que[$j]['q_text'].'
                                            </div>
                                            <div class="col-lg-1">
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-1">
                                            </div>
                                            <div class="col-lg-11">
                                                <div class="row">
                                                    '.static::examanswerindpaper($qtype[$i], $qshuffle[$i], $que[$j]['q_answers'], $qans[$i], $qcrct[$i]).'
                                                </div>
                                            </div>
                                        </div>
                                    </div>';
                            }
                        }
                    }
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-3"></div>
                            <div class="col-lg-6">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Individual Student Question Paper</h4>
                                            </header>
                                            <div class="content-body"> 
                                            </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function getsubjectexamdetails()
            {
                var date= $("#subject").val();
                $.ajax({
                    type: "POST",
                    data : {subject: date},
                    url: "/Exams/getsubjectexamdetails",
                    success: function(d){
                        $("#examdetails").html(d);
                    }
                });
            }
            </script>';
        }
    }
    private static function quesshuffle($a)
    {
        if(isset($a))
        {
            for($i=0; $i<sizeof($a); $i++)
            {
                $j = rand(0, sizeof($a)-1);
                if(!isset($b[$j]))
                {
                    $b[$j] = $a[$i];
                }
                else
                {
                    $i--;
                }
            }
            ksort($b);
            return $b;
        }
    }
    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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $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`='2' OR `user_role`='7' OR `user_role`='8') AND `org_id`='$_SESSION[org_id]') a JOIN degree_dept_master ddm ON a.fk_dept_id=ddm.id"), 'id', 'name');
            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">
                            </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>';
                }
            }
        }
    }
    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>';
                }
            }
        }
    }
    public static function mergesubjectdata()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $data = Inputs::optionsdb(Homem::getdata("SELECT sd.sub_id, sd.subname FROM subject_merge sm JOIN subject_data sd ON sm.fk_subject_id1=sd.sub_id JOIN subject_faculty sf ON sf.fk_sub_id=sm.fk_subject_id1 WHERE sf.fk_user_id=sm.fk_user_id AND sf.fk_user_id='$_SESSION[user_id]'"), 'sub_id', 'subname');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/savemergesubjectdata" 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">MERGE TWO SUBJECTS DATA</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="fromsubject" name="fromsubject" class="form-control" onchange="getsecondsubdetails()" required>
                                                            <option value="">From 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="tosubject" name="tosubject" class="form-control" required>
                                                                <option value="">To Subject</option>
                                                                
                                                            </select>
                                                        </div>
                                                    </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();
            echo '
            <script>
                function getsecondsubdetails()
                {
                    var subject = document.getElementById("fromsubject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsecondsubdetails",
                        success: function(d){
                            $("#tosubject").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 savemergesubjectdata()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if(isset($_POST['fromsubject']))
            {
                // Syllabu Merging start
                    $fdata = Homem::getdata("SELECT * FROM `subject_syllabus` WHERE `fk_sub_id`='$_POST[fromsubject]' AND `add_by`='$_SESSION[user_id]'");
                    $tdata = Homem::getdata("SELECT * FROM `subject_syllabus` WHERE `fk_sub_id`='$_POST[tosubject]' AND `add_by`='$_SESSION[user_id]'");
                    if(sizeof($fdata) > 0 && sizeof($tdata)==0)
                    {
                        for($i=0; $i<sizeof($fdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapt = $fdata[$i]['chapt_no'];
                            $chaptname = $fdata[$i]['chapt_name'];
                            $syllabus = $fdata[$i]['chapt_syllabus'];
                            $topics = $fdata[$i]['chapt_topics'];
                            $theory = $fdata[$i]['theory'];
                            $derivation = $fdata[$i]['derivation'];
                            $problems = $fdata[$i]['problems'];
                            $hours = $fdata[$i]['noofhours'];
                            $status = $fdata[$i]['status'];
                            $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[tosubject]', '$chapt', '$chaptname', '$syllabus', '$topics', '$theory', '$derivation', '$problems', '$hours', '$_SESSION[user_id]', '$date', '$status')";
                            Homem::insert($query);
                        }
                    }
                    if(sizeof($fdata) == 0 && sizeof($tdata)>0)
                    {
                        for($i=0; $i<sizeof($tdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapt = $tdata[$i]['chapt_no'];
                            $chaptname = $tdata[$i]['chapt_name'];
                            $syllabus = $tdata[$i]['chapt_syllabus'];
                            $topics = $tdata[$i]['chapt_topics'];
                            $theory = $tdata[$i]['theory'];
                            $derivation = $tdata[$i]['derivation'];
                            $problems = $tdata[$i]['problems'];
                            $hours = $tdata[$i]['noofhours'];
                            $status = $tdata[$i]['status'];
                            $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[fromsubject]', '$chapt', '$chaptname', '$syllabus', '$topics', '$theory', '$derivation', '$problems', '$hours', '$_SESSION[user_id]', '$date', '$status')";
                            Homem::insert($query);
                        }
                    }
                    if(sizeof($fdata) > 0 && sizeof($tdata)>0 && sizeof($fdata)>sizeof($tdata))
                    {
                        for($i=0; $i<sizeof($fdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapt = $fdata[$i]['chapt_no'];
                            $chaptname = $fdata[$i]['chapt_name'];
                            $syllabus = $fdata[$i]['chapt_syllabus'];
                            $topics = $fdata[$i]['chapt_topics'];
                            $theory = $fdata[$i]['theory'];
                            $derivation = $fdata[$i]['derivation'];
                            $problems = $fdata[$i]['problems'];
                            $hours = $fdata[$i]['noofhours'];
                            $status = $fdata[$i]['status'];
                            $count = 0;
                            for($j=0; $j<sizeof($tdata); $j++)
                            {
                                if($fdata[$i]['chapt_no']==$tdata[$j]['chapt_no'] && $fdata[$i]['status']==$tdata[$j]['status'])
                                {
                                    $count++;
                                }
                                if($count == 0 && $j==sizeof($tdata)-1)
                                {   
                                    $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[tosubject]', '$chapt', '$chaptname', '$syllabus', '$topics', '$theory', '$derivation', '$problems', '$hours', '$_SESSION[user_id]', '$date', '$status')";
                                    Homem::insert($query);
                                }
                            }
                        }
                    }
                    if(sizeof($fdata) > 0 && sizeof($tdata)>0 && sizeof($tdata)>sizeof($fdata))
                    {
                        for($i=0; $i<sizeof($tdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapt = $tdata[$i]['chapt_no'];
                            $chaptname = $tdata[$i]['chapt_name'];
                            $syllabus = $tdata[$i]['chapt_syllabus'];
                            $topics = $tdata[$i]['chapt_topics'];
                            $theory = $tdata[$i]['theory'];
                            $derivation = $tdata[$i]['derivation'];
                            $problems = $tdata[$i]['problems'];
                            $hours = $tdata[$i]['noofhours'];
                            $status = $tdata[$i]['status'];
                            $count = 0;
                            for($j=0; $j<sizeof($fdata); $j++)
                            {
                                if($fdata[$j]['chapt_no']==$tdata[$i]['chapt_no'] && $fdata[$j]['status']==$tdata[$i]['status'])
                                {
                                    $count++;
                                }
                                if($count == 0 && $j==sizeof($fdata)-1)
                                {   
                                    $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[fromsubject]', '$chapt', '$chaptname', '$syllabus', '$topics', '$theory', '$derivation', '$problems', '$hours', '$_SESSION[user_id]', '$date', '$status')";
                                    Homem::insert($query);
                                }
                            }
                        }
                    }
                // Syllabus Merging Completed
                // Questions Merging Started
                    $fdata = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[fromsubject]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
                    $tdata = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[tosubject]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
                    if(sizeof($fdata) > 0 && sizeof($tdata)==0)
                    {
                        for($i=0; $i<sizeof($fdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapter = $fdata[$i]['chapter'];
                            $topic = $fdata[$i]['topic'];
                            $q_div = $fdata[$i]['q_div'];
                            $q_type = $fdata[$i]['q_type'];
                            $q_no = $fdata[$i]['q_no'];
                            $q_text = $fdata[$i]['q_text'];
                            $q_options = $fdata[$i]['q_options'];
                            $q_answers = $fdata[$i]['q_answers'];
                            $q_correct = $fdata[$i]['q_correct'];
                            $q_tough = $fdata[$i]['q_tough'];
                            $exp = $fdata[$i]['exp'];
                            $status = $fdata[$i]['status'];
                            $q_lock = $fdata[$i]['q_lock'];
                            $query = "INSERT INTO `quiz_question_master` (`id`, `fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                                        (NULL, '$_POST[tosubject]', '$chapter', '$topic', '$q_div', '$q_type', '$q_no', '$q_text', '$q_options', '$q_answers', '$q_correct', '$q_tough', '$exp', '$_SESSION[user_id]', '$date', '$status', '$q_lock')";
                            Homem::insert($query);
                        }
                    }
                    if(sizeof($fdata) == 0 && sizeof($tdata)>0)
                    {
                        for($i=0; $i<sizeof($tdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapter = $tdata[$i]['chapter'];
                            $topic = $tdata[$i]['topic'];
                            $q_div = $tdata[$i]['q_div'];
                            $q_type = $tdata[$i]['q_type'];
                            $q_no = $tdata[$i]['q_no'];
                            $q_text = $tdata[$i]['q_text'];
                            $q_options = $tdata[$i]['q_options'];
                            $q_answers = $tdata[$i]['q_answers'];
                            $q_correct = $tdata[$i]['q_correct'];
                            $q_tough = $tdata[$i]['q_tough'];
                            $exp = $tdata[$i]['exp'];
                            $status = $tdata[$i]['status'];
                            $q_lock = $tdata[$i]['q_lock'];
                            $query = "INSERT INTO `quiz_question_master` (`id`, `fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                                        (NULL, '$_POST[fromsubject]', '$chapter', '$topic', '$q_div', '$q_type', '$q_no', '$q_text', '$q_options', '$q_answers', '$q_correct', '$q_tough', '$exp', '$_SESSION[user_id]', '$date', '$status', '$q_lock')";
                            Homem::insert($query);
                        }
                    }
                    if(sizeof($fdata) > 0 && sizeof($tdata)>0 && sizeof($fdata)>sizeof($tdata))
                    {
                        for($i=0; $i<sizeof($fdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapter = $fdata[$i]['chapter'];
                            $topic = $fdata[$i]['topic'];
                            $q_div = $fdata[$i]['q_div'];
                            $q_type = $fdata[$i]['q_type'];
                            $q_no = $fdata[$i]['q_no'];
                            $q_text = $fdata[$i]['q_text'];
                            $q_options = $fdata[$i]['q_options'];
                            $q_answers = $fdata[$i]['q_answers'];
                            $q_correct = $fdata[$i]['q_correct'];
                            $q_tough = $fdata[$i]['q_tough'];
                            $exp = $fdata[$i]['exp'];
                            $status = $fdata[$i]['status'];
                            $q_lock = $fdata[$i]['q_lock'];
                            $count = 0;
                            for($j=0; $j<sizeof($tdata); $j++)
                            {
                                if($fdata[$i]['chapter']==$tdata[$j]['chapter'] && 
                                    $fdata[$i]['topic']==$tdata[$j]['topic'] && 
                                    $fdata[$i]['q_div']==$tdata[$j]['q_div'] && 
                                    $fdata[$i]['q_type']==$tdata[$j]['q_type'] && 
                                    $fdata[$i]['q_text']==$tdata[$j]['q_text'] && 
                                    $fdata[$i]['q_answers']==$tdata[$j]['q_answers'] && 
                                    $fdata[$i]['q_correct']==$tdata[$j]['q_correct'] && 
                                    $fdata[$i]['q_tough']==$tdata[$j]['q_tough'] && 
                                    $fdata[$i]['exp']==$tdata[$j]['exp'])
                                {
                                    $count++;
                                    echo $count;
                                }
                                if($count == 0 && $j==sizeof($tdata)-1)
                                {   
                                    $query = "INSERT INTO `quiz_question_master` (`id`, `fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                                        (NULL, '$_POST[tosubject]', '$chapter', '$topic', '$q_div', '$q_type', '$q_no', '$q_text', '$q_options', '$q_answers', '$q_correct', '$q_tough', '$exp', '$_SESSION[user_id]', '$date', '$status', '$q_lock')";
                                    Homem::insert($query);
                                }
                            }
                        }
                    }
                    if(sizeof($fdata) > 0 && sizeof($tdata)>0 && sizeof($tdata)>sizeof($fdata))
                    {
                        for($i=0; $i<sizeof($tdata); $i++)
                        {
                            $date = date('Y-m-d');
                            $chapter = $tdata[$i]['chapter'];
                            $topic = $tdata[$i]['topic'];
                            $q_div = $tdata[$i]['q_div'];
                            $q_type = $tdata[$i]['q_type'];
                            $q_no = $tdata[$i]['q_no'];
                            $q_text = $tdata[$i]['q_text'];
                            $q_options = $tdata[$i]['q_options'];
                            $q_answers = $tdata[$i]['q_answers'];
                            $q_correct = $tdata[$i]['q_correct'];
                            $q_tough = $tdata[$i]['q_tough'];
                            $exp = $tdata[$i]['exp'];
                            $status = $tdata[$i]['status'];
                            $q_lock = $tdata[$i]['q_lock'];
                            $count = 0;
                            for($j=0; $j<sizeof($fdata); $j++)
                            {
                                if($fdata[$j]['chapter']==$tdata[$i]['chapter'] && 
                                    $fdata[$j]['topic']==$tdata[$i]['topic'] && 
                                    $fdata[$j]['q_div']==$tdata[$i]['q_div'] && 
                                    $fdata[$j]['q_type']==$tdata[$i]['q_type'] && 
                                    $fdata[$j]['q_text']==$tdata[$i]['q_text'] && 
                                    $fdata[$j]['q_answers']==$tdata[$i]['q_answers'] && 
                                    $fdata[$j]['q_correct']==$tdata[$i]['q_correct'] && 
                                    $fdata[$j]['q_tough']==$tdata[$i]['q_tough'] && 
                                    $fdata[$j]['exp']==$tdata[$i]['exp'])
                                {
                                    $count++;
                                }
                                if($count == 0 && $j==sizeof($fdata)-1)
                                {   
                                    $query = "INSERT INTO `quiz_question_master` (`id`, `fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                                        (NULL, '$_POST[fromsubject]', '$chapter', '$topic', '$q_div', '$q_type', '$q_no', '$q_text', '$q_options', '$q_answers', '$q_correct', '$q_tough', '$exp', '$_SESSION[user_id]', '$date', '$status', '$q_lock')";
                                    Homem::insert($query);
                                }
                            }
                        }
                    }
                // Questions Merging Completed
                echo '<script>window.location = "/Exams/mergesubjectdata?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/mergesubjectdata?status=0";</script>';
            }
        }
    }
    public static function getsecondsubdetails()
    {
        if(isset($_POST['subject']))
        {
            $data = Homem::getdata("SELECT sd.sub_id, sd.subname FROM subject_merge sm JOIN subject_data sd ON sm.fk_subject_id2=sd.sub_id JOIN subject_faculty sf ON sf.fk_sub_id=sm.fk_subject_id2 WHERE sf.fk_user_id=sm.fk_user_id AND sf.fk_user_id='$_SESSION[user_id]' AND sm.fk_subject_id1='$_POST[subject]'");
            echo '<option value="">To Subject</option>';
            // echo '<option value="">test</option>';
            for($i=0; $i<sizeof($data); $i++)
            {
                echo '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].'</option>';
            }
        }
    }
    public static function addmcqquestions()
    { 
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/saveaddmcqquestions" 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">ADD MCQ QUESTIONS</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">
                                                        <div class="form-group">                                                                                
                                                            <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                                <option value="">Select Chapter / Unit Number</option>
                                                            </select>
                                                        </div>
                                                    </div>                               
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="topic" name="topic" class="form-control" required>
                                                                <option value="">Select Topic</option>
                                                            </select>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="qdiv" name="qdiv" class="form-control" required>
                                                                <option value="">Select Question Divsion</option>
                                                                '.$qdiv.'
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="question" id="question" class="form-control" placeholder="Question" required></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row"> 
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="a[0]" id="a0" placeholder="First Answer" class="form-control" required />
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="a[1]" id="a1" placeholder="Second Answer" class="form-control" required />
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row"> 
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="a[2]" id="a2" placeholder="Third Answer" class="form-control" required />
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="a[3]" id="a3" placeholder="Fourth Answer" class="form-control" required />
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="answer" name="answer" class="form-control" required>
                                                                <option value="">Select Correct Answer</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                                                <option value="3">3</option>
                                                                <option value="4">4</option>
                                                            </select>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="tough" name="tough" class="form-control" required>
                                                                <option value="">Select Question Tough Level</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                                                <option value="3">3</option>
                                                                <option value="4">4</option>
                                                                <option value="5">5</option>
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="exp" id="exp" class="form-control" placeholder="Explanation"></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                
                                                            <input type="hidden" name="qtype" id="qtype" value="1" class="form-control" placeholder="MCQ">                            
                                                            <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>
                    </form>';
                }
                else
                {
                    echo '<div class="clearfix"></div>';
                }
               
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </script>  
            ';
            if(isset($_GET['editid']))
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_GET[editid]' AND `q_type`='1' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $ans = unserialize($data[0]['q_answers']);
                    $crct = explode("_", $data[0]['q_correct']);
                    echo '
                        <script>
                            $("#subject").val("'.$data[0]['fk_sub_id'].'");
                            getsubjectchapters();
                            setTimeout(function()
                            { 
                                $("#chapter").val("'.$data[0]['chapter'].'");
                                getsubchaptopics();
                            }, 300);
                            setTimeout(function()
                            { 
                                $("#topic").val("'.$data[0]['topic'].'");
                            }, 500);
                            $("#qdiv").val("'.$data[0]['q_div'].'");
                            $("#question").val("'.$data[0]['q_text'].'");
                            $("#a0").val("'.$ans[0].'");
                            $("#a1").val("'.$ans[1].'");
                            $("#a2").val("'.$ans[2].'");
                            $("#a3").val("'.$ans[3].'");
                            $("#answer").val("'.$crct[1].'");
                            $("#tough").val("'.$data[0]['q_tough'].'");
                            $("#exp").val("'.$data[0]['exp'].'");
                            $("#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 saveaddmcqquestions()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $ans = serialize($_POST['a']);
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '$ans', '', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $option = array();
                    for($i=1; $i <= 4; $i++)
                    {
                        $options[$i-1] = '<input type="radio" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="'.$qid.'_'.$i.'">';
                    }
                    $options1 = serialize($options);
                    $qcorrect = $qid.'_'.$_POST['answer'];
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addmcqquestions?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addmcqquestions?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='1' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $option = array();
                    for($i=1; $i <= 4; $i++)
                    {
                        $options[$i-1] = '<input type="radio" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="'.$qid.'_'.$i.'">';
                    }
                    $options1 = serialize($options);
                    $qcorrect = $qid.'_'.$_POST['answer'];
                    $ans = serialize($_POST['a']);
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_answers`='$ans', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addmcqquestions?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addmcqquestions?status=0";</script>';
                }
            }
        }
    }
    public static function addfillinblanks()
    {
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/saveaddfillinblanks" 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">ADD FILL IN BLANK QUESTIONS</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">
                                                        <div class="form-group">                                                                                
                                                            <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                                <option value="">Select Chapter / Unit Number</option>
                                                            </select>
                                                        </div>
                                                    </div>                               
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="topic" name="topic" class="form-control" required>
                                                                <option value="">Select Topic</option>
                                                            </select>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="qdiv" name="qdiv" class="form-control" required>
                                                                <option value="">Select Question Divsion</option>
                                                                '.$qdiv.'
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="question" id="question" class="form-control" placeholder="Question" required></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input id="answer" name="answer" placeholder="Correct Answer" class="form-control" required>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="tough" name="tough" class="form-control" required>
                                                                <option value="">Select Question Tough Level</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                                                <option value="3">3</option>
                                                                <option value="4">4</option>
                                                                <option value="5">5</option>
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="exp" id="exp" class="form-control" placeholder="Explanation" ></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group"> 
                                                            <input type="hidden" name="qtype" id="qtype" value="2" class="form-control" placeholder="FILL">                                           
                                                            <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>
                    </form>
                    ';
                }
                else
                {
                    echo '
                    <div class="clearfix"></div>';
                }
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </script>  
            ';
            if(isset($_GET['editid']))
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_GET[editid]' AND `q_type`='2' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#subject").val("'.$data[0]['fk_sub_id'].'");
                            getsubjectchapters();
                            setTimeout(function()
                            { 
                                $("#chapter").val("'.$data[0]['chapter'].'");
                                getsubchaptopics();
                            }, 300);
                            setTimeout(function()
                            { 
                                $("#topic").val("'.$data[0]['topic'].'");
                            }, 500);
                            $("#qdiv").val("'.$data[0]['q_div'].'");
                            $("#question").val("'.$data[0]['q_text'].'");
                            $("#answer").val("'.$data[0]['q_correct'].'");
                            $("#tough").val("'.$data[0]['q_tough'].'");
                            $("#exp").val("'.$data[0]['exp'].'");
                            $("#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 saveaddfillinblanks()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '', '$_POST[answer]', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $i = 1;
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $_POST['answer'];
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addfillinblanks?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addfillinblanks?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='2' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $i = 1;
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $_POST['answer'];
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addfillinblanks?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addfillinblanks?status=0";</script>';
                }
            }
        }
    }
    public static function addinterquestions()
    {
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddinterquestions" 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">ADD INTERMEDIATE ANSWER QUESTIONS</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">
                                                    <div class="form-group">                                                                                
                                                        <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                            <option value="">Select Chapter / Unit Number</option>
                                                        </select>
                                                    </div>
                                                </div>                               
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="topic" name="topic" class="form-control" required>
                                                            <option value="">Select Topic</option>
                                                        </select>
                                                    </div>
                                                </div>      
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="qdiv" name="qdiv" class="form-control" required>
                                                            <option value="">Select Question Divsion</option>
                                                            '.$qdiv.'
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="question" id="question" class="form-control" placeholder="Question" required></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="number" id="minanswer" name="minanswer" placeholder="Min Allowable Answer" class="form-control" required>
                                                    </div>
                                                </div>    
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="number" id="maxanswer" name="maxanswer" placeholder="Max Allowable Answer" class="form-control" required>
                                                    </div>
                                                </div>    
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <select id="tough" name="tough" class="form-control" required>
                                                            <option value="">Select Question Tough Level</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                            <option value="5">5</option>
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="exp" id="exp" class="form-control" placeholder="Expalanation" required></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">
                                                        <input type="hidden" name="qtype" id="qtype" value="3" class="form-control" placeholder="MCQ">                                            
                                                        <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>
                </form>
                ';
                }
                else
                {
                    echo '<div class="clearfix"></div>';
                }
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </script>  
            ';
            if(isset($_GET['editid']))
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_GET[editid]' AND `q_type`='3' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $ans = explode("_", $data[0]['q_correct']);
                    echo '
                        <script>
                            $("#subject").val("'.$data[0]['fk_sub_id'].'");
                            getsubjectchapters();
                            setTimeout(function()
                            { 
                                $("#chapter").val("'.$data[0]['chapter'].'");
                                getsubchaptopics();
                            }, 300);
                            setTimeout(function()
                            { 
                                $("#topic").val("'.$data[0]['topic'].'");
                            }, 500);
                            $("#qdiv").val("'.$data[0]['q_div'].'");
                            $("#question").val("'.$data[0]['q_text'].'");
                            $("#minanswer").val("'.$ans[0].'");
                            $("#maxanswer").val("'.$ans[1].'");
                            $("#tough").val("'.$data[0]['q_tough'].'");
                            $("#exp").val("'.$data[0]['exp'].'");
                            $("#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 saveaddinterquestions()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $ans = $_POST['minanswer'].'_'.$_POST['maxanswer'];
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '', '$ans', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $i = 1;
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="number" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $ans;
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addinterquestions?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addinterquestions?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='3' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $ans = $_POST['minanswer'].'_'.$_POST['maxanswer'];
                    $i = 1;
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $ans;
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addinterquestions?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addinterquestions?status=0";</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 getslots()
    {
        if(isset($_POST['hours']))
        {
            echo '
                <div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr>
                                <th>Hour Number</th>
                                <th>From Time</th>
                                <th>To Time</th>
                            </tr>
                        </thead>
                        <tbody>';
            for($i=0; $i<$_POST['hours']; $i++)
            {
                $j = $i+1;
                echo '<tr>';
                    echo '<td><input type="hidden" name="hourno['.$i.']" id="hourno['.$i.']" value="'.$j.'" class="form-control">'.$j.'</td>';
                    echo '<td><input type="text" name="ftime['.$i.']" id="ftime['.$i.']" onfocus="(this.type=`time`)" onblur="(this.type=`text`)" placeholder="From Time" class="form-control"></td>';
                    echo '<td><input type="text" name="ttime['.$i.']" id="ttime['.$i.']" onfocus="(this.type=`time`)" onblur="(this.type=`text`)" placeholder="To Time" class="form-control"></td>';
                echo '</tr>';
            }
            echo '</tbody></thead>';
        }
    }
    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`='2' OR `user_role`='7' OR `user_role`='8') AND `fk_dept_id`='$_POST[fdept]' AND `org_id`='$_SESSION[org_id]'");
            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'], '', '', '');
        }
    }
    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>';
            }
        }
    }
    public static function getstudentattendaceemptydata()
    {
        if(isset($_POST['subject']))
        {
            $subdata = Homem::getdata("SELECT * FROM subject_faculty sf JOIN subject_data sd ON sd.sub_id=sf.fk_sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]'");
            $course = $subdata[0]['course'];
            $dept = $subdata[0]['dept'];
            $regulation = $subdata[0]['regulation'];
            $syear = $subdata[0]['student_year'];
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `org_id`='473' AND `fk_course_id`='$course' AND `fk_dept_id`='$dept' AND `regulation`='$regulation' AND `fromyear`='$syear' AND `user_role`='3' ORDER BY `no` ASC");
            echo '<input type="hidden" name="scount" id="scount" placeholder="Student Count" value="'.sizeof($data).'" required>';
            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'], '', '', '');
            echo '
                <div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr>
                                <th><input type="checkbox" name="allpresent" id="allpresent" onchange="setallpresent()">Preasent</th>
                                <th>Hall Ticket Number</th>
                                <th>Name</th><th>Gender</th>
                            </tr>
                        </thead>
                        <tbody>';
            for($i=0; $i<sizeof($data); $i++)
            {
                echo '<tr>';
                echo '<td>
                        <input type="hidden" name="sid['.$i.']" id="sid['.$i.']" value="'.$data[$i]['id'].'">
                        <input type="hidden" name="sno['.$i.']" id="sno['.$i.']" value="'.$data[$i]['no'].'">
                        <input type="hidden" name="attend['.$i.']" id="attend['.$i.']" value="0">
                        <input type="checkbox" name="attend['.$i.']" id="attend['.$i.']" value="1">
                        </td>
                        ';
                echo '<td>'.$data[$i]['no'].'</td>';
                echo '<td>'.$data[$i]['name'].'</td>';
                echo '<td>'.$data[$i]['gender'].'</td>';
                echo '</tr>';
            }
            echo '
                        </tbody>
                    </table>
                </div>';
        }
    }
    private static function year()
    {
        $year = date('Y')+5;
        $a = '';
        for($i=0; $i<=40; $i++)
        {
            $y = $year-$i;
            $a .= '<option value="'.$y.'">'.$y.'</option>';
        }
        return $a;
    }
    private static function getdaybydate($date)
    {
        $dates = strtotime($date);
        $date = date('l', $dates);
        return $date;
    }
    public static function datesinmonth()
    {
        $year = date('Y');
        $lyear = $year%4;
        if($lyear == 0)
        {
            $leap = 1;
        }
        else
        {
            $leap = 0;
        }
        $mdays =  static::monthdays(date('m'), $leap);
        for($i=0; $i<$mdays; $i++)
        {
            $j = $i+1;
            if($j < 10)
            {
                $date = date('Y').'-'.date('m').'-'.sprintf("%02d", $j);
                $dates[$i]['date'] = $date;
                $dates[$i]['day'] = static::getdaybydate($date);
            }
            else
            {
                $date = date('Y').'-'.date('m').'-'.$j;
                $dates[$i]['date'] = $date;
                $dates[$i]['day'] = static::getdaybydate($date);
            }
        }
        return $dates;
    }
    public static function monthdays($month, $leap)
    {
        if($month == 1)
        {
            return 31;
        }
        else if($month == 2 && $leap ==0)
        {
            return 28;
        }
        else if($month == 2 && $leap == 1)
        {
            return 29;
        }
        else if ($month == 3)
        {
            return 31;
        }
        else if ($month == 4)
        {
            return 30;
        }
        else if ($month == 5)
        {
            return 31;
        }
        else if ($month == 6)
        {
            return 30;
        }
        else if ($month == 7)
        {
            return 31;
        }
        else if ($month == 8)
        {
            return 31;
        }
        else if ($month == 9)
        {
            return 30;
        }
        else if ($month == 10)
        {
            return 31;
        }
        else if ($month == 11)
        {
            return 30;
        }
        else
        {
            return 31;
        }
    }
    public static function addmcqquestionsupload()
    {
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saddmcqquestionsupload" method="POST" enctype="multipart/form-data">
                <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">ADD MCQ QUESTIONS</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">
                                                    <div class="form-group">                                                                                
                                                        <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                            <option value="">Select Chapter / Unit Number</option>
                                                        </select>
                                                    </div>
                                                </div>                               
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="topic" name="topic" class="form-control" required>
                                                            <option value="">Select Topic</option>
                                                        </select>
                                                    </div>
                                                </div>      
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="qdiv" name="qdiv" class="form-control" required>
                                                            <option value="">Select Question Divsion</option>
                                                            '.$qdiv.'
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="question" id="question" class="form-control" placeholder="Question" ></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                    <input type="file" name="questionu" id="questionu" placeholder="First Answer" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)"/>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row"> 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="a[0]" id="a0" placeholder="First Answer" class="form-control"  />
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="file" name="u0" id="u0" placeholder="First Answer" class="form-control"   accept=".jpg, .jpeg, .png" onchange="filevalidation(this)"/>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row"> 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="a[1]" id="a1" placeholder="Second Answer" class="form-control"  />
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="file" name="u1" id="u1" placeholder="Second Answer" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row"> 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="a[2]" id="a2" placeholder="Third Answer" class="form-control"  />
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="file" name="u2" id="u2" placeholder="Third Answer" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row"> 
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="text" name="a[3]" id="a3" placeholder="Fourth Answer" class="form-control"  />
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <input type="file" name="u3" id="u3" placeholder="Fourth Answer" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="answer" name="answer" class="form-control" required>
                                                            <option value="">Select Correct Answer</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                        </select>
                                                    </div>
                                                </div>      
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="tough" name="tough" class="form-control" required>
                                                            <option value="">Select Question Tough Level</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                            <option value="5">5</option>
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="exp" id="exp" class="form-control" placeholder="Explanation" ></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                    <input type="file" name="expu" id="expu" placeholder="Explanation" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                
                                                        <input type="hidden" name="qtype" id="qtype" value="1" class="form-control" placeholder="MCQ">                            
                                                        <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>
                </form>
                ';
                }
                else
                {
                    echo '<div class="clearfix"></div>';
                }
            echo '</body>';
            echo static::sscript();
            echo '
            <script>
                function filevalidation(data)
                {
                    const fi = document.getElementById(data.id); 
                    if (fi.files.length > 0) 
                    {
                        for (const i = 0; i <= fi.files.length - 1; i++) 
                        {
                            const fsize = fi.files.item(i).size;
                            const file = Math.round((fsize / 1024));
                            if (file > 3) {
                                swal("Sorry! File Size is Large", "File too Big, please upload file size lessthan 3kb.", "error");
                                  fi.value = "";
                            }
                            var filePath = fi.value;
                            var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i;
                            if (!allowedExtensions.exec(filePath)) {
                                swal("Sorry! File is in invalid format", "Invalid file type. Please upload .PNG/.JPG/.JPEG file types.", "error");
                                fi.value = "";
                            } 
                        }
                    }
                }
                function getsubjectchapters()
                {
                    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);
                        }
                    });
                }
            </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 saddmcqquestionsupload()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $options = array();
            $ans = serialize($_POST['a']);
            $ans = unserialize($ans);
            $img = '';
            if($_FILES["questionu"]["name"] != '')
            {
                $file_name=$_FILES["questionu"]["name"];
                $file_tmp=$_FILES["questionu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['question'] = $_POST['question'].$img;

            $img = '';
            if($_FILES["expu"]["name"] != '')
            {
                $file_name=$_FILES["expu"]["name"];
                $file_tmp=$_FILES["expu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['exp'] = $_POST['exp'].$img;

            for($i=0; $i<4; $i++)
            {
                $img = '';
                $file = 'u'.$i;
                if($_FILES[$file]["name"] != '')
                {
                    $file_name=$_FILES[$file]["name"];
                    $file_tmp=$_FILES[$file]["tmp_name"];
                    $img = static::filehandler($file_name, $file_tmp);
                }
                $a = 'a['.$i.']';
                $options[] = $ans[$i].$img;
            }
            $ans = serialize($options);
            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '$ans', '', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $option = array();
                    for($i=1; $i <= 4; $i++)
                    {
                        $options[$i-1] = '<input type="radio" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="'.$qid.'_'.$i.'">';
                    }
                    $options1 = serialize($options);
                    $qcorrect = $qid.'_'.$_POST['answer'];
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addmcqquestionsupload?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addmcqquestionsupload?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='1' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $option = array();
                    for($i=1; $i <= 4; $i++)
                    {
                        $options[$i-1] = '<input type="radio" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="'.$qid.'_'.$i.'">';
                    }
                    $options1 = serialize($options);
                    $qcorrect = $qid.'_'.$_POST['answer'];
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_answers`='$ans', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addmcqquestionsupload?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addmcqquestionsupload?status=0";</script>';
                }
            }
        }

    }
    public static function filehandler($file_name, $file_tmp)
    {
        $file_ext1 = explode('.', $file_name);
        $file_ext = $file_ext1[sizeof($file_ext1)-1];
        $data = file_get_contents($file_tmp);
        $base64 = 'data:image/' . $file_ext . ';base64,' . base64_encode($data);
        $img = '<img src="'.$base64.'" style="max-width:100%; height: auto;">';
        return $img;
    }
    public static function addfillinblanksupload()
    {
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                    echo '
                    <div class="clearfix"></div>
                    <form action="/Exams/saveaddfillinblanksupload" method="POST" enctype="multipart/form-data">
                    <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">ADD FILL IN BLANK QUESTIONS</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">
                                                        <div class="form-group">                                                                                
                                                            <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                                <option value="">Select Chapter / Unit Number</option>
                                                            </select>
                                                        </div>
                                                    </div>                               
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="topic" name="topic" class="form-control" required>
                                                                <option value="">Select Topic</option>
                                                            </select>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="qdiv" name="qdiv" class="form-control" required>
                                                                <option value="">Select Question Divsion</option>
                                                                '.$qdiv.'
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="question" id="question" class="form-control" placeholder="Question" ></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        <input type="file" name="questionu" id="questionu" placeholder="First Answer" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input id="answer" name="answer" placeholder="Correct Answer" class="form-control" required>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select id="tough" name="tough" class="form-control" required>
                                                                <option value="">Select Question Tough Level</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                                                <option value="3">3</option>
                                                                <option value="4">4</option>
                                                                <option value="5">5</option>
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <textarea name="exp" id="exp" class="form-control" placeholder="Expalanation" ></textarea>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        <input type="file" name="expu" id="expu" placeholder="Explanation" class="form-control"   accept=".jpg, .jpeg, .png" onchange="filevalidation(this)"/>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group"> 
                                                            <input type="hidden" name="qtype" id="qtype" value="2" class="form-control" placeholder="FILL">                                           
                                                            <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>
                    </form>
                    ';
                }
                else
                {
                    echo '
                    <div class="clearfix"></div>';
                }
            echo '</body>';
            echo static::sscript();
            echo '
            <script>
                function filevalidation(data)
                {
                    const fi = document.getElementById(data.id); 
                    if (fi.files.length > 0) 
                    {
                        for (const i = 0; i <= fi.files.length - 1; i++) 
                        {
                            const fsize = fi.files.item(i).size;
                            const file = Math.round((fsize / 1024));
                            if (file > 3) {
                                swal("Sorry! File Size is Large", "File too Big, please upload file size lessthan 3kb.", "error");
                                fi.value = "";
                            }
                            var filePath = fi.value;
                            var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i;
                            if (!allowedExtensions.exec(filePath)) {
                                swal("Sorry! File is in invalid format", "Invalid file type. Please upload .PNG/.JPG/.JPEG file types.", "error");
                                fi.value = "";
                            } 
                        }
                    }
                }
                function getsubjectchapters()
                {
                    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);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </script>  
            ';
            if(isset($_GET['editid']))
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_GET[editid]' AND `q_type`='2' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                            $("#subject").val("'.$data[0]['fk_sub_id'].'");
                            getsubjectchapters();
                            setTimeout(function()
                            { 
                                $("#chapter").val("'.$data[0]['chapter'].'");
                                getsubchaptopics();
                            }, 300);
                            setTimeout(function()
                            { 
                                $("#topic").val("'.$data[0]['topic'].'");
                            }, 500);
                            $("#qdiv").val("'.$data[0]['q_div'].'");
                            $("#question").val("'.$data[0]['q_text'].'");
                            $("#answer").val("'.$data[0]['q_correct'].'");
                            $("#tough").val("'.$data[0]['q_tough'].'");
                            $("#exp").val("'.$data[0]['exp'].'");
                            $("#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 saveaddfillinblanksupload()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $img = '';
            if($_FILES["questionu"]["name"] != '')
            {
                $file_name=$_FILES["questionu"]["name"];
                $file_tmp=$_FILES["questionu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['question'] = $_POST['question'].$img;

            $img = '';
            if($_FILES["expu"]["name"] != '')
            {
                $file_name=$_FILES["expu"]["name"];
                $file_tmp=$_FILES["expu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['exp'] = $_POST['exp'].$img;

            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '', '$_POST[answer]', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $i = 1;
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $_POST['answer'];
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addfillinblanksupload?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addfillinblanksupload?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='2' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $i = 1;
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $_POST['answer'];
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addfillinblanksupload?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addfillinblanksupload?status=0";</script>';
                }
            }
        }
    }
    public static function addinterquestionsupload()
    {
        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');
            $qdiv = Inputs::optionsdb(Homem::getdata("SELECT * FROM `subject_div`"), 'id', 'name');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                if(static::preqcheck() == 1)
                {
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddinterquestionsupload" method="POST" enctype="multipart/form-data">
                <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">ADD INTERMEDIATE ANSWER QUESTIONS</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">
                                                    <div class="form-group">                                                                                
                                                        <select id="chapter" name="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                            <option value="">Select Chapter / Unit Number</option>
                                                        </select>
                                                    </div>
                                                </div>                               
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="topic" name="topic" class="form-control" required>
                                                            <option value="">Select Topic</option>
                                                        </select>
                                                    </div>
                                                </div>      
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select id="qdiv" name="qdiv" class="form-control" required>
                                                            <option value="">Select Question Divsion</option>
                                                            '.$qdiv.'
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="question" id="question" class="form-control" placeholder="Question" ></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                    <input type="file" name="questionu" id="questionu" placeholder="Question" class="form-control"   accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="number" step="any" id="minanswer" name="minanswer" placeholder="Min Allowable Answer" class="form-control" required>
                                                    </div>
                                                </div>    
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <input type="number" step="any" id="maxanswer" name="maxanswer" placeholder="Max Allowable Answer" class="form-control" required>
                                                    </div>
                                                </div>    
                                                <div class="col-lg-4">
                                                    <div class="form-group">                                            
                                                        <select id="tough" name="tough" class="form-control" required>
                                                            <option value="">Select Question Tough Level</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                            <option value="5">5</option>
                                                        </select>
                                                    </div>
                                                </div>                         
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <textarea name="exp" id="exp" class="form-control" placeholder="Expalanation" ></textarea>
                                                    </div>
                                                </div>  										
                                            </div>
                                            <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        <input type="file" name="expu" id="expu" placeholder="Explanation" class="form-control"  accept=".jpg, .jpeg, .png" onchange="filevalidation(this)" />
                                                        </div>
                                                    </div>  										
                                                </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">
                                                        <input type="hidden" name="qtype" id="qtype" value="3" class="form-control" placeholder="MCQ">                                            
                                                        <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>
                </form>
                ';
                }
                else
                {
                    echo '<div class="clearfix"></div>';
                }
            echo '</body>';
            echo static::sscript();
            echo '
            <script>
                function filevalidation(data)
                {
                    const fi = document.getElementById(data.id); 
                    if (fi.files.length > 0) 
                    {
                        for (const i = 0; i <= fi.files.length - 1; i++) 
                        {
                            const fsize = fi.files.item(i).size;
                            const file = Math.round((fsize / 1024));
                            if (file > 3) {
                                swal("Sorry! File Size is Large", "File too Big, please upload file size lessthan 3kb.", "error");
                                fi.value = "";
                            }
                            var filePath = fi.value;
                            var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i;
                            if (!allowedExtensions.exec(filePath)) {
                                swal("Sorry! File is in invalid format", "Invalid file type. Please upload .PNG/.JPG/.JPEG file types.", "error");
                                fi.value = "";
                            } 
                        }
                    }
                }
                function getsubjectchapters()
                {
                    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);
                        }
                    });
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });     
            </script>  
            ';
            if(isset($_GET['editid']))
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_GET[editid]' AND `q_type`='3' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $ans = explode("_", $data[0]['q_correct']);
                    echo '
                        <script>
                            $("#subject").val("'.$data[0]['fk_sub_id'].'");
                            getsubjectchapters();
                            setTimeout(function()
                            { 
                                $("#chapter").val("'.$data[0]['chapter'].'");
                                getsubchaptopics();
                            }, 300);
                            setTimeout(function()
                            { 
                                $("#topic").val("'.$data[0]['topic'].'");
                            }, 500);
                            $("#qdiv").val("'.$data[0]['q_div'].'");
                            $("#question").val("'.$data[0]['q_text'].'");
                            $("#minanswer").val("'.$ans[0].'");
                            $("#maxanswer").val("'.$ans[1].'");
                            $("#tough").val("'.$data[0]['q_tough'].'");
                            $("#exp").val("'.$data[0]['exp'].'");
                            $("#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 saveaddinterquestionsupload()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $img = '';
            if($_FILES["questionu"]["name"] != '')
            {
                $file_name=$_FILES["questionu"]["name"];
                $file_tmp=$_FILES["questionu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['question'] = $_POST['question'].$img;

            $img = '';
            if($_FILES["expu"]["name"] != '')
            {
                $file_name=$_FILES["expu"]["name"];
                $file_tmp=$_FILES["expu"]["tmp_name"];
                $img = static::filehandler($file_name, $file_tmp);
            }
            $_POST['exp'] = $_POST['exp'].$img;
            if($_POST['edit_id'] == '')
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `q_div`='$_POST[qdiv]' AND `q_text`='$_POST[question]' AND `fk_user_id`='$_SESSION[user_id]'";
                $adata = Homem::getdata($query);
                if(sizeof($adata) == 0)
                {
                    $ans = $_POST['minanswer'].'_'.$_POST['maxanswer'];
                    $date = date('Y-m-d H:i:s A');
                    $query = "INSERT INTO `quiz_question_master` (`fk_sub_id`, `chapter`, `topic`, `q_div`, `q_type`, `q_no`, `q_text`, `q_options`, `q_answers`, `q_correct`, `q_tough`, `exp`, `fk_user_id`, `edate`, `status`, `q_lock`) VALUES 
                    ('$_POST[subject]', '$_POST[chapter]', '$_POST[topic]', '$_POST[qdiv]', '$_POST[qtype]', '', '$_POST[question]', '', '', '$ans', '$_POST[tough]', '$_POST[exp]', '$_SESSION[user_id]', '$date', '0', '0')";
                    Homem::insert($query);
                    $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `q_div`='$_POST[qdiv]' AND `q_type`='$_POST[qtype]' AND `q_text`='$_POST[question]' AND `q_tough`='$_POST[tough]' AND `fk_user_id`='$_SESSION[user_id]' AND `edate`='$date' AND `status`='0' AND `q_lock`='0' ORDER BY `id` DESC";
                    $qdata = Homem::getdata($query);
                    $qid = $qdata[0]['id'];
                    $i = 1;
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="number" step="any" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $ans;
                    $q_no = '';
                    $options1 = '';
                    $query = "UPDATE `quiz_question_master` SET `q_no`='$q_no', `q_options`='$options1', `q_correct`='$qcorrect', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addinterquestionsupload?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addinterquestionsupload?status=0";</script>';
                }
            }
            else
            {
                $query = "SELECT * FROM `quiz_question_master` WHERE `id`='$_POST[edit_id]' AND `q_type`='3' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $ans = $_POST['minanswer'].'_'.$_POST['maxanswer'];
                    $i = 1;
                    $qid = $_POST['edit_id'];
                    $q_no = '<input type="hidden" id="Q[{{i}}]" name="Q[{{i}}]" value="'.$qid.'"><input type="hidden" name="A[{{i}}]" value="">';
                    $options1 = '<input type="text" id="'.$qid.'_'.$i.'" name="A[{{i}}]" value="" class="form-control">';
                    $qcorrect = $ans;
                    $query = "UPDATE `quiz_question_master` SET `fk_sub_id`='$_POST[subject]', `chapter`='$_POST[chapter]', `topic`='$_POST[topic]', `q_div`='$_POST[qdiv]', `q_type`='$_POST[qtype]', `q_text`='$_POST[question]', `q_tough`='$_POST[tough]', `q_no`='$q_no', `q_text`='$_POST[question]', `q_options`='$options1', `q_correct`='$qcorrect', `exp`='$_POST[exp]', `status`='1' WHERE `id`='$qid'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Exams/addinterquestionsupload?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Exams/addinterquestionsupload?status=0";</script>';
                }
            }
        }
    }
    public static function approvalquestions()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            if(isset($_GET['delete']))
            {
                Homem::insert("UPDATE `quiz_question_master` SET `q_lock`='0', `status`='0' WHERE `id`='$_GET[delete]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='0'");
                echo '<script>window.location = "/Exams/approvalquestions?status=1";</script>';
            }
            if(isset($_GET['lockid']))
            {
                Homem::insert("UPDATE `quiz_question_master` SET `status`='1', `q_lock`='1' WHERE `id`='$_GET[lockid]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='0'");
                echo '<script>window.location = "/Exams/approvalquestions?status=1";</script>';
            }
            $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='0'");
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddmcqquestions" 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;">
                                    ';
                                    for($i=0; $i<sizeof($data); $i++)
                                    {
                                        if($data[$i]['q_type'] == 1)
                                        {
                                            $ans = unserialize($data[$i]['q_answers']);
                                            $crect = explode("_", $data[$i]['q_correct']);
                                            $opt = '';
                                            for($j=0; $j<sizeof($ans); $j++)
                                            {
                                                $k = $j+1;
                                                $opt .= '<tr><td><span style="color: red;">Option-'.$k.'</span><span style="color: green;">'.$ans[$j].'</span></td></tr>';
                                            }
                                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$crect[1].'</td></tr>';
                                            $opt .= '<tr><td><a href="?delete='.$data[$i]['id'].'" class="btn btn-danger">Delete</a><a href="?lockid='.$data[$i]['id'].'" class="btn btn-success">Lock</a></td></tr>';
                                            echo '
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                <div class="table-responsive">
                                                    <table class="table">
                                                        <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                                        '.$opt.'
                                                    </table>
                                                </div>
                                                </div>
                                            </div>';
                                        }
                                        if($data[$i]['q_type'] == 2)
                                        {
                                            $ans = $data[$i]['q_correct'];
                                            $opt = '';
                                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$ans.'</td></tr>';
                                            $opt .= '<tr><td><a href="?delete='.$data[$i]['id'].'" class="btn btn-danger">Delete</a><a href="?lockid='.$data[$i]['id'].'" class="btn btn-success">Lock</a></td></tr>';
                                            echo '
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                <div class="table-responsive">
                                                    <table class="table">
                                                        <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                                        '.$opt.'
                                                    </table>
                                                </div>
                                                </div>
                                            </div>';
                                        }
                                        if($data[$i]['q_type'] == 3)
                                        {
                                            $ans = explode("_", $data[$i]['q_correct']);
                                            // echo sizeof($ans);
                                            $opt = '';
                                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$ans[0].' to '.$ans[1].'</td></tr>';
                                            $opt .= '<tr><td><a href="?delete='.$data[$i]['id'].'" class="btn btn-danger">Delete</a><a href="?lockid='.$data[$i]['id'].'" class="btn btn-success">Lock</a></td></tr>';
                                            echo '
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                <div class="table-responsive">
                                                    <table class="table">
                                                        <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                                        '.$opt.'
                                                    </table>
                                                </div>
                                                </div>
                                            </div>';
                                        }
                                    }
                                    // echo '
                                    //     <div class="panel panel-default">
                                    //         <div class="panel-body">
                                    //         <div class="table-responsive">
                                    //             <table class="table">
                                    //                 <tr><td></td></tr>
                                    //             </table>
                                    //         </div>
                                    //         </div>
                                    //     </div>';
                                    echo '                
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </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>';
                }
            }
        }
    }
    private static function preqcheck()
    {
        $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='0'");
        if(sizeof($data) == 0)
        {
            return '1';
        }
        else
        {
            return '0';
        }
    }
    public static function questionscount()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $query = "SELECT sd.sub_id, sd.subname, sd.subcode, qqm.chapter, ss.chapt_name, ss.chapt_topics, qqm.topic FROM quiz_question_master qqm JOIN subject_data sd ON qqm.fk_sub_id=sd.sub_id JOIN subject_syllabus ss ON ss.fk_sub_id=sd.sub_id WHERE qqm.chapter=ss.chapt_no AND qqm.status='1' AND qqm.fk_user_id='$_SESSION[user_id]' AND qqm.q_lock='1'";
            $data = Homem::getdata($query);
            $subcode = array();
            foreach ($data as $h) {
                $subcode[] = $h['sub_id'];
            }
            $scode = array_values(array_unique($subcode));
            sort($scode);
            for($i=0; $i<sizeof($data); $i++)
            {
                for($j=0; $j<sizeof($scode); $j++)
                {
                    if($data[$i]['sub_id'] == $scode[$j])
                    {
                        $subname[$scode[$j]] = $data[$i]['subname'];
                    }
                }
            }
            for($j=0; $j<sizeof($scode); $j++)
            {
                $count = 0;
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]['sub_id'] == $scode[$j])
                    {
                        $count++;
                    }
                }
                $bitcount[$scode[$j]] = $count;
            }
            $a = '';
            for($j=0; $j<sizeof($scode); $j++)
            {
                $a .= '<tr><td>'.$subname[$scode[$j]].'</td><td>'.$bitcount[$scode[$j]].'</td></tr>';
            }
            $b = '';
            if($_SESSION['user_role'] == 6)
            {
                $query = "SELECT sd.sub_id, sd.subname, sd.subcode, qqm.chapter, ss.chapt_name, ss.chapt_topics, qqm.topic, um.id, um.name, um.fk_dept_id FROM quiz_question_master qqm JOIN subject_data sd ON qqm.fk_sub_id=sd.sub_id JOIN subject_syllabus ss ON ss.fk_sub_id=sd.sub_id JOIN user_master um ON um.id=qqm.fk_user_id WHERE qqm.chapter=ss.chapt_no AND qqm.status='1' AND qqm.q_lock='1'";
                $data = Homem::getdata($query);
                $subcode = array();
                $userid = array();
                foreach ($data as $h) 
                {
                    $subcode[] = $h['subcode'];
                    $userid[] = $h['id'];
                }
                $scode = array_values(array_unique($subcode));
                sort($scode);
                $uid = array_values(array_unique($userid));
                sort($uid);
                for($i=0; $i<sizeof($uid); $i++)
                {
                    for($j=0; $j<sizeof($scode); $j++)
                    {
                        $count = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['id'] == $uid[$i])
                            {
                                $uname[$uid[$i]] = $data[$k]['name'];
                            }
                            if($data[$k]['id'] == $uid[$i] &&
                                $data[$k]['subcode'] == $scode[$j] )
                            {
                                $sname[$scode[$j]] = $data[$k]['subname'];
                                $count++;
                            }
                            if($k == sizeof($data)-1)
                            {
                                if($count != 0)
                                {
                                    $b .= '<tr>
                                            <td>'.$uname[$uid[$i]].'</td>
                                            <td>'.$scode[$j].'</td>
                                            <td>'.$sname[$scode[$j]].'</td>
                                            <td>'.$count.'</td>
                                            </tr>';
                                }
                            }
                        }
                    }
                }
            }
            $c = '';
            $data = Homem::getdata("SELECT sd.sub_id, sd.subcode, sd.subname, qqm.chapter, qqm.topic, ss.chapt_name, ss.chapt_topics FROM quiz_question_master qqm JOIN subject_data sd ON qqm.fk_sub_id=sd.sub_id JOIN subject_syllabus ss ON ss.fk_sub_id=sd.sub_id WHERE qqm.fk_user_id='$_SESSION[user_id]' AND qqm.status='1' AND qqm.q_lock='1' AND ss.add_by=qqm.fk_user_id");
            $subcode = array();
            $chaptno = array();
            $topicno = array();
            foreach ($data as $h) {
                $subcode[] = $h['sub_id'];
                $chaptno[] = $h['chapter'];
                $topicno[] = $h['topic'];
            }
            $sid = array_values(array_unique($subcode));
            sort($sid);
            $cid = array_values(array_unique($chaptno));
            sort($cid);
            $tid = array_values(array_unique($topicno));
            sort($tid);
            
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddmcqquestions" 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;">
                                    ';
                                    echo '
                                        <div class="panel panel-default">
                                            <div class="panel-body">
                                            <div class="table-responsive">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>Subject Name</th>
                                                            <th>Active Quiz Question</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    '.$a.'
                                                    </tbody>
                                                </table>
                                            </div>';
                                            if($b != '')
                                            {
                                            echo '<div class="table-responsive">
                                                    <table class="table">
                                                        <thead>
                                                            <tr>
                                                                <th>Faculty Name</th>
                                                                <th>Subject Code</th>
                                                                <th>Subject Name</th>
                                                                <th>Active Quiz Question</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                        '.$b.'
                                                        </tbody>
                                                    </table>
                                                </div>';
                                            }
                                    echo '
                                            </div>
                                        </div>';
                                    echo '                
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </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 totalquestionscount()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7)
        {
            $a = '';
            $b = '';
            {
                $query = "SELECT sd.sub_id, sd.subname, sd.subcode, qqm.chapter, ss.chapt_name, ss.chapt_topics, qqm.topic, um.id, um.name, um.fk_dept_id FROM quiz_question_master qqm JOIN subject_data sd ON qqm.fk_sub_id=sd.sub_id JOIN subject_syllabus ss ON ss.fk_sub_id=sd.sub_id JOIN user_master um ON um.id=qqm.fk_user_id WHERE qqm.chapter=ss.chapt_no AND qqm.status='1' AND qqm.q_lock='1'";
                $data = Homem::getdata($query);
                $subcode = array();
                $userid = array();
                foreach ($data as $h) 
                {
                    $subcode[] = $h['sub_id'];
                    $userid[] = $h['id'];
                }
                $scode = array_values(array_unique($subcode));
                sort($scode);
                $uid = array_values(array_unique($userid));
                sort($uid);
                for($i=0; $i<sizeof($uid); $i++)
                {
                    for($j=0; $j<sizeof($scode); $j++)
                    {
                        $count = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['id'] == $uid[$i])
                            {
                                $uname[$uid[$i]] = $data[$k]['name'];
                            }
                            if($data[$k]['id'] == $uid[$i] &&
                                $data[$k]['sub_id'] == $scode[$j] )
                            {
                                $sname[$scode[$j]] = $data[$k]['subname'];
                                $count++;
                            }
                            if($k == sizeof($data)-1)
                            {
                                if($count != 0)
                                {
                                    $b .= '<tr>
                                            <td>'.$uname[$uid[$i]].'</td>
                                            <td>'.$sname[$scode[$j]].'</td>
                                            <td>'.$count.'</td>
                                            </tr>';
                                }
                            }
                        }
                    }
                }
            }
            $c = '';
            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;">
                                    ';
                                    echo '
                                        <div class="panel panel-default">
                                            <div class="panel-body">
                                           ';
                                            if($b != '')
                                            {
                                            echo '<div class="table-responsive">
                                                    <table class="table">
                                                        <thead>
                                                            <tr><th colspan="4">Total Questions Entered by the faculty</th></tr>
                                                            <tr>
                                                                <th>Faculty Name</th>
                                                                <th>Subject Name</th>
                                                                <th>Active Quiz Question</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                        '.$b.'
                                                        </tbody>
                                                    </table>
                                                </div>';
                                            }
                                    echo '
                                            </div>
                                        </div>';
                                    echo '                
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                        }
                    });
                }
                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);
                        }
                    });
                }
            </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 questionscounttopicwise()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 2)
        {
            $a = '';
            $b = '';
            $c = '';
            $data = Homem::getdata("SELECT sd.sub_id, sd.subcode, sd.subname, qqm.chapter, qqm.topic, ss.chapt_name, ss.chapt_topics FROM quiz_question_master qqm JOIN subject_data sd ON qqm.fk_sub_id=sd.sub_id JOIN subject_syllabus ss ON ss.fk_sub_id=sd.sub_id WHERE qqm.fk_user_id='$_SESSION[user_id]' AND qqm.status='1' AND qqm.q_lock='1' AND ss.add_by=qqm.fk_user_id AND ss.chapt_no=qqm.chapter");
            $subcode = array();
            $chaptno = array();
            $topicno = array();
            foreach ($data as $h) {
                $subcode[] = $h['sub_id'];
                $chaptno[] = $h['chapter'];
                $topicno[] = $h['topic'];
            }
            $sid = array_values(array_unique($subcode));
            sort($sid);
            $cid = array_values(array_unique($chaptno));
            sort($cid);
            $tid = array_values(array_unique($topicno));
            sort($tid);
            for($i=0; $i<sizeof($sid); $i++)
            {
                $topics = array();
                for($j=0; $j<sizeof($cid); $j++)
                {
                    for($k=0; $k<sizeof($data); $k++)
                    {
                        if($data[$k]['sub_id'] == $sid[$i] && 
                        $data[$k]['chapter'] == $cid[$j])
                        {
                            $topics[] = $data[$k]['topic'];
                            $chapters[] = $data[$k]['chapter'];
                            $subname[$sid[$i]] = $data[$k]['subname'];
                        }
                    }
                    $cha = array_values(array_unique($chapters));
                    sort($cha);
                    $chptid[$sid[$i]] = $cha;
                    $to = array_values(array_unique($topics));
                    sort($to);
                    $topicid[$sid[$i]][$cid[$j]] = $to;
                    for($k=0; $k<sizeof($chptid[$sid[$i]]); $k++)
                    {
                        for($l=0; $l<sizeof($data); $l++)
                        {
                            if($data[$l]['sub_id'] == $sid[$i] && 
                            $data[$l]['chapter'] == $cid[$j] && 
                            $chptid[$sid[$i]][$k] == $data[$l]['chapter'])
                            {
                                $chptname[$sid[$i]][$k] = $data[$l]['chapt_name'];
                                $chpttopics[$sid[$i]][$chptid[$sid[$i]][$k]] = $data[$l]['chapt_topics'];
                                $fchpttopics[$sid[$i]][$chptid[$sid[$i]][$k]] = explode(",", $chpttopics[$sid[$i]][$chptid[$sid[$i]][$k]]);
                            }
                        }
                    }
                    for($k=0; $k<sizeof($topicid[$sid[$i]][$cid[$j]]); $k++)
                    {
                        $cnt = 0;
                        for($l=0; $l<sizeof($data); $l++)
                        {
                            if($data[$l]['sub_id'] == $sid[$i] && 
                            $data[$l]['chapter'] == $cid[$j] && 
                            $topicid[$sid[$i]][$cid[$j]][$k] == $data[$l]['topic'])
                            {
                                $cnt++; 
                            }
                            if($l == sizeof($data)-1)
                            {
                                $count[$sid[$i]][$cid[$j]][$k] = $cnt;
                            }
                        }
                    }
                }
            }
            $m = 0;
            for($i=0; $i<sizeof($sid); $i++)
            {
                for($j=0; $j<sizeof($cid); $j++)
                {
                    for($k=0; $k<sizeof($topicid[$sid[$i]][$cid[$j]]); $k++)
                    {
                        if(isset($fchpttopics[$sid[$i]][$cid[$j]]))
                        {
                            $m++;
                            $l = $topicid[$sid[$i]][$cid[$j]][$k]-1;
                            $a .= '<tr>';
                            $a .= '<td>'.$m.'</td>';
                            $a .= '<td>'.$subname[$sid[$i]].'</td>';
                            $a .= '<td>'.$chptname[$sid[$i]][$j].'('.$cid[$j].')</td>';
                            $a .= '<td>'.$fchpttopics[$sid[$i]][$cid[$j]][$k].'('.$topicid[$sid[$i]][$cid[$j]][$k].')</td>';
                            $a .= '<td>'.$count[$sid[$i]][$cid[$j]][$k].'</td>';
                            $a .= '</tr>';
                        }
                    }
                }
            }
            // echo json_encode($count);
            // echo json_encode($chptname);
            // echo $_SESSION['user_id'];
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveaddmcqquestions" 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>S. No.</th>
                                                            <th>Subject Name</th>
                                                            <th>Chapter Name (Chapter Number)</th>
                                                            <th>Topic Name (Topic Number)</th>
                                                            <th>Number of Questions</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    '.$a.'
                                                    </tbody>
                                                </table>
                                            </div>';
                                            if($b != '')
                                            {
                                            echo '<div class="table-responsive">
                                                    <table class="table">
                                                        <thead>
                                                            <tr>
                                                                <th>Faculty Name</th>
                                                                <th>Subject Code</th>
                                                                <th>Subject Name</th>
                                                                <th>Active Quiz Question</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                        '.$b.'
                                                        </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>
                function getsubjectchapters()
                {
                    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);
                        }
                    });
                }
            </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 viewquestions()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $a = '';
            if(isset($_POST['subject']))
            {
                if($_POST['chapter']!="")
                {
                    $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `status`='1' AND `q_lock`='1' ORDER BY `id` DESC");
                }
                else
                {
                    $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `status`='1' AND `q_lock`='1'  ORDER BY `id` DESC");
                }
                if(sizeof($data) > 0)
                {
                    
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        if($data[$i]['q_type'] == 1)
                        {
                            $ans = unserialize($data[$i]['q_answers']);
                            $crect = explode("_", $data[$i]['q_correct']);
                            $opt = '';
                            for($j=0; $j<sizeof($ans); $j++)
                            {
                                $k = $j+1;
                                $opt .= '<tr><td><span style="color: red;">Option-'.$k.'</span><span style="color: green;">'.$ans[$j].'</span></td></tr>';
                            }
                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$crect[1].'</td></tr>';
                            $opt .= '<tr><td><span class="btn btn-danger">Chapter: '.$data[$i]['chapter'].'</span><span class="btn btn-success">Topic: '.$data[$i]['topic'].'</span></td></tr>';
                            $a .= '
                            <div class="shadow p-3 mb-5 bg-white rounded">
                                <div class="panel panel-default">
                                    <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                            '.$opt.'
                                        </table>
                                    </div>
                                    </div>
                                </div>
                            </div>';
                        }
                        if($data[$i]['q_type'] == 2)
                        {
                            $ans = $data[$i]['q_correct'];
                            $opt = '';
                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$ans.'</td></tr>';
                            $opt .= '<tr><td><span class="btn btn-danger">Chapter: '.$data[$i]['chapter'].'</span><span class="btn btn-success">Topic: '.$data[$i]['topic'].'</span></td></tr>';
                            $a .= '
                            <div class="shadow p-3 mb-5 bg-white rounded">
                                <div class="panel panel-default">
                                    <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                            '.$opt.'
                                        </table>
                                    </div>
                                    </div>
                                </div>
                            </div>';
                        }
                        if($data[$i]['q_type'] == 3)
                        {
                            $ans = explode("_", $data[$i]['q_correct']);
                            // echo sizeof($ans);
                            $opt = '';
                            $opt .= '<tr><td rowspan="4"><span style="color: green;">Answer</span>'.$ans[0].' to '.$ans[1].'</td></tr>';
                            $opt .= '<tr><td><span class="btn btn-danger">Chapter: '.$data[$i]['chapter'].'</span><span class="btn btn-success">Topic: '.$data[$i]['topic'].'</span></td></tr>';
                            $a .= '
                            <div class="shadow p-3 mb-5 bg-white rounded">
                                <div class="panel panel-default">
                                    <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tr><td colspan="2"><span style="color: red;">Question:</span>'.$data[$i]['q_text'].'</td></tr>
                                            '.$opt.'
                                        </table>
                                    </div>
                                    </div>
                                </div>
                            </div>';
                        }
                    }
                }
            }
            $subj = 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 '
            <!--code to disable selection by mouse start-->
                <style type="text/css">
                    body{
                        -webkit-touch-callout: none;
                        -webkit-user-select: none;
                        -khtml-user-select: none;
                        -moz-user-select: none;
                        -ms-user-select: none;
                        user-select: none;
                    }
                </style> 
            <!--code to disable selection by mouse End-->';
            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-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">VIEW QUESTIONS CHAPTER WISE</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="chapter" id="chapter" class="form-control" onchange="getchaptwiseqcount()">
                                                                <option value="">Select Chapter</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qavailable" id="qavailable" class="form-control" placeholder="Questions Available" readonly>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <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 btnsubmit">
                                                    <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">
                            '.$a.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                        }
                    });
                }
                function getchaptwiseqcount()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = document.getElementById("chapter").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter},
                        url: "/Exams/getchaptwiseqcount",
                        success: function(d){
                            // console.log(d);
                            $("#qavailable").val(d);
                        }
                    });
                }
            </script>
            ';
            echo '
            <!--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-->
            ';
            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>';
                }
            }
        }
    }

    /** Starting of Time Table master */
    public static function workingdays()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            $data = '
            <div class="table-responsive">
                <table class="table table-responsive-sm">
                    <thead>
                        <tr>
                            <th><input type="checkbox" name="allworking" id="allworking" onchange="setallpresent()">Working days</th>
                            <th>Date</th>
                            <th>Day</th>
                        </tr>
                    </thead>
                    <tbody>';
            $date = static::datesinmonth();
            for($i=0; $i<sizeof($date); $i++)
            {
                $data .= '<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>';
                $data .= '<td><input type="hidden" name="date['.$i.']" id="date['.$i.']" value="'.$date[$i]['date'].'">'.$date[$i]['date'].'</td>';
                $data .= '<td>'.$date[$i]['day'].'</td>';
                $data .= '</tr>';
            }
            $data .= '</tbody></table>';
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/saveworkingdays" 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">ADD WORKING DAYS</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="hidden" name="dcount" id="dcount" value="'.sizeof($date).'">                                            
                                                        '.$data.'
                                                    </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-3"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            $cdate = date('Y-m-');
            $mdata = (Homem::getdata("SELECT * FROM `tt_workdays` WHERE `dates` LIKE '%$cdate%'"));
            if(sizeof($mdata) > 0)
            {
                echo '
                    <script>
                    var data= '.json_encode($mdata).';
                    for(var i=0; i<data.length; i++)
                    {
                        // console.log(data[i]["dates"]);
                        var a = "work["+i+"]";
                        var ele=document.getElementsByName(a);
                        for(var j=0; j<ele.length; j++)
                        {  
                            if(ele[j].type=="checkbox" && data[i]["work"]==1)  
                            {
                                ele[j].checked=true;
                            }
                            if(ele[j].type=="checkbox" && data[i]["work"]==0) 
                            {
                                ele[j].checked=false;
                            }
                            if(ele[j].type!="checkbox")
                            {
                                var newval = ele[j].value;
                            }
                        }
                    }
                    </script>
                ';
            }
            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);
                            getstudentattendaceemptydata();
                        }
                    });
                }
                function getstudentattendaceemptydata()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getstudentattendaceemptydata",
                        success: function(d){
                            $("#students").html(d);
                        }
                    });
                }
            </script>';
            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>  
            ';
            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 saveworkingdays()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            $work = array();
            $work = $_POST['work'];
            $date = array();
            $date = $_POST['date'];
            for($i=0; $i<sizeof($_POST['work']); $i++)
            {
                if(sizeof(Homem::getdata("SELECT * FROM `tt_workdays` WHERE `dates`='$date[$i]'")) > 0)
                {
                    $status = Homem::insert("UPDATE `tt_workdays` SET `dates`='$date[$i]', `work`='$work[$i]', `fk_user_id`='$_SESSION[user_id]' WHERE `dates`='$date[$i]'");
                }
                else
                {
                    $status = Homem::insert("INSERT INTO `tt_workdays`(`dates`, `work`, `fk_user_id`) VALUES ('$date[$i]', '$work[$i]', '$_SESSION[user_id]')");
                }
            }
            echo '<script>window.location = "/Exams/workingdays?status=1";</script>';
        }
    }
    public static function createshift()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            $data = '';
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Exams/savecreateshift" 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">ADD WORKING DAY TIME SLOTS</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">
                                                        <input type="text" name="name" id="name" value="" placeholder="Shift Name" class="form-control" required>                                            
                                                    </div>
                                                </div>  	
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <select name="hours" id="hours" class="form-control" onchange="getslot()" required>
                                                            <option value="">Select Number of Hours including Lunch & Breaks</option>
                                                            <option value="1">One Hour</option>
                                                            <option value="2">Two Hours</option>
                                                            <option value="3">Three Hours</option>
                                                            <option value="4">Four Hours</option>
                                                            <option value="5">Five Hours</option>
                                                            <option value="6">Six Hours</option>
                                                            <option value="7">Seven Hours</option>
                                                            <option value="8">Eight Hours</option>
                                                            <option value="9">Nine Hours</option>
                                                            <option value="10">Ten Hours</option>
                                                            <option value="11">Eleven Hours</option>
                                                            <option value="12">Twelve Hours</option>
                                                            <option value="13">Thirteen Hours</option>
                                                            <option value="14">Fourteen Hours</option>
                                                            <option value="15">Fifteen Hours</option>
                                                        </select>                                            
                                                    </div>
                                                </div> 									
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <input type="text" name="fromtime" id="fromtime" onfocus="(this.type=`time`)" onblur="(this.type=`text`)" placeholder="From Time" class="form-control" required>                                            
                                                    </div>
                                                </div> 
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <input type="text" name="totime" id="totime" min="09:00" max="18:00" onfocus="(this.type=`time`)" onblur="(this.type=`text`)" placeholder="To Time" class="form-control" required>                                            
                                                    </div>
                                                </div> 										
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                            
                                                        <div id="getslots">
                                                        </div>
                                                    </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-3"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getslot()
                {
                    var hours = document.getElementById("hours").value;
                    $.ajax({
                        type: "POST",
                        data : {hours: hours},
                        url: "/Exams/getslots",
                        success: function(d){
                            $("#getslots").html(d);
                        }
                    });
                    //getslots
                }
            </script>';
            echo '
            <script type="text/javascript">  
                $(document).ready(function() {
                });
                function setallpresent()
                {
                }        
            </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 savecreateshift()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            if(sizeof(Homem::getdata("SELECT * FROM `tt_slotsmaster` WHERE `s_name`='$_POST[name]'")) ==0)
            {
                Homem::insert("INSERT INTO `tt_slotsmaster` (`s_id`, `s_name`, `noofhours`, `fromtime`, `totime`, `add_by`, `status`) VALUES (NULL, '$_POST[name]', '$_POST[hours]', '$_POST[fromtime]', '$_POST[totime]', '$_SESSION[user_id]', '1')");
                $data = Homem::getdata("SELECT * FROM `tt_slotsmaster` WHERE `s_name`='$_POST[name]' AND `add_by`='$_SESSION[user_id]'");
                $id = $data[0]['s_id'];
                $h = array();
                $h = $_POST['hourno'];
                $f = array();
                $f = $_POST['ftime'];
                $t = array();
                $t = $_POST['ttime'];
                $date = date('Y-m-d');
                for($i=0; $i<sizeof($h); $i++)
                {
                    if(sizeof(Homem::getdata("SELECT * FROM `tt_slottime` WHERE `fk_slot_id`='$id' AND `hour_no`='$h[$i]' AND `status`='1'")) ==0)
                    {
                        Homem::insert("INSERT INTO `tt_slottime` (`id`, `fk_slot_id`, `hour_no`, `f_time`, `t_time`, `add_by`, `edate`, `status`) VALUES (NULL, '$id', '$h[$i]', '$f[$i]', '$t[$i]', '$_SESSION[user_id]', '$date', '1')");
                    }
                }
                echo '<script>window.location = "/Exams/createshift?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/createshift?status=0";</script>';
            }
        }
    }

    public static function createtimetable()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $slot = Inputs::optionsdb(Homem::getdata("SELECT * FROM `tt_slotsmaster` WHERE `add_by`='$_SESSION[user_id]' AND `status`='1'"), 's_id', 's_name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/Exams/savecreatetimetable" 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">CREATE TIME TABLE</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <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="getstudentyear()">
                                                                <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="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-4">
                                                        <div class="form-group">                                            
                                                            <select name="slot" id="slot" class="form-control" onchange="getttslotdetails()">
                                                                <option value="">Select Time Slot</option>
                                                                '.$slot.'
                                                            </select>
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="noofhours" id="noofhours" class="form-control" placeholder="No of hours" readonly>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromtime" id="fromtime" class="form-control" onfocus="(this.type=`time`)" onblur="(this.type=`time`)" placeholder="From Time" required readonly>
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="totime" id="totime" class="form-control" placeholder="To Time" readonly>
                                                        </div>
                                                    </div>
                                                    <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>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div id="timetable" class="timetable">
                                                        </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-2"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            </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/getsubjectsfortt",
                        success: function(d){
                            $("#subject").html(d);
                            console.log(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);
                        }
                    });
                }
                function getttslotdetails()
                {
                    var fdept = document.getElementById("slot").value;
                    $.ajax({
                        type: "POST",
                        data : {slot: fdept},
                        url: "/Exams/getttslotdetails",
                        success: function(d){
                            // $("#faculty").html(d);
                            var obj = JSON.parse(d);
                            $("#noofhours").val(obj.length);
                            $("#fromtime").val(obj[0]["fromtime"]);
                            $("#totime").val(obj[0]["totime"]);
                            getemptytimetable();
                        }
                    });
                }
                function getemptytimetable()
                {
                    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;
                    var fdept = document.getElementById("slot").value;
                    $.ajax({
                        type: "POST",
                        data : {slot: fdept, course: course, dept: dept, regulation: regulation, year: year, sem: sem},
                        url: "/Exams/getemptytimetable",
                        success: function(d){
                            $("#timetable").html(d);
                        }
                    });
                }

            </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function getsubjectsfortt()
    {
        if(isset($_POST['course']) && isset($_POST['dept']) && isset($_POST['year']) && isset($_POST['sem']))
        {
            $data = Homem::getdata("SELECT sub_id, subname FROM `subject_data` WHERE `course`='$_POST[course]' AND `dept`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `year`='$_POST[year]' AND `sem`='$_POST[sem]' UNION SELECT id, name FROM `tt_extrasubj`");
            echo '<option value="">Select Subject</option>';
            echo Inputs::optionsdb($data, 'sub_id', 'subname');
        }
    }
    public static function getttslotdetails()
    {
        if(isset($_POST['slot']))
        {
            $data = Homem::getdata("SELECT * FROM tt_slotsmaster ttm JOIN tt_slottime ttt ON ttm.s_id=ttt.fk_slot_id WHERE ttt.fk_slot_id='$_POST[slot]'");
            if(sizeof($data) == $data[0]['noofhours'])
            {
                echo json_encode($data);
            }
        }
    }
    public static function getemptytimetable()
    {
        if(isset($_POST['slot']))
        {
            $data = Homem::getdata("SELECT sub_id, subname FROM `subject_data` WHERE `course`='$_POST[course]' AND `dept`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `year`='$_POST[year]' AND `sem`='$_POST[sem]' UNION SELECT id, name FROM `tt_extrasubj`");
            $option = '<option value="">Select Subject</option>';
            $option .= Inputs::optionsdb($data, 'sub_id', 'subname');
            $tdata = Homem::getdata("SELECT * FROM `tt_days`");
            $data = Homem::getdata("SELECT * FROM tt_slotsmaster ttm JOIN tt_slottime ttt ON ttm.s_id=ttt.fk_slot_id WHERE ttt.fk_slot_id='$_POST[slot]' ORDER BY ttt.hour_no ASC");
            if(sizeof($data) == $data[0]['noofhours'])
            {
                $width = number_format(100/(sizeof($data)+1), 2);
                $width = 'width="'.$width.'%"';
                $table = '';
                $tbody = '<thead><tr>';
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($i == 0)
                    {
                        $tbody .= '<td '.$width.'> Days & Timings</td>';
                    }
                    $tbody .= '<td '.$width.'>'.$data[$i]['f_time'].'-'.$data[$i]['t_time'].'</td>';
                }
                $tbody .= '</tr></thead><tbody>';
                for($i=0; $i<sizeof($tdata); $i++)
                {
                    $table .= '<tr><td '.$width.'>'.$tdata[$i]['name'].'</td>';
                    for($j=0; $j<sizeof($data); $j++)
                    {
                        $a = $i+1;
                        $b = $j+1;
                        $table .= '<td '.$width.'><select class="form-control" id="subj['.$a.']['.$b.']" name="subj['.$a.']['.$b.']" required>'.$option.'</select></td>';
                    }
                    $table .= '</tr>';
                }
                $table .= '</tbody>';
            }
        }
        echo '<table border="1px" width="100%">
        '.$tbody.$table.'
        </table>';
    }
    public static function savecreatetimetable()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            $date = date('Y-m-d');
            if(sizeof(Homem::getdata("SELECT * FROM `tt_regularmain` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `year`='$_POST[year]' AND `sem`='$_POST[sem]' AND `joinyear`='$_POST[syear]' AND `status`='1'")) == 0)
            {
                Homem::insert("INSERT INTO `tt_regularmain` (`tm_id`, `fk_course_id`, `fk_dept_id`, `regulation`, `year`, `sem`, `joinyear`, `fk_ttslot_id`, `slot_hours`, `sdate`, `edate`, `add_by`, `add_date`, `status`) VALUES (NULL, '$_POST[course]', '$_POST[dept]', '$_POST[regulation]', '$_POST[year]', '$_POST[sem]', '$_POST[syear]', '$_POST[slot]', '$_POST[noofhours]', '$_POST[sdate]', '$_POST[edate]', '$_SESSION[user_id]', '$date', '1')");
                $ndata = Homem::getdata("SELECT * FROM `tt_regularmain` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[dept]' AND `regulation`='$_POST[regulation]' AND `year`='$_POST[year]' AND `sem`='$_POST[sem]' AND `joinyear`='$_POST[syear]' AND `status`='1' AND `add_by`='$_SESSION[user_id]' AND `add_date`='$date' ORDER BY `tm_id` DESC");
                if(sizeof($ndata) > 0)
                {
                    $id = $ndata[0]['tm_id'];
                    $subj = $_POST['subj'];
                    $k = 0;
                    for($i=1; $i<=sizeof($subj); $i++)
                    {
                        for($j=1; $j<=$_POST['noofhours']; $j++)
                        {
                            $k++;
                            $a = $subj[$i][$j]; //Subj ID
                            Homem::insert("INSERT INTO `tt_regularsub` (`fk_ttregmain_id`, `fk_slot_id`, `day_id`, `hour_no`, `fk_sub_id`) VALUES ('$id', '$_POST[slot]', '$i', '$j', '$a')");
                        }
                    }
                }
                echo '<script>window.location = "/Exams/createtimetable?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/createtimetable?status=0";</script>';
            }
        }
    }

    public static function requestanhour()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 2)
        {
            $fdept = Inputs::optionsdb($data = Homem::getdata("SELECT * FROM (SELECT DISTINCT `fk_dept_id` FROM `user_master` WHERE (`user_role`='2' OR `user_role`='7' OR `user_role`='8') AND `org_id`='$_SESSION[org_id]') a JOIN degree_dept_master ddm ON a.fk_dept_id=ddm.id"), 'id', 'name');
            $subj = 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/saverequestanhour" 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">HOUR ADJUSTMENTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="classdate" id="classdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" onchange="getdayhours()" placeholder="Class Date" required>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="hours" id="hours" class="form-control" onchange="gethoursubject()" required>
                                                                <option value="">Select Hour</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" required>
                                                                <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()" required>
                                                            <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="getnewfacsub()" required>
                                                            <option value="">Select Faculty Name</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                        <select name="newsub" id="newsub" class="form-control" required>
                                                            <option value="">Select New Faculty Subject</option>
                                                        </select>
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                            <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">
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getdayhours()
                {
                    var date = document.getElementById("classdate").value;
                    $.ajax({
                        type: "POST",
                        data : {date: date},
                        url: "/Exams/getdayhours",
                        success: function(d){
                            $("#hours").html(d);
                            
                        }
                    });
                }
                function gethoursubject()
                {
                    var date = document.getElementById("classdate").value;
                    var hour = document.getElementById("hours").value;
                    $.ajax({
                        type: "POST",
                        data : {date: date, hour: hour},
                        url: "/Exams/gethoursubject",
                        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 getnewfacsub()
                {
                    var subject = document.getElementById("subject").value;
                    var faculty = document.getElementById("faculty").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, faculty: faculty},
                        url: "/Exams/getnewfacsub",
                        success: function(d){
                            $("#newsub").html(d);
                            
                        }
                    });
                }
            </script>
            ';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function getdayhours()
    {
        if(isset($_POST['date']))
        {
            $det = static::getdaybydate($_POST['date']);
            $a = Homem::getdata("SELECT * FROM `tt_days` WHERE `name`='$det'");
            $day = $a[0]['id'];
            Homem::getdata("SELECT * FROM `tt_workdays` WHERE `dates`='2021-04-30' AND `work`='1'");
            $data = Homem::getdata("SELECT sd.sub_id, sd.subname, tts.day_id, tts.hour_no FROM subject_data sd JOIN subject_faculty sf ON sd.sub_id=sf.fk_sub_id JOIN tt_regularmain ttr ON ttr.regulation=sd.regulation JOIN tt_regularsub tts ON ttr.tm_id=tts.fk_ttregmain_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0' AND tts.day_id='$day' AND sd.course=ttr.fk_course_id AND sd.dept=ttr.fk_dept_id AND sd.year=ttr.year AND sd.sem=ttr.sem AND tts.fk_sub_id=sd.sub_id ORDER BY tts.hour_no ASC");
            echo '<option value="">Select Hour</option>';
            // echo '<option value="">'.$a[0]['id'].'-day</option>';
            for($i=0; $i<sizeof($data); $i++)
            {
                echo '<option value="'.$data[$i]['hour_no'].'">'.$data[$i]['hour_no'].'</option>';
            }
        }
    }
    public static function gethoursubject()
    {
        if(isset($_POST['date']))
        {
            $det = static::getdaybydate($_POST['date']);
            $a = Homem::getdata("SELECT * FROM `tt_days` WHERE `name`='$det'");
            $day = $a[0]['id'];
            Homem::getdata("SELECT * FROM `tt_workdays` WHERE `dates`='2021-04-30' AND `work`='1'");
            $data = Homem::getdata("SELECT sd.sub_id, sd.subname, tts.day_id, tts.hour_no FROM subject_data sd JOIN subject_faculty sf ON sd.sub_id=sf.fk_sub_id JOIN tt_regularmain ttr ON ttr.regulation=sd.regulation JOIN tt_regularsub tts ON ttr.tm_id=tts.fk_ttregmain_id WHERE sf.fk_user_id='$_SESSION[user_id]' AND sf.status='1' AND sf.completed='0' AND tts.day_id='$day' AND sd.course=ttr.fk_course_id AND sd.dept=ttr.fk_dept_id AND sd.year=ttr.year AND sd.sem=ttr.sem AND tts.fk_sub_id=sd.sub_id AND tts.hour_no='$_POST[hour]' ORDER BY tts.hour_no ASC");
            echo '<option value="">Select Subject</option>';
            for($i=0; $i<sizeof($data); $i++)
            {
                echo '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].'</option>';
            }
        }
    }
    public static function getnewfacsub()
    {
        if(isset($_POST['subject']))
        {
            $data = Homem::getdata("SELECT DISTINCT b.sub_id, b.subname FROM (SELECT sd.course, sd.dept, sd.regulation, sd.year, sd.sem, sf.student_year, sd.sub_id, sd.subname 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 sd.sub_id='$_POST[subject]' AND sf.status='1' AND sf.completed='0') a JOIN (SELECT sd.course, sd.dept, sd.regulation, sd.year, sd.sem, sf.student_year, sd.sub_id, sd.subname FROM subject_faculty sf JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_user_id='$_POST[faculty]' AND sf.status='1' AND sf.completed='0') b ON a.course=b.course AND a.dept=b.dept AND a.regulation=b.regulation AND a.year=b.year AND a.sem=b.sem");
            echo '<option value="">Select New Faculty Subject</option>';
            for($i=0; $i<sizeof($data); $i++)
            {
                echo '<option value="'.$data[$i]['sub_id'].'">'.$data[$i]['subname'].'</option>';
            }
        }
    }

    public static function approveadjustments()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 2)
        {
            echo '';
        }
    }
    public static function dailyttapproval()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 7 || $_SESSION['user_role'] == 6)
        {
            echo '';
        }
    }

    public static function todayscheduledexams()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $date = date('Y-m-d');
            $data = Homem::getdata("SELECT * FROM quiz_examtt qet JOIN subject_data sd ON sd.sub_id=qet.fk_sub_id WHERE `add_by`='$_SESSION[user_id]' AND `add_date`LIKE'%$date%' AND qet.status='1'");
            $a = '';
            $b = '';
            for($i=0; $i<sizeof($data); $i++)
            {
                $b .= '
                <tr>
                    <td>'.$data[$i]['subname'].'</td>
                    <td>'.static::quizexamtype($data[$i]['fk_quizexamtype']).'</td>
                    <td>'.$data[$i]['ftime'].'</td>
                    <td>'.$data[$i]['ttime'].'</td>
                </tr>
                ';
            }
            $a .= '<div class="row">
                        <div class="col-md-2"></div>
                        <div class="col-md-8">
                        <div class="table-responsive"><table class="table" border="1px">
                        <thead><tr><th colspan="4">Scheduled Exams</th></tr><tr><th>Subject Name</th><th>Exam Type</th><th>From time</th><th>To time</th></tr></thead>
                        '.$b.'</table></div>
                        </div>
                        <div class="col-md-2"></div>
                    </div>';
            if(sizeof($data)>0)
            {
                return $a;
            }
            else
            {
                return '';
            }
        }
    }
    public static function singletopicexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $subj = 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/savesingletopicexam" 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">SINGLE TOPIC EXAM</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="chapter" id="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                                <option value="">Select Chapter</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="topic" id="topic" class="form-control" onchange="getchaptwisetopicqcount()" required>
                                                                <option value="">Select Topic</option>
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qavailable" id="qavailable" class="form-control" placeholder="Questions Available" readonly required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qcount" id="qcount" class="form-control" placeholder="No. of Questions per Paper" onchange="compareques()" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="number" name="duration" id="duration" class="form-control" placeholder="Time Duration (Min)" required>
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromtime" id="fromtime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="From Time" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">
                                                            <input type="hidden" name="exam_type" id="exam_type" class="form-control" placeholder="Quiz Exam Type">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">                                            
                                                            <input type="text" name="totime" id="totime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="To Time" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            <div id="students"></div>
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                        '.static::todayscheduledexams().'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getsubjectchapters()
                {
                    var subject = document.getElementById("subject").value;
                    getstdntbelongtosub();
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsubjectchapters",
                        success: function(d){
                            $("#chapter").html(d);
                        }
                    });
                }
                function getstdntbelongtosub()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getstdntbelongtosub",
                        success: function(d){
                            $("#students").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 getchaptwisetopicqcount()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = document.getElementById("chapter").value;
                    var topic = document.getElementById("topic").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter, topic: topic},
                        url: "/Exams/getchaptwisetopicqcount",
                        success: function(d){
                            // console.log(d);
                            $("#qavailable").val(d);
                        }
                    });
                }
                function compareques()
                {
                    var qavailable = document.getElementById("qavailable").value;
                    var qcount = document.getElementById("qcount").value;
                    var a="";
                    if(qavailable < qcount)
                    {
                        swal("Sorry..", "Number of Questions are not enough.", "error");
                        $(".btnsubmit").hide();
                        $("#qcount").val(a);
                    }
                    else
                    {
                        $(".btnsubmit").show();
                    }
                }
            </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 savesingletopicexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            if(isset($_POST['subject']))
            {
                $chpt = array();
                $chpt[] = $_POST['chapter'];
                $chapter = json_encode($chpt);
                $tpc = array();
                $tpc[] = $_POST['topic'];
                $topic = json_encode($tpc);
                $from = explode("T", $_POST['fromtime']);
                $_POST['fromtime'] = $from[0].' '.$from[1];
                $to = explode("T", $_POST['totime']);
                $_POST['totime'] = $to[0].' '.$to[1];
                $date = date('Y-m-d H:i:s A');
                Homem::insert("INSERT INTO `quiz_examtt` (`e_id`, `fk_sub_id`, `chapters`, `topics`, `fk_user_id`, `fk_quizexamtype`, `q_available`, `q_count`, `t_duration`, `ftime`, `ttime`, `add_by`, `add_date`, `status`, `completed`) VALUES (NULL, '$_POST[subject]', '$chapter', '$topic', '$_SESSION[user_id]', '1', '$_POST[qavailable]', '$_POST[qcount]', '$_POST[duration]', '$_POST[fromtime]', '$_POST[totime]', '$_SESSION[user_id]', '$date', '1', '0')");
                $data = Homem::getdata("SELECT * FROM `quiz_examtt` WHERE `fk_sub_id`='$_POST[subject]' AND `q_count`='$_POST[qcount]' AND `add_by`='$_SESSION[user_id]'  AND `status`='1' AND `completed`='0' ORDER BY `e_id` DESC");
                $id = $data[0]['e_id'];
                $sdata = Homem::getdata("SELECT um.id, um.no, um.name FROM subject_faculty sf JOIN user_master um ON sf.student_year=um.fromyear JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.course=um.fk_course_id AND sd.dept=um.fk_dept_id AND sd.regulation=um.regulation");
                $qdata = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
                $q = array();
                for($a=0; $a<sizeof($qdata); $a++)
                {
                    $q[] = $qdata[$a]['id'];
                }
                for($i=0; $i<sizeof($sdata); $i++)
                {
                    // shuffle($q);
                    shuffle($q);
                    // $q = static::quesshuffle($q);
                    $ques = array_slice($q, 0, $_POST['qcount']);
                    // $ques = array_rand($q, $_POST['qcount']);
                    $q_id = array();
                    $q_shuffle = array();
                    $q_ans = array();
                    $q_type = array();
                    for($b=0; $b<sizeof($qdata); $b++)
                    {
                        for($j=0; $j<sizeof($ques); $j++)
                        {
                            if($qdata[$b]['id'] == $ques[$j])
                            {
                                $q_id[] = $ques[$j];
                                $q_type[] = $qdata[$b]['q_type'];
                                $q_ans[] = $qdata[$b]['q_correct'];
                                if($qdata[$b]['q_type'] == "1")
                                {
                                    $q_shuffle[] = str_shuffle("0123");
                                }
                                else
                                {
                                    $q_shuffle[] = "0";
                                }
                            }
                        }
                    }
                    $qid = json_encode($q_id);
                    $qans = json_encode($q_ans);
                    $qshuffle = json_encode($q_shuffle);
                    $qtype = json_encode($q_type);
                    $sid = $sdata[$i]['id'];
                    Homem::insert("INSERT INTO `quiz_exam_paper` (`ep_id`, `fk_qett_id`, `fk_stdnt_id`, `q_id`, `q_ans`, `q_shuffle`, `q_type`, `status`, `completed`, `cancelled`, `remarks`) VALUES 
                    (NULL, '$id', '$sid', '$qid', '$qans', '$qshuffle', '$qtype', '1', '0', '0', '0')");
                }
                echo '<script>window.location = "/Exams/singletopicexam?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/singletopicexam?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Exams/singletopicexam?status=0";</script>';
        }
    }
    public static function singlechaptexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $subj = 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/savesinglechaptexam" 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">SINGLE CHAPTER EXAM</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="chapter" id="chapter" class="form-control" onchange="getchaptwiseqcount()" required>
                                                                <option value="">Select Chapter</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qavailable" id="qavailable" class="form-control" placeholder="Questions Available" readonly required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qcount" id="qcount" class="form-control" placeholder="No. of Questions per Paper" onchange="compareques()" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="number" name="duration" id="duration" class="form-control" placeholder="Time Duration (Min)" required>
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromtime" id="fromtime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="From Time" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">
                                                            <input type="hidden" name="exam_type" id="exam_type" class="form-control" placeholder="Quiz Exam Type">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">                                            
                                                            <input type="text" name="totime" id="totime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="To Time" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            <div id="students"></div>
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                        '.static::todayscheduledexams().'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                            getstdntbelongtosub();
                        }
                    });
                }
                function getstdntbelongtosub()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getstdntbelongtosub",
                        success: function(d){
                            $("#students").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 getchaptwiseqcount()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = document.getElementById("chapter").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter},
                        url: "/Exams/getchaptwiseqcount",
                        success: function(d){
                            // console.log(d);
                            $("#qavailable").val(d);
                        }
                    });
                }
                function compareques()
                {
                    var qavailable = document.getElementById("qavailable").value;
                    var qcount = document.getElementById("qcount").value;
                    var a="";
                    if(qavailable < qcount)
                    {
                        swal("Sorry..", "Number of Questions are not enough.", "error");
                        $(".btnsubmit").hide();
                        $("#qcount").val(a);
                    }
                    else
                    {
                        $(".btnsubmit").show();
                    }
                }
            </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 savesinglechaptexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            if(isset($_POST['subject']))
            {
                $chpt = array();
                $chpt[] = $_POST['chapter'];
                $chapter = json_encode($chpt);
                $tpc = array();
                $tpc[] = '';
                $topic = json_encode($tpc);
                $from = explode("T", $_POST['fromtime']);
                $_POST['fromtime'] = $from[0].' '.$from[1];
                $to = explode("T", $_POST['totime']);
                $_POST['totime'] = $to[0].' '.$to[1];
                $date = date('Y-m-d H:i:s A');
                Homem::insert("INSERT INTO `quiz_examtt` (`e_id`, `fk_sub_id`, `chapters`, `topics`, `fk_user_id`, `fk_quizexamtype`, `q_available`, `q_count`, `t_duration`, `ftime`, `ttime`, `add_by`, `add_date`, `status`, `completed`) VALUES (NULL, '$_POST[subject]', '$chapter', '$topic', '$_SESSION[user_id]', '2', '$_POST[qavailable]', '$_POST[qcount]', '$_POST[duration]', '$_POST[fromtime]', '$_POST[totime]', '$_SESSION[user_id]', '$date', '1', '0')");
                $data = Homem::getdata("SELECT * FROM `quiz_examtt` WHERE `fk_sub_id`='$_POST[subject]' AND `q_count`='$_POST[qcount]' AND `add_by`='$_SESSION[user_id]'  AND `status`='1' AND `completed`='0' ORDER BY `e_id` DESC");
                $id = $data[0]['e_id'];
                $sdata = Homem::getdata("SELECT um.id, um.no, um.name FROM subject_faculty sf JOIN user_master um ON sf.student_year=um.fromyear JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.course=um.fk_course_id AND sd.dept=um.fk_dept_id AND sd.regulation=um.regulation");
                $qdata = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
                $q = array();
                for($a=0; $a<sizeof($qdata); $a++)
                {
                    $q[] = $qdata[$a]['id'];
                }
                for($i=0; $i<sizeof($sdata); $i++)
                {
                    shuffle($q);
                    shuffle($q);
                    $ques = array_slice($q, 0, $_POST['qcount']);
                    $q_id = array();
                    $q_shuffle = array();
                    $q_ans = array();
                    $q_type = array();
                    for($b=0; $b<sizeof($qdata); $b++)
                    {
                        for($j=0; $j<sizeof($ques); $j++)
                        {
                            if($qdata[$b]['id'] == $ques[$j])
                            {
                                $q_id[] = $ques[$j];
                                $q_type[] = $qdata[$b]['q_type'];
                                $q_ans[] = $qdata[$b]['q_correct'];
                                if($qdata[$b]['q_type'] == "1")
                                {
                                    $q_shuffle[] = str_shuffle("0123");
                                }
                                else
                                {
                                    $q_shuffle[] = "0";
                                }
                            }
                        }
                    }
                    $qid = json_encode($q_id);
                    $qans = json_encode($q_ans);
                    $qshuffle = json_encode($q_shuffle);
                    $sid = $sdata[$i]['id'];
                    $qtype = json_encode($q_type);
                    Homem::insert("INSERT INTO `quiz_exam_paper` (`ep_id`, `fk_qett_id`, `fk_stdnt_id`, `q_id`, `q_ans`, `q_shuffle`, `q_type`, `status`, `completed`, `cancelled`, `remarks`) VALUES 
                    (NULL, '$id', '$sid', '$qid', '$qans', '$qshuffle', '$qtype', '1', '0', '0', '0')");
                }
                echo '<script>window.location = "/Exams/singletopicexam?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/singletopicexam?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Exams/singletopicexam?status=0";</script>';
        }
    }
    public static function multiplechaptexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $subj = 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/savemultiplechaptexam" 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">MULTIPLE CHAPTER EXAM</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <select name="chapter[]" id="chapter" multiple="multiple" class="form-control" onchange="getchaptwiseqcount()" required>
                                                                <option value="">Select Chapter</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qavailable" id="qavailable" class="form-control" placeholder="Questions Available" readonly required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qcount" id="qcount" class="form-control" placeholder="No. of Questions per Paper" onchange="compareques()" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="number" name="duration" id="duration" class="form-control" placeholder="Time Duration (Min)" required>
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromtime" id="fromtime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="From Time" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">
                                                            <input type="hidden" name="exam_type" id="exam_type" class="form-control" placeholder="Quiz Exam Type">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">                                            
                                                            <input type="text" name="totime" id="totime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="To Time" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            <div id="students"></div>
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                        '.static::todayscheduledexams().'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            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);
                            getstdntbelongtosub();
                        }
                    });
                }
                function getstdntbelongtosub()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getstdntbelongtosub",
                        success: function(d){
                            $("#students").html(d);
                        }
                    });
                }
                function getchaptwiseqcounttest()
                {
                    var chapter = document.getElementById("chapter").value;
                    var selected = [];
                    for (var option of document.getElementById("chapter").options)
                    {
                        if (option.selected) {
                            selected.push(option.value);
                        }
                    }
                    return selected;
                }
                function getchaptwiseqcount()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = getchaptwiseqcounttest();
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter},
                        url: "/Exams/getmutiplechaptwiseqcount",
                        success: function(d){
                            // console.log(d);
                            $("#qavailable").val(d);
                        }
                    });
                }
                function compareques()
                {
                    var qavailable = document.getElementById("qavailable").value;
                    var qcount = document.getElementById("qcount").value;
                    var a="";
                    if(qavailable < qcount)
                    {
                        swal("Sorry..", "Number of Questions are not enough.", "error");
                        $(".btnsubmit").hide();
                        $("#qcount").val(a);
                    }
                    else
                    {
                        $(".btnsubmit").show();
                    }
                }
            </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 savemultiplechaptexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            if(isset($_POST['subject']))
            {
                $chpt = $_POST['chapter'];
                foreach($chpt as $key => $val)
                {
                    if(empty($val))
                    {
                        unset($chpt[$key]);
                    } 
                }
                sort($chpt);
                $chapter = json_encode($chpt);
                $tpc = array();
                $tpc[] = '';
                $topic = json_encode($tpc);
                $from = explode("T", $_POST['fromtime']);
                $_POST['fromtime'] = $from[0].' '.$from[1];
                $to = explode("T", $_POST['totime']);
                $_POST['totime'] = $to[0].' '.$to[1];
                $date = date('Y-m-d H:i:s A');
                Homem::insert("INSERT INTO `quiz_examtt` (`e_id`, `fk_sub_id`, `chapters`, `topics`, `fk_user_id`, `fk_quizexamtype`, `q_available`, `q_count`, `t_duration`, `ftime`, `ttime`, `add_by`, `add_date`, `status`, `completed`) VALUES (NULL, '$_POST[subject]', '$chapter', '$topic', '$_SESSION[user_id]', '3', '$_POST[qavailable]', '$_POST[qcount]', '$_POST[duration]', '$_POST[fromtime]', '$_POST[totime]', '$_SESSION[user_id]', '$date', '1', '0')");
                $data = Homem::getdata("SELECT * FROM `quiz_examtt` WHERE `fk_sub_id`='$_POST[subject]' AND `q_count`='$_POST[qcount]' AND `add_by`='$_SESSION[user_id]'  AND `status`='1' AND `completed`='0' ORDER BY `e_id` DESC");
                $id = $data[0]['e_id'];
                $sdata = Homem::getdata("SELECT um.id, um.no, um.name FROM subject_faculty sf JOIN user_master um ON sf.student_year=um.fromyear JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.course=um.fk_course_id AND sd.dept=um.fk_dept_id AND sd.regulation=um.regulation");
                
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='".$_POST['subject']."' AND".static::mutiplechaptwiseqselectquery($chpt)." AND `fk_user_id`='".$_SESSION['user_id']."' AND `status`='1' AND `q_lock`='1'";
                $qdata = Homem::getdata($query);
                $q = array();
                for($a=0; $a<sizeof($qdata); $a++)
                {
                    $q[] = $qdata[$a]['id'];
                }
                for($i=0; $i<sizeof($sdata); $i++)
                {
                    shuffle($q);
                    shuffle($q);
                    $ques = array_slice($q, 0, $_POST['qcount']);
                    $q_id = array();
                    $q_shuffle = array();
                    $q_ans = array();
                    $q_type = array();
                    for($b=0; $b<sizeof($qdata); $b++)
                    {
                        for($j=0; $j<sizeof($ques); $j++)
                        {
                            if($qdata[$b]['id'] == $ques[$j])
                            {
                                $q_id[] = $ques[$j];
                                $q_type[] = $qdata[$b]['q_type'];
                                $q_ans[] = $qdata[$b]['q_correct'];
                                if($qdata[$b]['q_type'] == "1")
                                {
                                    $q_shuffle[] = str_shuffle("0123");
                                }
                                else
                                {
                                    $q_shuffle[] = "0";
                                }
                            }
                        }
                    }
                    $qid = json_encode($q_id);
                    $qans = json_encode($q_ans);
                    $qshuffle = json_encode($q_shuffle);
                    $sid = $sdata[$i]['id'];
                    $qtype = json_encode($q_type);
                    Homem::insert("INSERT INTO `quiz_exam_paper` (`ep_id`, `fk_qett_id`, `fk_stdnt_id`, `q_id`, `q_ans`, `q_shuffle`, `q_type`, `status`, `completed`, `cancelled`, `remarks`) VALUES 
                    (NULL, '$id', '$sid', '$qid', '$qans', '$qshuffle', '$qtype', '1', '0', '0', '0')");
                }
                echo '<script>window.location = "/Exams/multiplechaptexam?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/multiplechaptexam?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Exams/multiplechaptexam?status=0";</script>';
        }
    }
    public static function multipletopicexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            $subj = 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/savemultipletopicexam" 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">MULTIPLE TOPIC EXAM</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectchapters()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="chapter" id="chapter" class="form-control" onchange="getsubchaptopics()" required>
                                                                <option value="">Select Chapter</option>
                                                            </select>
                                                        </div>
                                                    </div>   
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <select name="topic[]" id="topic" multiple="multiple" class="form-control" onchange="getchaptwisetopicqcount()" required>
                                                                <option value="">Select Topics</option>
                                                            </select>
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qavailable" id="qavailable" class="form-control" placeholder="Questions Available" readonly required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="qcount" id="qcount" class="form-control" placeholder="No. of Questions per Paper" onchange="compareques()" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="number" name="duration" id="duration" class="form-control" placeholder="Time Duration (Min)" required>
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromtime" id="fromtime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="From Time" required>
                                                        </div>
                                                    </div> 
                                                    <div class="col-lg-4">
                                                        <div class="form-group">
                                                            <input type="hidden" name="exam_type" id="exam_type" class="form-control" placeholder="Quiz Exam Type">
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">                                            
                                                            <input type="text" name="totime" id="totime" class="form-control" onfocus="(this.type=`datetime-local`)" onblur="(this.type=`text`)"  placeholder="To Time" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            <div id="students"></div>
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                        '.static::todayscheduledexams().'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getsubjectchapters()
                {
                    var subject = document.getElementById("subject").value;
                    getstdntbelongtosub();
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getsubjectchapters",
                        success: function(d){
                            $("#chapter").html(d);
                        }
                    });
                }
                function getstdntbelongtosub()
                {
                    var subject = document.getElementById("subject").value;
                    $.ajax({
                        type: "POST",
                        data : {subject: subject},
                        url: "/Exams/getstdntbelongtosub",
                        success: function(d){
                            $("#students").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 getchaptwiseqcounttest()
                {
                    var chapter = document.getElementById("topic").value;
                    var selected = [];
                    for (var option of document.getElementById("topic").options)
                    {
                        if (option.selected) {
                            selected.push(option.value);
                        }
                    }
                    return selected;
                }
                function getchaptwisetopicqcount()
                {
                    var subject = document.getElementById("subject").value;
                    var chapter = document.getElementById("chapter").value;
                    var topic = getchaptwiseqcounttest();
                    // console.log(topic);
                    $.ajax({
                        type: "POST",
                        data : {subject: subject, chapter: chapter, topic: topic},
                        url: "/Exams/getchaptwisemultitopicqcount",
                        success: function(d){
                            // console.log(d);
                            $("#qavailable").val(d);
                        }
                    });
                }
                function compareques()
                {
                    var qavailable = document.getElementById("qavailable").value;
                    var qcount = document.getElementById("qcount").value;
                    var a="";
                    if(qavailable < qcount)
                    {
                        swal("Sorry..", "Number of Questions are not enough.", "error");
                        $(".btnsubmit").hide();
                        $("#qcount").val(a);
                    }
                    else
                    {
                        $(".btnsubmit").show();
                    }
                }
            </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 savemultipletopicexam()
    {
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2 || $_SESSION['user_role'] == 6)
        {
            if(isset($_POST['subject']))
            {
                $chpt = array();
                $chpt[] = $_POST['chapter'];
                $chapter = json_encode($chpt);
                $tpc = $_POST['topic'];
                $topic = json_encode($tpc);
                $from = explode("T", $_POST['fromtime']);
                $_POST['fromtime'] = $from[0].' '.$from[1];
                $to = explode("T", $_POST['totime']);
                $_POST['totime'] = $to[0].' '.$to[1];
                $date = date('Y-m-d H:i:s A');
                Homem::insert("INSERT INTO `quiz_examtt` (`e_id`, `fk_sub_id`, `chapters`, `topics`, `fk_user_id`, `fk_quizexamtype`, `q_available`, `q_count`, `t_duration`, `ftime`, `ttime`, `add_by`, `add_date`, `status`, `completed`) VALUES (NULL, '$_POST[subject]', '$chapter', '$topic', '$_SESSION[user_id]', '4', '$_POST[qavailable]', '$_POST[qcount]', '$_POST[duration]', '$_POST[fromtime]', '$_POST[totime]', '$_SESSION[user_id]', '$date', '1', '0')");
                $data = Homem::getdata("SELECT * FROM `quiz_examtt` WHERE `fk_sub_id`='$_POST[subject]' AND `q_count`='$_POST[qcount]' AND `add_by`='$_SESSION[user_id]'  AND `status`='1' AND `completed`='0' ORDER BY `e_id` DESC");
                $id = $data[0]['e_id'];
                $sdata = Homem::getdata("SELECT um.id, um.no, um.name FROM subject_faculty sf JOIN user_master um ON sf.student_year=um.fromyear JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.course=um.fk_course_id AND sd.dept=um.fk_dept_id AND sd.regulation=um.regulation");
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND ".static::mutipletopicwiseqselectquery($tpc)." AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'";
                // echo $query;
                $qdata = Homem::getdata($query);
                $q = array();
                for($a=0; $a<sizeof($qdata); $a++)
                {
                    $q[] = $qdata[$a]['id'];
                }
                for($i=0; $i<sizeof($sdata); $i++)
                {
                    shuffle($q);
                    // shuffle($q);
                    $ques = array_slice($q, 0, $_POST['qcount']);
                    $q_id = array();
                    $q_shuffle = array();
                    $q_ans = array();
                    $q_type = array();
                    for($b=0; $b<sizeof($qdata); $b++)
                    {
                        for($j=0; $j<sizeof($ques); $j++)
                        {
                            if($qdata[$b]['id'] == $ques[$j])
                            {
                                $q_id[] = $ques[$j];
                                $q_type[] = $qdata[$b]['q_type'];
                                $q_ans[] = $qdata[$b]['q_correct'];
                                if($qdata[$b]['q_type'] == "1")
                                {
                                    $q_shuffle[] = str_shuffle("0123");
                                }
                                else
                                {
                                    $q_shuffle[] = "0";
                                }
                            }
                        }
                    }
                    $qid = json_encode($q_id);
                    $qans = json_encode($q_ans);
                    $qshuffle = json_encode($q_shuffle);
                    $qtype = json_encode($q_type);
                    $sid = $sdata[$i]['id'];
                    Homem::insert("INSERT INTO `quiz_exam_paper` (`ep_id`, `fk_qett_id`, `fk_stdnt_id`, `q_id`, `q_ans`, `q_shuffle`, `q_type`, `status`, `completed`, `cancelled`, `remarks`) VALUES 
                    (NULL, '$id', '$sid', '$qid', '$qans', '$qshuffle', '$qtype', '1', '0', '0', '0')");
                }
                echo '<script>window.location = "/Exams/multipletopicexam?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Exams/multipletopicexam?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Exams/multipletopicexam?status=0";</script>';
        }
    }
    public static function mutipletopicwiseqselectquery($a)
    {
        if(isset($a))
        {
            if(is_array($a))
            {
                foreach($a as $key => $val)
                {
                    if(empty($val))
                    {
                        unset($a[$key]);
                    } 
                }
                sort($a);
                $b = '';
                if(sizeof($a) >= 2)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($a[$i] != '')
                        {
                            if($i == 0)
                            {
                                $b .= "(`topic`='".$a[$i]."' OR ";
                            }
                            if($i < sizeof($a)-1 && $i != 0)
                            {
                                $b .= "`topic`='".$a[$i]."' OR ";
                            }
                            if($i == sizeof($a)-1 && $i!=0)
                            {
                                $b .= "`topic`='".$a[$i]."') ";
                            }
                        }
                    }
                }
                if(sizeof($a) == 1)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($i == 0)
                        {
                            if($a[$i] != '')
                            {
                                $b .= "(`topic`='".$a[$i]."')";
                            }
                        }
                    }
                }
                return $b;
            }
        }
    }
    public static function mutiplechaptwiseqselectquery($a)
    {
        if(isset($a))
        {
            if(is_array($a))
            {
                foreach($a as $key => $val)
                {
                    if(empty($val))
                    {
                        unset($a[$key]);
                    } 
                }
                sort($a);
                $b = '';
                if(sizeof($a) >= 2)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($a[$i] != '')
                        {
                            if($i == 0)
                            {
                                $b .= "(`chapter`='".$a[$i]."' OR ";
                            }
                            if($i < sizeof($a)-1 && $i != 0)
                            {
                                $b .= "`chapter`='".$a[$i]."' OR ";
                            }
                            if($i == sizeof($a)-1 && $i!=0)
                            {
                                $b .= "`chapter`='".$a[$i]."') ";
                            }
                        }
                    }
                }
                if(sizeof($a) == 1)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($i == 0)
                        {
                            if($a[$i] != '')
                            {
                                $b .= "(`chapter`='".$a[$i]."')";
                            }
                        }
                    }
                }
                return $b;
            }
        }
    }
    public static function getstdntbelongtosub()
    {
        if(isset($_POST['subject']))
        {
            $a = '';
            $sdata = Homem::getdata("SELECT um.id, um.no, um.name FROM subject_faculty sf JOIN user_master um ON sf.student_year=um.fromyear JOIN subject_data sd ON sf.fk_sub_id=sd.sub_id WHERE sf.fk_sub_id='$_POST[subject]' AND sf.fk_user_id='$_SESSION[user_id]' AND sd.course=um.fk_course_id AND sd.dept=um.fk_dept_id AND sd.regulation=um.regulation");
            $a .= '<div class="table-responsive"><table class="table" border="1px"><thead><tr><th colspan="3">Total Number of Studnets Eligible for this subject is : '.sizeof($sdata).'</th></tr><tr>';
            $a .= '<th>S. No.</th><th>Hallticket Number</th><th>Name</th>';
            $a .= '</tr></thead>';
            $a .= '<tbody>';
            for($i=0; $i<sizeof($sdata); $i++)
            {
                $j = $i+1;
                $a .= '<tr><td>'.$j.'</td><td>'.$sdata[$i]['no'].'</td><td>'.$sdata[$i]['name'].'</td></tr>';
            }
            $a .= '</tbody></table>';
            echo $a;
            // echo sizeof($sdata);
        }
    }
    public static function getchaptwisetopicqcount()
    {
        if(isset($_POST['chapter']))
        {
            $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `topic`='$_POST[topic]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
            echo sizeof($data);
        }
    }
    public static function getchaptwisemultitopicqcount()
    {
        if(isset($_POST['chapter']))
        {
            if(is_array($_POST['topic']))
            {
                $a = $_POST['topic'];
                foreach($a as $key => $val)
                {
                    if(empty($val))
                    {
                        unset($a[$key]);
                    } 
                }
                sort($a);
                $b = '';
                if(sizeof($a) >= 2)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($a[$i] != '')
                        {
                            if($i == 0)
                            {
                                $b .= "(`topic`='".$a[$i]."' OR ";
                            }
                            if($i < sizeof($a)-1 && $i != 0)
                            {
                                $b .= "`topic`='".$a[$i]."' OR ";
                            }
                            if($i == sizeof($a)-1 && $i!=0)
                            {
                                $b .= "`topic`='".$a[$i]."') ";
                            }
                        }
                    }
                }
                if(sizeof($a) == 1)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($i == 0)
                        {
                            if($a[$i] != '')
                            {
                                $b .= "(`topic`='".$a[$i]."')";
                            }
                        }
                    }
                }
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND ".$b." AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'";
                $data = Homem::getdata($query);
                echo sizeof($data);
            }
        }
    }
    public static function getchaptwiseqcount()
    {
        if(isset($_POST['chapter']))
        {
            $data = Homem::getdata("SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='$_POST[subject]' AND `chapter`='$_POST[chapter]' AND `fk_user_id`='$_SESSION[user_id]' AND `status`='1' AND `q_lock`='1'");
            echo sizeof($data);
        }
    }
    public static function getmutiplechaptwiseqcount()
    {
        if(isset($_POST['chapter']))
        {
            if(is_array($_POST['chapter']))
            {
                $a = $_POST['chapter'];
                foreach($a as $key => $val)
                {
                    if(empty($val))
                    {
                        unset($a[$key]);
                    } 
                }
                sort($a);
                $b = '';
                if(sizeof($a) >= 2)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($a[$i] != '')
                        {
                            if($i == 0)
                            {
                                $b .= "(`chapter`='".$a[$i]."' OR ";
                            }
                            if($i < sizeof($a)-1 && $i != 0)
                            {
                                $b .= "`chapter`='".$a[$i]."' OR ";
                            }
                            if($i == sizeof($a)-1 && $i!=0)
                            {
                                $b .= "`chapter`='".$a[$i]."') ";
                            }
                        }
                    }
                }
                if(sizeof($a) == 1)
                {
                    for($i=0; $i<sizeof($a); $i++)
                    {
                        if($i == 0)
                        {
                            if($a[$i] != '')
                            {
                                $b .= "(`chapter`='".$a[$i]."')";
                            }
                        }
                    }
                }
                $query = "SELECT * FROM `quiz_question_master` WHERE `fk_sub_id`='".$_POST['subject']."' AND ".$b."AND `fk_user_id`='".$_SESSION['user_id']."' AND `status`='1' AND `q_lock`='1'";
                $data = Homem::getdata($query);
                echo sizeof($data);
            }
        }
    }
    public static function examanswershuffle($qid, $qno, $type, $shuffle, $options, $answers)
    {
        if($type == 1)
        {
            $options = unserialize($options);
			$answers = unserialize($answers);
            $shuff = str_split($shuffle);
            $ans = array();
            $ab = '';
            for($a=0; $a<sizeof($answers); $a++)
            {
                $b =$a+1;
                $ans[] = '<input type="radio" id="'.$qid.'_'.$b.'" name="A['.$qno.']" value="'.$qid.'_'.$b.'" required /> &nbsp;'.$answers[$a];
            }
            
            for($a=0; $a<sizeof($shuff); $a++)
			{
                $ab .= '<div class="col-lg-6">';
                $ab .= $ans[$shuff[$a]];
                $ab .= '</div>';
            }
            return $ab;
        }
        if($type == 2)
        {
            $ab = '';
            $ab .= '<div class="col-lg-4">';
            $ab .= '<input type="text" id="'.$qid.'_1" name="A['.$qno.']" value="" class="form-control" required />';
            $ab .= '</div>';
            $ab .= '<div class="col-lg-8"></div>';
            return $ab;
        }
        if($type == 3)
        {
            $ab = '';
            $ab .= '<div class="col-lg-4">';
            $ab .= '<input type="number" step="any" id="'.$qid.'_1" name="A['.$qno.']" value="" class="form-control" required>';
            $ab .= '</div>';
            $ab .= '<div class="col-lg-8"></div>';
            return $ab;
        }
        // return '<div class="col-lg-12">testy</div>';
        // print_r(str_split($shuffle));
    }
    public static function quizexamtype($id)
    {
        if(isset($id))
        {
            if($id == 1)
            {
                return 'Single Topic Exam';
            }
            else if($id == 2)
            {
                return 'Single Chapter Exam';
            }
            else if($id == 3)
            {
                return 'Multiple Chapter Unit';
            }
            else if($id == 4)
            {
                return 'Multiple Topic Exam';
            }
            else
            {
                return 'Exam';
            }
        }
    }
    public static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    public static function datetimem($id)
    {
        $date = explode(" ", $id);
        $data = explode('-', $date[0]);
        $final = $data[2].'-'.$data[1].'-'.$data[0].' '.$date[1];
        return $final;
    }
    public static function scheduledexams()
    {
        if($_SESSION['user_role'] == 3)
        {
            $data = Homem::getdata("SELECT qett.e_id, qett.fk_user_id, qett.add_by, qep.ep_id, qett.fk_sub_id, qett.t_duration, sd.subcode, sd.subname, ss.chapt_no, ss.chapt_name, ss.chapt_topics, um.name, sd.subname, qett.chapters, qett.topics, qett.fk_quizexamtype, qett.t_duration, qett.ftime, qett.ttime, qep.q_id FROM quiz_examtt qett JOIN quiz_exam_paper qep ON qett.e_id=qep.fk_qett_id JOIN subject_data sd ON qett.fk_sub_id=sd.sub_id JOIN user_master um ON qett.add_by=um.id JOIN subject_syllabus ss ON ss.fk_sub_id=qett.fk_sub_id WHERE qep.fk_stdnt_id='$_SESSION[user_id]' AND qett.status='1' AND qett.completed='0' AND qep.status='1' AND qep.completed='0' AND qep.cancelled='0' AND ss.add_by=qett.fk_user_id");
            $a = '';
            date_default_timezone_set('Asia/Kolkata');
            $date = date('Y-m-d H:i');
            $past = date("Y-m-d", strtotime("-2 days")).' '.'00:01';
            $future = date("Y-m-d", strtotime("+2 days")).' '.'00:01';
            $exid = array();
            foreach ($data as $h) {
                $exid[] = $h['e_id'];
            }
            $no = array_values(array_unique($exid));
            sort($no);
            for($j=0; $j<sizeof($no); $j++)
            {
                $status = 0;
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]['e_id'] == $no[$j] && $status == 0)
                    {
                        $status = 1;
                        $eid = $data[$i]['e_id'];
                        $pid = $data[$i]['ep_id'];
                        $count = Homem::getdata("SELECT * FROM `quiz_exam_answers` WHERE `fk_exam_id`='$eid' AND `fk_paper_id`='$pid' AND `fk_student_id`='$_SESSION[user_id]'");
                        if(sizeof($count) == 0)
                        {
                            if((strtotime($date) > strtotime($past)) && (strtotime($date) < strtotime($future)))
                            {
                                $button = '';
                                if((strtotime($date) > strtotime($data[$i]['ftime'])) && (strtotime($date) < strtotime($data[$i]['ttime'])))
                                {
                                    $button = '
                                            <div class="row">
                                                <div class="col-md-8"></div>
                                                <div class="col-md-4">  
                                                    <div class="form-group float-right">
                                                        <button class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Start Exam</button>
                                                    </div>
                                                </div>
                                            </div>';
                                }
                                $fid = $data[$i]['fk_user_id'];
                                $subid= $data[$i]['fk_sub_id'];
                                $sdata = Homem::getdata("SELECT * FROM subject_data sd JOIN subject_syllabus ss ON sd.sub_id=ss.fk_sub_id WHERE ss.add_by='$fid' AND sd.sub_id='$subid'");
                                $q = json_decode($data[$i]['q_id'], true);
                                $qno = sizeof($q);
                                $t = json_decode($data[$i]['topics'], true);
                                $tno = sizeof($t);
                                $ttopics = explode(",", $data[$i]['chapt_topics']);
                                $topic ='';
                                $a .=  '<div class="shadow-lg p-3 mb-5 bg-white rounded">
                                        <div class="row">
                                            <div class="col-md-12">
                                                <form action="/Exams/exam" method="POST">
                                                    <div class="row">
                                                        <div class="col-md-8">
                                                            <input type="hidden" name="examid" id="examid" class="form-control" value="'.$data[$i]['e_id'].'"required readonly>
                                                            <input type="hidden" name="paperid" id="paperid" class="form-control" value="'.$data[$i]['ep_id'].'"required readonly>
                                                            <input type="hidden" name="user_id" id="faculty_id" class="form-control" value="'.$data[$i]['add_by'].'"required readonly>
                                                            <input type="hidden" name="subjectid" id="subjectid" class="form-control" value="'.$data[$i]['fk_sub_id'].'"required readonly>
                                                            <span style="color:red;">Subject Name: </span><span style="color:green;"><strong>'.$data[$i]['subname'].'('.$data[$i]['subcode'].')</strong></span>
                                                            <br />
                                                            <span style="color:red;">Chapter Name: </span><span style="color:green;">'.$data[$i]['chapt_name'].'</strong>
                                                            <br />';
                                                            if($data[$i]['fk_quizexamtype'] == 1)
                                                            {
                                                                $a .= '<span style="color:red;">Topic Name: </span><span style="color:green;">'.$ttopics[$t[0]-1].'</strong>
                                                                        <br />';
                                                            }
                                    $a .=                  '<span style="color:red;">Exam Type: </span><span style="color:green;">'.static::quizexamtype($data[$i]['fk_quizexamtype']).'</strong>
                                                            <br />
                                                            <span style="color:red;">Conducted By: </span><span style="color:green;">'.$data[$i]['name'].'</strong>
                                                        </div>
                                                        <div class="col-md-4">
                                                            <span style="color:red;">Scheduled Exam Timings: </span><span style="color:green;">'.static::datetimem($data[$i]['ftime']).' to '.static::datetimem($data[$i]['ttime']).'</span>
                                                            <br />
                                                            <span style="color:red;">Number of Questions: </span><span style="color:green;">'.$qno.'</span>
                                                            <br />
                                                            <span style="color:red;">Exam Duration: </span><span style="color:green;">'.$data[$i]['t_duration'].' Mins</span>
                                                        </div>
                                                    </div>
                                                    '.$button.'
                                                </form>
                                            </div>
                                        </div>
                                    </div>';
                            }
                        }
                    }
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <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">SCHEDULED EXAMS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            '.$a.'
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>document.cookie = "myanswers = 0";</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 completedexams()
    {
        $a = '';
        if($_SESSION['user_role'] == 3)
        {
            $data = Homem::getdata("SELECT qep.ep_id, qea.qa_id, sd.subcode, sd.subname, qea.fk_paper_id, qea.answers, qep.q_ans, qep.q_shuffle, qea.fromtime, qea.totime, qea.marks, qea.status, qea.completed FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN subject_data sd ON sd.sub_id=qet.fk_sub_id WHERE qea.fk_student_id='$_SESSION[user_id]' ORDER BY qea.qa_id DESC");
            for($i=0; $i<sizeof($data); $i++)
            {
                $written = json_decode($data[$i]['answers'], true);
                $actual = json_decode($data[$i]['q_ans'], true);
                $ansid = $data[$i]['qa_id'];
                $epid = $data[$i]['ep_id'];
                $qshuffle = $data[$i]['q_shuffle'];
                $marks = 0;
                for($j=0; $j<sizeof($written); $j++)
                {
                    if($qshuffle[$j] != 0)
                    {
                        if($written[$j] == $actual[$j])
                        {
                            $marks++;
                        }
                    }
                    else
                    {
                        if(is_numeric($written[$j]))
                        {
                            echo '';
                        }
                    }
                }
                if($data[$i]['marks'] == "")
                {
                    Homem::insert("UPDATE `quiz_exam_answers` SET `marks`='$marks' AND `completed`='1' WHERE `qa_id`='$ansid' AND `fk_student_id`='$_SESSION[user_id]'");
                    Homem::insert("UPDATE `quiz_exam_paper` SET `completed`='1' WHERE `ep_id`='$epid' AND `fk_stdnt_id`='$_SESSION[user_id]'");
                }
                $nmarks[$i] = $marks;
            }
            echo is_numeric($a);
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <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">COMPLETED EXAM REPORTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            '.$a.'
                                                        </div>
                                                    </div>                         
                                                </div>
                                                <div class="row btnsubmit" style="display:none;">
                                                    <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">
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "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 questionquery($q_id, $sub_id, $user_id)
    {
        $a = $q_id;
        $query1 = '';
        for($i=0; $i<sizeof($a); $i++)
        {
            if($i == 0)
            {
                $query1 .= "(`id`='".$a[$i]."' OR ";
            }
            if($i!=0 && $i < (sizeof($a)-1))
            {
                $query1 .= "`id`='".$a[$i]."' OR ";
            }
            if($i == (sizeof($a)-1))
            {
                $query1 .= "`id`='".$a[$i]."')";
            }
        }
        $query = 'SELECT * FROM `quiz_question_master` WHERE ';
        $query2 = " AND `fk_sub_id`='$sub_id' AND `fk_user_id`='$user_id' AND `status`='1' AND `q_lock`='1'";
        $query = $query.$query1.$query2;
        $data = Homem::getdata($query);
        return json_encode($data);
    }
    public static function studentquesformat($q_id, $data, $q_shuffle)
    {
        $a = '';
        $k = 0;
        for($i=0; $i<sizeof($q_id); $i++)
        {
            for($j=0; $j<sizeof($data); $j++)
            {
                if($data[$j]['id'] == $q_id[$i])
                {
                    $k++;
                    $options = '';
                    $answers = $data[$j]['q_answers'];
                    $ans = static::examanswershuffle($data[$j]['id'], $k, $data[$j]['q_type'], $q_shuffle[$i], $options, $answers);
                    $a .= '
                        <div class="shadow-lg p-3 mb-5 bg-white rounded">
                            <div class="row">
                                <div class="col-lg-1 col-centered">
                                    <div style="width: 25px; height: 25px; background-color: green; border: solid 1px red; border-radius: 50%;" ><center><b style="color: white;">'.$k.'</b></center></div>
                                </div>
                                <div class="col-lg-11">
                                    <input type="hidden" classs="form-control" name="qtype['.$k.']" id="qtype['.$k.']" value="'.$data[$j]['q_type'].'" required>
                                    <input type="hidden" id="Q['.$k.']" name="Q['.$k.']" value="'.$data[$j]['id'].'" required>';
                    if($data[$j]['q_type'] == 1)
                    {
                        $a .= '<input type="hidden" name="A['.$k.']" value="">';
                    }   
                    $a .= $data[$j]['q_text'].'
                                </div>
                            <div class="col-lg-1">
                            </div>
                            <div class="col-lg-11">
                                <div class="row">
                                    '.$ans.'
                                </div>
                            </div>
                        </div>
                    </div>';
                }
            }
        }
        return $a;
    }
    public static function exam()
    {
        if($_SESSION['user_role'] == 3)
        {
            $a = '';
            if(isset($_POST['examid']))
            {
                $examid = $_POST['examid'];
                $paperid = $_POST['paperid'];
                $userid = $_POST['user_id'];
                $subjectid = $_POST['subjectid'];
                $query = "SELECT * FROM quiz_examtt qet JOIN quiz_exam_paper qep ON qet.e_id=qep.fk_qett_id WHERE qet.fk_sub_id='$subjectid' AND qet.add_by='$userid' AND qep.ep_id='$paperid' AND qet.e_id='$examid' AND qep.fk_stdnt_id='$_SESSION[user_id]'";
                $data = Homem::getdata($query);
                if(sizeof($data) == 1)
                {
                    $pdata = Homem::getdata("SELECT * FROM `quiz_exam_answers` WHERE `fk_suject_id`='$subjectid' AND `fk_exam_id`='$examid' AND `fk_paper_id`='$paperid' AND `fk_student_id`='$_SESSION[user_id]' AND `status`='1'");
                    if(sizeof($pdata) == 0)
                    {
                        $_SESSION['exam_status'] = '0';
                        $papertime = $data[0]['t_duration'];
                        $qids = $data[0]['q_id'];
                        $qshuffle = $data[0]['q_shuffle'];
                        date_default_timezone_set('Asia/Kolkata');
                        $ptime = date("Y-m-d H:i:s");
                        $newtimestamp = strtotime($ptime." + ".$papertime." minute");
                        $start_time = $ptime;
                        $end_time = date('Y-m-d H:i:s', $newtimestamp);
                        $_SESSION['examid'] = $examid;
                        $_SESSION['paperid'] = $paperid;
                        $_SESSION['examinerid'] = $userid;
                        $_SESSION['subjectid'] = $subjectid;
                        $_SESSION['start_time'] = $start_time;
                        $_SESSION['end_time'] = $end_time;
                        $_SESSION['exam_status'] = '1';
                        $q_id = json_decode($qids, true);
                        $q_shuffle = json_decode($qshuffle, true);
                        $fdata = static::questionquery($q_id, $subjectid, $userid);
                        $data = json_decode($fdata, true);
                        $a = '
                            <div class="shadow-lg p-3 mb-5 bg-white rounded">
                                <div class="row">
                                    <div class="col-md-12">
                                        Time Remaining: <strong><span style="color:red;" id="timer">
                                        <input type="hidden" id="examstatus" name="examstatus" value="5" clas=="form-control" required>
                                        <input type="hidden" id="examid" name="examid" value="'.$examid.'" class="form-control" required/>
                                        <input type="hidden" id="paperid" name="paperid" value="'.$paperid.'" class="form-control" required/>
                                        <input type="hidden" id="facultyid" name="facultyid" value="'.$userid.'" class="form-control" required/>
                                        <input type="hidden" id="subjectid" name="subjectid" value="'.$subjectid.'" class="form-control" required/>
                                    </div> 
                                </div>
                            </div>';
                        $a .= static::studentquesformat($q_id, $data, $q_shuffle);
                        $body = '
                        <div class="clearfix"></div>
                        <form id="frm_exam" action="/Exams/saveexamanswer" 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">EXAM QUESTIONS</h4>
                                                    </header>
                                                    <div class="content-body"> 
                                                        <div class="row">
                                                            <div class="col-lg-12">
                                                                <div class="form-group">
                                                                    '.$a.'
                                                                    <!--     
                                                                        <div class="shadow-sm p-3 mb-5 bg-white rounded">
                                                                            Small shadow
                                                                        </div>
                                                                        <div class="shadow p-3 mb-5 bg-white rounded">
                                                                            Regular shadow
                                                                        </div>                                      
                                                                        <div class="shadow-lg p-3 mb-5 bg-white rounded">
                                                                            Larger shadow
                                                                        </div>
                                                                    -->
                                                                </div>
                                                            </div> 								
                                                        </div>
                                                        <div class="shadow p-3 mb-5 bg-white rounded">
                                                            <div class="row">
                                                                <div class="col-md-12">
                                                                    <input type="checkbox" id="chkPassport" onclick="ShowHideDiv(this)" required /> Please Confirm for Submission.
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="row" id="dvPassport" style="display: none;">
                                                            <div class="col-md-12">  
                                                                <div class="form-group">
                                                                    <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="Edit ID">
                                                                    <input type="submit" name="submit" id="btn_submit_exam" value="Submit" class="btn btn-primary pull-right" />
                                                                    <!--<input type="submit" id="btn_reg" class="btn btn-primary pull-right" style="background-color: #002366 !important;" value="Submit">-->
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>                        
                                                </section>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-2"></div>
                                </div>
                            </div>
                        </form>
                        ';
                        $body .= '</body>';
                        $body .= static::script();
                        $npapertime = $papertime*60;
                        $script = '';
                        // First running script code to set timer value
                        // document.cookie = "mytimer2=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
                        {
                            $script = '<script  type="text/javascript">
                                var seconds = '.$npapertime.';
                                document.cookie = "mytimer2=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
                                document.getElementById("timer").innerHTML = secondsToHms(seconds);
                                var a = secondsToHms(seconds);
                                document.cookie = "mytimer2 ="+a;
                                // setInterval(function () { 
                                    location.reload(); 
                                // }, 1000);
                                function secondsToHms(d) 
                                {
                                    d = Number(d);
                                    var h = Math.floor(d / 3600);
                                    var m = Math.floor(d % 3600 / 60);
                                    var s = Math.floor(d % 3600 % 60);
                                    var hDisplay = h > 0 ? h + ":" : "";
                                    var mDisplay = m > 0 ? m + ":" : "";
                                    var sDisplay = s > 0 ? s + "" : "";
                                    var timervalue = hDisplay + mDisplay + sDisplay; 
                                    return hDisplay + mDisplay + sDisplay; 
                                }
                            </script>';
                        }
                        $_SESSION['body'] = $body;
                        Homem::insert("INSERT INTO `quiz_exam_answers` (`qa_id`, `fk_suject_id`, `fk_exam_id`, `fk_paper_id`, `fk_faculty_id`, `answers`, `fromtime`, `totime`, `fk_qsavetype`, `fk_student_id`, `marks`, `status`, `completed`) VALUES 
                        (NULL, '$subjectid', '$examid', '$paperid', '$userid', '', '$start_time', '', '1', '$_SESSION[user_id]', '', '1', '')");
                        echo static::css();
                        echo '
                            <!--code to disable selection by mouse start-->
                                <style type="text/css">
                                    body{
                                        -webkit-touch-callout: none;
                                        -webkit-user-select: none;
                                        -khtml-user-select: none;
                                        -moz-user-select: none;
                                        -ms-user-select: none;
                                        user-select: none;
                                    }
                                </style> 
                            <!--code to disable selection by mouse End-->';
                        echo "<body>";
                        echo $_SESSION['menu'];
                        echo $_SESSION['body'];
                        echo $script;
                    }
                    else
                    {
                        if(isset($_SESSION['exam_status']))
                        {
                            if($_SESSION['exam_status'] == '1')
                            {
                                echo static::css();
                                echo '
                                    <!--code to disable selection by mouse start-->
                                        <style type="text/css">
                                            body{
                                                -webkit-touch-callout: none;
                                                -webkit-user-select: none;
                                                -khtml-user-select: none;
                                                -moz-user-select: none;
                                                -ms-user-select: none;
                                                user-select: none;
                                            }
                                        </style> 
                                    <!--code to disable selection by mouse End-->';
                                echo "<body>";
                                echo $_SESSION['menu'];
                                echo $_SESSION['body'];
                            }
                        }
                    }
                }
            }
            
            if(isset($_SESSION['exam_status']))
            {
                if($_SESSION['exam_status'] == '1')
                {
                    echo '<script  type="text/javascript">
                    $(document).ready(function () {
                            setInterval(function () {
                                var b=getCookie("mytimer2");
                                document.getElementById("timer").innerHTML = b;
                                var a = parseInt(getlatesttimervalue(b));
                                if(a == 0)
                                {
                                    console.log("Exam Completed");
                                    // alert("Exam Completed");
                                }
                                else
                                {
                                    a--;
                                    var c = secondsToHms(a);
                                    document.cookie = "mytimer2 ="+c;
                                }
                            }, 1000);
                        });
                        function secondsToHms(d) 
                        {
                            d = Number(d);
                            var h = Math.floor(d / 3600);
                            var m = Math.floor(d % 3600 / 60);
                            var s = Math.floor(d % 3600 % 60);
                            var hDisplay = h > 0 ? h + ":" : "";
                            var mDisplay = m > 0 ? m + ":" : "";
                            var sDisplay = s > 0 ? s + "" : "";
                            var timervalue = hDisplay + mDisplay + sDisplay; 
                            return hDisplay + mDisplay + sDisplay; 
                        }
                        function getCookie(name) {
                            var v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
                            return v ? v[2] : null;
                        }
                        function getlatesttimervalue(a)
                        {
                            var timearray = a.split(":");
                            if(timearray.length == 3)
                            {
                                if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                                if(timearray[1] == "" || timearray[1] == null){timearray[1] = 0;}
                                if(timearray[2] == "" || timearray[2] == null){timearray[2] = 0;}
                                var time1 = timearray[0]*60*60; 
                                var time2 = timearray[1]*60; 
                                var time3 = timearray[2]; 
                                var time =parseInt(time1)+parseInt(time2)+parseInt(time3);
                            }
                            if(timearray.length == 2)
                            {
                                if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                                if(timearray[1] == "" || timearray[1] == null){timearray[1] = 0;}
                                var time1 = timearray[0]*60; 
                                var time2 = timearray[1]; 
                                var time=parseInt(time1) + parseInt(time2);
                            }
                            if(timearray.length == 1)
                            {
                                if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                                var time1 = timearray[0]; 
                                var time= parseInt(time1);
                            }
                            return time;
                        }
                        function getCookieexist(name) {
                            var dc = document.cookie;
                            var prefix = name + "=";
                            var begin = dc.indexOf("; " + prefix);
                            if (begin == -1) {
                                begin = dc.indexOf(prefix);
                                if (begin != 0) return null;
                            }
                            else
                            {
                                begin += 2;
                                var end = document.cookie.indexOf(";", begin);
                                if (end == -1) {
                                end = dc.length;
                                }
                            }
                            // because unescape has been deprecated, replaced with decodeURI
                            //return unescape(dc.substring(begin + prefix.length, end));
                            return decodeURI(dc.substring(begin + prefix.length, end));
                        } 
                        
                        </script>';
                }
                if(isset($_COOKIE['myanswers']))
                {
                    $myanswers = $_COOKIE['myanswers'];
                    echo '
                        <script>
                        var str = "'.$myanswers.'";
                        var myanswerarray = str.split(",");
                        var examid = $("#examid").val();
                        var paperid = $("#paperid").val();
                        var facultyid = $("#facultyid").val();
                        var form = document.getElementById("frm_exam");
                        inputs = form.getElementsByTagName("input");
                        qtype = [];
                        for(var i=0, len=inputs.length; i<len; i++){
                            if(inputs[i].type === "hidden"){
                                if(inputs[i].name.includes("qtype")){
                                    qtype.push(inputs[i].value);
                                }			   
                            }			
                        }
                        for(var i=0; i<myanswerarray.length; i++)
	                    {
                            if(myanswerarray[i] != "" && myanswerarray[i] != null)
                            {
                                if(qtype[i] == 1)
                                {
                                    radiobtn = document.getElementById(myanswerarray[i]);
                                    radiobtn.checked = true;
                                }
                                else
                                {
                                    var j = parseInt(i)+1;
                                    var a = "A["+j+"]";
                                    document.getElementsByName(a)[0].value = myanswerarray[i];
                                }
                            }
                        }
                        </script>
                    ';
                }
                {
                    date_default_timezone_set('Asia/Kolkata');
                    $present = date('Y-m-d H:i:s');
                    echo '
                        <!-- check timings regularly-->
                        <script>
                        setInterval(function(){
                            var a = "'.$_SESSION['end_time'].'";
                            $.ajax({
                                type: "POST",
                                data : {a: a},
                                url: "/Exams/checkexamtimes",
                                success: function(d){
                                    if(d != "notcompleted")
                                    {
                                        window.location="/Exams/scheduledexams?status=1";
                                    }
                                }
                            });
                        }, 1500);
                        </script>';
                    echo '
                    <script>
                    setInterval(function(){ 
                        var examid = $("#examid").val();
                        var paperid = $("#paperid").val();
                        var facultyid = $("#facultyid").val();
                        var form = document.getElementById("frm_exam");
                        inputs = form.getElementsByTagName("input");
                        qtype = [];questions = []; answers_grp = [];answers = []; ans_txt = []; ans_num= [];

                        for(var i=0, len=inputs.length; i<len; i++){
                            if(inputs[i].type === "hidden"){
                                if(inputs[i].name.includes("Q")){
                                    questions.push(inputs[i].value);
                                }			   
                            }			
                        }

                        for(var i=0, len=inputs.length; i<len; i++){
                            if(inputs[i].type === "hidden"){
                                if(inputs[i].name.includes("qtype")){
                                    qtype.push(inputs[i].value);
                                }			   
                            }			
                        }

                        for(var i=0, len=inputs.length; i<len; i++){
                            if(inputs[i].type === "radio"){
                                if(!answers_grp.includes(inputs[i].name) && inputs[i].name.includes("A"))
                                    answers_grp.push(inputs[i].name);
                            }
                            if(inputs[i].type === "text"){
                                if(!answers_grp.includes(inputs[i].name) && inputs[i].name.includes("A"))
                                    answers_grp.push(inputs[i].name);
                                    ans_txt.push(inputs[i].name)
                            }
                            if(inputs[i].type === "number" && inputs[i].name.includes("A")){
                                if(!answers_grp.includes(inputs[i].name))
                                    answers_grp.push(inputs[i].name);
                                    ans_num.push(inputs[i].name)
                            }
                        }

                        for(var i=0, len=qtype.length; i<len; i++)
                        {
                            var j =i+1;
                            let selectedValue;
                            if(qtype[i] != 1)
                            {
                                var b = "A["+j+"]";
                                var a = document.getElementsByName(b)[0];
                                selectedValue = a.value;
                            }
                            else
                            {
                                var a = getanswers(i, answers_grp);
                                selectedValue = a;
                            }
                            if(selectedValue == "" || selectedValue == null ) answers.push(""); else answers.push(selectedValue);
                        }
                        document.cookie = "myanswers ="+answers;
                        var str = answers;
                    }, 1500);

                    function getanswers(i, answers_grp)
                    {
                        const rbs = document.querySelectorAll(`input[name="`+ answers_grp[i] +`"]`);
                        let selectedValue;
                        for (const rb of rbs) {
                                if (rb.checked) {
                                    selectedValue = rb.value;
                                    break;
                                }
                        }
                        return selectedValue;
                    }
                    </script>';
                }
                // Automatic saving for every two minutes 
                {
                    echo '
                    <script>
                    var examid = $("#examid").val();
                    var paperid = $("#paperid").val();
                    var facultyid = $("#facultyid").val();
                    setInterval(function () { 
                        saveanswers(examid, paperid, 1);
                        // console.log(A);
                    }, 120000);
                    </script>';
                }
                // Automatic saving for first three seconds 
                {
                    echo '<script>
                    var examid = $("#examid").val();
                        var paperid = $("#paperid").val();
                        var facultyid = $("#facultyid").val();
                    setTimeout(function(){ 
                        saveanswers(examid, paperid, 1);
                        // alert(examid);
                    }, 3000);
                    </script>';
                }
                // Automatic save on inactive screen
                {
                    echo '<script>
                    function mouseescape()
                    {
                        var examid = $("#examid").val();
                        var paperid = $("#paperid").val();
                        var facultyid = $("#facultyid").val();
                        setTimeout(function(){ 
                            saveanswers(examid, paperid, 3);
                            // alert(examid);
                        }, 1000);
                    }
                    </script>';
                }
            }
            echo '
            <script type="text/javascript">
                function ShowHideDiv(chkPassport) {
                    var dvPassport = document.getElementById("dvPassport");
                    dvPassport.style.display = chkPassport.checked ? "block" : "none";
                }
            </script>
            <script>
                
                function saveanswers(examid, paperid, examstatus)
                {
                    var A = getCookie("myanswers");
                    $.ajax({
                        type: "POST",
                        data : {examid: examid, paperid: paperid, A: A, examstatus: examstatus},
                        url: "/Exams/saveexamanswers",
                        success: function(d){
                            // $("#hours").html(d);
                            // console.log(d);
                        }
                    });
                }
                function testfunction()
                {
                    window.location="/Homes/home";
                }
            </script>';
            {
                // Extra Scrripts to block user
            echo '
            <!--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") {
                                    mouseescape();
                                    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-->
            ';
            }
            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 checkexamtimes()
    {
        if($_SESSION['user_role'] == 3 && isset($_SESSION['end_time']))
        {
            date_default_timezone_set('Asia/Kolkata');
            $present = date('Y-m-d H:i:s');
            $diff = strtotime($present)-strtotime($_SESSION['end_time']);
            if($diff > 0)
            {            
                $A = explode(",", $_COOKIE['myanswers']);
                $ans = json_encode($A);
                Homem::insert("UPDATE `quiz_exam_answers` SET
                `fk_exam_id`='$_SESSION[examid]', `fk_paper_id`='$_SESSION[paperid]', `answers`='$ans', `totime`='$present', `fk_qsavetype`='6', `fk_student_id`='$_SESSION[user_id]', `completed`='1' WHERE 
                `fk_exam_id`='$_SESSION[examid]' AND `fk_paper_id`='$_SESSION[paperid]'");
                unset($_SESSION['examid']);
                unset($_SESSION['paperid']);
                unset($_SESSION['examinerid']);
                unset($_SESSION['subjectid']);
                unset($_SESSION['start_time']);
                unset($_SESSION['end_time']);
                unset($_SESSION['exam_status']);
                unset($_SESSION['body']);
                echo '<script>
                document.cookie = "mytimer2=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
                document.cookie = "myanswers=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
                document.cookie = "myanswers=0";
                document.cookie = "mytimer2=0";
                </script>';
                echo 'succssexamcompleted';
            }
            else
            {
                echo 'notcompleted';
            }
        }
    }
    public static function saveexamanswers()
    {
        if($_SESSION['user_role'] == 3 && isset($_SESSION['start_time']))
        {
            if(isset($_POST['examstatus']))
            {
                if($_POST['examstatus'] >= 1 && $_POST['examstatus'] < 5)
                {
                    $A = explode(",", $_POST['A']);
                    $ans = json_encode($A);
                }
            }
            date_default_timezone_set('Asia/Kolkata');
            $start_time = $_SESSION['start_time'];
            $end_time = $_SESSION['end_time'];
            $present_time = date("Y-m-d H:i:s");
            $st_diff = (strtotime($start_time)-strtotime($present_time))/60;
            $en_diff = (strtotime($end_time)-strtotime($present_time))/60;
            if(!isset($_POST['examid']))
            {
                $_POST['examid'] = $_SESSION['examid'];
            }
            if(!isset($_POST['paperid']))
            {
                $_POST['paperid'] = $_SESSION['paperid'];
            }
            if($en_diff >=-0.2 && $st_diff<0)
            {
                Homem::insert("UPDATE `quiz_exam_answers` SET
                 `fk_exam_id`='$_POST[examid]', `fk_paper_id`='$_POST[paperid]', `answers`='$ans', `totime`='$present_time', `fk_qsavetype`='$_POST[examstatus]', `fk_student_id`='$_SESSION[user_id]' WHERE 
                 `fk_exam_id`='$_POST[examid]' AND `fk_paper_id`='$_POST[paperid]'");
            }
            
        }
    }
    public static function saveexamanswer()
    {
        if(isset($_SESSION['examid']) && isset($_SESSION['paperid']))
        {
            $a = $_POST['A'];
            $b = array();
            for($i=1; $i<=sizeof($a); $i++)
            {
                $j = $i-1;
                $b[$j] = $a[$i];
            }
            $a = array();
            $a = $b;
            $ans = json_encode($a);
            date_default_timezone_set('Asia/Kolkata');
            $start_time = $_SESSION['start_time'];
            $end_time = $_SESSION['end_time'];
            $present_time = date("Y-m-d H:i:s");
            $st_diff = (strtotime($start_time)-strtotime($present_time))/60;
            $en_diff = (strtotime($end_time)-strtotime($present_time))/60;
            if($en_diff >=-0.2 && $st_diff<0)
            {
                Homem::insert("UPDATE `quiz_exam_answers` SET
                 `fk_exam_id`='$_SESSION[examid]', `fk_paper_id`='$_SESSION[paperid]', `answers`='$ans', `totime`='$present_time', `fk_qsavetype`='5', `fk_student_id`='$_SESSION[user_id]', `completed`='1' WHERE 
                 `fk_exam_id`='$_SESSION[examid]' AND `fk_paper_id`='$_SESSION[paperid]'");
            }
            unset($_SESSION['examid']);
            unset($_SESSION['paperid']);
            unset($_SESSION['examinerid']);
            unset($_SESSION['subjectid']);
            unset($_SESSION['start_time']);
            unset($_SESSION['end_time']);
            unset($_SESSION['exam_status']);
            unset($_SESSION['body']);
            echo '<script>
            document.cookie = "mytimer2=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
            document.cookie = "myanswers=; expires= Thu, 01 Jan 2021 00:00:00 UTC; path=/;";
            document.cookie = "myanswers=0";
            document.cookie = "mytimer2=0";
            window.location = "/Exams/scheduledexams?status=1";
            </script>';
        }
        else
        {
            echo '
            <script>
            window.location = "/Exams/scheduledexams?status=0";
            </script>';
        }

    }
    public static function examreports()
    {
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            $subj = 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="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">SUBJECT WISE EXAM REPORTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <select name="subject" id="subject" class="form-control" onchange="getsubjectexamdetails()" required>
                                                                <option value="">Select Subject</option>
                                                                '.$subj.'
                                                            </select>
                                                        </div>
                                                    </div>  
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                                <div id="examdetails">
                                </div>
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function getsubjectexamdetails()
            {
                var date= $("#subject").val();
                $.ajax({
                    type: "POST",
                    data : {subject: date},
                    url: "/Exams/getsubjectexamdetails",
                    success: function(d){
                        $("#examdetails").html(d);
                    }
                });
            }
            </script>';
        }
    }
    public static function subwiseexamreports()
    {
        $a ='';
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            if(isset($_GET['eid']))
            {
                $a .= '<div class="table-responsive"><table class="table" border="1px"><thead><tr>';
                $a .= '<th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Marks Obtained</th><th>View</th>';
                $a .= '</tr></thead>';
                $a .= '<tbody>';
                $data = Homem::getdata("SELECT qea.qa_id, qea.answers, qep.q_ans, qep.q_type, qea.marks, qea.fk_student_id, um.id, um.no, um.name FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN user_master um ON um.id=qea.fk_student_id WHERE qea.fk_exam_id=qep.fk_qett_id AND qep.fk_stdnt_id=qea.fk_student_id AND qea.fk_exam_id='$_GET[eid]' AND qet.add_by='$_SESSION[user_id]' ORDER BY um.no ASC");
                if(sizeof($data) > 0)
                {
                    $ht_no = array();
                    foreach ($data as $h) {
                        $ht_no[] = $h['no'];
                    }
                    $no = array_values(array_unique($ht_no));
                    sort($no);
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        $j = $i+1;
                        $a .= '<tr>';
                        $a .= '<td>'.$j.'</td>';
                        $a .= '<td>'.$no[$i].'</td>';
                        for($j=0; $j<sizeof($data); $j++)
                        {
                            if($no[$i] == $data[$j]['no'])
                            {
                                $pid = $data[$j]['qa_id'];
                                $a .= '<td>'.$data[$j]['name'].'</td>';
                                if($data[$j]['marks'] == '')
                                {
                                    $marks = static::answercheck($data[$j]['answers'], $data[$j]['q_ans'], $data[$j]['q_type']);
                                    $sid = $data[$j]['id'];
                                    Homem::insert("UPDATE `quiz_exam_answers` SET `marks`='$marks', `completed`='1', `status`='1' WHERE `qa_id`='$pid' AND `fk_student_id`='$sid'");
                                }
                                else
                                {
                                    $marks = $data[$j]['marks'];
                                }
                                $a .= '<td>'.$marks.'</td>';
                                $a .= '<td><a href="/Exams/Viewsubsingleqpapaer?pid='.$data[$j]['qa_id'].'">View</a></td>';
                            }
                        }
                        $a .= '</tr>';
                    }
                }
                $a .= '</tbody></table>';
            }
            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: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">SUBJECT WISE EXAMINATION PAPERS</h4>
                                            </header>
                                            <div class="content-body"> 
                                            </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function getsubjectexamdetails()
            {
                var date= $("#subject").val();
                $.ajax({
                    type: "POST",
                    data : {subject: date},
                    url: "/Exams/getsubjectexamdetails",
                    success: function(d){
                        $("#examdetails").html(d);
                    }
                });
            }
            </script>';
        }
    }
    public static function subwiseexamreportstocollege()
    {
        $a ='';
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            if(isset($_GET['eid']))
            {
                $a .= '<div class="table-responsive" id="exporttable"><table class="table  table-responsive-sm" border="1px"><thead>';
                $a .= '<tr><th colspan="4">HINDU COLLEGE OF ENGINEERING AND TECHNOLOGY, GUNTUR</th></tr>';
                $data = Homem::getdata("SELECT sd.year, sd.sem, sd.subcode, sd.subname, qet.q_count, qet.ttime, qea.qa_id, qea.answers, qep.q_ans, qep.q_type, qea.marks, qea.fk_student_id, um.id, um.no, um.name FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN user_master um ON um.id=qea.fk_student_id JOIN subject_data sd ON sd.sub_id=qet.fk_sub_id WHERE qea.fk_exam_id=qep.fk_qett_id AND qep.fk_stdnt_id=qea.fk_student_id AND qea.fk_exam_id='$_GET[eid]' AND qet.add_by='$_SESSION[user_id]' ORDER BY um.no ASC");
                if(sizeof($data) > 0)
                {
                    $date = explode(" ", $data[0]['ttime']);
                    $a .= '<tr><th colspan="2">Year/ Sem:'.$data[0]['year'].'/'.$data[0]['sem'].'</th><th colspan="2">Subject Name:'.$data[0]['subname'].'('.$data[0]['subcode'].')</th></tr>';
                    $a .= '<tr><th colspan="2">No. of Questions:'.$data[0]['q_count'].'</th><th colspan="2">Faculty Name:'.$_SESSION['name'].'</th></tr>';
                    $a .= '<tr><th colspan="2">Date:'.static::datem($date[0]).'</th><th colspan="2"></th></tr>';
                }
                $a .= '<tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Marks Obtained in Percentage</th></tr>';
                $a .= '</thead>';
                $a .= '<tbody>';
                if(sizeof($data) > 0)
                {
                    $ht_no = array();
                    foreach ($data as $h) {
                        $ht_no[] = $h['no'];
                    }
                    $no = array_values(array_unique($ht_no));
                    sort($no);
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        $j = $i+1;
                        $a .= '<tr>';
                        $a .= '<td>'.$j.'</td>';
                        $a .= '<td>'.$no[$i].'</td>';
                        for($j=0; $j<sizeof($data); $j++)
                        {
                            if($no[$i] == $data[$j]['no'])
                            {
                                $pid = $data[$j]['qa_id'];
                                $a .= '<td>'.$data[$j]['name'].'</td>';
                                $name[$no[$i]] = $data[$j]['name'];
                                if($data[$j]['marks'] == '')
                                {
                                    $marks = static::answercheck($data[$j]['answers'], $data[$j]['q_ans'], $data[$j]['q_type']);
                                    $sid = $data[$j]['id'];
                                    Homem::insert("UPDATE `quiz_exam_answers` SET `marks`='$marks', `completed`='1', `status`='1' WHERE `qa_id`='$pid' AND `fk_student_id`='$sid'");
                                }
                                else
                                {
                                    $marks = $data[$j]['marks'];
                                    $per1 = round(($data[$j]['marks']/$data[$j]['q_count'])*100, 0);
                                    $per[$no[$i]] = $per1;
                                }
                                $a .= '<td>'.$per1.'%</td>'; 
                            }
                        }
                        $a .= '</tr>';
                    }
                    $a .= '<tr><td colspan="4">Students Scored below 50%</td></tr>';
                    $j = 0;
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        if(isset($per[$no[$i]]))
                        {
                            if($per[$no[$i]] < 50)
                            {
                                $j++;
                                $a .= '<tr><td>'.$j.'</td><td>'.$no[$i].'</td><td>'.$name[$no[$i]].'</td><td>'.$per[$no[$i]].'%</td></tr>';
                            }
                        }
                    }
                    $a .= '<tr><td colspan="4">Students Scored 50% to 70%</td></tr>';
                    $k = 0;
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        if(isset($per[$no[$i]]))
                        {
                            if($per[$no[$i]] >= 50 && $per[$no[$i]] < 70)
                            {
                                $k++;
                                $a .= '<tr><td>'.$k.'</td><td>'.$no[$i].'</td><td>'.$name[$no[$i]].'</td><td>'.$per[$no[$i]].'%</td></tr>';
                            }
                        }
                    }
                    $a .= '<tr><td colspan="4">Students Scored above 70%</td></tr>';
                    $l = 0;
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        if(isset($per[$no[$i]]))
                        {
                            if($per[$no[$i]] >= 70)
                            {
                                $l++;
                                $a .= '<tr><td>'.$l.'</td><td>'.$no[$i].'</td><td>'.$name[$no[$i]].'</td><td>'.$per[$no[$i]].'%</td></tr>';
                            }
                        }
                    }
                }
                $a .= '</tbody></table></div>';
                $a .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            }
            // print_r($per);
            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: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">SUBJECT WISE EXAMINATION REPORTING FOR COLLEGE</h4>
                                            </header>
                                            <div class="content-body"> 
                                            </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function getsubjectexamdetails()
            {
                var date= $("#subject").val();
                $.ajax({
                    type: "POST",
                    data : {subject: date},
                    url: "/Exams/getsubjectexamdetails",
                    success: function(d){
                        $("#examdetails").html(d);
                    }
                });
            }
            </script>';
        }
    }
    public static function answercheck($qns, $qcorrect, $qtype)
    {
        $marks=0;
        $nqns = json_decode($qns, true);
        $nqcorrect = json_decode($qcorrect, true);
        $nqtype = json_decode($qtype, true);
        if($qns == "" || $qns == "0")
        {
            $marks = 0;
        }
        if(is_array($nqns))
        {
            if(sizeof($nqns) != sizeof($nqcorrect) && sizeof($nqns) != sizeof($nqtype))
            {
                $marks = 0;
            }
            else
            {
                for($i=0; $i<sizeof($nqtype); $i++)
                {
                    if($nqtype[$i] == 1)
                    {
                        if($nqns[$i] == $nqcorrect[$i])
                        {
                            $marks = $marks+1;
                        }
                        else
                        {
                            if($nqns[$i] !="" && $nqcorrect[$i]!="")
                            {
                                $nq1 = explode("_", $nqns[$i]);
                                $nq2 = explode("_", $nqcorrect[$i]);
                                if($nq1[1] == $nq2[1])
                                {
                                    $marks = $marks+1;
                                }
                            }
                        }
                    }
                    if($nqtype[$i] == 2)
                    {
                        $correct = $nqcorrect[$i];
                        if(is_numeric($correct))
                        {
                            if(trim($nqns[$i]) == trim($nqcorrect[$i]))
                            {
                                $marks = $marks+1;
                            }
                        }
                        else
                        {   
                            $nqns[$i] = strtoupper(trim($nqns[$i]));
                            $nqcorrect[$i] = strtoupper(trim($nqcorrect[$i]));
                            {
                                if($nqns[$i] == $nqcorrect[$i])
                                {
                                    $marks = $marks+1;
                                }
                            }
                        }
                    }
                    if($nqtype[$i] == 3)
                    {
                        $nqcrct = explode("_", $nqcorrect[$i]);
                        $minl = (int)$nqcrct[0];
                        $minm = (int)$nqcrct[1];
                        $crct = (int)$nqns[$i];
                        if($crct>=$minl && $crct<=$minm)
                        {
                            $marks = $marks+1;
                        }
                    }
                }
            }
        }
        else
        {
            $marks = 0;
        }
        return $marks;
    }
    public static function Viewsubsingleqpapaer()
    {
        $a ='';
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            if(isset($_GET['pid']))
            {
                $data = Homem::getdata("SELECT qea.qa_id, qep.q_shuffle, qea.answers, qep.ep_id, qep.q_id, qep.q_ans, qep.q_type, qea.marks, qea.fk_student_id, um.id, um.no, um.name FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN user_master um ON um.id=qea.fk_student_id WHERE qea.fk_exam_id=qep.fk_qett_id AND qep.fk_stdnt_id=qea.fk_student_id AND qea.qa_id='$_GET[pid]' AND qet.add_by='$_SESSION[user_id]'");
                if(sizeof($data) == 1)
                {
                    $qus = json_decode($data['0']['q_id'], true);
                    $qtype = json_decode($data['0']['q_type'], true);
                    $qans = json_decode($data['0']['answers'], true);
                    $qcrct = json_decode($data['0']['q_ans'], true);
                    $qshuffle = json_decode($data['0']['q_shuffle'], true);
                    if(is_array($qans))
                    {
                        if(sizeof($qcrct) != sizeof($qans))
                        {
                            $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                        }
                    }
                    else
                    {
                        $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                    }
                    $que = json_decode(static::anspaperquestionquery($qus), true);
                    $marks = static::answercheckindqpaper($data[0]['answers'], $data[0]['q_ans'], $data[0]['q_type']);
                    for($i=0; $i<sizeof($qus); $i++)
                    {
                        for($j=0; $j<sizeof($que); $j++)
                        {
                            if($qus[$i] == $que[$j]['id'])
                            {
                                if($marks[$i] == 1)
                                {
                                    $ans = 'correct';
                                }
                                else
                                {
                                    $ans = 'wrong';
                                }
                                $a .= '
                                    <div class="shadow-lg p-3 mb-5 bg-white rounded">
                                        <div class="row">
                                            <div class="col-lg-1 col-centered">
                                                <div style="width: 25px; height: 25px;"><center><img src="/hindu/eimages/'.$ans.'.png" height="25px" width="25px"></center></div>
                                            </div>
                                            <div class="col-lg-10">
                                                '.$que[$j]['q_text'].'
                                            </div>
                                            <div class="col-lg-1">
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-1">
                                            </div>
                                            <div class="col-lg-11">
                                                <div class="row">
                                                    '.static::examanswerindpaper($qtype[$i], $qshuffle[$i], $que[$j]['q_answers'], $qans[$i], $qcrct[$i]).'
                                                </div>
                                            </div>
                                        </div>
                                    </div>';
                            }
                        }
                    }
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-3"></div>
                            <div class="col-lg-6">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Individual Student Question Paper</h4>
                                            </header>
                                            <div class="content-body"> 
                                            </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            function getsubjectexamdetails()
            {
                var date= $("#subject").val();
                $.ajax({
                    type: "POST",
                    data : {subject: date},
                    url: "/Exams/getsubjectexamdetails",
                    success: function(d){
                        $("#examdetails").html(d);
                    }
                });
            }
            </script>';
        }
    }
    public static function examanswerindpaper($type, $shuffle, $answers, $qanswerd, $qcorrect)
    {
        if($type == 1)
        {
			$answers = unserialize($answers);
            $shuff = str_split($shuffle);
            $ans = array();
            $ab = '';
            $correct = explode("_", $qcorrect);
            if($qanswerd != '')
            {
                $actualans = explode("_", $qanswerd);
                $ansd = $actualans[1];
            }
            else
            {
                $ansd = '';
            }
            for($a=0; $a<sizeof($answers); $a++)
            {
                $b =$a+1;
                if($correct[1] == $b && $ansd==$b)
                {
                    $ans[] = ') '.'&nbsp;'.$answers[$a].'<span style="color: green;"><b> (Correct)</b></span><span style="color: red;"><b> (Opted)</b></span>';
                }
                elseif($correct[1] == $b && $ansd != $b)
                {
                    $ans[] = ') '.'&nbsp;'.$answers[$a].'<span style="color: green;"><b> (Correct)</b></span>';
                }
                elseif($correct[1] != $b && $ansd == $b)
                {
                    $ans[] = ') '.'&nbsp;'.$answers[$a].'<span style="color: red;"><b> (Opted)</b></span>';
                }
                else
                {
                    $ans[] = ') '.'&nbsp;'.$answers[$a];
                }
                
            }
            
            for($a=0; $a<sizeof($shuff); $a++)
			{
                $b =$a+1;
                $ab .= '<div class="col-lg-6">';
                $ab .= $b.$ans[$shuff[$a]];
                $ab .= '</div>';
            }
            return $ab;
        }
        if($type == 2)
        {
            $ab = '';
            $ab .= '<div class="col-lg-6">';
            $ab .= 'Answered:<span style="color: red;"><b>'.$qanswerd.'</b><span>';
            $ab .= '</div>';
            $ab .= '<div class="col-lg-6">';
            $ab .= 'Correct:<span style="color: green;"><b>'.$qcorrect.'</b><span>';
            $ab .= '</div>';
            return $ab;
        }
        if($type == 3)
        {
            $c = explode("_", $qcorrect);
            $ab = '';
            $ab .= '<div class="col-lg-6">';
            $ab .= 'Answered:<span style="color: red;"><b>'.$qanswerd.'</b><span>';
            $ab .= '</div>';
            $ab .= '<div class="col-lg-6">';
            $ab .= 'Correct:<span style="color: green;"><b>'.$c[0].' to '.$c[1].'</b><span>';
            $ab .= '</div>';
            return $ab;
        }
    }
    public static function anspaperquestionquery($q_id)
    {
        $a = $q_id;
        $query1 = '';
        for($i=0; $i<sizeof($a); $i++)
        {
            if($i == 0)
            {
                $query1 .= "(`id`='".$a[$i]."' OR ";
            }
            if($i!=0 && $i < (sizeof($a)-1))
            {
                $query1 .= "`id`='".$a[$i]."' OR ";
            }
            if($i == (sizeof($a)-1))
            {
                $query1 .= "`id`='".$a[$i]."')";
            }
        }
        $query = 'SELECT * FROM `quiz_question_master` WHERE ';
        $query2 = " AND `status`='1' AND `q_lock`='1'";
        $query = $query.$query1.$query2;
        $data = Homem::getdata($query);
        return json_encode($data);
    }
    public static function answercheckindqpaper($qns, $qcorrect, $qtype)
    {
        $marks= array();
        $nqns = json_decode($qns, true);
        $nqcorrect = json_decode($qcorrect, true);
        $nqtype = json_decode($qtype, true);
        if($qns == "" || $qns == "0")
        {
            for($i=0; $i<sizeof($nqcorrect); $i++)
            {
                $marks[] = 0;
            }
        }
        if(is_array($nqns))
        {
            if(sizeof($nqns) != sizeof($nqcorrect) && sizeof($nqns) != sizeof($nqtype))
            {
                for($i=0; $i<sizeof($nqcorrect); $i++)
                {
                    $marks[] = 0;
                }
            }
            else
            {
                for($i=0; $i<sizeof($nqtype); $i++)
                {
                    if($nqtype[$i] == 1)
                    {
                        if($nqns[$i] == $nqcorrect[$i])
                        {
                            $marks[] = 1;
                        }
                        else
                        {
                            if($nqns[$i] !="" && $nqcorrect[$i]!="")
                            {
                                $nq1 = explode("_", $nqns[$i]);
                                $nq2 = explode("_", $nqcorrect[$i]);
                                if($nq1[1] == $nq2[1])
                                {
                                    $marks[] = 1;
                                }
                                else
                                {
                                    $marks[] = 0;
                                } 
                            }
                            else
                            {
                                $marks[] = 0;
                            } 
                        }
                    }
                    if($nqtype[$i] == 2)
                    {
                        $correct = $nqcorrect[$i];
                        if(is_numeric($correct))
                        {
                            if(trim($nqns[$i]) == trim($nqcorrect[$i]))
                            {
                                $marks[] = 1;
                            }
                            else
                            {
                                $marks[] = 0;
                            }
                        }
                        else
                        {   
                            $nqns[$i] = strtoupper(trim($nqns[$i]));
                            $nqcorrect[$i] = strtoupper(trim($nqcorrect[$i]));
                            {
                                if($nqns[$i] == $nqcorrect[$i])
                                {
                                    $marks[] = 1;
                                }
                                else
                                {
                                    $marks[] = 0;
                                }
                            }
                        }
                    }
                    if($nqtype[$i] == 3)
                    {
                        $nqcrct = explode("_", $nqcorrect[$i]);
                        $minl = (int)$nqcrct[0];
                        $minm = (int)$nqcrct[1];
                        $crct = (int)$nqns[$i];
                        if($crct>=$minl && $crct<=$minm)
                        {
                            $marks[] = 1;
                        }
                        else
                        {
                            $marks[] = 0;
                        }
                    }
                }
            }
        }
        else
        {
            for($i=0; $i<sizeof($nqcorrect); $i++)
            {
                $marks[] = 0;
            }
        }
        return $marks;
    }
    public static function getsubjectexamdetails()
    {
        $a ='';
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 2)
        {
            $data = Homem::getdata("SELECT * FROM `quiz_examtt` WHERE `fk_sub_id`='$_POST[subject]' AND `add_by`='$_SESSION[user_id]' ORDER BY `e_id` DESC");
            $a .= '<div class="table-responsive"><table class="table" border="1px">
            <thead><tr>
            <th>Exam Type</th>
            <th>No.of Questions</th>
            <th>Duration</th>
            <th>No. of Question Papers</th>
            <th>No. of Answer Papers</th>
            <th>Date of Completion of Exam</th>
            <th>Reports</th>
            </tr></thead>
            <tbody>';
            for($i=0; $i<sizeof($data); $i++)
            {
                date_default_timezone_set('Asia/Kolkata');
                $present_time = date("Y-m-d H:i:s");
                $end_time = $data[$i]['ttime'];
                $dif = (strtotime($end_time)-strtotime($present_time))/(60*60);
                if($dif < 0)
                {
                    $eid = $data[$i]['e_id'];
                    if($data[$i]['completed'] == 0 || $data[$i]['completed'] == '' || $data[$i]['completed'] == "")
                    {
                        Homem::insert("UPDATE `quiz_examtt` SET `completed`='1' WHERE `e_id`='$eid'");
                        Homem::insert("UPDATE `quiz_exam_paper` SET `completed`='1' WHERE `fk_qett_id`='$eid'");
                        Homem::insert("UPDATE `quiz_exam_answers` SET `completed`='1' WHERE `fk_exam_id`='$eid'");
                    }
                    $pdata = Homem::getdata("SELECT * FROM `quiz_exam_paper`  WHERE `fk_qett_id`='$eid'");
                    $adata = Homem::getdata("SELECT * FROM `quiz_exam_answers`  WHERE `fk_exam_id`='$eid'");
                    $a .= '<tr><td>'.static::quizexamtype($data[$i]['fk_quizexamtype']).'</td>';
                    $a .= '<td>'.$data[$i]['q_count'].'</td>';
                    $a .= '<td>'.$data[$i]['t_duration'].'</td>';
                    $a .= '<td>'.sizeof($pdata).'</td>';
                    $a .= '<td>'.sizeof($adata).'</td>';
                    $a .= '<td>'.$data[$i]['ttime'].'</td>';
                    $a .= '<td><a href="/Exams/subwiseexamreports?eid='.$eid.'">Reports</a><br/><a href="/Exams/subwiseexamreportstocollege?eid='.$eid.'">College Report</a></td>';
                    $a .= '</tr>';
                }
            }
            $a .= '</tbody></table></div>';
            echo $a;
        }
    }
    public static function totalexamreports()
    {
        $a ='';
        $x = '';
        if($_SESSION['user_role'] == 6)
        {
            $x .= '<div class="table-responsive">
                    <table class="table" border="1px">
                    <thead><tr>
                    <th>Faculty Name</th>
                    <th>Subject Name</th>
                    <th>Course</th>
                    <th>Year</th>
                    <th>No. of Exams</th>
                    </tr></thead>
                    <tbody>';
            $data = Homem::getdata("SELECT qet.e_id, qet.fk_sub_id, qet.fk_quizexamtype, qet.q_count, qet.t_duration, qet.ttime, qet.add_date, um.id, um.name, sd.subcode, sd.subname, sd.course, sd.dept, sd.year, sd.sem, sd.sub_id FROM quiz_examtt qet JOIN subject_data sd ON sd.sub_id=qet.fk_sub_id JOIN user_master um ON um.id=qet.add_by ORDER BY qet.e_id DESC");
            $sub = array();
            $id = array();
            foreach ($data as $h) {
                $sub[] = $h['fk_sub_id'];
                $id[] = $h['id'];
            }
            $sub_id = array_values(array_unique($sub));
            sort($sub_id);
            $user_id = array_values(array_unique($id));
            sort($user_id);
            for($i=0; $i<sizeof($data); $i++)
            {
                for($a=0; $a<sizeof($user_id); $a++)
                {
                    if($user_id[$a] == $data[$i]['id'])
                    {
                        $user_name[$user_id[$a]] = $data[$i]['name'];
                    }
                }
                for($a=0; $a<sizeof($sub_id); $a++)
                {
                    if($sub_id[$a] == $data[$i]['fk_sub_id'])
                    {
                        $sub_code[$sub_id[$a]] = $data[$i]['subcode'];
                        $sub_name[$sub_id[$a]] = $data[$i]['subname'];
                        $year[$sub_id[$a]] = $data[$i]['year'];
                        $sem[$sub_id[$a]] = $data[$i]['sem'];
                        $course[$sub_id[$a]] = $data[$i]['course'];
                        $dept[$sub_id[$a]] = $data[$i]['dept'];
                    }
                }
            }
            for($a=0; $a<sizeof($user_id); $a++)
            {
                for($b=0; $b<sizeof($sub_id); $b++)
                {
                    $cont = 0;
                    for($c=0; $c<sizeof($data); $c++)
                    {
                        if($user_id[$a] == $data[$c]['id'] && $sub_id[$b] == $data[$c]['fk_sub_id'])
                        {
                            $cont++;
                        }
                        if($c == sizeof($data)-1)
                        {
                            if($cont > 0)
                            {
                                $count[$user_id[$a]][$sub_id[$b]] = $cont;
                                $x .= '<tr><td>'.$user_name[$user_id[$a]].'</td><td>'.$sub_name[$sub_id[$b]].'</td><td>'.static::course($course[$sub_id[$b]]).'/'.static::dept($dept[$sub_id[$b]]).'</td><td>'.$year[$sub_id[$b]].'</td><td>'.$cont.'</td></tr>';
                            }
                        }
                    }
                }
            }
            $x .= '</tbody></table>';

            $data = Homem::getdata("SELECT * FROM `quiz_examtt`");
            $a .= '<div class="table-responsive"><table class="table" border="1px">
            <thead><tr>
            <th>S. No.</th>
            <th>Exam Type</th>
            <th>No.of Questions</th>
            <th>Duration</th>
            <th>No. of Question Papers</th>
            <th>No. of Answer Papers</th>
            <th>Date of Completion of Exam</th>
            </tr></thead>
            <tbody>';
            for($i=0; $i<sizeof($data); $i++)
            {
                date_default_timezone_set('Asia/Kolkata');
                $present_time = date("Y-m-d H:i:s");
                $end_time = $data[$i]['ttime'];
                $dif = (strtotime($end_time)-strtotime($present_time))/(60*60);
                if($dif < 0)
                {
                    $eid = $data[$i]['e_id'];
                    if($data[$i]['completed'] == 0 || $data[$i]['completed'] == '' || $data[$i]['completed'] == "")
                    {
                        Homem::insert("UPDATE `quiz_examtt` SET `completed`='1' WHERE `e_id`='$eid'");
                        Homem::insert("UPDATE `quiz_exam_paper` SET `completed`='1' WHERE `fk_qett_id`='$eid'");
                        Homem::insert("UPDATE `quiz_exam_answers` SET `completed`='1' WHERE `fk_exam_id`='$eid'");
                    }
                }
                    $pdata = Homem::getdata("SELECT * FROM `quiz_exam_paper`  WHERE `fk_qett_id`='$eid'");
                    $adata = Homem::getdata("SELECT * FROM `quiz_exam_answers`  WHERE `fk_exam_id`='$eid'");
                    $j = $i+1;
                    $a .= '<tr><td>'.$j.'</td>';
                    $a .= '<td>'.static::quizexamtype($data[$i]['fk_quizexamtype']).'</td>';
                    $a .= '<td>'.$data[$i]['q_count'].'</td>';
                    $a .= '<td>'.$data[$i]['t_duration'].'</td>';
                    $a .= '<td>'.sizeof($pdata).'</td>';
                    $a .= '<td>'.sizeof($adata).'</td>';
                    $a .= '<td>'.$data[$i]['ttime'].'</td>';
                    $a .= '</tr>';
                
            }
            $a .= '</tbody></table></div>';
        
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">TOTAL EXAM REPORTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>  
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                                '.$x.'<br/>
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function studentexamreports()
    {
        if($_SESSION['user_role'] == 3)
        {
            $a = '';
            $data = Homem::getdata("SELECT qea.qa_id, qea.fk_paper_id, qea.fk_student_id, qea.marks, qet.e_id, qet.fk_sub_id, qet.fk_quizexamtype, qet.q_count, qet.t_duration, qet.ttime, qet.add_date, um.id, um.name, sd.subcode, sd.subname, sd.course, sd.dept, sd.year, sd.sem, sd.sub_id FROM quiz_examtt qet JOIN subject_data sd ON sd.sub_id=qet.fk_sub_id JOIN user_master um ON um.id=qet.add_by JOIN quiz_exam_answers qea ON qea.fk_exam_id=qet.e_id WHERE qea.fk_student_id='$_SESSION[user_id]' AND qea.marks!='' AND qea.completed='1' AND qet.completed='1' ORDER BY qet.e_id DESC");   
            $a .= '<div class="table-responsive"><table class="table" border="1px">
                <thead><tr>
                <th>S. No.</th>
                <th>Faculty Name</th>
                <th>Subject Name</th>
                <th>Marks Obtained</th>
                <th>Max Marks</th>
                <th>Last Date of Exam</th>
                <th>View Question Paper</th></tr></thead><tbody>';
            for($i=0; $i<sizeof($data); $i++)
            {
                $date = explode(" ", $data[$i]['ttime']);
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$data[$i]['name'].'</td>';
                $a .= '<td>'.$data[$i]['subname'].'</td>';
                $a .= '<td>'.$data[$i]['marks'].'</td>';
                $a .= '<td>'.$data[$i]['q_count'].'</td>';
                $a .= '<td>'.$date[0].'</td>';
                $a .= '<td><a href=/Exams/stdntviewanspaper?pid='.$data[$i]['qa_id'].'>View</a></td>';
                $a .= '</tr>';
            }
                $a.='</tbody></table>';
            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-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">EXAMS COMPLETED BY THE STUDENT</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function stdntviewanspaper()
    {
        $a ='';
        if($_SESSION['user_role'] == 3)
        {
            if(isset($_GET['pid']))
            {
                $data = Homem::getdata("SELECT qea.qa_id, qep.q_shuffle, qea.answers, qep.ep_id, qep.q_id, qep.q_ans, qep.q_type, qea.marks, qea.fk_student_id, um.id, um.no, um.name FROM quiz_exam_answers qea JOIN quiz_exam_paper qep ON qea.fk_paper_id=qep.ep_id JOIN quiz_examtt qet ON qet.e_id=qea.fk_exam_id JOIN user_master um ON um.id=qea.fk_student_id WHERE qea.fk_exam_id=qep.fk_qett_id AND qep.fk_stdnt_id=qea.fk_student_id AND qea.qa_id='$_GET[pid]' AND qea.fk_student_id='$_SESSION[user_id]'");
                if(sizeof($data) == 1)
                {
                    $qus = json_decode($data['0']['q_id'], true);
                    $qtype = json_decode($data['0']['q_type'], true);
                    $qans = json_decode($data['0']['answers'], true);
                    $qcrct = json_decode($data['0']['q_ans'], true);
                    $qshuffle = json_decode($data['0']['q_shuffle'], true);
                    if(is_array($qans))
                    {
                        if(sizeof($qcrct) != sizeof($qans))
                        {
                            $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                        }
                    }
                    else
                    {
                        $qans = array();
                            for($i=0; $i<sizeof($qcrct); $i++)
                            {
                                $qans[] = '';
                            }
                    }
                    $que = json_decode(static::anspaperquestionquery($qus), true);
                    $marks = static::answercheckindqpaper($data[0]['answers'], $data[0]['q_ans'], $data[0]['q_type']);
                    for($i=0; $i<sizeof($qus); $i++)
                    {
                        for($j=0; $j<sizeof($que); $j++)
                        {
                            if($qus[$i] == $que[$j]['id'])
                            {
                                if($marks[$i] == 1)
                                {
                                    $ans = 'correct';
                                }
                                else
                                {
                                    $ans = 'wrong';
                                }
                                $a .= '
                                    <div class="shadow-lg p-3 mb-5 bg-white rounded">
                                        <div class="row">
                                            <div class="col-lg-1 col-centered">
                                                <div style="width: 25px; height: 25px;"><center><img src="/hindu/eimages/'.$ans.'.png" height="25px" width="25px"></center></div>
                                            </div>
                                            <div class="col-lg-10">
                                                '.$que[$j]['q_text'].'
                                            </div>
                                            <div class="col-lg-1">
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-1">
                                            </div>
                                            <div class="col-lg-11">
                                                <div class="row">
                                                    '.static::examanswerindpaper($qtype[$i], $qshuffle[$i], $que[$j]['q_answers'], $qans[$i], $qcrct[$i]).'
                                                </div>
                                            </div>
                                        </div>
                                    </div>';
                            }
                        }
                    }
                }
            }
            echo static::css();
            echo '
            <!--code to disable selection by mouse start-->
                <style type="text/css">
                    body{
                        -webkit-touch-callout: none;
                        -webkit-user-select: none;
                        -khtml-user-select: none;
                        -moz-user-select: none;
                        -ms-user-select: none;
                        user-select: none;
                    }
                </style> 
            <!--code to disable selection by mouse End-->';
            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: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">Question Paper</h4>
                                            </header>
                                            <div class="content-body"> 
                                            </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">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>
            <!--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-->
            ';
        }
    }
    public static function zeroexam()
    {
        $a ='';
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
            $sfdata = Homem::getdata("SELECT DISTINCT `fk_sub_id` FROM `subject_faculty` WHERE `status`='1' ORDER BY `fk_sub_id` asc");
            $eqdata = Homem::getdata("SELECT DISTINCT `fk_sub_id` FROM `quiz_examtt` WHERE `status`='1' ORDER BY `fk_sub_id` asc");
            $subdata = Homem::getdata("SELECT sf.fk_sub_id, sd.subcode, sd.subname, sd.course, sd.dept, sd.regulation, sd.year, sd.sem, um.name 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'");
            $sub = array();
            $m =0;
            $a .= '<div class="table-responsive"><table class="table" border="1px">
            <thead><tr>
            <th>S. No.</th>
            <th>Sub Code</th>
            <th>Sub Name</th>
            </tr></thead>
            <tbody>';
            for($i=0; $i<sizeof($sfdata); $i++)
            {
                $count = 0;
                for($j=0; $j<sizeof($eqdata); $j++)
                {
                    if($sfdata[$i]['fk_sub_id'] == $eqdata[$j]['fk_sub_id'])
                    {
                        $count = 1;
                    }
                    if($j == sizeof($eqdata)-1)
                    {
                        if($count == 0)
                        {
                            $subid = $sfdata[$i]['fk_sub_id'];
                            for($k=0; $k<sizeof($subdata); $k++)
                            {
                                if($subdata[$k]['fk_sub_id'] == $subid)
                                {
                                    $m++;
                                    $a .= '<tr><td>'.$m.'</td><td>'.$subdata[$k]['subcode'].'</td><td>'.$subdata[$k]['subname'].'</td></tr>';
                                }
                            }
                        }
                    }
                }
            }
            $a .= '</tbody></table></div>';
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">ZERO EXAM REPORTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>  
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    public static function zeroquestion()
    {
        $a ='';
        if($_SESSION['user_role'] == 8 || $_SESSION['user_role'] == 6)
        {
            $sfdata = Homem::getdata("SELECT DISTINCT `fk_sub_id` FROM `subject_faculty` WHERE `status`='1' ORDER BY `fk_sub_id` asc");
            $eqdata = Homem::getdata("SELECT DISTINCT `fk_sub_id` FROM `quiz_question_master` WHERE `q_lock`='1' ORDER BY `fk_sub_id` asc");
            $subdata = Homem::getdata("SELECT sf.fk_sub_id, sd.subcode, sd.subname, sd.course, sd.dept, sd.regulation, sd.year, sd.sem, um.name 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'");
            $sub = array();
            $m =0;
            $a .= '<div class="table-responsive"><table class="table" border="1px">
            <thead><tr>
            <th>S. No.</th>
            <th>Sub Code</th>
            <th>Sub Name</th>
            </tr></thead>
            <tbody>';
            for($i=0; $i<sizeof($sfdata); $i++)
            {
                $count = 0;
                for($j=0; $j<sizeof($eqdata); $j++)
                {
                    if($sfdata[$i]['fk_sub_id'] == $eqdata[$j]['fk_sub_id'])
                    {
                        $count = 1;
                    }
                    if($j == sizeof($eqdata)-1)
                    {
                        if($count == 0)
                        {
                            $subid = $sfdata[$i]['fk_sub_id'];
                            for($k=0; $k<sizeof($subdata); $k++)
                            {
                                if($subdata[$k]['fk_sub_id'] == $subid)
                                {
                                    $m++;
                                    $a .= '<tr><td>'.$m.'</td><td>'.$subdata[$k]['subcode'].'</td><td>'.$subdata[$k]['subname'].'</td></tr>';
                                }
                            }
                        }
                    }
                }
            }
            $a .= '</tbody></table></div>';
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">ZERO QUESTION REPORTS</h4>
                                            </header>
                                            <div class="content-body"> 
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>  
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                                '.$a.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            echo '<script>
            </script>';
        }
    }
    // 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..