";
$tpl = '';
if(is_array($authperso_fields['FIELDS'])) {
foreach($authperso_fields['FIELDS'] as $field){
//printr($field);
$field_tpl=$authperso_field_tpl;
$field_tpl = str_replace("!!titre!!", $field['TITRE'], $field_tpl);
$field_tpl = str_replace("!!aff!!", $field['AFF'], $field_tpl);
$field_tpl = str_replace("!!comment!!", $field['COMMENT_DISPLAY'], $field_tpl);
$tpl.=$field_tpl;
}
}
$button_remplace = "";
$button_voir = "";
if ($pmb_type_audit && $id)
$bouton_audit= audit::get_dialog_button($id, ($this->id + 1000));
$aut_link= new aut_link($this->id+1000,$id);
$authperso_form_select = str_replace('', $aut_link->get_form('saisie_authperso') , $authperso_form_select);
// Indexation concept
if($thesaurus_concepts_active == 1){
$index_concept = new index_concept($id, TYPE_AUTHPERSO);
$authperso_form_select = str_replace('', $index_concept->get_form('saisie_authperso'), $authperso_form_select);
}
$authperso_form_select = str_replace("!!libelle!!", $msg['authperso_form_titre_new'], $authperso_form_select);
$authperso_form_select = str_replace("!!list_field!!", $tpl, $authperso_form_select);
$authperso_form_select = str_replace("!!retour!!", "$base_url&action=", $authperso_form_select);
$authperso_form_select = str_replace("!!action!!", "$base_url&action=update", $authperso_form_select);
$authperso_form_select = str_replace("!!id_authperso!!", $this->id, $authperso_form_select);
$authperso_form_select = str_replace("!!id!!", $id, $authperso_form_select);
return $authperso_form_select;
}
public function update_from_form($id=0) {
global $thesaurus_concepts_active;
global $authority_statut;
global $authority_thumbnail_url;
global $msg, $max_titre_uniforme;
global $responsabilities;
$id = (int) $id;
$p_perso=new custom_parametres_perso("authperso","authperso",$this->id);
if($p_perso->check_submited_fields()){ //Des erreurs de types dans les champs perso postés
$this->cp_error_message = $p_perso->error_message;
return;
}
$error_list = $p_perso->check_mandatory_fields_value();
if(count($error_list)){
$this->cp_error_message=sprintf($msg['parperso_field_is_needed'],$error_list[0]['field']['TITRE']);
return;
}
if(!$id){
$requete="insert into authperso_authorities set authperso_authority_authperso_num=".$this->id;
pmb_mysql_query($requete);
$id = pmb_mysql_insert_id();
audit::insert_creation ($this->id+1000,$id);
}else{
audit::insert_modif ($this->id+1000,$id);
}
if(!$id) return;
//update authority informations
$authority = new authority(0, $id, AUT_TABLE_AUTHPERSO);
$authority->set_num_statut($authority_statut);
$authority->set_thumbnail_url($authority_thumbnail_url);
$authority->update();
$p_perso->rec_fields_perso($id);
$aut_link= new aut_link($this->id+1000,$id);
$aut_link->save_form();
// Oeuvres associées à l'évennement
$query = "DELETE FROM tu_oeuvres_events WHERE oeuvre_event_authperso_authority_num=" . $id;
pmb_mysql_query($query);
$order = 0;
$max_titre_uniforme = intval($max_titre_uniforme);
for ($i = 0; $i < $max_titre_uniforme ; $i++) {
$var_tu_id = 'f_titre_uniforme_code' . $i;
global ${$var_tu_id};
if (($tu_id = intval(${$var_tu_id}))) {
$query = "INSERT INTO tu_oeuvres_events SET
oeuvre_event_authperso_authority_num =" . $id . ",
oeuvre_event_tu_num =" . $tu_id . ",
oeuvre_event_order =".$order++;
pmb_mysql_query($query);
}
}
// Responsabilities
if ($responsabilities) {
$responsabilities_instance = new responsabilities();
$responsabilities_instance->save_authperso($id, $responsabilities);
}
// Indexation concepts
if($thesaurus_concepts_active == 1){
$index_concept = new index_concept($id, TYPE_AUTHPERSO);
$index_concept->save();
}
// Mise à jour des vedettes composées contenant cette autorité
vedette_composee::update_vedettes_built_with_element($id, TYPE_AUTHPERSO);
$this->update_global_index($id);
// Publication d'un event
$evt_handler = events_handler::get_instance();
$event = new event_authperso("authperso", "update");
$event->set_id_authperso($id);
$evt_handler->send($event);
return $id;
}
public function update_global_index($id){
global $include_path;
$id = (int) $id;
$p_perso=new custom_parametres_perso("authperso","authperso",$this->id);
$mots_perso=$p_perso->get_fields_recherche($id);
if($mots_perso) {
$infos_global = $mots_perso.' ';
$infos_global_index = strip_empty_words($mots_perso).' ';
} else {
$infos_global = '';
$infos_global_index = '';
}
$req = "update authperso_authorities set authperso_infos_global='".addslashes($infos_global)."', authperso_index_infos_global='".addslashes(' '.$infos_global_index)."' where id_authperso_authority=$id";
pmb_mysql_query($req);
$indexation_authority = new indexation_authperso($include_path."/indexation/authorities/authperso/champs_base.xml", "authorities", (1000+$this->id), $this->id);
$indexation_authority->maj($id);
}
public function reindex_all(){
$req = "select id_authperso_authority from authperso_authorities";
$res = pmb_mysql_query($req);
while($fiche = pmb_mysql_fetch_object($res)){
$this->update_global_index($fiche->id_authperso_authority);
}
}
static public function update_all_global_index($id_authperso){
global $dbh, $msg;
global $include_path;
$id_authperso+= 0;
$req = "select id_authperso_authority from authperso_authorities where authperso_authority_authperso_num=".$id_authperso ;
$res = pmb_mysql_query($req);
$p_perso=new custom_parametres_perso("authperso","authperso",$id_authperso);
while($fiche = pmb_mysql_fetch_object($res)){
$id = $fiche->id_authperso_authority;
$mots_perso=$p_perso->get_fields_recherche($id);
if($mots_perso) {
$infos_global = $mots_perso.' ';
$infos_global_index = strip_empty_words($mots_perso).' ';
} else {
$infos_global = '';
$infos_global_index = '';
}
$req = "update authperso_authorities set authperso_infos_global='".addslashes($infos_global)."', authperso_index_infos_global='".addslashes(' '.$infos_global_index)."' where id_authperso_authority=$id";
pmb_mysql_query($req);
$indexation_authority = new indexation_authperso($include_path."/indexation/authorities/authperso/champs_base.xml", "authorities", (1000+$id_authperso), $id_authperso);
$indexation_authority->maj($id);
}
return "".$msg['admin_authperso_update_global_index_end']."";
}
public function delete($id) {
$id = (int) $id;
$is_used = $this->check_uses($id);
if (empty($is_used)) {
$evt_handler = events_handler::get_instance();
$event = new event_authperso("authperso", "delete");
$event->set_id_authperso($id);
$evt_handler->send($event);
// Lien événement
$query = "delete from tu_oeuvres_events where oeuvre_event_authperso_authority_num=$id";
pmb_mysql_query($query);
// Liens entre autorités
$req = "select authperso_authority_authperso_num from authperso_authorities,authperso where id_authperso=authperso_authority_authperso_num and id_authperso_authority=$id";
$res = pmb_mysql_query($req);
if ($r = pmb_mysql_fetch_object($res)) {
$query = "delete from aut_link where aut_link_from=" . ($r->authperso_authority_authperso_num + 1000) . " and aut_link_from_num=$id";
pmb_mysql_query($query);
$query = "delete from aut_link where aut_link_to=" . ($r->authperso_authority_authperso_num + 1000) . " and aut_link_to_num=$id";
pmb_mysql_query($query);
}
// Effacement de l'identifiant unique d'autorité
$authority = new authority(0, $id, AUT_TABLE_AUTHPERSO);
$authority->delete();
// Suppression des valeurs des champs perso
$p_perso = new custom_parametres_perso("authperso", "authperso", $this->id);
$p_perso->delete_values($id);
// Nettoyage indexation concepts
$index_concept = new index_concept($id, TYPE_AUTHPERSO);
$index_concept->delete();
indexation_authperso::delete_all_index($id, "authorities", "id_authority", AUT_TABLE_AUTHPERSO);
$responsabilities = new responsabilities();
$responsabilities->delete_authperso($id);
$req = "DELETE FROM authperso_authorities where id_authperso_authority=$id";
pmb_mysql_query($req);
audit::delete_audit($this->id + 1000, $id);
return false;
}
return $is_used;
}
public function replace_form($id) {
global $authperso_replace;
global $msg;
global $include_path;
if(!$id ) {
require_once("$include_path/user_error.inc.php");
error_message($msg[161], $msg[162], 1, static::format_url('&sub=&id='));
return;
}
$authperso_replace=str_replace('!!old_authperso_libelle!!', strip_tags(static::get_isbd($id)), $authperso_replace);
$authperso_replace=str_replace('!!id!!', $id, $authperso_replace);
$authperso_replace=str_replace('!!id_authperso!!', $this->id, $authperso_replace);
$authperso_replace = str_replace('!!controller_url_base!!', static::format_url(), $authperso_replace);
$authperso_replace=str_replace('!!cancel_action!!', static::format_back_url(), $authperso_replace);
return $authperso_replace;
}
public function replace($id,$by,$link_save=0) {
global $msg;
$id = (int) $id;
$by = (int) $by;
if (($id == $by) || (!$id) || (!$by)) {
return $msg[223];
}
$evt_handler = events_handler::get_instance();
$event = new event_authperso("authperso", "replace");
$event->set_id_authperso($id);
$event->set_replacement_id($by);
$evt_handler->send($event);
$aut_link= new aut_link($this->id+1000,$id);
// "Conserver les liens entre autorités" est demandé
if($link_save) {
// liens entre autorités
$aut_link->add_link_to($this->id +1000,$by);
}
$aut_link->delete();
// remplacement dans les notices
$requete = "UPDATE notices_authperso SET notice_authperso_authority_num='$by' WHERE notice_authperso_authority_num='$id' ";
@pmb_mysql_query($requete);
vedette_composee::replace($this->id +1000, $id, $by);
//Remplacement dans les champs persos sélecteur d'autorité
aut_pperso::replace_pperso(AUT_TABLE_AUTHPERSO, $this->id, $by);
// effacement de
$this->delete($id);
// effacement de l'identifiant unique d'autorité
$authority = new authority(0, $id, AUT_TABLE_AUTHPERSO);
$authority->delete();
$this->update_global_index($by);
}
public static function import($data) {
// to do
}
public function get_ajax_list($user_input){
$values=array();
$search_word = str_replace('*','%',$user_input);
$req = "select * from authperso_authorities where ( authperso_infos_global like '".addslashes($search_word)."%' or authperso_index_infos_global like ' ".addslashes($user_input)."%' ) and authperso_authority_authperso_num= ".$this->id;
$req .= " order by authperso_index_infos_global limit 20";
$res = pmb_mysql_query($req);
while(($r=pmb_mysql_fetch_object($res))) {
$values[$r->id_authperso_authority]=strip_tags(static::get_isbd($r->id_authperso_authority));
}
return($values);
}
public static function get_ajax_list_oeuvre_events($user_input, $oeuvre_event_type = 3) {
$values = array();
$search_word = str_replace('*', '%', $user_input);
$req = "SELECT * FROM authperso_authorities
JOIN authperso ON authperso_authorities.authperso_authority_authperso_num = authperso.id_authperso
WHERE (authperso_infos_global LIKE '".addslashes($search_word)."%' OR authperso_index_infos_global LIKE ' ".addslashes($user_input)."%')
AND authperso.authperso_oeuvre_event = 1
AND authperso_authority_authperso_num = $oeuvre_event_type
ORDER BY authperso_index_infos_global limit 20";
$res = pmb_mysql_query($req);
while ($r = pmb_mysql_fetch_object($res)) {
$values[$r->id_authperso_authority] = strip_tags(static::get_isbd($r->id_authperso_authority));
}
return($values);
}
public function get_cp_error_message(){
return $this->cp_error_message;
}
public static function set_controller($controller) {
static::$controller = $controller;
}
protected static function format_url($url='') {
global $base_path;
if(isset(static::$controller) && is_object(static::$controller)) {
return static::$controller->get_url_base().$url;
} else {
return $base_path.'/autorites.php?categ=authperso'.$url;
}
}
protected static function format_back_url() {
if(isset(static::$controller) && is_object(static::$controller)) {
return static::$controller->get_back_url();
} else {
return "history.go(-1)";
}
}
protected static function format_delete_url($url='') {
global $base_path;
if(isset(static::$controller) && is_object(static::$controller)) {
return static::$controller->get_delete_url();
} else {
return static::format_url("&sub=delete".$url);
}
}
public function get_searcher_instance() {
if (!isset($this->searcher_instance)) {
global $user_input;
$this->searcher_instance = searcher_factory::get_searcher('authperso', '', ($user_input ? $user_input : '*'), $this->id);
}
return $this->searcher_instance;
}
public function get_custom_fields_using_this_authority() {
$number = intval($this->id) + 1000;
$query = "";
$custom_fields = [];
foreach (self::$prefixes as $prefix) {
if ($query) {
$query .= " UNION ";
}
$query .= "SELECT idchamp, type, datatype, options, '".$prefix."' AS prefix
FROM ".$prefix."_custom
WHERE type = 'query_auth'
AND options LIKE '%".$number."%'";
}
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
while ($row = pmb_mysql_fetch_assoc($result)) {
if (!isset($custom_fields[$row["prefix"]])) {
$custom_fields[$row["prefix"]] = [];
}
$custom_fields[$row["prefix"]][] = $row["idchamp"];
}
}
return $custom_fields;
}
protected function check_uses($id) {
global $msg;
$display_messages = '';
$messages = [];
// Publication d'un event
$evt_handler = events_handler::get_instance();
$event = new event_authperso("authperso", "authperso_check_uses");
$event->set_id_authperso($id);
$evt_handler->send($event);
if (empty($event->get_error_message())) {
if ($usage = aut_pperso::delete_pperso(AUT_TABLE_AUTHPERSO, $id, 0)) {
// Cette autorité est utilisée dans des champs perso, impossible de supprimer
$messages[] = $msg['autority_delete_error'] . '
' . $usage['display'];
}
$attached_vedettes = vedette_composee::get_vedettes_built_with_element($id, TYPE_AUTHPERSO);
if (!empty($attached_vedettes)) {
if (isset($event->get_elements()['concept'])) {
if (count(array_diff($event->get_elements()['concept'], $attached_vedettes))) {
// Cette autorité est utilisée dans des vedettes composées, impossible de la supprimer
$messages[] = $msg["vedette_dont_del_autority"] . ' ' . vedette_composee::get_vedettes_display($attached_vedettes);
}
} else {
$messages[] = $msg["vedette_dont_del_autority"] . ' ' . vedette_composee::get_vedettes_display($attached_vedettes);
}
}
if (!empty($messages)) {
foreach ($messages as $message) {
$display_messages .= "$this->display $message";
}
}
return $display_messages;
}
return $event->get_error_message();
}
public function is_responsability_authperso() {
$req = "select authperso_responsability_authperso from authperso where id_authperso=". $this->id;
$res = pmb_mysql_query($req);
if(($r=pmb_mysql_fetch_object($res))) {
return $r->authperso_responsability_authperso;
}
return 0;
}
public function gen_template_responsability(int $id) {
$responsabilities = new responsabilities();
return $responsabilities->get_form(TYPE_AUTHPERSO_RESPONSABILITY, $id);
}
public function get_sort_entity_type() {
return "authperso";
}
} //authperso class end
class authpersos {
public $info=array();
protected static $instance;
public function __construct() {
$this->fetch_data();
}
public static function get_name($id_authperso){
$id_authperso = (int) $id_authperso;
$query = "select authperso_name from authperso where id_authperso = ".$id_authperso;
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
return pmb_mysql_result($result, 0);
}
}
public function fetch_data() {
global $PMBuserid;
$this->info=array();
$i=0;
$req="select * from authperso order by authperso_name";
$resultat=pmb_mysql_query($req);
if (pmb_mysql_num_rows($resultat)) {
while($r=pmb_mysql_fetch_object($resultat)){
// $this->info[$i]= new authperso($r->id_authperso);
$authperso= new authperso($r->id_authperso);
$this->info[$r->id_authperso]=$authperso->get_data();
$i++;
}
}
}
public function get_data(){
return($this->info);
}
public function get_all_index_fields(){
$index_fields=array();
$req="select id_authperso from authperso order by authperso_name";
$resultat=pmb_mysql_query($req);
if (pmb_mysql_num_rows($resultat)) {
while($r=pmb_mysql_fetch_object($resultat)){
$index_fields[]=$r->id_authperso;
}
}
return $index_fields;
}
public function get_onglet_list() {
$onglets=array();
foreach($this->info as $elt){
// if($elt['onglet_num'])
$onglets[$elt['onglet_num']][]=$elt;
}
return $onglets;
}
public function get_menu() {
global $authperso_list_tpl, $authperso_list_line_tpl, $msg, $categ;
$line_tpl="