require_once 'File/Convert.php';
$fc = new File_Convert($img->getStoreName(), $img->mimetype );
- $csv = $fc->convert('text/csv');
- $this->importCsv($csv);
+ $csv = $fc->convert('text/csv');
+ $ret = $this->importCsv($csv);
+
+
+
+ $this->jdata($ret['data'], false, isset($ret['extra']) ? $ret['extra'] : array() );
+
}
function importCsv($csv)
$this->jerr("invalid file");
}
- $req = array(
- 'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
- );
-
+
$cols = false;
- $rows = array();
$header = false;
+ $rows = array();
+ $extra = array();
while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
- if(!array_filter($n)){
+
+
+ if(!strlen(trim(implode('', $n)))){ // blank line;
+ if ($header) {
+ continue;
+ }
$header = true;
continue;
}
if(!$header){
- $rows[$n[0]] = $n[1];
+ $extra[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1];
continue;
}
continue;
}
- foreach($req as $r) {
- if (!in_array($r,$cols)) {
- $cols = false;
- break;
- }
- }
+
continue;
}
$rows[] = $row;
}
-
- if (empty($cols)) {
- $this->jerr("could not find a row with " . implode(' / ', $req));
- }
- print_r($cols);
fclose($fh);
- exit;
+
+
+ return array('extra' => $extra, 'data' => $rows);;
}
-
-}
+}
\ No newline at end of file