ExcelToJson.php
[Pman.Core] / ExcelToJson.php
index b479036..cad6033 100644 (file)
@@ -30,70 +30,8 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         require_once 'File/Convert.php';
         $fc = new File_Convert($img->getStoreName(), $img->mimetype );
         $csv = $fc->convert('text/csv');
-        $this->importCsv($csv);
-    }
-    
-    function importCsv($csv)
-    {
-        ini_set("auto_detect_line_endings", true);
-        
-        $fh = fopen($csv, 'r');
-        if (!$fh) {
-            $this->jerr("invalid file");
-        }
-        
-        $req = array(
-            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY', 'AA'
-        );
+        $data = $this->importCsv($csv);
+        $this->jdata($data);
         
-        $cols[] = false;
-        $rows = array();
-        $header = false;
-        
-        while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
-            if(!array_filter($n)){
-                $header = true;
-            }
-            
-            if(!$header){
-               $rows[$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;
-            }
-            
-            foreach($cols as $i=>$k) {
-                $row[$k] = $n[$i];
-            }
-            $rows[] = $row;
-            
-        }
-         exit;
-        if (empty($cols)) {
-            $this->jerr("could not find a row with " . implode(' / ', $req));
-        }
-        
-        fclose($fh);
-        
-        exit;
     }
-    
-}
+}
\ No newline at end of file