1 | <?php |
---|
2 | // +-------------------------------------------------+ |
---|
3 | // © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) |
---|
4 | // +-------------------------------------------------+ |
---|
5 | // $Id: term_show.class.php,v 1.22 2015-04-03 11:16:20 jpermanne Exp $ |
---|
6 | // |
---|
7 | // Gestion de l'affichage d'un notice d'un terme du thésaurus |
---|
8 | |
---|
9 | if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access"); |
---|
10 | |
---|
11 | require_once($class_path."/category.class.php"); |
---|
12 | require_once($class_path."/thesaurus.class.php"); |
---|
13 | require_once("$class_path/marc_table.class.php"); |
---|
14 | require_once("$class_path/aut_link.class.php"); |
---|
15 | |
---|
16 | class term_show { |
---|
17 | |
---|
18 | var $base_query; //Paramètres supplémentaires passés dans les URL |
---|
19 | var $term; //Terme à afficher |
---|
20 | var $parent_link; //Nom de la fonction à appeller pour afficher les liens d'action à côté des catégories |
---|
21 | var $url_for_term_show; //URL a rappeller |
---|
22 | var $keep_tilde; |
---|
23 | var $id_thes = 0; |
---|
24 | var $thes; |
---|
25 | |
---|
26 | function term_show($term,$url_for_term_show,$base_query,$parent_link,$keep_tilde=0, $id_thes) { |
---|
27 | |
---|
28 | $this->base_query=$base_query; |
---|
29 | $this->term=$term; |
---|
30 | $this->parent_link=$parent_link; |
---|
31 | $this->url_for_term_show=$url_for_term_show; |
---|
32 | $this->keep_tilde=$keep_tilde; |
---|
33 | $this->id_thes = $id_thes; |
---|
34 | $this->thes = new thesaurus($id_thes); |
---|
35 | } |
---|
36 | |
---|
37 | function has_child($categ_id) { |
---|
38 | |
---|
39 | $requete = "select count(1) from noeuds where num_parent = '".$categ_id."' "; |
---|
40 | $resultat=pmb_mysql_query($requete); |
---|
41 | return pmb_mysql_result($resultat,0,0); |
---|
42 | } |
---|
43 | |
---|
44 | //Récupération du chemin |
---|
45 | function get_categ_lib_($categ_id) { |
---|
46 | global $charset; |
---|
47 | |
---|
48 | $re=""; |
---|
49 | |
---|
50 | //Instanciation de la catégorie |
---|
51 | $r=new category($categ_id); |
---|
52 | //Récupération du chemin |
---|
53 | for ($i=0; $i<count($r->path_table); $i++) { |
---|
54 | if ($re!='') $re.=' - '; |
---|
55 | //Si la catégorie ne commence pas par "~", on affiche le libelle avec un lien pour la recherche sur le terme, sinon on affiche ~ |
---|
56 | if (($r->path_table[$i]['libelle'][0]!='~')||($this->keep_tilde)) |
---|
57 | $re.="<a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r->path_table[$i]['libelle']).'&id_thes='.$r->thes->id_thesaurus.'&'.$this->base_query."\">".htmlentities($r->path_table[$i]['libelle'],ENT_QUOTES,$charset).'</a>'; |
---|
58 | else{ |
---|
59 | $re.='~'; |
---|
60 | } |
---|
61 | } |
---|
62 | if ($re!='') $re.=' - '; |
---|
63 | //Si le libellé de la catégorie ne commence pas par "~", on affiche le libellé avec un lien sinon ~ |
---|
64 | if (($r->libelle[0]!='~')||($this->keep_tilde)) |
---|
65 | $re.="<a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r->libelle).'&id_thes='.$r->thes->id_thesaurus.'&'.$this->base_query."\">".htmlentities($r->libelle,ENT_QUOTES,$charset).'</a>'; |
---|
66 | else{ |
---|
67 | $re.='~'; |
---|
68 | } |
---|
69 | return $re; |
---|
70 | } |
---|
71 | |
---|
72 | function get_categ_lib($categ_id, $categ_libelle,$force_link=false) { |
---|
73 | global $charset; |
---|
74 | |
---|
75 | $r=new category($categ_id); |
---|
76 | |
---|
77 | if($r->is_under_tilde){ |
---|
78 | return "~"; |
---|
79 | } |
---|
80 | |
---|
81 | if ($r->parent_id) { |
---|
82 | $path=$this->get_categ_lib_($r->parent_id); |
---|
83 | } |
---|
84 | |
---|
85 | $same=false; |
---|
86 | if( pmb_strtolower(convert_diacrit($r->libelle)) == pmb_strtolower(convert_diacrit($categ_libelle))){ |
---|
87 | $same=true; |
---|
88 | } |
---|
89 | //if ($r->libelle != $categ_libelle) { |
---|
90 | if (!$same || $force_link) { |
---|
91 | if($same){ |
---|
92 | $re=htmlentities($r->libelle,ENT_QUOTES,$charset); |
---|
93 | }else{ |
---|
94 | $re="<a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r->libelle).'&id_thes='.$r->thes->id_thesaurus.'&'.$this->base_query."\">".htmlentities($r->libelle,ENT_QUOTES,$charset).'</a>'; |
---|
95 | } |
---|
96 | if ($path) $re.=' <font size=1>('.$path.')</font>'; |
---|
97 | } else { |
---|
98 | if ($path) $re=$path; |
---|
99 | } |
---|
100 | return $re; |
---|
101 | } |
---|
102 | |
---|
103 | function is_same_lib($categ_libelle,$categ_id) { |
---|
104 | $r=new category($categ_id); |
---|
105 | if( pmb_strtolower(convert_diacrit($r->libelle)) == pmb_strtolower(convert_diacrit($categ_libelle))){ |
---|
106 | return true; |
---|
107 | }else{ |
---|
108 | return false; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | function show_tree($categ_id,$prefixe,$level,$max_level) { |
---|
113 | |
---|
114 | global $charset; |
---|
115 | global $msg; |
---|
116 | global $lang; |
---|
117 | global $dbh; |
---|
118 | $pl=$this->parent_link; |
---|
119 | global $$pl; |
---|
120 | |
---|
121 | $res=''; |
---|
122 | |
---|
123 | if ($this->has_child($categ_id)&&($level<($max_level))) { |
---|
124 | |
---|
125 | $resultat_2=$this->do_query(4,$categ_id); |
---|
126 | |
---|
127 | while ($r2=pmb_mysql_fetch_object($resultat_2)) { |
---|
128 | if($r2->categ_libelle[0] != "~"){ |
---|
129 | $visible=$pl($r2->categ_id,$r2->categ_see); |
---|
130 | if ($visible["VISIBLE"]) { |
---|
131 | $res.='<font size=2>'.$visible['LINK'].' '.$prefixe." - <a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r2->categ_libelle).'&id_thes='.$this->id_thes.'&'.$this->base_query."\">".htmlentities($r2->categ_libelle,ENT_QUOTES,$charset).'</a></font>'; |
---|
132 | if ($r2->categ_see) { |
---|
133 | $res.='<br /><font size=1> <i>'.$msg['term_show_see'].' '.$this->get_categ_lib($r2->categ_see,$r2->categ_libelle,true); |
---|
134 | //if ($this->is_same_lib($r2->categ_libelle,$r2->categ_see)) $res.=' - '.htmlentities($r2->categ_libelle,ENT_QUOTES,$charset); |
---|
135 | $res.='</i></font>'; |
---|
136 | } |
---|
137 | $res.='<br />'; |
---|
138 | } |
---|
139 | $res.=$this->show_tree($r2->categ_id,$prefixe." - <a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r2->categ_libelle).'&id_thes='.$this->id_thes.'&'.$this->base_query."\">".htmlentities($r2->categ_libelle,ENT_QUOTES,$charset).'</a>',$level+1,$max_level); |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | return $res; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | function get_level($categ_id) { |
---|
148 | $l=0; |
---|
149 | $parent=new category($categ_id); |
---|
150 | $l=count($parent->path_table); |
---|
151 | return $l; |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | function show_notice() { |
---|
156 | |
---|
157 | global $history,$history_thes; |
---|
158 | global $charset; |
---|
159 | global $msg; |
---|
160 | global $dbh; |
---|
161 | global $lang; |
---|
162 | global $thesaurus_mode_pmb; |
---|
163 | $pl=$this->parent_link; |
---|
164 | global $$pl; |
---|
165 | |
---|
166 | $res=''; |
---|
167 | |
---|
168 | if ($history!='') { |
---|
169 | $res.="<a href=\"".$this->url_for_term_show.'?term='.rawurlencode(stripslashes($history)).'&id_thes='.rawurlencode(stripslashes($history_thes)).'&'.$this->base_query."\"><</a> "; |
---|
170 | } |
---|
171 | |
---|
172 | //Récupération des catégories ayant le même libellé |
---|
173 | $resultat_1=$this->do_query(1); |
---|
174 | |
---|
175 | if($thesaurus_mode_pmb == 0){ |
---|
176 | $res.='<b>'.htmlentities($this->term,ENT_QUOTES,$charset).'</b><blockquote>'; |
---|
177 | }else{ |
---|
178 | $res.='<b>'.htmlentities("[".$this->thes->libelle_thesaurus."] ".$this->term,ENT_QUOTES,$charset).'</b><blockquote>'; |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | //Initialisation du tableau des renvois (permet d'éviter d'afficher deux fois un même renvoi, ou un renvoi vers le noeud traité) |
---|
183 | $t_see=array(); |
---|
184 | |
---|
185 | //Pour chaque catégorie ayant le même libellé |
---|
186 | while ($r1=pmb_mysql_fetch_object($resultat_1)) { |
---|
187 | $t_see[$r1->categ_id]=1;//Pour les renvois vers le un noeud traité |
---|
188 | //Lecture du chemin vers la catégorie |
---|
189 | $renvoi=$this->get_categ_lib($r1->categ_id,$this->term).' '; |
---|
190 | //Si la catégorie est une sous catégorie d'une terme "~", alors c'est un renvoi d'un terme orphelin ou on en tient pas compte |
---|
191 | if (($renvoi[0]=='~')&&($r1->categ_see)&&(!$this->keep_tilde)) { |
---|
192 | //Si le renvoi n'existe pas déjà, on l'affiche et on l'enregistre |
---|
193 | if (!$t_see[$r1->categ_see]) { |
---|
194 | $visible=$pl($r1->categ_id,$r1->categ_see); |
---|
195 | if ($visible["VISIBLE"]) |
---|
196 | $res.=$visible["LINK"].' <i>'.$msg['term_show_see'].' </i>'.$this->get_categ_lib($r1->categ_see,$this->term).'<br />'; |
---|
197 | $t_see[$r1->categ_see]=1; |
---|
198 | } |
---|
199 | } else { |
---|
200 | if (($renvoi[0]!='~')||($this->keep_tilde)) { |
---|
201 | //Si la catégorie n'est pas une sous catégorie d'un terme "~", on affiche le chemin $visible=$pl($r1->categ_id,$r1->categ_see); |
---|
202 | $visible=$pl($r1->categ_id,$r1->categ_see); |
---|
203 | if ($visible["VISIBLE"]) { |
---|
204 | $res.=$visible["LINK"].' '.$renvoi.' - <b>'.$r1->categ_libelle.'</b><br />'; |
---|
205 | //Si il y a un renvoi, on l'affiche |
---|
206 | if ($r1->categ_see) { |
---|
207 | $res.='<blockquote>'.$msg['term_show_see'].' '.$this->get_categ_lib($r1->categ_see,$r1->categ_libelle,true); |
---|
208 | //Si c'est le même libellé, on l'ajoute au chemin parent, sans lien |
---|
209 | $res.='</blockquote><br />'; |
---|
210 | } |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | //Si le renvoi ne commence pas par "~" alors on affiche les sous niveaux et les catégories associées |
---|
216 | if (($renvoi[0]!='~')||($this->keep_tilde)) { |
---|
217 | //Affichage des premiers sous niveaux |
---|
218 | $res.='<blockquote>'; |
---|
219 | //Recherche du niveau de la catégorie (0,1 ou supérieur à 1) |
---|
220 | $l=$this->get_level($r1->categ_id); |
---|
221 | //Si le niveau est supérieur à 1, on affiche que deux sous niveaux sinon 3 |
---|
222 | if ($l>1) $max_level=3; else $max_level=2; |
---|
223 | |
---|
224 | //Affichage des n sous premiers niveaux |
---|
225 | $res.=$this->show_tree($r1->categ_id,$this->term,0,$max_level); |
---|
226 | $res.='</blockquote>'; |
---|
227 | |
---|
228 | //Recherche des catégories associées |
---|
229 | $requete = "select count(1) from voir_aussi where voir_aussi.num_noeud_orig = '".$r1->categ_id."' "; |
---|
230 | $nta=pmb_mysql_result(pmb_mysql_query($requete),0,0); |
---|
231 | //Si il y en a |
---|
232 | if ($nta) { |
---|
233 | $res.='<blockquote>'; |
---|
234 | |
---|
235 | $resultat_ta=$this->do_query(2,$r1->categ_id); |
---|
236 | |
---|
237 | $first = 1; |
---|
238 | $res1 = ''; |
---|
239 | while ($r_ta=pmb_mysql_fetch_object($resultat_ta)) { |
---|
240 | $visible=$pl($r_ta->categ_id,$r_ta->categ_see); |
---|
241 | if ($visible["VISIBLE"]) { |
---|
242 | if (!$first) $res1.=", "; else $first=0; |
---|
243 | $res1.=$visible["LINK"]." <a href=\"".$this->url_for_term_show.'?term='.rawurlencode($r_ta->categ_libelle).'&id_thes='.$this->id_thes.'&'.$this->base_query."\">".htmlentities($r_ta->categ_libelle,ENT_QUOTES,$charset).'</a>'; |
---|
244 | } |
---|
245 | } |
---|
246 | if ($res1!='') $res.=''.$msg['term_show_see_also'].'<blockquote><font size=2><i>'.$res1.'</i></font></blockquote>'; |
---|
247 | $res.= '</blockquote>'; |
---|
248 | } |
---|
249 | |
---|
250 | //Recherche des liens d'autorités entre catégories |
---|
251 | $aut_link= new aut_link(AUT_TABLE_CATEG,$r1->categ_id); |
---|
252 | if(count($aut_link->aut_list)){ |
---|
253 | $res1 = array(); |
---|
254 | $source = new marc_list("relationtype_autup"); |
---|
255 | $tab_lib_autup = $source->table; |
---|
256 | $source = new marc_list("relationtype_aut"); |
---|
257 | $tab_lib_aut = $source->table; |
---|
258 | foreach ( $aut_link->aut_list as $val ) { |
---|
259 | if($val["to"] == AUT_TABLE_CATEG){ |
---|
260 | $r_link=$this->do_query(3,$val["to_num"]); |
---|
261 | |
---|
262 | if(pmb_mysql_num_rows($r_link) == 1){ |
---|
263 | $r_link_res=pmb_mysql_fetch_object($r_link); |
---|
264 | $visible=$pl($r_link_res->categ_id,$r_link_res->categ_see); |
---|
265 | $info_thes=""; |
---|
266 | if($r_link_res->thes_id != $this->id_thes){ |
---|
267 | $info_thes="[".$r_link_res->thes_libelle."] "; |
---|
268 | } |
---|
269 | if ($visible["VISIBLE"]) { |
---|
270 | $tmp=$visible["LINK"]." ".htmlentities($info_thes,ENT_QUOTES,$charset).$this->get_categ_lib($r_link_res->categ_id, $this->term,true); |
---|
271 | if($val["flag_reciproc"]){ |
---|
272 | $res1[$tab_lib_autup[$val["type"]]][]=$tmp; |
---|
273 | }else{ |
---|
274 | $res1[$tab_lib_aut[$val["type"]]][]=$tmp; |
---|
275 | } |
---|
276 | } |
---|
277 | } |
---|
278 | } |
---|
279 | } |
---|
280 | if(count($res1)){ |
---|
281 | $res.='<blockquote>'.$msg['aut_link'].' :'; |
---|
282 | foreach ( $res1 as $key => $value ) { |
---|
283 | $res.='<font size=2><i><blockquote>'.htmlentities($key,ENT_QUOTES,$charset).' : '.implode(",",$value).'</blockquote></i></font>'; |
---|
284 | } |
---|
285 | $res.= '</blockquote>'; |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|
290 | $res.= '</blockquote>'; |
---|
291 | return $res; |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | function do_query($mode,$param=""){ |
---|
296 | global $lang; |
---|
297 | $select="SELECT DISTINCT noeuds.id_noeud AS categ_id, "; |
---|
298 | $from="FROM noeuds "; |
---|
299 | $join=" JOIN categories AS catdef ON noeuds.id_noeud = catdef.num_noeud AND catdef.langue = '".addslashes($this->thes->langue_defaut)."' "; |
---|
300 | $where="WHERE 1 "; |
---|
301 | $order="ORDER BY categ_libelle "; |
---|
302 | $limit=""; |
---|
303 | |
---|
304 | if(($lang==$this->thes->langue_defaut) || (in_array($lang, thesaurus::getTranslationsList())===false)){ |
---|
305 | $simple=true; |
---|
306 | }else{ |
---|
307 | $simple=false; |
---|
308 | } |
---|
309 | |
---|
310 | //$select.= "noeuds.num_parent AS categ_parent, "; |
---|
311 | |
---|
312 | |
---|
313 | if($simple){ |
---|
314 | $select.="catdef.libelle_categorie AS categ_libelle, "; |
---|
315 | //$select.= "catdef.note_application as categ_comment, "; |
---|
316 | //$select.= "catdef.index_categorie as index_categorie "; |
---|
317 | }else{ |
---|
318 | $select.="IF (catlg.num_noeud IS NULL, catdef.libelle_categorie, catlg.libelle_categorie) AS categ_libelle, "; |
---|
319 | $join.="LEFT JOIN categories AS catlg ON catdef.num_noeud = catlg.num_noeud AND catlg.langue = '".$lang."' "; |
---|
320 | //$select.= "if (catlg.num_noeud is null, catdef.note_application, catlg.note_application) as categ_comment, "; |
---|
321 | //$select.= "if (catlg.num_noeud is null, catdef.index_categorie, catlg.index_categorie) as index_categorie "; |
---|
322 | } |
---|
323 | |
---|
324 | if($mode == 1){ |
---|
325 | $where.="AND noeuds.num_thesaurus = '".$this->id_thes."' "; |
---|
326 | if($simple){ |
---|
327 | $where.="AND catdef.libelle_categorie = '".addslashes($this->term)."' "; |
---|
328 | }else{ |
---|
329 | $where.="AND (IF (catlg.num_noeud IS NULL, catdef.libelle_categorie = '".addslashes($this->term)."', catlg.libelle_categorie = '".addslashes($this->term)."') ) "; |
---|
330 | } |
---|
331 | }elseif($mode == 2){ |
---|
332 | $from="FROM voir_aussi JOIN noeuds ON noeuds.id_noeud=voir_aussi.num_noeud_dest ";//On écrase l'ancien from car ce n'est pas ce que l'on veut |
---|
333 | $where.="AND voir_aussi.num_noeud_orig = '".$param."' "; |
---|
334 | }elseif($mode == 3){ |
---|
335 | $select.="noeuds.num_thesaurus as thes_id, "; |
---|
336 | $select.="thesaurus.libelle_thesaurus as thes_libelle, "; |
---|
337 | $join.="JOIN thesaurus ON noeuds.num_thesaurus=thesaurus.id_thesaurus "; |
---|
338 | $where.="AND noeuds.id_noeud = '".$param."' "; |
---|
339 | }elseif($mode == 4){ |
---|
340 | $where.="AND noeuds.num_parent = '".$param."' "; |
---|
341 | $limit.="LIMIT 400"; |
---|
342 | } |
---|
343 | |
---|
344 | $select.="noeuds.num_renvoi_voir AS categ_see "; |
---|
345 | |
---|
346 | $requete=$select.$from.$join.$where.$order.$limit; |
---|
347 | return pmb_mysql_query($requete); |
---|
348 | } |
---|
349 | } |
---|
350 | ?> |
---|