<?php
include("../db.php");
$ch=$_REQUEST["type"];
if($ch=="examSummery"){
	$whereC=array();$subjWhere="";
		if(isset($_REQUEST["cls"]) && $_REQUEST["cls"]!="")
			$whereC[]=" class='".$_REQUEST["cls"]."' ";
		if(isset($_REQUEST["subject"]) && $_REQUEST["subject"]!="")
			$subjWhere=" and subject='".$_REQUEST["subject"]."' ";
			
		$whereM="";
		$whereC[]="session='".$_SESSION["admin"]["session"]."'";
		$whereC[]="school_id='".$_SESSION["admin"]["school_id"]."'";
		
		$whereM1="";
		if(is_array($whereC) && count($whereC)>0)
			$whereM1=" where ".implode(" and ",$whereC);
		
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereC[]=" section='".$_REQUEST["section"]."' ";
		if(is_array($whereC) && count($whereC)>0)
			$whereM=" where ".implode(" and ",$whereC);
		
		$allstudent=$db->getRows("select * from student $whereM order by name");
		$allsubject=$db->getRows("select * from subject $whereM1 $subjWhere");
		//echo $db->getLastQuery();echo $db->getErMsg();
	?>
        <center>
        <h4 style="color:green;font-weight:800;margin:3px 0px;">GRADE DETAIL</h4>
        <ul style="padding: 1px 5px;;font-size:11px;color:#fff;font-weight:800;">
                  <li style="float:left;width:24%;background:#2938FF;margin-right: 2px; padding: 5px 1px 5px 5px;">Class : <?php echo $_REQUEST["cls"];?></li> 
                 
                  <li style="float:left;width:24%;background:#EC0D2E;margin-right: 2px; padding: 5px 1px 5px 5px;">Section : <?php echo $_REQUEST["section"];?></li> 
                 
                  <li style="float:left;width:24%;background:#07B714;margin-right: 2px; padding: 5px 1px 5px 5px;">Exam Term : <?php echo $_REQUEST["term"];?></li> 
                  <li style="float:left;width:23%;background:#11AEE4;margin-right: 2px; padding: 5px 1px 5px 5px;">Session : <?php echo $_SESSION["admin"]["session"];?></li> 
                  
               </ul> </center>
     
          <!--<div class="headPrint hide" style="border: none;">
     	  <div style="margin-left:70px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="80px" style="margin:12px 0px 0px 10px;"></div>
         <div style="float:left;text-align:center;"> <h1 style="font-size:45px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
           </div> 
          </div>-->	
	<?php	if(is_array($allstudent) && count($allstudent)>0){
			?><table class="table" cellpadding="0" cellspacing="0">
			<thead>
            <tr style="background: #D5DA13;">
            <td width="2%" style="color:#000;padding:6px;border-left: 1px solid red;">S.No</td>
            <td style="color:#000;padding:6px;text-align:center">Student</td>
            <td style="color:#000;padding:6px;text-align:center">Father's Name</td>
            <?php 
			if(is_array($allsubject) && count($allsubject)>0){
				foreach($allsubject as $sub){
					?><td width="7%" style="color:#000;padding:6px;text-align:center"><?php echo $sub["subject"] ?></td><?php
				}
			}?>
            </tr>
            </thead>
			<?php $ij=0;
			foreach($allstudent as $stu){$ij++;
				?>
				<tr>
                	<td style="border-left: 1px solid red;"><?php echo $ij; ?></td>
                	<td style="text-align:center"><?php echo $stu["name"] ?></td>
                    <td style="text-align:center"><?php echo $stu["fname"] ?></td>
                    <?php 
					if(is_array($allsubject) && count($allsubject)>0){
						foreach($allsubject as $sub){
							?><td style="text-align:center">
                            <?php 
							$examResultData=$db->getRow("select * from exammarks where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$stu["idno"]."' and type='".$_REQUEST["term"]."' and subject='".$sub["subject"]."'");
							?>
                            <?php $total=$db->getVal("select total from examterm where school_id='".$_SESSION["admin"]["school_id"]."' and name='".$_REQUEST["term"]."'"); ?>
                             <?php echo FindGrade((int)$examResultData["obtain"],$total); ?>
                             
                             <?php
							 $detail=array("idno"=>$stu["idno"],
							 				"subject"=>$sub["subject"],
											"term"=>$_REQUEST["term"],
											"total"=>$total,
											"class"=>$_REQUEST["cls"]
											);
							$data=base64_encode(json_encode($detail));
							 ?>
                             <input type="hidden" name="detail[]" value="<?php echo $data ?>" />
                             
                            </td><?php
							
						}
					}?>
                </tr>
				<?php
			}
			?></table><?php
		}
 }
elseif($ch=="junior_examSummery"){
	$whereC=array();$subjWhere="";
		if(isset($_REQUEST["cls"]) && $_REQUEST["cls"]!="")
			$whereC[]=" class='".$_REQUEST["cls"]."' ";
					
		$whereM="";
		$whereC[]="session='".$_SESSION["admin"]["session"]."'";
		$whereC[]="school_id='".$_SESSION["admin"]["school_id"]."'";
		
		$whereM1="";
		if(is_array($whereC) && count($whereC)>0)
			$whereM1=" where ".implode(" and ",$whereC);
		
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereC[]=" section='".$_REQUEST["section"]."' ";
		if(is_array($whereC) && count($whereC)>0)
			$whereM=" where ".implode(" and ",$whereC);
		
		$allstudent=$db->getRows("select * from student $whereM and issue_TC=0 and status=1 order by name");
		$allsubject=$db->getRows("select * from sub_junior $whereM1 $subjWhere");
		//echo $db->getLastQuery();echo $db->getErMsg();
	?>
        <center>
        <h4 style="color:green;font-weight:800;margin:3px 0px;">GRADE DETAIL</h4>
        <ul style="padding: 1px 5px;;font-size:11px;color:#fff;font-weight:800;">
                  <li style="float:left;width:24%;background:#2938FF;margin-right: 2px; padding: 5px 1px 5px 5px;">Class : <?php echo $_REQUEST["cls"];?></li> 
                 
                  <li style="float:left;width:24%;background:#EC0D2E;margin-right: 2px; padding: 5px 1px 5px 5px;">Section : <?php echo $_REQUEST["section"];?></li> 
                 
                  <li style="float:left;width:24%;background:#07B714;margin-right: 2px; padding: 5px 1px 5px 5px;">Exam Term : <?php echo $_REQUEST["term"];?></li> 
                  <li style="float:left;width:23%;background:#11AEE4;margin-right: 2px; padding: 5px 1px 5px 5px;">Session : <?php echo $_SESSION["admin"]["session"];?></li> 
                  
               </ul> </center>
     
          <!--<div class="headPrint hide" style="border: none;">
     	  <div style="margin-left:70px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="80px" style="margin:12px 0px 0px 10px;"></div>
         <div style="float:left;text-align:center;"> <h1 style="font-size:45px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
           </div> 
          </div>-->	
	<?php	if(is_array($allstudent) && count($allstudent)>0){
			?><table class="table" cellpadding="0" cellspacing="0">
			<thead>
            <tr style="background: #D5DA13;">
            <td width="2%" style="color:#000;padding:6px;border-left: 1px solid red;">S.No</td>
            <td style="color:#000;padding:6px;text-align:center">Student</td>
            <td style="color:#000;padding:6px;text-align:center">Father's Name</td>
            <?php 
			if(is_array($allsubject) && count($allsubject)>0){
				foreach($allsubject as $sub){
					?><td width="7%" style="color:#000;padding:6px;text-align:center"><?php echo $sub["subject"] ?></td><?php
				}
			}?>
            </tr>
            </thead>
			<?php $ij=0;
			foreach($allstudent as $stu){$ij++;
				?>
				<tr>
                	<td style="border-left: 1px solid red;"><?php echo $ij; ?></td>
                	<td style="text-align:center"><?php echo $stu["name"] ?></td>
                    <td style="text-align:center"><?php echo $stu["fname"] ?></td>
                    <?php 
					if(is_array($allsubject) && count($allsubject)>0){
						foreach($allsubject as $sub){
							?><td style="text-align:center">
                            <?php 
							$examResultData=$db->getRow("select sum(total),sum(obtain) from exammarks_junior where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$stu["idno"]."' and type='".$_REQUEST["term"]."' and subject='".$sub["subject"]."'");
							?>
                            <?php $total=$db->getVal("select total from examterm where school_id='".$_SESSION["admin"]["school_id"]."' and name='".$_REQUEST["term"]."'"); ?>
                             <?php echo $examResultData[1]; ?>
                             
                             <?php
							 $detail=array("idno"=>$stu["idno"],
							 				"subject"=>$sub["subject"],
											"term"=>$_REQUEST["term"],
											"total"=>$examResultData[0],
											"class"=>$_REQUEST["cls"]
											);
							$data=base64_encode(json_encode($detail));
							 ?>
                             <input type="hidden" name="detail[]" value="<?php echo $data ?>" />
                             
                            </td><?php
							
						}
					}?>
                </tr>
				<?php
			}
			?></table><?php
		}
 }
elseif($ch=="classSubject"){
	$subjects=$db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."'");
	?><select name="subject" id="subject" onChange="fetchResult('term','class','subject','section')"><?php
	if(is_array($subjects) && count($subjects)>0){
		?><option value="">Select Subject</option><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["subject"] ?>">
				<?php echo $cla["subject"] ?>
			</option>
			<?php
		}
	}else{
		?><option value="">Please select another class</option><?php
	}
	?></select><?php
}elseif($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="idno" id="idno"><?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
}elseif($ch=="findSubject"){
	
	$subjects=$db->getRows("select * from sub_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	?><select name="subject" id="subject"><?php echo $db->getLastQuery(); print_r($subjects);
	if(is_array($subjects) && count($subjects)>0){
		?><option value="">Subjects</option><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["subject"] ?>">
				<?php echo $cla["subject"] ?>
			</option>
			<?php
		}
	}
	?></select><?php
}elseif($ch=="findDivision"){
	
	$subjects=$db->getRows("select * from sub_div where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	?><select name="division[]" id="division" multiple="multiple"><?php 
	if(is_array($subjects) && count($subjects)>0){
		?><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["div_name"] ?>">
				<?php echo $cla["div_name"] ?>
			</option>
			<?php
		}
	}
	?></select><?php
}elseif($ch=="findSubject_primary"){
	
	$subjects=$db->getRows("select * from primary_subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	?><select name="subject" id="subject"><?php echo $db->getLastQuery(); print_r($subjects);
	if(is_array($subjects) && count($subjects)>0){
		?><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["subject"] ?>">
				<?php echo $cla["subject"] ?>
			</option>
			<?php
		}
	}
	?></select><?php
}elseif($ch=="exam_data"){
	$where="";
	if(isset($_REQUEST["class"]))$where=" AND class='".$_REQUEST["class"]."'";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$aryList=array();
	if($_REQUEST["action"]=="add")
	$aryList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' $where  and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by name");
	else
	$aryList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' $where  and idno in(select distinct(idno) from exammarks) and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by name");
	
	//$aryList=$db->getRows($sql_limit);
	$aryPgAct=array("page_id"=>"make_admission","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['idno'];
			$i++;
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class'])."(".POST($iList['section']).")".'",';
			$aryData.='"'.POST($iList['medium']).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['mobile']).'",';
			$aryData.='"';
			$aryPgAct['term']=$_REQUEST["term"];
			if($_REQUEST["action"]=="add"){
				$aryPgAct['type']="addMarksheet";$aryPgAct['action']="add";
				$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\'><button type=\'button\' class=\'btn btn-info\'>add Marksheer</button></a>';
			}else{ 
				$aryPgAct['type']="view";$aryPgAct['action']="view";$aryPgAct['page_id']="viewmarksheet";
				$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\' ><button type=\'button\' class=\'btn btn-danger\'>View Marksheet</button></a>';
			}
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getErMsg().$db->getLastQuery();
	}
}elseif($ch=="scriteria"){
	
	//echo $_REQUEST['subc'];
	$subc=$db->getRows("select * from criteria where school_id='".$_SESSION["admin"]["school_id"]."' and type='".$_REQUEST["subc"]."'");
	?><select name="sub_criteria" id="sub_criteria"><?php
	if(is_array($subc) && count($subc)>0){
		?><option value="">Select Sub-Criteria</option><?php
		foreach($subc as $sub){
			?>
			<option value="<?php echo $sub["name"] ?>">
				<?php echo $sub["name"] ?>
			</option>
			<?php
		}
	}
	?></select><?php
}elseif($ch=="naz_type"){
	$alltype=array();
	if($_REQUEST["myyupe"]=="criteria"){
		$alltype=$db->getRows("select * from naz_type where type='subject' and class='".$_REQUEST["cla"]."'");
		?><div class="control-group">
            <label class="control-label" for="underof">Select Under of</label>
            <div class="controls">
                <select name="underof" id="underof">
				<option value="">Select</option><?php
				foreach($alltype as $atype){
					?><option <?php if($_REQUEST["selected"]==$atype["id"])echo 'selected';?> value="<?php echo $atype["id"]; ?>"><?php echo $atype["name"] ?></option><?php
				}
				?></select>
			</div>
		</div><?php
	}elseif($_REQUEST["myyupe"]=="subcriteria"){
		$alltype=$db->getRows("select * from naz_type where type='subject' and class='".$_REQUEST["cla"]."'");
		?>
        <input type="hidden" value="mybubnews" id="mssss" />
        <div class="control-group">
            <label class="control-label" for="">Select Subject</label>
            <div class="controls">
                <select onChange="checktypeNew('#mssss','criteriasL',this)">
				<option value="">Select</option><?php
				foreach($alltype as $atype){
					?><option <?php if($_REQUEST["selected"]==$atype["id"])echo 'selected';?> value="<?php echo $atype["id"]; ?>"><?php echo $atype["name"] ?></option><?php
				}
				?></select>
			</div>
		</div><?php
	}elseif($ch=="unlink_file"){
	   // print_r($_REQUEST["type"]);
	   unlink("../marks_excel/". $id);
echo '1';
}
	elseif($_REQUEST["myyupe"]=="mybubnews"){
		$alltype=$db->getRows("select * from naz_type where type='criteria' and underof='".$_REQUEST["unserof"]."' and class='".$_REQUEST["cla"]."'");
		//echo $db->getLastQuery();
		?>
        <input type="hidden" value="mybubnews" id="mssss" />
        <div class="control-group">
            <label class="control-label" for="">Select Criteria</label>
            <div class="controls">
                <select name="underof" id="underof">
				<option value="">Select</option><?php
				foreach($alltype as $atype){
					?><option <?php if($_REQUEST["selected"]==$atype["id"])echo 'selected';?> value="<?php echo $atype["id"]; ?>"><?php echo $atype["name"] ?></option><?php
				}
				?></select>
			</div>
		</div><?php
	}
}

elseif($ch == "getCriteria")
{
    ?>
        <select name="criteria" id="criteria">
        	<option value="">Select Criteria</option>
        	<?php
            $type=$db->getRows("select * from criteria where class='$_POST[cls]' and session='".$_SESSION["admin"]["session"]."' group by type");
			if(is_array($type) && count($type)>0){
				foreach($type as $t){
					?>
					<option <?php if($t["type"]==$_GET["criteria"])echo 'selected';?> value="<?php echo $t["type"] ?>"><?php echo $t["type"] ?></option><?php
				}
			}
			?>
        </select>
    <?php
}

if($ch=="filter_subject"){
    $class = $_POST[classname];
    $section = $_POST['section'];
    ?>
    <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 where class='$class' and section='$section' order by id ASC");
        foreach($allSubjects as $sub){               ?>
        <option value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>  <?php } ?>
    </select>
    <?php
}

?>