/**
  * A wrapper for the import function getPreviewDataFromExcel 
  * @param String filePath
  * @param String ext
  * @return Array
  */
 protected function getPreviewDataFromExcel($filePath, $ext)
 {
     $fileHandle = openImportExcelFile($filePath, $ext);
     $headerFieldsFromExcel = getImportExcelFields($fileHandle);
     $fieldsData = $this->getCorrespondingImportFieldsData($headerFieldsFromExcel);
     $previewData = getPreviewDataFromExcel($fileHandle, $fieldsData);
     $previewData["fieldsData"] = $fieldsData;
     return $previewData;
 }
function ImportFromExcel($uploadfile)
{
    $autoinc = false;
    $ret = 1;
    global $error_message, $keys, $goodlines, $total_records, $conn, $strOriginalTableName, $strTableName, $keys_present;
    $data = openImportExcelFile($uploadfile);
    // populate field names array
    $fields = array();
    $fields = getImportExcelFields($data);
    $fields = getFieldNamesByHeaders($fields);
    $keys_present = 1;
    for ($k = 0; $k < count($keys); $k++) {
        if (!in_array(RemoveFieldWrappers($keys[$k]), $fields)) {
            $keys_present = 0;
            break;
        }
    }
    if (in_array("Record ID", $fields)) {
        $autoinc = true;
    }
    if ($autoinc) {
        $sql = "SET IDENTITY_INSERT " . AddTableWrappers($strOriginalTableName) . " ON";
        db_exec($sql, $conn);
    }
    $ret = getImportExcelData($data, $fields);
    if ($autoinc) {
        $sql = "SET IDENTITY_INSERT " . AddTableWrappers($strOriginalTableName) . " OFF";
        db_exec($sql, $conn);
    }
    return $ret;
}
function ImportFromExcel($uploadfile)
{
    $autoinc = false;
    $ret = 1;
    global $error_message, $keys, $goodlines, $total_records, $conn, $strOriginalTableName, $strTableName, $keys_present;
    $data = openImportExcelFile($uploadfile);
    // populate field names array
    $fields = array();
    $fields = getImportExcelFields($data);
    $fields = getFieldNamesByHeaders($fields);
    $keys_present = 1;
    for ($k = 0; $k < count($keys); $k++) {
        if (!in_array(RemoveFieldWrappers($keys[$k]), $fields)) {
            $keys_present = 0;
            break;
        }
    }
    $ret = getImportExcelData($data, $fields);
    return $ret;
}
function ImportFromExcel($uploadfile, $strOriginalTableName, $ext, $keys, &$keys_present, &$total_records, &$error_message, &$goodlines, $pageObject, $cipherer)
{
	global $conn, $strTableName;
	
	$autoinc = false;
	$ret = 1;
	
	$data = openImportExcelFile($uploadfile);
	
	// populate field names array
	
	$fields = array();
	
	$fields = getImportExcelFields($data);
	
	$fields = getFieldNamesByHeaders($fields, $strOriginalTableName, $ext);	
	if($fields == null) // if error happened
		return;
	
	$keys_present=1;
	
	for($k=0; $k<count($keys); $k++)
	{
		if (!in_array(RemoveFieldWrappers($keys[$k]),$fields))
		{
			$keys_present=0;
			break;
		}
	}

		if(in_array("id",$fields))
		$autoinc=true;
				
if(GetDatabaseType() == 2 && $autoinc)
{
	$sql = "SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." ON";
	db_exec($sql,$conn);
}
$ret = getImportExcelData($data, $fields, $error_message, $goodlines, $keys, $keys_present, $strOriginalTableName, $pageObject, $cipherer, $autoinc, $total_records);
if(GetDatabaseType() == 2 && $autoinc)
{
	$sql="SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." OFF";
	db_exec($sql,$conn);
}
		
	
	return $ret;

}