xml_file = $xml_file; $this->full_path = $full_path; $this->parse_search_file(); } /** * Visibilité d'un onglet / d'un champ de recherche * @param array $element */ protected function parse_visibility($element) { $parsed_visibility = array(); if(isset($element['VAR']) && is_array($element['VAR'])) { for ($j=0; $j $subfieldrestrict['SUB_FIELD'][0]['value'], 'values' => explode(',', $subfieldrestrict['VALUES'][0]['value']), 'op' => $subfieldrestrict['OP'][0]['value'], 'not' => (isset($subfieldrestrict['NOT'][0]['value']) ? $subfieldrestrict['NOT'][0]['value'] : '') ); } } $parsed_field['FIELDRESTRICT'][] = array( 'field' => $fieldrestrict['FIELD'][0]['value'], 'values' => explode(',', $fieldrestrict['VALUES'][0]['value']), 'op' => $fieldrestrict['OP'][0]['value'], 'not' => (isset($fieldrestrict['NOT'][0]['value']) ? $fieldrestrict['NOT'][0]['value'] : ''), 'sub' => $subfieldsrestrict ); } } }else if(isset($field['CLASS'][0]['NAME'])) { $parsed_field['CLASS'] = $field['CLASS'][0]['NAME']; if(isset($field['CLASS'][0]['FIELDRESTRICT']) && count($field['CLASS'][0]['FIELDRESTRICT'])) { $field_restrict = array(); foreach ($field['CLASS'][0]['FIELDRESTRICT'] as $fieldrestrict) { $subfieldsrestrict = array(); if(isset($fieldrestrict['SUB'])) { foreach ($fieldrestrict['SUB'][0]['FIELDRESTRICT'] as $subfieldrestrict) { $subfieldsrestrict[] = array( 'sub_field' => $subfieldrestrict['SUB_FIELD'][0]['value'], 'values' => explode(',', $subfieldrestrict['VALUES'][0]['value']), 'op' => $subfieldrestrict['OP'][0]['value'], 'not' => (isset($subfieldrestrict['NOT'][0]['value']) ? $subfieldrestrict['NOT'][0]['value'] : '') ); } } $parsed_field['FIELDRESTRICT'][] = array( 'field' => $fieldrestrict['FIELD'][0]['value'], 'values' => explode(',', $fieldrestrict['VALUES'][0]['value']), 'op' => $fieldrestrict['OP'][0]['value'], 'not' => (isset($fieldrestrict['NOT'][0]['value']) ? $fieldrestrict['NOT'][0]['value'] : ''), 'sub' => $subfieldsrestrict ); } } } else { $parsed_field['CLASS'] = $field['CLASS'][0]['value']; } } $parsed_field['VARVIS'] = $this->parse_visibility($field); return $parsed_field; } //Parse du fichier de configuration protected function parse_search_file() { global $base_path, $charset, $include_path; global $msg, $KEY_CACHE_FILE_XML; if(!$this->xml_file) { $this->xml_file = "authorities"; } if(!$this->full_path){ $filepath = $include_path."/searcher_tabs/".$this->xml_file."_subst.xml"; if (!file_exists($filepath)) { $filepath = $include_path."/searcher_tabs/".$this->xml_file.".xml"; } } else { $filepath = $this->full_path.$this->xml_file."_subst.xml"; if (!file_exists($filepath)) { $filepath = $this->full_path.$this->xml_file.".xml"; } } $fileInfo = pathinfo($filepath); $fileName = preg_replace("/[^a-z0-9]/i","",$fileInfo['dirname'].$fileInfo['filename'].$charset); $tempFile = $base_path."/temp/XML".$fileName.".tmp"; $dejaParse = false; $cache_php=cache_factory::getCache(); $key_file=""; if ($cache_php) { $key_file=getcwd().$fileName.filemtime($filepath); $key_file=$KEY_CACHE_FILE_XML.md5($key_file); if($tmp_key = $cache_php->getFromCache($key_file)){ if($cache = $cache_php->getFromCache($tmp_key)){ if(count($cache) == 3){ $this->url_target = $cache[0]; $this->default_mode = $cache[1]; $this->tabs = $cache[2]; $dejaParse = true; } } } }else{ if (file_exists($tempFile) ) { //Le fichier XML original a-t-il été modifié ultérieurement ? if (filemtime($filepath) > filemtime($tempFile)) { //on va re-générer le pseudo-cache unlink($tempFile); } else { $dejaParse = true; } } if ($dejaParse) { $tmp = fopen($tempFile, "r"); $cache = unserialize(fread($tmp,filesize($tempFile))); fclose($tmp); if(count($cache) == 3){ $this->url_target = $cache[0]; $this->default_mode = $cache[1]; $this->tabs = $cache[2]; }else{ //SOUCIS de cache... unlink($tempFile); $dejaParse = false; } } } if(!$dejaParse){ $fp=fopen($filepath,"r") or die("Can't find XML file"); $size=filesize($filepath); $xml=fread($fp,$size); fclose($fp); $param=_parser_text_no_function_($xml, "PMBTABS"); //Lecture du mode par défaut if($param['DEFAULT_MODE']) { $this->default_mode = $param['DEFAULT_MODE'][0]['value']; } //Lecture de l'url $this->url_target = $param['URL_TARGET'][0]['value']; $this->tabs = array(); //Lecture des onglets for ($i=0; $iparse_visibility($p_tab); $fields = array(); if(isset($p_tab['SEARCHFIELDS'][0]['FIELD'])) { $search_fields = $p_tab['SEARCHFIELDS'][0]['FIELD']; //Lecture des champs de recherche if(is_array($search_fields)){ for ($j=0; $jparse_field($search_fields[$j]); } } } $tab['SEARCHFIELDS'] = $fields; $fields = array(); if(isset($p_tab['FILTERFIELDS'][0]['FIELD'])) { $filter_fields = $p_tab['FILTERFIELDS'][0]['FIELD']; //Lecture des filtres de recherche if(is_array($filter_fields)){ for ($j=0; $jparse_field($filter_fields[$j]); } } } $tab['FILTERFIELDS'] = $fields; $this->tabs[$tab['MODE']] = $tab; } if($key_file){ $key_file_content=$KEY_CACHE_FILE_XML.md5(serialize(array($this->url_target,$this->default_mode,$this->tabs))); $cache_php->setInCache($key_file_content, array($this->url_target,$this->default_mode,$this->tabs)); $cache_php->setInCache($key_file,$key_file_content); }else{ $tmp = fopen($tempFile, "wb"); fwrite($tmp,serialize(array( $this->url_target, $this->default_mode, $this->tabs, ))); fclose($tmp); } } } protected function get_field($field, $type) { global $charset; global $msg; global $lang; //Récupération des valeurs du POST $field_name = $this->get_field_name($field, $type); $values = $this->get_values_from_field($field_name, $type); $display = "
"; $display .= ""; $display .= "
"; $display .= "
"; switch ($field['INPUT_TYPE']) { case "authoritie": if(!isset($values[0])) $values[0] = ''; if ($values[0] != 0) { switch ($field ['INPUT_OPTIONS'] ['SELECTOR']) { case "auteur" : $aut = new auteur($values[0]); $libelle = $aut->get_isbd(); break; case "categorie" : $libelle = categories::getlibelle($values[0], $lang); break; case "editeur" : $ed = new editeur($values[0]); $libelle = $ed->get_isbd(); break; case "collection" : $coll = new collection($values[0]); $libelle = $coll->get_isbd(); break; case "subcollection" : $coll = new subcollection($values[0]); $libelle = $coll->get_isbd(); break; case "serie" : $serie = new serie($values[0]); $libelle = $serie->get_isbd(); break; case "indexint" : $indexint = new indexint($values[0]); $libelle = $indexint->get_isbd(); break; case "titre_uniforme" : $tu = new titre_uniforme($values[0]); $libelle = $tu->get_isbd(); break; default : $libelle = $values[0]; break; } } else { $libelle = ""; } if(isset($field ['INPUT_OPTIONS'] ['ATT_ID_FILTER']) && $field ['INPUT_OPTIONS'] ['ATT_ID_FILTER']) { $att_id_filter = "att_id_filter='".$field ['INPUT_OPTIONS'] ['ATT_ID_FILTER']."'"; } else { $att_id_filter = ""; } $display .= ""; $display .= ""; break; case "text": if(isset($field['INPUT_OPTIONS']['IFSEARCHEMPTY'])) { $this->js_dynamic_check_form .= "if(!document.getElementById('".$field_name."').value) document.getElementById('".$field_name."').value='".$field['INPUT_OPTIONS']['IFSEARCHEMPTY']."';"; } $input_placeholder = ''; if(isset($field['INPUT_OPTIONS']['PLACEHOLDER'])) { if (substr($field['INPUT_OPTIONS']['PLACEHOLDER'],0,4)=="msg:") { $input_placeholder = $msg[substr($field['INPUT_OPTIONS']['PLACEHOLDER'],4,strlen($field['INPUT_OPTIONS']['PLACEHOLDER'])-4)]; } else { $input_placeholder = $field['INPUT_OPTIONS']["PLACEHOLDER"]; } } $display.=""; break; case "query_list": $query=$field["INPUT_OPTIONS"]["QUERY"][0]["value"]; if (isset($field["INPUT_OPTIONS"]["FILTERING"])) { if ($field["INPUT_OPTIONS"]["FILTERING"] == "yes") { $query = str_replace("!!acces_j!!", "", $query); $query = str_replace("!!statut_j!!", "", $query); $query = str_replace("!!statut_r!!", "", $query); } } if (isset($field["INPUT_OPTIONS"]["QUERY"][0]["USE_GLOBAL"])) { $use_global = explode(",", $field["INPUT_OPTIONS"]["QUERY"][0]["USE_GLOBAL"]); for($j=0; $j"; if($field["INPUT_OPTIONS"]["QUERY"][0]["ALLCHOICE"] == "yes"){ $display .= ""; } $result=pmb_mysql_query($query); while ($row=pmb_mysql_fetch_array($result)) { $display.="
"; return $display; } public function get_form() { global $msg; global $current_module; $form = ""; $tab=$this->get_current_tab(); $form .= "

".get_msg_to_display($tab['TITLE'])."

"; foreach ($tab['SEARCHFIELDS'] as $search_field) { if($this->visibility($search_field)) { $form .= $this->get_field($search_field, 'search'); } } $form .= "
$msg[155] $msg[1550]
"; $i=0; foreach ($tab['FILTERFIELDS'] as $filter_field) { if($this->visibility($filter_field)) { if($i%2 == 0) $form .= "
"; else $form .= "
"; $form .= $this->get_field($filter_field, 'filter'); $form .= "
"; $i++; } } $form .= "
"; return $form; } public function get_title() { global $msg; $title = "

"; $title .= $msg['search']." : ".get_msg_to_display($this->tabs[$this->current_mode]['TITLE']); $title .= "

"; return $title; } public function get_tabs() { $tabs = "
"; foreach ($this->tabs as $tab) { if($this->visibility($tab)) { $tabs .= "current_mode == $tab['MODE'] ? "class='selected'" : "").">".get_msg_to_display($tab['TITLE']).""; } } $tabs .= "
"; return $tabs; } protected function get_values_from_field($field_name) { global ${$field_name}; if(is_array(${$field_name})) { return ${$field_name}; } else { return array(); } } private function get_field_name($field, $type = 'search') { if($type == 'filter') { $field_name="filter_field_tab_".$field['ID']; } else { $field_name="search_field_tab_".$field['ID']; } return $field_name; } private function get_values_from_form() { $data = array(); $tab=$this->get_current_tab(); foreach ($tab['SEARCHFIELDS'] as $search_field) { $t = array(); $t['id'] = $search_field['ID']; $t['values'] = $this->get_values_from_field($this->get_field_name($search_field, 'search')); $t['class'] = (isset($search_field['CLASS']) ? $search_field['CLASS'] : ''); $t['type'] = $search_field['TYPE']; $t['mode'] = (isset($search_field['MODE']) ? $search_field['MODE'] : ''); if(isset($search_field['FIELDRESTRICT']) && is_array($search_field['FIELDRESTRICT'])) { $t['fieldrestrict'] = $search_field['FIELDRESTRICT']; } $data['SEARCHFIELDS'][]= $t; } foreach ($tab['FILTERFIELDS'] as $filter_field) { $t = array(); $t['id'] = $filter_field['ID']; $t['values'] = $this->get_values_from_field($this->get_field_name($filter_field, 'filter')); $t['globalvar'] = $filter_field['GLOBALVAR'][0]['value']; $data['FILTERFIELDS'][]= $t; } return $data; } private function search() { global $page, $nb_per_page_search; $values = $this->get_values_from_form(); $searcher_authorities_tab = new searcher_authorities_tab($values); $this->objects_ids = $searcher_authorities_tab->get_sorted_result("default",$page*$nb_per_page_search,$nb_per_page_search); $this->search_nb_results = $searcher_authorities_tab->get_nb_results(); } protected function get_current_tab(){ return $this->tabs[$this->current_mode]; } protected function make_hidden_form() { global $charset; $tab=$this->get_current_tab(); $form = "
"; foreach ($tab['SEARCHFIELDS'] as $search_field) { $field_name = $this->get_field_name($search_field, 'search'); $values = $this->get_values_from_field($field_name); for($i=0; $i < count($values); $i++) { $form .= ""; } } foreach ($tab['FILTERFIELDS'] as $filter_field) { $field_name = $this->get_field_name($filter_field, 'filter'); $values = $this->get_values_from_field($field_name); for($i=0; $i < count($values); $i++) { $form .= ""; } } $form .= "
"; return $form; } protected function get_human_field($field, $values) { global $msg, $charset; switch ($field["INPUT_TYPE"]) { case "list": $options=$field["INPUT_OPTIONS"]["OPTIONS"][0]; $opt=array(); for ($j=0; $j=0) $field_aff[$j]=$opt[$values[$j]]; // $opt[$values[$j]] peut etre à -1 else $field_aff[$j]=''; } break; case "marc_list": $opt=marc_list_collection::get_instance($field["INPUT_OPTIONS"]["NAME"][0]["value"]); for ($j=0; $jtable[$values[$j]]; } break; case "date": $field_aff[0]=format_date($values[0]); break; case "authoritie": for($j=0 ; $jlibelle_thesaurus . "]"; if (isset ( $fieldvar ["id_thesaurus"] )) { unset ( $fieldvar ["id_thesaurus"] ); } break; case "auteur" : $aut = new auteur ( $values [$j] ); $values [$j] = $aut->get_isbd(); break; case "editeur" : $ed = new editeur ( $values [$j] ); $values [$j] = $ed->get_isbd(); break; case "collection" : $coll = new collection ( $values [$j] ); $values [$j] = $coll->get_isbd(); break; case "subcollection" : $coll = new subcollection ( $values [$j] ); $values [$j] = $coll->get_isbd(); break; case "serie" : $serie = new serie ( $values [$j] ); $values [$j] = $serie->get_isbd(); break; case "indexint" : $indexint = new indexint ( $values [$j] ); $values [$j] = $indexint->get_isbd(); break; case "titre_uniforme" : $tu = new titre_uniforme ( $values [$j] ); $values [$j] = $tu->get_isbd(); break; case "notice" : $values [$j] = notice::get_notice_title($values [$j]); break; } } } $field_aff= $values; break; default: $field_aff[0]=$values[0]; break; } return ''.get_msg_to_display($field['TITLE']).' '.implode(' ', $field_aff); } protected function make_human_query($without_tags = false) { global $msg; global $charset; $human_queries = array(); $tab = $this->get_current_tab(); foreach ($tab['SEARCHFIELDS'] as $search_field) { $values = $this->clean_array($this->get_values_from_field($this->get_field_name($search_field, 'search'))); if(is_array($values) && isset($values[0]) && ($values[0] != '')) { $human_queries[] = $this->get_human_field($search_field, $values); } } foreach ($tab['FILTERFIELDS'] as $filter_field) { $values = $this->clean_array($this->get_values_from_field($this->get_field_name($filter_field, 'filter'))); if(is_array($values) && isset($values[0]) && ($values[0] != '')) { $human_queries[] = $this->get_human_field($filter_field, $values); } } $research = implode(', ', $human_queries); if($this->search_nb_results) { $research .= " => ".sprintf($msg["searcher_results"], $this->search_nb_results); } else { $research .= " => ".sprintf($msg[1915], $this->search_nb_results); } if ($without_tags) { return $research; } return "
".$research."
"; } protected function pager() { global $msg; global $page, $nb_per_page_search; if (!$this->search_nb_results) return; if($page) $this->page = $page; $this->nbepage=ceil($this->search_nb_results/$nb_per_page_search); $suivante = $this->page+1; $precedente = $this->page-1; if (!$this->page) $page_en_cours=0 ; else $page_en_cours=$this->page ; // affichage du lien précédent si nécéssaire $nav_bar = ''; if($precedente >= 0) $nav_bar .= "[$msg[48]]"; $deb = $page_en_cours - 10 ; if ($deb<0) $deb=0; for($i = $deb; ($i < $this->nbepage) && ($i<$page_en_cours+10); $i++) { if($i==$page_en_cours) $nav_bar .= "".($i+1).""; else $nav_bar .= "".($i+1).""; if($i<$this->nbepage) $nav_bar .= " "; } if($suivante<$this->nbepage) $nav_bar .= "[$msg[49]]"; // affichage de la barre de navigation print "
$nav_bar
"; } public function show_result() { global $msg,$charset,$dbh; global $begin_result_liste; global $end_result_liste; print $this->make_hidden_form(); print $this->make_human_query(); if(count($this->objects_ids)) { $elements_authorities_list_ui = new elements_authorities_list_ui($this->objects_ids, $this->search_nb_results, 1); $elements = $elements_authorities_list_ui->get_elements_list(); print $begin_result_liste; search_authorities::get_caddie_link(); print $elements; print $end_result_liste; $this->pager(); } } protected function is_multi_search_criteria(){ $tab=$this->get_current_tab(); return $tab['MULTISEARCHCRITERIA']; } public function proceed($mode=0, $action="") { global $search; global $pmb_extended_search_dnd_interface; global $page, $msg; if(!$mode) { $this->current_mode=$this->default_mode; } else { $this->current_mode=$mode; } print $this->get_title(); print $this->get_tabs(); $tab=$this->get_current_tab(); if($this->is_multi_search_criteria()){ $sc=new search_authorities(true, 'search_fields_authorities'); switch($action){ case 'search': $sc->reduct_search(); $this->set_session_history($sc->make_human_query(), $tab, "QUERY"); print $sc->show_results($this->url_target."&mode=".$tab['MODE']."&action=search", $this->url_target."&mode=".$tab['MODE'], true, '', true ); $this->set_session_history($sc->make_human_query(), $tab, "AUT"); break; default: if($tab['PREDEFINEDSEARCH'] && !(is_array($search) && count($search))) { $search_perso = new search_perso($tab['PREDEFINEDSEARCH'], 'AUTHORITIES'); $sc->unserialize_search($search_perso->query); } print $sc->show_form($this->url_target."&mode=".$tab['MODE'], $this->url_target."&mode=".$tab['MODE']."&action=search", "", $this->url_target."_perso&sub=form"); if ($pmb_extended_search_dnd_interface){ if(!isset($search_perso) || !is_object($search_perso)) { $search_perso = new search_perso(0, 'AUTHORITIES'); } print ''; } break; } } else { switch($action){ case 'search': $this->search(); $this->set_session_history($this->make_human_query(true), $tab, "QUERY"); print $this->show_result(); $this->set_session_history($this->make_human_query(true), $tab, "AUT", "simple"); break; default: print $this->get_form(); break; } } } protected function clean_array($values_array){ global $charset; $temp = array(); foreach($values_array as $key => $value){ $temp[$key] = htmlentities(stripslashes($value), ENT_QUOTES, $charset); } return $temp; } public function get_mode_multi_search_criteria($id_predefined_search=0){ $mode = 0; $founded_predefined_search = false; foreach ($this->tabs as $tab) { if($tab['MULTISEARCHCRITERIA'] && $tab['PREDEFINEDSEARCH']) { if($tab['PREDEFINEDSEARCH'] == $id_predefined_search) { $mode = $tab['MODE']; $founded_predefined_search = true; } } elseif(!$founded_predefined_search && $tab['MULTISEARCHCRITERIA']) { $mode = $tab['MODE']; } } return $mode; } // fonction de calcul de la visibilite d'un onglet / d'un champ de recherche protected function visibility($element) { if (!count($element['VARVIS'])) return true; for ($i=0; $iurl_target."&mode=".$tab["MODE"]; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["POST"] = $_POST; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["GET"] = $_GET; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["GET"]["sub"] = ""; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["POST"]["sub"] = ""; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["HUMAN_QUERY"] = $human_query; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["HUMAN_TITLE"] = "[".$msg["132"]."] ".get_msg_to_display($tab["TITLE"]); $_POST["page"] = 0; $page = 0; } break; case 'AUT' : if ($_SESSION["CURRENT"] !== false) { $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["URI"] = $this->url_target."&mode=".$tab["MODE"]."&action=search"; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["PAGE"] = $page+1; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["POST"] = $_POST; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["GET"] = $_GET; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["HUMAN_QUERY"] = $human_query; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["SEARCH_TYPE"] = $search_type; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["FORM_VALUES"] = $this->get_values_from_form(); $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]['TEXT_LIST_QUERY']=''; $_SESSION["session_history"][$_SESSION["CURRENT"]][$type]["TEXT_QUERY"] = ""; } break; } } } ?>