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