<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<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: 100% !important;overflow: inherit !important;} 
</style>
<?php
$pgMod="report";
$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
}
	?>
    <form method="get" action="">
    <input type="hidden" name="src" value="Reception" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Search Jobs Record</h3>
                    <div>
                        <button type="submit" name="searchs" class="btn btn-primary">Search</button>
      <!--                  <button type="submit" name="marks" class="btn btn-primary">Cross List</button>-->
						<!--<button type="submit" name="fee" class="btn btn-primary"> Add Marks</button>-->
      <!--                  <button type="submit" name="create_file" class="btn btn-primary"> Create Excel file</button>-->
                        
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row hide">

                        <div class="control-group span3">
                            <label class="control-label" for="class">Department</label><br>
                            <!--<div class="controls">  -->
                                <select class="input-block-level" name="department">
							        <option value="">--Select Department--</--Select--></option>
							        <?php $department = $db->getRows("select * from job_department");
							                foreach($department as $d){ ?>
							                <option value="<?php echo $d['id']; ?>" <?php if($_GET['department']== $d['id'])echo "selected"; ?>><?php echo $d["name"]; ?></option>
							        <?php } ?>
							    </select>
                            <!--</div>-->
                        </div>

                        <div class="control-group span3">
                            <label class="control-label" for="class">Designation</label><br>
                            <!--<div class="controls">-->
                                <select class="input-block-level" name="designation">
							        <option value="">--Select Designation--</--Select--></option>
							        <?php $designation = $db->getRows("select * from job_designation");
							                foreach($designation as $d){ ?>
							                <option value="<?php echo $d['id']; ?>" <?php if($aryForm['designation']== $d['id'])echo "selected"; ?>><?php echo $d["name"]; ?></option>
							        <?php } ?>
							    </select>
                            <!--</div>-->
                        </div>

                        <div class="control-group span3">
                            <label class="control-label" for="medium">JobType</label><br>
                            <!--<div class="controls">-->
                                <select class="input-block-level" name="jobtype">
							        <option value="">--Select Job Type--</--Select--></option>
							        <?php $jobtype = $db->getRows("select * from job_type");
							                foreach($jobtype as $d){ ?>
							                <option value="<?php echo $d['id']; ?>" <?php if($aryForm['jobtype']== $d['id'])echo "selected"; ?>><?php echo $d["name"]; ?></option>
							        <?php } ?>
							    </select>
                            <!--</div>-->
                        </div>

                        <div class="control-group span3">
                            <label class="control-label" for="term">Process</label><br>
                            <!--<div class="controls">-->
                                <select class="input-block-level" name="process">
							        <option value="">--Select Process--</--Select--></option>
							        <?php $jobtype = $db->getRows("select * from job_process");
							                foreach($jobtype as $d){ ?>
							                <option value="<?php echo $d['id']; ?>" <?php if($aryForm['process']== $d['id'])echo "selected"; ?>><?php echo $d["name"]; ?></option>
							        <?php } ?>
							    </select>
                            <!--</div>-->
                        </div>
                    </div>
                    <br>
				</div>
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";

	if(isset($_GET["search"])){
		?><form method="post" action="">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Jobs Report</h3>
                    <div>
                        <!--<button class="btn btn-danger" onclick="ExportToExcel('xlsx')">Export Excel</button>-->
                        <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>
				          <button type="button" name="fee" onClick="printDivNoHeader('printableDiv')" class="btn btn-primary"> Print</button>
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
		
		<?php
		$whereC=array();
		if($_GET["department"]!="")
			$whereC[]=" department='".$_GET["department"]."' ";

		if($_GET["designation"]!="")
			$whereC[]=" designation='".$_GET["designation"]."' ";

		if($_GET["jobtype"]!="")
			$whereC[]=" jobtype='".$_GET["jobtype"]."' ";

		if($_GET["process"]!="")
			$whereC[]=" process='".$_GET["process"]."' ";

		if(is_array($whereC) && count($whereC)>0)
			$whereM=" where ".implode(" and ",$whereC);

		$alljobs = $db->getRows("select * from jobs $whereM ");

		if(is_array($alljobs) && count($alljobs)>0){
			?>
            <div id="printableDiv">
			
			<div class="headPrint hide" style="border: none;">
		        
			 <div style="margin-left:55px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="90px" width="110px" style="margin:0px 0px 3px 10px;"></div>
			 <div style="float:left;text-align:center;margin-bottom:18px;"> <h1 style="font-size:30px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
			   <span style="font-size:16px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
			 </div> 
		    </div>

		  	<div style="font-size: 18px;clear: both;font-weight: bold;padding: 5px;color: #000;text-align: center;border-right: 1px solid #000;  border-left: 1px solid #000;border-top: 1px solid #000;border-bottom: 1px solid #000;"> Jobs Report</div>

            <div class="divclass">
                <table class="table" cellspacing="0" cellpadding="0" border="1" id="tbl_exporttable_to_xls">

            <thead>
    			<tr>
                    <th>S.No.</th>
                    <th>Job</th>
                    <th>Department</th>
                    <th>Designation</th>
        			<th>Jobtype</th>
    	    		<th>Process</th>
    	    		<th>Description</th>
    	    		<th>Experience</th>
    	    		<th>Opening Date</th>
    	    		<th>Salary</th>
    	    		<th>Status</th>
                </tr>
            </thead>
            <tbody>
			<?php $i=0;
			foreach($alljobs as $job){$i++;
				?>
				<tr> 
                	<td><?php echo $i; ?></td>
            		<td><?php echo $job["title"] ?></td>
                    <td><?php echo $db->getVal("select name from job_department where id='".$job['department']."' "); ?></td>
                    <td><?php echo $db->getVal("select name from job_designation where id='".$job['designation']."' "); ?></td>
                    <td><?php echo $db->getVal("select name from job_type where id='".$job['jobtype']."' "); ?></td>
                    <td><?php echo $db->getVal("select name from job_process where id='".$job['process']."' "); ?></td>
                    <td><?php echo $job["description"] ?></td>
                    <td><?php echo $job["experience"] ?> years</td>
                    <td><?php echo date('d-m-y', strtotime($job["opening_date"])); ?></td>
                    <td><?php echo $job["min_salary"]." - ".$job["max_salary"] ?></td>
                    <td><?php if($job["status"]===1)echo "Active"; else echo "Inactive"; ?></td>
                </tr>
				<?php   }   ?>
			</tbody>
			</table>
            </div>

			</div>
			<?php
		} ?>
		</div></div></div></div></form>
		<?php
	}
?>

    <script>

        function ExportToExcel(type, fn, dl) {
            var elt = document.getElementById('tbl_exporttable_to_xls');
            var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
            return dl ?
                XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
                XLSX.writeFile(wb, fn || ('Exam Wise Report.' + (type || 'xlsx')));
        }

        $("#btn_excel").click(function(e) {
            // var filename = $("#filename").val();

        let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
        let url = URL.createObjectURL(file);
        let a = $("<a />", {
        href: url,
        download: "Job Report.xls"}).appendTo("body").get(0).click();
        e.preventDefault();
        });

    </script>




