<?php
//echo "<pre>";print_r($_SERVER);exit;

function insertData($class, $db)
{
if(empty($class))
return;

$sections = $_POST['sections'][$class];
if( count($sections) > 0 ) {

foreach( $sections as $section){

$newExam = array(
"section" => $section,
"class" => $class,
"teacher_id"=>$_GET['teacher'],
"school_id"=>$_SESSION["admin"]["school_id"],
"session"=>$_SESSION["admin"]["session"]
);
$db->delete("remarks_role","where section = '$section' and class='$class' and teacher_id=$_GET[teacher]");
$db->insertAry("remarks_role",$newExam);
}
} else {

$newExam = array(
"section" => '',
"class" => $class,
"teacher_id"=>$_GET['teacher'],
"school_id"=>$_SESSION["admin"]["school_id"],
"session"=>$_SESSION["admin"]["session"]
);


$db->delete("remarks_role","where section = '$section' and class='$class' and teacher_id=$_GET[teacher]");
$db->insertAry("remarks_role",$newExam);

}

}

if($_POST){
 
if(is_array($_POST["classes"]) && count($_POST["classes"])>0){
    
$teacher_ex=$db->getVal("select id  from remarks_role where teacher_id='".$_GET['teacher']."' and session='".$_SESSION["admin"]["session"]."'   ");

	if($teacher_ex){
		$db->delete("remarks_role","where teacher_id='".$_GET['teacher']."'");
	}
foreach($_POST["classes"] as $class){
insertData($class, $db);
}

}

}
?>

<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="remarks_role";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
$pgAct=strtolower($_GET['action']);

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></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></b> <?php echo $alert_err[0] ?></i>
</div>
<?php
}
?>
    <form method="get" action="">
        <input type="hidden" name="src" value="Notice" />
    <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="submit" name="remarks_role"  class="btn btn-primary">Remarks Role</button>
                                            
</div>
</div>
<div class="well no-padding">
                <div class="controls controls-row">
                        
                      <div class="control-group span4">
                            <label class="control-label" for="class">Teacher List</label>
                            <div class="controls">
                                <select name="teacher" id="teacher">
                                    <option value="">Teacher</option>
                                    <?php 
                                        $staff=$db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' ");
                                        foreach($staff as $cla){
                                            ?>
                                            <option <?php if($cla["idno"]==$_GET["teacher"])echo 'selected';?> value="<?php echo $cla["idno"] ?>">
                                                <?php echo $cla["name"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
         
                   
                    </div>
                    <br>
</div>
<!-- / Forms: Content -->
</div>
    </div>
    </form>
<?php
$where=array();
$qry="";
if(isset($_GET["remarks_role"])){
?><form method="post" action="">
<div class="row-fluid">
            <div class="span12">
            <div class="top-bar">
<h3><i class="icon-cog"></i>Assign Remarks role </h3>
                    <div>
<button type="submit"  class="btn btn-primary"> Save </button>
</div>
</div>
<div class="well no-padding">
                <div class="controls controls-row">


<?php
$whereC=array();
if(isset($_GET["class"]) && $_GET["class"]!="")
$whereC[]=" class='".$_GET["class"]."' ";

/*if(isset($_GET["medium"]) && $_GET["medium"]!="")
$whereC[]=" medium='".$_GET["medium"]."' ";
*/	
$whereM="";$whereM1="";
if(is_array($whereC) && count($whereC)>0)
$whereM1=" where ".implode(" and ",$whereC);

if(isset($_GET["section"]) && $_GET["section"]!="")
$whereC[]=" section='".$_GET["section"]."' ";
if(is_array($whereC) && count($whereC)>0)
$whereM=" where ".implode(" and ",$whereC);

         $allclass=$db->getRows("select class from class where school_id='".$_SESSION["admin"]["school_id"]."' ");
?>           
            <table class='table' >

            <?php 

if(is_array($allclass) && count($allclass)>0){

foreach($allclass as $sub){

?>
<tr style="font-size: 15px;">

                <td><?php echo $sub["class"] ?> <input type="checkbox" name="classes[]" value="<?php echo $sub["class"] ?>" <?php $chcks= $db->getVal("SELECT  id  FROM  remarks_role where class='".$sub["class"]."'  and teacher_id='".$_GET['teacher']."' ");  if ($chcks) echo "checked='checked'"; ?>></td>	
<?php
        $allsection=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
if(is_array($allsection) && count($allsection)>0){
foreach($allsection as $sec){
?><td><?php echo $sec["name"] ?>
      <input type="checkbox" style="width:40px" name="sections[<?php echo $sub["class"] ?>][]" value="<?php echo $sec["name"] ?>" <?php $chck= $db->getVal("SELECT  id  FROM  remarks_role where class='".$sub["class"]."' and section='".$sec["name"]."' and teacher_id='".$_GET['teacher']."' ");  if ($chck) echo "checked='checked'"; ?>>
   
            <?php   $sub["class"];
               $detail=array("class"=>$sub["class"]


);
$data=base64_encode(json_encode($detail));
?>
                             <input type="hidden" name="detail[]" value="<?php echo $data ?>" />	  

   </td>	
<?php }  }	
}
}?>
            </tr>

<?php
}
?></table>

<?php
//}
?></div></div></div></div></form><?php


echo $db->getErMsg();
?>
<script type="text/javascript">

$(document).ready(function(){
/*$("student").change(function(){
var v=this.val();
alert(v);
});*/
});
function validateme(a){
var v=parseInt(a.value);
var t=$('#total').val();
//	var r=$(this).val();
if(v>t){
alert("Please enter correct marks");
//return false;
a.value='';
}
else if(isNaN(v)){
alert("Please enter only number");
a.value='';
}
//alert(r);
}
</script>
<style type="text/css">
@media print {
    #myPrntbtn {
        display :  none;
    }
}

@media screen {
   #myPrntbtn1 {
        display: none;
    }
}
</style>
