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; }
function update($value, $force = false) { global $dbh; global $msg, $charset; global $include_path; global $pmb_synchro_rdf; global $thesaurus_concepts_active; global $opac_enrichment_bnf_sparql; if (!$value['name']) { return false; } // nettoyage des chaînes en entrée $value['name'] = clean_string($value['name']); $value['rejete'] = clean_string($value['rejete']); $value['date'] = clean_string($value['date']); $value['lieu'] = clean_string($value['lieu']); $value['ville'] = clean_string($value['ville']); $value['pays'] = clean_string($value['pays']); $value['subdivision'] = clean_string($value['subdivision']); $value['numero'] = clean_string($value['numero']); if (!$force) { if ($this->id) { // s'assurer que l'auteur n'existe pas déjà switch ($value['type']) { case 71: // Collectivité $and_dedoublonnage = " and author_subdivision ='" . $value['subdivision'] . "' and author_lieu='" . $value['lieu'] . "' and author_ville = '" . $value['ville'] . "' and author_pays = '" . $value['pays'] . "' and author_numero ='" . $value['numero'] . "' "; break; case 72: // Congrès $and_dedoublonnage = " and author_subdivision ='" . $value['subdivision'] . "' and author_lieu='" . $value['lieu'] . "' and author_ville = '" . $value['ville'] . "' and author_pays = '" . $value['pays'] . "' and author_numero ='" . $value['numero'] . "' "; break; default: $and_dedoublonnage = ''; break; } $dummy = "SELECT * FROM authors WHERE author_type='" . $value['type'] . "' AND author_name='" . $value['name'] . "'"; $dummy .= " AND author_rejete='" . $value['rejete'] . "' "; $dummy .= "AND author_date='" . $value[date] . "' and author_id!='" . $this->id . "' {$and_dedoublonnage} "; $check = pmb_mysql_query($dummy, $dbh); if (pmb_mysql_num_rows($check)) { $auteur_exists = new auteur(pmb_mysql_result($check, 0, "author_id")); require_once "{$include_path}/user_error.inc.php"; warning($msg[200], htmlentities($msg[220] . " -> " . $auteur_exists->display, ENT_QUOTES, $charset)); return FALSE; } } else { // s'assurer que l'auteur n'existe pas déjà if ($id_auteur_exists = auteur::check_if_exists($value)) { $auteur_exists = new auteur($id_auteur_exists); require_once "{$include_path}/user_error.inc.php"; warning($msg[200], htmlentities($msg[220] . " -> " . $auteur_exists->display, ENT_QUOTES, $charset)); return FALSE; } } // s'assurer que la forme_retenue ne pointe pas dans les deux sens if ($this->id) { $dummy = "SELECT * FROM authors WHERE author_id='" . $value[voir_id] . "' and author_see='" . $this->id . "'"; $check = pmb_mysql_query($dummy, $dbh); if (pmb_mysql_num_rows($check)) { require_once "{$include_path}/user_error.inc.php"; warning($msg[200], htmlentities($msg['author_forme_retenue_error'] . " -> " . $this->display, ENT_QUOTES, $charset)); return FALSE; } } } $requete = "SET author_type='{$value['type']}', "; $requete .= "author_name='{$value['name']}', "; $requete .= "author_rejete='{$value['rejete']}', "; $requete .= "author_date='{$value['date']}', "; $requete .= "author_lieu='" . $value["lieu"] . "', "; $requete .= "author_ville='" . $value["ville"] . "', "; $requete .= "author_pays='" . $value["pays"] . "', "; $requete .= "author_subdivision='" . $value["subdivision"] . "', "; $requete .= "author_numero='" . $value["numero"] . "', "; $requete .= "author_web='{$value['author_web']}', "; $requete .= "author_see='{$value['voir_id']}', "; $requete .= "author_comment='{$value['author_comment']}', "; $word_to_index = $value["name"] . " " . $value["rejete"] . " " . $value["lieu"] . " " . $value["ville"] . " " . $value["pays"] . " " . $value["numero"] . " " . $value["subdivision"]; if ($value['type'] == 72) { $word_to_index .= " " . $value["date"]; } $requete .= "index_author=' " . strip_empty_chars($word_to_index) . " ',"; $requete .= "author_import_denied= " . ($value['import_denied'] ? 1 : 0); if ($this->id) { audit::insert_modif(AUDIT_AUTHOR, $this->id); // update // on checke s'il n'y a pas un renvoi circulaire if ($this->id == $value['voir_id']) { require_once "{$include_path}/user_error.inc.php"; warning($msg[199], htmlentities($msg[222] . " -> " . $this->display, ENT_QUOTES, $charset)); return FALSE; } $requete = 'UPDATE authors ' . $requete; $requete .= ' WHERE author_id=' . $this->id . ' ;'; if (pmb_mysql_query($requete, $dbh)) { // liens entre autorités $aut_link = new aut_link(AUT_TABLE_AUTHORS, $this->id); $aut_link->save_form(); $aut_pperso = new aut_pperso("author", $this->id); $aut_pperso->save_form(); auteur::update_index($this->id); // mise à jour de l'auteur dans la base rdf if ($pmb_synchro_rdf) { $synchro_rdf = new synchro_rdf(); $synchro_rdf->updateAuthority($this->id, 'auteur'); } // ////////////////////////modif de l'update/////////////////////////////// $query = "select 1 from authors where (author_enrichment_last_update < now()-interval '0' day) and author_id={$this->id}"; $result = pmb_mysql_query($query, $dbh); if ($opac_enrichment_bnf_sparql && pmb_mysql_num_rows($result)) { auteur::author_enrichment($this->id); } // //////////////////////////////////////////////////////////////////////// } else { require_once "{$include_path}/user_error.inc.php"; warning($msg[199], htmlentities($msg[208] . " -> " . $this->display, ENT_QUOTES, $charset)); return FALSE; } } else { // creation $requete = 'INSERT INTO authors ' . $requete . ' '; if (pmb_mysql_query($requete, $dbh)) { $this->id = pmb_mysql_insert_id(); // liens entre autorités $aut_link = new aut_link(AUT_TABLE_AUTHORS, $this->id); $aut_link->save_form(); $aut_pperso = new aut_pperso("author", $this->id); $aut_pperso->save_form(); audit::insert_creation(AUDIT_AUTHOR, $this->id); // ajout des enrichissements si activés if ($opac_enrichment_bnf_sparql) { auteur::author_enrichment($this->id); } } else { require_once "{$include_path}/user_error.inc.php"; warning($msg[200], htmlentities($msg[221] . " -> " . $requete, ENT_QUOTES, $charset)); return FALSE; } } // Indexation concepts if ($thesaurus_concepts_active == 1) { $index_concept = new index_concept($this->id, TYPE_AUTHOR); $index_concept->save(); } // Mise à jour des vedettes composées contenant cette autorité vedette_composee::update_vedettes_built_with_element($this->id, "author"); return TRUE; }