1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2007 * |
---|
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
---|
8 | * * |
---|
9 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
---|
10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
14 | include_spip('inc/actions'); |
---|
15 | include_spip('inc/mots'); |
---|
16 | include_spip('public/assembler'); //pour recuperer_fond |
---|
17 | |
---|
18 | // http://doc.spip.org/@inc_editer_mot_dist |
---|
19 | function inc_editer_mot($objet, $id_objet, $cherche_mot, $select_groupe, $flag,$simplifie='non') { |
---|
20 | global $options, $connect_statut, $spip_lang_rtl, $spip_lang_right, $spip_lang; |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | if (!($options == 'avancees' AND $GLOBALS['meta']["articles_mots"] != 'non')) |
---|
25 | return ''; |
---|
26 | |
---|
27 | $visible = ($cherche_mot OR ($flag === 'ajax')); |
---|
28 | |
---|
29 | /////////////////////////// |
---|
30 | // MODIFICATION |
---|
31 | /////////////////////////// |
---|
32 | |
---|
33 | if($simplifie!='oui') $simplifie=(_request('simplifie')=='oui')?'oui':'non'; |
---|
34 | |
---|
35 | global $choses_possibles; |
---|
36 | include(_DIR_PLUGIN_MOTSPARTOUT."/mots_partout_choses.php"); |
---|
37 | |
---|
38 | if ($objet == 'syndic') $table=$objet; |
---|
39 | else $table=$objet.'s'; |
---|
40 | |
---|
41 | //bloc de modification du core : on utilise chose possibles et pas des if |
---|
42 | if (isset($choses_possibles[$table])) { |
---|
43 | if ($choses_possibles[$table]['id_chose']) |
---|
44 | $table_id = $choses_possibles[$table]['id_chose']; |
---|
45 | else $table_id = 'id_'.$objet; |
---|
46 | if ($choses_possibles[$table]['objet']) $objet=$choses_possibles[$table]['objet']; |
---|
47 | else $objet = substr($table,0,-1); |
---|
48 | if ($choses_possibles[$table]['url_base']) $url_base=$choses_possibles[$table]['url_base']; |
---|
49 | else $url_base = $table; |
---|
50 | if (is_array($id_objet)){ |
---|
51 | foreach($id_objet as $key => $value) |
---|
52 | if ($key=='id_objet') $_id_objet=$id_objet['id_objet']; |
---|
53 | else $url_base.=$value; |
---|
54 | $id_objet=$_id_objet; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | //Ceci n'est plus vraiment utile dans le cas de la squeletisation |
---|
60 | $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot")); |
---|
61 | |
---|
62 | if (!($nombre_mots = $cpt['n'])) { |
---|
63 | if (!$flag) return; |
---|
64 | $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui'")); |
---|
65 | |
---|
66 | if (!$cpt['n']) return; |
---|
67 | } |
---|
68 | ////////////////////// |
---|
69 | |
---|
70 | |
---|
71 | //preparation de l'utilisation de recuperer_fond a ce niveau |
---|
72 | //definition du contexte |
---|
73 | |
---|
74 | /*$squel=recup_squelette_motspartout("listemot_".$table); |
---|
75 | $contexte_liste=array("table"=>$table,"id_objet"=>$id_objet,"visible"=>$visible,"simplifie"=>$simplifie); |
---|
76 | |
---|
77 | $res=recuperer_fond($squel,$contexte_liste);*/ |
---|
78 | |
---|
79 | |
---|
80 | // |
---|
81 | // Preparer l'affichage |
---|
82 | // |
---|
83 | |
---|
84 | // La reponse |
---|
85 | $reponse = ''; |
---|
86 | if ($flag AND $cherche_mot) { |
---|
87 | $reindexer = false; |
---|
88 | list($reponse, $nouveaux_mots) = recherche_mot_cle($cherche_mot, $select_groupe, $objet, $id_objet, $table, $table_id, $url_base); |
---|
89 | foreach($nouveaux_mots as $nouv_mot) { |
---|
90 | if ($nouv_mot!='x') { |
---|
91 | $reindexer |= inserer_mot("spip_mots_$table", $table_id, $id_objet, $nouv_mot); |
---|
92 | } |
---|
93 | } |
---|
94 | if ($reindexer AND ($GLOBALS['meta']['activer_moteur'] == 'oui')) { |
---|
95 | include_spip("inc/indexation"); |
---|
96 | marquer_indexer("spip_$table", $id_objet); |
---|
97 | } |
---|
98 | } |
---|
99 | $form = afficher_mots_cles($flag, $objet, $id_objet, $table, $table_id, $url_base, $visible,$simplifie); |
---|
100 | |
---|
101 | if($simplifie!='oui'){ |
---|
102 | |
---|
103 | // Envoyer titre + div-id + formulaire + fin |
---|
104 | if ($flag){ |
---|
105 | if ($visible) |
---|
106 | $bouton = bouton_block_visible("lesmots".$id_objet); |
---|
107 | else |
---|
108 | $bouton = bouton_block_invisible("lesmots".$id_objet); |
---|
109 | } else $bouton = ''; |
---|
110 | |
---|
111 | $bouton .= _T('titre_mots_cles').aide ("artmots"); |
---|
112 | |
---|
113 | $res = '<div> </div>' // place pour l'animation pendant Ajax |
---|
114 | . debut_cadre_enfonce("mot-cle-24.gif", true, "", $bouton) |
---|
115 | . $reponse |
---|
116 | . $form |
---|
117 | . fin_cadre_enfonce(true); |
---|
118 | |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | $res = '<div> </div>' // place pour l'animation pendant Ajax |
---|
123 | . $reponse |
---|
124 | . $form; |
---|
125 | } |
---|
126 | return ajax_action_greffe("editer_mot-$id_objet", $res); |
---|
127 | } |
---|
128 | |
---|
129 | // http://doc.spip.org/@inserer_mot |
---|
130 | function inserer_mot($table, $table_id, $id_objet, $id_mot) |
---|
131 | { |
---|
132 | $result = spip_num_rows(spip_query("SELECT id_mot FROM $table WHERE id_mot=$id_mot AND $table_id=$id_objet")); |
---|
133 | |
---|
134 | if (!$result) { |
---|
135 | spip_query("INSERT INTO $table (id_mot,$table_id) VALUES ($id_mot, $id_objet)"); |
---|
136 | } |
---|
137 | return $result; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | // http://doc.spip.org/@recherche_mot_cle |
---|
142 | function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, $table_id, $url_base) |
---|
143 | { |
---|
144 | ///////////////////// |
---|
145 | //MODIFICATION |
---|
146 | ///////////////////// |
---|
147 | /*if ($table == 'articles') $ou = _T('info_l_article'); |
---|
148 | else*/ if ($table == 'breves') $ou = _T('info_la_breve'); |
---|
149 | else if ($table == 'rubriques') $ou = _T('info_la_rubrique'); |
---|
150 | else $ou = _T('info_l_'.$objet); |
---|
151 | ///////////////////// |
---|
152 | $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe=$id_groupe"); |
---|
153 | |
---|
154 | $table_mots = array(); |
---|
155 | $table_ids = array(); |
---|
156 | while ($row = spip_fetch_array($result)) { |
---|
157 | $table_ids[] = $row['id_mot']; |
---|
158 | $table_mots[] = $row['titre']; |
---|
159 | } |
---|
160 | |
---|
161 | $nouveaux_mots = array(); |
---|
162 | $res = ''; |
---|
163 | |
---|
164 | foreach (preg_split("/ *[,;] */", $cherche_mots) as $cherche_mot) { |
---|
165 | if ($cherche_mot) { |
---|
166 | $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids); |
---|
167 | $res .= "<p>" . debut_boite_info(true); |
---|
168 | if (!$resultat) { |
---|
169 | $res .= "<b>"._T('info_non_resultat', array('cherche_mot' => $cherche_mot))."</b><br /></p>"; |
---|
170 | } |
---|
171 | else if (count($resultat) == 1) { |
---|
172 | $nouveaux_mots[] = $resultat[0]; |
---|
173 | $row = spip_fetch_array(spip_query("SELECT titre FROM spip_mots WHERE id_mot=$resultat[0]")); |
---|
174 | $res .= "<b>"._T('info_mot_cle_ajoute')." $ou : </b><br /><ul>"; |
---|
175 | $res .= "<li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($row['titre'])."</span></b></span></li>\n"; |
---|
176 | $res .= "</ul>"; |
---|
177 | } |
---|
178 | else $res .= affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base); |
---|
179 | |
---|
180 | /* if (autoriser('modifier','groupemots',$id_groupe)) { |
---|
181 | $titre = rawurlencode($cherche_mot); |
---|
182 | $res .= "<div style='width: 200px;'>"; |
---|
183 | $res .= icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&id_groupe=$id_groupe&ajouter_id_article=$id_objet&table=$table&table_id=$table_id&titre=$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false); |
---|
184 | $res .= "</div> "; |
---|
185 | } |
---|
186 | */ |
---|
187 | |
---|
188 | $res .= fin_boite_info(true) . "</p>"; |
---|
189 | } |
---|
190 | } |
---|
191 | return array($res, $nouveaux_mots); |
---|
192 | } |
---|
193 | |
---|
194 | // http://doc.spip.org/@afficher_mots_cles |
---|
195 | function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible,$simplifie='non') |
---|
196 | { |
---|
197 | global $spip_lang_rtl, $spip_lang, $spip_lang_right, $connect_statut, $connect_toutes_rubriques; |
---|
198 | |
---|
199 | |
---|
200 | $les_mots = array(); |
---|
201 | $id_groupes_vus = array(); |
---|
202 | $groupes_vus = array(); |
---|
203 | $result = spip_query("SELECT mots.id_mot, mots.titre, mots.descriptif, mots.id_groupe FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot ORDER BY mots.type, mots.titre"); |
---|
204 | if (spip_num_rows($result) > 0) { |
---|
205 | |
---|
206 | $tableau= array(); |
---|
207 | |
---|
208 | //Dans le cas du form simplifie on ne mets pas l'icone |
---|
209 | if($simplifie!='oui') |
---|
210 | $cle = http_img_pack('petite-cle.gif', "", "width='23' height='12'"); |
---|
211 | |
---|
212 | $ret = generer_url_retour($url_base, $table_id."=".$id_objet."&simplifie=".$simplifie."#mots-".$id_objet); |
---|
213 | while ($row = spip_fetch_array($result)) { |
---|
214 | |
---|
215 | $id_mot = $row['id_mot']; |
---|
216 | $titre_mot = $row['titre']; |
---|
217 | $descriptif_mot = $row['descriptif']; |
---|
218 | $id_groupe = $row['id_groupe']; |
---|
219 | |
---|
220 | $id_groupes_vus[] = $id_groupe; |
---|
221 | $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret"); |
---|
222 | |
---|
223 | //Dans le cas du form simplifie on ne mets pas l'icone |
---|
224 | if($simplifie!='oui') |
---|
225 | $vals= array("<a href='$url'>$cle</a>"); |
---|
226 | else $vals=array(); |
---|
227 | |
---|
228 | |
---|
229 | $row_groupe = spip_fetch_array(spip_query("SELECT titre, unseul, obligatoire, minirezo, comite FROM spip_groupes_mots WHERE id_groupe = $id_groupe")); |
---|
230 | // On recupere le typo_mot ici, et non dans le mot-cle lui-meme; sinon bug avec arabe |
---|
231 | |
---|
232 | $type_mot = typo($row_groupe['titre']); |
---|
233 | $flag_groupe = ($flag_editable AND |
---|
234 | ((($connect_statut === '1comite') AND $row_groupe['comite'] === 'oui') OR (($connect_statut === '0minirezo') AND $row_groupe['minirezo'] === 'oui'))); |
---|
235 | |
---|
236 | |
---|
237 | //TODO : il faut gérer a ce ce niveau le formulaire de mot remplace dans le cas du formulaire simplifie |
---|
238 | if (($row_groupe['unseul'] == "oui") AND $flag_groupe) { |
---|
239 | $vals[]= formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet); |
---|
240 | } else { |
---|
241 | $vals[]= "<a href='$url'>".typo($titre_mot)."</a>"; |
---|
242 | } |
---|
243 | |
---|
244 | //Dans le cas du form simplifie on ne mets pas le lien vers le groupe de mots |
---|
245 | if ($simplifie!='oui') { |
---|
246 | if ($connect_toutes_rubriques ) |
---|
247 | $vals[]= "<a href='" . generer_url_ecrire("mots_type","id_groupe=$id_groupe") . "'>$type_mot</a>"; |
---|
248 | |
---|
249 | else $vals[] = $type_mot; |
---|
250 | } |
---|
251 | |
---|
252 | if ($flag_editable){ |
---|
253 | if ($flag_groupe) { |
---|
254 | |
---|
255 | //formulaire simplifie : |
---|
256 | //on ne mets pas la chaine de traduction de l'action supprimer ( on aura donc juste la croix rouge et le lien) |
---|
257 | $s=""; |
---|
258 | if ($simplifie!='oui') { |
---|
259 | $s .= _T('info_retirer_mot'). " "; |
---|
260 | } |
---|
261 | |
---|
262 | $s.= http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"); |
---|
263 | $s = ajax_action_auteur('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base."&simplifie=".$simplifie, "$table_id=$id_objet", array($s,''),"&id_objet=$id_objet&objet=$objet"); |
---|
264 | } else $s = " "; |
---|
265 | $vals[] = $s; |
---|
266 | } else $vals[]= ""; |
---|
267 | |
---|
268 | $tableau[] = $vals; |
---|
269 | |
---|
270 | $les_mots[] = $id_mot; |
---|
271 | } |
---|
272 | |
---|
273 | if($simplifie!='oui'){ |
---|
274 | $largeurs = array('25', '', '', ''); |
---|
275 | }else{ |
---|
276 | $largeurs = array(); |
---|
277 | } |
---|
278 | $styles = array('arial11', 'arial2', 'arial2', 'arial1'); |
---|
279 | |
---|
280 | $res = "\n<div class='liste'>" |
---|
281 | . "\n<table width='100%' cellpadding='3' cellspacing='0' border='0'>"; |
---|
282 | |
---|
283 | if($simplifie=='oui'){ |
---|
284 | $res.="<tr><td colspan='2'>"._T('motspartout:liste_mots_clefs')."</td></tr>"; |
---|
285 | } |
---|
286 | //TODO : a passer avec recuperer_fond |
---|
287 | $res.= afficher_liste($largeurs, $tableau, $styles) |
---|
288 | . "</table></div>"; |
---|
289 | } else $res =''; |
---|
290 | |
---|
291 | if ($flag_editable) |
---|
292 | $res .= formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet,$simplifie); |
---|
293 | |
---|
294 | return $res; |
---|
295 | } |
---|
296 | |
---|
297 | // http://doc.spip.org/@formulaire_mot_remplace |
---|
298 | function formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet) |
---|
299 | { |
---|
300 | $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe = $id_groupe ORDER by titre"); |
---|
301 | |
---|
302 | $s = ''; |
---|
303 | |
---|
304 | while ($row_autres = spip_fetch_array($result)) { |
---|
305 | $id = $row_autres['id_mot']; |
---|
306 | $le_titre_mot = supprimer_tags(typo($row_autres['titre'])); |
---|
307 | $selected = ($id == $id_mot) ? " selected='selected'" : ""; |
---|
308 | $s .= "\n<option value='$id'$selected> $le_titre_mot</option>"; |
---|
309 | } |
---|
310 | |
---|
311 | $ancre = "valider_groupe_".$id_groupe."_obj_".$id_objet; |
---|
312 | // forcer le recalcul du noeud car on est en Ajax |
---|
313 | $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; |
---|
314 | |
---|
315 | $corps = "<select name='nouv_mot' onchange=\"$jscript1\"" |
---|
316 | . " class='fondl spip_xx-small' style='width:90px;'>" |
---|
317 | . $s |
---|
318 | . "</select>" |
---|
319 | . "<span >\n " ; |
---|
320 | |
---|
321 | $t = _T('bouton_changer'); |
---|
322 | |
---|
323 | return ajax_action_post('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet",$corps, $t, " class='fondo spip_xx-small visible_au_chargement' id='$ancre'", "", "&id_objet=$id_objet&objet=$objet"); |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | // http://doc.spip.org/@formulaire_mots_cles |
---|
328 | function formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet,$simplifie='non') { |
---|
329 | |
---|
330 | |
---|
331 | global $connect_statut, $spip_lang, $spip_lang_right, $spip_lang_rtl; |
---|
332 | |
---|
333 | //Yoann |
---|
334 | if(!$table) $table="articles"; //nous évite d'avoir des plantages |
---|
335 | //TODO a tester en enlevant ca |
---|
336 | //FIN YOANN |
---|
337 | |
---|
338 | if ($les_mots) { |
---|
339 | $nombre_mots_associes = count($les_mots); |
---|
340 | $les_mots = join($les_mots, ","); |
---|
341 | } else { |
---|
342 | $les_mots = "0"; |
---|
343 | $nombre_mots_associes = 0; |
---|
344 | } |
---|
345 | $cond_id_groupes_vus = "0"; |
---|
346 | if ($id_groupes_vus) $cond_id_groupes_vus = join(",",$id_groupes_vus); |
---|
347 | |
---|
348 | |
---|
349 | //$res.=$table."-".$objet.$id_objet.$simplifie; |
---|
350 | //return $res; |
---|
351 | |
---|
352 | $query="SELECT id_groupe,unseul,obligatoire,titre, ".creer_objet_multi ("titre", $spip_lang)." FROM spip_groupes_mots WHERE ".$table." = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND (unseul != 'oui' OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus))) AND id_parent =0 ORDER BY multi"; |
---|
353 | |
---|
354 | $result_groupes = spip_query($query); |
---|
355 | |
---|
356 | |
---|
357 | |
---|
358 | $nb_groupes = spip_num_rows(spip_query("SELECT * FROM spip_groupes_mots WHERE ".$table." = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND obligatoire = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus)")); |
---|
359 | |
---|
360 | |
---|
361 | if($simplifie!='oui'){ |
---|
362 | if ($visible) |
---|
363 | $res = debut_block_visible("lesmots".$id_objet); |
---|
364 | else if ($nb_groupes > 0) { |
---|
365 | $res = debut_block_visible("lesmots".$id_objet); |
---|
366 | // vilain hack pour redresser un triangle |
---|
367 | $couche_a_redresser = $GLOBALS['numero_block']['lesmots'.$id_objet]; |
---|
368 | if ($GLOBALS['browser_layer']) |
---|
369 | $res .= http_script(" |
---|
370 | triangle = findObj('triangle$couche_a_redresser'); |
---|
371 | if (triangle) triangle.src = '" . _DIR_IMG_PACK . "deplierbas$spip_lang_rtl.gif';"); |
---|
372 | } else $res = debut_block_invisible("lesmots".$id_objet); |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | if ($nombre_mots_associes > 3) { |
---|
377 | $res .= "<div align='right' class='arial1'>" |
---|
378 | . ajax_action_auteur('editer_mot', "$id_objet,-1,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array(_T('info_retirer_mots'),''),"&id_objet=$id_objet&objet=$objet") |
---|
379 | . "</div><br />\n"; |
---|
380 | } |
---|
381 | |
---|
382 | |
---|
383 | // |
---|
384 | |
---|
385 | // Afficher un menu par groupe de mots |
---|
386 | $ajouter =''; |
---|
387 | while ($row = spip_fetch_array($result_groupes)) { |
---|
388 | |
---|
389 | if ($menu = menu_mots($row, $id_groupes_vus, $les_mots,$id_objet,$table)) { |
---|
390 | $id_groupe = $row['id_groupe']; |
---|
391 | list($corps, $clic) = $menu; |
---|
392 | |
---|
393 | $ajouter .= ajax_action_post('editer_mot', |
---|
394 | "$id_objet,,$table,$table_id,$objet", |
---|
395 | $url_base, |
---|
396 | "$table_id=$id_objet", |
---|
397 | $corps, |
---|
398 | $clic, |
---|
399 | " class='visible_au_chargement fondo spip_xx-small' id='valider_groupe_".$id_groupe."_obj_".$id_objet."'", "", |
---|
400 | "&id_objet=$id_objet&objet=$objet&select_groupe=$id_groupe&simplifie=$simplifie"); |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | if ($ajouter) { |
---|
405 | if( $simplifie!='oui') |
---|
406 | $message = "<span class='verdana1'><b>"._T('titre_ajouter_mot_cle')."</b></span>\n"; |
---|
407 | |
---|
408 | $res .= "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>" |
---|
409 | . $ajouter |
---|
410 | ."</div>\n" ; |
---|
411 | } |
---|
412 | |
---|
413 | if($simplifie!='oui'){ |
---|
414 | if (autoriser('modifier','groupemots')) { |
---|
415 | $titre = _request('cherche_mot') |
---|
416 | ? "&titre=".rawurlencode(_request('cherche_mot')) : ''; |
---|
417 | $bouton_ajouter = icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet&simplifie=".$simplifie)), "mot-cle-24.gif", "creer.gif", false) |
---|
418 | . "\n"; |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | |
---|
426 | if ($message OR $bouton_ajouter) { |
---|
427 | $res .= "<div style='width:170px;'>$message |
---|
428 | <br />$bouton_ajouter</div>\n"; |
---|
429 | } |
---|
430 | |
---|
431 | if($simplifie!='oui'){ |
---|
432 | $res.= fin_block(); |
---|
433 | } |
---|
434 | |
---|
435 | return $res; |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | // http://doc.spip.org/@menu_mots |
---|
440 | function menu_mots($row, $id_groupes_vus, $les_mots, $cle_objet='',$table="articles") |
---|
441 | { |
---|
442 | $rand = rand(0,10000); # pour antifocus & ajax |
---|
443 | |
---|
444 | $id_groupe = $row['id_groupe']; |
---|
445 | |
---|
446 | $query="SELECT id_mot, type, titre FROM spip_mots WHERE id_groupe =$id_groupe " . ($les_mots ? "AND id_mot NOT IN ($les_mots) " : '') . "ORDER BY type, titre"; |
---|
447 | |
---|
448 | $result = spip_query($query); |
---|
449 | |
---|
450 | // MODIFICATION |
---|
451 | //dans le cas ou on a pas de mots clefs associes au groupe (principe de l'arborescence) |
---|
452 | //on va prendre les sous-groupe comme etant signe d'affichage |
---|
453 | $n = spip_num_rows($result); |
---|
454 | if (!$n) { |
---|
455 | $cpt =spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_groupes_mots WHERE id_parent=$id_groupe")); |
---|
456 | if(!$cpt['n']) return ''; |
---|
457 | } |
---|
458 | //FIN |
---|
459 | |
---|
460 | $titre = textebrut(typo($row['titre'])); |
---|
461 | $titre_groupe = entites_html($titre); |
---|
462 | $unseul = $row['unseul'] == 'oui'; |
---|
463 | $obligatoire = $row['obligatoire']=='oui' AND !in_array($id_groupe, $id_groupes_vus); |
---|
464 | |
---|
465 | $res = ''; |
---|
466 | $ancre = "valider_groupe_".$id_groupe."_obj_".$cle_objet; |
---|
467 | |
---|
468 | // forcer le recalcul du noeud car on est en Ajax |
---|
469 | $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; |
---|
470 | $jscript2 = "if(!antifocus_mots['$rand-$id_groupe']){this.value='';antifocus_mots['$rand-$id_groupe']=true;}"; |
---|
471 | |
---|
472 | if ($n > 50) { |
---|
473 | $jscript = "onfocus=\"$jscript1 $jscript2\""; |
---|
474 | |
---|
475 | if ($obligatoire) |
---|
476 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#E86519;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
477 | else if ($unseul) |
---|
478 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#cccccc;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
479 | else |
---|
480 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; ' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
481 | |
---|
482 | $res .= "<input type='hidden' name='select_groupe' value='$id_groupe' /> "; |
---|
483 | return array($res, _T('bouton_chercher')); |
---|
484 | } else { |
---|
485 | |
---|
486 | $jscript = "onchange=\"$jscript1\""; |
---|
487 | |
---|
488 | if ($obligatoire) |
---|
489 | $res .= "<select name='nouv_mot' size='1' style='width: 180px; background-color:#E86519;' class='fondl' $jscript>"; |
---|
490 | else if ($unseul) |
---|
491 | $res .= "<select name='nouv_mot' size='1' style='width: 180px; background-color:#cccccc;' class='fondl' $jscript>"; |
---|
492 | else |
---|
493 | $res .= "<select name='nouv_mot' size='1' style='width: 180px; ' class='fondl' $jscript>"; |
---|
494 | |
---|
495 | //on a le groupe de mots de base |
---|
496 | $res .= "\n<option value='x' style='font-variant: small-caps;'>$titre</option>"; |
---|
497 | |
---|
498 | //on boucle sur les mots du groupe de base |
---|
499 | while($row = spip_fetch_array($result)) { |
---|
500 | $res .= "\n<option value='" .$row['id_mot'] . |
---|
501 | "'> " . |
---|
502 | textebrut(typo($row['titre'])) . |
---|
503 | "</option>"; |
---|
504 | } |
---|
505 | |
---|
506 | } |
---|
507 | |
---|
508 | |
---|
509 | //ARBORESCENCE : on va rajouter dans le select les sous-groupes ainsi que leurs mots clefs |
---|
510 | $res.=select_sous_menu_groupe_mots($id_groupe,$table); //gestion de la hiérarchie des mots clefs |
---|
511 | $res .= "</select> "; |
---|
512 | |
---|
513 | return array($res, _T('bouton_choisir')); |
---|
514 | } |
---|
515 | |
---|
516 | |
---|
517 | |
---|
518 | // http://doc.spip.org/@select_sous_menu_groupe_mots |
---|
519 | function select_sous_menu_groupe_mots($id_groupe,$table='articles',$niveau=0){ |
---|
520 | //fonction recursive qui permet de recuperer larborescence des groupes de mots et les mots |
---|
521 | |
---|
522 | global $spip_lang,$connect_statut,$cond_id_groupes_vus; |
---|
523 | |
---|
524 | |
---|
525 | $query="SELECT id_groupe,titre, ".creer_objet_multi ("titre", $spip_lang)." FROM spip_groupes_mots WHERE `".$table."` = 'oui' AND ".substr($connect_statut,1)." = 'oui' ".($cond_id_groupes_vus?" AND (unseul != 'oui' OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus)) )":"")." AND id_parent=".$id_groupe." ORDER BY multi"; |
---|
526 | |
---|
527 | |
---|
528 | //boucle sur les sous groupes |
---|
529 | |
---|
530 | $result_sous_groupes = spip_query($query); |
---|
531 | |
---|
532 | |
---|
533 | while ($row = spip_fetch_array($result_sous_groupes)) { |
---|
534 | $res .= "\n<option value='" .$row['id_groupe'] . |
---|
535 | "'>".str_repeat(" ",$niveau) . |
---|
536 | textebrut(typo($row['titre'])) . |
---|
537 | "</option>"; |
---|
538 | //BOUCLES sur les mots de chaque sous groupe |
---|
539 | $result = spip_query("SELECT id_mot, type, titre,".creer_objet_multi ("titre", $spip_lang)." FROM spip_mots WHERE id_groupe =".$row['id_groupe']." ORDER BY type, titre"); |
---|
540 | |
---|
541 | while($row2 = spip_fetch_array($result)) { |
---|
542 | $res .= "\n<option value='" .$row2['id_mot'] . |
---|
543 | "'>".str_repeat(" ",$niveau)." ->" . |
---|
544 | textebrut(typo($row2['titre'])) . |
---|
545 | "</option>"; |
---|
546 | } |
---|
547 | |
---|
548 | $res.=select_sous_menu_groupe_mots($row['id_groupe'],$table,$niveau+1); |
---|
549 | } |
---|
550 | return $res; |
---|
551 | } |
---|
552 | |
---|
553 | |
---|
554 | /* code commenté en attendant d'avoir la fonctionnalité des squelettes pour l'affichage des mots clefs |
---|
555 | function recup_squelette_motspartout($squel){ |
---|
556 | |
---|
557 | if($fond=find_in_path($squel)) return $fond; |
---|
558 | else {//on va aller chercher l'interface générale |
---|
559 | $squel="fond/listemot_general"; |
---|
560 | return find_in_path($squel); |
---|
561 | } |
---|
562 | |
---|
563 | }*/ |
---|
564 | |
---|
565 | |
---|
566 | |
---|
567 | ?> |
---|