<style>

.popup-form{
	margin:0px;
	border:2px solid #600;
	padding:5px; 
}
.title{
  text-align: center; 
  color: #fff;
  background-color: #1443BD;
  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(isset($_POST['update_student'])){

	$saveAry=array(
	                "name"          =>  $_POST["name"],
					"fname"         =>  $_POST["fname"],
					"mname"         =>  $_POST["mname"],
					"section"       =>  $_POST["section"],
					"mobile"        =>  $_POST["mobile"],
					"feducation"    =>  $_POST["account"]
				);

    $flgUp=$db->updateAry("student", $saveAry, "where session='".$_SESSION["admin"]["session"]."' and idno='".$_GET["idno"]."' ");

	if($flgUp)	{	
    	echo "Record Save Successfully<br>".$db->getErMsg();
		}
	else{
		echo "Please enter Detail<br>";
	}
}

if(isset($_POST['update_discount_mode'])){
    $saveAry=array(
	                "discount_mode"    =>  $_POST["discount_mode"],
				);

    $flgUp=$db->updateAry("tbl_info", $saveAry, "where 1 ");

	echo "Discount Mode Updated Successfully<br>";

}


if(isset($_POST['add_fees'])){
	$chkname=$db->getVal("select id from otherfee_structure where otype='".$_GET['idno']."' and name='".$_POST['title']."'");
    $classname=$db->getVal("select class from student where idno='".$_GET['idno']."' and session='".$_SESSION["admin"]["session"]."' ");

    	if($chkname>0){
    		echo 'This fee is already submitted , please enter another fee title';
			unset($_SESSION['form']);
// 			redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
// 			exit;
		}else {
		    
	    		$feename = $_POST['title'];
            	$extra_name = str_replace(' ', '_', $feename);

            	$saveAry1=array("name"      => $extra_name,
					            "class"     =>  $classname,
					            "fee"       =>  $_POST['fixedfee'],
					            "month"     =>  $_POST['month'],
					            "otype"     =>  $_GET["idno"],
					            "session"    =>  $_SESSION["admin"]["session"],
					            "school_id" =>  $_SESSION["admin"]["school_id"],
					            "added_by"  =>  $_SESSION["admin"]["uid"],
				);

        	 $check_val=$db->getVal("Select id from otherfee_structure where otype='".$_GET["idno"]."' and name='".$_POST['title']."' and fee='".$_POST['fixedfee']."' and month='".$_REQUEST['month']."'  and session='".$_SESSION["admin"]["session"]."'");
        
            if (!empty($check_val)) {
                // $ary_exit[]=$name;
            }
            else
            {
            	$flgIn=$db->insertAry("otherfee_structure",$saveAry1);
            }
		}
}
/*
if($_POST){
	print_r($_POST);
	die();
	$saveAry=array("name"=>$_POST["name"],
					"fname"=>$_POST["fname"],
					"mname"=>$_POST["mname"],
					"section"=>$_POST["section"],
					"mobile"=>$_POST["mobile"],
					"feducation"=>$_POST["account"],
				   "bus_status"=>$_POST["bus_status"]
				);

    $flgUp=$db->updateAry("student",$saveAry,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");


	$chkname=$db->getVal("select id from otherfee_structure where otype='".$_GET['id']."' and name='".$_POST['title']."'");

    $classname=$db->getVal("select class from student where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."' ");
    
    	if($chkname>0){
    		$_SESSION['msg']='Back Dues is already submitted for this fee title please enter another fee title';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
			exit;
		}else {
            	$saveAry1=array("session"    =>  $_SESSION["admin"]["session"],
					            "school_id" =>  $_SESSION["admin"]["school_id"],
					            "added_by"  =>  $_SESSION["admin"]["uid"],
					            "class"     =>  $classname,
					            "month"     =>  $_POST['month'],
					            "otype"     =>  $_GET["id"],
				);

        	 $check_val=$db->getVal("Select id from otherfee_structure where otype='".$_GET["id"]."' and name='".$_POST['title']."' and fee='".$_POST['fixedfee']."' and month='".$_REQUEST['month']."'  and session='".$_SESSION["admin"]["session"]."'");
        
            if (!empty($check_val)) { 
                // $ary_exit[]=$name;
            }
            else
            {
            	$flgIn=$db->insertAry("otherfee_structure",$saveAry1);
            }
		}

	if($flgUp)	{	
    	echo "Record Save Successfully<br>".$db->getErMsg();
		}
	else{
	//	echo "Please enter Detail<br>";
	}
}
*/
$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['idno']."'");
?>
<link rel="stylesheet" href="<?php echo URL_ROOT; ?>js/jquery-ui.css">
<script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<script src="<?php echo URL_ROOT; ?>js/jquery-ui.js"></script>
<script>
var add_tr='<tr id="row_1"><td ><input type="text" class="st-forminput" style="width:86%;" name="attr_month[]" /></td><td ><textarea type="text" class="st-forminput" style="width:86%;" name="attr_name[]" ></textarea></td><td><input type="text" class="st-forminput" style="width:90%;" name="attr_value[]" /></td><td><a class="delete" href="javascript:;">X</a></td></tr>';
$(document).ready(function(){
	$("#add").click(function(){
		$("#tbody").append($(add_tr));
	
		$('#tbody td a.delete').on('click',function() { 
			var rowCount = $('#tbody tr').length;
			if(rowCount<=1){
				//alert("This item cannot deleted !!!");
			}else{
				$(this).parent().parent().remove(); 
			}
		});	
	});
});
function fetchDetail(ids){
	var values=$(ids).val();
	 $.getJSON("ajax.php?type=getValByRecepit&id="+values, function(field){
		 //alert(field.month)
		$("#month").val(field.month)
		$("#name").val(field.name)
		$("#value").val(field.value)
    });
}
$(function() {
	$(".datepicker").each(function(index, element) {
        var d = new Date(); // for now
		datetext=d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
		$( this ).datepicker({
		  changeMonth: true,
		  changeYear: true,
		  showOn: "button",
		  buttonImage: "<?php echo URL_ROOT ?>js/images/calendar.gif",
		  buttonImageOnly: true,
		  buttonText: "Select date",
		  dateFormat: 'yy-mm-dd ',
		  onSelect: function(datetext){
			var d = new Date(); // for now
			datetext=datetext+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			$(this).val(datetext);
		  }
		});
    });
});


</script>

<h2 class="title">Student  Detail</h2>

<center><table>
     <?php
    	$aryForm=$db->getRow("SELECT name,fname,mname,class,section,mobile,feducation,bus_status FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["idno"]."'");

  ?>
   <div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i></h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

                    <div style="width:49%;display:inline-block;">
                            <table style="display:inline-block;">
                            </table>
                    </div>

                    <div style="width:49%;display:inline-block;">
                            <table style="display:inline-block;">
                            </table>
                    </div>                

            <div style="display:flex;margin-top:-30px;">

                <div style="width:40%; border: 4px solid black;background: #C1CCD8;">
                    <form method="post" action="">
                    <table width="100%">
                        <tr>
                            <td>STUDENT NAME</td>
                            <td><input type="text" name="name" class="input-block-level" value="<?php if($_POST)echo $_POST["name"]; else echo $aryForm["name"] ?>"></td>
                        </tr>

                        <tr>
                            <td>FATHER NAME</td>
                            <td><input type="text" name="fname" class="input-block-level" value="<?php if($_POST)echo $_POST["fname"]; else echo $aryForm["fname"] ?>"></td>

                        </tr>
 
                        <tr>
                            <td>MOTHER NAME</td>
                            <td><input type="text" name="mname" class="input-block-level" value="<?php if($_POST)echo $_POST["mname"]; else echo $aryForm["mname"] ?>"></td>
                        </tr>

                        <tr>
                            <td>MOBILE</td>
                            <td><input type="text" name="mobile" class="input-block-level" value="<?php if($_POST)echo $_POST["mobile"]; else echo $aryForm["mobile"] ?>"></td>
                        </tr>

                        <tr>
                            <td>ACCOUNT NO.</td>
                            <td><input type="text" name="account" class="input-block-level" value="<?php if($_POST)echo $_POST["account"]; else echo $aryForm["account"] ?>"></td>
                        </tr>

                        <tr>
                            <td>SECTION</td>
                            <td>
                                <select class="span12" name="section" class="input-block-level"  <?php /* if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"';*/ ?> >
                        			<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>
                        	</td>
                        </tr>
 
                        <tr>
                            <td>BUS STATUS</td>
                            <td><input class="checkboxes" type="checkbox" <?php if($aryForm["bus_status"]=='1') { ?> checked  <?php  }  ?> name="bus_status" value="<?php if($aryForm["bus_status"]=='0') { echo '1';} else { echo '0';   } ?>"  /></td>
                        </tr>
                        
                        <tr>
                            <td colspan="2"><button type="submit" name="update_student" class="btn btn-primary"> Update Student Details</button> </td>
                            <!--<td><input class="checkboxes" type="checkbox" <?php if($aryForm["bus_status"]=='1') { ?> checked  <?php  }  ?> name="bus_status" value="<?php if($aryForm["bus_status"]=='0') { echo '1';} else { echo '0';   } ?>"  /></td>-->
                        </tr>

                    </table>
                    </form>
                </div>

                <div style="width:30%;float:left;margin-left:10px;border: 4px solid black;background: #C1CCD8;">
                    <form method="post" action="">
                    <table width="100%" style='background: #C1CBD8;font-size:12px;'>
                       <tr>
                            <td>FEE TITLE</td>
                            <td><input type="text" name="title" class="input-block-level" value=""></td>
                        </tr>
                        <tr>
                            <td>SELECT MONTH</td>
                            <td>
                                <select name="month">
								    <option value="">--Select Month--</option>
                                <?php
                                $allmonths = $db->getRows("select * from months");
                            	$monthnames = [];
        
                                foreach($allmonths as $m){
                                    $monthnames[]="$m[name]"; 
                                    
                    	    	    $checked = "";
        					        $cmonth=(date("n")+9);
        						    if($cmonth>12){ $cmonth = date("n")-3; }
                                	    if($cmonth===$m['month'] ){
            						        $checked="selected='selected'";
                                	    }
                            	    echo "<option value='".$m['month']."' $checked>$m[name]</option>";
                        	    }
            				// 		for($icheck=1;$icheck<=12;$icheck++){
            				// 		  $cheched="";
            				// 		  $cmonth=$aryForm['month'];
            				// 		  if($cmonth>12){$cmonth=date("n")-3;}
            				// 		  if($icheck<=9){
            				// 				if($cmonth==$icheck )
            				// 				$cheched="selected='selected'";
            				// 				echo "<option value='".$icheck."' $cheched>";
            				// 				$newDate=date("Y")."-".($icheck+3)."-1";
            				// 				echo date("F",strtotime($newDate));//."(".($ij+3).")";
            				// 		  }
            				// 		  else{
            				// 			  	if($cmonth==$icheck )
            				// 			  	$cheched="selected='selected'";
            				// 			  	echo "<option value='".$icheck."' $cheched>";
            				// 				$newDate=date("Y")."-".($icheck-9)."-1";
            				// 				echo date("F",strtotime($newDate));//."(".($ij-9).")";
            				// 		  }
            				// 		  echo "</option>";
            				// 		}
        						?>
        						</select>
                            </td>
                        </tr>
                        <tr>
                            <td>AMOUNT</td>
                            <td><input type="text" name="fixedfee" class="input-block-level" value=""></td>
                        </tr>
                        <tr>
                            <td colspan="2">
        						<button type="submit" name="add_fees" class="btn btn-primary"> Add Fees</button>
                            </td>
                        </tr>
                </table>
                </form>
                </div>

                <div style="width:30%;float:left;margin-left:10px;border: 4px solid black;background: #C1CCD8;">
                    <h4>DISCOUNT MODE</h4>
                    <?php $disc_mode = $db->getVal("SELECT discount_mode FROM tbl_info"); ?>
                    <form method="post" action="">
                    <table width="100%" style='background: #C1CBD8;font-size:12px;'>
                       <tr>
                            <td><input type="radio" <?php if($disc_mode=="0") echo "checked"; ?> name="discount_mode" value="0" /></td>
                            <td>Amount Wise</td>
                        </tr>
                        <tr>
                            <td><input type="radio" <?php if($disc_mode=="1") echo "checked"; ?> name="discount_mode" value="1" /></td>
                            <td>Percentage Wise</td>
                        </tr>
                        <tr>
                            <td colspan="2">
        						<button type="submit" name="update_discount_mode" class="btn btn-primary"> Update Discount Mode</button>
                            </td>
                        </tr>
                </table>
                </form>
                </div>
            </div>
					<br>


					<!--<div class="form-actions">-->
					<!--	<button type="submit" class="btn btn-primary"> Save</button>-->
					<!--	<button type="button" class="btn"> Cancel</button>-->
					<!--</div>-->

				</div>


			</div>
</table></center>



<h2 class="title">Other Fee Details</h2>

<table border="1" cellspacing="0" cellpadding="1" style="width:100%;">
    <tr>
        <th>S.No.</th>
        <th>Fee Title</th>
        <th>Amount</th>
        <th>Month</th>
        <th>Action</th>
    </tr>
<?php 
    $records = $db->getRows("select * from otherfee_structure where otype='".$_GET["idno"]."' and session='".$_SESSION["admin"]["session"]."' ");
        $i = 0;
        foreach($records as $clist){ $i++;
?>
        <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $clist['name']; ?></td>
            <td><?php echo $clist['fee']; ?></td>
            <td><?php
                //     if($clist['month']<=9){
                // 	    $cmonth = date("Y")."-".($clist['month']+3)."-1";
                // 	} else {
                // 	    $cmonth = date("Y")."-".($clist['month']-9)."-1";
                // 	}
                // 	echo date("F",strtotime($cmonth));
                
                echo $db->getVal("select name from months where month='$clist[month]'");

                ?>
            </td>
            <td>
                <?php 
                // $roll = $db->getVal("select roll from users where id='".$_SESSION['admin']['uid']."' ");
                $checkfee = $db->getVal("select id from reff_receipt where idno='$_GET[idno]' and type='$clist[name]' and session='".$_SESSION["admin"]["session"]."' ");
                if(!$checkfee){
                ?>
                    <button style="background:red;color:white;width:50px;padding:0px;" onclick="deletefees(<?php echo $clist['id'];?>)">Delete</button>
                <?php
                }
            ?>
            </td>
        </tr>
<?php } ?>

</table>

<script>
    function deletefees(id){

    var r = confirm("Do you really want to delete this fees?");
        if (r == true) {
            $.post( "<?php echo URL_ROOT ?>print/ajax.php", {
        			type: "deletefees",
        			id: id,
        			idno: "<?php echo $_GET['idno'] ?>"
        		} , function( data ) {
                    // alert(data);

        	});
        location.reload(true);
        }
    location.reload(true);
        
    }
</script>


