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_generique.php,v 1.3 2015-04-03 11:16:22 jpermanne Exp $ |
---|
6 | |
---|
7 | //Exécution de l'export |
---|
8 | $base_path = "../.."; |
---|
9 | $base_auth = "ADMINISTRATION_AUTH"; |
---|
10 | $base_title = "\$msg[export_title_only]"; |
---|
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."/export_param.class.php"); |
---|
16 | |
---|
17 | //Récupération du chemin du fichier de paramétrage de l'import |
---|
18 | function _item_($param) { |
---|
19 | global $export_type; |
---|
20 | global $i; |
---|
21 | global $param_path; |
---|
22 | global $export_type_l; |
---|
23 | |
---|
24 | if ($i == $export_type) { |
---|
25 | $param_path = $param['PATH']; |
---|
26 | $export_type_l = $param['NAME']; |
---|
27 | } |
---|
28 | $i ++; |
---|
29 | } |
---|
30 | |
---|
31 | //Récupération du paramètre d'import |
---|
32 | function _output_($param) { |
---|
33 | global $output; |
---|
34 | global $output_type; |
---|
35 | global $output_params; |
---|
36 | |
---|
37 | $output = $param['IMPORTABLE']; |
---|
38 | $output_type = $param['TYPE']; |
---|
39 | $output_params = $param; |
---|
40 | } |
---|
41 | |
---|
42 | function _input_($param) { |
---|
43 | global $specialexport; |
---|
44 | |
---|
45 | if ($param["SPECIALEXPORT"]=="yes") { |
---|
46 | $specialexport=true; |
---|
47 | } else $specialexport=false; |
---|
48 | } |
---|
49 | |
---|
50 | if (file_exists("imports/catalog_subst.xml")) |
---|
51 | $fic_catal = "imports/catalog_subst.xml"; |
---|
52 | else |
---|
53 | $fic_catal = "imports/catalog.xml"; |
---|
54 | |
---|
55 | //Initialisation si première fois |
---|
56 | if ($first != 1) { |
---|
57 | //pmb_mysql_query("delete from import_marc"); |
---|
58 | |
---|
59 | $origine=str_replace(" ","",microtime()); |
---|
60 | $origine=str_replace("0.","",$origine); |
---|
61 | |
---|
62 | //Récupération du répertoire |
---|
63 | $i = 0; |
---|
64 | $param_path = ""; |
---|
65 | _parser_($fic_catal, array("ITEM" => "_item_"), "CATALOG"); |
---|
66 | |
---|
67 | //Lecture des paramètres |
---|
68 | _parser_("imports/".$param_path."/params.xml", array("OUTPUT" => "_output_","INPUT" => "_input_"), "PARAMS"); |
---|
69 | |
---|
70 | //Si l'export est spécial, on charge la fonction d'export |
---|
71 | if ($specialexport) require_once("imports/".$param_path."/export.inc.php"); |
---|
72 | |
---|
73 | //En fonction du type de fichier de sortie, inclusion du script de gestion des sorties |
---|
74 | switch ($output_type) { |
---|
75 | case "xml" : |
---|
76 | require_once ("imports/output_xml.inc.php"); |
---|
77 | break; |
---|
78 | case "iso_2709" : |
---|
79 | require_once ("imports/output_iso_2709.inc.php"); |
---|
80 | break; |
---|
81 | case "custom" : |
---|
82 | require_once ("imports/$param_path/".$output_params['SCRIPT']); |
---|
83 | break; |
---|
84 | case "txt": |
---|
85 | require_once ("imports/output_txt.inc.php"); |
---|
86 | break; |
---|
87 | default : |
---|
88 | die($msg["export_cant_find_output_type"]); |
---|
89 | } |
---|
90 | |
---|
91 | //Création du fichier de sortie |
---|
92 | $file_out = "export".$origine.".".$output_params['SUFFIX']."~"; |
---|
93 | } else { |
---|
94 | //Récupération du répertoire |
---|
95 | $i = 0; |
---|
96 | $param_path == ""; |
---|
97 | _parser_($fic_catal, array("ITEM" => "_item_"), "CATALOG"); |
---|
98 | |
---|
99 | //Lecture des paramètres |
---|
100 | _parser_("imports/".$param_path."/params.xml", array("OUTPUT" => "_output_", "INPUT" => "_input_"), "PARAMS"); |
---|
101 | |
---|
102 | //Si l'export est spécial, on charge la fonction d'export |
---|
103 | if ($specialexport) require_once("imports/".$param_path."/export.inc.php"); |
---|
104 | } |
---|
105 | |
---|
106 | //Requête de sélection et de comptage des notices |
---|
107 | if ($n_current == "") |
---|
108 | $n_current = 0; |
---|
109 | |
---|
110 | $typdoc = "typdoc$lender"; |
---|
111 | $td = $$typdoc; |
---|
112 | $statutdoc = "statut$lender"; |
---|
113 | $sd = $$statutdoc; |
---|
114 | |
---|
115 | $requete = "select notice_id from notices"; |
---|
116 | $requete_count = "select count(distinct notice_id) from notices"; |
---|
117 | |
---|
118 | if (($lender != "x") || ($td != "") || ($sd != "")) { |
---|
119 | $requete.= " , exemplaires"; |
---|
120 | $requete_count.= " , exemplaires"; |
---|
121 | $requete_where.= " expl_notice=notice_id"; |
---|
122 | } |
---|
123 | |
---|
124 | if ($lender != "x") { |
---|
125 | $requete_where.= " and expl_owner=$lender"; |
---|
126 | } |
---|
127 | |
---|
128 | if ($td != "") { |
---|
129 | $l_td = implode(",", $td); |
---|
130 | $requete_where.= " and expl_typdoc in (".$l_td.")"; |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | if ($sd != "") { |
---|
135 | $l_sd = implode(",", $sd); |
---|
136 | $requete_where.= " and expl_statut in (".$l_sd.")"; |
---|
137 | } |
---|
138 | |
---|
139 | if ($requete_where != "") { |
---|
140 | $requete.= " where ".$requete_where; |
---|
141 | $requete_count.= " where ".$requete_where; |
---|
142 | } |
---|
143 | |
---|
144 | $requete.= " group by notice_id limit $n_current,200"; |
---|
145 | |
---|
146 | //Nombre de notices correspondantes aux critères |
---|
147 | $resultat = pmb_mysql_query($requete_count); |
---|
148 | $n_notices = pmb_mysql_result($resultat, 0, 0); |
---|
149 | |
---|
150 | if ($first!=1) { |
---|
151 | $_SESSION["param_export"]["notice_exporte"]=""; |
---|
152 | //On enregistre les variables postées dans la session |
---|
153 | export_param::init_session(); |
---|
154 | $fo = fopen("$base_path/temp/".$file_out, "w+"); |
---|
155 | //Entête |
---|
156 | @ fwrite($fo, _get_header_($output_params)); |
---|
157 | fclose($fo); |
---|
158 | } |
---|
159 | |
---|
160 | if ($n_notices == 0) { |
---|
161 | error_message($msg["export_no_notice_found"], $msg["export_no_notice_for_criterias"], 1, "export.php"); |
---|
162 | exit; |
---|
163 | } |
---|
164 | |
---|
165 | //Affichage de la progression |
---|
166 | $percent = @ round(($n_current / $n_notices) * 100); |
---|
167 | if ($percent == 0) |
---|
168 | $percent = 1; |
---|
169 | echo "<center><h3>".$msg["export_running"]."</h3></center><br />\n"; |
---|
170 | 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"; |
---|
171 | echo "<center>".sprintf($msg["export_progress"],$n_current,$n_notices,($n_notices - $n_current))."</center>"; |
---|
172 | |
---|
173 | //Début d'export du lot |
---|
174 | $resultat = pmb_mysql_query($requete); |
---|
175 | |
---|
176 | //Recherche du no_notice le plus grand |
---|
177 | $requete_max="select max(no_notice) from import_marc where origine='$origine'"; |
---|
178 | $resultat_max=pmb_mysql_query($requete_max); |
---|
179 | $no_notice=pmb_mysql_result($resultat_max,0,0)*1+1; |
---|
180 | |
---|
181 | $z = 0; |
---|
182 | if($_SESSION["param_export"]["notice_exporte"]) $notice_exporte = $_SESSION["param_export"]["notice_exporte"]; |
---|
183 | else $notice_exporte=array(); |
---|
184 | if($_SESSION["param_export"]["bulletin_exporte"]) $bulletin_exporte = $_SESSION["param_export"]["bulletin_exporte"]; |
---|
185 | else $bulletin_exporte=array(); |
---|
186 | while (list ($id) = pmb_mysql_fetch_row($resultat)) { |
---|
187 | if (!$specialexport) { |
---|
188 | $e_notice=array(); |
---|
189 | $param = new export_param(EXP_SESSION_CONTEXT); |
---|
190 | $e = new export(array($id),$notice_exporte, $bulletin_exporte); |
---|
191 | do { |
---|
192 | $nn=$e -> get_next_notice($lender, $td, $sd, $keep_expl, $param->get_parametres($param->context)); |
---|
193 | if ($e->notice) $e_notice[]=$e->notice; |
---|
194 | } while ($nn); |
---|
195 | $notice_exporte=$e->notice_exporte; |
---|
196 | //Pour les exemplaires de bulletin |
---|
197 | do { |
---|
198 | $nn=$e -> get_next_bulletin($lender, $td, $sd, $keep_expl,$param->get_parametres($param->context)); |
---|
199 | if ($e->notice) $e_notice[]=$e->notice; |
---|
200 | } while ($nn); |
---|
201 | $bulletin_exporte=$e->bulletins_exporte; |
---|
202 | } else { |
---|
203 | $e_notice = _export_($id,$keep_expl); |
---|
204 | } |
---|
205 | if (!is_array($e_notice)) { |
---|
206 | $requete = "insert into import_marc (no_notice, notice, origine) values($no_notice,'".addslashes($e_notice)."', '$origine')"; |
---|
207 | pmb_mysql_query($requete); |
---|
208 | $no_notice++; |
---|
209 | $z ++; |
---|
210 | } else { |
---|
211 | for($i=0; $i<sizeof($e_notice);$i++) { |
---|
212 | $requete = "insert into import_marc (no_notice, notice, origine) values($no_notice,'".addslashes($e_notice[$i])."', '$origine')"; |
---|
213 | pmb_mysql_query($requete); |
---|
214 | $no_notice++; |
---|
215 | } |
---|
216 | $z ++; |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | //Paramètres passés pour l'appel suivant |
---|
222 | $query = "n_current=". ($n_current + $z); |
---|
223 | for ($i = 0; $i < count($td); $i ++) { |
---|
224 | $query.= "&".$typdoc."[$i]=".$td[$i]; |
---|
225 | } |
---|
226 | for ($i = 0; $i < count($sd); $i ++) { |
---|
227 | $query.= "&".$statutdoc."[$i]=".$sd[$i]; |
---|
228 | } |
---|
229 | $query.= "&lender=$lender&export_type=".$export_type."&first=1&keep_expl=$keep_expl&origine=$origine"; |
---|
230 | |
---|
231 | if ($z < 200) { |
---|
232 | //Fin de l'export ?? |
---|
233 | 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>"; |
---|
234 | $_SESSION["param_export"]["notice_exporte"]=''; |
---|
235 | $_SESSION["param_export"]["bulletin_exporte"]=''; |
---|
236 | } else { |
---|
237 | $_SESSION["param_export"]["notice_exporte"]=$notice_exporte; |
---|
238 | $_SESSION["param_export"]["bulletin_exporte"]=$bulletin_exporte; |
---|
239 | //Lot suivant |
---|
240 | echo "<script>setTimeout(\"document.location='start_export.php?".$query."'\",1000);</script>"; |
---|
241 | } |
---|
242 | |
---|
243 | ?> |
---|