コード例 #1
0
ファイル: export.class.php プロジェクト: hogsim/PMB
 function get_next_notice($lender = "", $td = array(), $sd = array(), $keep_expl = false, $params = array())
 {
     global $is_expl_caddie;
     global $include_path, $lang;
     global $opac_show_book_pics;
     global $dbh, $charset;
     if (!$is_expl_caddie) {
         $requete_panier = "select count(*) from expl_cart_id";
         $res_panier = @pmb_mysql_query($requete_panier);
         if ($res_panier) {
             $is_expl_caddie = 2;
         } else {
             $is_expl_caddie = 1;
         }
     }
     unset($this->xml_array);
     $this->xml_array = array();
     $this->notice = "";
     if ($this->current_notice != -1 && array_search($this->notice_list[$this->current_notice], $this->notice_exporte) !== false) {
         $this->current_notice++;
         if ($this->current_notice >= count($this->notice_list)) {
             $this->current_notice = -1;
         }
         return true;
     }
     if ($this->current_notice != -1) {
         //Recuperation des infos de la notice
         $requete = "select * from notices where notice_id=" . $this->notice_list[$this->current_notice];
         $resultat = pmb_mysql_query($requete);
         $res = pmb_mysql_fetch_object($resultat);
         if (!$res) {
             return false;
         }
         //Remplissage des champs immediats
         //Numero unique de la base
         $this->add_field("001", "", "", $res->notice_id);
         //Champ de traitement
         if ($charset == "utf-8") {
             $encodage = "50  ";
         } else {
             $encodage = "0103";
         }
         $c100 = substr($res->create_date, 0, 4) . substr($res->create_date, 5, 2) . substr($res->create_date, 8, 2) . "u        u  u0frey" . $encodage . "    ba";
         $this->add_field("100", "  ", array("a" => $c100), "");
         //Titre
         $titre[c] = "200";
         $titre[ind] = "1 ";
         $labels = array("a", "c", "d", "e");
         $subfields = array();
         for ($i = 1; $i < 5; $i++) {
             $v = "";
             eval("\$v=\$res->tit{$i};");
             $subfields[$labels[$i - 1]] = $v;
         }
         if ($res->niveau_biblio == 'b' && $res->niveau_hierar == '2') {
             $req_bulletin = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero from bulletins WHERE num_notice=" . $res->notice_id;
             $result_bull = pmb_mysql_query($req_bulletin);
             while ($bull = pmb_mysql_fetch_object($result_bull)) {
                 $subfields["h"] = $bull->bulletin_numero;
                 $subfields["i"] = $bull->bulletin_titre;
                 $subfields["9"] = "id:" . $bull->bulletin_id;
             }
         }
         $this->add_field("200", "1 ", $subfields);
         //Titres Uniformes
         $rqt_tu = "select * from notices_titres_uniformes,titres_uniformes where tu_id =ntu_num_tu and ntu_num_notice = '" . $this->notice_list[$this->current_notice] . "' order by ntu_ordre";
         $result_tu = pmb_mysql_query($rqt_tu);
         if (pmb_mysql_num_rows($result_tu)) {
             while ($row_tu = pmb_mysql_fetch_object($result_tu)) {
                 $subfields = array();
                 $subfields["9"] = "id:" . $row_tu->tu_id;
                 $subfields["a"] = $row_tu->tu_name;
                 $subfields["u"] = $row_tu->tu_tonalite;
                 $subfields["n"] = $row_tu->tu_comment;
                 $subfields["i"] = $row_tu->ntu_titr;
                 $subfields["k"] = $row_tu->ntu_date;
                 $subfields["l"] = $row_tu->ntu_sous_vedette;
                 $subfields["m"] = $row_tu->ntu_langue;
                 $subfields["q"] = $row_tu->ntu_version;
                 $subfields["w"] = $row_tu->ntu_mention;
                 $rqt_tucomp = "SELECT * FROM tu_distrib WHERE distrib_num_tu='" . $row_tu->tu_id . "' ORDER BY distrib_ordre,distrib_name";
                 $result_tucomp = pmb_mysql_query($rqt_tucomp);
                 if (pmb_mysql_num_rows($result_tucomp)) {
                     while ($row_tucomp = pmb_mysql_fetch_object($result_tucomp)) {
                         $subfields["r"][] = $row_tucomp->distrib_name;
                     }
                 }
                 $rqt_tucomp = "SELECT * FROM tu_ref WHERE ref_num_tu='" . $row_tu->tu_id . "' ORDER BY ref_ordre,ref_name";
                 $result_tucomp = pmb_mysql_query($rqt_tucomp);
                 if (pmb_mysql_num_rows($result_tucomp)) {
                     while ($row_tucomp = pmb_mysql_fetch_object($result_tucomp)) {
                         $subfields["s"][] = $row_tucomp->ref_name;
                     }
                 }
                 $rqt_tucomp = "SELECT * FROM tu_subdiv WHERE subdiv_num_tu='" . $row_tu->tu_id . "' ORDER BY subdiv_ordre,subdiv_name";
                 $result_tucomp = pmb_mysql_query($rqt_tucomp);
                 if (pmb_mysql_num_rows($result_tucomp)) {
                     while ($row_tucomp = pmb_mysql_fetch_object($result_tucomp)) {
                         $subfields["j"][] = $row_tucomp->subdiv_name;
                     }
                 }
                 $this->add_field("500", "10", $subfields);
             }
         }
         //Titre du pério pour les notices de bulletin
         $subfields = array();
         if ($res->niveau_biblio == 'b' && $res->niveau_hierar == '2') {
             $req_bulletin = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero, tit1 as titre from bulletins, notices WHERE bulletin_notice=notice_id AND num_notice=" . $res->notice_id;
             $result_bull = pmb_mysql_query($req_bulletin);
             while ($bull = pmb_mysql_fetch_object($result_bull)) {
                 $subfields["a"] = $bull->titre;
             }
         }
         $this->add_field("530", "  ", $subfields);
         //Date en 210 pour les notices de bulletin
         $subfields = array();
         if ($res->niveau_biblio == 'b' && $res->niveau_hierar == '2') {
             $req_bulletin = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero from bulletins WHERE num_notice=" . $res->notice_id;
             $result_bull = pmb_mysql_query($req_bulletin);
             while ($bull = pmb_mysql_fetch_object($result_bull)) {
                 $subfields["h"] = $bull->date_date;
                 $subfields["d"] = $bull->mention_date;
             }
         }
         $this->add_field("210", "  ", $subfields);
         //isbn
         $subfields = array();
         $subfields["a"] = $res->code;
         $subfields["d"] = $res->prix;
         $this->add_field("010", "  ", $subfields);
         // URL
         $subfields = array();
         $subfields["u"] = $res->lien;
         $subfields["q"] = $res->eformat;
         $this->add_field("856", "  ", $subfields);
         //Langage
         $rqttmp_lang = "select type_langue,code_langue from notices_langues where num_notice='{$res->notice_id}' order by ordre_langue ";
         $restmp_lang = pmb_mysql_query($rqttmp_lang);
         $ind = "0 ";
         $subfields_101 = array();
         while ($tmp_lang = pmb_mysql_fetch_object($restmp_lang)) {
             if ($tmp_lang->type_langue) {
                 $ind = "1 ";
                 $subfields_101['c'][] = $tmp_lang->code_langue;
             } else {
                 $subfields_101['a'][] = $tmp_lang->code_langue;
             }
         }
         $this->add_field('101', $ind, $subfields_101);
         //Mention d'edition
         $subfields = array();
         $subfields["a"] = $res->mention_edition;
         $this->add_field("205", "  ", $subfields);
         //Collation
         $subfields = array();
         $subfields["a"] = $res->npages;
         $subfields["c"] = $res->ill;
         $subfields["d"] = $res->size;
         $subfields["e"] = $res->accomp;
         $this->add_field("215", "  ", $subfields);
         //Notes
         $subfields = array();
         $subfields["a"] = $res->n_gen;
         $this->add_field("300", "  ", $subfields);
         $subfields["a"] = $res->n_contenu;
         $this->add_field("327", "  ", $subfields);
         $subfields["a"] = $res->n_resume;
         $this->add_field("330", "  ", $subfields);
         //Auteurs
         //Recherche des auteurs;
         $requete = "select author_id, author_type, author_name, author_rejete, author_date, responsability_fonction, responsability_type \n\t\t\t,author_subdivision, author_lieu,author_ville, author_pays,author_numero,author_web, author_comment\n\t\t\tfrom authors, responsability where responsability_notice=" . $res->notice_id . " and responsability_author=author_id order by responsability_ordre asc";
         $resultat = pmb_mysql_query($requete) or die(pmb_mysql_error() . "<br />" . $requete);
         while ($auth = pmb_mysql_fetch_object($resultat)) {
             //Si c'est un 70 (individuel) alors on l'exporte
             $subfields = array();
             $attrs = array();
             if ($params["include_authorite_ids"]) {
                 $attrs["id"] = $auth->author_id;
             }
             if ($auth->author_type == "70") {
                 // Personne physique
                 //Champ = author_type + responsability_type (70 + 0 pour auteur principal = 700 !)
                 $auth_code = $auth->author_type . $auth->responsability_type;
                 $subfields["a"] = $auth->author_name;
                 $subfields["b"] = $auth->author_rejete;
                 $subfields["c"] = $auth->author_comment;
                 //Fonction
                 $subfields["4"] = $auth->responsability_fonction;
                 //Dates
                 if ($auth->author_date != "") {
                     $subfields["f"] = $auth->author_date;
                 }
                 $subfields["N"] = $auth->author_web;
                 $subfields["9"] = "id:" . $auth->author_id;
                 $this->add_field($auth_code, " 1", $subfields, "", $attrs);
             } elseif ($auth->author_type == "71" || $auth->author_type == "72") {
                 //Collectivité
                 $auth_code = $auth->author_type . $auth->responsability_type;
                 $subfields["a"] = $auth->author_name;
                 $subfields["b"] = $auth->author_subdivision;
                 $subfields["c"] = $auth->author_comment;
                 $subfields["g"] = $auth->author_rejete;
                 $subfields["d"] = $auth->author_numero;
                 //Fonction
                 $subfields["4"] = $auth->responsability_fonction;
                 //Dates
                 if ($auth->author_date != "") {
                     $subfields["f"] = $auth->author_date;
                 }
                 $lieu = $auth->author_lieu;
                 if ($auth->author_ville) {
                     if ($lieu) {
                         $lieu .= "; ";
                     }
                     $lieu .= $auth->author_ville;
                 }
                 if ($auth->author_pays) {
                     if ($lieu) {
                         $lieu .= "; ";
                     }
                     $lieu .= $auth->author_pays;
                 }
                 $subfields["e"] = $lieu;
                 $subfields["K"] = $auth->author_lieu;
                 $subfields["L"] = $auth->author_ville;
                 $subfields["M"] = $auth->author_pays;
                 $subfields["N"] = $auth->author_web;
                 $subfields["9"] = "id:" . $auth->author_id;
                 if ($auth->author_type == "71") {
                     $auth_code = $auth->author_type . $auth->responsability_type;
                     $this->add_field($auth_code, "02", $subfields, "", $attrs);
                 } elseif ($auth->author_type == "72") {
                     $auth_code = "71" . $auth->responsability_type;
                     $this->add_field($auth_code, "12", $subfields, "", $attrs);
                 }
             }
         }
         //Editeurs et date de la notice
         $c102_export = false;
         //Le champ 102 n'est pas répétable
         $requete = "select * from publishers where ed_id =" . $res->ed1_id;
         $resultat = pmb_mysql_query($requete);
         $subfields = array();
         $attrs = array();
         if ($params["include_authorite_ids"]) {
             $attrs["id"] = $res->ed1_id;
         }
         if ($ed1 = pmb_mysql_fetch_object($resultat)) {
             $subfields["a"] = $ed1->ed_ville;
             $subfields["b"] = trim($ed1->ed_adr1 . "\n" . $ed1->ed_adr2 . "\n" . $ed1->ed_cp . "\n" . $ed1->ed_ville . "\n" . $ed1->ed_pays);
             $subfields["c"] = $ed1->ed_name;
             $subfields["d"] = $res->year;
             $subfields["z"] = $ed1->ed_pays;
             if (trim($ed1->ed_pays)) {
                 $parser = new XMLlist("{$include_path}/marc_tables/{$lang}/country.xml");
                 $parser->analyser();
                 if ($tmp = array_search(trim($ed1->ed_pays), $parser->table)) {
                     $subfields_102 = array();
                     $subfields_102["a"] = mb_strtolower($tmp);
                     $this->add_field("102", "  ", $subfields_102);
                     $c102_export = true;
                 }
             }
             $subfields["9"][] = "id:" . $ed1->ed_id;
             if (trim($ed1->ed_web)) {
                 $subfields["9"][] = "web:" . $ed1->ed_web;
             }
             if (trim($ed1->ed_comment)) {
                 $subfields["9"][] = "comment:" . $ed1->ed_comment;
             }
             if (trim($ed1->ed_cp)) {
                 $subfields["9"][] = "cp:" . $ed1->ed_cp;
             }
             if (trim($ed1->ed_adr1)) {
                 $subfields["9"][] = "adr1:" . $ed1->ed_adr1;
             }
             if (trim($ed1->ed_adr2)) {
                 $subfields["9"][] = "adr2:" . $ed1->ed_adr2;
             }
         } elseif ($res->year && $res->niveau_biblio != 'b') {
             $subfields["d"] = $res->year;
         }
         $this->add_field("210", "  ", $subfields, "", $attrs);
         $requete = "select * from publishers where ed_id =" . $res->ed2_id;
         $resultat = pmb_mysql_query($requete);
         $subfields = array();
         $attrs = array();
         if ($params["include_authorite_ids"]) {
             $attrs["id"] = $res->ed2_id;
         }
         if ($ed1 = pmb_mysql_fetch_object($resultat)) {
             $subfields["a"] = $ed1->ed_ville;
             $subfields["b"] = trim($ed1->ed_adr1 . "\n" . $ed1->ed_adr2 . "\n" . $ed1->ed_cp . "\n" . $ed1->ed_ville . "\n" . $ed1->ed_pays);
             $subfields["c"] = $ed1->ed_name;
             $subfields["d"] = $res->year;
             $subfields["z"] = $ed1->ed_pays;
             if (trim($ed1->ed_pays) && !$c102_export) {
                 $parser = new XMLlist("{$include_path}/marc_tables/{$lang}/country.xml");
                 $parser->analyser();
                 if ($tmp = array_search(trim($ed1->ed_pays), $parser->table)) {
                     $subfields_102 = array();
                     $subfields_102["a"] = mb_strtolower($tmp);
                     $this->add_field("102", "  ", $subfields_102);
                 }
             }
             $subfields["9"][] = "id:" . $ed1->ed_id;
             if (trim($ed1->ed_web)) {
                 $subfields["9"][] = "web:" . $ed1->ed_web;
             }
             if (trim($ed1->ed_comment)) {
                 $subfields["9"][] = "comment:" . $ed1->ed_comment;
             }
             if (trim($ed1->ed_cp)) {
                 $subfields["9"][] = "cp:" . $ed1->ed_cp;
             }
             if (trim($ed1->ed_adr1)) {
                 $subfields["9"][] = "adr1:" . $ed1->ed_adr1;
             }
             if (trim($ed1->ed_adr2)) {
                 $subfields["9"][] = "adr2:" . $ed1->ed_adr2;
             }
         }
         $this->add_field("210", "  ", $subfields, "", $attrs);
         //Collections
         $requete = "select * from collections where collection_id=" . $res->coll_id;
         $resultat = pmb_mysql_query($requete);
         $subfields = array();
         $subfields_410 = array();
         $subfields_411 = array();
         $subfields_s = array();
         $attrs = array();
         if ($params["include_authorite_ids"]) {
             $attrs["id"] = $res->coll_id;
         }
         if ($col = pmb_mysql_fetch_object($resultat)) {
             $subfields["a"] = $col->collection_name;
             $subfields_410["t"] = $col->collection_name;
             $subfields["v"] = $res->nocoll;
             $subfields_410["v"] = $res->nocoll;
             $subfields["x"] = $col->collection_issn;
             $subfields_410["x"] = $col->collection_issn;
             $subfields["9"] = "id:" . $res->coll_id;
             $subfields_410["9"] = "id:" . $res->coll_id;
         }
         //Recherche des sous collections
         $requete = "select * from sub_collections where sub_coll_id=" . $res->subcoll_id;
         $resultat = pmb_mysql_query($requete);
         if ($subcol = pmb_mysql_fetch_object($resultat)) {
             $subfields_s["i"] = $subcol->sub_coll_name;
             $subfields_411["t"] = $subcol->sub_coll_name;
             $subfields_s["x"] = $subcol->sub_coll_issn;
             $subfields_411["x"] = $subcol->sub_coll_issn;
             $subfields_s["9"] = "id:" . $res->subcoll_id;
             $subfields_411["9"] = "id:" . $res->subcoll_id;
         }
         $attrs2 = array();
         if ($params["include_authorite_ids"]) {
             $attrs2["id"] = $res->subcoll_id;
         }
         $this->add_field("225", "2 ", $subfields, "", $attrs);
         $this->add_field("410", " 0", $subfields_410, "", $attrs);
         $this->add_field("225", "2 ", $subfields_s, "", $attrs2);
         $this->add_field("411", " 0", $subfields_411, "", $attrs2);
         $requete = "select * from series where serie_id=" . $res->tparent_id;
         $resultat = pmb_mysql_query($requete);
         $subfields = array();
         $attrs = array();
         if ($serie = pmb_mysql_fetch_object($resultat)) {
             $subfields["t"] = $serie->serie_name;
             $subfields["v"] = $res->tnvol;
             if ($params["include_authorite_ids"]) {
                 $attrs["id"] = $serie->serie_id;
             }
         }
         $this->add_field("461", " 0", $subfields, '', $attrs);
         //dewey
         $subfields = array();
         //Recher du code dewey
         $requete = "select * from indexint where indexint_id=" . $res->indexint;
         $resultat = pmb_mysql_query($requete);
         if ($code_dewey = pmb_mysql_fetch_object($resultat)) {
             $subfields["a"] = $code_dewey->indexint_name;
             $subfields["l"] = $code_dewey->indexint_comment;
             $subfields["9"] = "id:" . $code_dewey->indexint_id;
             $this->add_field("676", "  ", $subfields);
         }
         //Vignette
         if ($opac_show_book_pics) {
             $vignette = get_vignette($this->notice_list[$this->current_notice]);
             if ($vignette) {
                 $this->add_field("896", "  ", array("a" => $vignette));
             }
         }
         if ($keep_expl) {
             if ($res->niveau_biblio == 'b' && $res->niveau_hierar == '2') {
                 //Si c'est une notice de bulletin
                 $requete = "SELECT bulletin_id FROM bulletins WHERE num_notice='" . $res->notice_id . "'";
                 $res_bull = pmb_mysql_query($requete);
                 if (pmb_mysql_num_rows($res_bull)) {
                     $id_bull = pmb_mysql_result($res_bull, 0, 0);
                     if (array_search($id_bull, $this->bulletins_exporte) === false && array_search($id_bull, $this->expl_bulletin_a_exporter) === false) {
                         //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                         $this->expl_bulletin_a_exporter[] = $id_bull;
                     }
                 }
             } else {
                 //Si non
                 //Traitement des exemplaires
                 $this->processing_expl($lender, $td, $sd, $params, $res->notice_id, 0);
             }
         }
         //Mots cles
         $subfields = array();
         $subfields["a"] = $res->index_l;
         $this->add_field("610", "0 ", $subfields);
         //Descripteurs
         $requete = "SELECT libelle_categorie,categories.num_noeud,categories.langue,categories.num_thesaurus FROM categories, notices_categories WHERE notcateg_notice=" . $res->notice_id . " and categories.num_noeud = notices_categories.num_noeud ORDER BY ordre_categorie";
         $resultat = pmb_mysql_query($requete);
         if (pmb_mysql_num_rows($resultat)) {
             for ($i = 0; $i < pmb_mysql_num_rows($resultat); $i++) {
                 $subfields = array();
                 $subfields["9"][] = "id:" . pmb_mysql_result($resultat, $i, 1);
                 $subfields["9"][] = "lang:" . pmb_mysql_result($resultat, $i, 2);
                 $subfields["9"][] = "idthes:" . pmb_mysql_result($resultat, $i, 3);
                 $subfields["a"] = pmb_mysql_result($resultat, $i, 0);
                 $this->add_field("606", " 1", $subfields);
             }
         }
         //Champs perso de notice traite par la table notice_custom
         $this->processing_cp("notices", $res->notice_id);
         //Notices liées, relations entre notices
         if ($params["genere_lien"]) {
             //On choisit d'exporter les notices mères
             if ($params["mere"]) {
                 $requete = "SELECT num_notice, linked_notice, relation_type, rank from notices_relations where num_notice=" . $res->notice_id . " order by num_notice, rank asc";
                 $resultat = pmb_mysql_query($requete);
                 while ($notice_fille = pmb_mysql_fetch_object($resultat)) {
                     $requete_mere = "SELECT * FROM notices WHERE notice_id=" . $notice_fille->linked_notice;
                     $resultat_mere = pmb_mysql_query($requete_mere);
                     while ($notice_mere = pmb_mysql_fetch_object($resultat_mere)) {
                         $subfields = array();
                         $list_titre = array();
                         $list_auteurs = array();
                         $list_options = array();
                         //On recopie les informations de la notice fille
                         if ($params["notice_mere"]) {
                             $subfields["0"] = $notice_mere->notice_id;
                         }
                         $list_titre[] = $notice_mere->tit1 ? $notice_mere->tit1 : " ";
                         //auteur
                         $rqt_aut = "select author_name, author_rejete from responsability join authors on author_id = responsability_author and responsability_notice=" . $notice_mere->notice_id . " where responsability_type != 2 order by responsability_type,responsability_ordre";
                         $res_aut = pmb_mysql_query($rqt_aut);
                         $mere_aut = array();
                         while ($mere_aut = pmb_mysql_fetch_object($res_aut)) {
                             $list_auteurs[] = $mere_aut->author_name . ($mere_aut->author_rejete ? ", " . $mere_aut->author_rejete : "");
                         }
                         $list_options[] = "bl:" . $notice_mere->niveau_biblio . $notice_mere->niveau_hierar;
                         $list_options[] = "id:" . $notice_mere->notice_id;
                         if ($notice_fille->rank) {
                             $list_options[] = "rank:" . $notice_fille->rank;
                         }
                         if ($notice_fille->relation_type) {
                             $list_options[] = "type_lnk:" . $notice_fille->relation_type;
                         }
                         $list_options[] = 'lnk:parent';
                         $subfields["9"] = $list_options;
                         //Relation avec mono = ISBN
                         if ($notice_mere->niveau_biblio == 'm' && $notice_mere->niveau_hierar == '0') {
                             if ($notice_mere->code) {
                                 $subfields["y"] = $notice_mere->code;
                             }
                             $subfields["t"] = $list_titre;
                             $subfields["a"] = $list_auteurs;
                         }
                         //Relation avec pério = ISSN
                         if ($notice_mere->niveau_biblio == 's' && $notice_mere->niveau_hierar == '1') {
                             if ($notice_mere->code) {
                                 $subfields["x"] = $notice_mere->code;
                             }
                             $subfields["t"] = $list_titre;
                         }
                         //Relation avec articles
                         if ($notice_mere->niveau_biblio == 'a' && $notice_mere->niveau_hierar == '2') {
                             $req_art = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero, tit1, code from analysis join bulletins on bulletin_id=analysis_bulletin join notices on bulletin_notice=notice_id where analysis_notice=" . $notice_mere->notice_id;
                             $result_art = pmb_mysql_query($req_art);
                             while ($notice_art = pmb_mysql_fetch_object($result_art)) {
                                 $subfields["d"] = $notice_art->date_date;
                                 $subfields["e"] = $notice_art->mention_date;
                                 $subfields["v"] = $notice_art->bulletin_numero;
                                 if ($notice_art->code) {
                                     $subfields["x"] = $notice_art->code;
                                 }
                                 $list_titre[] = $notice_art->bulletin_titre ? $notice_art->bulletin_titre : " ";
                                 $list_titre[] = $notice_art->tit1 ? $notice_art->tit1 : " ";
                                 $subfields["t"] = $list_titre;
                                 if ($keep_expl && array_search($notice_art->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_art->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                                     //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                                     $this->expl_bulletin_a_exporter[] = $notice_art->bulletin_id;
                                 }
                             }
                         }
                         //Relation avec bulletins
                         if ($notice_mere->niveau_biblio == 'b' && $notice_mere->niveau_hierar == '2') {
                             $req_bull = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero, tit1, code from bulletins join notices on bulletin_notice=notice_id  WHERE num_notice=" . $notice_mere->notice_id;
                             $result_bull = pmb_mysql_query($req_bull);
                             while ($notice_bull = pmb_mysql_fetch_object($result_bull)) {
                                 $subfields["d"] = $notice_bull->date_date;
                                 $subfields["e"] = $notice_bull->mention_date;
                                 $subfields["v"] = $notice_bull->bulletin_numero;
                                 if ($notice_bull->code) {
                                     $subfields["x"] = $notice_bull->code;
                                 }
                                 $list_titre[] = $notice_bull->bulletin_titre ? $notice_bull->bulletin_titre : " ";
                                 $list_titre[] = $notice_bull->tit1 ? $notice_bull->tit1 : " ";
                                 $subfields["t"] = $list_titre;
                                 if ($keep_expl && array_search($notice_bull->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_bull->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                                     //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                                     $this->expl_bulletin_a_exporter[] = $notice_bull->bulletin_id;
                                 }
                             }
                         }
                         $list_attribut = new XMLlist("{$include_path}/marc_tables/{$lang}/relationtypeup_unimarc.xml");
                         $list_attribut->analyser();
                         $table_attribut = $list_attribut->table;
                         //On teste si la relation est spéciale, de type contient dans une boite
                         if ($notice_fille->relation_type == 'd') {
                             $indicateur = "d0";
                         } else {
                             $indicateur = "  ";
                         }
                         $this->add_field($table_attribut[$notice_fille->relation_type], $indicateur, $subfields);
                         //On exporte les notices mères liées
                         if ($params["notice_mere"] && array_search($notice_mere->notice_id, $this->notice_exporte) === false) {
                             $this->notice_list[] = $notice_mere->notice_id;
                         }
                     }
                 }
             }
             //On choisit d'exporter les notices filles
             if ($params["fille"]) {
                 $requete = "SELECT num_notice, linked_notice, relation_type, rank from notices_relations where linked_notice=" . $res->notice_id . " order by num_notice, rank asc";
                 $resultat = pmb_mysql_query($requete);
                 while ($notice_mere = pmb_mysql_fetch_object($resultat)) {
                     $requete_fille = "SELECT * FROM notices WHERE notice_id=" . $notice_mere->num_notice;
                     $resultat_fille = pmb_mysql_query($requete_fille);
                     while ($notice_fille = pmb_mysql_fetch_object($resultat_fille)) {
                         $subfields = array();
                         $list_titre = array();
                         $list_options = array();
                         //On recopie les informations de la notice fille
                         if ($params["notice_fille"]) {
                             $subfields["0"] = $notice_fille->notice_id;
                         }
                         $list_titre[] = $notice_fille->tit1 ? $notice_fille->tit1 : " ";
                         $list_options[] = "bl:" . $notice_fille->niveau_biblio . $notice_fille->niveau_hierar;
                         $list_options[] = "id:" . $notice_fille->notice_id;
                         if ($notice_mere->rank) {
                             $list_options[] = "rank:" . $notice_mere->rank;
                         }
                         if ($notice_mere->relation_type) {
                             $list_options[] = "type_lnk:" . $notice_mere->relation_type;
                         }
                         $list_options[] = 'lnk:child';
                         $subfields["9"] = $list_options;
                         //Relation avec mono = ISBN
                         if ($notice_fille->niveau_biblio == 'm' && $notice_fille->niveau_hierar == '0') {
                             if ($notice_fille->code) {
                                 $subfields["y"] = $notice_fille->code;
                             }
                             $subfields["t"] = $list_titre;
                         }
                         //Relation avec pério = ISSN
                         if ($notice_fille->niveau_biblio == 's' && $notice_fille->niveau_hierar == '1') {
                             if ($notice_fille->code) {
                                 $subfields["x"] = $notice_fille->code;
                             }
                             $subfields["t"] = $list_titre;
                         }
                         //Relation avec articles
                         if ($notice_fille->niveau_biblio == 'a' && $notice_fille->niveau_hierar == '2') {
                             $req_art = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero, tit1, code from analysis join bulletins on bulletin_id=analysis_bulletin join notices on bulletin_notice=notice_id where analysis_notice=" . $notice_fille->notice_id;
                             $result_art = pmb_mysql_query($req_art);
                             while ($notice_art = pmb_mysql_fetch_object($result_art)) {
                                 $subfields["d"] = $notice_art->date_date;
                                 $subfields["e"] = $notice_art->mention_date;
                                 $subfields["v"] = $notice_art->bulletin_numero;
                                 if ($notice_art->code) {
                                     $subfields["x"] = $notice_art->code;
                                 }
                                 $list_titre[] = $notice_art->bulletin_titre ? $notice_art->bulletin_titre : " ";
                                 $list_titre[] = $notice_art->tit1 ? $notice_art->tit1 : " ";
                                 $subfields["t"] = $list_titre;
                                 if ($keep_expl && array_search($notice_art->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_art->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                                     //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                                     $this->expl_bulletin_a_exporter[] = $notice_art->bulletin_id;
                                 }
                             }
                         }
                         //Relation avec bulletins
                         if ($notice_fille->niveau_biblio == 'b' && $notice_fille->niveau_hierar == '2') {
                             $req_bull = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero, tit1, code from bulletins join notices on bulletin_notice=notice_id  WHERE num_notice=" . $notice_fille->notice_id;
                             $result_bull = pmb_mysql_query($req_bull);
                             while ($notice_bull = pmb_mysql_fetch_object($result_bull)) {
                                 $subfields["d"] = $notice_bull->date_date;
                                 $subfields["e"] = $notice_bull->mention_date;
                                 $subfields["v"] = $notice_bull->bulletin_numero;
                                 if ($notice_bull->code) {
                                     $subfields["x"] = $notice_bull->code;
                                 }
                                 $list_titre[] = $notice_bull->bulletin_titre ? $notice_bull->bulletin_titre : " ";
                                 $list_titre[] = $notice_bull->tit1 ? $notice_bull->tit1 : " ";
                                 $subfields["t"] = $list_titre;
                                 if ($keep_expl && array_search($notice_bull->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_bull->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                                     //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                                     $this->expl_bulletin_a_exporter[] = $notice_bull->bulletin_id;
                                 }
                             }
                         }
                         $list_attribut = new XMLlist("{$include_path}/marc_tables/{$lang}/relationtypedown_unimarc.xml");
                         $list_attribut->analyser();
                         $table_attribut = $list_attribut->table;
                         //On teste si la relation est spéciale, de type contient dans une boite
                         if ($notice_fille->relation_type == 'd') {
                             $indicateur = "d0";
                         } else {
                             $indicateur = "  ";
                         }
                         $this->add_field($table_attribut[$notice_mere->relation_type], $indicateur, $subfields);
                         //On exporte les notices filles liées
                         if ($params["notice_fille"] && array_search($notice_fille->notice_id, $this->notice_exporte) === false) {
                             $this->notice_list[] = $notice_fille->notice_id;
                         }
                     }
                 }
             }
             //On choisit d'exporter les liens vers les périodiques pour les notices d'article
             if ($params["perio_link"]) {
                 $req_perio_link = "SELECT notice_id, tit1, code from bulletins,analysis,notices WHERE bulletin_notice=notice_id and bulletin_id=analysis_bulletin and analysis_notice=" . $res->notice_id;
                 $result_perio_link = pmb_mysql_query($req_perio_link);
                 while ($notice_perio_link = pmb_mysql_fetch_object($result_perio_link)) {
                     $subfields_461 = array();
                     $list_options = array();
                     if ($params["notice_perio"]) {
                         $subfields_461["0"] = $notice_perio_link->notice_id;
                     }
                     $subfields_461["t"] = $notice_perio_link->tit1 ? $notice_perio_link->tit1 : " ";
                     if ($notice_perio_link->code) {
                         $subfields_461["x"] = $notice_perio_link->code;
                     }
                     $attrs = array("id" => $notice_perio_link->notice_id);
                     $list_options[] = "id:" . $notice_perio_link->notice_id;
                     $list_options[] = 'lnk:perio';
                     $subfields_461["9"] = $list_options;
                     $this->add_field("461", "  ", $subfields_461, '', $attrs);
                     //On exporte les notices de pério liées
                     if ($params["notice_perio"] && array_search($notice_perio_link->notice_id, $this->notice_exporte) === false) {
                         $this->notice_list[] = $notice_perio_link->notice_id;
                     }
                 }
             }
             //On génère le bulletinage pour les notices de pério
             if ($params["bulletinage"]) {
                 $req_bulletinage = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero from bulletins, notices WHERE bulletin_notice = notice_id AND notice_id=" . $res->notice_id;
                 $result_bulletinage = pmb_mysql_query($req_bulletinage);
                 while ($notice_bulletinage = pmb_mysql_fetch_object($result_bulletinage)) {
                     $subfields_462 = array();
                     $list_options = array();
                     $attrs = array("id" => $notice_bulletinage->bulletin_id);
                     $subfields_462["d"] = $notice_bulletinage->date_date;
                     $subfields_462["e"] = $notice_bulletinage->mention_date;
                     $subfields_462["v"] = $notice_bulletinage->bulletin_numero;
                     $subfields_462["t"] = $notice_bulletinage->bulletin_titre ? $notice_bulletinage->bulletin_titre : " ";
                     $list_options[] = "id:" . $notice_bulletinage->bulletin_id;
                     $list_options[] = 'lnk:bull';
                     $subfields_462["9"] = $list_options;
                     $this->add_field("462", "  ", $subfields_462, '', $attrs);
                     if ($keep_expl && array_search($notice_bulletinage->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_bulletinage->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                         //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                         $this->expl_bulletin_a_exporter[] = $notice_bulletinage->bulletin_id;
                     }
                 }
             }
             //On choisit d'exporter les liens vers les bulletins pour les notices d'article
             if ($params["bull_link"]) {
                 $req_bull_link = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, bulletin_numero from bulletins, analysis WHERE bulletin_id=analysis_bulletin and analysis_notice=" . $res->notice_id;
                 $result_bull_link = pmb_mysql_query($req_bull_link);
                 while ($notice_bull_link = pmb_mysql_fetch_object($result_bull_link)) {
                     $subfields_463 = array();
                     $list_options = array();
                     $attrs = array("id" => $notice_bull_link->bulletin_id);
                     $subfields_463["d"] = $notice_bull_link->date_date;
                     $subfields_463["e"] = $notice_bull_link->mention_date;
                     $subfields_463["v"] = $notice_bull_link->bulletin_numero;
                     $subfields_463["t"] = $notice_bull_link->bulletin_titre ? $notice_bull_link->bulletin_titre : " ";
                     $list_options[] = "id:" . $notice_bull_link->bulletin_id;
                     $list_options[] = 'lnk:bull';
                     $subfields_463["9"] = $list_options;
                     $this->add_field("463", "  ", $subfields_463, '', $attrs);
                     if ($keep_expl && array_search($notice_bull_link->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_bull_link->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                         //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                         $this->expl_bulletin_a_exporter[] = $notice_bull_link->bulletin_id;
                     }
                 }
             }
             //On choisit d'exporter les liens vers les articles pour les notices de pério
             if ($params["art_link"]) {
                 $req_art_link = "SELECT bulletin_id, bulletin_numero, date_date, mention_date, bulletin_titre, analysis_notice, a.tit1 as titre, a.npages as page from notices p left join bulletins on bulletin_notice=p.notice_id left join analysis on analysis_bulletin=bulletin_id join notices a on a.notice_id=analysis_notice WHERE p.notice_id=" . $res->notice_id;
                 $result_art_link = pmb_mysql_query($req_art_link);
                 while ($notice_art_link = pmb_mysql_fetch_object($result_art_link)) {
                     $subfields_464 = array();
                     $tab_titre = array();
                     $list_options = array();
                     $attrs = array("id" => $notice_art_link->analysis_notice);
                     $tab_titre[] = $notice_art_link->titre ? $notice_art_link->titre : " ";
                     $tab_titre[] = $notice_art_link->bulletin_titre ? $notice_art_link->bulletin_titre : " ";
                     if ($params["notice_art"]) {
                         $subfields_464["0"] = $notice_art_link->analysis_notice;
                     }
                     $subfields_464["t"] = $tab_titre;
                     $subfields_464["d"] = $notice_art_link->date_date;
                     $subfields_464["e"] = $notice_art_link->mention_date;
                     $subfields_464["v"] = $notice_art_link->bulletin_numero;
                     $list_options[] = "id:" . $notice_art_link->analysis_notice;
                     $list_options[] = "page:" . $notice_art_link->page;
                     $list_options[] = 'lnk:art';
                     $subfields_464["9"] = $list_options;
                     $this->add_field("464", "  ", $subfields_464, '', $attrs);
                     if ($keep_expl && array_search($notice_art_link->bulletin_id, $this->bulletins_exporte) === false && array_search($notice_art_link->bulletin_id, $this->expl_bulletin_a_exporter) === false) {
                         //Si on exporte les exemplaires on garde l'ID du bulletin pour exporter ses exemplaires
                         $this->expl_bulletin_a_exporter[] = $notice_art_link->bulletin_id;
                     }
                     //On exporte les notices d'articles liées
                     if ($params["notice_art"] && array_search($notice_art_link->analysis_notice, $this->notice_exporte) === false) {
                         $this->notice_list[] = $notice_art_link->analysis_notice;
                     }
                 }
             }
         }
         //Etat de collection
         if ($res->niveau_biblio == 's' && $res->niveau_hierar == '1') {
             $req = "SELECT collections_state.*, archempla_libelle, archtype_libelle, archstatut_opac_libelle, archstatut_gestion_libelle, location_libelle FROM collections_state " . "LEFT JOIN arch_emplacement ON archempla_id=collstate_emplacement " . "LEFT JOIN arch_type ON archtype_id=collstate_type " . "LEFT JOIN arch_statut ON archstatut_id=collstate_statut " . "LEFT JOIN docs_location ON idlocation=location_id " . "WHERE id_serial='" . $res->notice_id . "'";
             $res_etat = pmb_mysql_query($req);
             if ($res_etat && pmb_mysql_num_rows($res_etat)) {
                 while ($etat = pmb_mysql_fetch_object($res_etat)) {
                     $subfields = array();
                     $attrs = array();
                     $subfields["9"] = "id:" . $etat->collstate_id;
                     $subfields["a"] = $etat->location_libelle;
                     $subfields["b"] = $etat->state_collections;
                     $subfields["c"] = $etat->archempla_libelle;
                     $subfields["d"] = $etat->archtype_libelle;
                     $subfields["e"] = $etat->collstate_origine;
                     $subfields["f"] = $etat->collstate_cote;
                     $subfields["g"] = $etat->collstate_archive;
                     $subfields["h"] = $etat->archstatut_opac_libelle;
                     $subfields["i"] = $etat->collstate_lacune;
                     $subfields["j"] = $etat->collstate_note;
                     $subfields["k"] = $etat->archstatut_gestion_libelle;
                     $this->add_field("950", "  ", $subfields, "", $attrs);
                     //Export des cp d'etat de collection
                     $this->processing_cp("collstate", $etat->collstate_id, $etat->collstate_id);
                 }
             }
         }
         //Documents numeriques
         if ($params['docnum']) {
             // recuperation des documents numeriques
             $q = "select explnum_id from explnum where explnum_notice='" . $res->notice_id . "' ";
             $q .= "union ";
             $q .= "select explnum_id from explnum, bulletins where bulletin_id = explnum_bulletin and bulletins.num_notice='" . $res->notice_id . "' ";
             $r = pmb_mysql_query($q, $dbh);
             if (pmb_mysql_num_rows($r)) {
                 while ($row = pmb_mysql_fetch_object($r)) {
                     $subfields_897 = array();
                     $dn = new explnum($row->explnum_id);
                     if ($dn->isURL()) {
                         //URL
                         $subfields_897['a'] = $dn->explnum_url;
                         $subfields_897['b'] = $dn->explnum_nom;
                         $subfields_897['f'] = '';
                         $subfields_897['p'] = '';
                     } elseif ($dn->isEnUpload() && $params['docnum_rep']) {
                         //Répertoire
                         $dest_file = $dn->copy_to($params['docnum_rep'], true);
                         if ($dest_file) {
                             $subfields_897['a'] = $dest_file;
                             $subfields_897['b'] = $dn->explnum_nom ? $dn->explnum_nom : $dn->explnum_nomfichier;
                             $subfields_897['f'] = $dn->explnum_nomfichier;
                             $subfields_897['p'] = '';
                         }
                     } elseif ($dn->isEnBase() && $params['docnum_rep']) {
                         //Base
                         $dest_file = $dn->copy_to($params['docnum_rep'], true);
                         if ($dest_file) {
                             $subfields_897['a'] = $dest_file;
                             $subfields_897['b'] = $dn->explnum_nom ? $dn->explnum_nom : $dn->explnum_nomfichier;
                             $subfields_897['f'] = $dn->explnum_nomfichier;
                             $subfields_897['p'] = '';
                         }
                     }
                     if (count($subfields_897)) {
                         $this->add_field('897', '  ', $subfields_897);
                     }
                 }
             }
         }
         //Record field
         $biblio = $res->niveau_biblio;
         $hierar = $res->niveau_hierar;
         if ($biblio == 'b' && $hierar == '2') {
             //si on a un bulletin on modifie b2 en s2
             $biblio = 's';
             $hierar = '2';
         }
         $this->xml_array['rs']['value'] = "n";
         $this->xml_array['dt']['value'] = $res->typdoc;
         $this->xml_array['bl']['value'] = $biblio;
         $this->xml_array['hl']['value'] = $hierar;
         $this->xml_array['el']['value'] = 1;
         $this->xml_array['ru']['value'] = "i";
         if (array_search($res->notice_id, $this->notice_exporte) === false) {
             $this->notice_exporte[] = $res->notice_id;
         }
         $this->toxml();
         $this->current_notice++;
         if ($this->current_notice >= count($this->notice_list)) {
             $this->current_notice = -1;
         }
         return true;
     } else {
         return false;
     }
 }