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


if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['bus']) || trim($_POST['bus'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Bus Name.");
	}elseif(!isset($_POST['root']) || trim($_POST['root'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Bus Root.");
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{
		
       $_POST["school_id"]=$_SESSION["admin"]["school_id"];
         $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("bus",$_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'])!='')
	{
		$flgUp=$db->updateAry("bus",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
		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("bus","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 student where status=1 and  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
}
if($pgAct=="issue" && isset($_GET['id']) && trim($_GET['id']) !='')
{
?>
<!-- Forms --> 
	<div class="row-fluid">
        
	</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 class="btn btn-default" type="button" style="float:right" onclick="window.open('print/?page_id=idcard_all&class='+$('#class').val())">ID Card</button>
    <button class="btn btn-primary" type="button" style="float:right" onclick="window.open('print/?page_id=admitcard_all&class='+$('#class').val()+'&section='+$('#section').val())">Admit Card</button>
    <button class="btn btn-primary" type="button" style="float:right" onclick="window.open('print/?page_id=demand_fee&class='+$('#class').val())">Demand Fee</button>
    </div>
    <div class="well no-padding">
		<div style="position: absolute;width:300px;z-index: 99999;margin: 30px;">
        <select onchange="fetchByClass()" class="span6" name="class" id="class"  <?php if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?> >
									<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>
          <select onchange="fetchByClass()" class="span6" name="section" id="section" <?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 value="<?php echo $cla["name"] ?>">
                            <?php echo $cla["name"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select></div>
        <input type="hidden" id="tabletype" value="idcard_data" />
        <table class="table" id="ajaxtable">
            <thead>
                <tr>
                    <th width="10px">Serial No</th>
                    <th width="50px"></th>
                    <th>Name</th>
                    <th>Class</th>
                    <th>Medium</th>
                    <th>Father</th>
                    <th>Mobile</th>
                    <th width="200px">Action</th>
                </tr>
            </thead>
            
             <tfoot>
                <tr>
                	<th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th colspan="2"></th>
                </tr>
            </tfoot>
        </table>
		
	</div></div></div>
	<?php
}
?>
<input type="hidden" name="idno" id="idno" />
<div class="over">
<div id="example"></div>
<div id="gallery"></div>
<div id="button"><button type="button" onclick="okpress()">ok</button><button onclick="resetpress()" type="button">reset</button><button onclick="cancelpress()" type="button">cancel</button></div>
</div>
<style>
.over{position: fixed;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.84);
  top: 0;
  left: 0;
  display:none;
  z-index: 910001;}
#example{
	height: 371px;
  width: 500px;
  position: relative;
  top: 50px;
  left: 173px;
  overflow: hidden;
  z-index: 910002; 
}
#button{display:none;}
</style>

<script type="text/javascript" src="js/photobooth_min.js"></script>
<script>
//$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
//});
function fetchByClass(id){
	var name=$("#class").val();
	var section=$("#section").val();
	//alert(name+section);
	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 takePhoto(id){
	$(".over").show();$("#idno").val(id);
	$('#example').photobooth().on("image",function( event, dataUrl ){
		$( "#gallery" ).append( '<img id="imgsrc" src="' + dataUrl + '" >');
		$("#example").hide();$("#button").show();
	});
}
function cancelpress(){
	window.location='?page_id=idCard';
}
function resetpress(){
	$("#example").show();$("#button").hide();$( "#gallery" ).html('');
}
function okpress(){
	$.post( "ajax.php", { type: "updateImage" ,idno: $("#idno").val(), imgsrc: $("#imgsrc").attr("src")} , function( data ) {
	  window.location.href = '?page_id=idCard';
	});
}

</script>
<!-- / Forms -->