<style>
.popup-form{
	margin:0px;
	border:2px solid #600;
	padding:5px;
}
.title{
  text-align: center;
  color: #fff;
  background-color: #A7A1A1;
  padding: 4px;
  border: 1px inset #1443BD;
  box-shadow: 0px 0px 10px #050101;
  border-radius: 5px;
}
.btn-new{
  background-color: #05967A;
  color: #fff;
  border: 2px outset #05967A;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
  box-shadow: 0px 2px #352E2E;
}
.btn-delete{
  background-color: #CA1A1A;
  border: 2px outset #CA1A1A;
  box-shadow: 1px 3px #322C2C;
  color: #fff;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
}
.select-text{
	padding: 3px;
  border: 2px solid #747171;
  color: #380303;
  font-weight: 600;
}
.level, .btn-new, .btn-delete{
	margin-left: 10px;
  margin-right: 5px;
}
</style>
<?php
if($_POST){
	//print_r($_POST);
	$pre_class=trim($_POST['pre_class']);
	unset($_POST['pre_class']);
	//print_r($_POST);
	$f=$db->updateAry("student",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	
	$f1=$db->updateAry("otherfee_structure",$_POST,"where  otype='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	
	//$current_id=$db->getRows("select id, name from extrafee_type where  class='".$_POST['class']."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	$pre_id=$db->getRows("select id,type from extrafee_type where  class='".$pre_class."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
if(!empty($pre_id)){
	foreach($pre_id as $pre_id1){
		$current_id=$db->getVal("select id from extrafee_type where  type='".$pre_id1['type']."' and class='".$_POST['class']."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
if(!empty($current_id)){
		$u=array(type=>$current_id);
			
		$test=$db->updateAry("extrafee",$u,"where idno ='".$_GET['id']."' and type='".$pre_id1[id]."'  ");
          }
		  
		  
		}
}else{
		// previous is empty but current is not empty
		
		/*$cure_id=$db->getRows("select id,type from extrafee_type where  class='".$_POST['class']."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");

	foreach($cure_id as $cure_id1){
		$current_id1=$db->getVal("select id from extrafee_type where  type='".$cure_id1['type']."' and class='".$_POST['class']."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
/*if(!empty($current_id1)){
		$u=array(type=>$current_id1);
			
		$test=$db->updateAry("extrafee",$u,"where idno ='".$_GET['id']."' and type='".$cure_id1[id]."' ");
          }*/
		  
		$extrafee1=$db->getRows("select * from extrafee_type where class='".$_POST["class"]."' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); 
		
		foreach($extrafee1 as $extrafee){
		
		$saveAry=array(

						"session"	=>	$_SESSION["admin"]["session"],

					    "school_id"	=>	$_SESSION["admin"]["school_id"],

					    "added_by"	=>	$_SESSION["admin"]["uid"],

					    "type"	=>	$extrafee["id"],

						"idno"	=>	$_GET['id'],

						"pay"	=> 	0,

						"status"	=>	1

						);
		               for($i=1; $i<=12;$i++){

							if($extrafee["p".$i]>"0"){

								$saveAry["pid"]="p".$i;

								$saveAry["fee"]=$extrafee["p".$i];

								$db->insertAry("extrafee",$saveAry);

							}

						}
		  	 
		}
  }
		
		
		

if(!empty( $idno_exist)){
	
	
}

	if($f){  echo 'Changed'; }
	
}
?>
<h2 class="title">Change Class</h2>
<form method="post" action="">
<table>
    <tr>
        <th>Name</th>
		<th></th>
		<th></th>
		<th></th>
        <th>Class</th>
        <th></th>
        <th></th>
        		
    </tr>
	<?php  
?>
    <tr>
               
         <td><?= $n=$db->getVal("select name from student where  idno='".$_GET[id]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");?>
		 <?php $_SESSION["class"]=$db->getVal("select class from student where  idno='".$_GET[id]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'"); ?>
		 </td> 
		 <td></td>
		 <td></td>
		 <td></td>

<td><select  class="span12" name="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><td>
<td><input type='hidden' name='pre_class' value=" <?= $_SESSION["class"] ?>"></td>								
            
      <td><input type='submit' value='Submit'></td>
  
    </tr>
	
	
</table>
</form>
