<?php	$days = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday'
];

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> !-->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
    
    
    
    <script>
$(document).ready(function(){
  $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myTable tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
</script>

 <script>
$(document).ready(function(){
  $("#myInput2").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myTable2 tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
</script>
<?php
//echo "<pre>";print_r($_SERVER);exit;
	//echo "<pre>";
	if(isset($_POST['calendar'])){
		 $day=$_POST['day'];

			$db->delete("event_detail","where   month='".$_GET['fmonth']."' and session='".$_SESSION["admin"]["session"]."'");

foreach($day as $x => $x_value) {


  $saveAry=array(
            "month"=>$_GET['fmonth'],
            "day"=>$x_value,
            "event"=>$_POST['root'][$x],
             "session"=>$_SESSION["admin"]["session"],
              "school_id"=>$_SESSION["admin"]["school_id"],
              "added_by"=>$_SESSION["admin"]["uid"],

      );
		$flgIn=$db->insertAry("event_detail",$saveAry);
		

    
}

	if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		} 
	
	 }
	 





if(isset($_POST['update_timetable']))
{
			$allperiod=$db->getVal("select class_period from class_period  where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

//print_r($days);

			$db->delete("time_table","where   class='".$_GET['class']."' and section='".$_GET['section']."'  and session='".$_SESSION["admin"]["session"]."'");

    $resulr1=$_POST['subject'];

foreach($days as $x => $x_value) {

for($ii=1;$ii<=($allperiod);$ii++){
    



  $saveAry=array(
            "class"=>$_GET['class'],
            "section"=>$_GET['section'],
            "subject"=>$_POST[$x_value."_".$ii],
            "teacher"=>$_POST["teacher_".$x_value."_".$ii],

            "day"=>$x_value,
             "class_period"=>$ii,
             "session"=>$_SESSION["admin"]["session"],
              "school_id"=>$_SESSION["admin"]["school_id"],
              "added_by"=>$_SESSION["admin"]["uid"],

      );
		$flgIn=$db->insertAry("time_table",$saveAry);
		

    
}




    
}
  
 	if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		} 
    
}


	 
?>

<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="class";
$pgAct="view";

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
}
	?>
    <form method="get" action="">
    <input type="hidden" name="src" value="TimeTable" />
    <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="class_period" class="btn btn-primary">class period</button>
                        <button type="submit" name="calendar" class="btn btn-primary">calendar</button>

                        

					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
                        
                        <div class="control-group span4">
                            <label class="control-label" for="class">Class</label>
                            <div class="controls">
                                <select name="class" 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"]==$_GET["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                                                <?php echo $cla["class"] ?>
                                            </option >
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="control-group span4">
                            <label class="control-label" for="class">Section</label>
                            <div class="controls">
                         <select name="section" 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"]==$_GET["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                            <?php echo $cla["name"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
                            </div>
                        </div>
                        
                        
                        
                        <div class="controls span3" STYLE="width: 150px;">
                                <select name="fmonth" id="fmonth" STYLE="width: 150px;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["fmonth"]==$m)$selected=" selected ";
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                            </div>
                       
                    </div>
                    <br>
				</div>
				<!-- / Forms: Content -->
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";
		

		if(isset($_GET["class_period"])){
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Add Result of students</h3>
                    <div>
						<button type="submihostel" name="update_timetable" class="btn btn-primary"> Save </button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="container">
		<?php
		$whereC=array();
		if(isset($_GET["class"]) && $_GET["class"]!="")
			$whereC[]=" class='".$_GET["class"]."' ";
		
		if(isset($_GET["section"]) && $_GET["section"]!="")
			$whereC[]=" section='".$_GET["section"]."' ";
		$whereM="";
		if(is_array($whereC) && count($whereC)>0)
			$whereM=" where ".implode(" and ",$whereC);
		
			$allperiod=$db->getVal("select class_period from class_period  where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

		//if(is_array($allstudent) && count($allstudent)>0){
			?><table class="table ">
			     
			 <thead>
			<tr>
            <th width="15%">Day</th>
             <?php 
		//	if(is_array($allperiod) && count($allperiod)>0){
				for($ii=1;$ii<=($allperiod);$ii++){
					?><th style="border-left:2px solid black;border-top:2px solid black;border-bottom:2px solid black;border-right:2px solid black;"><center><?php echo $ii;  ?></center></th><?php
				}
		//	}?>
       </thead>
       	<?php $x=0;
					//	$days=$db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
						foreach($days as $d){ $fsAry=array();$final="";
						?><tr>
								<td style="border-right:2px solid #FA0606"><?php echo ucfirst($d) ?><input type="hidden" name="subject[]" value="<?php echo $d ?>" /></td>
								<?php 
								for($i=1; $i<=($allperiod);$i++){
				$data=$db->getRow("select subject,teacher from time_table  where   session='".$_SESSION["admin"]["session"]."' and class='".$_GET['class']."' and section='".$_GET['section']."' and day='".$d."'  and class_period='".$i."'");
			//	echo $ss="select subject,teacher from time_table  where   session='".$_SESSION["admin"]["session"]."' and class='".$_GET['class']."' and section='".$_GET['section']."' and day='".$d."'  and class_period='".$i."'";
							    
						?>
								<td style="border-right:2px solid #FA0606">
                                 <input type="text" name="<?php  echo $d  ?>_<?php  echo $i  ?>"  placeholder="subject name"  value="<?php echo $data["subject"]; ?>" style="width:92px; color:red">
                                 
                                 
                                 
                                 <select name="teacher_<?php  echo $d  ?>_<?php  echo $i  ?>" id="teacher" style="width:110px;">
                                    <option value="">select_Staff</option>
                                    <?php 
                                        $staff=$db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' ");
                                        foreach($staff as $cla){
                                            ?>

                                            <option <?php if($cla["idno"]==$data["teacher"])echo 'selected';?> value="<?php echo $cla["idno"] ?>">
                                                <?php echo $cla["name"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                                
								 </td>
								<?php } }
							?>
       
            </tr>
             </thead>
              <tbody id="myTable">
			<?php $i=0;
			foreach($allstudent as $stu){ $i++;
				?>
				<tr>
                	<td><?php echo $i; ?></td>

               
			 	    
                </tr>
				<?php
			}
			?></table> </tbody><?php
		//}
		?></div></div></div></div></form>
		
		<?php
	}
	

	
		if(isset($_GET["calendar"])){
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Add Result of students</h3>
                    <div>
						<button type="submihostel" name="calendar" class="btn btn-primary"> Save </button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="container">
		<?php
		$whereC=array();
		if(isset($_GET["fmonth"]) && $_GET["fmonth"]!="")
			$month=$_GET["fmonth"];
		
 $days=cal_days_in_month(CAL_GREGORIAN,$month,2020);	
		
			$allperiod=$db->getVal("select class_period from class_period  where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

		//if(is_array($allstudent) && count($allstudent)>0){
			?><table class="table ">
			     
			 <thead>
			<tr>
            <th width="10%">Day</th>
            <th width="40%">Event Name</th>
             
       </thead>
       	<?php $x=0;
					//	$days=$db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
						for($i=1; $i<=($days);$i++){
						?><tr>
								<td ><?php echo $i; ?><input type="hidden" name="day[]" value="<?php echo $i ?>" /></td>
							<?php
					$event=$db->getRows("select * from event");
		
					$data=$db->getVal("select event from event_detail  where   session='".$_SESSION["admin"]["session"]."' and month='".$_GET['fmonth']."'  and day='".$i."' ");
						
							?>
							
							
								<td>
								     
                            <select name="root[]">
                            <option value="">-select-</option>
                            	<?php if(is_array($event) && count($event)>0){
									foreach($event as $hos){
										?><option <?php if($hos["id"]==$data["event"])echo 'selected';  ?> value="<?php echo $hos["id"] ?>"><?php echo $hos["name"] ?></option><?php
									}
								}?>
                            </select>
                                                       
                            </td>	
								<?php 
							 }
							?>
       
            </tr>
             </thead>
              <tbody id="myTable">
		
			
				<?php
			
			?></table> </tbody><?php
		//}
		?></div></div></div></div></form>
		
		<?php
	}
	
	if(isset($_GET["student_installment"])){
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Add Result of students</h3>
                    <div>
						<button type="update_installmen" name="update_student_installment" class="btn btn-primary">Save </button>
					</div>
				</div>

					 </div>
				<div class="well no-padding">
                	<div class="controls controls-row" >
                	    
                	    <div style="overflow-x:scroll;width:100%;">

		<?php
         $cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");
         
         $where = " session='".$_SESSION["admin"]["session"]."' ";
         
         if($_GET["class"]!=""){
             $where .= " and class='".$_GET["class"]."' ";
         }
         
          if($_GET["section"]!=""){
             $where .= " and section='".$_GET["section"]."' ";
         }

		$allstudent=$db->getRows("select * from student where $where and school_id='".$_SESSION["admin"]["school_id"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");

		if(is_array($allstudent) && count($allstudent)>0){
			?>
			
			<table class="table" >
			<tr>
            <td>SNo.</td><td>Student name</td><td>Father Name</td><td>class</td><td>Install 1</td><td>Install 2</td>
            <td>Install 3</td><td>Install 4</td><td>Install 5</td><td>Install 6</td><td>Install 7</td>
            <td>Install 8</td><td>Install 9</td><td>Install 10</td><td>Install 11</td><td>Install 12</td>
            </tr>
			<?php $i=0;
			foreach($allstudent as $stu){ $i++;
				?>
				<tr>
                	<td><?php echo $i; ?></td>
             	    <td><?php echo $stu["name"]; ?></td>
					<td><?php echo $stu["fname"]; ?></td>
					<td><?php echo $stu["class"]; ?></td>
					<?php 
					//echo $stu[idno];
					$aryForm=$db->getRow("SELECT * FROM installment WHERE school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$stu["idno"]."'");
                     ?>
					<input type="hidden" name="idno[]" required  value="<?php echo $stu["idno"] ?>" readonly="readonly" />

                    <td>
                       <div class="controls">
						  <input type="text" name="i1<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i1"]; ?>" style="width:80px;">
						</div>
                    </td>
              
			 	    <td>
                       <div class="controls">
						  <input type="text" name="i2<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i2"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i3<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i3"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i4<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i4"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i5<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i5"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i6<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i6"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i7<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i7"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i8<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i8"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i9<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i9"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i10<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i10"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i11<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i11"]; ?>" style="width:80px;">
						</div>
                    </td>
                    
                    <td>
                       <div class="controls">
						  <input type="text" name="i12<?php echo $stu["idno"] ?>" class="input-block-level" value="<?php echo $aryForm["i12"]; ?>" style="width:80px;">
						</div>
                    </td>

                </tr>
				<?php
			}
			?></table><?php
		}
		?>
		</div>
		</div></div></div></div></form>
		
		<?php
	}?>
</body>
</html>	
<script type="text/javascript">
// Material Select Initialization
$(document).ready(function() {
$('.mdb-select').materialSelect();
});
    
    
    
    function filterRecord(){
 alert();
 var classname = document.getElementById("class").value;
 var subject = document.getElementById("mySelect1").value;
 var subsubject = document.getElementById("subSubjectid").value;  
 var chapter = document.getElementById("chapter").value;   

  document.getElementById('filterdata').innerHTML = 'hee';

   // $.post( "Notice/ajax.php", { type: "filterRecord" ,classname: classname ,subject: subject ,subsubject: subsubject , chapter: chapter} , function( data ) {
//alert(data);
  //document.getElementById('filterdata').innerHTML = data;
  //  });
}

	//$(document).ready(function() {
    //$('#example').DataTable();
//} );

    </script>