/**
  * Parse le fichier xml
  */
 private function parse_file()
 {
     global $base_path, $include_path;
     global $msg;
     if (!$this->xml_file) {
         $this->xml_file = "display_tabs";
     }
     if (!$this->full_path) {
         $filepath = $include_path . "/authorities/" . $this->xml_file . "_subst.xml";
         if (!file_exists($filepath)) {
             $filepath = $include_path . "/authorities/" . $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);
     $tempFile = $base_path . "/temp/XML" . preg_replace("/[^a-z0-9]/i", "", $fileInfo['dirname'] . $fileInfo['filename'] . $charset) . ".tmp";
     $dejaParse = false;
     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) == 1) {
             $this->tabs = $cache[0];
         } else {
             //SOUCIS de cache...
             unlink($tempFile);
             $this->parse_search_file();
         }
     } else {
         $fp = fopen($filepath, "r") or die("Can't find XML file");
         $size = filesize($filepath);
         $xml = fread($fp, $size);
         fclose($fp);
         $tabs = _parser_text_no_function_($xml, "PMBTABS");
         $this->tabs = array();
         //Lecture des onglets
         foreach ($tabs['TAB'] as $tab) {
             $current_tab = new elements_list_tab($tab['NAME'], get_msg_to_display($tab['LABEL']), $tab['CONTENTTYPE']);
             if ($tab['CONTENTTYPE'] == 'authorities') {
                 // Si on a affaire à un onlget d'autorité, on regarde s'il est spécialisé dans un type d'autorité
                 if ($tab['AUTHORITYTYPE'][0]['value'] && defined($tab['AUTHORITYTYPE'][0]['value'])) {
                     $current_tab->set_content_authority_type(constant($tab['AUTHORITYTYPE'][0]['value']));
                 }
             }
             // on récupère les éléments de requête
             if ($tab['QUERY'][0]) {
                 $query_elements = $this->parse_query_elements($tab['QUERY'][0]);
                 $current_tab->set_query_elements($query_elements);
             }
             // on récupère le callable
             if ($tab['CALLABLE'][0]) {
                 $callable = $this->parse_callable($tab['CALLABLE'][0]);
                 $current_tab->set_callable($callable);
             }
             // on récupère les filtres
             if ($tab['FILTERS'][0]['FILTER']) {
                 $filters = $this->parse_filters($tab['FILTERS'][0]['FILTER']);
                 $current_tab->set_filters($filters);
             }
             $this->tabs[$tab['FOR']][] = $current_tab;
         }
         $tmp = fopen($tempFile, "wb");
         fwrite($tmp, serialize(array($this->tabs)));
         fclose($tmp);
     }
 }
 /**
  * Méthode permettant de récupérer les autorités indexées avec un concept utilisant cette autorité
  * @param elements_list_tab $tab
  * @param authority_tabs $authority_tabs
  * @return authority_tab Onglet
  */
 protected static function get_tab_authorities_indexed_with_concept($tab, $authority)
 {
     global $dbh, $msg;
     $types_needed = array(TYPE_AUTHOR, TYPE_CATEGORY, TYPE_PUBLISHER, TYPE_COLLECTION, TYPE_SUBCOLLECTION, TYPE_SERIE, TYPE_TITRE_UNIFORME, TYPE_INDEXINT, TYPE_AUTHPERSO);
     $concepts_ids = $authority->get_concepts_ids();
     $nb_result = 0;
     if (count($concepts_ids)) {
         $query = 'select count(distinct num_object, type_object) from index_concept where num_concept in (' . implode(',', $concepts_ids) . ') and type_object in (' . implode(',', $types_needed) . ')';
         $nb_result = pmb_mysql_result(pmb_mysql_query($query, $dbh), 0, 0);
     }
     $tab->set_nb_results($nb_result);
     if (!$quoi && $nb_result) {
         // Si $quoi n'est pas valorisé et qu'on a des résultats, on valorise $quoi avec cet onglet
         $quoi = $tab->get_name();
     }
     if ($nb_result && $quoi == $tab->get_name()) {
         // On définit les filtres
         $filter = array('name' => 'common_indexed_authorities_by_types', 'label' => $msg['authority_tabs_common_indexed_authorities_by_types']);
         $tab->set_filters(array($filter));
         $groups = array();
         $query = 'select count(distinct num_object) as nb, type_object, id_authperso, authperso_name from index_concept left join authperso_authorities on num_object = id_authperso_authority and type_object = ' . TYPE_AUTHPERSO . ' left join authperso on id_authperso = authperso_authority_authperso_num where num_concept in (' . implode(',', $concepts_ids) . ') and type_object in (' . implode(',', $types_needed) . ') group by type_object, id_authperso';
         $result = pmb_mysql_query($query, $dbh);
         if ($result && pmb_mysql_num_rows($result)) {
             while ($row = pmb_mysql_fetch_object($result)) {
                 if ($row->type_object == TYPE_AUTHPERSO && !isset($groups[1000 + $row->id_authperso])) {
                     $groups[1000 + $row->id_authperso] = array('label' => $row->authperso_name, 'nb_results' => $row->nb);
                 } else {
                     if (!isset($groups[$row->type_object])) {
                         $groups[$row->type_object] = array('label' => authority::get_type_label_from_type_id(index_concept::get_aut_table_type_from_type($row->type_object)), 'nb_results' => $row->nb);
                     }
                 }
             }
         }
         if (count($groups)) {
             // On trie le tableau
             uasort($groups, array('authority_tabs', '_sort_groups_by_label'));
             $tab->add_groups($filter['name'], array('label' => $filter['label'], 'elements' => $groups));
             $filter_values = $tab->get_filter_values($filter['name']);
             $authpersos_needed = array();
             if ($filter_values && count($filter_values)) {
                 $types_needed = array();
                 foreach ($filter_values as $value) {
                     if ($value > 1000) {
                         if (!in_array(TYPE_AUTHPERSO, $types_needed)) {
                             $types_needed[] = TYPE_AUTHPERSO;
                         }
                         $authpersos_needed[] = $value - 1000;
                     } else {
                         $types_needed[] = $value;
                     }
                 }
             }
             $query = 'select SQL_CALC_FOUND_ROWS num_object, type_object, authperso_authority_authperso_num';
             $query .= ' from index_concept left join authperso_authorities on num_object = id_authperso_authority and type_object = ' . TYPE_AUTHPERSO;
             $query .= ' where num_concept in (' . implode(',', $concepts_ids) . ') and type_object in (' . implode(',', $types_needed) . ')';
             // si on a des filtres sur des authorités persos
             if (count($authpersos_needed)) {
                 $query .= ' and (authperso_authority_authperso_num is null or authperso_authority_authperso_num in (' . implode(',', $authpersos_needed) . '))';
             }
             $query .= authority_tabs::get_limit();
             // on lance la requête
             $result = pmb_mysql_query($query, $dbh);
             $records_ids = array();
             if ($result && pmb_mysql_num_rows($result)) {
                 while ($row = pmb_mysql_fetch_object($result)) {
                     $authority = new authority(0, $row->num_object, index_concept::get_aut_table_type_from_type($row->type_object));
                     $records_ids[] = $authority->get_id();
                 }
             }
             $nb_filtered_results = pmb_mysql_result(pmb_mysql_query('select FOUND_ROWS()'), 0, 0);
             $tab->set_nb_filtered_results($nb_filtered_results);
             $tab->set_contents($records_ids);
         }
     }
 }