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

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=="addMarksheet" && isset($_GET['id']) && trim($_GET['id']) !='')
{
}
elseif($pgAct=="tc" && isset($_GET['id']) && trim($_GET['id']) !='')
{
	$dateAry=array("issue_TC"=>1);
	$flgIn=$db->updateAry("student",$dateAry,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno=".$_GET["id"]);
	
	if(!is_null($flgIn))
	{
		
		$flgUp=$db->delete("installment","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
		$flgUp=$db->delete("transaction","where school_id='".$_SESSION["admin"]["school_id"]."' and rid='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
		$flgUp=$db->delete("installment_time","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
		$flgUp=$db->delete("installment_fine","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
		$flgUp=$db->delete("alert","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
		$flgUp=$db->delete("notification","where school_id='".$_SESSION["admin"]["school_id"]."' and userid='".$_GET['id']."'");
		//$flgUp=$db->delete("reff_receipt","where idno='".$_GET['id']."'");
		//$flgUp=$db->delete("receipt","where idno='".$_GET['id']."'");
		$flgUp=$db->delete("hostelinstallment","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
		if(!is_null($flgUp)){
		$_SESSION['msg']='Saved Successfully! and all data of the student removed successfully';
		unset($_SESSION['form']);
		sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent Transfer certificate is successfully given to  Your child ".mydetail("name",$_GET["id"],"student")." in ".$LinksDetails["site_name"],"slert_TC");
		redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"TC", "page_id"=>$pgMod)));
		}}
	else
	{
		array_push($alert_err,$db->getErMsg());
		
	}
}
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
}

	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    </div>
    <div class="well no-padding">
	<?php
	/*
	$aryPgAct=array("page_id"=>$pgMod,"action"=>"add");
	$sql="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name";
	if($pgAct=="view")
		$sql="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=1 order by name";
	$aryList=$db->getRows($sql);
	if(is_array($aryList) && count($aryList)>0)
	{$ijk=0;
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>Serial No</th>
                    <th>Name</th>
                    <th>Class</th>
                    <th>Medium</th>
                    <th>Father</th>
                    <th>Mobile</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; $ijk++;
            $aryPgAct["id"]=$clist['idno'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $ijk; ?></td>
                    <td><?php echo $clist["name"] ?></td>
                    <td><?php echo $clist["class"] ?></td>
                     <td><?php echo $clist["medium"] ?></td>
                    <td><?php echo $clist["fname"] ?></td>
                    <td><?php echo $clist["mobile"] ?></td>
                    <td>
                     <?php if($clist["issue_TC"]==0){ $aryPgAct['action']="tc"; ?>
                         <a href="javascript:;" onclick="giveTC('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Give TC</button></a>  
                    <?php } $aryPgAct['action']="print"; ?>
                         <a target="_blank" href="<?php echo URL_ROOT."print/".getQueryString($aryPgAct); ?>" class="confirmation"><button type="button" class="btn ">Print TC</button></a> 
                    </td>
                </tr>
            <?php } ?>
            </tbody>
             <tfoot>
                <tr>
                	<th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th colspan="2"></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
	}
	?>
    <?php
	*/
	$aryPgAct=array("src"=>"TC", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by name");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
       
         <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="tc_data" />
        <table class="table" id="ajaxtable">
            <thead>
                <tr>
                    <th>Serial No</th>
                    <th>Name</th>
                    <th>Class</th>
                    <th>Medium</th>
                    <th>Admission no</th>
                    <th>Bus Root</th>
                    <th>Cast</th>
                    <th>Father</th>
                    <th>Mobile</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tfoot>
            </tfoot>
            <tbody>
           
            </tbody>
        </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

?>
<script type="text/javascript">
$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'TC/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='TC/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": 'TC/ajax.php?type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}
}
function giveTC(url){
		if(confirm("are you sure want to Issue TC"))window.location=url;
}
</script>
<!-- / Forms -->