<?php

require_once (PATH_CONTROLLERS . "Common.php") ;
require_once (PATH_MODELS . "admin/CompanyClass.php") ;
require_once (PATH_MODELS . "hr/EmployeeClass.php") ;
require_once (PATH_MODELS . "hr/DepartmentClass.php") ;

	$fn = $_REQUEST['n'] ;
	$isSuccess = true ;
    if (!empty($_FILES)) {
        $docfile =  basename($_FILES[$fn]['name']);
        $pi = pathinfo($docfile);
        $ext = $pi['extension'];
        
        Log::write($_FILES[$fn]['name']);
        Log::write($ext);
        
        if (file_exists($_FILES[$fn]['tmp_name'])){
            
            Log::write("exist");
            $file = fopen($_FILES[$fn]['tmp_name'],"r");

            while(! feof($file)){
                $tempLine = fgetcsv($file);
                if(count($tempLine) > 0){
                    Log::write("Count : " . count($tempLine));
                    foreach($tempLine as $item){
                        Log::write($item);
                    }
                }
            }

            fclose($file);
        } else {
            Log::write("not exist");
        }
    } else {
        $isSuccess = false;
        $err = "No upload file found." ;
    }
    
	if($isSuccess){
		echo Status::Ok . "|File is succesfully imported!";
	}else{
		echo Status::Error . "|" . $err ;
	}
    
?>