<?php
ob_start();
session_name('CAKEPHP'); session_start();
error_reporting(FALSE);
include('includes/DateFunctions.inc');
include('exportconfig.php');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
class db_query
{
  function getField($table, $condition, $val, $field)
  {
    global $db;
    $sql = mysqli_query($db, "select " . $field . " from " . $table . " where " . $condition . " ='" . $val . "'");
    $r = mysqli_fetch_array($sql);
    //echo "select ".$field." from ".$table." where ".$condition." ='".$val."'"; 
    return ($r[$field]);
  }
}
$s = new db_query();


$sql = $_SESSION['sqlexport'];
$data1 = "";
$data1 .= "<table width='100%' border='1' cellspacing='0' cellpadding='3'>
  <tr>
    <th><strong>EMPLOYEE CODE </strong></th>
    <th><strong>EMPLOYEE NAME </strong></th>
    <th><strong>SITE</strong></th>
    <th><strong>DATE OF BIRTH</strong></th>
    <th><strong>DATE OF JOIN</strong></th>
    <th><strong>DEPARTMENT</strong></th>
    <th><strong>DESIGNATION</strong></th>
	  </tr>";

$result = mysqli_query($db, $sql);
$i = 1;

while ($myrow = mysqli_fetch_array($result)) {
  $data1 .= "<tr bgcolor='#FFFFFF'>";
  $data1 .= "<td>'" . $myrow['emp_code'] . "'</td>";
  $data1 .= "<td>" . $myrow['emp_name'] . "</td>";
  $data1 .= "<td>" . $site_sql = $s->getField('locations', 'loccode', $myrow['emp_site'], 'locationname') . "</td>";
  $data1 .= "<td>" . ConvertSQLDate($myrow['dob']) . "</td>";
  $data1 .= "<td>" . ConvertSQLDate($myrow['doj']) . "</td>";
  $data1 .= "<td>" .
    $dept_sql = $s->getField('deptmaster', 'id', $myrow['department'], 'deptname') . "</td>";
  $data1 .= "<td>" . $desig_sql = $s->getField('desigmaster', 'id', $myrow['designation'], 'designame') . "</td>";
  $data1 .= "</tr>";
}
$data1 .= "</table> ";

$header = '';
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=EmployeeListDetails.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data1";
