id_import ; $nb_notices++; //on la traite comme une notice d'autorités... $notice_authority = new notice_authority($notobj->notice); if($notice_authority->error){ //en cas d'erreur à la lecture d'un format unimarc A, on a peut être un format unimarc B et une notice de collection $notice_authority = new notice_authority_serie($notobj->notice,"UNI","iso-8859-1",$type_link['subcollection']); if($notice_authority->error){ $fp = fopen ("../../temp/err_import_authorities".SESSid.".unimarc","a+"); fwrite ($fp, $notobj->notice); fclose ($fp); $nb_notices_rejetees++; } } //on a une notice correcte, on regarde si on doit la traitée... if(!$notice_authority->error && ($authorities_type == 'all' || $notice_authority->type == $authorities_type)){ //on y va... $authority_import = new $pmb_import_modele_authorities($notice_authority,$create_link,$create_link_spec,$force_update,$id_thesaurus,$type_link['rejected'],$type_link['associated']); //on récupère les infos classiques... $authority_import->get_informations(); //on donne la possibilité d'agir sur les données avant l'import... $authority_import->get_informations_callback(); //si la notice est d'un type connu et donc importable dans PMB if($authority_import->notice->type != ""){ // on importe $authority_import->import(); // et on donne la possibilité d'un traitement post-import $authority_import->import_callback(); if(isset($nb_notices_import) && is_array($nb_notices_import) && $nb_notices_import[$authority_import->notice->type]){ $nb_notices_import[$authority_import->notice->type]++; }else{ $nb_notices_import[$authority_import->notice->type]=1; } }elseif(!$notice_authority->error){ $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('iimport_authorities".addslashes(SESSid).".php', '".addslashes($msg[import_authorite_bad_type].($notice_authority->type != "" ? $msg["import_authorities_type_".$notice_authority->type] : $msg["52"]))."') ") ; } }elseif(!$notice_authority->error){ $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('iimport_authorities".addslashes(SESSid).".php', '".addslashes($msg[import_authorite_bad_type].($notice_authority->type != "" ? $msg["import_authorities_type_".$notice_authority->type] : $msg["52"]))."') ") ; } // la notice à été traitée, on la supprime de la table d'import... $query = "delete from import_marc where id_import = ".$idnotice_import; mysql_query($query); } } //on regarde si besoin d'une autre passe... if($nb_notices_remanning>$pmb_import_limit_record_load){ $form = str_replace("!!file_submit!!",$file_submit,$authorities_import_afterupload_form); $form = str_replace("!!from_file!!",$from_file,$form); $form = str_replace("!!create_link!!",$create_link,$form); $form = str_replace("!!create_link_spec!!",$create_link_spec,$form); $form = str_replace("!!force_update!!",$force_update,$form); $form = str_replace("!!authorities_type!!",$authorities_type,$form); $form = str_replace("!!total!!",$total,$form); $form = str_replace("!!nb_notices!!",$nb_notices,$form); $form = str_replace("!!nb_notices_import!!",serialize($nb_notices_import),$form); $form = str_replace("!!nb_notices_rejetees!!",$nb_notices_rejetees,$form); $form = str_replace("!!type_link!!",serialize($type_link),$form); $form = str_replace("!!id_thesaurus!!",$id_thesaurus,$form); print $form; printf($msg['nb_authorities_already_imported'],$nb_notices,$total); }else{ //c'est fini ! printf($msg['end_authorities_import'],$nb_notices); print "
"; if(isset($nb_notices_import) && is_array($nb_notices_import)){ foreach ( $nb_notices_import as $key => $value ) { print $value." ".htmlentities($msg["import_authorities_type_".$key]." ".$msg["import_authorities_import_success"],ENT_QUOTES,$charset)."
"; } } if($nb_notices_rejetees){ printf($msg['import_authorities_error'],$nb_notices_rejetees); if(file_exists("../../temp/err_import_authorities".SESSid.".unimarc")){ print " ".$msg['download']."
"; } } $gen_liste_log=""; $resultat_liste=mysql_query("SELECT error_origin, error_text, count(*) as nb_error FROM error_log where error_origin in ('iimport_authorities".addslashes(SESSid).".php') group by error_origin, error_text ORDER BY error_origin, error_text" ); $nb_liste=mysql_num_rows($resultat_liste); if ($nb_liste>0) { $gen_liste_log = "

".$msg[538]."
" ; $gen_liste_log.=""; $i_log=0; while ($i_log<$nb_liste) { $gen_liste_log.=""; $gen_liste_log.="" ; $gen_liste_log.="" ; $gen_liste_log.="" ; $gen_liste_log.="" ; $i_log++; } } $gen_liste_str.="
".$msg[539]."".$msg[540]."".$msg[541]."
".htmlentities(mysql_result($resultat_liste,$i_log,"error_origin"),ENT_QUOTES,$charset)."".htmlentities(mysql_result($resultat_liste,$i_log,"error_text"),ENT_QUOTES,$charset)."".htmlentities(mysql_result($resultat_liste,$i_log,"nb_error"),ENT_QUOTES,$charset)."
\n" ; print $gen_liste_log; //on supprime les tables d'import... mysql_query("drop table authorities_import"); mysql_query("drop table authorities_import_links"); } break; // formulaire de base case "before_upload" : default : //affichage du selectionneur de thesaurus et du lien vers les thésaurus $liste_thesaurus = thesaurus::getThesaurusList(); $sel_thesaurus = ''; $lien_thesaurus = ''; $sel_thesaurus = ""; $form = str_replace("!!thesaurus!!",$sel_thesaurus,$authorites_import_form_content); print $form; break; } function loadfile_in_base(){ global $msg ; global $sub ; global $noticenumber, $file_submit, $from_file, $pb_fini, $reload ; global $pmb_import_limit_read_file ; if ($noticenumber=="") $noticenumber=0; if (!file_exists($file_submit)) { print $file_submit; printf ($msg[506],$from_file); /* The file %s doesn't exist... */ return; } if (filesize($file_submit)==0) { printf ($msg[507],$from_file); /* The file % is empty, it's going to be deleted */ unlink ($to_file); return; } $handle = fopen ($file_submit, "rb"); if (!$handle) { printf ($msg[508],$from_file); /* Unable to open the file %s ... */ return; } $file_size=filesize ($file_submit); $contents = fread ($handle, $file_size); fclose ($handle); /* First load of the shot, let's empty the import table */ if ($reload=="") { $sql = "DELETE FROM import_marc WHERE origine='".addslashes(SESSid)."' "; $sql_result = mysql_query($sql) or die ("Couldn't delete import table !"); $sql = "DELETE FROM error_log WHERE error_origin LIKE '%_".addslashes(SESSid).".%' "; $sql_result = mysql_query($sql) or die ("Couldn't delete error_log table !"); } /* The whole file is in $contents, let's read it */ $str_lu=""; $j=0; $i=0; $pb_fini=""; $txt=""; while ( ($i<=strlen($contents)) && ($pb_fini=="") ) { $car_lu=substr($contents,$i,1) ; $i++; if ($i<=strlen($contents)) { if ($car_lu != chr(0x1d)) { /* the read car isn't the end of the notice */ $str_lu = $str_lu.$car_lu; } else { /* the read car is the end of a notice */ $str_lu = $str_lu.$car_lu; $j++; $sql = "INSERT INTO import_marc (notice,origine) VALUES('".addslashes($str_lu)."','".addslashes(SESSid)."')"; $sql_result = mysql_query($sql) or die ("Couldn't insert record!"); if ($j>=$pmb_import_limit_read_file && $i=$pmb_import_limit_read_file && $i>=strlen($contents)){ $pb_fini = "EOF"; } $str_lu=""; } } else { /* the wole file has been read */ $pb_fini="EOF"; } } /* end while red file */ if ($pb_fini=="EOF") { /* The file has been read, we can delete it */ unlink ($file_submit); } }