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