<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
</style>
<!--<link rel="stylesheet" media="all" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />-->
<!--<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>-->
<!--<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>-->
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script>
$(document).ready(function(){
	$('.datePick').datepicker();
});
</script>
<script>
var root='<?php echo URL_ROOT; ?>';
function getExam(id,exam){
	$("#exam").html("Loading..");
	$("#ExamDetail").html('');
	$.post( "<?php echo URL_ROOT ?>TimeTable/ajax.php", { 
	type: "getExamDropdown", cls:  id, exam:	exam } , 
	function( data ) {
	  	$("#exam").html(data); 
		$('.datePick').datepicker();
	});
}
function showExam(exam){
	$("#ExamDetail").html('<center><img src="'+root+'assets/icon/load.gif" /></enter>');
	var cls=$("#cls").val();
	$.post( "<?php echo URL_ROOT ?>TimeTable/ajax.php", { 
	type: "showExamDetail", cls: cls, exam: exam } , 
	function( data ) {
	  	$("#ExamDetail").html(data);
		$('.datePick').datepicker();
	});
}
function showSelectedExam(cls,exam){
	$("#ExamDetail").html('<center><img src="'+root+'assets/icon/load.gif" /></enter>');
	$("#cls").val(cls);getExam(cls,exam);
	$.post( "<?php echo URL_ROOT ?>TimeTable/ajax.php", { 
	type: "showExamDetail1", cls: cls, exam: exam } , 
	function( data ) {
	  	$("#ExamDetail").html(data);
		$('.datePick').datepicker();
	});
}
function findStudent(t){
	var cls=$("#class").val();
	var section=$("#section").val();
	
	  	$("#findStudent").html(section);
	
}

function findmnth(){
	var month=$("#month").val()
	  	$("#month").val(month);
}

function findStudent(t){
	var cls=$("#class").val();
	var section=$("#section").val();
	$.post( "TimeTable/ajax.php", { type: "findStudent" ,cls: cls, section: section } , function( data ) {
	  	$("#findStudent").html(data);
	});
}

function getType(id){
	$.post( "Exam/ajax.php", { type: "exmtype" ,class: id } , function( data ) {
	  	$("#extype").html(data);
	});
}
</script>
<?php
$pgMod="exam";
$pgAct="view";

if($_POST){
	if(isset($_POST['submit'])) {
	    $check = $db->getRows("select * from examTimeTable where class='".$_POST["class"]."' and type='".$_POST["exam"]."' and session='".$_SESSION["admin"]["session"]."' ");
	    if(count($check) > 0){
	        echo "<script>alert('Timetalbe already exists');</script>";
	    } else {
        	if(is_array($_POST["subject"]) && count($_POST["subject"])>0)
        	$db->delete("examTimeTable","where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_POST["class"]."' and type='".$_POST["exam"]."'");
            	for($i=0; $i<count($_POST["subject"]);$i++){
            		$saveAry=array(	"class"=>$_POST["class"],
            						"type"=>$_POST["exam"],
            						"subject"=>$_POST["subject"][$i],
            						"examDate"=>$_POST["examDate"][$i],
            						"seating_plan"=>$_POST["seating_plan"][$i],
            						"seating1_time"=>$_POST["seating1_time"],
            						"seating2_time"=>$_POST["seating2_time"],
            						//"schedule"=>$_POST["schedule"][$i],
            						"school_id"=>$_SESSION["admin"]["school_id"],
            						"added_by"=>$_SESSION["admin"]["uid"],
            						"session"=>$_SESSION["admin"]["session"]
            						);
            		$_SESSION["msg"]="time table create successfully";
            		
            		$db->insertAry("examTimeTable",$saveAry);
            		
            	}
        	redirect("?src=TimeTable&page_id=".$pgMod);
	    }
	}
	
	if(isset($_POST['edit'])){
	    $class = $_GET['class'];
	    $type  = $_GET['exam'];
	    $i = 0;
	    foreach($_POST["subject"] as $sub){
	        $updateAry = array(
	                        "examDate"      =>  $_POST['examDate'][$i],
	                        "seating_plan"  =>  $_POST['seating_plan'][$i],
                        	"seating1_time" =>  $_POST["seating1_time"],
    						"seating2_time" =>  $_POST["seating2_time"],
	                    );

            $flgUp = $db->updateAry("examTimeTable", $updateAry, " where subject='$sub' and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."' and session='".$_SESSION["admin"]["session"]."'");
            $i++;
	    }
	    
        redirect("?src=TimeTable&page_id=".$pgMod);
	}
	
}



if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if($pgAct=="delete" && $_GET["id"]!=""){
	$db->delete("examTimeTable","where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."' and session='".$_SESSION["admin"]["session"]."'");
	$_SESSION["msg"]="time table delete successfully";
	redirect("?src=TimeTable&page_id=".$pgMod);
}elseif($pgAct=="publish" && $_GET["id"]!=""){
	$db->updateAry("examTimeTable",array("publish"=>1),"where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."' and session='".$_SESSION["admin"]["session"]."'");
	$_SESSION["msg"]="time table Publish successfully";
	/*$student=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and  class='".$_GET["class"]."' and session='".$_SESSION["admin"]["session"]."'");
	if(is_array($student) && count($student)>0){
		foreach($student as $iList){
			sms($iList["mobile"],"Dear Parent, It is to inform you that exam timetable of  class ".$_GET["class"]."(".$_GET["exam"].") is Declare in ".$LinksDetails["site_name"],"exam_timetable");
		}
	}*/
	redirect("?src=TimeTable&page_id=".$pgMod);
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice </b><?php echo ucfirst($_SESSION['msg']) ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}


if(isset($_POST['print'])){

$_POST['section'];

$flag = $db->getVal("select admit_card_flag from tbl_info ");
    if($flag == 1){
        echo ("<SCRIPT LANGUAGE='JavaScript'>
          window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
       </SCRIPT>");
    }
    else {
        if($_POST["idno"]==""){
            echo ("<SCRIPT LANGUAGE='JavaScript'>alert('Please select student');</SCRIPT>");
        }
        else {
            $duemonth = $db->getVal("select month from timetableexam where  name='$_GET[exam]' and session ='".$_SESSION["admin"]["session"]."' ");
            $_REQUEST['class'] = $_GET['class'];
            $_REQUEST['section'] = $_GET['section']; 
            $uid = $_REQUEST['uid'] = $_POST['idno']; 
            $session = $_REQUEST['session'] = $_SESSION['admin']['session'];
            $_REQUEST['due_month'] = $duemonth;

//     $monthsList1 = array(
//     1   =>  'April',
//     2   =>  'May',
//     3   =>  'June',
//     4   =>  'July ',
//     5   =>  'August',
//     6   =>  'September',
//     7   =>  'October',
//     8   =>  'November',
//     9   =>  'December',
//     10  =>  'January',
//     11  =>  'February',
//     12  =>  'March'
// );

$allmonths = $db->getRows("select * from months");

$monthsList1 = array();
    foreach($allmonths as $my){
        $monthsList1[$my['month']] = $my['name'];
    }

$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();
$overAllNewextra=0;

$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='1' and session='$session' and status=1 order by type");

$m = $duemonth;

$fStudent = $db->getRow("select * from student where idno='$uid' and  school_id='1' and session='$session' and status=1 and issue_TC=0");

$i=0;$total_comp=0;
if(count($fStudent) > 1){
    for($j=1; $j<=$m; $j++){
        $md[]=$j;
    }
    // $md = 1;
    $mdf= implode(',',$md);

    $i++;
    $mn=$m;

    $tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
    $j=0;$other=0;$k=0;$total_extra=0;$count=0;
    $m1=$m+1;
    foreach($monthsList1 as $key=>$val){

        $count++;

        if($mn===0){}
        else{ $mn--;
            $installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
            if(is_array($installTution) && count($installTution)>0){
			    $tution = $installTution["i$key"]-$installTution["ip$key"];
			} else {
                $tution="";
            }
            $overAlltution=$tution;



// Transport
            $installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
            if(is_array($installTution) && count($installTution)>0){
			    $trasnport=$installTution["b$key"]-$installTution["bp$key"];
			}else{
                $trasnport="";
            }
            $overAllTransport=$trasnport;

            $extrasum=array();
            if(is_array($aryFeeType) && count($aryFeeType)>0){
                foreach($aryFeeType as $ftype){
                    $sums=0;
                    $Ftypeid=$db->getVal("select id from extrafee_type where type='".$ftype["type"]."' and class='".$fStudent["class"]."'");
                    $installTution=$db->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
                    $no=array();
                    if(is_array($installTution) && count($installTution)>0){
						$sums = $installTution["fee"]-$installTution["pay"];
					}else{
                        $sums="";
                    }
                    $extrasum[]=$sums;
                    $total_extra+=$sums;
                    $tp=$ftype["type"];
                    $overAllextra[$tp]+=$sums;
                }
            }

            $overAllNewextra=0;
            for($ij=0; $ij<count($aryFeeType); $ij++){
                $overAllNewextra+=$extrasum[$ij];
            }

            $total=0;
            if($overAlltution=="0"&&$overAllTransport==0&&$overAllNewextra==0)
            {$total==0;}
            elseif($overAlltution==""&&$overAllTransport==""&&$overAllNewextra=="")
            {$total="";}
            else{ $total=$overAlltution+$overAllTransport+$overAllNewextra;}

            // if($key=="12"){
            //     $total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");

            //     $total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");

            //     $te=$db->getVal("SELECT sum(fee-pay) FROM extrafee WHERE idno='$uid' and pid='p12' and session='$session'  ");

            //     $total22=$total23+$total24+$te;
            //     $total_full+=$total22;
            // }
            // else{
                $total_full=$total_full+$total;
            // }
        }
    }

    $install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='1' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='$session'");

    if(is_array($install) && count($install)>0){
        $k=0;$c=0;$other2=0;
        foreach($install as $ins){$k+=2;$c++;
            if($fStudent['stype']=="old" && $ins['otype']=="new"){
                $over="";
            }
            elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
                $over="";
            }
            else{
                $installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");
                $installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='1' and session='$session' ");
                $t=0;$other1=0;$other_left=0;$dis=0;
                $t=$ins['fee'];
                if(is_array($installTution2) && count($installTution2)>0){
                    $dis=$installTution2['discount'];
                    if($t==$dis)
                        $t=0;
                    else
                        $t=$t-$dis;
                }
                if(is_array($installTution) && count($installTution)>0){
                    if($installTution['fine']!=""){
                        if(is_array($installTution1) && count($installTution1)>0)
                        {	foreach ($installTution1 as $instt)
                            $other_left+=$instt['fine'];
                        }
                        $other=$installTution['fine'];

                        if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
                        {$other+=$other_left;}
                    }
                    else
                        $other=0;
                }else{
                    $other="";
                }
                $other1=$other;

                $overAllOther=$t - $other1;
                $over=$overAllOther;
                $other2+=$over;

            }
        }
    }
    $total_full+=$other2;

    // $install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='1' and session='$session' ");
    $install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and month in ($mdf) and name like 'b%' and  school_id='1' and session='$session' ");
    $discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$session."' ");

    $install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='1' and session='".$session."'");

    $discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='1' and session='$session')   and session='$session' ");

    $dues=0;
    if(is_array($install) && count($install)>0){
        $installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");

        if(is_array($installTution) && count($installTution)>0){
            $total_dues=0;
            foreach($installTution as $ins){
                $total_dues+=$ins['fine'];
            }
            if($install['fee']==$total_dues)
                $dues=0;
            else $dues=$install['fee']-$total_dues-$discount;

            $installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
            $dues=$dues-$installTution_remain;
        }
        else
            $dues=$install['fee']-$discount;
    }
    else
        $dues="";
    $alldues+=$dues;

    $total_full+=$dues;

    $install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='1' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='$session' ");

    if(is_array($install) && count($install)>0){
        $k=0;$b=0;$other2_hostel=0;
        foreach($install as $ins){$k+=2;$b++;
            if($fStudent['htype']=="old" && $ins['otype']=="new"){
                $over_hostel="";
            }
            elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
                $over_hostel="";
            }
            elseif($fStudent['htype']==""){
                $over_hostel="";
            }
            else{
                $installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");
                $installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");
                $installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='1' and session='$session' ");
                $t=0;$other1=0;$other_left=0;$dis=0;
                $t=$ins['fee'];
                if(is_array($installTution2) && count($installTution2)>0){
                    $dis=$installTution2['discount'];
                    if($t==$dis)
                        $t=0;
                    else
                        $t=$t-$dis;
                }
                if(is_array($installTution) && count($installTution)>0){
                    if($installTution['fine']!=""){
                        if(is_array($installTution1) && count($installTution1)>0)
                        {	foreach ($installTution1 as $instt)
                            $other_left+=$instt['fine'];
                        }
                        $other=$installTution['fine'];

                        if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
                        {$other+=$other_left;}
                    }
                    else
                        $other=0;
                }else{
                    $other="";
                }
                $other1=$other;

                $overAllOther_hostel=$t - $other1;
                $over_hostel=$overAllOther_hostel;
                $other2_hostel+=$over_hostel;

            }
        }
    }$total_full+=$other2_hostel;
    $install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='1' and session='$session' ");
    $dues=0;$total_dues=0;$fine_t=0;
    if(is_array($install) && count($install)>0){
        foreach($install as $ins){
            $fine_t+=$ins["fee"];
            $installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");
            if(is_array($installTution) && count($installTution)>0){
                foreach($installTution as $ins){
                    $total_dues+=$ins['fine'];
                }
            }
            else
                $dues=$ins['fee'];
        }
        if($fine_t==$total_dues)
            $dues=0;
        else $dues=$fine_t-$total_dues;

    }
    else
        $dues="";
    $alldues+=$dues;

    $total_full+=$dues-$discount2;

    $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."' and name like 'Latefine%'");

    $dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in($install2[id])   and session='$session' ");

    $to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='$session' ");

    $to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='$session' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");

    $dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='$session' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");

    $t2=$to-$to1-$dis1;

    if($dues=="0")
    {
        $finetotal=$dues;
    }
    else
    {
        $finetotal=$dues-$dis3;
    }
    $total_comp+=$total_full+$t2;
}

    if($flag == 2) {
        if ($total_comp > 0) {
            echo ("<SCRIPT LANGUAGE='JavaScript'>alert('Please Clear Dues');</SCRIPT>");
        } else {
            echo ("<SCRIPT LANGUAGE='JavaScript'>
                window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
            </SCRIPT>");
        }
    }elseif ($flag == 3) {
        if ($total_comp > 0) {
            if ($fStudent['admit_card_view'] == 1) {
            echo ("<SCRIPT LANGUAGE='JavaScript'>
                window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
            </SCRIPT>");
            } else {
                echo ("<SCRIPT LANGUAGE='JavaScript'>alert('Please Clear Dues');</SCRIPT>");
            }
        } else {
        echo ("<SCRIPT LANGUAGE='JavaScript'>
          window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
       </SCRIPT>");
        }
    } elseif ($flag == 4) {
        if ($fStudent['admit_card_view'] == 1) {
            echo ("<SCRIPT LANGUAGE='JavaScript'>
                window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
            </SCRIPT>");
        } else {
            echo ("<SCRIPT LANGUAGE='JavaScript'>alert('Admit card is not available now');</SCRIPT>");
        }
    } else {
        echo ("<SCRIPT LANGUAGE='JavaScript'>alert('Admit card is not available now');</SCRIPT>");
    }

            // echo ("<SCRIPT LANGUAGE='JavaScript'>
            //     window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
            // </SCRIPT>");
        }
    }
}
if(isset($_POST['printall'])) {

$_POST['month'];

echo ("<SCRIPT LANGUAGE='JavaScript'>
     
      window.location.href='../print/?page_id=timetable&class=".$_GET['class']."&exam=".$_GET['exam']."&section=".$_POST['section']."&idno=".$_POST['idno']."&month=".$_POST['month']."'
       </SCRIPT>");	
//echo "treasure will be set if the form has been submitted (to TRUE, I believe)";
}
	

if($pgAct=="view" && $_GET["id"]!="")
{   
	$examSchedule=$db->getRows("select * from examSchedule where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."'");
	$timeTable=$db->getRows("select * from examTimeTable where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."'");
	?>
	
	
	<form method="post" action="">

  	 <div class="well no-padding">
        <div class="controls controls-row">
                           


                      <div >
                           
                            <div class="controls span3">
                                <select onchange="findStudent()" name="class" id="class">
                                   
                                    <?php 
                                        $class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET['class']."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                                                <?php echo $cla["class"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                     </div>
						   
                           <div >
                           
                            <div class="controls span3">
                               <select name="section" onchange="findStudent()" id="section">
                                    <option value="">Section</option>
                                    <?php 
                                        $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["name"]==$aryForm["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                                                <?php echo $cla["name"] ?>
                                            </option>
                                            <?php
                                
                                        }
                                    ?>
                                </select>
								</div>
								</div>
							 <div>

                        <div class="controls span3">
                            <div class="controls span3" id="findStudent">
                                <select  name="idno" id="idno">
                                    <option value="">All Student</option>
                                    <?php $students = $db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' and session='".$_SESSION["admin"]["session"]."' and status='1' order by name");
                                		foreach($students as $stu){
                                			?>
                                			<option value="<?php echo $stu["idno"] ?>">
                                				<?php echo $stu["name"] ?>
                                			</option>
                                			<?php
                                		}
                                	?>
                                </select>
                            </div>
         			    </div>  	
							</div>	
						<div>
                            <div class="controls span3">
								<select name="month" onchange="findmonth()" id="month">
                                    <option value="">month</option>
                                    <?php
                                        // $monthsList1 = array(
                                        //     1   => 'Apr',
                                        //     2   => 'May',
                                        //     3   => 'Jun',
                                        //     4   => 'Jul',
                                        //     5   => 'Aug',
                                        //     6   => 'Sep',
                                        //     7   => 'Oct',
                                        //     8   => 'Nov',
                                        //     9   => 'Dec',
                                        // 	10  => 'Jan',
                                        //     11  => 'Feb',
                                        //     12  => 'Mar'
                                        // );
                                        $allmonths = $db->getRows("select * from months");

                                        $monthsList1 = array();
                                            foreach($allmonths as $my){
                                                $monthsList1[$my['month']] = $my['name'];
                                            }

                                        foreach($monthsList1 as $key=>$value ){
                                            ?>
                                            <option value="<?php echo $key ?>">
                                                <?php echo $value ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
    <div align="center">
        <input type="submit" name="print" value="Print"  class="btn btn-primary"/>
      <!--<input type="submit" name="printall" value="Print All" class="btn btn-primary" type="button"  >-->
    </div>						
</div>

</form>
	<div class="row-fluid">
	    <div class="span12"><div class="top-bar">
    	<h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
        <div style="float:right; margin-top:5px">
                </div>
    </div>
    <div class="well no-padding" id="printDiv">
    	<table class="table">
        <tr>
        <!--<th></th>-->
    	<?php
		/*foreach($examSchedule as $sub){
			?><th><?php echo $sub["start"]." - ".$sub["end"] ?></th><?php
		}*/
		?>
         </tr>
         
         <?php
		 	foreach($timeTable as $table){
				?>
				<tr>
                	<td><?php echo $table["examDate"] ?></td>
                    <td><?php echo $table["subject"] ?></td>
                    <?php
					
					?>
                </tr>
				<?php
			}
		 ?>
        </table>
	</div>
	</div>
	</div>
	</div>
	<?php
}
elseif($pgAct=="edit" && $_GET["class"]!="" && $_GET["exam"]!=""){
$Timetable=$db->getRows("select * from examTimeTable where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."'");

$seatingtime = $db->getRow("select * from examTimeTable where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_GET["class"]."' and type='".$_GET["exam"]."'");
	?>

	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    </div>
        <form method="post" action="">
            <div class="well no-padding">
        
        <table class="table">
        <tr>
		    <td colspan="3">
		        1st Seating Timing <input type="text" name="seating1_time" value="<?php echo $seatingtime['seating1_time']; ?>" />&ensp;&ensp;&ensp;&ensp;&ensp;
		        2nd Seating Timing <input type="text" name="seating2_time" value="<?php echo $seatingtime['seating2_time']; ?>" />
		    </td>
		</tr>
        <?php
		foreach($Timetable as $tt){
			?>
			<tr>
            	<td><input type="text" name="subject[]" required  value="<?php echo $tt["subject"] ?>" readonly="readonly" /></td>
                <td><input type="text" class="datePick" required  value="<?php echo $tt["examDate"] ?>" name="examDate[]" /></td>
				<td>
				    <select name="seating_plan[]">
                        <option <?php if($tt["seating_plan"]=="")echo 'selected';?>  value="">Select Seating </option>
        				<option <?php if($tt["seating_plan"]=="1st Seating")echo 'selected';?> value="1st Seating">1st Seating</option>
        				<option <?php if($tt["seating_plan"]=="2nd Seating")echo 'selected';?> value="2nd Seating">2nd Seating</option>
                    </select>
                </td>
            </tr>
			<?php
		}
		?></table>

        <div class="form-actions">
        <input type="submit" name="edit" value="Save" class="btn btn-primary" />
        <button type="reset" class="btn"> Cancel</button>
        </div>

            </div>
        </form>
    </div>
    </div>

<?php
}

else
{
	?>

	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    </div>
    <form method="post" action="">
    <div class="well no-padding">
    <div class="control-group">
        <label class="control-label" for="cls">Class</label>
        <div class="controls">
            <select name="class" id="cls" class="span6">
            <option>Select class</option>
                <?php 
                    $class=$db->getRows("select distinct(class) from subject_mp where school_id='".$_SESSION["admin"]["school_id"]."' ");
                    foreach($class as $cla){
                        ?>
                        <option <?php if($cla["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                            <?php echo $cla["class"] ?>
                        </option>
                        <?php
                    }
                ?>
            </select>
            
            <select name="exam" id="exam" onchange="showExam(this.value)">
        <option>Select exam</option>
		<?php 
       	$class=$db->getRows("select distinct(name) from timetableexam where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
        if(is_array($class) && count($class)>0){
		    foreach($class as $cla){
                ?>
                <option  value="<?php echo $cla["name"] ?>">
                    <?php echo $cla["name"] ?>
                </option>
                <?php
            }
		}
        ?>
    </select>
            
            <!--<span id="exam">-->
            <!--<select name="class" id="class" class="span6">-->
            <!--    <option>Select Exam</option>-->
            <!--</select></span>-->
        </div>
    </div>
    <div id="ExamDetail">
         <div class="row-fluid"><div class="span12"><div class="top-bar">
            <h3><i class="icon-eye-open"></i> Exam Timetable list</h3>
            </div>
                <div class="well no-padding">
                <?php
                $aryPgAct=array("src"=>"TimeTable", "page_id"=>$pgMod,"action"=>"add");
                $aryList=$db->getRows("SELECT * FROM examTimeTable where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' group by class, type"); $i=0;
                if(is_array($aryList) && count($aryList)>0)
                {
                    ?>
                    <table class="table" id="example"> 
                        <thead>
                            <tr>
                                <th>Class</th>
								<!-- <th>Section</th> !-->
								
                                <th>Type</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach($aryList as $clist){ $i++; 
                        ?>
                            <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                                <td><?php echo $clist["class"] ?></td>
							<!--	<td>
                               <select name="section" onchange="findStudent()" id="section">
                                    <option value="">Section</option>
                                    <?php 
                                        $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["name"]==$aryForm["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                                                <?php echo $cla["name"] ?>
                                            </option>
                                            <?php
                                
                                        }
                                    ?>
                                </select>
                            </td> !-->
							
							
                                <td><?php echo $clist["type"] ?></td>
                                <td>
                                <?php 
								
					$aryPgAct["id"]=$clist['id'];$aryPgAct['class']=$clist["class"];
					$aryPgAct['month']=$_REQUEST['month'];
					$aryPgAct['exam']=$clist["type"];$aryPgAct['section']=$_GET['section'];
 
 ?> 
                                     
                                <?php $aryPgAct['action']="publish"; ?>
                                     <!--<a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Publish</button></a>-->
                                
                                <?php $aryPgAct['action']="view"; ?>
                                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">View</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>  

                                     <!--<a style="float:left" onclick="showSelectedExam('<?php echo $clist["class"] ?>','<?php echo $clist["type"] ?>')" href="javascript:;"><button type="button" class="btn btn-info">Edit</button></a>-->
                                     <a style="float:left" href="?src=TimeTable&page_id=exam&action=edit&class=<?php echo $clist["class"] ?>&exam=<?php echo $clist["type"] ?>"><button type="button" class="btn btn-info">Edit</button></a>



                                </td>
                            </tr>
                        <?php } ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th></th>
                                <th colspan="2"></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
					echo $db->getErMsg();
                }
                ?>
                </div>
            </div>
            </div>
    </div>
	</div>
    </form>
    </div>
	
	</div>
	<?php
}
?>


