1 | <?php |
---|
2 | // +-------------------------------------------------+ |
---|
3 | // © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) |
---|
4 | // +-------------------------------------------------+ |
---|
5 | // $Id: convert.class.php,v 1.6 2012-04-27 15:25:49 dbellamy Exp $ |
---|
6 | |
---|
7 | if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access"); |
---|
8 | |
---|
9 | require_once ("$include_path/parser.inc.php"); |
---|
10 | |
---|
11 | //Récupération du chemin du fichier de paramétrage de l'import |
---|
12 | function _item_convert_($param) { |
---|
13 | global $export_type; |
---|
14 | global $i; |
---|
15 | global $param_path; |
---|
16 | global $export_type_l; |
---|
17 | |
---|
18 | if ($i == $export_type) { |
---|
19 | $param_path = $param['PATH']; |
---|
20 | $export_type_l = $param['NAME']; |
---|
21 | } |
---|
22 | $i ++; |
---|
23 | } |
---|
24 | |
---|
25 | function _item_export_list_convert_($param) { |
---|
26 | global $export_list; |
---|
27 | global $i, $iall; |
---|
28 | |
---|
29 | if ($param["EXPORT"]=="yes") { |
---|
30 | $t=array(); |
---|
31 | $t["NAME"]=$param["EXPORTNAME"]; |
---|
32 | $t["PATH"]=$param["PATH"]; |
---|
33 | $t["ID"]=$i; |
---|
34 | $t["IDALL"]=$iall; |
---|
35 | $export_list[]=$t; |
---|
36 | $i++; |
---|
37 | } |
---|
38 | $iall++; |
---|
39 | } |
---|
40 | |
---|
41 | //Récupération du paramètre d'import |
---|
42 | function _output_convert_($param) { |
---|
43 | global $output; |
---|
44 | global $output_type; |
---|
45 | global $output_params; |
---|
46 | |
---|
47 | $output = $param['IMPORTABLE']; |
---|
48 | $output_type = $param['TYPE']; |
---|
49 | $output_params = $param; |
---|
50 | } |
---|
51 | |
---|
52 | function _input_convert_($param) { |
---|
53 | global $specialexport; |
---|
54 | global $input_type; |
---|
55 | global $input_params; |
---|
56 | |
---|
57 | $input_type = $param['TYPE']; |
---|
58 | $input_params = $param; |
---|
59 | |
---|
60 | if ($param["SPECIALEXPORT"]=="yes") { |
---|
61 | $specialexport=true; |
---|
62 | } else $specialexport=false; |
---|
63 | } |
---|
64 | |
---|
65 | //Récupération des étapes de conversion |
---|
66 | function _step_convert_($param) { |
---|
67 | global $step; |
---|
68 | |
---|
69 | $step[] = $param; |
---|
70 | } |
---|
71 | |
---|
72 | //Récupération du nom de l'import |
---|
73 | function _import_name_convert_($param) { |
---|
74 | global $import_name; |
---|
75 | |
---|
76 | $import_name = $param['value']; |
---|
77 | } |
---|
78 | |
---|
79 | class convert { |
---|
80 | |
---|
81 | var $export_type; |
---|
82 | var $id_notice; |
---|
83 | var $prepared_notice; |
---|
84 | var $output_notice; |
---|
85 | var $message_convert; |
---|
86 | var $error; |
---|
87 | |
---|
88 | function convert($notice,$type_convert,$do_not_start_yet=false) { |
---|
89 | global $i; |
---|
90 | global $param_path; |
---|
91 | global $specialexport; |
---|
92 | global $output_type; |
---|
93 | global $output_params; |
---|
94 | global $step; |
---|
95 | global $export_type; |
---|
96 | global $base_path; |
---|
97 | global $class_path; |
---|
98 | global $include_path; |
---|
99 | global $msg; |
---|
100 | |
---|
101 | $step=array(); |
---|
102 | |
---|
103 | $this->export_type=$type_convert; |
---|
104 | $export_type=$type_convert; |
---|
105 | |
---|
106 | //Récupération du répertoire |
---|
107 | $i = 0; |
---|
108 | $param_path = ""; |
---|
109 | if (file_exists("$base_path/admin/convert/imports/catalog_subst.xml")) { |
---|
110 | $fic_catal = "$base_path/admin/convert/imports/catalog_subst.xml"; |
---|
111 | } else { |
---|
112 | $fic_catal = "$base_path/admin/convert/imports/catalog.xml"; |
---|
113 | } |
---|
114 | _parser_($fic_catal, array("ITEM" => "_item_convert_"), "CATALOG"); |
---|
115 | |
---|
116 | //Lecture des paramètres |
---|
117 | _parser_("$base_path/admin/convert/imports/".$param_path."/params.xml", array("IMPORTNAME" => "_import_name_convert_","STEP" => "_step_convert_","OUTPUT" => "_output_convert_","INPUT" => "_input_convert_"), "PARAMS"); |
---|
118 | |
---|
119 | //En fonction du type de fichier de sortie, inclusion du script de gestion des sorties |
---|
120 | switch ($output_type) { |
---|
121 | case "xml" : |
---|
122 | require_once ("$base_path/admin/convert/imports/output_xml.inc.php"); |
---|
123 | break; |
---|
124 | case "iso_2709" : |
---|
125 | require_once ("$base_path/admin/convert/imports/output_iso_2709.inc.php"); |
---|
126 | break; |
---|
127 | case "custom" : |
---|
128 | require_once ("$base_path/admin/convert/imports/".$param_path."/".$output_params['SCRIPT']); |
---|
129 | break; |
---|
130 | case "txt": |
---|
131 | require_once ("$base_path/admin/convert/imports/output_txt.inc.php"); |
---|
132 | break; |
---|
133 | default : |
---|
134 | die($msg["export_cant_find_output_type"]); |
---|
135 | } |
---|
136 | |
---|
137 | $this->prepared_notice=$notice; |
---|
138 | if (!$do_not_start_yet) { |
---|
139 | $this->output_notice.=$this->transform(); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | function get_exports() { |
---|
144 | global $export_list; |
---|
145 | global $i, $iall; |
---|
146 | global $base_path; |
---|
147 | $i=0; |
---|
148 | $iall=0; |
---|
149 | if (file_exists("$base_path/admin/convert/imports/catalog_subst.xml")) |
---|
150 | $fic_catal = "$base_path/admin/convert/imports/catalog_subst.xml"; |
---|
151 | else |
---|
152 | $fic_catal = "$base_path/admin/convert/imports/catalog.xml"; |
---|
153 | |
---|
154 | _parser_($fic_catal, array("ITEM" => "_item_export_list_convert_"), "CATALOG"); |
---|
155 | return $export_list; |
---|
156 | } |
---|
157 | |
---|
158 | function get_header() { |
---|
159 | global $output_params; |
---|
160 | return _get_header_($output_params); |
---|
161 | } |
---|
162 | |
---|
163 | function get_footer() { |
---|
164 | global $output_params; |
---|
165 | return _get_footer_($output_params); |
---|
166 | } |
---|
167 | |
---|
168 | function transform() { |
---|
169 | global $step; |
---|
170 | global $param_path; |
---|
171 | global $n_errors; |
---|
172 | global $message_convert; |
---|
173 | global $input_type; |
---|
174 | global $base_path; |
---|
175 | global $include_path; |
---|
176 | global $class_path; |
---|
177 | global $input_params; |
---|
178 | global $msg; |
---|
179 | |
---|
180 | $notice=$this->prepared_notice; |
---|
181 | |
---|
182 | //Inclusion des librairies éventuelles |
---|
183 | for ($i = 0; $i < count($step); $i ++) { |
---|
184 | if ($step[$i]['TYPE'] == "custom") { |
---|
185 | //echo "imports/".$param_path."/".$step[$i][SCRIPT][0][value]; |
---|
186 | require_once ("$base_path/admin/convert/imports/".$param_path."/".$step[$i]['SCRIPT'][0]['value']); |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | require_once ("$base_path/admin/convert/xmltransform.php"); |
---|
191 | |
---|
192 | //En fonction du type de fichier d'entrée, inclusion du script de gestion des entrées |
---|
193 | switch ($input_type) { |
---|
194 | case "xml" : |
---|
195 | require_once ("$base_path/admin/convert/imports/input_xml.inc.php"); |
---|
196 | break; |
---|
197 | case "iso_2709" : |
---|
198 | require_once ("$base_path/admin/convert/imports/input_iso_2709.inc.php"); |
---|
199 | break; |
---|
200 | case "text" : |
---|
201 | require_once("$base_path/admin/convert/imports/input_text.inc.php"); |
---|
202 | break; |
---|
203 | case "custom" : |
---|
204 | require_once ("$base_path/admin/convert/imports/$param_path/".$input_params['SCRIPT']); |
---|
205 | break; |
---|
206 | default : |
---|
207 | die($msg["ie_import_entry_not_valid"]); |
---|
208 | } |
---|
209 | |
---|
210 | for ($i = 0; $i < count($step); $i ++) { |
---|
211 | $s = $step[$i]; |
---|
212 | $islast=($i==count($step)-1); |
---|
213 | $isfirst=($i==0); |
---|
214 | switch ($s[TYPE]) { |
---|
215 | case "xmltransform" : |
---|
216 | $r = perform_xslt($notice, $s, $islast, $isfirst, $param_path); |
---|
217 | break; |
---|
218 | case "toiso" : |
---|
219 | $r = toiso($notice, $s, $islast, $isfirst, $param_path); |
---|
220 | break; |
---|
221 | case "isotoxml" : |
---|
222 | $r = isotoxml($notice, $s, $islast, $isfirst, $param_path); |
---|
223 | break; |
---|
224 | case "texttoxml": |
---|
225 | $r = texttoxml($notice, $s, $islast, $isfirst, $param_path); |
---|
226 | break; |
---|
227 | case "custom" : |
---|
228 | eval("\$r=".$s['CALLBACK'][0][value]."(\$notice, \$s, \$islast, \$isfirst, \$param_path);"); |
---|
229 | break; |
---|
230 | } |
---|
231 | if (!$r['VALID']) { |
---|
232 | $this->n_errors=true; |
---|
233 | $this->message_convert= $r['ERROR']; |
---|
234 | $notice = ""; |
---|
235 | break; |
---|
236 | } else { |
---|
237 | $notice = $r['DATA']; |
---|
238 | if($r['WARNING']){ |
---|
239 | $this->n_errors=true; |
---|
240 | $this->message_convert= $r['WARNING']; |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | return $notice; |
---|
245 | } |
---|
246 | |
---|
247 | // Récupération de l'id à partir du nom de l'export |
---|
248 | function get_id_by_path($path) { |
---|
249 | global $export_list; |
---|
250 | if (!count($export_list)) start_export::get_exports() ; |
---|
251 | for ($i=0;$i<count($export_list);$i++) { |
---|
252 | if ($export_list[$i]["PATH"]==$path) return $export_list[$i]["IDALL"] ; |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | } |
---|
257 | |
---|
258 | ?> |
---|