PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/admin_mots-cles/inc/amocles_administrateurs_liste.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 390 lines | 247 code | 68 blank | 75 comment | 55 complexity | 43a376510f7503371f555f1814cf800d MD5 | raw file
  1. <?php
  2. // inc/amocles_administrateurs_liste.php
  3. // $LastChangedRevision$
  4. // $LastChangedBy$
  5. // $LastChangedDate$
  6. /*****************************************************
  7. Copyright (C) 2007-2008 Christian PAULUS
  8. cpaulus@quesaco.org - http://www.quesaco.org/
  9. /*****************************************************
  10. This file is part of Amocles.
  11. Amocles is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. Amocles is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with Amocles; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. /*****************************************************
  23. Ce fichier est un des composants de Amocles.
  24. Amocles est un programme libre, vous pouvez le redistribuer et/ou le modifier
  25. selon les termes de la Licence Publique Generale GNU publiee par
  26. la Free Software Foundation (version 2 ou bien toute autre version ulterieure
  27. choisie par vous).
  28. Amocles est distribue car potentiellement utile, mais SANS AUCUNE GARANTIE,
  29. ni explicite ni implicite, y compris les garanties de commercialisation ou
  30. d'adaptation dans un but specifique. Reportez-vous a la Licence Publique Generale GNU
  31. pour plus de details.
  32. Vous devez avoir recu une copie de la Licence Publique Generale GNU
  33. en meme temps que ce programme ; si ce n'est pas le cas, ecrivez a la
  34. Free Software Foundation, Inc.,
  35. 59 Temple Place, Suite 330, Boston, MA 02111-1307, etats-Unis.
  36. *****************************************************/
  37. /***************************************************************************\
  38. * Certains elements ici sont directement extraits de SPIP 192c
  39. * *
  40. * Copyright (c) 2001-2007 *
  41. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  42. * *
  43. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  44. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  45. \***************************************************************************/
  46. if (!defined("_ECRIRE_INC_VERSION")) return;
  47. include_spip('inc/presentation');
  48. include_spip('inc/actions');
  49. if(!amocles_spip_est_inferieur_193())
  50. {
  51. include_spip('inc/presenter_liste');
  52. }
  53. // L'ajout d'un auteur se fait par mini-navigateur dans la fourchette:
  54. define('_SPIP_SELECT_MIN_AUTEURS', 10); // en dessous: balise Select
  55. define('_SPIP_SELECT_MAX_AUTEURS', 100); // au-dessus: saisie + return
  56. // CP-20071105 - Adapte de inc_editer_auteurs_dist()
  57. function amocles_liste_admins_groupes_mots($type, $id, $flag, $cherche_auteur, $ids, $titre_boite, $script_edit_objet) {
  58. global $options;
  59. $cond_les_auteurs = $arg_ajax = "";
  60. $aff_les_auteurs = afficher_auteurs_objet($type, $id, $flag, $cond_les_auteurs, $script_edit_objet, $arg_ajax);
  61. if ($flag AND $options == 'avancees') {
  62. $futurs = amocles_ajouter_auteurs_objet($type, $id, $cond_les_auteurs, $script_edit_objet, $arg_ajax);
  63. } else $futurs = '';
  64. $ldap = isset($GLOBALS['meta']['ldap_statut_import']) ?
  65. $GLOBALS['meta']['ldap_statut_import'] : '';
  66. return amocles_editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $aff_les_auteurs, $futurs, $ldap,$titre_boite,$script_edit_objet, $arg_ajax);
  67. }
  68. // CP-20071105 - Adapte de editer_auteurs_objet()
  69. function amocles_editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $les_auteurs, $futurs, $statut, $titre_boite,$script_edit_objet, $arg_ajax)
  70. {
  71. global $spip_lang_left, $spip_lang_right, $options;
  72. $bouton_creer_auteur = $GLOBALS['connect_toutes_rubriques'];
  73. $clic = _T('icone_creer_auteur');
  74. //
  75. // complement de action/editer_auteurs.php pour notifier la recherche d'auteur
  76. //
  77. if ($cherche_auteur) {
  78. $reponse = ""
  79. . "<div style='text-align: $spip_lang_left'>"
  80. . debut_boite_info(true)
  81. . rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
  82. . fin_boite_info(true)
  83. . '</div>';
  84. } else $reponse ='';
  85. $reponse .= $les_auteurs;
  86. //
  87. // Ajouter un auteur
  88. //
  89. $res = '';
  90. if ($flag && ($options == 'avancees')) {
  91. $res = "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
  92. . $futurs
  93. ."</div>\n"
  94. . $res;
  95. }
  96. // petit triangle a deplier
  97. $bouton = ""
  98. . (
  99. (!$flag)
  100. ? ''
  101. :
  102. (
  103. ($flag === 'ajax')
  104. ? bouton_block_visible("auteurs$type")
  105. : bouton_block_invisible("auteurs$type")
  106. )
  107. )
  108. . $titre_boite
  109. ;
  110. $res = '<div><div>&nbsp;</div>' // pour placer le gif patienteur
  111. . debut_cadre_enfonce("", true, "", $bouton)
  112. . $reponse
  113. . (
  114. ($flag === 'ajax')
  115. ? debut_block_visible("auteurs$type")
  116. : debut_block_invisible("auteurs$type")
  117. )
  118. . $res
  119. . fin_block()
  120. . fin_cadre_enfonce(true)
  121. . '</div>'
  122. ;
  123. if(version_compare($GLOBALS['spip_version_code'],'1.9300','>=')) {
  124. return ajax_action_greffe("editer_auteurs-$id", "", $res);
  125. }
  126. return ajax_action_greffe("editer_auteurs-$id", $res);
  127. }
  128. // http://doc.spip.org/@determiner_auteurs_objet
  129. function determiner_auteurs_objet($type, $id, $cond='', $limit='')
  130. {
  131. $les_auteurs = array();
  132. if (!preg_match(',^[a-z]*$,',$type)) {
  133. return $les_auteurs;
  134. }
  135. $sql_in = implode(",", amocles_admins_groupes_mots_get_ids());
  136. $result = spip_query("SELECT id_auteur FROM spip_auteurs WHERE id_auteur IN ($sql_in) "
  137. . ($limit? " LIMIT $limit": '')
  138. );
  139. return $result;
  140. }
  141. // http://doc.spip.org/@determiner_non_auteurs
  142. function determiner_non_auteurs($type, $id, $cond_les_auteurs, $order)
  143. {
  144. $cond = '';
  145. $res = determiner_auteurs_objet($type, $id, $cond_les_auteurs);
  146. if (spip_num_rows($res)<200){ // probleme de performance au dela, on ne filtre plus
  147. while ($row = spip_fetch_array($res))
  148. $cond .= ",".$row['id_auteur'];
  149. }
  150. if (strlen($cond))
  151. $cond = "id_auteur NOT IN (" . substr($cond,1) . ') AND ';
  152. return spip_query("SELECT * FROM spip_auteurs WHERE $cond" . "statut!='5poubelle' AND statut!='6forum' AND statut!='nouveau' ORDER BY $order");
  153. }
  154. // http://doc.spip.org/@rechercher_auteurs_objet
  155. function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
  156. {
  157. if (!$ids) {
  158. return "<strong>"._T('texte_aucun_resultat_auteur', array('cherche_auteur' => $cherche_auteur)).".</strong><br />";
  159. }
  160. elseif ($ids == -1) {
  161. return "<strong>"._T('texte_trop_resultats_auteurs', array('cherche_auteur' => $cherche_auteur))."</strong><br />";
  162. }
  163. elseif (preg_match('/^\d+$/',$ids)) {
  164. $row = spip_fetch_array(spip_query("SELECT nom FROM spip_auteurs WHERE id_auteur=$ids"));
  165. return "<strong>"._T('texte_ajout_auteur')."</strong><br /><ul><li><span class='verdana1 spip_small'><strong><span class='spip_medium'>".typo($row['nom'])."</span></strong></span></li></ul>";
  166. }
  167. else {
  168. $ids = preg_replace('/[^0-9,]/','',$ids); // securite
  169. $result = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur IN ($ids) ORDER BY nom");
  170. $res = "<strong>"
  171. . _T('texte_plusieurs_articles', array('cherche_auteur' => $cherche_auteur))
  172. . "</strong><br />"
  173. . "<ul class='verdana1'>";
  174. while ($row = spip_fetch_array($result)) {
  175. $id_auteur = $row['id_auteur'];
  176. $nom_auteur = $row['nom'];
  177. $email_auteur = $row['email'];
  178. $bio_auteur = $row['bio'];
  179. $res .= "<li><strong>".typo($nom_auteur)."</strong>";
  180. if ($email_auteur) $res .= " ($email_auteur)";
  181. $res .= " | "
  182. . ajax_action_auteur('editer_auteurs', "$id,$type,$id_auteur",$script_edit_objet,"id_{$type}=$id", array(_T('lien_ajouter_auteur')),$arg_ajax);
  183. if (trim($bio_auteur)) {
  184. $res .= "<br />".couper(propre($bio_auteur), 100)."\n";
  185. }
  186. $res .= "</li>\n";
  187. }
  188. $res .= "</ul>";
  189. return $res;
  190. }
  191. }
  192. // CP-20071105 - Adapte de afficher_auteurs_objet()
  193. function afficher_auteurs_objet($type, $id, $flag_editable, $cond_les_auteurs, $script_edit, $arg_ajax)
  194. {
  195. global $connect_statut, $options, $connect_id_auteur, $spip_display;
  196. $les_auteurs = array();
  197. if (!preg_match(',^[a-z]*$,',$type)) return $les_auteurs;
  198. $result = determiner_auteurs_objet($type, $id, $cond_les_auteurs);
  199. $cpt = spip_num_rows($result);
  200. $tmp_var = "amocles_administrateurs-$id";
  201. $nb_aff = floor(1.5 * _TRANCHES);
  202. if ($cpt > $nb_aff) {
  203. $nb_aff = _TRANCHES;
  204. //$tranches = afficher_tranches_requete($cpt, $tmp_var, generer_url_ecrire('editer_auteurs',$arg_ajax), $nb_aff);
  205. $tranches = afficher_tranches_requete($cpt, $tmp_var, generer_url_ecrire('amocles_administrateurs', $arg_ajax), $nb_aff);
  206. } else $tranches = '';
  207. $deb_aff = _request($tmp_var);
  208. $deb_aff = ($deb_aff !== NULL ? intval($deb_aff) : 0);
  209. $limit = (($deb_aff < 0) ? '' : "$deb_aff, $nb_aff");
  210. $result = determiner_auteurs_objet($type,$id,$cond_les_auteurs,$limit);
  211. // charger ici meme si pas d'auteurs
  212. // car inc_formater_auteur peut aussi redefinir determiner_non_auteurs qui sert plus loin
  213. if (!$formater_auteur = charger_fonction("formater_auteur_$type", 'inc',true))
  214. $formater_auteur = charger_fonction('formater_auteur', 'inc');
  215. if (!spip_num_rows($result)) return '';
  216. $table = array();
  217. while ($row = spip_fetch_array($result)) {
  218. $id_auteur = $row['id_auteur'];
  219. $vals = $formater_auteur($id_auteur);
  220. // lien retirer auteur
  221. if (
  222. $flag_editable
  223. && ($id_auteur != 1) // ne pas proposer de supprimer admin 1.
  224. && ($connect_id_auteur != $id_auteur || $connect_statut == '0minirezo')
  225. && ($options == 'avancees')
  226. ) {
  227. $vals[] = ajax_action_auteur('amocles_administrateur'
  228. , "$id,$type,-$id_auteur"
  229. , $script_edit
  230. , "id_{$type}=$id"
  231. , array(_T('lien_retirer_auteur')."&nbsp;". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"))
  232. , $arg_ajax);
  233. } else $vals[] = "";
  234. $table[] = $vals;
  235. }
  236. $largeurs = array('14', '', '', '', '', '');
  237. $styles = array('arial11', 'arial2', 'arial11', 'arial11', 'arial11', 'arial1');
  238. $t = afficher_liste($largeurs, $table, $styles);
  239. if ($spip_display != 4)
  240. $t = $tranches
  241. . "<table width='100%' cellpadding='3' cellspacing='0' border='0'>"
  242. . $t
  243. . "</table>";
  244. return ("<div class='liste'>$t</div>\n");
  245. }
  246. // CP-20071105 - Adapte de ajouter_auteurs_objet()
  247. function amocles_ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit, $arg_ajax)
  248. {
  249. if (!$determiner_non_auteurs = charger_fonction('determiner_non_auteurs_'.$type,'inc',true))
  250. $determiner_non_auteurs = 'determiner_non_auteurs';
  251. $query = $determiner_non_auteurs($type, $id, $cond_les_auteurs, "statut, nom");
  252. if (!$num = spip_num_rows($query)) return '';
  253. $js = "findObj_forcer('valider_ajouter_auteur').style.visibility='visible';";
  254. $text = "<span class='verdana1'><strong>"
  255. . _T('titre_cadre_ajouter_auteur')
  256. . "</strong></span>\n";
  257. if ($num <= _SPIP_SELECT_MIN_AUTEURS){
  258. $sel = "$text<select name='nouv_auteur' size='1' style='width:150px;' class='fondl' onchange=\"$js\">" .
  259. objet_auteur_select($query) .
  260. "</select>";
  261. $clic = _T('bouton_ajouter');
  262. } else if ((_SPIP_AJAX < 1) OR ($num >= _SPIP_SELECT_MAX_AUTEURS)) {
  263. $sel = "$text <input type='text' name='cherche_auteur' onclick=\"$js\" class='fondl' value='' size='20' />";
  264. $clic = _T('bouton_chercher');
  265. } else {
  266. $sel = selecteur_auteur_ajax($type, $id, $js, $text);
  267. $clic = _T('bouton_ajouter');
  268. }
  269. return (
  270. ajax_action_post('amocles_administrateur', "$id,$type", $script_edit, "id_{$type}=$id"
  271. , $sel, $clic, "class='fondo visible_au_chargement' id='valider_ajouter_auteur'", "", $arg_ajax)
  272. );
  273. }
  274. // http://doc.spip.org/@objet_auteur_select
  275. function objet_auteur_select($result)
  276. {
  277. global $couleur_claire, $connect_statut ;
  278. $statut_old = $premiere_old = $res = '';
  279. while ($row = spip_fetch_array($result)) {
  280. $id_auteur = $row["id_auteur"];
  281. $nom = $row["nom"];
  282. $email = $row["email"];
  283. $statut = $row["statut"];
  284. $statut=str_replace("0minirezo", _T('info_administrateurs'), $statut);
  285. $statut=str_replace("1comite", _T('info_redacteurs'), $statut);
  286. $statut=str_replace("6visiteur", _T('info_visiteurs'), $statut);
  287. $premiere = strtoupper(substr(trim($nom), 0, 1));
  288. if ($connect_statut != '0minirezo')
  289. if ($p = strpos($email, '@'))
  290. $email = substr($email, 0, $p).'@...';
  291. if ($email)
  292. $email = " ($email)";
  293. if ($statut != $statut_old) {
  294. $res .= "\n<option value=\"x\" />";
  295. $res .= "\n<option value=\"x\" style='background-color: $couleur_claire;'> $statut</option>";
  296. }
  297. if ($premiere != $premiere_old AND ($statut != _T('info_administrateurs') OR !$premiere_old))
  298. $res .= "\n<option value=\"x\" />";
  299. $res .= "\n<option value=\"$id_auteur\">&nbsp;&nbsp;&nbsp;&nbsp;" . supprimer_tags(couper(typo("$nom$email"), 40)) . '</option>';
  300. $statut_old = $statut;
  301. $premiere_old = $premiere;
  302. }
  303. return $res;
  304. }
  305. // CP-20071105 - Adapte de selecteur_auteur_ajax ()
  306. function selecteur_auteur_ajax($type, $id, $js, $text)
  307. {
  308. include_spip('inc/chercher_rubrique');
  309. $url = generer_url_ecrire('selectionner_auteur');
  310. return $text . construire_selecteur($url, $js, 'selection_auteur', 'nouv_auteur', ' type="hidden"');
  311. }
  312. ?>