Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Kingdee.php
1 <?php
2 require_once 'Pman/Roo.php';
3
4 class Pman_Xtuple_Kingdee extends Pman_Roo 
5 {
6     
7     function getAuth() {
8         if(HTML_FlexyFramework::get()->cli) {
9             return true;
10         }
11         return parent::getAuth();
12     }
13
14     function fetchSchema($type)
15     {
16         $headers = array();
17         
18         // read header file
19         
20         require_once 'File/Convert.php';
21         
22         $fc = new File_Convert("Pman/Xtuple/Kingdee/Schema/{$type}_Header.csv", 'text/csv');
23         $content = $fc->convert('text/csv');
24         
25         $fh = fopen($content, 'r');
26         
27         if (!$fh) {
28             $this->jerr("invalid {$type}_Header file");
29         }
30         
31         $count = 1;
32         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
33             foreach($n as $k) {
34                 if(empty($k)){
35                     continue;
36                 }
37                 $headers['Page' . $count][] = array(
38                                             'header' => trim($k),
39                                             'dataIndex' => preg_replace(array('/\s/','/\&|\.|\/|\-|\(|\)/'), array('_', ''), strtolower(trim($k))),
40                                             'width' => 75
41                                         );
42             }
43             
44             $count++;
45         }
46         
47         fclose($fh);
48         
49         // read schema file
50         
51         $fc = new File_Convert("Pman/Xtuple/Kingdee/Schema/{$type}_Schema.csv", 'text/csv');
52         $content = $fc->convert('text/csv');
53         
54         $fh = fopen($content, 'r');
55         
56         if (!$fh) {
57             $this->jerr("invalid {$type}_Schema file");
58         }
59         
60         $cols = false;
61         $rows = array();
62         
63         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
64             if (!strlen(implode('', $n))) {
65                 continue;
66             }
67             if (!$cols) {
68                 $cols = array();
69                 foreach($n as $k) {
70                     $cols[] = trim($k);
71                     if($k == 'FPage'){
72                         $headers['t_Schema'][] = array(
73                             'header' => trim($k),
74                             'dataIndex' => trim($k),
75                             'width' => 75
76                         );
77                         continue;
78                     }
79                     $headers['t_Schema'][] = array(
80                         'header' => trim($k),
81                         'dataIndex' => trim($k),
82                         'dataFormat' => 'string',
83                         'width' => 75
84                     );
85                 }
86                 
87                 if (empty($cols)) {
88                     continue;
89                 }
90                 continue;
91             }
92             
93             foreach($cols as $i=>$k) {
94                 $row[$k] = $n[$i];
95             }
96             
97             $rows[] = $row;
98             
99         }
100         
101         fclose($fh);
102         
103         $sheets = array();
104         
105         foreach ($headers as $k => $v){
106             $sheets[$k] = array(
107                 'workbook' => $k,
108                 'cols' => $v
109             );
110         }
111         
112         return array('SHEETS' => $sheets, 'SCHEMA' => $rows);
113     }
114 }