"_item_"), "CATALOG"); //Lecture des paramètres _parser_("imports/".$param_path."/params.xml", array("IMPORTNAME" => "_import_name_", "NPERPASS" => "_n_per_pass_", "INPUT" => "_input_", "STEP" => "_step_", "OUTPUT" => "_output_"), "PARAMS"); //Inclusion des librairies éventuelles if (is_array($step)) { for ($i = 0; $i < count($step); $i ++) { if ($step[$i]['TYPE'] == "custom") { //echo "imports/".$param_path."/".$step[$i][SCRIPT][0][value]; require_once ("imports/".$param_path."/".$step[$i]['SCRIPT'][0]['value']); } } } require_once ("xmltransform.php"); //En fonction du type de fichier d'entrée, inclusion du script de gestion des entrées $input_instance = start_import::get_instance_from_input_type($input_type); //En fonction du type de fichier de sortie, inclusion du script de gestion des sorties $output_instance = start_export::get_instance_from_output_type($output_type); //Si premier accès if(!isset($first)) $first = ''; if (!$first) { $origine=str_replace(" ","",microtime()); $origine=str_replace("0.","",$origine); //Copie du fichier dans le répertoire temporaire if ($_FILES['import_file']['name']) { if (!@ copy($_FILES['import_file']['tmp_name'], "$base_path/temp/".$origine.$_FILES['import_file']['name'])) { error_message_history($msg["ie_tranfert_error"], $msg["ie_transfert_error_detail"], 1); exit; } else $file_in = $origine.$_FILES['import_file']['name']; } else if ($file_in && file_exists($base_path."/temp/".$file_in)){ } else { if (!$file_in) $file_in = "convert".(defined("LOCATION")?"_".constant("LOCATION"):"").".fic"; if (!file_exists($base_path."/temp/convert".(defined("LOCATION")?"_".constant("LOCATION"):"").".fic")) { error_message_history($msg["ie_file_not_found"], sprintf($msg["ie_file_not_found_detail"],$file_in), 1); exit; } } //Première notice = 0 $n_current = 0; //Nombre d'erreurs = 0; $n_errors = 0; //Création du fichier de sortie $f = explode(".", $file_in); if (count($f) > 1) { unset($f[count($f) - 1]); } $file_out = implode(".", $f).".".$output_params['SUFFIX']."~"; $fo = fopen("$base_path/temp/".$file_out, "w+"); //Ouverture du fichier d'origine $fi = fopen("$base_path/temp/".$file_in, "r"); //Récupération du nombre de notices et enregistrement dans la base de données des notices if(is_object($input_instance)) { $index = $input_instance->_get_n_notices_($fi, "$base_path/temp/".$file_in, $input_params,$origine); } else { $index = _get_n_notices_($fi, "$base_path/temp/".$file_in, $input_params,$origine); } if (count($index) == 0) { error_message_history($msg["ie_empty_file"], sprintf($msg["ie_empty_file_detail"],$import_type_l), 1); exit; } //Entête if(isset($output_params['SCRIPT'])) { $class_name = str_replace('.class.php', '', $output_params['SCRIPT']); } if(is_object($output_instance)) { fwrite($fo, $output_instance->_get_header_($output_params)); } elseif (isset($class_name) && class_exists($class_name)) { $import_instance = new $class_name(); fwrite($fo, $import_instance->_get_header_($output_params)); } else { fwrite($fo, _get_header_($output_params)); } fclose($fo); //Vidage de la table de log //pmb_mysql_query("delete from error_log where error_origin='convert.log'"); } function convert_notice($notice,$encoding) { global $step; global $param_path; global $n_errors; global $message_convert; global $n_current; global $z; if (is_array($step)) { for ($i = 0; $i < count($step); $i ++) { $s = $step[$i]; //si on a un encodage sur la notice, on le rajoute aux parametres if($encoding) $s['ENCODING'] = $encoding; $islast=($i==count($step)-1); $isfirst=($i==0); switch ($s['TYPE']) { case "xmltransform" : $r = perform_xslt($notice, $s, $islast, $isfirst, $param_path); break; case "toiso" : $r = toiso($notice, $s, $islast, $isfirst, $param_path); break; case "isotoxml" : $r = isotoxml($notice, $s, $islast, $isfirst, $param_path); break; case "texttoxml": $r = texttoxml($notice, $s, $islast, $isfirst, $param_path); break; case "custom" : $static = explode('.', $s['SCRIPT'][0]['value']); if (class_exists($static[0])) { eval("\$r=".$static[0]."::".$s['CALLBACK'][0]['value']."(\$notice, \$s, \$islast, \$isfirst, \$param_path);"); } else { eval("\$r=".$s['CALLBACK'][0]['value']."(\$notice, \$s, \$islast, \$isfirst, \$param_path);"); } break; } if (!$r['VALID']) { $n_errors ++; $message_convert.= "Notice ". ($n_current + $z)." : ".$r['ERROR']."
\n"; $notice = ""; break; } else { $notice = $r['DATA']; if(isset($r['WARNING']) && $r['WARNING']){ $n_errors ++; $message_convert.= "Notice ". ($n_current + $z)." : ".$r['WARNING']."
\n"; } } } } return $notice; } $requete="select count(1) from import_marc where origine='$origine'"; $resultat=pmb_mysql_query($requete); $n_notices=pmb_mysql_result($resultat,0,0); $percent = @ round(($n_current / $n_notices) * 100); if ($percent == 0) $percent = 1; echo "

".$msg["conversion_en_cours"]."


\n"; echo "
".round($percent)."%
\n"; echo "".sprintf($msg["ie_processed_notices"],$n_current,$n_notices,($n_notices - $n_current)).""; $z = 0; //Ouverture du fichier final $f = explode(".", $file_in); if (count($f) > 1) { unset($f[count($f) - 1]); } if (empty($output_params['SUFFIX'])) $output_params['SUFFIX'] = ''; $file_out = implode(".", $f).".".$output_params['SUFFIX']."~"; $fo = fopen("$base_path/temp/".$file_out, "r+"); //Positionnement a la fin du fichier fseek($fo, filesize("$base_path/temp/".$file_out)); for ($i = $n_current; $i < $n_current + $n_per_pass; $i ++) { $requete="select notice, encoding from import_marc where no_notice=".($i+1)." and origine='$origine'"; $resultat=pmb_mysql_query($requete); if (pmb_mysql_num_rows($resultat)!=0) { //Si la notice existe début de conversion $obj=pmb_mysql_fetch_object($resultat); $notice_ = convert_notice($obj->notice,$obj->encoding); @fwrite($fo, $notice_); $z ++; } else break; } //Y-a-t-il eu des erreurs ? if ($message_convert != "") { $requete="insert into error_log (error_date,error_origin, error_text) values(now(),'convert.log ".$origine."','".addslashes($message_convert)."')"; pmb_mysql_query($requete); echo pmb_mysql_error(); } //Fin du fichier de notice ? if ($z < $n_per_pass) { $n_current = $n_current + $z; if(isset($output_params['SCRIPT'])) { $class_name = str_replace('.class.php', '', $output_params['SCRIPT']); } if(is_object($output_instance)) { fwrite($fo, $output_instance->_get_footer_($output_params)); } elseif (isset($class_name) && class_exists($class_name)) { $export_instance = new $class_name(); fwrite($fo, $export_instance->_get_footer_($output_params)); } else { fwrite($fo, _get_footer_($output_params)); } fclose($fo); $requete="delete from import_marc where origine='$origine'"; pmb_mysql_query($requete); if ($redirect) { $redirect .= "&file_in=".rawurlencode($file_in)."&suffix=".$output_params['SUFFIX']."&origine=".$origine."&import_type=$import_type&outputtype=".$output_params["TYPE"]."&converted=1"; $location = "parent.document.location='".$redirect."'"; } else { if (!isset($output_params['MIMETYPE'])) $output_params['MIMETYPE'] = ''; if (!isset($index)) $index = array(); $location = "document.location='end_import.php?file_in=".rawurlencode($file_in)."&first=1&n_current=".$n_current."&import_type=".$import_type."&n_total=".count($index)."&n_errors=$n_errors&output=$output&suffix=".$output_params['SUFFIX']."&import_type_l=".rawurlencode($import_type_l)."&noimport=$noimport".$redirect_string."&mimetype=".rawurlencode($output_params['MIMETYPE'])."&origine=".$origine."'"; } echo ""; } else { //Si pas fin, recharegement de la page pour les $n_per_pass_suivants $n_current = $n_current + $n_per_pass; fclose($fo); if ($redirect) $redirect_string = "&redirect=".urlencode($redirect); else $redirect_string = ""; echo ""; } ?>