/** * Performs the actual import - imports the current chunk from the data file. */ private function _Import() { $TypeLang = "Import".ucfirst($this->type); //$current_file = @array_shift($this->ImportSession['ChunkList']); if(!isset($this->ImportSession['DoneCount'])) { $this->ImportSession['DoneCount'] = 0; } if(!isset($this->ImportSession['StartTime'])) { $this->ImportSession['StartTime'] = time(); } $done = 0; $percent = 0; if (isset($this->ImportSession['DoneCount'])) { $done = $this->ImportSession['DoneCount']; //$percent = ceil(($done/$this->ImportSession['TotalItems']) * 100); $percent = ceil(($this->ImportSession['LastPosition']/$this->ImportSession['TotalFileSize'])*100); } $importer = new ISC_ADMIN_CSVPARSER; if(isset($this->ImportSession['FieldSeparator']) && $this->ImportSession['FieldSeparator'] != "") { $importer->FieldSeparator = $this->ImportSession['FieldSeparator']; } if(isset($this->ImportSession['FieldEnclosure']) && $this->ImportSession['FieldEnclosure'] != "") { $importer->FieldEnclosure = $this->ImportSession['FieldEnclosure']; } $importer->SetRecordFields($this->ImportSession['FieldList']); $importer->OpenCSVFile($this->ImportSession['ImportFile'], $this->ImportSession['LastPosition'], 20); if ($this->ImportSession['LastPosition'] < $this->ImportSession['TotalFileSize']) { // This is our first iteration of the import, headers are enabled so skip past the first row if(isset($this->ImportSession['Headers']) && $this->ImportSession['Headers'] == 1 && !isset($this->ImportSession['InImport'])) { $importer->FetchNextRecord(); } $this->ImportSession['InImport'] = 1; while(($record = $importer->FetchNextRecord(true)) !== false) { // Call the function to handle the record $this->_ImportRecord($record); $currentPosition = $importer->GetCurrentPosition(); //$newPercent = ceil(($done/$this->ImportSession['TotalItems']* 100)); $newPercent = ceil(($currentPosition/$this->ImportSession['TotalFileSize'])*100); if($newPercent > $percent) { $percent = $newPercent; $report = $this->_FetchInlineReport(); // Update the status echo "<script type='text/javascript'>\n"; echo sprintf("self.parent.UpdateImportStatusReport('%s');", str_replace(array("\n", "\r", "'"), array(" ", "", "\\'"), $report)); $GLOBALS['ISC_LANG']['ImportInProgressDesc'] = sprintf(GetLang('ImportInProgressDesc'), $this->ImportSession['DoneCount']+$importer->GetRecordNum()); echo sprintf("self.parent.UpdateImportStatus('%s', %d);", str_replace(array("\n", "\r", "'"), array(" ", "", "\\'"), GetLang('ImportInProgressDesc')), $percent); echo "</script>\n"; flush(); } $this->ImportSession['DoneCount']++; } $this->ImportSession['LastPosition'] = $importer->GetCurrentPosition(); //$this->ImportSession['DoneCount'] += $importer->GetRecordNum(); } $GLOBALS['ImportSession'] = $_REQUEST['ImportSession']; $this->SaveImportSession(); // Nothing left to import, redirect to the finish page if($this->ImportSession['LastPosition'] === false || $this->ImportSession['LastPosition'] >= $this->ImportSession['TotalFileSize']) { $locationUrl = "index.php?ToDo=Import".ucfirst($this->type)."&Step=5&ImportSession=".urlencode($GLOBALS['ImportSession']); ?> <script type="text/javascript"> window.onload = function() { self.parent.parent.location= '<?php echo $locationUrl; ?>'; } </script> <?php exit; } // Still importing, jump to next page else { $locationUrl = "index.php?ToDo=Import".ucfirst($this->type)."&Step=4&x=".rand(1, 50)."&ImportSession=".$GLOBALS['ImportSession']; ?> <script type="text/javascript"> window.onload = function() { setTimeout('window.location="<?php echo $locationUrl; ?>"', 10); } </script> <?php exit; } }