<?php


class CSVImporter 
{
var $table;
var $Csv;
var $truncate;
var $cnx;


function CSVImporter ($table, $Csv, $truncate, $cnx)
{
global $db;
	$this->table = $table;
	$this->Csv = $Csv;
	$this->truncate = $truncate;
	$this->cnx = $cnx;
}












function InsertData ($values)
{
global $db;
//print_r($values);

$fields = array('e_code','e_name','site','shift_start','shift_end','time_in','time_out','ot_hrs','attendance_date'
          ,'pres_abs','pres_abs1');


$n = 1;

for ($i=0; $i <2; $i++)
{

$sql = "INSERT INTO ".$this->table." (";

for ($i=0; $i < count($fields); $i++)
{
$sql .= $fields [$i];

	if ($i < count ($fields) - 1)
	{
	$sql .= ", ";
	}
}

$sql .= ") 
	VALUES
(";

for ($i=0; $i < count($values); $i++)
{

	$sql .="'".$values [$i]."'";
	


	if ($i < count ($values) - 1)
	{
	$sql .= ",";
	}

$n++;	

}

 $sql .= ")";

DB_query($sql,$db);
}


}


function TruncateTable ()
{
global $db;
 $sql='TRUNCATE table '.$this->table; 

if (DB_query($sql,$db)) { $exito="si"; }else{ $exito="no"; }

return $exito;

}



function Upload () {
global $db;
ini_set ('auto_detect_line_endings','1');

if ($this->truncate == "yes") 
	{ 
	$this->TruncateTable ();
	}

$row�=�1; 
$data2=$_FILES['imprt']['tmp_name'];
if (($handle = fopen($data2, "r")) !== FALSE) {
	$mycsv = array();
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) $mycsv[] = $data;
    fclose($handle);  
  
  
		for($i=1;$i<count($mycsv);$i++)
		{	
		//print_r($mycsv[$i]);	
		$this->InsertData ($mycsv[$i]);
		}
		
	
	
}



}

}
$s=new db_query();

?>