<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: 96.7% !important;overflow: inherit !important;} 
</style>
<?php
$pgMod="otherfee_discount";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['class']) || trim($_POST['class'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please select class.");
	}elseif(!isset($_POST['other_id']) || trim($_POST['other_id'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please select Offer to.");
	}
	elseif(!isset($_POST['idno']) || trim($_POST['idno'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please select student.");
	}
	elseif(!isset($_POST['discount']) || trim($_POST['discount'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter discount.");
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$LinksDetails["id"];
		$_POST["session"]=$_SESSION["admin"]["session"];
		if($_POST["section"]=="")unset($_POST["section"]);
       $_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("otherfee_discount",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Student","page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
		$_POST["session"]=$_SESSION["admin"]["session"];
		$flgUp=$db->updateAry("otherfee_discount",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
		//echo $db->getLastQuery();exit;
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Student","page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("otherfee_discount","where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Student","page_id"=>$pgMod)));
} 
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
}
if($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM otherfee_discount WHERE school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New otherfee Discount</h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">
                		<div class="control-group">
							<label class="control-label" for="class">Class Name</label>
							<div class="controls">
								<select name="class" id="class" onchange="getStudentlist();getOtherFeelist(this.value);">
                                    <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>
							</div>
						</div>
                        <div class="control-group">
                            <label class="control-label" for="class">Section</label>
                            <div class="controls">
                               <select name="section" id="section" onchange="getStudentlist();" >
                <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 ">
							<label class="control-label" for="otype">Offer to</label>
							<div class="controls" id="studentList">
								<select name="otype" id="otype">
                                    <option value="">select Student</option>
                                </select>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="name">Other Fee</label>
							<div class="controls" id="Otfee">
								<select name="class" id="class">
                                    <option value="">select other fee</option>
                                </select>
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="discount">Discount Fees</label>
							<div class="controls">
								<input type="number" id="discount" name="discount" required class="input-block-level" value="<?php if($_POST)echo $_POST["discount"]; else echo $aryForm["discount"] ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="detail">Discount detail</label>
							<div class="controls">
								<textarea id="detail" name="detail" class="input-block-level"><?php if($_POST)echo $_POST["detail"]; else echo $aryForm["detail"] ?></textarea>
							</div>
						</div>
                        
                        
                        
						<div class="form-actions">
							<button type="submit" class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
	</div>
<?php   
}else{
	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    <button style="float:right; margin-top:5px" onclick="window.location='./?src=Student&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Student","page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM otherfee_discount where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'"); $i=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                	<th>Student</th>
                    <th>Other Reason</th>
                    <th>Class</th>
                    <th>Discount</th>
                    <th>Details</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                	<td><?php echo mydetail("name",$clist["idno"],"student") ?></td>
                    <td><?php echo $db->getVal("select name from otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$clist["other_id"]."'") ?></td>
                    <td><?php echo $clist["class"];//."(".$clist["medium"].")" ?></td>
                    <td><?php echo $clist["discount"] ?></td>
                    <td><?php echo $clist["detail"] ?></td>
                    <td>
                    <?php $aryPgAct['action']="edit";$aryPgAct['page_id']=$pgMod; ?>
                         <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                    <?php $aryPgAct['action']="delete"; ?>
                         <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th></th>
                    <th colspan="4"></th>
                </tr>
            </tfoot>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div></div></div>
	<?php
}
?>
<!-- / Forms -->
<script>
<?php 
//echo"<pre>";print_r($aryForm);echo"</pre>";
if(is_array($aryForm) && count($aryForm)>0){?>
$(document).ready(function(e) {
    getStudentlist('<?php echo $aryForm["class"] ?>');
	getOtherFeelist('<?php echo $aryForm["class"] ?>');
});
<?php }?>
function getStudentlist(){
	var id=$("#class").val();
	var section=$("#section").val();
	$.post( "ajax.php", { type: "getOtherStudentlist" ,class: id <?php if(is_array($aryForm) && count($aryForm)>0) echo ',idno:"'.$aryForm["idno"].'"'; ?>, section: section} , function( data ) {
	  	$("#studentList").html(data);
	});
}
function getOtherFeelist(id){
	$.post( "ajax.php", { type: "getOtherStudentFee" ,class: id <?php if(is_array($aryForm) && count($aryForm)>0) echo ',other_id:"'.$aryForm["other_id"].'"'; ?>} , function( data ) {
	  	$("#Otfee").html(data);
	});
}
</script>