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);
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();
}
}
// 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_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);
if(file_exists("../../temp/err_import_authorities".SESSid.".unimarc")){
print " ";
printf($msg['import_authorities_error'],$nb_notices_rejetees);
print " ".$msg['download']."";
}
//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);
}
}