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_caddie.php,v 1.22 2015-04-03 11:16:22 jpermanne Exp $ |
---|
6 | |
---|
7 | //Exécution de l'export |
---|
8 | $base_path = "../.."; |
---|
9 | $base_auth = "CATALOGAGE_AUTH"; |
---|
10 | $base_title = "\$msg[export_title]"; |
---|
11 | require ($base_path."/includes/init.inc.php"); |
---|
12 | |
---|
13 | require_once ("$include_path/parser.inc.php"); |
---|
14 | require_once ("$base_path/admin/convert/export.class.php"); |
---|
15 | require_once("$class_path/caddie.class.php"); |
---|
16 | require_once("$class_path/export_param.class.php"); |
---|
17 | |
---|
18 | //Récupération du chemin du fichier de paramétrage de l'import |
---|
19 | function _item_($param) { |
---|
20 | global $export_type; |
---|
21 | global $i; |
---|
22 | global $param_path; |
---|
23 | global $export_type_l; |
---|
24 | |
---|
25 | if ($i == $export_type) { |
---|
26 | $param_path = $param['PATH']; |
---|
27 | $export_type_l = $param['NAME']; |
---|
28 | } |
---|
29 | $i ++; |
---|
30 | } |
---|
31 | |
---|
32 | //Récupération du paramètre d'import |
---|
33 | function _output_($param) { |
---|
34 | global $output; |
---|
35 | global $output_type; |
---|
36 | global $output_params; |
---|
37 | |
---|
38 | $output = $param['IMPORTABLE']; |
---|
39 | $output_type = $param['TYPE']; |
---|
40 | $output_params = $param; |
---|
41 | } |
---|
42 | |
---|
43 | function _input_($param) { |
---|
44 | global $specialexport; |
---|
45 | |
---|
46 | if ($param["SPECIALEXPORT"]=="yes") { |
---|
47 | $specialexport=true; |
---|
48 | } else $specialexport=false; |
---|
49 | } |
---|
50 | |
---|
51 | //Initialisation si première fois |
---|
52 | if (file_exists("imports/catalog_subst.xml")) |
---|
53 | $fic_catal = "imports/catalog_subst.xml"; |
---|
54 | else |
---|
55 | $fic_catal = "imports/catalog.xml"; |
---|
56 | |
---|
57 | if ($first != 1) { |
---|
58 | //pmb_mysql_query("delete from import_marc"); |
---|
59 | |
---|
60 | $origine=str_replace(" ","",microtime()); |
---|
61 | $origine=str_replace("0.","",$origine); |
---|
62 | |
---|
63 | //Récupération du répertoire |
---|
64 | $i = 0; |
---|
65 | $param_path == ""; |
---|
66 | |
---|
67 | _parser_($fic_catal, array("ITEM" => "_item_"), "CATALOG"); |
---|
68 | |
---|
69 | //Lecture des paramètres |
---|
70 | _parser_("imports/".$param_path."/params.xml", array("OUTPUT" => "_output_", "INPUT" => "_input_"), "PARAMS"); |
---|
71 | |
---|
72 | //Si l'export est spécial, on charge la fonction d'export |
---|
73 | if ($specialexport) require_once("imports/".$param_path."/export.inc.php"); |
---|
74 | |
---|
75 | //En fonction du type de fichier de sortie, inclusion du script de gestion des sorties |
---|
76 | switch ($output_type) { |
---|
77 | case "xml" : |
---|
78 | require_once ("imports/output_xml.inc.php"); |
---|
79 | break; |
---|
80 | case "iso_2709" : |
---|
81 | require_once ("imports/output_iso_2709.inc.php"); |
---|
82 | break; |
---|
83 | case "txt": |
---|
84 | require_once ("imports/output_txt.inc.php"); |
---|
85 | break; |
---|
86 | case "custom" : |
---|
87 | require_once ("imports/$param_path/".$output_params['SCRIPT']); |
---|
88 | break; |
---|
89 | default : |
---|
90 | die($msg["export_cant_find_output_type"]); |
---|
91 | } |
---|
92 | |
---|
93 | //Création du fichier de sortie |
---|
94 | $file_out = "export".$origine.".".$output_params['SUFFIX']."~"; |
---|
95 | } else { |
---|
96 | //Récupération du répertoire |
---|
97 | $i = 0; |
---|
98 | $param_path == ""; |
---|
99 | _parser_($fic_catal, array("ITEM" => "_item_"), "CATALOG"); |
---|
100 | |
---|
101 | //Lecture des paramètres |
---|
102 | _parser_("imports/".$param_path."/params.xml", array("OUTPUT" => "_output_", "INPUT" => "_input_"), "PARAMS"); |
---|
103 | |
---|
104 | //Si l'export est spécial, on charge la fonction d'export |
---|
105 | if ($specialexport) require_once("imports/".$param_path."/export.inc.php"); |
---|
106 | } |
---|
107 | |
---|
108 | //Requête de sélection et de comptage des notices |
---|
109 | if ($n_current == "") |
---|
110 | $n_current = 0; |
---|
111 | |
---|
112 | //Récupération des notices |
---|
113 | $n_notices=0; |
---|
114 | $myCart=new caddie($idcaddie); |
---|
115 | //Pour le cas ou on a un panier d'exemplaire avec des exemplaires de bulletin |
---|
116 | $bulletin_a_exporter=array(); |
---|
117 | switch ($myCart->type) { |
---|
118 | case "NOTI" : |
---|
119 | $liste_flag=array(); |
---|
120 | $liste_no_flag=array(); |
---|
121 | if ($elt_flag) { |
---|
122 | $liste_flag=$myCart->get_cart("FLAG"); |
---|
123 | } |
---|
124 | if ($elt_no_flag) { |
---|
125 | $liste_no_flag=$myCart->get_cart("NOFLAG"); |
---|
126 | } |
---|
127 | $liste=$liste_flag; |
---|
128 | for ($i=0; $i<count($liste_no_flag); $i++) { |
---|
129 | $liste[]=$liste_no_flag[$i]; |
---|
130 | } |
---|
131 | break; |
---|
132 | case "EXPL" : |
---|
133 | $liste_flag=array(); |
---|
134 | $liste_no_flag=array(); |
---|
135 | if ($elt_flag) { |
---|
136 | $liste_flag=$myCart->get_cart("FLAG"); |
---|
137 | } |
---|
138 | if ($elt_no_flag) { |
---|
139 | $liste_no_flag=$myCart->get_cart("NOFLAG"); |
---|
140 | } |
---|
141 | $liste=$liste_flag; |
---|
142 | for ($i=0; $i<count($liste_no_flag); $i++) { |
---|
143 | $liste[]=$liste_no_flag[$i]; |
---|
144 | } |
---|
145 | $requete="create temporary table expl_cart_id (id integer) ENGINE=MyISAM "; |
---|
146 | pmb_mysql_query($requete); |
---|
147 | for ($i=0; $i<count($liste); $i++) { |
---|
148 | $requete="insert into expl_cart_id (id) values($liste[$i])"; |
---|
149 | pmb_mysql_query($requete); |
---|
150 | } |
---|
151 | //Récupération des id notices |
---|
152 | $requete="select expl_notice from exemplaires, expl_cart_id where expl_notice!=0 and expl_id=id group by expl_notice"; |
---|
153 | $resultat=pmb_mysql_query($requete); |
---|
154 | $liste=array(); |
---|
155 | while (list($id)=pmb_mysql_fetch_row($resultat)) { |
---|
156 | $liste[]=$id; |
---|
157 | } |
---|
158 | if($keep_expl && $_SESSION["param_export"]["genere_lien"] ){ |
---|
159 | //Récupération des id de bulletin si on exporte les exemplaires |
---|
160 | $requete="select expl_bulletin from exemplaires, expl_cart_id where expl_bulletin!=0 and expl_id=id group by expl_bulletin"; |
---|
161 | $resultat=pmb_mysql_query($requete); |
---|
162 | while (list($id)=pmb_mysql_fetch_row($resultat)) { |
---|
163 | $bulletin_a_exporter[]=$id; |
---|
164 | } |
---|
165 | if(!count($liste)){ |
---|
166 | //Il faut au moin une notice de monographie pour que l'export des exemplaires de bulletin soit réalisé |
---|
167 | $liste[]=0; |
---|
168 | } |
---|
169 | } |
---|
170 | break; |
---|
171 | case "BULL" : |
---|
172 | $liste=array(); |
---|
173 | $liste_flag=array(); |
---|
174 | $liste_no_flag=array(); |
---|
175 | if ($elt_flag) { |
---|
176 | $liste_flag=$myCart->get_cart("FLAG"); |
---|
177 | } |
---|
178 | if ($elt_no_flag) { |
---|
179 | $liste_no_flag=$myCart->get_cart("NOFLAG"); |
---|
180 | } |
---|
181 | $liste=$liste_flag; |
---|
182 | for ($i=0; $i<count($liste_no_flag); $i++) { |
---|
183 | $liste[]=$liste_no_flag[$i]; |
---|
184 | } |
---|
185 | $requete="create temporary table bull_cart_id (id integer) ENGINE=MyISAM "; |
---|
186 | pmb_mysql_query($requete); |
---|
187 | for ($i=0; $i<count($liste); $i++) { |
---|
188 | $requete="insert into bull_cart_id (id) values($liste[$i])"; |
---|
189 | pmb_mysql_query($requete); |
---|
190 | } |
---|
191 | //Récupération des id notices |
---|
192 | $requete="select analysis_notice from analysis, bull_cart_id where analysis_bulletin=id group by analysis_notice"; |
---|
193 | $resultat=pmb_mysql_query($requete); |
---|
194 | $liste=array(); |
---|
195 | while (list($id)=pmb_mysql_fetch_row($resultat)) { |
---|
196 | $liste[]=$id; |
---|
197 | } |
---|
198 | break; |
---|
199 | } |
---|
200 | $n_notices=count($liste); |
---|
201 | |
---|
202 | if ($first!=1) { |
---|
203 | $_SESSION["param_export"]["notice_exporte"]=""; |
---|
204 | $_SESSION["param_export"]["bulletin_exporte"]=""; |
---|
205 | //On enregistre les variables postées dans la session |
---|
206 | export_param::init_session(); |
---|
207 | |
---|
208 | if ($output_params["SPECIALDOCTYPE"] == "yes") { |
---|
209 | if ($liste[0]) $output_params["DOCTYPE"] = pmb_mysql_result(pmb_mysql_query("select typdoc from notices where notice_id='".$liste[0]."'"),0,0); |
---|
210 | } |
---|
211 | $fo = fopen("$base_path/temp/".$file_out, "w+"); |
---|
212 | //Entête |
---|
213 | @ fwrite($fo, _get_header_($output_params)); |
---|
214 | fclose($fo); |
---|
215 | } |
---|
216 | |
---|
217 | if ($n_notices == 0) { |
---|
218 | error_message_history($msg["export_no_notice_found"], $msg["export_no_notice_for_criterias"], 1); |
---|
219 | exit; |
---|
220 | } |
---|
221 | |
---|
222 | //Affichage de la progression |
---|
223 | $percent = @ round(($n_current / $n_notices) * 100); |
---|
224 | if ($percent == 0) |
---|
225 | $percent = 1; |
---|
226 | echo "<center><h3>".$msg["export_running"]."</h3></center><br />\n"; |
---|
227 | echo "<table align=center width=100%><tr><td style=\"border-width:1px;border-style:solid;border-color:#FFFFFF;\" width=100%><img src=\"$base_path/images/jauge.png\" width=\"".$percent."%\" height=\"16\"></td></tr><tr><td ><center>".round($percent)."%</center></td></tr></table>\n"; |
---|
228 | echo "<center>".sprintf($msg["export_progress"],$n_current,$n_notices,($n_notices - $n_current))."</center>"; |
---|
229 | |
---|
230 | //Début d'export du lot |
---|
231 | //Recherche du no_notice le plus grand |
---|
232 | $requete="select max(no_notice) from import_marc where origine='$origine'"; |
---|
233 | $resultat=pmb_mysql_query($requete); |
---|
234 | $no_notice=pmb_mysql_result($resultat,0,0)*1+1; |
---|
235 | |
---|
236 | $z = 0; |
---|
237 | if($_SESSION["param_export"]["notice_exporte"]) $notice_exporte = $_SESSION["param_export"]["notice_exporte"]; |
---|
238 | else $notice_exporte=array(); |
---|
239 | if($_SESSION["param_export"]["bulletin_exporte"]) $bulletin_exporte = $_SESSION["param_export"]["bulletin_exporte"]; |
---|
240 | else $bulletin_exporte=array(); |
---|
241 | while (($z<200)&&(($n_current+$z)<count($liste))) { |
---|
242 | $id=$liste[$n_current+$z]; |
---|
243 | if (!$specialexport) { |
---|
244 | $e_notice=array(); |
---|
245 | $param = new export_param(EXP_SESSION_CONTEXT); |
---|
246 | $e = new export(array($id),$notice_exporte, $bulletin_exporte); |
---|
247 | //Pour le cas ou on exporte les exemplaires et que l'on avait un panier d'exemplaire avec des bulletins |
---|
248 | if(count($bulletin_a_exporter)){ |
---|
249 | for($b=0;$b<count($bulletin_a_exporter);$b++){ |
---|
250 | if(array_search($bulletin_a_exporter[$b],$bulletin_exporte)===false){ |
---|
251 | //Si le bulletin ne fait pas partie de ceux déjà exporté |
---|
252 | $e->expl_bulletin_a_exporter[]=$bulletin_a_exporter[$b]; |
---|
253 | } |
---|
254 | } |
---|
255 | } |
---|
256 | if($id){//Pour éviter des erreurs si on export des exemplaires de bulletin sans monographie a partir d'un panier d'exemplaire |
---|
257 | do { |
---|
258 | $nn=$e -> get_next_notice($lender, $td, $sd, $keep_expl,$param->get_parametres($param->context) ); |
---|
259 | if ($e->notice) $e_notice[]=$e->notice; |
---|
260 | } while ($nn); |
---|
261 | $notice_exporte=$e->notice_exporte; |
---|
262 | } |
---|
263 | //Pour les exemplaires de bulletin |
---|
264 | do { |
---|
265 | $nn=$e -> get_next_bulletin($lender, $td, $sd, $keep_expl,$param->get_parametres($param->context)); |
---|
266 | if ($e->notice) $e_notice[]=$e->notice; |
---|
267 | } while ($nn); |
---|
268 | $bulletin_exporte=$e->bulletins_exporte; |
---|
269 | } else { |
---|
270 | $e_notice = _export_($id,$keep_expl); |
---|
271 | } |
---|
272 | if (!is_array($e_notice)) { |
---|
273 | $requete = "insert into import_marc (no_notice, notice, origine) values($no_notice,'".addslashes($e_notice)."', '$origine')"; |
---|
274 | pmb_mysql_query($requete); |
---|
275 | $no_notice++; |
---|
276 | $z ++; |
---|
277 | } else { |
---|
278 | for($i=0; $i<sizeof($e_notice);$i++) { |
---|
279 | $requete = "insert into import_marc (no_notice, notice, origine) values($no_notice,'".addslashes($e_notice[$i])."', '$origine')"; |
---|
280 | pmb_mysql_query($requete); |
---|
281 | $no_notice++; |
---|
282 | } |
---|
283 | $z ++; |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | //Paramètres passés pour l'appel suivant |
---|
288 | $query = "n_current=". ($n_current + $z); |
---|
289 | $query.="&elt_flag=$elt_flag&elt_no_flag=$elt_no_flag&idcaddie=$idcaddie"; |
---|
290 | $query.= "&export_type=".$export_type."&first=1&keep_expl=$keep_expl&origine=$origine"; |
---|
291 | |
---|
292 | if ($z < 200) { |
---|
293 | //Fin de l'export ?? |
---|
294 | echo "<script>setTimeout(\"document.location='start_import.php?first=1&import_type=$export_type&file_in=export".$origine.".fic&noimport=1&origine=$origine'\",1000)</script>"; |
---|
295 | $_SESSION["param_export"]["notice_exporte"]=''; |
---|
296 | $_SESSION["param_export"]["bulletin_exporte"]=''; |
---|
297 | } else { |
---|
298 | //Lot suivant |
---|
299 | $_SESSION["param_export"]["notice_exporte"]=$notice_exporte; |
---|
300 | $_SESSION["param_export"]["bulletin_exporte"]=$bulletin_exporte; |
---|
301 | echo "<script>setTimeout(\"document.location='start_export_caddie.php?".$query."'\",1000);</script>"; |
---|
302 | } |
---|
303 | |
---|
304 | ?> |
---|