Example #1
0
         /* the notice is new, we are going to import it... */
         if ($new_notice == 1) {
             import_new_notice();
             if ($link_generate) {
                 import_notice_link();
             }
             import_new_notice_suite();
             // Mise à jour de la table "notices_global_index"
             notice::majNoticesGlobalIndex($notice_id);
             // Mise à jour de la table "notices_mots_global_index"
             notice::majNoticesMotsGlobalIndex($notice_id);
         } else {
             $notice_deja_presente++;
             //TRAITEMENT DES DOCS NUMERIQUES SUR NOTICE EXISTANTE
             if ($add_explnum === TRUE) {
                 ajoute_explnum();
             }
         }
         // TRAITEMENT DES EXEMPLAIRES ICI
         if ($sub == "import_expl") {
             traite_exemplaires();
         }
         // fin if $sub=import_expl
     }
     /* this has been succesfuly read, it can be deleted */
     $sql_del = "delete from import_marc where id_import = '" . $idnotice_import . "' ";
     $sql_result_del = pmb_mysql_query($sql_del) or die("Couldn't delete import_marc {$idnotice_import} !");
 }
 /* end while records in import table */
 $sql = "select count(1) as reste from import_marc where origine='" . addslashes(SESSid) . "'";
 $sql_result = pmb_mysql_query($sql) or die("Couldn't select count import table !");
 function import_basic($notices, $params = array(), $with_expl = false)
 {
     global $base_path, $class_path, $include_path, $dbh, $msg, $charset;
     global $deflt_integration_notice_statut, $deflt_lenders, $deflt_docs_statut, $deflt_docs_location;
     $log = array();
     //On contrôle tous les paramètres obligatoires
     if (!$params["func_import"]) {
         $params["func_import"] = "func_bdp.inc.php";
         //Function d'import à utiliser
     }
     if (file_exists($base_path . "/admin/import/" . $params["func_import"])) {
         require_once $base_path . "/admin/import/" . $params["func_import"];
     } else {
         require_once $base_path . "/admin/import/func_bdp.inc.php";
     }
     //Notices
     if (!isset($params["isbn_mandatory"])) {
         $params["isbn_mandatory"] = "0";
     }
     //ISBN obligatoire ?
     if (!isset($params["isbn_dedoublonnage"])) {
         $params["isbn_dedoublonnage"] = "1";
     }
     //Dédoublonnage sur ISBN ?
     if (!isset($params["isbn_only"])) {
         $params["isbn_only"] = "0";
     }
     //Que les ISBN
     if (!isset($params["statutnot"])) {
         $params["statutnot"] = $deflt_integration_notice_statut;
     }
     //Statut des notices importées  -> On met la valeur du paramètre utilisateur "Statut de notice par défaut en intégration de notice"
     if (!isset($params["link_generate"])) {
         $params["link_generate"] = "0";
     }
     //Générer les liens entre notices ?
     if (!isset($params["authorities_notices"])) {
         $params["authorities_notices"] = "0";
     }
     //Tenir compte des notices d'autorités
     if (!isset($params["authorities_default_origin"])) {
         $params["authorities_default_origin"] = "";
     }
     //Origine par défaut des autorités si non précisé dans les notices
     //Exemplaires
     if ($with_expl) {
         if (!isset($params["book_lender_id"])) {
             $params["book_lender_id"] = $deflt_lenders;
         }
         //Propriétaire  -> On met la valeur du paramètre utilisateur "Propriétaire par défaut en création d'exemplaire"
         if (!isset($params["book_statut_id"])) {
             $params["book_statut_id"] = $deflt_docs_statut;
         }
         //Statut  -> On met la valeur du paramètre utilisateur "Statut de document par défaut en création d'exemplaire"
         if (!isset($params["book_location_id"])) {
             $params["book_location_id"] = $deflt_docs_location;
         }
         //Localisation  -> On met la valeur du paramètre utilisateur "Localisation du document par défaut en création d'exemplaire"
         if (!isset($params["cote_mandatory"])) {
             $params["cote_mandatory"] = "0";
         }
         //Cote obligatoire ?
         if (!isset($params["tdoc_codage"])) {
             $params["tdoc_codage"] = "0";
         }
         //Types de document Codage du propriétaire ?
         if (!isset($params["statisdoc_codage"])) {
             $params["statisdoc_codage"] = "0";
         }
         //Codes statistiques Codage du propriétaire ?
         if (!isset($params["sdoc_codage"])) {
             $params["sdoc_codage"] = "0";
         }
         //Sections Codage du propriétaire ?
     }
     //Find de contrôle des paramètres obligatoires
     //On rend global tous les paramètres passés (et pas forcément que les obligatoires) pour la suite
     foreach ($params as $key => $value) {
         global ${$key};
         ${$key} = $value;
     }
     if (count($notices)) {
         ob_start();
         //On temporise toutes les sorties (dans le cas ou dans la fonction d'import on fait des sorties écrans directement)
         $nbtot_notice = count($notices);
         $notice_deja_presente = 0;
         $notice_rejetee = 0;
         global $notices_crees, $notices_a_creer, $bulletins_crees, $bulletins_a_creer;
         $notices_crees = $notices_a_creer = $bulletins_crees = $bulletins_a_creer = array();
         if ($with_expl) {
             global $section_995, $typdoc_995, $codstatdoc_995, $nb_expl_ignores;
             $section_995_ = new marc_list("section_995");
             $section_995 = $section_995_->table;
             $typdoc_995_ = new marc_list("typdoc_995");
             $typdoc_995 = $typdoc_995_->table;
             $codstatdoc_995_ = new marc_list("codstatdoc_995");
             $codstatdoc_995 = $codstatdoc_995_->table;
             $nb_expl_ignores = 0;
         }
         foreach ($notices as $notice) {
             $notice = utf8_decode($notice);
             $res_lecture = recup_noticeunimarc($notice);
             if ($params["link_generate"]) {
                 recup_noticeunimarc_link($notice);
             }
             global $tit_200a;
             if (!$res_lecture || !$tit_200a[0]) {
                 $res_lecture = 0;
                 $fp = fopen($base_path . "/temp/err_import.unimarc", "a+");
                 fwrite($fp, $notice);
                 fclose($fp);
                 $notice_rejetee++;
             } else {
                 recup_noticeunimarc_suite($notice);
                 global $isbn, $EAN, $issn_011, $collection_225, $collection_410, $code, $code10, $isbn_OK, $notice_id;
                 if ($isbn[0] == "NULL") {
                     $isbn[0] = "";
                 }
                 // si isbn vide, on va tenter de prendre l'EAN stocké en 345$b
                 if ($isbn[0] == "") {
                     $isbn[0] = $EAN[0];
                 }
                 // si isbn vide, on va tenter de prendre le serial en 011
                 if ($isbn[0] == "") {
                     $isbn[0] = $issn_011[0];
                 }
                 // si ISBN obligatoire et isbn toujours vide :
                 if ($params["isbn_mandatory"] == 1 && $isbn[0] == "") {
                     // on va tenter de prendre l'ISSN stocké en 225$x
                     $isbn[0] = $collection_225[0]['x'];
                     // si isbn toujours vide, on va tenter de prendre l'ISSN stocké en 410$x
                     if ($isbn[0] == "") {
                         $isbn[0] = $collection_410[0]['x'];
                     }
                 }
                 // on commence par voir ce que le code est (basé sur la recherche par code du module catalogage
                 $ex_query = clean_string($isbn[0]);
                 $EAN = '';
                 $isbn = '';
                 $code = '';
                 $code10 = '';
                 if (isEAN($ex_query)) {
                     // la saisie est un EAN -> on tente de le formater en ISBN
                     $EAN = $ex_query;
                     $isbn = EANtoISBN($ex_query);
                     // si échec, on prend l'EAN comme il vient
                     if (!$isbn) {
                         $code = str_replace("*", "%", $ex_query);
                     } else {
                         $code = $isbn;
                         $code10 = formatISBN($code, 10);
                     }
                 } else {
                     if (isISBN($ex_query)) {
                         // si la saisie est un ISBN
                         $isbn = formatISBN($ex_query);
                         // si échec, ISBN erroné on le prend sous cette forme
                         if (!$isbn) {
                             $code = str_replace("*", "%", $ex_query);
                         } else {
                             $code10 = $isbn;
                             $code = formatISBN($code10, 13);
                         }
                     } else {
                         // ce n'est rien de tout ça, on prend la saisie telle quelle
                         $code = str_replace("*", "%", $ex_query);
                     }
                 }
                 $isbn_OK = $code;
                 $new_notice = 0;
                 $notice_id = 0;
                 // le paramétrage est-il : dédoublonnage sur code ? / Ne dédoublonner que sur code ISBN (ignorer les ISSN) ?
                 if ($params["isbn_dedoublonnage"] && !$params["isbn_only"] || $params["isbn_dedoublonnage"] && $params["isbn_only"] && isISBN($isbn)) {
                     $trouvees = 0;
                     if ($EAN && $isbn) {
                         // cas des EAN purs : constitution de la requête
                         $requete = "SELECT distinct notice_id FROM notices ";
                         $requete .= " WHERE notices.code in ('{$code}','{$EAN}'" . ($code10 ? ",'{$code10}'" : "") . ") limit 1";
                         $myQuery = mysql_query($requete, $dbh);
                         $trouvees = mysql_num_rows($myQuery);
                     } elseif ($isbn) {
                         // recherche d'un isbn
                         $requete = "SELECT distinct notice_id FROM notices ";
                         $requete .= " WHERE notices.code in ('{$code}'" . ($code10 ? ",'{$code10}'" : "") . ") limit 1";
                         $myQuery = mysql_query($requete, $dbh);
                         $trouvees = mysql_num_rows($myQuery);
                     } elseif ($code) {
                         // note : le code est recherché dans le champ code des notices
                         // (cas des code-barres disques qui échappent à l'EAN)
                         //
                         $requete = "SELECT notice_id FROM notices ";
                         $requete .= " WHERE notices.code like '{$code}' limit 10";
                         $myQuery = mysql_query($requete, $dbh);
                         $trouvees = mysql_num_rows($myQuery);
                     }
                     // dédoublonnage sur isbn
                     if ($EAN || $isbn || $code) {
                         if ($trouvees == 0) {
                             $new_notice = 1;
                         } else {
                             $new_notice = 0;
                             $notice_id = mysql_result($myQuery, 0, "notice_id");
                             $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('import_expl_" . addslashes(SESSid) . ".inc', '" . $msg[542] . " {$EAN}  || {$isbn} || {$code} " . addslashes($tit_200a[0]) . "') ");
                         }
                     } else {
                         if ($params["isbn_mandatory"] == 1) {
                             $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . $msg[543] . "') ");
                         } else {
                             $new_notice = 1;
                             $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . $msg[565] . "') ");
                         }
                     }
                 } else {
                     // pas de dédoublonnage
                     if ($params["isbn_mandatory"] == 1 && $isbn_OK == "") {
                         $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . $msg[543] . "') ");
                     } elseif ($isbn_OK) {
                         $new_notice = 1;
                     } else {
                         $new_notice = 1;
                         $sql_log = mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . $msg[565] . "') ");
                     }
                 }
                 /* the notice is new, we are going to import it... */
                 if ($new_notice == 1) {
                     import_new_notice();
                     if ($params["link_generate"]) {
                         import_notice_link();
                     }
                     import_new_notice_suite();
                     // Mise à jour de la table "notices_global_index"
                     notice::majNoticesGlobalIndex($notice_id);
                     // Mise à jour de la table "notices_mots_global_index"
                     notice::majNoticesMotsGlobalIndex($notice_id);
                 } else {
                     $notice_deja_presente++;
                     //TRAITEMENT DES DOCS NUMERIQUES SUR NOTICE EXISTANTE
                     global $add_explnum;
                     //Fonction d'import func_ensai_ensae.inc.php
                     if ($add_explnum === TRUE && function_exists("ajoute_explnum")) {
                         ajoute_explnum();
                     }
                 }
                 // TRAITEMENT DES EXEMPLAIRES ICI
                 if ($with_expl) {
                     traite_exemplaires();
                 }
             }
         }
         //Fin du traitement des notices
         //Gestion des logs
         $formulaire = "";
         $script = "";
         $log["notice_deja_presente"] = $notice_deja_presente;
         $log["notice_rejetee"] = $notice_rejetee;
         $log["nbtot_notice"] = $nbtot_notice;
         $log["stdout"] = ob_get_contents();
         if ($charset != "utf-8") {
             $log["stdout"] = utf8_encode($log["stdout"]);
         }
         ob_end_clean();
         $gen_liste_log = "";
         $resultat_liste = mysql_query("SELECT error_origin, error_text, count(*) as nb_error FROM error_log where error_origin in ('expl_" . addslashes(SESSid) . ".class','import_expl_" . addslashes(SESSid) . ".inc','iimport_expl_" . addslashes(SESSid) . ".inc','import_" . addslashes(SESSid) . ".inc.php', 'import_" . addslashes(SESSid) . ".inc','import_func_" . addslashes(SESSid) . ".inc.php') group by error_origin, error_text", $dbh);
         $nb_liste = mysql_num_rows($resultat_liste);
         if ($nb_liste > 0) {
             $i_log = 0;
             while ($i_log < $nb_liste) {
                 $tmp = array();
                 $tmp["error_origin"] = mysql_result($resultat_liste, $i_log, "error_origin");
                 if ($charset != "utf-8") {
                     $tmp["error_origin"] = utf8_encode($tmp["error_origin"]);
                 }
                 $tmp["error_text"] = mysql_result($resultat_liste, $i_log, "error_text");
                 if ($charset != "utf-8") {
                     $tmp["error_text"] = utf8_encode($tmp["error_text"]);
                 }
                 $tmp["nb_error"] = mysql_result($resultat_liste, $i_log, "nb_error");
                 $log["error_log"][] = $tmp;
                 $i_log++;
             }
             mysql_query("DELETE FROM error_log WHERE error_origin  in ('expl_" . addslashes(SESSid) . ".class','import_expl_" . addslashes(SESSid) . ".inc','iimport_expl_" . addslashes(SESSid) . ".inc','import_" . addslashes(SESSid) . ".inc.php', 'import_" . addslashes(SESSid) . ".inc','import_func_" . addslashes(SESSid) . ".inc.php')", $dbh);
         } else {
             $log["result"] = $this->msg["import_basic_msg_ok"];
             if ($charset != "utf-8") {
                 $log["result"] = utf8_encode($log["result"]);
             }
         }
     } else {
         $log["result"] = $this->msg["import_basic_msg_ko"];
         if ($charset != "utf-8") {
             $log["result"] = utf8_encode($log["result"]);
         }
     }
     return $log;
 }