<style>
.popup-form{
	margin:6px;
	border:2px solid #600;
	padding:6px;
}
.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-tab{
	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){
	if($_POST['migrate']){
	if(is_array($_POST["idno"]) && count($_POST["idno"])>0){
		for($i=0; $i<count($_POST["idno"]);$i++){
        // echo $_POST['idno'][$i];
			$idno=$db->getVal("select idno from session_idno where is_root='".$_POST["idno"][$i]."' and session='".$_POST["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");
			if($idno==""){
				echo "student <strong>".$_POST["name"][$i]."</strong> not migrated to this session <br>";
			}else{
				$check=$db->getVal("select idno from student where idno='".$idno."' and class='".$_POST["class"]."'");
				if($check!=""){
				    // echo "Select id from otherfee_structure where session ='".$_POST["session"]."' and class ='".$_POST['class']."' and name = 'Back_Dues' and otype='$idno' ";
				    $res=$db->getVal("Select id from otherfee_structure where session ='".$_POST["session"]."' and class ='".$_POST['class']."' and name = 'Back_Dues' and otype='$idno' ");
				    // echo $res;
				    if($res == ""){
				    
					$saveAry=array( "session"=>$_POST["session"],
									"school_id"=>$_SESSION["admin"]["school_id"],
									"added_by"=>$_SESSION["admin"]["uid"],
									"class"=>$_POST["class"],
									"otype"=>$idno,
									"month"=>"1",
									"name"=>"Back_Dues",
									"fee"=>$_POST["left"][$i]
									);
					$flgIn=$db->insertAry("otherfee_structure",$saveAry);
					echo "Rs ".$_POST["left"][$i]." has been successfully added to new seesion for student <strong>".$_POST["name"][$i]."</strong><br />";
				    }
				    else{
						echo "Migrate for student <strong>".$_POST["name"][$i]." </strong> already added to new session. <br />";
					}
				    
				}else{
					echo "student <strong>".$_POST["name"][$i]."</strong> id is $idno but assign another class".$db->getLastQuery()."<br>";
				}
			}
		}	
	}
	}
	elseif($_POST['delete']){
		/*$qry=("Delete from otherfee_structure where session ='".$_POST['session']."' and class ='".$_POST['class']."' and name ='Back_Dues'");
		echo $qry;exit;
		$flgIn1=mysql_query($qry);*/
		
		$res=$db->delete("otherfee_structure","where session ='".$_POST['session']."' and class ='".$_POST['class']."' and name ='Back_Dues'");
			if(!is_null($res)) { echo "All data deleted Successfully"; }
			else { array_push($alert_err,$db->getErMsg()); }
		}
}else{
?>
<form method="post" action="">
<div class="popup-form">
 
  
<strong class="level">Class </strong>
<select class="select-tab" name="class" id="class">
            <option value="">Promoted 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["admissionclass"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                        <?php echo $cla["class"] ?>
                    </option>
                    <?php
                }
            ?>
        </select>
      
<strong class="level">Next Session </strong>
<select class="select-tab" name="session" id="session">
		<?php 
            $class=$db->getRows("select * from session  where school_id='".$_SESSION["admin"]["school_id"]."'  order by session");
            foreach($class as $cla){
                ?>
                <option value="<?php echo $cla["session"] ?>">
                    <?php echo $cla["session"] ?>
                </option>
                <?php
            }
        ?>
        </select>
       
<input type="submit" class="btn-new" name="migrate" value="Migrate" />
<input type="submit" class="btn-delete" name="delete" value="Delete" />
<input type="hidden" name="class_old" value="<?php echo $_GET["class"] ?>">
</div> 
<table class="table" width="100%" border="1" cellpadding="0" cellspacing="0" style="text-align:center;color:#0F05AD;">
<tr>
	<th>No.</th>
    <th>Class</th>
    <th>Name</th>
    <th>Migrate Fee</th>
</tr>
<?php $i=0;
foreach($_GET as $key=>$val){
	$name=explode("`",$key);
	if(is_numeric($val) && $key!="class" && $val!=0){$i++;
	?><tr>
    
    <td><?php echo $i; ?></td>
    <td><?php echo $_GET["class"]; ?></td>
    <td><input type="hidden" name="idno[]" value="<?php echo $name[1] ?>">
	<input type="hidden" name="name[]" value="<?php echo $name[0] ?>"><?php echo $name[0] ?></td>
    <td><input type="hidden" name="left[]" value="<?php echo $val ?>"><?php echo $val ?></td>
    </tr><?php
	}
}
?>
</table>
</form>
<?php
}
?>