<?php 
include("../db.php");
$ch=$_REQUEST["type"];$status="";

if($ch == "attendance"){
    $idno = $_SESSION['user']['idno'];
    $class = $_SESSION['user']['class'];
    $session = $_SESSION['user']['session'];
	$monthnum = $_POST['month'];

    $years = explode("-",$_SESSION["admin"]["session"]); 

    if($monthnum > 3){
        $year = $years[0];
    } else {
        $year = $years[1];
    }

    $monthname  =   date('F', mktime(0, 0, 0, $monthnum, 1));

//     $monthname  =   date('F', mktime(0, 0, 0, $monthnum, 1));
//     $currentyear =  date("Y");

// 	if($monthnum > 3){
// 	    $year = ($currentyear-1);
// 	}
// 	else {
// 	    $year = $currentyear;
// 	}
	
        $holidayAry = array();
        $holidays=$db->getRows("SELECT date FROM holiday WHERE session='".$session."' AND month='$monthname' AND class='$class' ");
        foreach($holidays as $h){
            array_push($holidayAry, $h['date']);
        }

function showCurrentMonth($current_Month, $year, $holidayAry, $monthname)
{
    global $db;
$date = mktime(12, 0, 0, $current_Month, 1, $year);
$numberOfDays =cal_days_in_month(CAL_GREGORIAN,$current_Month, $year);
$offset = date("w", $date);
$row_number = 1;
// time to draw the month header
echo "<h3 style='color:green;'>$monthname - $year</h3>";

echo "<table class='table table-bordered table-striped'><br/>";
echo "<tr style='font-size:25px;color:#555;'><th class='text-danger'>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr> <tr>";
// this will print the additional td record in case the month is not starting with the Sunday.
for($i = 1; $i <= $offset; $i++)
{
echo "<td></td>";
}
//  this will print the number of days.
for($day = 1; $day <= $numberOfDays; $day++)
{
if( ($day + $offset - 1) % 7 == 0 && $day != 1)
{
echo "</tr> <tr>";
$row_number++;
}

$date1 = date_create("$year-$current_Month-$day");
$chkdate = date_format($date1,"Y-m-d");

$dayname = date("l", strtotime("$year-$current_Month-$day"));

if($dayname == "Sunday"){
    $daycolor = "#DC143C";
} else {
    $daycolor = "green";
}

// if(in_array("$chkdate", $holidayAry)){
//     echo "<td style='color:blue;font-weight:bold;font-size:25px;'>$day <span style='float:right;margin-bottom:0px;font-weight:normal;'>H</span></td>";
// }
// else  {
// echo "<td style='font-weight:bold;font-size:25px;color:$daycolor'>" . $day . "</td>";
// }

$data = $db->getRow("select * from calendar where date='$year-$current_Month-$day' and session='".$_SESSION['admin']['session']."' ");

?>

<td style="color:<?php echo $daycolor; ?>">
    <input type="hidden" name="date[]" value="<?php echo $year."-".$current_Month."-".$day; ?>" />
    <input type="hidden" name="month" value="<?php echo $current_Month; ?>" />
    <input type="hidden" name="year" value="<?php echo $year; ?>" />
    <div style="display:inline-block;font-size:25px;width:40px;">
    <?php echo $day; ?>
    </div>
    <div style="display:inline-block;">
        <input type="radio" name="type_<?php echo $day; ?>" value="working" <?php if($data['type'] == 'working'){ echo "checked"; } ?>> Working <br>
        <input type="radio" name="type_<?php echo $day; ?>" value="holiday" <?php if($data['type'] == 'holiday'){ echo "checked"; } ?>> Holiday
    </div>
    <input type="text" name="remark_<?php echo $day; ?>" value="<?php echo $data['remark'];?>" style="width:90px;border:none;border-bottom:solid 1px green;"/>
</td>

<?php

}
while( ($day + $offset) <= $row_number * 7)
{
echo "<td></td>";
$day++;
}
echo "</tr></table>";


}

showCurrentMonth($monthnum, $year, $holidayAry,  $monthname);

}


if($ch=="get_student_list")
{
    $classAry = $_POST['classAry'];
    if(count($classAry) > 0){
    echo "
                    <table class='table'>
                    <tr>
                        <th><input type='checkbox' checked='checked' id='checkall' onchange='checkStudents()'  /> Check All </th>
                        <th>Adm. No.</th>
                        <th>Name</th>
                        <th>Class/Sec</th>
                    </tr>
    ";
    $i = 1;
    foreach($classAry as $class){
        $cls = $class['class'];
        $secAry = $class['section'];
        $wheresection = '';
        $sections = '';

            $allstudents = $db->getRows("select * from student where class='$cls' and school_id='".$_SESSION["admin"]["school_id"]."' AND session='".$_SESSION["admin"]["session"]."' ");
            
            foreach($allstudents as $student){
                if(count($secAry) > 0){
                    if (in_array("$student[section]", $secAry)){
                    ?>
                    <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                    <tr>
                        <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                        <td><?php echo $student['admissionno']; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $cls."/".$student['section']; ?></td>
                    </tr>
                 <?php
                    }
                    } else {
                ?>
                    <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                    <tr>
                        <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                        <td><?php echo $student['admissionno']; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $cls."/".$student['section']; ?></td>
                    </tr>
                 <?php
                }
                 $i++;
            }
             
            
        // }
    }
    echo "</table>";
    }
}


if($ch=="get_report_list")
{
    $classAry = $_POST['classAry'];
    if(count($classAry) > 0){
        echo "
                    <table class='table'>
                    <tr>
                        <th><input type='checkbox' checked='checked' id='checkall' onchange='checkStudents()'  /> Check All </th>
                        <th>Adm. No.</th>
                        <th>Name</th>
                        <th>Class/Sec</th>
                    </tr>
    ";
        $i = 1;
        foreach($classAry as $class){
            $cls = $class['class'];
            $secAry = $class['section'];
            $wheresection = '';
            $sections = '';

            $allstudents = $db->getRows("select * from student where class='$cls' and school_id='".$_SESSION["admin"]["school_id"]."' AND session='".$_SESSION["admin"]["session"]."' ");

            foreach($allstudents as $student){
                if(count($secAry) > 0){
                    if (in_array("$student[section]", $secAry)){
                        ?>
                        <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                        <tr>
                            <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['report_view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                            <td><?php echo $student['admissionno']; ?></td>
                            <td><?php echo $student['name']; ?></td>
                            <td><?php echo $cls."/".$student['section']; ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    ?>
                    <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                    <tr>
                        <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['report_view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                        <td><?php echo $student['admissionno']; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $cls."/".$student['section']; ?></td>
                    </tr>
                    <?php
                }
                $i++;
            }


            // }
        }
        echo "</table>";
    }
}

if($ch=="get_exam_student_list")
{
    $classAry = $_POST['classAry'];
    if(count($classAry) > 0){
        echo "
                    <table class='table'>
                    <tr>
                        <th><input type='checkbox' checked='checked' id='checkall' onchange='checkStudents()'  /> Check All </th>
                        <th>Adm. No.</th>
                        <th>Name</th>
                        <th>Class/Sec</th>
                    </tr>
    ";
        $i = 1;
        foreach($classAry as $class){
            $cls = $class['class'];
            $secAry = $class['section'];
            $wheresection = '';
            $sections = '';

            $allstudents = $db->getRows("select * from student where class='$cls' and school_id='".$_SESSION["admin"]["school_id"]."' AND session='".$_SESSION["admin"]["session"]."' ");

            foreach($allstudents as $student){
                if(count($secAry) > 0){
                    if (in_array("$student[section]", $secAry)){
                        ?>
                        <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                        <tr>
                            <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['exam_view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                            <td><?php echo $student['admissionno']; ?></td>
                            <td><?php echo $student['name']; ?></td>
                            <td><?php echo $cls."/".$student['section']; ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    ?>
                    <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                    <tr>
                        <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['exam_view_result'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                        <td><?php echo $student['admissionno']; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $cls."/".$student['section']; ?></td>
                    </tr>
                    <?php
                }
                $i++;
            }


            // }
        }
        echo "</table>";
    }
}


if($ch=="get_admit_card_student_list")
{
    $classAry = $_POST['classAry'];
    if(count($classAry) > 0){
        echo "
                    <table class='table'>
                    <tr>
                        <th><input type='checkbox' checked='checked' id='checkall' onchange='checkStudents()'  /> Check All </th>
                        <th>Adm. No.</th>
                        <th>Name</th>
                        <th>Class/Sec</th>
                    </tr>
    ";
        $i = 1;
        foreach($classAry as $class){
            $cls = $class['class'];
            $secAry = $class['section'];
            $wheresection = '';
            $sections = '';

            $allstudents = $db->getRows("select * from student where class='$cls' and school_id='".$_SESSION["admin"]["school_id"]."' AND session='".$_SESSION["admin"]["session"]."' ");

            foreach($allstudents as $student){
                if(count($secAry) > 0){
                    if (in_array("$student[section]", $secAry)){
                        ?>
                        <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                        <tr>
                            <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['admit_card_view'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                            <td><?php echo $student['admissionno']; ?></td>
                            <td><?php echo $student['name']; ?></td>
                            <td><?php echo $cls."/".$student['section']; ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    ?>
                    <input type="hidden" name="allstudent[]" value="<?php echo $student['idno']; ?>" />
                    <tr>
                        <td><input type="checkbox" name="idno<?php echo $student['idno']; ?>" class="check-students" value="<?php echo $student['idno']; ?>" <?php if($student['admit_card_view'] == 1)echo "checked"; ?> /> <?php echo $i; ?> </td>
                        <td><?php echo $student['admissionno']; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $cls."/".$student['section']; ?></td>
                    </tr>
                    <?php
                }
                $i++;
            }


            // }
        }
        echo "</table>";
    }
}



if($ch=="findStudent"){
	$where="";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$where=" AND section='".$_REQUEST["section"]."' ";
	$subjects=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."' $where order by name");
 ?><select name="studentname" id="studentname"><?php
	if(is_array($subjects) && count($subjects)>0){
		?><option value="">All Student</option><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["idno"] ?>">
				<?php echo $cla["name"] ?>
			</option>
			<?php
		}
	}
	?></select>
              <?php
}

if(isset($_POST['teacherwisehw']) ){
    $fromdate = $_POST[fromdate];
    $todate = $_POST[todate];
    $teacher = $_POST[teacher_id];
    
    $where = " assignment.date BETWEEN '$fromdate' and '$todate'";
    
    if($teacher!=""){
        $where .= " and assignment.Added_by='$teacher' ";
    }

    $getHomework = $db->getRows("select * from assignment LEFT JOIN staff ON staff.idno=assignment.Added_by where $where and assignment.status=1 and assignment.school_id='".$_SESSION["admin"]["school_id"]."' and assignment.session='".$_SESSION["admin"]["session"]."' ");

    if(count($getHomework) > 0){ ?>
    <button class="btn btn-danger" onclick="exportTableToExcel('hwWise', 'HW Teacher Wise Report')" style="float:right;">Excel</button>
    <?php
    echo "
        <table class='table'>
            <tr>
                <th>S.No.</th>
                <th>Teacher Name</th>
                <th>Designation</th>
                <th>Class</th>
                <th>Homework</th>
                <th>Download</th>
            </tr>";
            $i=1;
    foreach($getHomework as $homework){
        echo "<tr>
                <td>$i</td>
                <td>$homework[name]</td>
                <td>$homework[designation]</td>
                <td>$homework[class] - $homework[section]</td>
                <td>$homework[detail]</td>
                <td><a href='../uploads/assignment/$homework[upload_assignment]' style='background:green;color:white;border:solid 1px green;border-radius:5px;padding:5px;' download>Download</a></td>
            </tr>";
            $i++;
    }

    echo "</table>";
    }
    else {
        echo "No Record Found.";
    }

}

if($ch=="attendance_message"){
 
    $fromdate = $_REQUEST[fromdate];
    $todate = $_REQUEST[todate];
    $teacher = $_REQUEST[teacher_id];
    
    $where = "date BETWEEN '$fromdate' and '$todate'";
    
    if($teacher!=""){
        $where .= " and Added_by='$teacher' ";
    }

   $getHomework=$db->getRows("select * from assignment  where $where and status=1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' group by Added_by ");
    
  // ECHO $S="select * from assignment  where $where and status=1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ";
 $i=0;
$jsonn=array();
 foreach($getHomework as $ids){
 
 $name=$db->getVal("select  name from staff  where idno='".$ids['Added_by']."'  ");  
$class=$db->getVal("select  GROUP_CONCAT('''',class,'''') as class from assignment  where Added_by='".$ids['Added_by']."' and status=1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");
     //echo $ss="select class from assignment  where Added_by='".$ids['Added_by']."' and status=1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ";
    
    $section=$ids['section'];
    $stu_class=$ids['class'];
  	$jsonn[]=$name;




    $i++;
 }
  $ss=implode(",",$jsonn);
 $homework= json_encode($jsonn);
 
		$status=sms($LinksDetails["DirectorNumber"],"Homework Assign By    ".$ss." is date $fromdate " ,"fee_submit");	

}

if(isset($_POST['classwisehw']) ){
    $fromdate = $_POST[fromdate];
    $todate = $_POST[todate];
    $class = $_POST['class'];
    $section = $_POST['section'];

    $where = " assignment.date BETWEEN '$fromdate' and '$todate'";

    if($class!=""){
        $where .= " and assignment.class='$class' ";
    }
    if($section!=""){
        $where .= " and assignment.section='$section' ";
    }

    $getHomework = $db->getRows("select * from assignment LEFT JOIN staff ON staff.idno=assignment.Added_by where $where and assignment.status=1 and assignment.school_id='".$_SESSION["admin"]["school_id"]."' and assignment.session='".$_SESSION["admin"]["session"]."' ");

    if(count($getHomework) > 0){ ?>
        <button class="btn btn-danger" onclick="exportTableToExcel('classWise', 'HW Class Wise Report')" style="float:right;">Excel</button>
        <?php
    echo "
        <table class='table'>
            <tr>
                <th>S.No.</th>
                <th>Teacher Name</th>
                <th>Designation</th>
                <th>Class</th>
                <th>Homework</th>
                <th>Download</th>
            </tr>";
            $i=1;
    foreach($getHomework as $homework){
        echo "<tr>
                <td>$i</td>
                <td>$homework[name]</td>
                <td>$homework[designation]</td>
                <td>$homework[class] - $homework[section]</td>
                <td>$homework[detail]</td>
                <td><a href='../uploads/assignment/$homework[upload_assignment]' style='background:green;color:white;border:solid 1px green;border-radius:5px;padding:5px;' download>Download</a></td>
            </tr>";
            $i++;
    }

    echo "</table>";
    }
    else {
        echo "No Record Found.";
    }

}

if(isset($_POST['classteacher']) ){
    $class = $_POST['class'];
    $section = $_POST['section'];

    $where = "session='".$_SESSION["admin"]["session"]."' ";
    if($class!=""){
        $where .= "and class='$class' ";
    }
    if($section!=""){
        $where .= " and section='$section' ";
    }

    $staff = $db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' and status=1 order by name");

    if(count($staff) > 0){ ?>
          <button class="btn btn-danger" onclick="exportTableToExcel('clsTeacher', 'Class Teacher Report')" style="float:right;">Excel</button>
          <?php
    echo "
        <table class='table'>
            <tr>
                <th>S.No.</th>
                <th>Teacher Name</th>
                <th>Mobile</th>
                <th>Designation</th>
                <th>Assigned Class & Section</th>
                <th>Subject</th>
                <th>Photo</th>
            </tr>";
            
        if($class!="" || $section!=""){
            
        $i=1;
        foreach($staff as $teacher){
            $roles = $db->getRows("select * from assign_teacher where $where and teacher_id=$teacher[idno] and school_id=1 and is_class_teacher=1 order by section ASC ");
            if(count($roles)>0){
            echo "<tr>
                <td>$i</td>
                <td>$teacher[name]</td>
                <td>$teacher[mobile]</td>
                <td>$teacher[designation]</td>
                <td>";
                foreach($roles as $role){
                    echo "$role[class] - $role[section]<br>";
                }
                echo "</td>
                <td>$teacher[experience]</td>
                    <td><img src='../media/photo/$teacher[photo]' style='width:80px;'/></td>
                </tr>";
            $i++;
            }

        }
            
        }
        else {
            
            $i=1;
            
    foreach($staff as $teacher){
        echo "<tr>
                <td>$i</td>
                <td>$teacher[name]</td>
                <td>$teacher[mobile]</td>
                <td>$teacher[designation]</td>
                <td>";

                $roles = $db->getRows("select * from assign_teacher where $where and teacher_id=$teacher[idno] and school_id=1 and is_class_teacher=1 order by section ASC ");
                foreach($roles as $role){
                    echo "$role[class] - $role[section]<br>";
                }
                echo "</td>
                <td>$teacher[experience]</td>
                    <td><img src='../media/photo/$teacher[photo]' style='width:80px;'/></td>
                </tr>";
            $i++;
        }
    }
    echo "</table>";
    }
    else {
        echo "No Record Found.";
    }

}

if(isset($_POST['subjectteacher']) ){
    $class = $_POST['class'];
    $section = $_POST['section'];

    $where = "session='".$_SESSION["admin"]["session"]."' ";
    if($class!=""){
        $where .= "and class='$class' ";
    }
    if($section!=""){
        $where .= " and section='$section' ";
    }

    $staff = $db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' and status=1 order by name");

    if(count($staff) > 0){?>
      <button class="btn btn-danger" onclick="exportTableToExcel('subTeacher', 'Subject Teacher')" style="float:right;">Excel</button>
    <?php
    echo "
        <table class='table'>
            <tr>
                <th>S.No.</th>
                <th>Teacher Name</th>
                <th>Mobile</th>
                <th>Designation</th>
                <th>Assigned Class & Section</th>
                <th>Subject</th>
                <th>Photo</th>
            </tr>";

        if($class!="" || $section!=""){

        $i=1;
        foreach($staff as $teacher){
            $roles = $db->getRows("select * from assign_teacher where $where and teacher_id=$teacher[idno] and school_id=1 and is_class_teacher=0 order by section ASC ");
            if(count($roles)>0){
            echo "<tr>
                <td>$i</td>
                <td>$teacher[name]</td>
                <td>$teacher[mobile]</td>
                <td>$teacher[designation]</td>
                <td>";


                foreach($roles as $role){
                    echo "$role[class] - $role[section]<br>";
                }
                echo "</td>
                    <td>$teacher[experience]</td>
                    <td><img src='../media/photo/$teacher[photo]' style='width:80px;'/></td>
                </tr>";
            $i++;
            }

        }

        }
        else {

        $i=1;
    foreach($staff as $teacher){
        echo "<tr>
                <td>$i</td>
                <td>$teacher[name]</td>
                <td>$teacher[mobile]</td>
                <td>$teacher[designation]</td>
                <td>";

                $roles = $db->getRows("select * from assign_teacher where $where and teacher_id=$teacher[idno] and school_id=1 and is_class_teacher=0 order by section ASC ");
                foreach($roles as $role){
                    echo "$role[class] - $role[section]<br>";
                }
                echo "</td>
                <td>$teacher[experience]</td>
                    <td><img src='../media/photo/$teacher[photo]' style='width:80px;'/></td>
                </tr>";
            $i++;
        }
    }
    echo "</table>";
    }
    else {
        echo "No Record Found.";
    }

}

if($ch=="filter_subject"){
    $class = $_POST[classname];
    ?>
    <select id="mySelect1" name="parent_subject" style="width:100%"  onchange="changeSubject(this.value)" required>
        <option value="">--Select Subject--</option>           
        <?php $allSubjects = $db->getRows("select * from subject_new where class='$class' and parent_subject='0' and type='subject' order by id ASC");           foreach($allSubjects as $sub){               ?>
        <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>  <?php } ?>
    </select>
    <?php
}

if($ch=="filter_sub_subject"){
	$subject_id = $_POST['subject'];
 ?>
 <select name="sub_subject" style="width:100%;" required>
           <option value="">--Select Sub-subject --</option>
            <?php $allSubjects = $db->getRows("select * from subject_new where parent_subject='".$subject_id."' and type='sub_subject'  order by id ASC ");
            foreach($allSubjects as $sub){
                ?>
                <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
                              <?php
}

if($ch=="filterSubSubject"){
	$subject_id = $_POST['subject'];
 ?>
 <select name="sub_subject" style="width:100%;" id="subSubjectid" onchange="filterChapter(this.value)" required>
           <option value="">--Select Sub-subject --</option>
            <?php $allSubjects = $db->getRows("select * from subject_new where parent_subject='".$subject_id."' and type='sub_subject'  order by id ASC");
            foreach($allSubjects as $sub){
                ?>
                <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
  <?php
}

if($ch=="filterChapter"){
	$subject_id = $_POST['subject'];
 ?>
 <select id="chapter" name="chapter" style="width:100%;" onchange="getpaper(this.value)" required>
           <option  value="">--Select Chapter --</option>
            <?php $allSubjects = $db->getRows("select * from subject_new where sub_subject='".$subject_id."'  order by id ASC ");
            foreach($allSubjects as $sub){
                ?>
                <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
  <?php
    
}

if($ch=="getPaper"){
	$chapter_id = $_POST['chapter'];
 ?>
 <select name="paper" style="width:100%;" required>
           <option  value="">--Select Chapter --</option>
            <?php $allPapers = $db->getRows("select * from assignment_paper where chapter='".$chapter_id."' and paper_type='1' order by id ASC ");
            $i = 0;
            foreach($allPapers as $paper){ $i++;
                ?>
                <option value="<?php echo $paper['id']; ?>"><?php echo "Paper ".$i." (Total Que. ".$paper[total_questions].")"; ?></option>
                <?php
                }
            ?>
        </select>
  <?php
    
}

if($ch=="filter_subject2"){
	$class = $_POST['classname'];
 ?>
 <select id="mySelect2" name="parent_subject2" style="width:100%"  onchange="changeSubject()">
           <option value="">--Select Subject--</option>
            <?php $allSubjects = $db->getRows("select * from subject_new where class='".$class."' and session='".$_SESSION["admin"]["session"]."' and parent_subject=0 order by id ASC");
            foreach($allSubjects as $sub){
                ?>
                <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
                              <?php
}

if($ch=="delete_file"){
	$id = $_POST['id'];

    $image = $db->getRow("select * from assignment_files where id='".$id."' and session='".$_SESSION["admin"]["session"]."' ");

    $img = $image['name'];
    $type = $image['type'];

    if($type == "key_terms"){
        unlink("../uploads/keyterms/$img");
    }
    
    if($type == "mind_map"){
        unlink("../uploads/mindmap/$img");
    }

    if($type == "key_notes"){
        unlink("../uploads/keynotes/$img");
    }
    
    if($type == "practical_projects"){
        unlink("../uploads/practicalprojects/$img");
    }
    
    if($type == "videos"){
        unlink("../uploads/videos/$img");
    }
    
    $res=$db->delete("assignment_files","where session='".$_SESSION["admin"]["session"]."' and id='".$id."' ");
//    echo json_encode($res);

}

if($ch=="delete_econtent_file"){
	$id = $_POST['id'];

        $image = $db->getRow("select * from econtent_files where id='".$id."' and session='".$_SESSION["admin"]["session"]."' ");

        $img = $image['name'];

        unlink("../uploads/econtent/$img");

    $res=$db->delete("econtent_files","where session='".$_SESSION["admin"]["session"]."' and id='".$id."' ");

}

if($ch=="delete_question"){
	$qid = $_POST['qid'];
    $res=$db->delete("assignment_questions","where id='$qid' ");
}

if($ch=="delete_question_file"){
	$id = $_POST['file_id'];
	
	$getImageName = $db->getRow("select * from assignment_question_files where id='".$id."' ");
	$image = $getImageName['name'];
        unlink("../uploads/questionimages/$image");
    $res=$db->delete("assignment_question_files","where id='".$id."' ");

}

if($ch=="delete_subjectimage"){
	$id = $_POST['id'];

    $image = $db->getVal("select subject_image from subject_new where id='".$id."' and session='".$_SESSION["admin"]["session"]."' and type='subject' ");

    unlink("../uploads/subjectimage/$image");

	$saveAry=array("subject_image"=>"",);
    $flgUp=$db->updateAry("subject_new", $saveAry,"where id='".$id."' and session='".$_SESSION["admin"]["session"]."' and type='subject' ");
}

if($ch=="filterRecord"){
		$class = $_POST['classname'];
		$subject = $_POST['subject'];
		$subsubject = $_POST['subsubject'];
		$chapter = $_POST['chapter'];
		
		
			$conwhere="";

			if(isset($_POST['classname']) && trim($_POST['classname'])!=""){
			$conwhere.="and class='".$_POST["classname"]."' ";
	  	    }
	  	    
	  	    	if(isset($_POST['subject']) && trim($_POST['subject'])!=""){
	  	    	    
			  	$conwhere.="and parent_subject='".$_POST["subject"]."' ";
	  	    }
	  	    
	  	    if(isset($_POST['subsubject']) && trim($_POST['subsubject'])!=""){
	  	    	    
			  	$conwhere.="and sub_subject='".$_POST["subsubject"]."' ";
	  	    }
	  	    
	  	    
	  	    if(isset($_POST['chapter']) && trim($_POST['chapter'])!=""){
	  	    	    
			  	$conwhere.="and chapter='".$_POST["chapter"]."' ";
	  	    }
		?>

 <div id="filterdata">
            
	<?php
			$aryPgAct=array("src"=>"Notice", "page_id"=>"add_assignment");
	$aryList=$db->getRows("SELECT * FROM assignment_new where  session='".$_SESSION["admin"]["session"]."' $conwhere "); 

	//$aryList=$db->getRows("SELECT * FROM assignment_new where (class like '%".$class."%' OR parent_subject like '%".$subject."%' OR sub_subject like '%".$subsubject."%' OR 	chapter like '%".$chapter."%') and session='".$_SESSION["admin"]["session"]."' "); 
	    $i = 0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th style="width:50px;">S.No.</th>
                    <th>Class</th>
                    <th>Subject</th>
                    <th>Sub-subjects</th>
                    <th>Chapters</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["class"]; ?></td>
                    <td><?php echo $subject = $db->getVal("select subject from subject_new where id = '".$clist["parent_subject"]."' and type='subject' ") ?></td>
                    <td><?php echo $sub_subject = $db->getVal("select subject from subject_new where id = '".$clist["sub_subject"]."' and type='sub_subject' ") ?></td>
                    <td><?php echo $chapter = $db->getVal("select subject from subject_new where id = '".$clist["chapter"]."' and type='chapter' ") ?></td>
               
               <td>
                    <?php $aryPgAct['action']="addmore"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-primary">Add More</button></a>
                    <?php $aryPgAct['action']="edit"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                    <?php $aryPgAct['action']="delete"; ?>
                         <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th colspan="3"></th>
                </tr>
            </tfoot>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div>

 <?php  
}

if($ch=="filterRecord_subject"){
		$class = $_POST['classname'];
		$subject = $_POST['subject'];
				$conwhere="";

			if(isset($_POST['classname']) && trim($_POST['classname'])!=""){
			$conwhere.="and class='".$_POST["classname"]."' ";
	  	    }
	  	    
	  	    	if(isset($_POST['subject']) && trim($_POST['subject'])!=""){
	  	    	    
	  	    $sub=$db->getVal("select subject from subject_new  where id='".$_POST['subject']."'");	    
			   $conwhere.=" and subject='".$sub."' ";
	  	    }
		?>

 <div id="filterdata">
            
	<?php //echo $ss="SELECT * FROM subject_new where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $conwhere  and parent_subject=0 order by id";
		$aryPgAct=array("src"=>"Notice", "page_id"=>"add_subject");

	$aryList=$db->getRows("SELECT * FROM subject_new where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $conwhere  and parent_subject=0 order by id"); $i=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th>Class</th>
                    <th>Subject</th>
                    <th>Sub-subjects</th>
                    <th>Chapters</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $clist["class"] ?></td>
                    <td><?php echo $clist["subject"] ?><br>
                        <?php if($clist["subject_image"]!=""){ ?>
                        <a href="uploads/subjectimage/<?php echo $clist['subject_image']; ?>" download>
                            <img src="uploads/subjectimage/<?php echo $clist['subject_image']; ?>" style="width:50px;height:50px;"/>
                        </a>
                        <?php } ?>
                    </td>

                     <?php
                        $arun = ''; $k='';
                        $subSubjects = $db->getRows("SELECT * FROM subject_new where session='".$_SESSION["admin"]["session"]."' and parent_subject='".$clist["id"]."' and sub_subject=0 order by id ASC");
                        // print_r($subSubjects);
                        foreach($subSubjects as $ss){
                            $arun .= $ss['subject'].", ";
                            
                            $chapters = $db->getRows("select * from subject_new where sub_subject='".$ss[id]."' and type='chapter' order by id ASC ");
                            //print_r($chapters);
                            
                            foreach($chapters as $ch){
                                $k .= $ch['subject'].", ";
                            }
                            
                        }
                        ?>
                    <td>
                        <?php echo $arun;  ?>
                    </td>
                    <td>
                        <?php echo $k; ?>
                    </td>
                    
                     <td>
                    <!--<?php $aryPgAct['action']="edit"; ?>-->
                    <!--     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>-->
                    <?php $aryPgAct['action']="delete"; ?>
                         <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th colspan="3"></th>
                </tr>
            </tfoot>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div>

 <?php  
}

if($ch=="filterRecord_image"){
		$class = $_POST['classname'];
		$subject = $_POST['subject'];
				$conwhere="";

			if(isset($_POST['classname']) && trim($_POST['classname'])!=""){
			$conwhere.="and class='".$_POST["classname"]."' ";
	  	    }
	  	    
	  	    	if(isset($_POST['subject']) && trim($_POST['subject'])!=""){
	  	    	    
	  	    $sub=$db->getVal("select subject from subject_new  where id='".$_POST['subject']."'");	    
			   $conwhere.=" and subject='".$sub."' ";
	  	    }
		?>

 <div id="filterdata_image">
            
	<?php //echo $ss="SELECT * FROM subject_new where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $conwhere  and parent_subject=0 order by id";
		$aryPgAct=array("src"=>"Notice", "page_id"=>"add_subject");

	$aryList=$db->getRows("SELECT * FROM subject_new where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $conwhere and parent_subject=0 and type='subject' order by id"); $i=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
	  <form class="login-form" method="post" enctype="multipart/form-data">
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th>S.No.</th>
                    <th>Class</th>
                    <th>Subject</th>
                    <th>Image</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
				<input type="hidden" name="subjectid[]" required  value="<?php echo $clist["id"] ?>" readonly="readonly" />
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["class"]; ?></td>
                    <td><?php echo $clist["subject"] ?></td>
                    <td><input type="file" id="photo" name="photo[]" class="input-block-level" ></td>
                   <td>
                        <?php if($clist["subject_image"]!="") { ?>
                        <img src="uploads/subjectimage/<?php echo $clist['subject_image']; ?>" style="width:50px;height:50px;" />
                        <a href='uploads/subjectimage/<?php echo $clist['subject_image']; ?>' download><button type="button" class="btn" style="background:green;color:white;width:80px;padding:3px;font-size:12px;">Download</button></a>
                        <a href="javascript:;" onclick="delete_subjectimage('<?php echo $clist['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:80px;padding:3px;font-size:12px;">Delete</button></a> 
                        <?php } ?>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th colspan="3"></th>
                </tr>
            </tfoot>
        </table>
        <div class="form-actions">
			<button type="submit" name="update_photos" class="btn btn-primary"> Save</button>
			<button type="button" class="btn"> Cancel</button>
		</div>
    </form>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div>

 <?php  
}

if($ch=="filterRecord_question"){
		$class = $_POST['classname'];
		$subject = $_POST['subject'];
		$subsubject = $_POST['subsubject'];
		$chapter = $_POST['chapter'];
		
		
			$conwhere="";

			if(isset($_POST['classname']) && trim($_POST['classname'])!=""){
			$conwhere.="and class='".$_POST["classname"]."' ";
	  	    }
	  	    
	  	    	if(isset($_POST['subject']) && trim($_POST['subject'])!=""){
	  	    	    
			  	$conwhere.="and parent_subject='".$_POST["subject"]."' ";
	  	    }
	  	    
	  	    if(isset($_POST['subsubject']) && trim($_POST['subsubject'])!=""){
	  	    	    
			  	$conwhere.="and sub_subject='".$_POST["subsubject"]."' ";
	  	    }
	  	    
	  	    
	  	    if(isset($_POST['chapter']) && trim($_POST['chapter'])!=""){
	  	    	    
			  	$conwhere.="and chapter='".$_POST["chapter"]."' ";
	  	    }
		?>

 <div id="filterdata">
            
	<?php
			$aryPgAct=array("src"=>"Notice", "page_id"=>"add_questions");
	$aryList=$db->getRows("SELECT * FROM assignment_paper where session='".$_SESSION["admin"]["session"]."' $conwhere "); 
	    $i = 0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th style="width:50px;">S.No.</th>
                    <th>Class</th>
                    <th>Subject</th>
                    <th>Sub-subjects</th>
                    <th>Chapters</th>
                    <th>Details</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["class"]; ?></td>
                    <td><?php echo $subject = $db->getVal("select subject from subject_new where id = '".$clist["parent_subject"]."' and type='subject' ") ?></td>
                    <td><?php echo $sub_subject = $db->getVal("select subject from subject_new where id = '".$clist["sub_subject"]."' and type='sub_subject' ") ?></td>
                    <td><?php echo $chapter = $db->getVal("select subject from subject_new where id = '".$clist["chapter"]."' and type='chapter' ") ?></td>
                    <td>
                        Total Questions : <?php echo $totalquestions = $db->getVal("select count(id) from assignment_question where paper_id = '".$clist["id"]."' and session='".$_SESSION["admin"]["session"]."' ") ?>
                    </td>
                     <td>
                    <?php $aryPgAct['action']="addmore"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-primary">Add More</button></a>                        
                    <?php $aryPgAct['action']="edit"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                    <?php $aryPgAct['action']="delete"; ?>
                     <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th colspan="4"></th>
                </tr>
            </tfoot>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?><div>
	</div></div></div>
	<?php 
}


if($ch=="get_question_session"){
    
    $allsession = $db->getRows("select * from assignment_question_session");
    ?>
    <option value="">-- Select session --</option>
    <?php
    foreach($allsession as $session){
     ?>
        <option value="<?php echo $session[que_session]; ?>"><?php echo $session[que_session]; ?></option>     
     <?php
    }
    ?>

    <?php
}

if(isset($_POST[examresult]) ){
    $class = $_POST['class'];
    $parent_subject = $_POST['parent_subject'];
    $sub_subject = $_POST['sub_subject'];
    $chapter = $_POST['chapter'];
    $paperid = $_POST['paper'];

    $wheresec = "";
    if($_POST['section']!=""){
        $wheresec =  " and section='".$_POST['section']."' ";
    }

    $allpapers = $db->getRow("select * from assignment_paper where class='$class' and parent_subject='$parent_subject' and sub_subject='$sub_subject' and chapter='$chapter' and id='$paperid' ");
// echo "select * from assignment_paper where class='$class' and parent_subject='$parent_subject' and sub_subject='$sub_subject' and chapter='$chapter'";    

    if(count($allpapers) > 0 ){

        $attemptedpaper = $db->getRows("select * from assignment_attempt_paper where pid='$allpapers[id]' ");
        $totalque = $db->getVal("select count(id) from assignment_questions where paper_id='$allpapers[id]' ");
            if(count($attemptedpaper) > 0){
                ?>
                <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Report')" style="float:right;margin:10px;">Excel</button>
                <table class="table" id="tblData" border="1">

                    <thead>
                        <tr>
                            <th>S.No.</th>
                            <th>Student Name</th>
                            <th>Admission No.</th>
                            <th>Roll No.</th>
                            <th>Total Question</th>
                            <th>Correct</th>
                            <th>Wrong</th>
                            <th>Skipped</th>
                            <th>Marks<br>
                            (<?php echo $totalque*$allpapers['per_que_marks']; ?>)
                            </th>
                            <th>View</th>                            
                        </tr>
                    </thead>
                    <tbody>                
                <?php
                $i = 0;
                foreach($attemptedpaper as $paper){ 
                    $student = $db->getRow("select * from student where idno = '$paper[uid]' $wheresec");
                    if($student){$i++;
                    ?>
                    <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $student['admissionno'];?></td>
                        <td><?php echo $student['fincome'];?></td>
                        <td><?php echo $totalque;?></td>
                        <td><?php echo $paper['correct'];?></td>
                        <td><?php echo $paper['wrong'];?></td>
                        <td><?php echo $paper['skipped'];?></td>
                        <td>
                            <?php
                                echo $paper['correct']*$allpapers['per_que_marks'];
                            ?>
                        </td>
                        <td>
                            <button type="button" onclick="viewSolution(<?php echo $paper[pid]; ?>, <?php echo $student[idno]; ?>, <?php echo $paper[correct];?>, <?php echo $paper[wrong];?>,<?php echo $paper[skipped];?>)" class="btn btn-info" >View Solution</button>
                            <a href="<?php echo URL_ROOT; ?>print/?page_id=paper_solution&type=objective&pid=<?php echo $paper[pid]; ?>&idno=<?php echo $student[idno]; ?>" class="btn btn-primary" target="_blank">Print</a>
                            <button type="button" class="btn btn-danger" onclick="deleteattemptpaper(<?php echo $paper[id]; ?>)">Delete</button>
                        </td>
                    </tr>
                    <?
                }
                }
                echo "</tbody>
                    </table>";
            } else {
                echo "No Record Found.";
            }

    }
    else {
        echo "No paper exists in this Chapter";
    }

}

if(isset($_POST['subjectiveresult']) ){
    $class = $_POST['class'];
    $parent_subject = $_POST['parent_subject'];
    $sub_subject = $_POST['sub_subject'];
    $chapter = $_POST['chapter'];
    // $paperid = $_POST['paper'];
    $wheresec = "";
    if($_POST['section']!=""){
    $wheresec =  " and section='".$_POST['section']."' ";
    }

    // $allpapers = $db->getRow("select * from assignment_paper where class='$class' and parent_subject='$parent_subject' and sub_subject='$sub_subject' and chapter='$chapter' and id='$paperid' ");
    $allpapers = $db->getRow("select * from assignment_paper where class='$class' and parent_subject='$parent_subject' and sub_subject='$sub_subject' and chapter='$chapter' and paper_type='2' ");

    if(count($allpapers) > 0 ){

        $attemptedpaper = $db->getRows("select * from assignment_attempt_paper where pid='$allpapers[id]' ");
        
            if(count($attemptedpaper) > 0){
                ?>
                <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Report')" style="float:right;margin:10px;">Excel</button>
                <table class="table" id="tblData" border="1">

                    <thead>
                        <tr>
                            <th>S.No.</th>
                            <th>Student Name</th>
                            <th>Admission No.</th>
                            <th>Roll No.</th>
                            <th>Total Question</th>
                            <th>View</th>                            
                        </tr>
                    </thead>
                    <tbody>                
                <?php
                $i = 0;
                foreach($attemptedpaper as $paper){ 
                    $student = $db->getRow("select * from student where idno = '$paper[uid]' $wheresec");
                    if($student){$i++;
                    ?>
                    <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $student['name']; ?></td>
                        <td><?php echo $student['admissionno'];?></td>
                        <td><?php echo $student['fincome'];?></td>
                        <td><?php echo $allpapers['total_questions'];?></td>
                        <td>
                            <!--<button type="button" onclick="viewSolution1(<?php echo $paper[pid]; ?>, <?php echo $student[idno]; ?>, <?php echo $paper[correct];?>, <?php echo $paper[wrong];?>,<?php echo $paper[skipped];?>)" class="btn btn-info" >View Solution</button>-->
                            <!--<button type="button" class="btn btn-danger" onclick="deleteattemptpaper(<?php echo $paper[id]; ?>)">Delete</button>-->
                            <a href="<?php echo URL_ROOT; ?>print/?page_id=paper_solution&type=subjective&pid=<?php echo $paper[pid]; ?>&idno=<?php echo $student[idno]; ?>" class="btn btn-primary" target="_blank">Print</a>
                                <button type="button" class="btn btn-danger" onclick="deleteattemptpaper(<?php echo $paper[id]; ?>)">Delete</button>
                        </td>
                    </tr>

                    <?
                    }
                }
                echo "</tbody>
                    </table>";
            } else {
                echo "No Record Found.";
            }

    }
    else {
        echo "No paper exists in this Chapter";
    }

}


if($ch=="delete_attempt_paper"){
	$id = $_POST['pid'];
// 	echo $id;
    $res=$db->delete("assignment_attempt_paper","where id='$id' ");
    $res=$db->delete("assignment_attempt_question","where att_paper_id='$id' ");
    
    $files = $db->getRows("select * from assignment_attempt_subj_files where att_paper_id='$id' ");
    foreach($files as $img){
            unlink("../uploads/subjectiveexam/$img[name]");
    }
    
    $res=$db->delete("assignment_attempt_subj_files","where att_paper_id='$id' ");

    
}

if($ch == "viewSolution"){
    $pid = $_POST['pid'];
    $uid = $_POST['uid'];
 
    $attemptpaper = $db->getRow("select * from assignment_paper where id='$pid' ");
    if(count($attemptpaper) > 0){

    $allquestions = $db->getRows("select * from assignment_questions where paper_id='$pid' ");
    
    $att_paper = $db->getRow("select * from assignment_attempt_paper where pid='$pid' and uid='$uid' ");
    $dataPoints = array(
    	array("label"=>"Skipped", "y"=>$att_paper['skipped']),
    	array("label"=>"Wrong", "y"=>$att_paper['wrong']),
    	array("label"=>"Correct", "y"=>$att_paper['correct']),
    );
?>
<style>
    .nav-link{
        background:red;
        color:white;
    }
</style>
<script>
    
    var chart = new CanvasJS.Chart("chartContainer", {
    	animationEnabled: true,
    	title: {
    		text: ""
    	},
    	subtitles: [{
    		text: ""
    	}],
    	data: [{
    		type: "pie",
    		yValueFormatString: "#,##0\"\"",
    		indexLabel: "{label} ({y})",
    		dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
    	}]
    });
    chart.render();
    $(".canvasjs-chart-credit").hide(); 
    
</script>
    <!--<div id="chartContainer" style="height: 370px; width: 100%;"></div>-->

 

    <ul class="nav nav-pills" role="tablist">
        <li class="nav-item active" style="width:24%;text-align:center;font-size:18px;">
          <a class="nav-link" data-toggle="pill" href="#home" >All Questions</a>
        </li>
        <li class="nav-item" style="width:24%;text-align:center;font-size:18px;">
          <a class="nav-link" data-toggle="pill" href="#correct">Correct&emsp; <?php echo "<b style='font-weight:900;'>$att_paper[correct]</b>"; ?> </a>
        </li>
        <li class="nav-item" style="width:24%;text-align:center;font-size:18px;">
          <a class="nav-link" data-toggle="pill" href="#wrong">Wrong&emsp; <?php echo "<b style='font-weight:900;'>$att_paper[wrong]</b>"; ?></a>
        </li>
        <li class="nav-item" style="width:24%;text-align:center;font-size:18px;">
          <a class="nav-link" data-toggle="pill" href="#skipped">Skipped&emsp; <?php echo "<b style='font-weight:900;'>$att_paper[skipped]</b>"; ?></a>
        </li>
    </ul>

<div class="tab-content">

  <div id="home" class="tab-pane fade in active">

    <?php
            if(count($allquestions)>0 ){
            $i = 0;
            foreach($allquestions as $question){ $i++;
             $qtype = $question['qtype'];
             $questatus = '';
                $allimages = $db->getRows("select * from assignment_question_files where paper_id='$pid' and question_id='$question[id]' ");

                $att_question = $db->getRow("select * from assignment_attempt_question where pid='$pid' and uid='$uid' and qid='$question[id]' ");

                $correctans = json_decode($question['answer'],true);

                if(count($att_question) > 1){
                
                                    if($question[qtype] == 2){
                
                                        $givenans = json_decode($att_question['answer']);
                
                                        $multipleans = '';
                
                                        foreach($givenans as $ans){
                                            if(in_array($ans, $correctans) ){
                                                $multipleans = "Correct";
                                                $break;
                                            }
                                        }
                
                                        if($multipleans=="Correct"){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    elseif($question[qtype] == 6){
                                        
                                        $matchingans = 0;
                                        
                                        $givenans = json_decode($att_question['answer']);
                                        
                                        $corrarr1 = $correctans[0];
                                        $corrarr2 = $correctans[1];
                                        $corrarr3 = $correctans[2];
                                        $corrarr4 = $correctans[3];
                                        
                                        $arr1 = $givenans[0][0];
                                        $arr2 = $givenans[1][0];
                                        $arr3 = $givenans[2][0];
                                        $arr4 = $givenans[3][0];
                
                                        if(in_array($arr1, $corrarr1) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr2, $corrarr2) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr3, $corrarr3) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr4, $corrarr4) ){
                                            $matchingans = 1;
                                        }
                                        
                                        if($matchingans==1){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    
                                    else {
                                        if($question[answer]==$att_question[answer]){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                                    }
                
                                }
                                else {
                                    $questatus = 3;
                                }
                
                ?>
                    <table class="" style="margin:20px 0px;border:solid 1px #e5e5e5;float:left;background:#fff0f7;width:100%;">
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Question.<?php echo $i; ?></td>
                            <td><?php echo $question['question']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <?php foreach($allimages as $image){
                                    if($image['image_type'] == "question_image"){
                                        echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                    }
                                } ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Options :</td>
                            <td>
                                <?php 
                                    if($qtype == 1 || $qtype == 2 || $qtype == 3 || $qtype == 4){
                                     $options= json_decode($question[options], true);
                                        $j = 0;
                                        foreach($options as $opt){ $j++;
                                            echo "<li style='display:block;'>$j. $opt[answer]</li>";
                                            foreach($allimages as $image){ 
                                                if($image['image_type'] == "option_image" && $image['option_no'] == $j){ 
                                                    echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        $options= json_decode($question[options], true);
                                        $m_options = json_decode($question[m_options], true);
                                		$marray = array();
                                    		foreach ($m_options as $key ) {
                                    			$marray[] = $key[answer];
                                    		}
                                        $j = 0;$k=0;
                                        echo "<table class='table'><tr style='font-weight:bold;'><td>Column A</td><td>Column B</td>";
                                        foreach($options as $opt){ $j++;
                                            echo "<tr><td>$j. $opt[answer]</td><td>$j. $marray[$k]</td></tr>";
                                            $k++;
                                        }
                                        echo "</table>";
                                    }
                                ?>                                
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Correct Answer:</td>
                            <td>
                                <?php 
                                    if($qtype == 6){
                                    foreach($correctans as $cans){
                                        echo json_encode($cans);
                                    }
                                } else{
                                    foreach($correctans as $cans){
                                        echo "$cans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Your Answer:</td>
                            <td>
                                <?php $yourans = json_decode($att_question['answer'],true);
                                if($qtype==6){
                                    foreach($yourans as $yans){
                                        echo json_encode($yans);
                                    }
                                    
                                } else{
                                    foreach($yourans as $yans){
                                        echo "$yans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Status:</td>
                            <td>
                                <?php 
                                    if($questatus == 1){
                                        echo "<h3 class='text-success'><i class='fa fa-check'></i> Correct</h3>";
                                    }
                                    if($questatus == 2){
                                        echo "<h3 class='text-danger'><i class='fa fa-times'></i> Wrong</h3>";
                                    }
                                    if($questatus == 3){
                                        echo "<h3 class='text-primary'>Skipped</h3>";
                                    }
                                ?>
                            </td>
                        </tr>

                    </table>
                <?php
                
            }
            
        }

    ?>

  </div>
  
  <div id="correct" class="tab-pane fade">
    <?php
            if(count($allquestions)>0 ){
            $i = 0;
            foreach($allquestions as $question){ $i++;
             $qtype = $question['qtype'];
             $questatus = '';
                $allimages = $db->getRows("select * from assignment_question_files where paper_id='$pid' and question_id='$question[id]' ");

                $att_question = $db->getRow("select * from assignment_attempt_question where pid='$pid' and uid='$uid' and qid='$question[id]' ");

                $correctans = json_decode($question['answer'],true);

                if(count($att_question) > 1){
                
                                    if($question[qtype] == 2){
                
                                        $givenans = json_decode($att_question['answer']);
                
                                        $multipleans = '';
                
                                        foreach($givenans as $ans){
                                            if(in_array($ans, $correctans) ){
                                                $multipleans = "Correct";
                                                $break;
                                            }
                                        }
                
                                        if($multipleans=="Correct"){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    elseif($question[qtype] == 6){
                                        
                                        $matchingans = 0;
                                        
                                        $givenans = json_decode($att_question['answer']);
                                        
                                        $corrarr1 = $correctans[0];
                                        $corrarr2 = $correctans[1];
                                        $corrarr3 = $correctans[2];
                                        $corrarr4 = $correctans[3];
                                        
                                        $arr1 = $givenans[0][0];
                                        $arr2 = $givenans[1][0];
                                        $arr3 = $givenans[2][0];
                                        $arr4 = $givenans[3][0];
                
                                        if(in_array($arr1, $corrarr1) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr2, $corrarr2) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr3, $corrarr3) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr4, $corrarr4) ){
                                            $matchingans = 1;
                                        }
                                        
                                        if($matchingans==1){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    
                                    else {
                                        if($question[answer]==$att_question[answer]){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                                    }
                
                                }
                                else {
                                    $questatus = 3;
                                }
                                
                    if($questatus == 1) {
                
                ?>
                    <table class="" style="margin:20px 0px;border:solid 1px #e5e5e5;float:left;background:#fff0f7;width:100%;">
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Question.<?php echo $i; ?></td>
                            <td><?php echo $question['question']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <?php foreach($allimages as $image){
                                    if($image['image_type'] == "question_image"){
                                        echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                    }
                                } ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Options :</td>
                            <td>
                                <?php 
                                    if($qtype == 1 || $qtype == 2 || $qtype == 3 || $qtype == 4){
                                     $options= json_decode($question[options], true);
                                        $j = 0;
                                        foreach($options as $opt){ $j++;
                                            echo "<li style='display:block;'>$j. $opt[answer]</li>";
                                            foreach($allimages as $image){ 
                                                if($image['image_type'] == "option_image" && $image['option_no'] == $j){ 
                                                    echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        $options= json_decode($question[options], true);
                                        $m_options = json_decode($question[m_options], true);
                                		$marray = array();
                                    		foreach ($m_options as $key ) {
                                    			$marray[] = $key[answer];
                                    		}
                                        $j = 0;$k=0;
                                        echo "<table class='table'><tr style='font-weight:bold;'><td>Column A</td><td>Column B</td>";
                                        foreach($options as $opt){ $j++;
                                            echo "<tr><td>$j. $opt[answer]</td><td>$j. $marray[$k]</td></tr>";
                                            $k++;
                                        }
                                        echo "</table>";
                                    }
                                ?>                                
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Correct Answer:</td>
                            <td>
                                <?php 
                                    if($qtype == 6){
                                    foreach($correctans as $cans){
                                        echo json_encode($cans);
                                    }
                                } else{
                                    foreach($correctans as $cans){
                                        echo "$cans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Your Answer:</td>
                            <td>
                                <?php $yourans = json_decode($att_question['answer'],true);
                                if($qtype==6){
                                    foreach($yourans as $yans){
                                        echo json_encode($yans);
                                    }
                                    
                                } else{
                                    foreach($yourans as $yans){
                                        echo "$yans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Status:</td>
                            <td>
                                <?php 
                                    if($questatus == 1){
                                        echo "<h3 class='text-success'><i class='fa fa-check'></i> Correct</h3>";
                                    }
                                    if($questatus == 2){
                                        echo "<h3 class='text-danger'><i class='fa fa-times'></i> Wrong</h3>";
                                    }
                                    if($questatus == 3){
                                        echo "<h3 class='text-primary'>Skipped</h3>";
                                    }
                                ?>
                            </td>
                        </tr>

                    </table>
                <?php
                    }
            }
            
        }

    ?>
  </div>
  
  <div id="wrong" class="tab-pane fade">
    <?php
            if(count($allquestions)>0 ){
            $i = 0;
            foreach($allquestions as $question){ $i++;
             $qtype = $question['qtype'];
             $questatus = '';
                $allimages = $db->getRows("select * from assignment_question_files where paper_id='$pid' and question_id='$question[id]' ");

                $att_question = $db->getRow("select * from assignment_attempt_question where pid='$pid' and uid='$uid' and qid='$question[id]' ");

                $correctans = json_decode($question['answer'],true);

                if(count($att_question) > 1){
                
                                    if($question[qtype] == 2){
                
                                        $givenans = json_decode($att_question['answer']);
                
                                        $multipleans = '';
                
                                        foreach($givenans as $ans){
                                            if(in_array($ans, $correctans) ){
                                                $multipleans = "Correct";
                                                $break;
                                            }
                                        }
                
                                        if($multipleans=="Correct"){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    elseif($question[qtype] == 6){
                                        
                                        $matchingans = 0;
                                        
                                        $givenans = json_decode($att_question['answer']);
                                        
                                        $corrarr1 = $correctans[0];
                                        $corrarr2 = $correctans[1];
                                        $corrarr3 = $correctans[2];
                                        $corrarr4 = $correctans[3];
                                        
                                        $arr1 = $givenans[0][0];
                                        $arr2 = $givenans[1][0];
                                        $arr3 = $givenans[2][0];
                                        $arr4 = $givenans[3][0];
                
                                        if(in_array($arr1, $corrarr1) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr2, $corrarr2) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr3, $corrarr3) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr4, $corrarr4) ){
                                            $matchingans = 1;
                                        }
                                        
                                        if($matchingans==1){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    
                                    else {
                                        if($question[answer]==$att_question[answer]){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                                    }
                
                                }
                                else {
                                    $questatus = 3;
                                }
                                
                    if($questatus == 2) {
                
                ?>
                    <table class="" style="margin:20px 0px;border:solid 1px #e5e5e5;float:left;background:#fff0f7;width:100%;">
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Question.<?php echo $i; ?></td>
                            <td><?php echo $question['question']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <?php foreach($allimages as $image){
                                    if($image['image_type'] == "question_image"){
                                        echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                    }
                                } ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Options :</td>
                            <td>
                                <?php 
                                    if($qtype == 1 || $qtype == 2 || $qtype == 3 || $qtype == 4){
                                     $options= json_decode($question[options], true);
                                        $j = 0;
                                        foreach($options as $opt){ $j++;
                                            echo "<li style='display:block;'>$j. $opt[answer]</li>";
                                            foreach($allimages as $image){ 
                                                if($image['image_type'] == "option_image" && $image['option_no'] == $j){ 
                                                    echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        $options= json_decode($question[options], true);
                                        $m_options = json_decode($question[m_options], true);
                                		$marray = array();
                                    		foreach ($m_options as $key ) {
                                    			$marray[] = $key[answer];
                                    		}
                                        $j = 0;$k=0;
                                        echo "<table class='table'><tr style='font-weight:bold;'><td>Column A</td><td>Column B</td>";
                                        foreach($options as $opt){ $j++;
                                            echo "<tr><td>$j. $opt[answer]</td><td>$j. $marray[$k]</td></tr>";
                                            $k++;
                                        }
                                        echo "</table>";
                                    }
                                ?>                                
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Correct Answer:</td>
                            <td>
                                <?php 
                                    if($qtype == 6){
                                    foreach($correctans as $cans){
                                        echo json_encode($cans);
                                    }
                                } else{
                                    foreach($correctans as $cans){
                                        echo "$cans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Your Answer:</td>
                            <td>
                                <?php $yourans = json_decode($att_question['answer'],true);
                                if($qtype==6){
                                    foreach($yourans as $yans){
                                        echo json_encode($yans);
                                    }
                                    
                                } else{
                                    foreach($yourans as $yans){
                                        echo "$yans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Status:</td>
                            <td>
                                <?php 
                                    if($questatus == 1){
                                        echo "<h3 class='text-success'><i class='fa fa-check'></i> Correct</h3>";
                                    }
                                    if($questatus == 2){
                                        echo "<h3 class='text-danger'><i class='fa fa-times'></i> Wrong</h3>";
                                    }
                                    if($questatus == 3){
                                        echo "<h3 class='text-primary'>Skipped</h3>";
                                    }
                                ?>
                            </td>
                        </tr>

                    </table>
                <?php
                    }
            }
            
        }

    ?>
  </div>
  
  <div id="skipped" class="tab-pane fade">
    <?php
            if(count($allquestions)>0 ){
            $i = 0;
            foreach($allquestions as $question){ $i++;
             $qtype = $question['qtype'];
             $questatus = '';
                $allimages = $db->getRows("select * from assignment_question_files where paper_id='$pid' and question_id='$question[id]' ");

                $att_question = $db->getRow("select * from assignment_attempt_question where pid='$pid' and uid='$uid' and qid='$question[id]' ");

                $correctans = json_decode($question['answer'],true);

                if(count($att_question) > 0){
                
                                    if($question[qtype] == 2){
                
                                        $givenans = json_decode($att_question['answer']);
                
                                        $multipleans = '';
                
                                        foreach($givenans as $ans){
                                            if(in_array($ans, $correctans) ){
                                                $multipleans = "Correct";
                                                $break;
                                            }
                                        }
                
                                        if($multipleans=="Correct"){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    elseif($question[qtype] == 6){
                                        
                                        $matchingans = 0;
                                        
                                        $givenans = json_decode($att_question['answer']);
                                        
                                        $corrarr1 = $correctans[0];
                                        $corrarr2 = $correctans[1];
                                        $corrarr3 = $correctans[2];
                                        $corrarr4 = $correctans[3];
                                        
                                        $arr1 = $givenans[0][0];
                                        $arr2 = $givenans[1][0];
                                        $arr3 = $givenans[2][0];
                                        $arr4 = $givenans[3][0];
                
                                        if(in_array($arr1, $corrarr1) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr2, $corrarr2) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr3, $corrarr3) ){
                                            $matchingans = 1;
                                        }
                
                                        if(in_array($arr4, $corrarr4) ){
                                            $matchingans = 1;
                                        }
                                        
                                        if($matchingans==1){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                
                                    }
                                    
                                    else {
                                        if($question[answer]==$att_question[answer]){
                                            $questatus = 1;
                                        }
                                        else {
                                            $questatus = 2;
                                        }
                                    }
                
                                }
                                else {
                                    $questatus = 3;
                                }

                    if($questatus == 3) {
                
                ?>
                    <table class="" style="margin:20px 0px;border:solid 1px #e5e5e5;float:left;background:#fff0f7;width:100%;">
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Question.<?php echo $i; ?></td>
                            <td><?php echo $question['question']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <?php foreach($allimages as $image){
                                    if($image['image_type'] == "question_image"){
                                        echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                    }
                                } ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Options :</td>
                            <td>
                                <?php 
                                    if($qtype == 1 || $qtype == 2 || $qtype == 3 || $qtype == 4){
                                     $options= json_decode($question[options], true);
                                        $j = 0;
                                        foreach($options as $opt){ $j++;
                                            echo "<li style='display:block;'>$j. $opt[answer]</li>";
                                            foreach($allimages as $image){ 
                                                if($image['image_type'] == "option_image" && $image['option_no'] == $j){ 
                                                    echo "<img src='../uploads/questionimages/$image[name]' style='width:200px;height:150px;margin:5px;' />";
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        $options= json_decode($question[options], true);
                                        $m_options = json_decode($question[m_options], true);
                                		$marray = array();
                                    		foreach ($m_options as $key ) {
                                    			$marray[] = $key[answer];
                                    		}
                                        $j = 0;$k=0;
                                        echo "<table class='table'><tr style='font-weight:bold;'><td>Column A</td><td>Column B</td>";
                                        foreach($options as $opt){ $j++;
                                            echo "<tr><td>$j. $opt[answer]</td><td>$j. $marray[$k]</td></tr>";
                                            $k++;
                                        }
                                        echo "</table>";
                                    }
                                ?>                                
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Correct Answer:</td>
                            <td>
                                <?php 
                                    if($qtype == 6){
                                    foreach($correctans as $cans){
                                        echo json_encode($cans);
                                    }
                                } else{
                                    foreach($correctans as $cans){
                                        echo "$cans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Your Answer:</td>
                            <td>
                                <?php $yourans = json_decode($att_question['answer'],true);
                                if($qtype==6){
                                    foreach($yourans as $yans){
                                        echo json_encode($yans);
                                    }
                                    
                                } else{
                                    foreach($yourans as $yans){
                                        echo "$yans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Status:</td>
                            <td>
                                <?php 
                                    if($questatus == 1){
                                        echo "<h3 class='text-success'><i class='fa fa-check'></i> Correct</h3>";
                                    }
                                    if($questatus == 2){
                                        echo "<h3 class='text-danger'><i class='fa fa-times'></i> Wrong</h3>";
                                    }
                                    if($questatus == 3){
                                        echo "<h3 class='text-primary'>Skipped</h3>";
                                    }
                                ?>
                            </td>
                        </tr>

                    </table>
                <?php
                    }
            }
            
        }
 
    ?>
  </div>

</div>

<?php
        
    }

}

?>

