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