[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / exec / controle_forum.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 include_spip('inc/forum');
17
18 // http://doc.spip.org/@forum_parent
19 function forum_parent($id_forum) {
20 $row=sql_fetsel("*", "spip_forum", "id_forum=$id_forum AND statut != 'redac'");
21 if (!$row) return '';
22 $id_forum=$row['id_forum'];
23 $forum_id_parent=$row['id_parent'];
24 $forum_id_rubrique=$row['id_rubrique'];
25 $forum_id_article=$row['id_article'];
26 $forum_id_breve=$row['id_breve'];
27 $forum_id_syndic=$row['id_syndic'];
28 $forum_stat=$row['statut'];
29
30 if ($forum_id_article > 0) {
31 $row=sql_fetsel("id_article, titre, statut", "spip_articles", "id_article=$forum_id_article");
32 $id_article = $row['id_article'];
33 $titre = $row['titre'];
34 $statut = $row['statut'];
35 if ($forum_stat == "prive" OR $forum_stat == "privoff") {
36 return array('pref' => _T('item_reponse_article'),
37 'url' => generer_url_ecrire("articles","id_article=$id_article"),
38 'type' => 'id_article',
39 'valeur' => $id_article,
40 'titre' => $titre);
41 } else {
42 $ancre = "forum$id_forum" ;
43 return array('pref' => _T('lien_reponse_article'),
44 'url' => generer_url_entite($id_article,'article', '',$ancre, true),
45 'type' => 'id_article',
46 'valeur' => $id_article,
47 'titre' => $titre,
48 'avant' => "<a href='" . generer_url_ecrire("articles_forum","id_article=$id_article") . "'><span style='color: red'>"._T('lien_forum_public'). "</span></a><br />");
49 }
50 }
51 else if ($forum_id_rubrique > 0) {
52 $row = sql_fetsel("*", "spip_rubriques", "id_rubrique=$forum_id_rubrique");
53 $id_rubrique = $row['id_rubrique'];
54 $titre = $row['titre'];
55 return array('pref' => _T('lien_reponse_rubrique'),
56 'url' => generer_url_entite($id_rubrique,'rubrique','','',true),
57 'type' => 'id_rubrique',
58 'valeur' => $id_rubrique,
59 'titre' => $titre);
60 }
61 else if ($forum_id_syndic > 0) {
62 $row = sql_fetsel("*", "spip_syndic", "id_syndic=$forum_id_syndic");
63 $id_syndic = $row['id_syndic'];
64 $titre = $row['nom_site'];
65 $statut = $row['statut'];
66 return array('pref' => _T('lien_reponse_site_reference'),
67 'url' => generer_url_ecrire("sites","id_syndic=$id_syndic"),
68 'type' => 'id_syndic',
69 'valeur' => $id_syndic,
70 'titre' => $titre);
71 }
72 else if ($forum_id_breve > 0) {
73 $row = sql_fetsel("*", "spip_breves", "id_breve=$forum_id_breve");
74 $id_breve = $row['id_breve'];
75 $date_heure = $row['date_heure'];
76 $titre = $row['titre'];
77 if ($forum_stat == "prive") {
78 return array('pref' => _T('lien_reponse_breve'),
79 'url' => generer_url_ecrire("breves_voir","id_breve=$id_breve"),
80 'type' => 'id_breve',
81 'valeur' => $id_breve,
82 'titre' => $titre);
83 } else {
84 return array('pref' => _T('lien_reponse_breve_2'),
85 'url' => generer_url_entite($id_breve, 'breve','','',true),
86 'type' => 'id_breve',
87 'valeur' => $id_breve,
88 'titre' => $titre);
89 }
90 }
91 else if ($forum_stat == "privadm") {
92 $retour = forum_parent($forum_id_parent);
93 if ($retour) return $retour;
94 else return array('pref' => _T('info_message'),
95 'url' => generer_url_ecrire('forum_admin'),
96 'titre' => _T('info_forum_administrateur'));
97 }
98 else {
99 $retour = forum_parent($forum_id_parent);
100 if ($retour) return $retour;
101 else return array('pref' => _T('info_message'),
102 'url' => generer_url_ecrire('forum'),
103 'titre' => _T('info_forum_interne'));
104 }
105 }
106
107 // http://doc.spip.org/@controle_forum_boucle
108 function controle_forum_boucle($row, $args) {
109
110 $id_forum = $row['id_forum'];
111 $forum_id_parent = $row['id_parent'];
112 $forum_id_rubrique = $row['id_rubrique'];
113 $forum_id_article = $row['id_article'];
114 $forum_id_breve = $row['id_breve'];
115 $forum_date_heure = $row['date_heure'];
116 $forum_titre = echapper_tags($row['titre']);
117 $forum_texte = $row['texte'];
118 $forum_auteur = echapper_tags(extraire_multi($row['auteur']));
119 $forum_email_auteur = echapper_tags($row['email_auteur']);
120 $forum_nom_site = echapper_tags($row['nom_site']);
121 $forum_url_site = echapper_tags($row['url_site']);
122 $forum_stat = $row['statut'];
123 $forum_ip = $row['ip'];
124 $forum_id_auteur = $row["id_auteur"];
125
126 $r = forum_parent($id_forum);
127 $avant = $r['avant'];
128 $url = $r['url'];
129 $titre = $r['titre'];
130 $type = $r['type'];
131 $valeur = $r['valeur'];
132 $pref = $r['pref'];
133
134 if ($documents = sql_allfetsel('doc.id_document, doc.fichier AS fichier', 'spip_documents AS doc LEFT JOIN spip_documents_liens AS lien ON doc.id_document=lien.id_document', 'lien.id_objet='.intval($id_forum)." AND objet='forum'")) {
135 include_spip('inc/documents');
136 foreach ($documents as $k => $t) {
137 $h = generer_url_entite($t['id_document'], 'document');
138 $documents[$k] = "<a href='".$h."'>".basename($t['fichier'])."</a>";
139 }
140 }
141
142 switch($forum_stat) {
143 case 'off':
144 case 'privoff':
145 $style = " style='border: 2px #ff0000 dashed;'";
146 break;
147 case 'prop':
148 $style = " style='border: 2px yellow solid; background-color: white;'";
149 break;
150 case 'spam':
151 $style = " style='border: 2px black dotted;'";
152 break;
153 default:
154 $style = "";
155 break;
156 }
157
158 if ($forum_email_auteur) {
159 if (email_valide($forum_email_auteur))
160 $forum_email_auteur = "<a href='mailto:"
161 .htmlspecialchars($forum_email_auteur)
162 ."?subject=".rawurlencode($forum_titre)."'>".$forum_email_auteur
163 ."</a>";
164 $forum_auteur .= " &mdash; $forum_email_auteur";
165 }
166
167 $suite = "\n<br />$avant<b>$pref\n<a href='$url' class='controle'>$titre</a></b>"
168 . "<div class='controle'>".justifier(propre($forum_texte))."</div>";
169 include_spip('public/composer');
170 if ($forum_notes = safehtml(calculer_notes()))
171 $suite .= "<div class='notes controle'>".justifier(safehtml($forum_notes))."</div>";
172
173 if (strlen($forum_url_site) > 10 AND strlen($forum_nom_site) > 3)
174 $suite .= "\n<div style='text-align: left' class='serif'><b><a href='$forum_url_site'>$forum_nom_site</a></b></div>";
175
176 return "\n<div><br /><a id='forum$id_forum'></a></div>" .
177 debut_cadre_forum("", true, "", typo($forum_titre)) .
178 "<div$style>" .
179 date_interface($forum_date_heure) .
180 safehtml("<span class='arial2'> / <b>$forum_auteur</b></span>") .
181 boutons_controle_forum($id_forum, $forum_stat, $forum_id_auteur, "$type=$valeur", $forum_ip, 'controle_forum', $args) .
182 safehtml(lignes_longues($suite)) .
183 afficher_forum_mots($id_forum) .
184 join(', ', $documents) .
185 "<div class='nettoyeur'></div></div>".
186 fin_cadre_forum(true);
187 }
188
189 //
190 // Debut de la page de controle
191 //
192
193 // http://doc.spip.org/@exec_controle_forum_dist
194 function exec_controle_forum_dist()
195 {
196 exec_controle_forum_args(intval(_request('id_rubrique')),
197 _request('type'),
198 intval(_request('debut')),
199 intval(_request('pas')),
200 intval(_request('enplus')),
201 _request('recherche'));
202 }
203
204 // http://doc.spip.org/@exec_controle_forum_args
205 function exec_controle_forum_args($id_rubrique, $type, $debut, $pas, $enplus, $recherche)
206 {
207 if (!autoriser('publierdans','rubrique',$id_rubrique)) {
208 include_spip('inc/minipres');
209 echo minipres();
210 } else {
211
212 if (!preg_match('/^\w+$/', $type)) $type = 'public';
213 $formulaire_recherche = formulaire_recherche("controle_forum","<input type='hidden' name='type' value='$type' />");
214
215 list($from,$where) = critere_statut_controle_forum($type, $id_rubrique, $recherche);
216
217 // Si un id_controle_forum est demande, on adapte le debut
218 if ($debut_id_forum = intval(_request('debut_id_forum'))
219 AND (NULL !== ($d = sql_getfetsel('date_heure', 'spip_forum', "id_forum=$debut_id_forum")))) {
220 $debut = sql_countsel($from, $where . (" AND F.date_heure > '$d'"));
221 }
222
223 if ($recherche)
224 $args = 'recherche='.rawurlencode($recherche).'&';
225 else $args = '';
226
227 $args .= (!$id_rubrique ? "" : "id_rubrique=$id_rubrique&") . 'type=';
228
229 $query = array('SELECT' => "F.id_forum, F.id_parent, F.id_rubrique, F.id_article, F.id_breve, F.date_heure, F.titre, F.texte, F.auteur, F.email_auteur, F.nom_site, F.url_site, F.statut, F.ip, F.id_auteur",
230 'FROM' => $from,
231 'WHERE' => $where,
232 'GROUP BY' => "",
233 'ORDER BY' => "F.date_heure DESC");
234
235 $nav = affiche_navigation_forum($query, 'controle_forum', $args . $type, $debut, $pas, $enplus);
236
237 $select = sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY'], $query['LIMIT']);
238
239 $res = '';
240 while ($row = sql_fetch($select))
241 $res .= controle_forum_boucle($row, "$args$type&debut=$debut");
242 $res = "<br />$nav<br />$res<br />$nav";
243
244 if (_AJAX) {
245 ajax_retour($res);
246 } else {
247 $ancre = 'controle_forum';
248 $res = "<div id='$ancre' class='serif2'>$res</div>";
249
250 pipeline('exec_init',array('args'=>array('exec'=>'controle_forum', 'type'=>$type),'data'=>''));
251
252
253 $commencer_page = charger_fonction('commencer_page', 'inc');
254 echo $commencer_page(_T('titre_page_forum_suivi'), "forum", "forum-controle");
255
256 echo "<br /><br /><br />";
257 echo gros_titre(_T('titre_forum_suivi'),'',false);
258
259 echo debut_onglet();
260 echo onglet(_T('onglet_messages_publics'), generer_url_ecrire('controle_forum', $args . "public"), "public", $type=='public', "forum-public-24.gif");
261 echo onglet(_T('onglet_messages_internes'), generer_url_ecrire('controle_forum', $args . "interne"), "interne", $type=='interne', "forum-interne-24.gif");
262
263 list($from,$where) = critere_statut_controle_forum('vide', $id_rubrique);
264 $n = sql_fetsel('1', $from, $where);
265 if ($n) echo onglet(_T('onglet_messages_vide'), generer_url_ecrire('controle_forum', $args . "vide"), "vide", $type=='vide');
266
267 list($from,$where) = critere_statut_controle_forum('prop', $id_rubrique);
268 $f = sql_fetsel('1', $from, $where);
269 if ($f)
270 echo onglet(_T('texte_statut_attente_validation'), generer_url_ecrire('controle_forum', $args . "prop"), "prop", $type=='prop');
271
272 echo fin_onglet();
273
274 echo debut_gauche('', true);
275 echo debut_boite_info(true);
276 echo "<span class='verdana1 spip_small'>", _T('info_gauche_suivi_forum_2'), aide("suiviforum"), "</span>";
277
278 // Afficher le lien RSS
279
280 echo bouton_spip_rss("forums_$type");
281
282 echo fin_boite_info(true);
283
284 echo pipeline('affiche_gauche',array('args'=>array('exec'=>'controle_forum', 'type'=>$type),'data'=>''));
285 echo creer_colonne_droite('', true);
286 echo pipeline('affiche_droite',array('args'=>array('exec'=>'controle_forum', 'type'=>$type),'data'=>''));
287
288
289 echo debut_droite('', true);
290 echo pipeline('affiche_milieu',array('args'=>array('exec'=>'controle_forum', 'type'=>$type),'data'=>''));
291
292 echo $formulaire_recherche . "<div class='nettoyeur'></div>";
293 echo $res;
294 echo fin_gauche(), fin_page();
295 }
296 }
297 }
298 ?>