<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>
<?php
$pgMod="exam";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
if($_POST){
	//echo "<pre>";//print_r($_POST);exit;
	$i=0;
	//echo $db->getlastQuery().$res;;exit;
	foreach($_POST["type"] as $type){
		$newExam=array();
		$newExam["type"]=$type;
		foreach($_POST["subject"] as $subject){
			$newExam["subject"]=$subject;
			$newExam["class"]=$_POST["class"];
			$newExam["total"]=$_POST[$subject][$i];
			$newExam["school_id"]=$_SESSION["admin"]["school_id"];
            $newExam["added_by"]=$_SESSION["admin"]["uid"];
  			$newExam["session"]= $_SESSION["admin"]["session"];
		//$res=$db->delete("examtype","where class='".$_POST["class"]."' and subject='".$subject."' and type='".$type."' and session='".$_SESSION["admin"]["session"]."'");
			$db->insertAry("examtype",$newExam);
			//print_r($newExam);
		}
		$i++;
	}
	redirect();
	//echo "</pre>";exit;
}
elseif($pgAct=="delete" && isset($_GET['class']) && trim($_GET['class'])!='')
{
	$res=$db->delete("examtype","where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET['class']."'");
//	$res2=$db->delete("subject_mp","where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET['class']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; 
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Exam", "page_id"=>$pgMod)));}
	else { array_push($alert_err,$db->getErMsg()); }
	
} 
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 $_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
}
?>
<script type="text/javascript">

function createExam(cla,exam,utype){
	if(cla==""){
		alert("Please select class");
	}
	else if(exam=="" && utype=="add"){
		alert("Please enter no of exams");
	}
	else{
		$.post( "Exam/ajax.php", { type: "NoOfExam", class: cla, noexam:exam, action:utype} , function( data ) {
			$("#detail").html(data);
		});
	}
}
</script>
<input type="hidden" name="src" value="Exam" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Search Student Record</h3>
                    <div>
						<button type="button" name="fee" onClick="createExam($('#class').val(),$('#noexam').val(),'add')" class="btn btn-primary"> Create</button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
                        <div class="control-group span6">
                            <label class="control-label" for="class">Class</label>
                            <div class="controls">
                                <select name="class span12" id="class">
                                    <option value="">Class</option>
                                    <?php 
                                        $class=$db->getRows("select * from class  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>
                            </div>
                        </div>
                        <div class="control-group span6">
                            <label class="control-label" for="class">No of Exam</label>
                            <div class="controls">
                                <input type="text" name="noexam" id="noexam" /> 
                            </div>
                        </div>
                    </div>
                    
                    <br>
				</div>
				<!-- / Forms: Content -->

			</div>
    </div>
    
    <div id="detail">
    	<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>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Exam", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select distinct(class) from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class!='' and session='".$_SESSION["admin"]["session"]."' order by class");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>Class</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>
                         <button onClick="createExam('<?php echo $clist["class"] ?>','0','edit')" type="button" class="btn btn-info">Edit Exam</button>
        				<?php $aryPgAct['action']="delete";$aryPgAct['class']=$clist["class"]; ?>
                         <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 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><?php echo $db->getErMsg(); ?>
        </div>
        <?php
	}
	?>
	</div></div></div>
    </div>