diff --git a/ecrire/exec/grouper_mots.php b/ecrire/exec/grouper_mots.php index 4346f9c7daa852f128e53407d02ca589d0e62c66..5e632769f52c2e6e2a98e14b998c1fc8feebdaa7 100644 --- a/ecrire/exec/grouper_mots.php +++ b/ecrire/exec/grouper_mots.php @@ -18,13 +18,15 @@ include_spip('base/abstract_sql'); function exec_grouper_mots_dist() { - return afficher_groupe_mots(intval(_request('id_groupe'))); + $id_groupe = intval(_request('id_groupe')); + $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_mots WHERE id_groupe=$id_groupe")); + if (! ($cpt = $cpt['n'])) return '' ; + return afficher_groupe_mots($id_groupe, $cpt); } // http://doc.spip.org/@afficher_groupe_mots -function afficher_groupe_mots($id_groupe) { - global $connect_statut; - global $spip_lang_right, $couleur_claire, $spip_lang; +function afficher_groupe_mots($id_groupe, $cpt) { + global $connect_statut, $spip_lang_right, $spip_lang; // ceci sert a la fois: // - a construire le nom du parametre d'URL indiquant la tranche @@ -32,17 +34,6 @@ function afficher_groupe_mots($id_groupe) { // tant pour la prochaine tranche que pour le retrait de mot $tmp_var = "editer_mot-$id_groupe"; - $select = 'id_mot, id_groupe, titre, ' - . creer_objet_multi ("titre", $spip_lang); - $from = 'spip_mots'; - $where = "id_groupe=$id_groupe" ; - - $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM $from WHERE $where")); - - if (! ($cpt = $cpt['n'])) return '' ; - - $occurrences = calculer_liens_mots(); - $nb_aff = floor(1.5 * _TRANCHES); if ($cpt > $nb_aff) { @@ -51,13 +42,17 @@ function afficher_groupe_mots($id_groupe) { } else $tranches = ''; - $table = array(); $deb_aff = _request($tmp_var); $deb_aff = ($deb_aff !== NULL ? intval($deb_aff) : 0); - $result = spip_query($q="SELECT $select FROM $from WHERE $where ORDER BY multi" . (($deb_aff < 0) ? '' : " LIMIT $deb_aff, $nb_aff")); + $select = 'id_mot, id_groupe, titre, ' + . creer_objet_multi ("titre", $spip_lang); + $result = spip_query($q="SELECT $select FROM spip_mots WHERE id_groupe=$id_groupe ORDER BY multi" . (($deb_aff < 0) ? '' : " LIMIT $deb_aff, $nb_aff")); + + $table = array(); + $occurrences = calculer_liens_mots($id_groupe); while ($row = spip_fetch_array($result)) { - $table[] = afficher_groupe_mots_boucle($row, $occurrences); + $table[] = afficher_groupe_mots_boucle($row, $occurrences, $cpt); } if ($connect_statut=="0minirezo") { @@ -69,19 +64,17 @@ function afficher_groupe_mots($id_groupe) { $styles = array('arial11', 'arial1'); } - $res = http_img_pack("searching.gif", "*", "style='visibility: hidden; position: absolute; $spip_lang_right: 0px; top: -20px;' id='img_$tmp_var'") + return http_img_pack("searching.gif", "*", "style='visibility: hidden; position: absolute; $spip_lang_right: 0px; top: -20px;' id='img_$tmp_var'") . "<div class='liste'>" . "<table border='0' cellspacing='0' cellpadding='3' width='100%'>" . $tranches . afficher_liste($largeurs, $table, $styles) . "</table>" . "</div>"; - - return $res; } // http://doc.spip.org/@afficher_groupe_mots_boucle -function afficher_groupe_mots_boucle($row, $occurrences) +function afficher_groupe_mots_boucle($row, $occurrences, $total) { global $connect_statut; @@ -136,48 +129,58 @@ function afficher_groupe_mots_boucle($row, $occurrences) $href = "<a href='" . generer_url_ecrire("mots_tous","conf_mot=$id_mot&na=$na&nb=$nb&nr=$nr&ns=$ns&son_groupe=$id_groupe") . "#editer_mot-$id_groupe" . "'>$clic</a>"; - else $href = ajax_action_auteur('editer_mot', "$id_groupe,$id_mot,,,",'grouper_mots', "&id_groupe=$id_groupe", array($clic,'')); + else { + $href = generer_supprimer_mot($id_mot, $id_groupe, $clic, $total); + } + $vals[] = "<div style='text-align:right;'>$href</div>"; } return $vals; } +function generer_supprimer_mot($id_mot, $id_groupe, $clic, $total) +{ + $cont = ($total > 1) + ? '' + : "function(r) {ajax_double(\"editer_mot-$id_groupe\", \"editer_mot-$id_groupe-supprimer\", r)}"; + return ajax_action_auteur('editer_mot', "$id_groupe,$id_mot,,,",'grouper_mots', "&id_groupe=$id_groupe", array($clic,''), '', $cont); +} // // Calculer les nombres d'elements (articles, etc.) lies a chaque mot // // http://doc.spip.org/@calculer_liens_mots -function calculer_liens_mots() +function calculer_liens_mots($id_groupe) { if ($GLOBALS['connect_statut'] =="0minirezo") $aff_articles = "'prepa','prop','publie'"; else $aff_articles = "'prop','publie'"; $articles = array(); - $result_articles = spip_query("SELECT COUNT(*) as cnt, lien.id_mot FROM spip_mots_articles AS lien, spip_articles AS article WHERE article.id_article=lien.id_article AND article.statut IN ($aff_articles) GROUP BY lien.id_mot"); + $result_articles = spip_query("SELECT COUNT(*) as cnt, lien.id_mot FROM spip_mots_articles AS lien, spip_articles AS article, spip_mots AS M WHERE lien.id_mot=M.id_mot AND M.id_groupe=$id_groupe AND article.id_article=lien.id_article AND article.statut IN ($aff_articles) GROUP BY lien.id_mot"); while ($row = spip_fetch_array($result_articles)){ $articles[$row['id_mot']] = $row['cnt']; } $rubriques = array(); - $result_rubriques = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_rubriques AS lien, spip_rubriques AS rubrique WHERE rubrique.id_rubrique=lien.id_rubrique GROUP BY lien.id_mot"); + $result_rubriques = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_rubriques AS lien, spip_mots AS M WHERE lien.id_mot=M.id_mot AND M.id_groupe=$id_groupe GROUP BY lien.id_mot"); while ($row = spip_fetch_array($result_rubriques)){ $rubriques[$row['id_mot']] = $row['cnt']; } $breves = array(); - $result_breves = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_breves AS lien, spip_breves AS breve WHERE breve.id_breve=lien.id_breve AND breve.statut IN ($aff_articles) GROUP BY lien.id_mot"); + $result_breves = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_breves AS lien, spip_breves AS breve, spip_mots AS M WHERE lien.id_mot=M.id_mot AND M.id_groupe=$id_groupe breve.id_breve=lien.id_breve AND breve.statut IN ($aff_articles) GROUP BY lien.id_mot"); while ($row = spip_fetch_array($result_breves)){ $breves[$row['id_mot']] = $row['cnt']; } $syndic = array(); - $result_syndic = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_syndic AS lien, spip_syndic AS syndic WHERE syndic.id_syndic=lien.id_syndic AND syndic.statut IN ($aff_articles) GROUP BY lien.id_mot"); + $result_syndic = spip_query("SELECT COUNT(*) AS cnt, lien.id_mot FROM spip_mots_syndic AS lien, spip_syndic AS syndic, spip_mots AS M WHERE lien.id_mot=M.id_mot AND M.id_groupe=$id_groupe AND syndic.id_syndic=lien.id_syndic AND syndic.statut IN ($aff_articles) GROUP BY lien.id_mot"); while ($row = spip_fetch_array($result_syndic)){ $sites[$row['id_mot']] = $row['cnt']; diff --git a/ecrire/exec/mots_tous.php b/ecrire/exec/mots_tous.php index 16e06403cead9debc5e5e867750ea945385af166..b9b037c967bc4240938285477206f8825282da7c 100644 --- a/ecrire/exec/mots_tous.php +++ b/ecrire/exec/mots_tous.php @@ -120,31 +120,32 @@ while ($row_groupes = spip_fetch_array($result_groupes)) { // // Afficher les mots-cles du groupe // - $supprimer_groupe = afficher_groupe_mots($id_groupe); - echo "<div id='editer_mot-$id_groupe' style='position: relative;'>"; + $groupe = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_mots WHERE id_groupe=$id_groupe")); + $groupe = $groupe['n']; + + echo "<div\nid='editer_mot-$id_groupe' style='position: relative;'>"; // Preliminaire: confirmation de suppression d'un mot lie à qqch // (cf fin de afficher_groupe_mots_boucle executee a l'appel precedent) if ($conf_mot AND $son_groupe==$id_groupe) - echo confirmer_mot($conf_mot, $id_groupe); + echo confirmer_mot($conf_mot, $id_groupe, $groupe); - echo $supprimer_groupe; + if ($groupe) echo afficher_groupe_mots($id_groupe, $groupe); echo "</div>"; - if (acces_mots() AND !$conf_mot){ + if (acces_mots()){ echo "\n<table cellpadding='0' cellspacing='0' border='0' width='100%'>"; echo "<tr>"; echo "<td>"; icone(_T('icone_modif_groupe_mots'), generer_url_ecrire("mots_type","id_groupe=$id_groupe"), "groupe-mot-24.gif", "edit.gif"); echo "</td>"; - if (!$supprimer_groupe) { - echo "<td>"; - icone(_T('icone_supprimer_groupe_mots'), generer_url_ecrire("mots_tous","supp_group=$id_groupe"), "groupe-mot-24.gif", "supprimer.gif"); - echo "</td>"; - echo "<td> </td>"; // Histoire de forcer "supprimer" un peu plus vers la gauche - } + echo "\n<td id=editer_mot-$id_groupe-supprimer", + (!$groupe ? '' : " style='visibility: hidden'"), + ">"; + icone(_T('icone_supprimer_groupe_mots'), generer_url_ecrire("mots_tous","supp_group=$id_groupe"), "groupe-mot-24.gif", "supprimer.gif"); + echo "</td>"; echo "<td>"; echo "<div align='$spip_lang_right'>"; icone(_T('icone_creation_mots_cles'), generer_url_ecrire("mots_edit","new=oui&id_groupe=$id_groupe&redirect=" . generer_url_retour('mots_tous')), "mot-cle-24.gif", "creer.gif"); @@ -164,29 +165,31 @@ while ($row_groupes = spip_fetch_array($result_groupes)) { fin_page(); } -function confirmer_mot ($conf_mot, $son_groupe) +function confirmer_mot ($conf_mot, $son_groupe, $total) { $row = spip_fetch_array(spip_query("SELECT * FROM spip_mots WHERE id_mot=$conf_mot")); + if (!$row) return ""; // deja detruit (acces concurrent etc) + $id_mot = $row['id_mot']; $titre_mot = typo($row['titre']); $type_mot = typo($row['type']); - if (($na = intval($na)) == 1) { + if (($na = intval(_request('na'))) == 1) { $texte_lie = _T('info_un_article')." "; } else if ($na > 1) { $texte_lie = _T('info_nombre_articles', array('nb_articles' => $na)) ." "; } - if (($nb = intval($nb)) == 1) { + if (($nb = intval(_request('nb'))) == 1) { $texte_lie .= _T('info_une_breve')." "; } else if ($nb > 1) { $texte_lie .= _T('info_nombre_breves', array('nb_breves' => $nb))." "; } - if (($ns = intval($ns)) == 1) { + if (($ns = intval(_request('ns'))) == 1) { $texte_lie .= _T('info_un_site')." "; } else if ($ns > 1) { $texte_lie .= _T('info_nombre_sites', array('nb_sites' => $ns))." "; } - if (($nr = intval($nr)) == 1) { + if (($nr = intval(_request('nr'))) == 1) { $texte_lie .= _T('info_une_rubrique')." "; } else if ($nr > 1) { $texte_lie .= _T('info_nombre_rubriques', array('nb_rubriques' => $nr))." "; @@ -195,10 +198,11 @@ function confirmer_mot ($conf_mot, $son_groupe) return debut_boite_info(true) . "<div class='serif'>" . _T('info_delet_mots_cles', array('titre_mot' => $titre_mot, 'type_mot' => $type_mot, 'texte_lie' => $texte_lie)) - . "<p>" - . ajax_action_auteur('editer_mot', "$son_groupe,$id_mot,,,",'grouper_mots', "&id_groupe=$son_groupe", array("<b>" . _T('item_oui') . "</b>", '')) - . ' ' + . "<p style='text-align: right'>" + . generer_supprimer_mot($id_mot, $son_groupe, ("<b>" . _T('item_oui') . "</b>"), $total) + . "<br />\n" . _T('info_oui_suppression_mot_cle') + . '</p>' /* troublant. A refaire avec une visibility . "<LI><B><A href='" . generer_url_ecrire("mots_tous") @@ -209,7 +213,6 @@ function confirmer_mot ($conf_mot, $son_groupe) . _T('info_non_suppression_mot_cle') . "</UL>" */ . "</div>" - . fin_boite_info(true) - . "<br />"; + . fin_boite_info(true); } ?> diff --git a/ecrire/img_pack/layer.js b/ecrire/img_pack/layer.js index 46435c479e929ace35405593dd4530b10c1b8f22..7594c474ec31dadbc33d827aab3b1afcd9b86d5b 100644 --- a/ecrire/img_pack/layer.js +++ b/ecrire/img_pack/layer.js @@ -276,6 +276,14 @@ function retour_id_url(r, Field, jjscript) if (jjscript) jjscript(); } +function ajax_double(id, id2, r) +{ + noeud = document.getElementById(id); + noeud.innerHTML = r; + noeud = document.getElementById(id2); + noeud.style.visibility = "visible"; +} + // ne sert que pour selecteur_rubrique_ajax() dans inc/chercher_rubrique.php function charger_id_url_si_vide (myUrl, myField, jjscript) { var Field = findObj_forcer(myField); // selects the given element diff --git a/ecrire/inc/actions.php b/ecrire/inc/actions.php index ce2d55ff0daac2125bd97a8c927182af6bcf6e57..544ee762c82c80992a12103e5ada0b1ecb90da79 100644 --- a/ecrire/inc/actions.php +++ b/ecrire/inc/actions.php @@ -112,7 +112,7 @@ function redirige_action_auteur($action, $arg, $ret, $gra='', $mode=false, $atts // d'attribut id = $action-$id (cf. AjaxSqueeze dans layer.js) // http://doc.spip.org/@ajax_action_auteur -function ajax_action_auteur($action, $id, $script, $args='', $corps=false, $args_ajax='') +function ajax_action_auteur($action, $id, $script, $args='', $corps=false, $args_ajax='', $fct_ajax='') { $ancre = "$action-" . intval($id); @@ -133,12 +133,14 @@ function ajax_action_auteur($action, $id, $script, $args='', $corps=false, $args // Methode Ajax else { if ($args AND !$args_ajax) $args_ajax = "&$args"; - return redirige_action_auteur($action, + return redirige_action_auteur($action, $id, $action, "script=$script$args_ajax&var_ajaxcharset=utf-8", $corps, - " method='post'\nonsubmit='return AjaxSqueeze(this, \"$ancre\")'"); + (" method='post'\nonsubmit=" + . declencheur_ajax('this', $ancre, $fct_ajax))); + } } @@ -153,16 +155,30 @@ function ajax_action_auteur($action, $id, $script, $args='', $corps=false, $args false); if ($args AND !$args_ajax) $args_ajax = "&$args"; + $ajax = redirige_action_auteur($action, $id, $action, "script=$script$args_ajax&var_ajaxcharset=utf-8"); if ($att) $clic = "\n<div$att>$clic</div>"; - return "<a href='$href'\nonclick='return AjaxSqueeze(\"$ajax\",\"$ancre\");'>$clic</a>"; + return "<a href='$href'\nonclick=" + . declencheur_ajax("\"$ajax\"", $ancre, $fct_ajax) + . ">$clic</a>"; } } +function declencheur_ajax($request, $noeud, $fct_ajax) +{ + return "'return AjaxSqueeze(" + . $request + . ',"' + . $noeud + . '"' + . (!$fct_ajax ? '' : ",$fct_ajax") + . ")'"; +} + // http://doc.spip.org/@determine_upload function determine_upload() {