<?php
$pgMod="driver";
$pgAct="view";
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
}
?>
<!-- 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;} 
.classList{cursor:pointer;text-decoration:none;display:block;border:1px solid #666;margin: 5px 0;padding: 5px 11px;}
.selected{background-color: #ccc;color: #fff;font-weight: bolder;box-shadow: 5px 5px 16px #000;}
.imgs{float:left;height: 60px;margin-right: 10px;}
.classList span{color:#F00; font-weight:bolder;}
.driverDetail { border: 1px solid #000;padding: 5px 10px;background-color: #ccc;box-shadow: 0 0 10px #2B2929;font-weight: bolder;font-size: 14px;margin: 10px 5px;}
</style>
<form method="post" action="" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Check bus Status</h3>
            </div>
            <div class="well">
			<!-- Forms: Box -->
			<div class="span3">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
                    <h3><i class="icon-cog"></i> Select Bus</h3>
                    <div style="float:right; margin-top:5px">
                    <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Bus Status')" >Excel</button>
                	<button type="button" onclick="printDiv('fetchStudent')" class="btn btn-primary">Print</button>
                </div>
                </div>
				<!-- / Forms: Top Bar -->

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

                    <div class="control-group">
                    	<ul>
						<?php 
							$class=$db->getRows("select * from bus where school_id='".$_SESSION["admin"]["school_id"]."'");
							foreach($class as $cla){
								?>
								<li class="classList" onClick="selectClass('<?php echo $cla["id"] ?>','<?php echo $cla["root"] ?>',this)">
									<?php echo $cla["bus"] ?>(<?php echo $cla["root"] ?>)
                                </li>
								<?php
							}
						?>
                        </ul>
					</div>

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

			</div>
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
			<div class="span9">

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

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

					<!-- Forms: Form -->
                        <div class="control-group" id="fetchStudent">
							Please select Bus
						</div>
						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

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

			</div>
			<!-- / Forms: Box -->
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<script>
var urlroot='<?php echo URL_ROOT; ?>';
function selectClass(id,root,tis){
	//alert(name+"-"+id);
	$(".classList").removeClass('selected');
	$(tis).addClass('selected');
	$("#fetchStudent").html('<center><img src="'+urlroot+'assets/icon/load.gif" /></enter>');
	$.post( "<?php echo URL_ROOT ?>Transport/ajax.php", { 
				type: "fetchStudent", 
				id: root,
				name: id
	} , function( data ) {
		$("#fetchStudent").html(data);
	});
}

    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');

    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
    e.preventDefault();
}
</script>
