<?php
//echo "<pre>";print_r($_SERVER);exit;
	//echo "<pre>";
	if(isset($_GET['roll_no'])){
				$i=0;
				$where="";
			if(isset($_GET["section"]) && $_GET["section"]!="")$where=" and section='".$_GET["section"]."'";
			$student=$db->getRows("select name,idno,fname from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and class='".$_GET["class"]."' $where order by name");
			//print_r($student);
			foreach($student as $stu){$i++;
				$reffarray=array('fincome'=>$i);
								//print_r($reffarray);
				$inup1=$db->updateAry("student",$reffarray," where session='2015-2016' and idno=".$stu["idno"]."");
			}
				$_SESSION['msg']="Roll No of class : ".$_GET['class']." generated successfully..!";
			
	 }
	 
if(isset($_POST["busroot"])){
	
	
if(is_array($_POST["sibling"]) && count($_POST["sibling"])>0)

$resulr1=array_filter($_POST["sibling"]);
	
$db->delete("assign_teacher","where   is_class_teacher='0' and class='".$_GET["class"]."' and section='".$_GET["section"]."'");

$dataBus=array();
foreach($resulr1 as $x => $x_value) {
	
	
$saveAry=array(
              "class"=>$_GET["class"],
              "section"=>$_GET["section"],
              "teacher_id"=>$_POST["sibling"][$x],
              "is_class_teacher"=>0,
		      "session"=>$_SESSION["admin"]["session"],
		      "school_id"=>$_SESSION["admin"]["school_id"],
		      "added_by"=>$_SESSION["admin"]["uid"]

					);
		
$flgUp=$db->insertAry("assign_teacher",$saveAry);
}
if(!is_null($flgUp))
		{
			
			$_SESSION['msg']='update Successfully';
		}
}

if(isset($_POST["class_teacher"])){
	
	
if(is_array($_POST["sibling"]) && count($_POST["sibling"])>0)

$resulr1=array_filter($_POST["sibling"]);
$db->delete("assign_teacher","where   is_class_teacher='1' and class='".$_GET["class"]."' and section='".$_GET["section"]."'");

$dataBus=array();
foreach($resulr1 as $x => $x_value) {
	
//	$db->delete("assign_teacher","where  teacher_id=".$_POST["sibling"][$x]." and is_class_teacher='1' and class='".$_GET["class"]."' and section='".$_GET["section"]."'");
	
$saveAry=array(
              "class"=>$_GET["class"],
              "section"=>$_GET["section"],
              "teacher_id"=>$_POST["sibling"][$x],
              "is_class_teacher"=>1,
		      "session"=>$_SESSION["admin"]["session"],
		      "school_id"=>$_SESSION["admin"]["school_id"],
		      "added_by"=>$_SESSION["admin"]["uid"]
		      

					);
		
$flgUp=$db->insertAry("assign_teacher",$saveAry);
}
if(!is_null($flgUp))
		{
			
			$_SESSION['msg']='update Successfully';
		}
}	
	 
?>

<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_teacher";
$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="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="class_teacher" class="btn btn-primary">Assign Class Teacher</button>
                         <button type="submit" name="teacher" class="btn btn-primary">Assign Subject  Teacher</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="control-group span4">
                             <div class="control-group">
							<label class="control-label" for="sibling">Teacher</label>
							<div class="controls">
							<select class="span12" name="sibling[]" id="sibling" multiple="multiple">
                                	<option value="">none</option>
									<?php 
										$student=$db->getRows("select * from staff where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
										
										
										
										foreach($student as $st){
											
											
											?>
											<option <?php if($st["idno"]==$aryForm["sibling"])echo 'selected';?> value="<?php echo $st["idno"] ?>">
												 <?php echo $st["name"]." - department- ".$st["department"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>
                        </div>
                       !-->
                    </div>
                    <br>
				</div>
				<!-- / Forms: Content -->
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";	
	
	if(isset($_GET["class_teacher"])){
	  
	    $where="";
	    if(isset($_REQUEST['section']) && trim($_REQUEST['section'])!=""){
			$conwhere.=" and section='".$_REQUEST['section']."' ";
	    }
			if(isset($_REQUEST['class']) && trim($_REQUEST['class'])!=""){
			$conwhere.=" and class='".$_REQUEST['class']."' ";
			}
		
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Assign Class Teacher</h3>
                    <div>
						<button type="submit" name="class_teacher" class="btn btn-primary"> Save </button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
		
		 <!-- <div class="control-group span4">
                            <label class="control-label" for="class" onchange="findteacher()">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 span3">
                            
                            <div class="controls span3">
                               <select name="section" onchange="findteacher()" 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 class="control-group span3">
							<label class="control-label" for="sibling">Teacher</label>
							<div class="controls" id="findStudent">
					         <select  name="idno[]" id="idno" multiple="multiple">
                               <option value="">All Staff</option>
                              </select>
                       </div></div> !-->
                       
                       
                       
		 <div class="control-group span4">
                             <div class="control-group">
							<label class="control-label" for="sibling">Teacher</label>
							<div class="controls">
							<select class="span12" name="sibling[]" id="sibling" multiple="multiple">
                                	<option value="">none</option>
									<?php 
										$student=$db->getRows("select * from staff where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

										foreach($student as $st){
  $teacher_sib=$db->getval("select teacher_id from assign_teacher where teacher_id='".$st['idno']."' and class='".$_GET['class']."' and section='".$_GET['section']."' and 	is_class_teacher='1' " );
	
											?>
											<option <?php if($st["idno"]==$teacher_sib)echo 'selected';?> value="<?php echo $st["idno"] ?>">
												 <?php echo $st["name"]." - department- ".$st["department"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>
                        </div> 
		</div></div></div></div></form><?php
	}
	
	
		if(isset($_GET["teacher"])){
		    
		      $where="";
	    if(isset($_REQUEST['section']) && trim($_REQUEST['section'])!=""){
			$conwhere.=" and section='".$_REQUEST['section']."' ";
	    }
			if(isset($_REQUEST['class']) && trim($_REQUEST['class'])!=""){
			$conwhere.=" and class='".$_REQUEST['class']."' ";
			}
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Assign Subject  Teacher</h3>
                    <div>
						<button type="submit" name="busroot" class="btn btn-primary"> Save </button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">

                            <div class="control-group span4">
                            <div class="control-group">
							<label class="control-label" for="sibling">Subject Teacher</label>
							<div class="controls">
							<select class="span12" name="sibling[]" id="sibling" multiple="multiple">
                            	<option value="">none</option>
								<?php 
									$student=$db->getRows("select * from staff where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

									foreach($student as $st){
    $teacher_sib=$db->getval("select teacher_id from assign_teacher where teacher_id='".$st['idno']."' and class='".$_GET['class']."' and section='".$_GET['section']."' and 	is_class_teacher='0' " );

											?>
											<option <?php if($st["idno"]==$teacher_sib)echo 'selected';?> value="<?php echo $st["idno"] ?>">
												 <?php echo $st["name"]." - department- ".$st["department"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>
                        </div> 

		</div></div></div></div></form><?php
	}
	?>
<script type="text/javascript">	
	function findteacher(t){
	var cls=$("#class").val();
	var section=$("#section").val();
//	alert(section);
//	alert(cls);
	$.post( "Faculty/ajax.php", { type: "findteacher" ,cls: cls, section: section } , function( data ) {
	   // alert(data);
	  	$("#findStudent").html(data);
	});
}
</script>