示例#1
0
function import_new_notice_suite()
{
    global $dbh;
    global $notice_id;
    global $bl, $hl;
    global $infos_4XX;
    global $hierarchic_level;
    global $bibliographic_level;
    global $doc_type;
    global $origine_notice;
    global $notices_crees;
    global $issn_011, $info_900;
    global $tit_200a;
    global $isbn;
    global $statutnot;
    global $info_003;
    global $info_336, $info_337;
    global $isbn_only, $isbn_dedoublonnage;
    if (isset($bibliographic_level) && isset($hierarchic_level)) {
        $niveau_biblio = $bibliographic_level . $hierarchic_level;
    } else {
        $niveau_biblio = $bl . $hl;
    }
    //num_notice = fille
    //linked_notice = mere
    $sens = array('mother' => array("linked_notice", "num_notice"), 'child' => array("num_notice", "linked_notice"));
    $link_type = array('412' => array('code' => "v", 'sens_link' => "child"), '413' => array('code' => "v", 'sens_link' => "mother"), '421' => array('code' => "e", 'sens_link' => "mother"), '422' => array('code' => "e", 'sens_link' => "child"), '423' => array('code' => "k", 'sens_link' => "child"), '430' => array('code' => "l", 'sens_link' => "child"), '431' => array('code' => "o", 'sens_link' => "mother"), '432' => array('code' => "t", 'sens_link' => "child"), '433' => array('code' => "o", 'sens_link' => "mother"), '434' => array('code' => "m", 'sens_link' => "child"), '435' => array('code' => "s", 'sens_link' => "child"), '436' => array('code' => "n", 'sens_link' => "mother"), '437' => array('code' => "o", 'sens_link' => "mother"), '440' => array('code' => "l", 'sens_link' => "mother"), '441' => array('code' => "o", 'sens_link' => "child"), '442' => array('code' => "t", 'sens_link' => "mother"), '443' => array('code' => "o", 'sens_link' => "child"), '444' => array('code' => "m", 'sens_link' => "mother"), '445' => array('code' => "s", 'sens_link' => "mother"), '446' => array('code' => "o", 'sens_link' => "child"), '447' => array('code' => "n", 'sens_link' => "child"), '451' => array('code' => "u", 'sens_link' => "child"), '452' => array('code' => "p", 'sens_link' => "child"), '453' => array('code' => "h", 'sens_link' => "mother"), '454' => array('code' => "h", 'sens_link' => "child"), '455' => array('code' => "q", 'sens_link' => "mother"), '456' => array('code' => "q", 'sens_link' => "child"), '520' => array('code' => "f", 'sens_link' => "child"));
    //dédoublonnage !
    if ($isbn && $isbn_dedoublonnage) {
        $query = "select notice_id from notices where code like '" . $isbn . "' and notice_id != " . $notice_id;
        $result = mysql_query($query);
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_object($result);
            notice::del_notice($notice_id);
            $notice_id = $row->notice_id;
            mysql_query("insert into error_log (error_origin, error_text) values ('import_expl_" . addslashes(SESSid) . ".inc', '" . addslashes("La notice (" . $tit_200a[0] . ", " . $isbn . ") n'a pas été reprise car elle existe déjà en base (notice id: " . $notice_id . ")") . "') ");
        }
    }
    if (!$isbn_dedoublonnage || $isbn_only == 1) {
        $rq = "UPDATE notices SET code=REPLACE(code, '_pasToucheACa', '') WHERE notice_id = " . $notice_id;
        mysql_query($rq);
    } elseif ($issn_011[0]) {
        $query = "select notice_id from notices where code like '" . $issn_011[0] . "' and notice_id != " . $notice_id;
        $result = mysql_query($query);
        if (mysql_num_rows($result)) {
            while ($row = mysql_fetch_object($result)) {
                if (in_array($row->notice_id, $notices_crees)) {
                    $old = new notice($row->notice_id);
                    $old->replace($notice_id);
                    $tab = array_flip($notices_crees);
                    unset($tab[$row->notice_id]);
                    $notices_crees = array_flip($tab);
                } else {
                    notice::del_notice($notice_id);
                    $notice_id = $row->notice_id;
                    mysql_query("insert into error_log (error_origin, error_text) values ('import_expl_" . addslashes(SESSid) . ".inc', '" . addslashes("La notice (" . $tit_200a[0] . ", " . $isbn . ") n'a pas été reprise car elle existe déjà en base (notice id: " . $notice_id . ")") . "') ");
                }
            }
        }
    }
    $n_gen_plus = "";
    if (count($info_336)) {
        foreach ($info_336 as $value) {
            if ($tmp = trim($value)) {
                if ($n_gen_plus) {
                    $n_gen_plus .= "\n";
                }
                $n_gen_plus .= $tmp;
            }
        }
    }
    if (count($info_337)) {
        foreach ($info_337 as $value) {
            if ($tmp = trim($value)) {
                if ($n_gen_plus) {
                    $n_gen_plus .= "\n";
                }
                $n_gen_plus .= $tmp;
            }
        }
    }
    if ($n_gen_plus) {
        $requ = "UPDATE notices SET n_gen=IF(n_gen != '',CONCAT(n_gen,'\n" . addslashes($n_gen_plus) . "'),'" . addslashes($n_gen_plus) . "') WHERE notice_id = " . $notice_id;
        if (!mysql_query($requ)) {
            echo "Requête echoué: " . $requ . "<br/>";
        }
    }
    switch ($niveau_biblio) {
        case "s1":
        case "s0":
            foreach ($infos_4XX as $key => $children) {
                foreach ($children as $child) {
                    $issn = "";
                    //on commence par chercher si la notice existe
                    $issn = traite_code_ISSN($child['x']);
                    if ($issn) {
                        $query = "select notice_id from notices where code ='" . $issn . "' and niveau_biblio = 's' and niveau_hierar = '1'";
                        $result = mysql_query($query);
                        if (!mysql_num_rows($result)) {
                            //la notice n'existe pas, il faut la créer...
                            /* Origine de la notice */
                            $origine_not['nom'] = clean_string($origine_notice[0]['b']);
                            $origine_not['pays'] = clean_string($origine_notice[0]['a']);
                            $orinot_id = origine_notice::import($origine_not);
                            if ($orinot_id == 0) {
                                $orinot_id = 1;
                            }
                            $query = "insert into notices set \n\t\t\t\t\t\t\t\ttypdoc = '" . $doc_type . "',\n\t\t\t\t\t\t\t\ttit1 = '" . addslashes(clean_string($child['t'])) . "',\n\t\t\t\t\t\t\t\tcode = '" . $issn . "',\n\t\t\t\t\t\t\t\tniveau_biblio = 's',\n\t\t\t\t\t\t\t\tniveau_hierar = '1',\n\t\t\t\t\t\t\t\tstatut = " . $statutnot . ",\n\t\t\t\t\t\t\t\torigine_catalogage = '" . $orinot_id . "',\n\t\t\t\t\t\t\t\tcreate_date = sysdate(),\n\t\t\t\t\t\t\t\tupdate_date = sysdate()\n\t\t\t\t\t\t\t";
                            mysql_query($query);
                            $child_id = mysql_insert_id();
                            $notices_crees[$child[0]] = $child_id;
                            notice::majNotices($child_id);
                            notice::majNoticesGlobalIndex($child_id);
                            notice::majNoticesMotsGlobalIndex($child_id);
                        } else {
                            $child_id = mysql_result($result, 0, 0);
                        }
                        if ($child_id) {
                            // on regarde si une relation similaire existe déjà...
                            $query = "select relation_type from notices_relations where relation_type = '" . $link_type[$key]['code'] . "' and ((num_notice = " . $notice_id . " and linked_notice = " . $child_id . ") or (num_notice = " . $child_id . " and linked_notice = " . $notice_id . "))";
                            $result = mysql_query($query);
                            if (!mysql_num_rows($result)) {
                                $rank = 0;
                                $query = "select count(rank) from notices_relations where relation_type = '" . $link_type[$key]['code'] . "' and ";
                                if ($link_type[$key]['sens_link'] == "mother") {
                                    $query .= "num_notice = " . $child_id;
                                } else {
                                    $query .= "num_notice = " . $notice_id;
                                }
                                $result = mysql_query($query);
                                if (mysql_num_rows($result)) {
                                    $rank = mysql_result($result, 0, 0);
                                }
                                $query = "insert into notices_relations set \n\t\t\t\t\t\t\t\t\t" . $sens[$link_type[$key]['sens_link']][0] . " = " . $notice_id . ",\n\t\t\t\t\t\t\t\t\t" . $sens[$link_type[$key]['sens_link']][1] . " = " . $child_id . ",\n\t\t\t\t\t\t\t\t\trelation_type = '" . $link_type[$key]['code'] . "',\n\t\t\t\t\t\t\t\t\trank = " . ($rank + 1) . "\n\t\t\t\t\t\t\t\t";
                                mysql_query($query);
                            }
                        }
                    }
                }
            }
            break;
    }
    if (count($info_900)) {
        for ($i = 0; $i < count($info_900); $i++) {
            if (trim($info_900[$i]["a"])) {
                if (!renseigne_cp_agro($info_900[$i], $notice_id)) {
                    mysql_query("insert into error_log (error_origin, error_text) values ('import_expl_" . addslashes(SESSid) . ".inc', '" . addslashes("La valeur  : " . $info_900[$i]["a"] . " n'a pas été reprise dans le champ personnalisé : " . $info_900[$i]["n"] . " car le champ n'existe pas ou n'est pas défini de la même façon") . "') ");
                }
            }
        }
    }
    if ($tmp = trim($info_003[0])) {
        $requete = "SELECT notices_custom_origine FROM notices_custom_values WHERE notices_custom_champ=22 AND notices_custom_origine='" . $notice_id . "' AND notices_custom_small_text='" . addslashes($tmp) . "' ";
        $res = mysql_query($requete);
        if ($res && mysql_num_rows($res)) {
        } else {
            $requete = "INSERT INTO notices_custom_values(notices_custom_champ, notices_custom_origine, notices_custom_small_text) VALUES('22','" . $notice_id . "','" . addslashes($tmp) . "')";
            mysql_query($requete);
        }
    }
}
 function make_first_search()
 {
     global $msg, $dbh;
     global $elt_query;
     global $location_query, $date_ech_query;
     global $nb_per_page, $nb_per_page_select;
     global $results_show_all;
     if (!$nb_per_page) {
         $nb_per_page = $nb_per_page_select;
     }
     $restrict = "1 ";
     if ($location_query != '-1') {
         $restrict .= "and location_id='" . $location_query . "' ";
     }
     $restrict .= "and notice_id=num_notice ";
     if ($date_ech_query != '-1') {
         $restrict .= "and date_fin < '" . $date_ech_query . "' ";
     }
     $suite_rqt = "or code='" . $elt_query . "' ";
     $issn_verif = traite_code_ISSN(stripslashes($elt_query));
     if (isISSN(stripslashes($elt_query))) {
         $suite_rqt .= " or code='" . $issn_verif . "' ";
         $q_count = "select count(abt_id) from notices, abts_abts where " . $restrict . " and (0 " . $suite_rqt . ")";
         $r_count = pmb_mysql_query($q_count);
         $n_count = pmb_mysql_result($r_count, 0, 0);
         $this->nbresults = $n_count;
         $q_list = "select tit1, abt_id, abt_name from notices, abts_abts where " . $restrict . " and (0 " . $suite_rqt . ") ORDER BY 1,3";
         if (!$results_show_all) {
             $q_list .= " limit " . $this->page * $nb_per_page . ", " . $nb_per_page . " ";
         }
         $r_list = pmb_mysql_query($q_list, $dbh);
         $this->t_query = $r_list;
         if (!$results_show_all) {
             $this->nbepage = ceil($this->nbresults / $nb_per_page);
         } else {
             $this->nbepage = 1;
         }
     } else {
         $aq = new analyse_query(stripslashes($elt_query));
         if ($aq->error) {
             $this->show_form();
             error_message($msg["searcher_syntax_error"], sprintf($msg["searcher_syntax_error_desc"], $aq->current_car, $aq->input_html, $aq->error_message));
             return;
         } else {
             $q_members = $aq->get_query_members("notices", "index_wew", "index_sew", "abt_id");
             $q_count = "select count(abt_id) from notices, abts_abts where " . $restrict . " and (" . $q_members["where"] . " " . $suite_rqt . ")";
             $r_count = pmb_mysql_query($q_count);
             $n_count = pmb_mysql_result($r_count, 0, 0);
             $this->nbresults = $n_count;
             $q_list = "select abt_id, " . $q_members['select'] . " as pert from notices, abts_abts where " . $restrict . " and (" . $q_members["where"] . " " . $suite_rqt . ") " . $q_members['post'];
             if (!$results_show_all) {
                 $q_list .= " limit " . $this->page * $nb_per_page . ", " . $nb_per_page . " ";
             }
             //on surcharge la requête d'origine pour ajouter trier sur titre de périodique
             $new_q_list = "\n\t\t\t\t\t\tSELECT tit1, a.abt_id, a.abt_name, pert \n\t\t\t\t\t\tFROM notices n, abts_abts a, (" . $q_list . ") as q \n\t\t\t\t\t\tWHERE q.abt_id=a.abt_id AND a.num_notice=n.notice_id \n\t\t\t\t\t\tORDER BY 1 ASC,3 DESC";
             $r_list = pmb_mysql_query($new_q_list, $dbh);
             $this->t_query = $r_list;
             if (!$results_show_all) {
                 $this->nbepage = ceil($this->nbresults / $nb_per_page);
             } else {
                 $this->nbepage = 1;
             }
         }
     }
     return ELT_LIST;
 }