<?php
$pgMod="liveclass";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	$_SESSION['form']=$_POST;
	//$section=$_POST["section"];unset($_POST["section"]);
		
	if(isset($_FILES["photo"]["name"]) && !empty($_FILES["photo"]["name"])){
		$lfilename = basename($_FILES['photo']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		$lnewfile=md5(microtime()).".".$lext;
		if(move_uploaded_file($_FILES['photo']['tmp_name'],"media/photo/".$lnewfile))
		{
			$_POST["photo"]=$lnewfile;
		}
	}
	
	if($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("liveclass",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($_POST["mobile"],"Dear Parent Your admission enquiry is successfully submitted in ".$LinksDetails["site_name"],"student_enrollment");
			if($db->getErMsg()!=""){
				array_push($alert_err,$db->getErMsg());
			}else{
				redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
			}
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{		
		$flgUp=$db->updateAry("enquiry",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
		//echo $db->getLastQuery();exit;
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	//$flgUp=$db->updateAry("student",array("status"=>0),"where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	//$flgUp=$db->updateAry("installment",array("status"=>0),"where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("enquiry","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$where="where rid=".$_GET["id"]." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'";
		$res=$db->delete("transaction","$where");
	if(!is_null($flgUp)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
}
/*elseif($pgAct=="cancel" && isset($_GET['id']) && trim($_GET['id'])!='')
{	 $idate=date("Y-m-d");
	$flgUp=$db->updateAry("student",array("status"=>3, "added_by"=>$_SESSION["admin"]["uid"], "idate"=>$idate),"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	redirect(URL_ADMIN_HOME.getQueryString(array("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 enquiry WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !='')){
	 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
?>
<!-- Forms --> 
<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>
<form method="post" action="" id="printableDiv" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Create New Admission</h3>
                 <?php if(isset($_GET["id"])){ ?><button type="button" onclick="window.location='?page_id=make_admission&action=cancel&id=<?php echo $_GET["id"] ?>';" class="btn btn-danger" style="margin:8px 0px 0px 600px;"> Inactive</button><?php } ?>
                <div style="float:right; margin-top:5px">
                    <button type="button" onclick="checkvalid(this)" class="btn btn-primary" id="saveformbutton"> Save</button>
                    <button type="submit" id="saveme" style="display:none" class="btn btn-primary"> Save</button>
                   
                </div>
            </div>
            <div class="well">
			<!-- Forms: Box -->
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

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

					<!-- Forms: Form -->
                    
						<div class="control-group">
							<label class="control-label" for="name">Channel ID</label>
							<div class="controls">
								<input type="text" id="channel_id" name="channel_id" class="input-block-level" value="<?php echo $aryForm["channel_id"]; ?>" >
							</div>
						</div>
                     
	 					<div class="control-group">
							<label class="control-label" for="name"> Name</label>
							<div class="controls">
								<input type="text" id="name" name="name" class="input-block-level" value="<?php echo $aryForm["name"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="foccupation">Detail</label>
							<div class="controls">
								<input type="text" id="detail" name="detail" class="input-block-level" value="<?php echo $aryForm["detail"]; ?>" >
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for="photo">Photo</label>
							<div class="controls">
								<input type="file" name="photo" id="photo">
							</div>
						</div>
                        <!--<div class="control-group">
							<label class="control-label" for="feducation">Blood group</label>
							<div class="controls">
								<input type="text" id="feducation" name="feducation" class="input-block-level" value="<?php echo $aryForm["feducation"]; ?>" >
							</div>
						</div>-->
                        
              
                       <!-- <div class="control-group">
							<label class="control-label" for="meducation">Adhar no</label>
							<div class="controls">
								<input type="text" id="meducation" name="meducation" class="input-block-level" value="<?php echo $aryForm["meducation"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fincome">Rashan no</label>
							<div class="controls">
								<input type="text" id="mincome" name="mincome" class="input-block-level" value="<?php echo $aryForm["mincome"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fincome">Bank Account no</label>
							<div class="controls">
								<input type="text" id="fincome" name="fincome" class="input-block-level" value="<?php echo $aryForm["fincome"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="cast">Cast</label>
							<div class="controls">
								<input type="text" id="cast" name="cast" class="input-block-level" value="<?php echo $aryForm["cast"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="email">E-mail</label>
							<div class="controls">
								<input type="email" id="email" name="email" class="input-block-level" value="<?php echo $aryForm["email"]; ?>" >
							</div>
						</div>-->
                      
                        
                        <!--<div class="control-group">
							<label class="control-label" for="class">Is BPL student</label>
							<div class="controls">
                            	<input <?php if($aryForm["bpl"]==1)echo 'checked="checked"'; ?>  type="checkbox" <?php if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?> value="1" name="bpl" /> check if student is BPL
							</div>
						</div>-->
						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

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

			</div>
			<!-- / Forms: Box -->
            <!-- Forms: Box -->
			<!-- / Forms: Box -->
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<?php
}
else{
	?>
    <script>
    </script>
	<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='./?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("page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM  liveclass  "); 
	    $i = 0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th style="width:50px;">S.No.</th>
                    <th>channel id</th>
                    <th>name</th>
                    <th>detail</th>
                    <th>photo</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 $i; ?></td>
                    <td><?php echo $clist["channel_id"]; ?></td>
                    <td><?php echo $clist["name"]; ?></td>
                    <td><?php echo $clist["detail"]; ?></td>
                    <td><?php echo $clist["photo"]; ?></td>
                    <td>
                    
                    <?php $aryPgAct['action']="edit"; ?>
                     <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 colspan="3"></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 type="text/javascript">
$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'Enquiry/ajax.php?type='+$('#tabletype').val(),
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
});
function fetchByClass(){
	var name=$("#class").val();
	var section=$("#section").val();
	if(name!=""){
		var url='ajax.php?class='+name+'&type='+$('#tabletype').val();
		if(section!=""){
			url+='&section='+section
		}
		 oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": url,
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}else{
		var oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}
}
function checkform(){
	var data="name="+$("#name").val()+"&dob="+$("#dob").val()+"&fname="+$("#fname").val()+"&mname="+$("#mname").val()+"&cast="+$("#cast").val()+"&mobile="+$("#mobile").val();
	$.post( "ajax.php?"+data, { type: "PreCheckExist"} , function( data ) {
		//alert(data);
	  	if(data=="0"){
			$("#saveme").click();
		}else{
			alert(data);
			if(confirm("are you sureyou want to register a this student?")){
				$("#saveme").click();
			}else{
				if(confirm("You want to add new student?")){
					window.location='?page_id=make_admission&action=add';
				}else{
					window.location='?page_id=make_admission';
				}
			}
		}
	});
	return false;
}
function changeIns(){
	var cla=$("#class").val();
	$.post( "ajax.php", { type: "classinstallment" ,class: cla } , function( data ) {
	  	$("#ins").html(data);
		getTotal();
	});
}
function buschangeIns(){
	var bus=$("#bus").val();
	if(bus==""){
		$("#busins").html('');
	}else{
		$.post( "ajax.php", { type: "businstallment", bus: bus } , function( data ) {
			$("#busins").html(data);
			getbusTotal();
		});
	}
}
function hostelchangeIns(){
	var hostel=$("#hostel").val();
	if(hostel==""){
		$("#hostelins").html('');
	}else{
		$.post( "ajax.php", { type: "hostelinstallment", hostel: hostel } , function( data ) {
			$("#hostelins").html(data);
			gethostelTotal();
		});
	}
}
function getTotal(){
	var sum=0;var classfee=0;var busfee=0;
	var cost = document.getElementsByName('fee[]');
	classfee=$('#classfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#feetotal').val(parseInt(sum));
	$('#oldtotal').val(parseInt(sum));
}
function getbusTotal(){
	var sum=0;var classfee=0;var busfee=0;
	var cost = document.getElementsByName('busfee[]');
	classfee=$('#busclassfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#busfeetotal').val(parseInt(sum));
	$('#busoldtotal').val(parseInt(sum));
}
function gethostelTotal(){
	var sum=0;var hostelfee=0;
	var cost = document.getElementsByName('hostelfee[]');
	hostelfee=$('#hostelclassfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#hostelfeetotal').val(parseInt(sum));
	$('#hosteloldtotal').val(parseInt(sum));
}
function updateIns(){
	var sum=0;
	 var discountAmt=$("#discount").val();
	 var TotalAmt=$('#oldtotal').val();
	 var RestedAmt=TotalAmt-discountAmt;
	 var cost = document.getElementsByName('fee[]');
	 if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#discount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.feeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.feeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#feetotal').val(parseInt(sum));
}
function busupdateIns(){
	var sum=0;
	 var discountAmt=$("#busdiscount").val();
	 var TotalAmt=$('#busoldtotal').val();
	 var RestedAmt=TotalAmt-discountAmt;
	 var cost = document.getElementsByName('busfee[]');
	 if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#busdiscount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.busfeeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.busfeeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#busfeetotal').val(parseInt(sum));
}
function hostelupdateIns(){
	var sum=0;
	var discountAmt=$("#hosteldiscount").val();
	var TotalAmt=$('#hosteloldtotal').val();
	var RestedAmt=TotalAmt-discountAmt;
	var cost = document.getElementsByName('hostelfee[]');
	if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#hosteldiscount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.hostelfeeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.hostelfeeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#hostelfeetotal').val(parseInt(sum));
}
function getsibling(id){
	$.post( "ajax.php", { type: "getsibling", id: id } , function( data ) {
	  	alert(data);
	});
}
function checkvalid(id){
	if($("#channel_id").val()=="")
		alert("student name cannot blank");

	else
	{
		$("#saveformbutton").hide();
		$("#saveme").click();
	}
}
</script>