[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / afficher_objets / exec / visiteurs.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2010 *
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
15 include_spip('inc/presentation');
16
17 // Constante pour le nombre d'auteurs par page.
18 @define('MAX_AUTEURS_PAR_PAGE', 30);
19 @define('AUTEURS_MIN_REDAC', "0minirezo,1comite,5poubelle");
20 @define('AUTEURS_DEFAUT', '');
21 // decommenter cette ligne et commenter la precedente
22 // pour que l'affichage par defaut soit les visiteurs
23 #@define('AUTEURS_DEFAUT', '!');
24
25 // http://doc.spip.org/@exec_auteurs_dist
26 function exec_visiteurs_dist()
27 {
28 $tri = preg_replace('/\W/', '', _request('tri'));
29 if (!$tri) $tri='nom';
30 $statut = _request('statut');
31 if (!$statut) $statut = "!" . AUTEURS_MIN_REDAC;
32 $debut = intval(_request('debut'));
33
34 $recherche = NULL;
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']));
42 else {
43 $recherche = "aut.id_auteur=0"; // rien trouve !
44 }
45 }
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);
48 }
49
50
51 // http://doc.spip.org/@exec_auteurs_args
52 function exec_auteurs_args($statut, $tri, $debut, $recherche=NULL, $trouve='', $cherche='')
53 {/*
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);
57
58
59 $recherche = auteurs_tranches(afficher_n_auteurs($auteurs), $debut, $lettre, $tri, $statut, MAX_AUTEURS_PAR_PAGE, $nombre_auteurs,$cherche);
60
61 if ($cherche){
62 if (count($auteurs))
63 $recherche = "<h3>". _T('info_resultat_recherche')." &laquo;$cherche&raquo;</h3>" . $recherche;
64 else
65 $recherche = "<h3>". _T('info_recherche_auteur_zero',array('cherche_auteur'=>$cherche))."</h3>" . $recherche;
66 }
67
68 }
69
70 if (_AJAX) {
71 ajax_retour($recherche); //ecrire en id='auteurs' ci-dessous
72 } else {
73 */
74 pipeline('exec_init',array('args'=>array('exec'=>'auteurs'),'data'=>''));
75
76 $visiteurs = !statut_min_redac($statut);
77 $commencer_page = charger_fonction('commencer_page', 'inc');
78 echo $commencer_page(
79 $visiteurs ? _T('info_visiteurs') : _T('info_auteurs'),
80 "auteurs","redacteurs");
81
82 echo bandeau_auteurs($tri, $visiteurs);
83
84 echo $trouve, "<div class='nettoyeur'></div>";
85
86 $contexte = $_GET;
87 $contexte['nb'] = MAX_AUTEURS_PAR_PAGE;
88 if (substr($statut,0,1)!=='!')
89 $contexte['statut'] = explode(',',$statut);
90 else {
91 $statut = substr($statut,1);
92 $statut = explode(',',$statut);
93 $statut = sql_allfetsel('DISTINCT statut','spip_auteurs',sql_in('statut',$statut,'NOT'));
94 $contexte['statut'] = array_map('reset',$statut);
95 }
96
97 if ($GLOBALS['visiteur_session']['statut']=='0minirezo'){
98 // n'exclure que les articles a la poubelle des compteurs
99 $contexte['filtre_statut_articles'] = array('poubelle');
100 }
101 else {
102 // exclure les articles a la poubelle, en redac ou refuse des compteurs
103 $contexte['filtre_statut_articles'] = array('prepa','poubelle','refuse');
104 }
105
106 $lister_objets = charger_fonction('lister_objets','inc');
107 echo $lister_objets('auteurs',$contexte);
108
109 # echo "<div id='auteurs'>", $recherche, "</div>";
110 echo pipeline('affiche_milieu',array('args'=>array('exec'=>'auteurs'),'data'=>''));
111 echo fin_gauche(), fin_page();
112 # }
113 }
114
115 // http://doc.spip.org/@bandeau_auteurs
116 function bandeau_auteurs($tri, $visiteurs)
117 {
118 global $connect_id_auteur, $connect_statut, $connect_toutes_rubriques;
119
120 $ret = debut_gauche("auteurs",true) . debut_boite_info(true);
121
122 if ($visiteurs)
123 $ret .= "\n<p class='arial1'>"._T('info_gauche_visiteurs_enregistres'). '</p>';
124 else
125 $ret .= "\n<p class='arial1'>"._T('info_gauche_auteurs'). '</p>';
126
127 if ($connect_statut == '0minirezo')
128 $ret .= "\n<p class='arial1'>". _T('info_gauche_auteurs_exterieurs') . '</p>';
129
130 $ret .= fin_boite_info(true);
131
132 $ret .= pipeline('affiche_gauche',array('args'=>array('exec'=>'auteurs'),'data'=>''));
133
134 if ($connect_statut == '0minirezo') {
135
136 if ($connect_toutes_rubriques)
137 $res = icone_horizontale(_T('icone_creer_nouvel_auteur'), generer_url_ecrire("auteur_infos", 'new=oui'), "auteur-24.gif", "creer.gif", false);
138 else $res = '';
139
140 $res .= icone_horizontale(_T('icone_informations_personnelles'), generer_url_ecrire("auteur_infos","id_auteur=$connect_id_auteur"), "fiche-perso-24.gif","rien.gif", false);
141
142 if (avoir_visiteurs(true)) {
143 if ($visiteurs)
144 $res .= icone_horizontale (_T('icone_afficher_auteurs'), generer_url_ecrire("auteurs"), "auteur-24.gif", "", false);
145 else
146 $res .= icone_horizontale (_T('icone_afficher_visiteurs'), generer_url_ecrire("visiteurs"), "auteur-24.gif", "", false);
147 }
148 $ret .= bloc_des_raccourcis($res);
149 }
150 $ret .= creer_colonne_droite('auteurs',true);
151 $ret .= pipeline('affiche_droite',array('args'=>array('exec'=>'auteurs'),'data'=>''));
152 $ret .= debut_droite('',true);
153
154 $ret .= "\n<br />";
155 $ret .= gros_titre($visiteurs ? _T('info_visiteurs') : _T('info_auteurs'),'',false);
156 $ret .= "\n<br />";
157 return $ret;
158 }
159
160 // http://doc.spip.org/@statut_min_redac
161 function statut_min_redac($statut)
162 {
163 $x = (!$statut)
164 || (strpos($statut, "0minirezo")!==false)
165 || (strpos($statut, "1comite")!==false);
166
167 return $statut[0] =='!' ? !$x : $x;
168 }
169
170 // http://doc.spip.org/@lettres_d_auteurs
171 function lettres_d_auteurs($query, $debut, $max_par_page, $tri)
172 {
173 $auteurs = $lettre = array();
174 $lettres_nombre_auteurs = 0;
175 $lettre_prec ="";
176 $nombre_auteurs = 0;
177 $query = sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY']);
178
179 while ($auteur = sql_fetch($query)) {
180 if ($nombre_auteurs>=$debut AND $nombre_auteurs<$debut+$max_par_page) {
181 $auteur['restreint'] = sql_countsel("spip_auteurs_rubriques", "id_auteur=".$auteur['id_auteur']);
182
183 $auteurs[] = $auteur;
184 }
185
186 if ($tri == 'nom') {
187 $premiere_lettre = strtoupper(spip_substr(corriger_typo($auteur['nom']),0,1));
188 if ($premiere_lettre != $lettre_prec) {
189 $lettre[$premiere_lettre] = $nombre_auteurs;
190 }
191 $lettre_prec = $premiere_lettre;
192 }
193 $nombre_auteurs++;
194 }
195 return array($auteurs, $lettre, $nombre_auteurs, $debut);
196 }
197
198 // http://doc.spip.org/@auteurs_tranches
199 function auteurs_tranches($auteurs, $debut, $lettre, $tri, $statut, $max_par_page, $nombre_auteurs, $cherche='')
200 {
201 global $spip_lang_right;
202
203 $arg = ($statut ? ("&statut=" .urlencode($statut)) : '')
204 . ($cherche ? ("&recherche=" . urlencode($cherche)) : '');
205
206 $res ="\n<tr class='titrem'>"
207 . "\n<th style='width: 20px'>";
208
209 if ($tri=='statut')
210 $res .= http_img_pack('admin-12.gif','', " class='lang'");
211 else {
212 $t = _T('lien_trier_statut');
213 $res .= auteurs_href(http_img_pack('admin-12.gif', $t, "class='lang'"),"tri=statut$arg", " title=\"$t\"");
214 }
215
216 $res .= "</th><th style='width: 20px'></th><th>";
217
218 if ($tri=='nom')
219 $res .= '<b>'._T('info_nom').'</b>';
220 else
221 $res .= auteurs_href(_T('info_nom'), "tri=nom$arg", " title='"._T('lien_trier_nom'). "'");
222
223 $res .= "</th><th>";
224
225 if ($tri=='site')
226 $res .= '<b>'._T('info_site').'</b>';
227 else
228 $res .= auteurs_href(_T('info_site'), "tri=site$arg", " title='"._T('info_site'). "'");
229
230 $res .= '</th><th>';
231
232 $col = statut_min_redac($statut) ? _T('info_articles') : _T('message') ;
233
234 if ($tri=='nombre')
235 $res .= '<b>' . $col .'</b>';
236 else
237 $res .= auteurs_href($col, "tri=nombre$arg", " title=\""._T('lien_trier_nombre_articles'). '"');
238
239 $res .= "</th></tr>\n";
240
241 if ($nombre_auteurs > $max_par_page) {
242 $res .= "\n<tr class='' ><td colspan='5'><div class='arial1 tranches'>";
243
244 for ($j=0; $j < $nombre_auteurs; $j+=$max_par_page) {
245 if ($j > 0) $res .= " | ";
246
247 if ($j == $debut)
248 $res .= "<b>$j</b>";
249 else if ($j > 0)
250 $res .= auteurs_href($j, "tri=$tri$arg&debut=$j");
251 else
252 $res .= auteurs_href('0', "tri=$tri$arg");
253 if ($debut > $j AND $debut < $j+$max_par_page){
254 $res .= " | <b>$debut</b>";
255 }
256 }
257
258 if ($tri == 'nom') {
259 $res .= "</div><div>\n";
260 $val_prev = 0;
261 foreach ($lettre as $key => $val) {
262 if ($val == $debut)
263 $res .= "<b>$key</b>\n";
264 else {
265 if ($debut>$val_prev && $debut<$val)
266 $res .= "<b>..</b> ";
267 $res .= auteurs_href($key, "tri=$tri$arg&debut=$val") . "\n";
268 }
269 $val_prev = $val;
270 }
271 $res .= "</div></td></tr>\n";
272 }
273 }
274
275 $nav = '';
276 $debut_suivant = $debut + $max_par_page;
277 if ($debut_suivant < $nombre_auteurs OR $debut > 0) {
278 $nav = "\n<table id='bas' style='width: 100%' border='0'>"
279 . "\n<tr class=''><td align='left'>";
280
281 if ($debut > 0) {
282 $debut_prec = max($debut - $max_par_page, 0);
283 $nav .= auteurs_href('&lt;&lt;&lt;',"tri=$tri&debut=$debut_prec$arg");
284 }
285 $nav .= "</td><td style='text-align: $spip_lang_right'>";
286 if ($debut_suivant < $nombre_auteurs) {
287 $nav .= auteurs_href('&gt;&gt;&gt;',"tri=$tri&debut=$debut_suivant&$arg");
288 }
289 $nav .= "</td></tr></table>\n";
290 }
291
292 return debut_cadre('liste','auteur-24.gif','','','lesauteurs')
293 . "\n<br /><table class='arial2' cellpadding='2' cellspacing='0' style='width: 100%; border: 0px;'>\n"
294 . $res
295 . $auteurs
296 . "</table>\n<br />"
297 . $nav
298 . fin_cadre();
299 }
300
301 // http://doc.spip.org/@auteurs_href
302 function auteurs_href($clic, $args='', $att='')
303 {
304 $h = generer_url_ecrire('auteurs', $args);
305 $a = 'auteurs';
306
307 if (_SPIP_AJAX === 1 )
308 $att .= ("\nonclick=" . ajax_action_declencheur($h,$a));
309
310 return "<a href='$h#$a'$att>$clic</a>";
311 }
312
313
314 // http://doc.spip.org/@requete_auteurs
315 function requete_auteurs($tri, $statut, $recherche=NULL)
316 {
317 global $connect_statut, $spip_lang, $connect_id_auteur;
318
319 //
320 // Construire la requete
321 //
322
323 // si on n'est pas minirezo, ignorer les auteurs sans article
324 // sauf les admins, toujours visibles.
325
326 // limiter les statuts affiches
327 if ($connect_statut == '0minirezo') {
328 if ($statut[0]=='!') {
329 $statut = substr($statut,1); $not = "NOT";
330 } else $not = '';
331 $visit = !statut_min_redac($statut);
332 $statut = preg_split('/\W+/', $statut);
333 $sql_visible = sql_in("aut.statut", $statut, $not);
334 } else {
335 $sql_visible = "(
336 aut.statut = '0minirezo'
337 OR aut.id_auteur=$connect_id_auteur
338 OR " . sql_in('art.statut', array('prop', 'publie'))
339 . ')';
340 $visit = false;
341 }
342
343 $sql_sel = '';
344 $join = $visit ?
345 ""
346 :
347 (strpos($sql_visible,'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)"):"");
348
349 // tri
350 switch ($tri) {
351 case 'nombre':
352 $sql_sel = "COUNT(lien.id_article) AS compteur";
353 $sql_order = 'compteur DESC, unom';
354 $join = $visit ?
355 "LEFT JOIN spip_forum AS lien ON aut.id_auteur=lien.id_auteur"
356 : ("LEFT JOIN spip_auteurs_articles AS lien ON aut.id_auteur=lien.id_auteur"
357 . (strpos($sql_visible,'art.statut')?" LEFT JOIN spip_articles AS art ON (lien.id_article = art.id_article)":""));
358 break;
359
360 case 'site':
361 $sql_order = 'site, unom';
362 break;
363
364 case 'statut':
365 $sql_order = 'statut, unom';
366 break;
367
368 case 'nom':
369 default:
370 $sql_sel = sql_multi ("nom", $spip_lang);
371 $sql_order = "multi";
372 }
373 //
374 // La requete de base est tres sympa
375 // (pour les visiteurs, ca postule que les messages concernent des articles)
376 return array('SELECT' =>
377 array_diff(
378 array(
379 "aut.id_auteur AS id_auteur",
380 "aut.statut AS statut",
381 "aut.nom_site AS site",
382 "aut.nom AS nom",
383 "UPPER(aut.nom) AS unom",
384 $sql_sel),array('',null)),
385 'FROM' => "spip_auteurs AS aut $join",
386 'WHERE' => $sql_visible . ($recherche
387 ? " AND $recherche"
388 : ''),
389 'GROUP BY' => "aut.statut, aut.nom_site, aut.nom, aut.id_auteur",
390 'ORDER BY' => $sql_order);
391 }
392
393 // http://doc.spip.org/@afficher_n_auteurs
394 function afficher_n_auteurs($auteurs) {
395
396 $res = '';
397 $formater_auteur = charger_fonction('formater_auteur', 'inc');
398 foreach ($auteurs as $row) {
399
400 list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur']);
401
402 $res .= "\n<tr class='tr_liste'>"
403 . "\n<td>"
404 . $s
405 . "</td><td class='arial1'>"
406 . $mail
407 . "</td><td class='verdana1'>"
408 . $nom
409 . ((isset($row['restreint']) AND $row['restreint'])
410 ? (" &nbsp;<small>"._T('statut_admin_restreint')."</small>")
411 : '')
412 ."</td><td class='arial1'>"
413 . $w
414 . "</td><td class='arial1'>"
415 . $p
416 . "</td></tr>\n";
417 }
418 return $res;
419 }
420 ?>