static function import($value, $from_form = 0)
 {
     global $dbh;
     // Si vide on sort
     if (trim($value['name']) == '') {
         return FALSE;
     }
     if (!$from_form) {
         $value['name'] = addslashes($value['name']);
         $value['num_author'] = addslashes($value['num_author']);
         $value['form'] = addslashes($value['form']);
         $value['date'] = addslashes($value['date']);
         $value['subject'] = addslashes($value['subject']);
         $value['place'] = addslashes($value['place']);
         $value['history'] = addslashes($value['history']);
         $value['characteristic'] = addslashes($value['characteristic']);
         $value['intended_termination'] = addslashes($value['intended_termination']);
         $value['intended_audience'] = addslashes($value['intended_audience']);
         $value['context'] = addslashes($value['context']);
         $value['equinox'] = addslashes($value['equinox']);
         $value['coordinates'] = addslashes($value['coordinates']);
         $value['tonalite'] = addslashes($value['tonalite']);
         $value['comment'] = addslashes($value['comment']);
         $value['databnf_uri'] = addslashes($value['databnf_uri']);
         for ($i = 0; $i < count($value['distrib']); $i++) {
             $value['distrib'][$i] = addslashes($value['distrib'][$i]);
         }
         for ($i = 0; $i < count($value['ref']); $i++) {
             $value['ref'][$i] = addslashes($value['ref'][$i]);
         }
         for ($i = 0; $i < count($value['subdiv']); $i++) {
             $value['subdiv'][$i] = addslashes($value['subdiv'][$i]);
         }
         for ($i = 0; $i < count($value['authors']); $i++) {
             // les champs auteurs sont addslashes dans import auteur
             $value['authors'][$i]['type'] = addslashes($value['authors'][$i]['type']);
             $value['authors'][$i]['fonction'] = addslashes($value['authors'][$i]['fonction']);
         }
     }
     $marc_key = new marc_list("music_key");
     $marc_form = new marc_list("music_form");
     $flag_form = false;
     $flag_key = false;
     foreach ($marc_form->table as $value_form => $libelle_form) {
         if ($value_form == $value['form']) {
             $flag_form = true;
         }
     }
     foreach ($marc_key->table as $value_key => $libelle_key) {
         if ($value_key == $value['tonalite']) {
             $flag_key = true;
         }
     }
     if (count($value['authors'])) {
         for ($i = 0; $i < count($value['authors']); $i++) {
             if ($value['authors'][$i]['id']) {
                 $tu_auteur = new auteur($value['authors'][$i]['id']);
                 if (!$tu_auteur->id) {
                     // id non valide
                     $value['authors'][$i]['id'] = 0;
                 }
             }
             if (!$value['authors'][$i]['id']) {
                 // création ou déjà existant. auteur::import addslashes les champs
                 $value['authors'][$i]['id'] = auteur::import($value['authors'][$i]);
             }
         }
     }
     // $value déjà addslashes plus haut -> 1
     $titre = titre_uniforme::import_tu_exist($value, 1);
     if ($titre) {
         return $titre;
     }
     $requete = "INSERT INTO titres_uniformes SET ";
     $requete .= "tu_name='" . $value["name"] . "', ";
     $requete .= "tu_num_author='" . $value["num_author"] . "', ";
     $requete .= (!$flag_form ? "tu_forme='" : "tu_forme_marclist='") . $value['form'] . "', ";
     $requete .= "tu_date='" . $value["date"] . "', ";
     $requete .= "tu_sujet='" . $value["subject"] . "', ";
     $requete .= "tu_lieu='" . $value["place"] . "', ";
     $requete .= "tu_histoire='" . $value["history"] . "', ";
     $requete .= "tu_caracteristique='" . $value["characteristic"] . "', ";
     $requete .= "tu_completude='" . $value["intended_termination"] . "', ";
     $requete .= "tu_public='" . $value["intended_audience"] . "', ";
     $requete .= "tu_contexte='" . $value["context"] . "', ";
     $requete .= "tu_equinoxe='" . $value["equinox"] . "', ";
     $requete .= "tu_coordonnees='" . $value["coordinates"] . "', ";
     $requete .= (!$flag_key ? "tu_tonalite='" : "tu_tonalite_marclist='") . $value['tonalite'] . "', ";
     $requete .= "tu_comment='" . $value["comment"] . "', ";
     $requete .= "tu_databnf_uri='" . $value["databnf_uri"] . "' ";
     // insertion du titre uniforme	et mise à jour de l'index tu
     if (pmb_mysql_query($requete, $dbh)) {
         $tu_id = pmb_mysql_insert_id();
     } else {
         return FALSE;
     }
     if (count($value['authors'])) {
         $ordre = 0;
         $rqt_ins = "INSERT INTO responsability_tu (responsability_tu_author_num, responsability_tu_num, responsability_tu_fonction, responsability_tu_type, responsability_tu_ordre) VALUES ";
         foreach ($value['authors'] as $author) {
             if ($author['id']) {
                 $rqt = $rqt_ins . " ('" . $author['id'] . "','" . $tu_id . "','" . $author['fonction'] . "','" . $author['type'] . "', {$ordre}) ";
                 $res_ins = @pmb_mysql_query($rqt);
                 $ordre++;
             }
         }
     }
     // Distribution instrumentale et vocale (pour la musique)
     for ($i = 0; $i < count($value['distrib']); $i++) {
         $requete = "INSERT INTO tu_distrib SET\n\t\t\tdistrib_num_tu='{$tu_id}',\n\t\t\tdistrib_name='" . $value['distrib'][$i] . "',\n\t\t\tdistrib_ordre='{$i}' ";
         pmb_mysql_query($requete, $dbh);
     }
     // Référence numérique (pour la musique)
     for ($i = 0; $i < count($value['ref']); $i++) {
         $requete = "INSERT INTO tu_ref SET\n\t\t\tref_num_tu='{$tu_id}',\n\t\t\tref_name='" . $value['ref'][$i] . "',\n\t\t\tref_ordre='{$i}' ";
         pmb_mysql_query($requete, $dbh);
     }
     // Subdivision de forme
     for ($i = 0; $i < count($value['subdiv']); $i++) {
         $requete = "INSERT INTO tu_subdiv SET\n\t\t\tsubdiv_num_tu='{$tu_id}',\n\t\t\tsubdiv_name='" . $value['subdiv'][$i] . "',\n\t\t\tsubdiv_ordre='{$i}' ";
         pmb_mysql_query($requete, $dbh);
     }
     audit::insert_creation(AUDIT_TITRE_UNIFORME, $tu_id);
     //update authority informations
     $authority = new authority(0, $tu_id, AUT_TABLE_TITRES_UNIFORMES);
     $authority->set_num_statut($value["statut"]);
     $authority->update();
     // mise à jour du champ index du titre uniforme
     if ($tu_id) {
         titre_uniforme::update_index_tu($tu_id);
         titre_uniforme::tu_enrichment($tu_id);
     }
     return $tu_id;
 }
Пример #2
0
function update_aut()
{
    global $dbh;
    global $text, $n, $t_xml;
    //Reprise des auteurs sans élément rejeté et des titres de notices lorsque tronqués.
    //Upload du fichier
    if (!$_FILES['userfile']['tmp_name']) {
        print "Cliquez sur Pr&eacute;c&eacute;dent et choisissez un fichier";
        exit;
    } elseif (!move_uploaded_file($_FILES['userfile']['tmp_name'], "../../temp/" . basename($_FILES['userfile']['tmp_name']))) {
        print "Le fichier n'a pas pu être t&eacute;l&eacute;charg&eacute;. Voici plus d'informations :<br />";
        print_r($_FILES) . "<p>";
        exit;
    }
    $fichier = @fopen("../../temp/" . basename($_FILES['userfile']['tmp_name']), "r");
    if ($fichier) {
        print "<br /><br />";
        print "T&eacute;l&eacute;chargement du fichier effectu&eacute;.<br /><hr />";
        print "Traitement du fichier en cours.<br />";
        $nb_ok = 0;
        $tab_err = array();
        //definition header et footer
        $header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><inm:results>";
        $footer = "</inm:results>";
        $compte = 0;
        while (!feof($fichier)) {
            $buffer = "";
            $deb = FALSE;
            $i = 0;
            while ($i < 200 && !feof($fichier)) {
                $line = fgets($fichier, 4096);
                if (strpos($line, "<inm:Recordset") === FALSE && strpos($line, "<inm:Record") !== FALSE) {
                    $deb = TRUE;
                }
                if ($deb) {
                    $buffer .= trim($line);
                }
                if (strpos($line, "</inm:Record>") !== FALSE) {
                    $deb = FALSE;
                    $i++;
                }
            }
            if ($buffer) {
                $buffer = $header . $buffer . $footer;
                //parse buffer
                $text = '';
                $t_xml = array();
                $n = 0;
                $encoding = "UTF-8";
                $parser = xml_parser_create($encoding);
                xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $encoding);
                xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
                xml_set_element_handler($parser, "debutBalise", "finBalise");
                xml_set_character_data_handler($parser, "texte");
                if (!xml_parse($parser, $buffer, TRUE)) {
                    die(sprintf("erreur XML %s à la ligne: %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
                }
                xml_parser_free($parser);
                $tmp_compte = $compte;
                $tmp_val = array();
                //traitement des enregistrements
                for ($i = 1; $i <= count($t_xml); $i++) {
                    //Il faut un code-barres d'exemplaire et un auteur sans element rejete
                    $t_xml[$i]['INM:CODE-BARRE'][0] = trim($t_xml[$i]['INM:CODE-BARRE'][0]);
                    $q = "select notice_id,tit1 from notices join exemplaires on expl_notice=notice_id where expl_cb='" . $t_xml[$i]['INM:CODE-BARRE'][0] . "' ";
                    $r = mysql_query($q, $dbh);
                    if (mysql_num_rows($r)) {
                        $n = mysql_result($r, 0, 0);
                        $t = mysql_result($r, 0, 1);
                        /*
                        if ($t != $t_xml[$i]['INM:TITRE'][0]) {
                        	print "ancien titre = ".$t.'<br/>';
                        	print "nouveau titre=".$t_xml[$i]['INM:TITRE'][0].'<br/>';
                        }
                        */
                        foreach ($t_xml[$i]['INM:AUTEUR'] as $k => $v) {
                            $t_xml[$i]['INM:AUTEUR'][$k] = trim($v);
                            if (strpos($v, ',') === FALSE) {
                                $compte++;
                                $tmp_val[$compte]['name'] = clean_string(utf8_decode($v));
                                $tmp_val[$compte]['type'] = '70';
                                $aut = auteur::import($tmp_val[$compte]);
                                $q1 = "select count(*) from responsability join authors on author_id=responsability_author where responsability_notice='" . $n . "' and responsability_type='0' ";
                                $r1 = mysql_query($q1, $dbh);
                                $n1 = mysql_result($r1, 0, 0);
                                if ($n1) {
                                    $q2 = "select max(ordre)*1+1 from responsability join authors on author_id=responsability_author where responsability_notice_id='" . $n . "' and responsability_type='1' ";
                                    $r2 = mysql_query($q2, $dbh);
                                    $n2 = mysql_result($r2, 0, 0);
                                    $q3 = "insert ignore into responsability (responsability_author,responsability_notice,responsability_fonction,responsability_type,responsability_ordre) ";
                                    $q3 .= "values ('" . $aut . "','" . $n . "','','1','" . $n2 . "') ";
                                    mysql_query($q3, $dbh);
                                } else {
                                    $q3 = "insert ignore into responsability (responsability_author,responsability_notice,responsability_fonction,responsability_type,responsability_ordre) ";
                                    $q3 .= "values ('" . $aut . "','" . $n . "','','0','0') ";
                                    mysql_query($q3, $dbh);
                                }
                            }
                        }
                        foreach ($t_xml[$i]['INM:AUTEUR-COLLECTIF'] as $k => $v) {
                            $t_xml[$i]['INM:AUTEUR-COLLECTIF'] = trim($v);
                            if (strpos($v, ',') === FALSE) {
                                $compte++;
                                $tmp_val[$compte]['name'] = clean_string(utf8_decode($v));
                                $tmp_val[$compte]['type'] = '71';
                                $aut = auteur::import($tmp_val[$compte]);
                                $q1 = "select count(*) from responsability join authors on author_id=responsability_author where responsability_notice='" . $n . "' and responsability_type='0' ";
                                $r1 = mysql_query($q1, $dbh);
                                $n1 = mysql_result($r1, 0, 0);
                                if ($n1) {
                                    $q2 = "select max(ordre)*1+1 from responsability join authors on author_id=responsability_author where responsability_notice_id='" . $n . "' and responsability_type='1' ";
                                    $r2 = mysql_query($q2, $dbh);
                                    $n2 = mysql_result($r2, 0, 0);
                                    $q3 = "insert ignore into responsability (responsability_author,responsability_notice,responsability_fonction,responsability_type,responsability_ordre) ";
                                    $q3 .= "values ('" . $aut . "','" . $n . "','','1','" . $n2 . "') ";
                                    mysql_query($q3, $dbh);
                                } else {
                                    $q3 = "insert ignore into responsability (responsability_author,responsability_notice,responsability_fonction,responsability_type,responsability_ordre) ";
                                    $q3 .= "values ('" . $aut . "','" . $n . "','','0','0') ";
                                    mysql_query($q3, $dbh);
                                }
                            }
                        }
                        foreach ($t_xml[$i]['INM:AUTEUR-SECONDAIRE'] as $k => $v) {
                            $t_xml[$i]['INM:AUTEUR-SECONDAIRE'][$k] = trim($v);
                            if (strpos($v, ',') === FALSE) {
                                $compte++;
                                $tmp_val[$compte]['name'] = clean_string(utf8_decode($v));
                                $tmp_val[$compte]['type'] = '70';
                                $aut = auteur::import($tmp_val[$compte]);
                                $q2 = "select max(ordre)*1+1 from responsability join authors on author_id=responsability_author where responsability_notice_id='" . $n . "' and responsability_type='2' ";
                                $r2 = mysql_query($q2, $dbh);
                                $n2 = mysql_result($r2, 0, 0);
                                $q3 = "insert ignore into responsability (responsability_author,responsability_notice,responsability_fonction,responsability_type,responsability_ordre) ";
                                $q3 .= "values ('" . $aut . "','" . $n . "','','2','" . $n2 . "') ";
                                mysql_query($q3, $dbh);
                            }
                        }
                        if ($compte != $tmp_compte) {
                            print 'notice n° ' . $n . ' - ' . $t . '<br />';
                            foreach ($tmp_val as $v) {
                                print $v['name'] . '<br />';
                            }
                            print '<br/>';
                            print '_______________________________<br />';
                            $tmp_val = array();
                            $tmp_compte = $compte;
                        }
                    }
                }
            }
        }
        fclose($fichier);
        unlink("../../temp/" . basename($_FILES['userfile']['tmp_name']));
        print "Traitement du fichier termin&eacute;.";
        print "<br /><hr />";
        print "Nb total d'enregistrements modifi&eacute;s = " . $compte . '<br />';
        if (count($tab_err)) {
            for ($i = 0; $i < count($tab_err); $i++) {
                print "Erreur &agrave; l&apos;enregistrement n° " . $tab_err[$i] . "<br />";
            }
            print "<hr /><br />";
        }
    } else {
        print "Le fichier n&apos;a pu &ecirc;tre lu .";
    }
}
Пример #3
0
 function insert_authority_infos($authority_number, $type, $id_origin_authority, $authority_infos = array())
 {
     global $opac_enrichment_bnf_sparql;
     //on a un numéro d'autorité, on regarde si on l'a déjà rencontré
     $num_authority = $authority_infos['id'];
     $query = "select id_authority_source,num_authority from authorities_sources where authority_number = '" . $authority_number . "' and num_origin_authority='" . $id_origin_authority . "' and authority_type = '" . $type . "'";
     $result = pmb_mysql_query($query) or die("can't select authorities_sources :" . $query);
     if (pmb_mysql_num_rows($result)) {
         $row = pmb_mysql_fetch_object($result);
         $num_authority = $row->num_authority;
         $num_authority_source = $row->id_authority_source;
         // on cherche la préférence... dès fois que...
         $query = "select id_authority_source, num_authority from authorities_sources where authority_number = '" . $authority_number . "' and authority_type = '" . $type . "' and authority_favorite = 1";
         $result = pmb_mysql_query($query) or die("can't select authorities_sources :" . $query);
         if (pmb_mysql_num_rows($result)) {
             $row = pmb_mysql_fetch_object($result);
             $num_authority = $row->num_authority;
             $num_authority_source = $row->id_authority_source;
         }
     } else {
         // on importe l'autorité dans la base si elle n'a pas d'id
         if ($num_authority == 0) {
             switch ($type) {
                 case "author":
                     $num_authority = auteur::import($authority_infos);
                     break;
                 case "uniform_title":
                     $num_authority = titre_uniforme::import($authority_infos);
                     break;
                 case "category":
                     $num_authority = category::import($authority_infos);
                     break;
                 case "collection":
                     $num_authority = collection::import($authority_infos);
                     break;
                 case "subcollection":
                     $num_authority = subcollection::import($authority_infos);
                     break;
                 case "serie":
                     break;
             }
         }
         // on intègre la source de l'autorité
         $query = "insert into authorities_sources set\n\t\t\tnum_authority = '{$num_authority}',\n\t\t\tauthority_number = '" . $authority_number . "',\n\t\t\tauthority_type = '{$type}',\n\t\t\tnum_origin_authority = " . $id_origin_authority . ",\n\t\t\timport_date = now()";
         pmb_mysql_query($query) or die("can't insert authorities_sources :" . $query);
         $num_authority_source = pmb_mysql_insert_id();
         ////////////////////////////////////////////////////////////////
         if ($opac_enrichment_bnf_sparql && $type == 'author') {
             auteur::author_enrichment($num_authority);
         }
     }
     return $num_authority;
 }
Пример #4
0
function keep_authority_infos($authority_number, $type, $origin_authority, $notice_id, $authority_infos = array())
{
    //on a un numéro d'autorité, on regarde si on l'a déjà rencontré
    $query = "select id_authority_source,num_authority from authorities_sources where authority_number = '" . $authority_number . "' and num_origin_authority='" . $origin_authority . "' and authority_type = '" . $type . "'";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
        $row = mysql_fetch_object($result);
        $num_authority = $row->num_authority;
        $num_authority_source = $row->id_authority_source;
        // on cherche la préférence... dès fois que...
        $query = "select id_authority_source, num_authority from authorities_sources where authority_number = '" . $authority_number . "' and authority_type = '" . $type . "' and authority_favorite = 1";
        $result = mysql_query($query);
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_object($result);
            $num_authority = $row->num_authority;
            $num_authority_source = $row->id_authority_source;
        }
    } else {
        // c'est un petit nouveau
        switch ($type) {
            case "author":
                $num_authority = auteur::import($authority_infos);
                break;
            case "uniform_title":
                $num_authority = titre_uniforme::import($authority_infos);
                break;
            case "category":
                $num_authority = category::import($authority_infos);
                break;
            case "collection":
                $num_authority = collection::import($authority_infos);
                break;
            case "subcollection":
                $num_authority = subcollection::import($authority_infos);
                break;
            case "serie":
                break;
        }
        $query = "insert into authorities_sources set \n\t\t\tnum_authority = '{$num_authority}',\n\t\t\tauthority_number = '" . $authority_number . "',\n\t\t\tauthority_type = '{$type}',\n\t\t\tnum_origin_authority = " . $origin_authority . ",\n\t\t\timport_date = now()";
        mysql_query($query);
        $num_authority_source = mysql_insert_id();
    }
    //certaines autorités sont créés avant la notice...
    if ($notice_id != 0) {
        $query = "insert into notices_authorities_sources set \n\t\tnum_authority_source = " . $num_authority_source . ",\n\t\tnum_notice = " . $notice_id;
        mysql_query($query);
    }
    return $num_authority;
}
Пример #5
0
 protected function create_notice()
 {
     global $pmb_keyword_sep;
     global $pmb_type_audit;
     global $webdav_current_user_name, $webdav_current_user_id;
     if ($this->data['publisher']) {
         $ed_1 = \editeur::import(array('name' => $this->data['publisher']));
     } else {
         $ed_1 = 0;
     }
     $ind_wew = $this->data['tit1'] . " " . $this->data['tit4'];
     $ind_sew = \strip_empty_words($ind_wew);
     $query = "insert into notices set\n\t\t\t\ttit1 = '" . addslashes($this->data['tit1']) . "'," . ($this->data['code'] ? "code='" . $this->data['code'] . "'," : "") . "ed1_id = '" . $ed_1 . "'," . ($this->data['tit4'] ? "tit4 = '" . addslashes($this->data['tit4']) . "'," : "") . ($this->data['npages'] ? "npages = '" . addslashes($this->data['npages']) . "'," : "") . ($this->data['index_l'] ? "index_l = '" . addslashes($this->data['index_l']) . "'," : "") . "\n\t\t\t\tyear = '" . $this->data['year'] . "',\n\t\t\t\tniveau_biblio='m',\n\t\t\t\tniveau_hierar='0',\n\t\t\t\tstatut = '" . $this->config['default_statut'] . "',\n\t\t\t\tindex_wew = '" . $ind_wew . "',\n\t\t\t\tindex_sew = '" . $ind_sew . "',\n\t\t\t\tn_resume = '" . addslashes($this->data['n_resume']) . "',\n\t\t\t\tlien = '" . addslashes($url) . "',\n\t\t\t\tindex_n_resume = '" . \strip_empty_words($this->data['n_resume']) . "'," . ($this->data['thumbnail_content'] ? "thumbnail_url = 'data:image/png;base64," . base64_encode($this->data['thumbnail_content']) . "'," : "") . "create_date = sysdate(),\n\t\t\t\tupdate_date = sysdate()";
     pmb_mysql_query($query);
     $notice_id = pmb_mysql_insert_id();
     //traitement audit
     if ($pmb_type_audit) {
         $query = "INSERT INTO audit SET ";
         $query .= "type_obj='1', ";
         $query .= "object_id='{$notice_id}', ";
         $query .= "user_id='{$webdav_current_user_id}', ";
         $query .= "user_name='{$webdav_current_user_name}', ";
         $query .= "type_modif=1 ";
         $result = @pmb_mysql_query($query);
     }
     if (count($this->data['authors'])) {
         $i = 0;
         foreach ($this->data['authors'] as $author) {
             $aut = array();
             if ($author['file-as']) {
                 $infos = explode(",", $author['file-as']);
                 $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70);
             }
             if (!$aut['name']) {
                 $aut = array('name' => $author['value'], 'type' => 70);
             }
             $aut_id = \auteur::import($aut);
             if ($aut_id) {
                 $query = "insert into responsability set\n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0'";
                 pmb_mysql_query($query);
                 $i++;
             }
         }
     }
     if (count($this->data['co_authors'])) {
         foreach ($this->data['co_authors'] as $author) {
             $aut = array();
             if ($author['file-as']) {
                 $infos = explode(",", $author['file-as']);
                 $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70);
             }
             if (!$aut['name']) {
                 $aut = array('name' => $author['value'], 'type' => 70);
             }
             $aut_id = \auteur::import($aut);
             if ($aut_id) {
                 $query = "insert into responsability set\n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0',\n\t\t\t\t\t\t\trepsonsability_ordre = '" . $i . "'";
                 pmb_mysql_query($query);
                 $i++;
             }
         }
     }
     return $notice_id;
 }
Пример #6
0
 public function create_authority()
 {
     switch ($this->notice->type) {
         case "author":
             $this->authority_id = auteur::import($this->notice->specifics_data);
             break;
         case "uniform_title":
             $this->authority_id = titre_uniforme::import($this->notice->specifics_data);
             break;
         case "collection":
             $this->authority_id = collection::import($this->notice->specifics_data);
             if ($this->authority_id != 0 && $this->notice->specifics_data['subcollections']) {
                 for ($i = 0; $i < count($this->notice->specifics_data['subcollections']); $i++) {
                     $this->notice->specifics_data['subcollections'][$i]['coll_parent'] = $this->authority_id;
                     $subcoll_id = subcollection::check_if_exists($this->notice->specifics_data['subcollections'][$i]);
                     if ($subcoll_id != 0 && $this->notice->specifics_data['subcollections'][$i]['authority_number']) {
                         $query = "insert into authorities_sources set \n\t\t\t\t\t\t\t\t\tnum_authority = " . $subcoll_id . ",\n\t\t\t\t\t\t\t\t\tauthority_number = '" . $this->notice->specifics_data['subcollections'][$i]['authority_number'] . "',\t\n\t\t\t\t\t\t\t\t\tauthority_type = 'subcollection',\n\t\t\t\t\t\t\t\t\tnum_origin_authority = " . $this->num_origin . ",\n\t\t\t\t\t\t\t\t\tauthority_favorite = 0,\n\t\t\t\t\t\t\t\t\timport_date = now()";
                         mysql_query($query);
                     }
                 }
             }
             break;
         case "subcollection":
             $this->authority_id = subcollection::import($this->notice->specifics_data);
             if ($this->authority_id != 0 && $this->notice->specifics_data['collection'] && $this->notice->specifics_data['collection']['authority_number']) {
                 $coll_id = collection::check_if_exists($this->notice->specifics_data['collection']);
                 $query = "insert into authorities_sources set \n\t\t\t\t\t\t\tnum_authority = " . $coll_id . ",\n\t\t\t\t\t\t\tauthority_number = '" . $this->notice->specifics_data['collection']['authority_number'] . "',\t\n\t\t\t\t\t\t\tauthority_type = 'collection',\n\t\t\t\t\t\t\tnum_origin_authority = " . $this->num_origin . ",\n\t\t\t\t\t\t\tauthority_favorite = 0,\n\t\t\t\t\t\t\timport_date = now()";
                 mysql_query($query);
             }
             break;
         case "category":
             $this->authority_id = category::import($this->notice->specifics_data, $this->id_thesaurus, $this->get_parent_category(), $this->notice->common_data['lang']);
             break;
         default:
             //	on fait rien...
             break;
     }
     if ($this->authority_id) {
         $query = "insert into authorities_sources set \n\t\t\t\tnum_authority = " . $this->authority_id . ",\n\t\t\t\tauthority_number = '" . $this->notice->common_data['authority_number'] . "',\t\n\t\t\t\tauthority_type = '" . $this->notice->type . "',\n\t\t\t\tnum_origin_authority = " . $this->num_origin . ",\n\t\t\t\tauthority_favorite = 1,\n\t\t\t\timport_date = now(),\n\t\t\t\tupdate_date = now()";
         mysql_query($query);
     } else {
         return false;
     }
 }
Пример #7
0
    /**
     * @param array $entry le tableau $entry généré par la fonction buildEntry()
     * 
     * Fonction d'import d'une notice formaté par la fonction buildEntry()
     * Ajoute les informations d'audit
     * Ajoute les champs personnalisés
     * Ajoute les tables annexes [responsability], [notices_categories] et [notices_langues]
     * Met à jours l'indexation de la notice
     */
    static function buildNotice(&$entry)
    {
        global $pmb_type_audit;
        global $webdav_current_user_name, $webdav_current_user_id;
        //la notice existe déjà ? si oui, on renvoi l'id trouvé
        if ($entry['niveau_biblio'] . $entry['niveau_hierar'] == 'a2') {
            $query = '
			SELECT n1.* FROM notices AS n1
			JOIN analysis ON n1.notice_id=analysis_notice
			JOIN bulletins ON bulletin_id=analysis_bulletin
			JOIN notices AS n2 ON n2.notice_id=bulletin_notice
			WHERE n1.tit1="' . addslashes($entry['tit1']) . '" 
			AND n1.niveau_biblio="' . addslashes($entry['niveau_biblio']) . '" 
			AND n1.niveau_hierar="' . addslashes($entry['niveau_hierar']) . '"
			AND bulletin_numero="' . addslashes($entry['bulletin']['bulletin_numero']) . '"
			AND mention_date="' . addslashes($entry['bulletin']['mention_date']) . '"
			AND date_date="' . addslashes($entry['bulletin']['date_date']) . '"
			AND n2.tit1="' . addslashes($entry['periodique']['tit1']) . '" 
			AND n2.niveau_biblio="' . addslashes($entry['periodique']['niveau_biblio']) . '" 
			AND n2.niveau_hierar="' . addslashes($entry['periodique']['niveau_hierar']) . '"
			';
            $result = mysql_query($query);
        } else {
            $query = 'SELECT * FROM notices WHERE tit1="' . addslashes($entry['tit1']) . '" AND niveau_biblio="' . addslashes($entry['niveau_biblio']) . '" AND niveau_hierar="' . addslashes($entry['niveau_hierar']) . '"';
            $result = mysql_query($query);
        }
        if (mysql_num_rows($result)) {
            // La notice existe
            $entry = array_merge(mysql_fetch_array($result, MYSQL_ASSOC), $entry);
            //TODO : A vérifier
            $first = true;
            $query = 'UPDATE notices SET ';
            foreach (array_keys($entry) as $fieldName) {
                if (!is_array($entry[$fieldName]) && $entry[$fieldName] != '' && $fieldName != 'ancien_num_name') {
                    if (!$first) {
                        $query .= ',';
                    }
                    $query .= $fieldName . '="' . addslashes($entry[$fieldName]) . '"';
                    $first = false;
                }
            }
            $query .= ' WHERE notice_id="' . addslashes($entry['notice_id']) . '"';
            mysql_query($query) or die('echec de la requete : ' . $query . '<br/>' . mysql_error() . "\n");
        } else {
            //les éditeurs
            if (sizeof($entry['publishers'])) {
                foreach ($entry['publishers'] as $id => $publisher) {
                    if ($id < 2) {
                        if ($id === 0) {
                            $entry['ed1_id'] = \editeur::import($publisher);
                        } elseif ($id === 1) {
                            $entry['ed2_id'] = \editeur::import($publisher);
                        }
                    }
                }
            }
            //la collection
            if (sizeof($entry['collections']) && $entry['ed1_id']) {
                $entry['collections']['parent'] = $entry['ed1_id'];
                $entry['coll_id'] = \collection::import($entry['collections']);
            }
            $first = true;
            $query = 'INSERT INTO notices SET ';
            foreach ($entry as $fieldName => $value) {
                if (!is_array($value) && $value != '') {
                    if (!$first) {
                        $query .= ',';
                    }
                    $query .= $fieldName . '="' . addslashes(trim($value)) . '"';
                    $first = false;
                }
            }
            mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
            $entry['notice_id'] = mysql_insert_id();
            if ($pmb_type_audit && ($webdav_current_user_id || $webdav_current_user_name) && $entry['create_date']) {
                //ajout des informations d'audit
                $query = 'INSERT INTO audit (type_obj,object_id,user_id,user_name,type_modif,quand) VALUES (1,' . $entry['notice_id'] . ',' . $webdav_current_user_id . ',"' . addslashes($webdav_current_user_name) . '",1,"' . $entry['create_date'] . '")';
                mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
            }
        }
        //les champs persos
        if (sizeof($entry['cp'])) {
            foreach ($entry['cp'] as $cp) {
                \parametres_perso::import($entry['notice_id'], $cp['field'], $cp['value'], 'notices');
            }
        }
        //ajout dans les tables annexes a la notice
        if (sizeof($entry['annexes'])) {
            foreach ($entry['annexes'] as $typeAnnexe => $annexes) {
                foreach ($annexes as $id => $annexe) {
                    switch ($typeAnnexe) {
                        case 'responsability':
                            //Import et récupération des identifiants auteurs
                            $entry['annexes'][$typeAnnexe][$id]['responsability_author'] = \auteur::import($entry['annexes'][$typeAnnexe][$id]['authors']);
                            $entry['annexes'][$typeAnnexe][$id]['responsability_notice'] = $entry['notice_id'];
                            break;
                        case 'notices_categories':
                            //Import et récupération des identifiants catégories
                            $query = 'SELECT num_noeud FROM categories WHERE libelle_categorie="' . addslashes(trim($entry['annexes'][$typeAnnexe][$id]['categories']['libelle_categorie'])) . '" AND num_thesaurus=' . $entry['annexes'][$typeAnnexe][$id]['categories']['num_thesaurus'] . ' AND langue="' . $entry['annexes'][$typeAnnexe][$id]['categories']['langue'] . '"';
                            $result = mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
                            if (mysql_num_rows($result)) {
                                //le noeud existe déjà
                                $entry['annexes'][$typeAnnexe][$id]['num_noeud'] = mysql_result($result, 0, 0);
                            } else {
                                //le noeud n'existe pas, on cherche le parent non classé
                                $query = 'SELECT id_noeud FROM noeuds WHERE autorite="NONCLASSES" AND num_thesaurus=' . $entry['annexes'][$typeAnnexe][$id]['categories']['num_thesaurus'];
                                $result = mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
                                if (mysql_num_rows($result)) {
                                    //on ajoute le noeud
                                    $query = 'INSERT INTO noeuds SET num_parent=' . mysql_result($result, 0, 0) . ', visible=1, num_thesaurus=' . $entry['annexes'][$typeAnnexe][$id]['categories']['num_thesaurus'];
                                    mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
                                    $entry['annexes']['notices_categories'][$id]['num_noeud'] = mysql_insert_id();
                                    //on ajoute la catégorie
                                    $categorie = new \categories($entry['annexes'][$typeAnnexe][$id]['num_noeud'], $entry['annexes'][$typeAnnexe][$id]['categories']['langue']);
                                    $categorie->libelle_categorie = trim($entry['annexes'][$typeAnnexe][$id]['categories']['libelle_categorie']);
                                    $categorie->save();
                                }
                            }
                            $entry['annexes'][$typeAnnexe][$id]['notcateg_notice'] = $entry['notice_id'];
                            break;
                        case 'notices_langues':
                            $entry['annexes'][$typeAnnexe][$id]['num_notice'] = $entry['notice_id'];
                            break;
                        case 'notices_authorities_sources':
                            $entry['annexes'][$typeAnnexe][$id]['num_notice'] = $entry['notice_id'];
                            break;
                        case 'notices_relations':
                            $entry['annexes'][$typeAnnexe][$id]['num_notice'] = $entry['notice_id'];
                            break;
                        case 'notices_titres_uniformes':
                            $entry['annexes'][$typeAnnexe][$id]['ntu_num_notice'] = $entry['notice_id'];
                            break;
                    }
                    $first = true;
                    $query = 'INSERT IGNORE INTO ' . $typeAnnexe . ' SET ';
                    foreach ($entry['annexes'][$typeAnnexe][$id] as $fieldName => $value) {
                        if (!is_array($value) && $value != '') {
                            if (!$first) {
                                $query .= ',';
                            }
                            $query .= $fieldName . '="' . addslashes(trim($value)) . '"';
                            $first = false;
                        }
                    }
                    mysql_query($query) or die('Echec d\'execution de la requete ' . $query . '  : ' . mysql_error());
                }
            }
        }
        \notice::majNoticesTotal($entry['notice_id']);
    }
Пример #8
0
 function get_notice_by_meta($name, $filename)
 {
     global $pmb_keyword_sep;
     global $pmb_type_audit;
     global $webdav_current_user_name, $webdav_current_user_id;
     \create_tableau_mimetype();
     $mimetype = \trouve_mimetype($filename, extension_fichier($name));
     $notice_id = 0;
     $title = $cplt = $code = $pages = $year = $keywords = $url = $thumbnail_content = "";
     //on commence avec la gymnatisque des métas...
     if ($mimetype == "application/epub+zip") {
         //pour les ebook, on gère ca directement ici !
         $epub = new \epubData(realpath($filename));
         $title = $epub->metas['title'][0];
         $authors = $epub->metas['creator'];
         $co_authors = $epub->metas['contributor'];
         if ($epub->metas['identifier']['isbn']) {
             $code = \formatISBN($epub->metas['identifier']['isbn'], 13);
         } else {
             if ($epub->metas['identifier']['ean']) {
                 $code = \EANtoISBN($epub->metas['identifier']['ean']);
                 $code = \formatISBN($code, 13);
             }
         }
         if ($epub->metas['identifier']['uri']) {
             $url = \clean_string($epub->metas['identifier']['uri']);
         }
         $publisher = $epub->metas['publisher'][0];
         $year = $epub->metas['date'][0]['value'];
         if (strlen($year) && strlen($year) != 4) {
             $year = \formatdate(detectFormatDate($year));
         }
         $lang = $epub->metas['language'];
         $resume = implode("\n", $epub->metas['description']);
         $keywords = implode($pmb_keyword_sep, $epub->metas['subject']);
         //jouons à et si on trouvait a vignette...
         $img = imagecreatefromstring($epub->getCoverContent());
         $file = tempnam(sys_get_temp_dir(), "vign");
         imagepng($img, $file);
         $thumbnail_content = file_get_contents($file);
         unlink($file);
     } else {
         $metas = \extract_metas(realpath($filename), $mimetype);
         if ($metas['Title'] && $metas['Author'] && $metas['Subject']) {
             $title = $metas['Title'];
             $author = $metas['Author'];
             $cplt = $metas['Subject'];
         } else {
             // métas non fiable, on regarde avec le titre...
             $title = $name;
         }
         //date de création...
         if ($metas["CreateDate"]) {
             $year = substr($metas["CreateDate"], 0, 4);
         }
         //pages
         if ($metas['PageCount']) {
             $pages = $metas['PageCount'];
         }
         //keywords
         if ($metas['Keywords']) {
             foreach ($metas['Keywords'] as $keyword) {
                 if ($keywords != "") {
                     $keywords .= $pmb_keyword_sep;
                 }
                 $keywords .= $keyword;
             }
         }
     }
     $query = "select notice_id from notices where tit1 = '" . addslashes($title) . "'";
     $result = mysql_query($query);
     if (mysql_num_rows($result)) {
         $notice_id = mysql_result($result, 0, 0);
     }
     if (!$notice_id) {
         //en cas d'une leture moyenne des infos, on s'assure d'avoir au moins un titre....
         if (!$title) {
             $title = $name;
         }
         if ($publisher) {
             $ed_1 = \editeur::import(array('name' => $publisher));
         } else {
             $ed_1 = 0;
         }
         $ind_wew = $title . " " . $cplt;
         $ind_sew = \strip_empty_words($ind_wew);
         $query = "insert into notices set \n\t\t\t\ttit1 = '" . addslashes($title) . "'," . ($code ? "code='" . $code . "'," : "") . "ed1_id = '" . $ed_1 . "'," . ($cplt ? "tit4 = '" . addslashes($cplt) . "'," : "") . ($pages ? "npages = '" . addslashes($pages) . "'," : "") . ($keywords ? "index_l = '" . addslashes($keywords) . "'," : "") . "\n\t\t\t\tyear = '" . $year . "',\n\t\t\t\tniveau_biblio='m', \n\t\t\t\tniveau_hierar='0',\n\t\t\t\tstatut = '" . $this->config['default_statut'] . "',\n\t\t\t\tindex_wew = '" . $ind_wew . "',\n\t\t\t\tindex_sew = '" . $ind_sew . "',\n\t\t\t\tn_resume = '" . addslashes($resume) . "',\n\t\t\t\tlien = '" . addslashes($url) . "',\n\t\t\t\tindex_n_resume = '" . \strip_empty_words($resume) . "'," . ($thumbnail_content ? "thumbnail_url = 'data:image/png;base64," . base64_encode($thumbnail_content) . "'," : "") . "create_date = sysdate(), \n\t\t\t\tupdate_date = sysdate()";
         mysql_query($query);
         $notice_id = mysql_insert_id();
         $sign = new \notice_doublon();
         mysql_query("update notices set signature = '" . $sign->gen_signature($notice_id) . "' where notice_id = " . $notice_id);
         //traitement audit
         if ($pmb_type_audit) {
             $query = "INSERT INTO audit SET ";
             $query .= "type_obj='1', ";
             $query .= "object_id='{$notice_id}', ";
             $query .= "user_id='{$webdav_current_user_id}', ";
             $query .= "user_name='{$webdav_current_user_name}', ";
             $query .= "type_modif=1 ";
             $result = @mysql_query($query);
         }
         if (count($authors)) {
             $i = 0;
             foreach ($authors as $author) {
                 $aut = array();
                 if ($author['file-as']) {
                     $infos = explode(",", $author['file-as']);
                     $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70);
                 }
                 if (!$aut['name']) {
                     $aut = array('name' => $author['value'], 'type' => 70);
                 }
                 $aut_id = \auteur::import($aut);
                 if ($aut_id) {
                     $query = "insert into responsability set \n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0'";
                     mysql_query($query);
                     $i++;
                 }
             }
         }
         if (count($co_authors)) {
             foreach ($co_authors as $author) {
                 $aut = array();
                 if ($author['file-as']) {
                     $infos = explode(",", $author['file-as']);
                     $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70);
                 }
                 if (!$aut['name']) {
                     $aut = array('name' => $author['value'], 'type' => 70);
                 }
                 $aut_id = \auteur::import($aut);
                 if ($aut_id) {
                     $query = "insert into responsability set \n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0',\n\t\t\t\t\t\t\trepsonsability_ordre = '" . $i . "'";
                     mysql_query($query);
                     $i++;
                 }
             }
         }
     }
     return $notice_id;
 }