<?php
session_name('CAKEPHP'); @session_start();
$PageSecurity=12;
error_reporting(0);
global $db;

if(isset($_REQUEST['impsave']) && $_REQUEST['impsave']='Save'){ 
	if($_FILES['imprt']['name']!='' && $_FILES['imprt']['size']>0){	
  $Filepath = $_FILES['imprt']['name'];
  $delimiter=",";
  $data_array=array();
  move_uploaded_file($_FILES['imprt']['tmp_name'], $Filepath);
  require('php-excel-reader/excel_reader2.php');
  require('reader/SpreadsheetReader.php');
  try{
  $Spreadsheet = new SpreadsheetReader($Filepath);
  $i=0;
  $fields = array('e_code','e_name','site','shift_start','shift_end','time_in','time_out','ot_hrs','attendance_date','pres_abs','pres_abs1');
  $sql_upload_qry="INSERT INTO daily_attendance_2 (";
    foreach ($fields as $key => $value) {
      $sql_upload_qry.=$value.',';
    }
    $sql_upload_qry=rtrim($sql_upload_qry,',');
    $sql_upload_qry.=') values ';
    foreach ($Spreadsheet as $Row){
      if(count($Row)=='11'){
        $sql_upload_qry.="(";
        foreach ($Row as $keyRow => $valueRow) {
          $sql_upload_qry.='"'.$valueRow.'",';
        }
        $sql_upload_qry=rtrim($sql_upload_qry,',');
        $sql_upload_qry.='),';
        $i++;
      } else {
        $_SESSION['success_msg']='Inproper File Formate. Error Reading File';
        echo '0';
        break;
      }
    }
    $sql_upload_qry=rtrim($sql_upload_qry,',');
  }catch(Exception $E) {
    echo '0';
  }
}
@unlink($_FILES['cnvrt']['name']);
}




?>