3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/presentation');
17 // Constante pour le nombre d'auteurs par page.
18 if (!defined('MAX_AUTEURS_PAR_PAGE')) define('MAX_AUTEURS_PAR_PAGE', 30);
19 if (!defined('AUTEURS_MIN_REDAC')) define('AUTEURS_MIN_REDAC', "0minirezo,1comite,5poubelle");
20 if (!defined('AUTEURS_DEFAUT')) define('AUTEURS_DEFAUT', '');
21 // decommenter cette ligne et commenter la precedente
22 // pour que l'affichage par defaut soit les visiteurs
23 #if (!defined('AUTEURS_DEFAUT')) define('AUTEURS_DEFAUT', '!');
25 // http://doc.spip.org/@exec_auteurs_dist
26 function exec_auteurs_dist()
28 $tri = preg_replace('/\W/', '', _request('tri'));
29 if (!$tri) $tri='nom';
30 $statut = _request('statut');
31 if (!$statut) $statut = AUTEURS_DEFAUT
. AUTEURS_MIN_REDAC
;
32 $debut = intval(_request('debut'));
35 if ($cherche = _request('recherche')) {
36 include_spip('inc/rechercher');
37 $tables = liste_des_champs();
38 $tables = array('auteur'=>$tables['auteur']);
39 $recherche = recherche_en_base($cherche, $tables,array('toutvoir'=>true));
40 if ($recherche['auteur'])
41 $recherche = sql_in('aut.id_auteur', array_keys($recherche['auteur']));
43 $recherche = "aut.id_auteur=0"; // rien trouve !
46 $form = formulaire_recherche("auteurs",(($s=_request('statut'))?
"<input type='hidden' name='statut' value='$s' />":""));
47 exec_auteurs_args($statut, $tri, $debut, $recherche,$form, $cherche);
51 // http://doc.spip.org/@exec_auteurs_args
52 function exec_auteurs_args($statut, $tri, $debut, $recherche=NULL, $trouve='', $cherche='')
54 if ($recherche !=='') {
55 list($auteurs, $lettre, $nombre_auteurs, $debut) =
56 lettres_d_auteurs(requete_auteurs($tri, $statut, $recherche), $debut, MAX_AUTEURS_PAR_PAGE
, $tri);
60 $arg = ($statut ?
("&statut=" .urlencode($statut)) : '')
61 . ($cherche ?
("&recherche=" . urlencode($cherche)) : '');
63 $recherche = auteurs_tranches(afficher_n_auteurs($auteurs), $debut, $lettre, $tri, $statut, MAX_AUTEURS_PAR_PAGE
, $nombre_auteurs, $arg);
66 $cherche = htmlspecialchars($cherche);
68 $recherche = "<h3>". _T('info_resultat_recherche')." «$cherche»</h3>" . $recherche;
70 $recherche = "<h3>". _T('info_recherche_auteur_zero',array('cherche_auteur'=>$cherche))."</h3>" . $recherche;
76 ajax_retour($recherche); //ecrire en id='auteurs' ci-dessous
79 pipeline('exec_init',array('args'=>array('exec'=>'auteurs'),'data'=>''));
81 $visiteurs = !statut_min_redac($statut);
82 $commencer_page = charger_fonction('commencer_page', 'inc');
84 $visiteurs ?
_T('info_visiteurs') : _T('info_auteurs'),
85 "auteurs","redacteurs");
87 echo bandeau_auteurs($visiteurs);
89 echo $trouve, "<div class='nettoyeur'></div>";
91 echo "<div id='auteurs'>", $recherche, "</div>";
92 echo pipeline('affiche_milieu',array('args'=>array('exec'=>'auteurs'),'data'=>''));
93 echo fin_gauche(), fin_page();
97 // http://doc.spip.org/@bandeau_auteurs
98 function bandeau_auteurs($visiteurs)
100 global $connect_id_auteur;
102 $ret = debut_gauche("auteurs",true) . debut_boite_info(true);
105 $ret .= "\n<p class='arial1'>"._T('info_gauche_visiteurs_enregistres'). '</p>';
107 $ret .= "\n<p class='arial1'>"._T('info_gauche_auteurs'). '</p>';
109 if (autoriser('voir', 'auteur'))
110 $ret .= "\n<p class='arial1'>". _T('info_gauche_auteurs_exterieurs') . '</p>';
112 $ret .= fin_boite_info(true);
114 $ret .= pipeline('affiche_gauche',array('args'=>array('exec'=>'auteurs'),'data'=>''));
116 if (autoriser('voir', 'auteur')) {
118 if (autoriser('creer', 'auteur'))
119 $res = icone_horizontale(_T('icone_creer_nouvel_auteur'), generer_url_ecrire("auteur_infos", 'new=oui'), "auteur-24.gif", "creer.gif", false);
122 $res .= icone_horizontale(_T('icone_informations_personnelles'), generer_url_ecrire("auteur_infos","id_auteur=$connect_id_auteur"), "fiche-perso-24.gif","rien.gif", false);
124 if (avoir_visiteurs(true)) {
126 $res .= icone_horizontale (_T('icone_afficher_auteurs'), generer_url_ecrire("auteurs", "statut=" . AUTEURS_MIN_REDAC
), "auteur-24.gif", "", false);
128 $res .= icone_horizontale (_T('icone_afficher_visiteurs'), generer_url_ecrire("auteurs","statut=!" . AUTEURS_MIN_REDAC
), "auteur-24.gif", "", false);
130 $ret .= bloc_des_raccourcis($res);
132 $ret .= creer_colonne_droite('auteurs',true);
133 $ret .= pipeline('affiche_droite',array('args'=>array('exec'=>'auteurs'),'data'=>''));
134 $ret .= debut_droite('',true);
137 $ret .= gros_titre($visiteurs ?
_T('info_visiteurs') : _T('info_auteurs'),'',false);
142 // http://doc.spip.org/@statut_min_redac
143 function statut_min_redac($statut)
146 ||
(strpos($statut, "0minirezo")!==false)
147 ||
(strpos($statut, "1comite")!==false);
149 return $statut[0] =='!' ?
!$x : $x;
152 // http://doc.spip.org/@lettres_d_auteurs
153 function lettres_d_auteurs($query, $debut, $max_par_page, $tri)
155 $auteurs = $lettre = array();
156 $lettres_nombre_auteurs = 0;
159 $query = sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY']);
161 while ($auteur = sql_fetch($query)) {
162 if ($nombre_auteurs>=$debut AND $nombre_auteurs<$debut+
$max_par_page) {
163 $auteur['restreint'] = sql_countsel("spip_auteurs_rubriques", "id_auteur=".$auteur['id_auteur']);
165 $auteurs[] = $auteur;
169 $premiere_lettre = strtoupper(spip_substr(corriger_typo($auteur['nom']),0,1));
170 if ($premiere_lettre != $lettre_prec) {
171 $lettre[$premiere_lettre] = $nombre_auteurs;
173 $lettre_prec = $premiere_lettre;
177 return array($auteurs, $lettre, $nombre_auteurs, $debut);
180 // http://doc.spip.org/@auteurs_tranches
181 function auteurs_tranches($auteurs, $debut, $lettre, $tri, $statut, $max_par_page, $nombre_auteurs, $arg='')
183 global $spip_lang_right;
185 $res ="\n<tr class='titrem'>"
186 . "\n<th style='width: 20px'>";
189 $res .= http_img_pack('admin-12.gif','', " class='lang'");
191 $t = _T('lien_trier_statut');
192 $res .= auteurs_href(http_img_pack('admin-12.gif', $t, "class='lang'"),"tri=statut$arg", " title=\"$t\"");
195 $res .= "</th><th style='width: 20px'></th><th>";
198 $res .= '<b>'._T('info_nom').'</b>';
200 $res .= auteurs_href(_T('info_nom'), "tri=nom$arg", " title='"._T('lien_trier_nom'). "'");
205 $res .= '<b>'._T('info_site').'</b>';
207 $res .= auteurs_href(_T('info_site'), "tri=site$arg", " title='"._T('info_site'). "'");
211 $col = statut_min_redac($statut) ?
_T('info_articles') : _T('message') ;
214 $res .= '<b>' . $col .'</b>';
216 $res .= auteurs_href($col, "tri=nombre$arg", " title=\""._T('lien_trier_nombre_articles'). '"');
218 $res .= "</th></tr>\n";
220 if ($nombre_auteurs > $max_par_page) {
221 $res .= "\n<tr class='' ><td colspan='5'><div class='arial1 tranches'>";
223 for ($j=0; $j < $nombre_auteurs; $j+
=$max_par_page) {
224 if ($j > 0) $res .= " | ";
229 $res .= auteurs_href($j, "tri=$tri$arg&debut=$j");
231 $res .= auteurs_href('0', "tri=$tri$arg");
232 if ($debut > $j AND $debut < $j+
$max_par_page){
233 $res .= " | <b>$debut</b>";
238 $res .= "</div><div>\n";
240 foreach ($lettre as $key => $val) {
242 $res .= "<b>$key</b>\n";
244 if ($debut>$val_prev && $debut<$val)
245 $res .= "<b>..</b> ";
246 $res .= auteurs_href($key, "tri=$tri$arg&debut=$val") . "\n";
250 $res .= "</div></td></tr>\n";
255 $debut_suivant = $debut +
$max_par_page;
256 if ($debut_suivant < $nombre_auteurs OR $debut > 0) {
257 $nav = "\n<table id='bas' style='width: 100%' border='0'>"
258 . "\n<tr class=''><td align='left'>";
261 $debut_prec = max($debut - $max_par_page, 0);
262 $nav .= auteurs_href('<<<',"tri=$tri&debut=$debut_prec$arg");
264 $nav .= "</td><td style='text-align: $spip_lang_right'>";
265 if ($debut_suivant < $nombre_auteurs) {
266 $nav .= auteurs_href('>>>',"tri=$tri&debut=$debut_suivant&$arg");
268 $nav .= "</td></tr></table>\n";
271 return debut_cadre('liste','auteur-24.gif','','','lesauteurs')
272 . "\n<br /><table class='arial2' cellpadding='2' cellspacing='0' style='width: 100%; border: 0px;'>\n"
280 // http://doc.spip.org/@auteurs_href
281 function auteurs_href($clic, $args='', $att='')
283 $h = generer_url_ecrire('auteurs', $args);
286 if (_SPIP_AJAX
=== 1 )
287 $att .= ("\nonclick=" . ajax_action_declencheur($h,$a));
289 return "<a href='$h#$a'$att>$clic</a>";
293 // http://doc.spip.org/@requete_auteurs
294 function requete_auteurs($tri, $statut, $recherche=NULL)
296 global $connect_id_auteur;
298 // si on n'est pas minirezo, ignorer les auteurs sans article
299 // sauf les admins, toujours visibles.
301 // limiter les statuts affiches
302 if (autoriser('voir', 'auteur')) {
303 if ($statut[0]=='!') {
304 $statut = substr($statut,1); $not = "NOT";
306 $visit = !statut_min_redac($statut);
307 $statut = preg_split('/\W+/', $statut);
308 $where = sql_in("aut.statut", $statut, $not);
311 aut.statut = '0minirezo'
312 OR aut.id_auteur=$connect_id_auteur
313 OR " . sql_in('art.statut', array('prop', 'publie'))
317 if ($recherche) $where .= " AND $recherche" ;
318 return requete_auteurs_tri($tri, $where, $visit);
321 function requete_auteurs_tri($tri, $where, $visit=false)
329 (strpos($where,'art.statut')?
("LEFT JOIN spip_auteurs_articles AS lien ON aut.id_auteur=lien.id_auteur" . " LEFT JOIN spip_articles AS art ON (lien.id_article = art.id_article)"):"");
334 $sql_sel = "COUNT(lien.id_article) AS compteur";
335 $sql_order = 'compteur DESC, unom';
337 "LEFT JOIN spip_forum AS lien ON aut.id_auteur=lien.id_auteur"
338 : ("LEFT JOIN spip_auteurs_articles AS lien ON aut.id_auteur=lien.id_auteur"
339 . (strpos($where,'art.statut')?
" LEFT JOIN spip_articles AS art ON (lien.id_article = art.id_article)":""));
343 $sql_order = 'site, unom';
347 $sql_order = 'statut, unom';
352 $sql_sel = sql_multi ("nom", $spip_lang);
353 $sql_order = "multi";
356 // La requete de base est tres sympa
357 // (pour les visiteurs, ca postule que les messages concernent des articles)
358 return array('SELECT' =>
361 "aut.id_auteur AS id_auteur",
362 "aut.statut AS statut",
363 "aut.nom_site AS site",
365 "UPPER(aut.nom) AS unom",
366 $sql_sel),array('',null)),
367 'FROM' => "spip_auteurs AS aut $join",
369 'GROUP BY' => "aut.statut, aut.nom_site, aut.nom, aut.id_auteur",
370 'ORDER BY' => $sql_order);
373 // http://doc.spip.org/@afficher_n_auteurs
374 function afficher_n_auteurs($auteurs) {
377 $formater_auteur = charger_fonction('formater_auteur', 'inc');
378 foreach ($auteurs as $row) {
380 list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur']);
382 $res .= "\n<tr class='tr_liste'>"
385 . "</td><td class='arial1'>"
387 . "</td><td class='verdana1'>"
389 . ((isset($row['restreint']) AND $row['restreint'])
390 ?
(" <small>"._T('statut_admin_restreint')."</small>")
392 ."</td><td class='arial1'>"
394 . "</td><td class='arial1'>"