search.php 23.3 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
<?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * FORUM2
 *
 * Copyright 2007 - 2010
 * - Julien Etelain < julien dot etelain at gmail dot com >
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
 * - Benjamin Collet <bcollet at oxynux dot org>
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
Ayolo's avatar
Ayolo committed
28
29
30
31
32
33
34
35

$topdir = "../";

require_once($topdir. "include/site.inc.php");
require_once($topdir . "include/entities/asso.inc.php");
require_once($topdir . "include/entities/forum.inc.php");
require_once($topdir . "include/entities/sujet.inc.php");
require_once($topdir . "include/entities/message.inc.php");
mbriand's avatar
mbriand committed
36
require_once($topdir . "include/entities/utilisateur.inc.php");
Ayolo's avatar
Ayolo committed
37
38
39
40
41
42
43
44

require_once($topdir . "include/entities/news.inc.php");
require_once($topdir . "include/entities/sondage.inc.php");
require_once($topdir . "sas2/include/cat.inc.php");

require_once($topdir . "include/cts/forum.inc.php");

$site = new site ();
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

if (!$site->get_param ("forum_open", false)) {
  if (!$site->user->is_in_group ("moderateur_forum") &&
      !$site->user->is_in_group ("root")) {
    $site->start_page ("forum", "Forum");
    $cts = new contents ("Forum fermé",
        $site->get_param ("forum_message", "Maintenance."));
    $site->add_contents ($cts);
    $site->end_page();
    exit();
  } else {
    $cts = new contents ();
    $cts->add_paragraph ("<b>Attention, forum fermé aux non-modérateurs : ".
        $site->get_param ("forum_message", "Maintenance.")."</b>");
    $site->add_contents ($cts);
  }
}

Ayolo's avatar
Ayolo committed
63
64
65
66
67
68
69
$site->add_css("css/forum.css");

$forum = new forum($site->db);
$forum->load_by_id(1);

if ( $_REQUEST["page"] == "unread" )
{
Krophil's avatar
Krophil committed
70
71
  header("Location: https://ae2.utbm.fr/forum/last_unread")

Ayolo's avatar
Ayolo committed
72
  $site->allow_only_logged_users("forum");
73

Ayolo's avatar
Ayolo committed
74
  $site->start_page("forum","Messages non lus");
75

Ayolo's avatar
Ayolo committed
76
  $cts = new contents($forum->get_html_link()." / <a href=\"search.php?page=unread\">Messages non lus</a>");
77

Feu's avatar
wip    
Feu committed
78
  $cts->add_paragraph(
Feu's avatar
Feu committed
79
  "<a href=\"search.php?page=unread\">".
Feu's avatar
Feu committed
80
    "<img src=\"".$wwwtopdir."images/icons/16/reload.png\" class=\"icon\" alt=\"\" />Actualiser".
Feu's avatar
Feu committed
81
  "</a> ".
Feu's avatar
wip    
Feu committed
82
83
84
85
86
87
88
  "<a href=\"./?action=setallread\">".
    "<img src=\"".$wwwtopdir."images/icons/16/valid.png\" class=\"icon\" alt=\"\" />Marquer tout comme lu".
  "</a> ".
  "<a href=\"search.php\">".
    "<img src=\"".$wwwtopdir."images/icons/16/search.png\" class=\"icon\" alt=\"\" />Rechercher".
  "</a>"
  ,"frmtools");
89
90


Ayolo's avatar
Ayolo committed
91
92
93
  $query = "SELECT frm_sujet.*, ".
      "frm_message.date_message, " .
      "frm_message.id_message, " .
Feu's avatar
Feu committed
94
      "COALESCE(
BenC's avatar
Bleh    
BenC committed
95
96
97
        dernier_auteur_etu_utbm.surnom_utbm,
        CONCAT(dernier_auteur.prenom_utl,' ',dernier_auteur.nom_utl)
      ) AS `nom_utilisateur_dernier_auteur`, " .
Ayolo's avatar
Ayolo committed
98
      "dernier_auteur.id_utilisateur AS `id_utilisateur_dernier`, " .
Feu's avatar
Feu committed
99
      "COALESCE(
BenC's avatar
Bleh    
BenC committed
100
101
102
          premier_auteur_etu_utbm.surnom_utbm,
          CONCAT(premier_auteur.prenom_utl,' ',premier_auteur.nom_utl)
        ) AS `nom_utilisateur_premier_auteur`, " .
Ayolo's avatar
Ayolo committed
103
      "premier_auteur.id_utilisateur AS `id_utilisateur_premier`, " .
Feu's avatar
wip    
Feu committed
104
      "1 AS `nonlu`, " .
Feu's avatar
wip    
Feu committed
105
      "titre_forum AS `soustitre_sujet`, " .
106
107
      "frm_sujet_utilisateur.etoile_sujet AS `etoile`, " .
      "frm_forum.droits_acces_forum, ".
108
      "frm_forum.id_groupe ".
Ayolo's avatar
Ayolo committed
109
110
111
112
113
      "FROM frm_sujet " .
      "INNER JOIN frm_forum USING(id_forum) ".
      "LEFT JOIN frm_message ON ( frm_message.id_message = frm_sujet.id_message_dernier ) " .
      "LEFT JOIN utilisateurs AS `dernier_auteur` ON ( dernier_auteur.id_utilisateur=frm_message.id_utilisateur ) " .
      "LEFT JOIN utilisateurs AS `premier_auteur` ON ( premier_auteur.id_utilisateur=frm_sujet.id_utilisateur ) ".
BenC's avatar
Bleh    
BenC committed
114
115
      "LEFT JOIN utl_etu_utbm AS `dernier_auteur_etu_utbm` ON ( dernier_auteur_etu_utbm.id_utilisateur=frm_message.id_utilisateur ) " .
      "LEFT JOIN utl_etu_utbm AS `premier_auteur_etu_utbm` ON ( premier_auteur_etu_utbm.id_utilisateur=frm_sujet.id_utilisateur )" .
Ayolo's avatar
Ayolo committed
116
117
118
119
      "LEFT JOIN frm_sujet_utilisateur ".
        "ON ( frm_sujet_utilisateur.id_sujet=frm_sujet.id_sujet ".
        "AND frm_sujet_utilisateur.id_utilisateur='".$site->user->id."' ) ".
      "WHERE ";
120

Ayolo's avatar
Ayolo committed
121
122
  if( is_null($site->user->tout_lu_avant))
    $query .= "(frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
123
              "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ";
Ayolo's avatar
Ayolo committed
124
125
126
  else
    $query .= "((frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
              "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ".
127
              "AND frm_message.date_message > '".date("Y-m-d H:i:s",$site->user->tout_lu_avant)."') ";
Ayolo's avatar
Ayolo committed
128
129
130
131

  if ( !$forum->is_admin( $site->user ) )
  {
    $grps = $site->user->get_groups_csv();
mbriand's avatar
bleh    
mbriand committed
132
    $query .= "AND frm_message.msg_supprime='0' ";
Ayolo's avatar
Ayolo committed
133
134
135
    $query .= "AND ((droits_acces_forum & 0x1) OR " .
      "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
      "(id_groupe_admin IN ($grps)) OR " .
Feu's avatar
fix    
Feu committed
136
      "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$site->user->id."')) ";
Ayolo's avatar
Ayolo committed
137
138
  }

Feu's avatar
wip    
Feu committed
139
140
141
142

  $query_fav = $query."AND frm_sujet_utilisateur.etoile_sujet='1' ";
  $query_fav .= "ORDER BY frm_message.date_message DESC ";
  $query_fav .= "LIMIT 75 ";
143

Feu's avatar
wip    
Feu committed
144
  $query .= "AND ( frm_sujet_utilisateur.etoile_sujet IS NULL OR frm_sujet_utilisateur.etoile_sujet!='1' ) ";
Ayolo's avatar
Ayolo committed
145
  $query .= "ORDER BY frm_message.date_message DESC ";
Feu's avatar
wip    
Feu committed
146
147
148
149
  $query .= "LIMIT 75 ";

  /*$query .= "ORDER BY frm_message.date_message DESC ";
  $query .= "LIMIT 100 ";*/
150

Feu's avatar
wip    
Feu committed
151
152
153
154
  $req = new requete($site->db,$query_fav);
  if ( $req->lines > 0 )
  {
    $cts->add_title(2,"Sujets favoris avec des messages non lus");
155
156
    $rows = array();
    while ( $row = $req->get_row() )
157
    {
mbriand's avatar
gna !    
mbriand committed
158
      if (($row['id_groupe'] != 7) || ($row['droits_acces_forum'] & 0x1) || ($site->user->is_in_group("root")))
159
160
        $rows[] = $row;
    }
161

162
163
    $cts->add(new sujetslist($rows, $site->user, "./", null, null,true));
    $cts->add_paragraph("&nbsp;");
Feu's avatar
wip    
Feu committed
164
  }
165
166


Ayolo's avatar
Ayolo committed
167
  $req = new requete($site->db,$query);
Feu's avatar
wip    
Feu committed
168
169
170
  if ( $req->lines > 0 )
  {
    $cts->add_title(2,"Sujets avec des messages non lus");
171
    $rows = array();
172
    {
173
    while ( $row = $req->get_row() )
174
      if (($row['id_groupe'] != 7) || ($row['droits_acces_forum'] & 0x1) || ($site->user->is_in_group("root")))
175
176
        $rows[] = $row;
    }
177

178
    $cts->add(new sujetslist($rows, $site->user, "./", null, null,true));
Feu's avatar
wip    
Feu committed
179
  }
180

Ayolo's avatar
Ayolo committed
181
  $site->add_contents($cts);
182

Ayolo's avatar
Ayolo committed
183
184
185
  $site->end_page();
  exit();
}
BenC's avatar
BenC committed
186
187
elseif ( $_REQUEST["page"] == "starred" )
{
Krophil's avatar
Krophil committed
188
189
  header("Location: https://ae2.utbm.fr/forum")

BenC's avatar
BenC committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  $site->allow_only_logged_users("forum");

  $site->start_page("forum","Sujets favoris");

  $cts = new contents($forum->get_html_link()." / <a href=\"search.php?page=starred\">Sujets favoris</a>");

  $query = "SELECT frm_sujet.*, ".
      "frm_message.date_message, " .
      "frm_message.id_message, " .
      "COALESCE(
        dernier_auteur_etu_utbm.surnom_utbm,
        CONCAT(dernier_auteur.prenom_utl,' ',dernier_auteur.nom_utl)
      ) AS `nom_utilisateur_dernier_auteur`, " .
      "dernier_auteur.id_utilisateur AS `id_utilisateur_dernier`, " .
      "COALESCE(
          premier_auteur_etu_utbm.surnom_utbm,
          CONCAT(premier_auteur.prenom_utl,' ',premier_auteur.nom_utl)
        ) AS `nom_utilisateur_premier_auteur`, " .
      "premier_auteur.id_utilisateur AS `id_utilisateur_premier`, " .
BenC's avatar
BenC committed
209
      "IF(frm_sujet.id_message_dernier > frm_sujet_utilisateur.id_message_dernier_lu,1,0) AS `nonlu`, " .
BenC's avatar
BenC committed
210
      "titre_forum AS `soustitre_sujet`, " .
211
212
      "0 AS `etoile`, " .
      "frm_forum.droits_acces_forum, ".
213
      "frm_forum.id_groupe ".
BenC's avatar
BenC committed
214
215
216
217
218
219
220
221
222
223
      "FROM frm_sujet " .
      "INNER JOIN frm_forum USING(id_forum) ".
      "LEFT JOIN frm_message ON ( frm_message.id_message = frm_sujet.id_message_dernier ) " .
      "LEFT JOIN utilisateurs AS `dernier_auteur` ON ( dernier_auteur.id_utilisateur=frm_message.id_utilisateur ) " .
      "LEFT JOIN utilisateurs AS `premier_auteur` ON ( premier_auteur.id_utilisateur=frm_sujet.id_utilisateur ) ".
      "LEFT JOIN utl_etu_utbm AS `dernier_auteur_etu_utbm` ON ( dernier_auteur_etu_utbm.id_utilisateur=frm_message.id_utilisateur ) " .
      "LEFT JOIN utl_etu_utbm AS `premier_auteur_etu_utbm` ON ( premier_auteur_etu_utbm.id_utilisateur=frm_sujet.id_utilisateur )" .
      "LEFT JOIN frm_sujet_utilisateur ".
        "ON ( frm_sujet_utilisateur.id_sujet=frm_sujet.id_sujet ".
        "AND frm_sujet_utilisateur.id_utilisateur='".$site->user->id."' ) ".
BenC's avatar
BenC committed
224
      "WHERE frm_sujet_utilisateur.etoile_sujet='1' ";
BenC's avatar
BenC committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

  if ( !$forum->is_admin( $site->user ) )
  {
    $grps = $site->user->get_groups_csv();
    $query .= "AND ((droits_acces_forum & 0x1) OR " .
      "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
      "(id_groupe_admin IN ($grps)) OR " .
      "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$site->user->id."')) ";
  }

  $query .= "ORDER BY frm_message.date_message DESC ";

  $req = new requete($site->db,$query);

  if ( $req->lines > 0 )
  {
    $rows = array();
    while ( $row = $req->get_row() )
243
    {
244
      if (($row['id_groupe'] != 7) || ($row['droits_acces_forum'] & 0x1) || ($site->user->is_in_group("root")))
245
246
        $rows[] = $row;
    }
BenC's avatar
BenC committed
247
248
249
250
251
252
253
254
255
256
257
258

    $cts->add(new sujetslist($rows, $site->user, "./", null, null,true));
    $cts->add_paragraph("&nbsp;");
  }
  else
    $cts->add_paragraph("Vous n'avez aucun sujet favoris.");

  $site->add_contents($cts);

  $site->end_page();
  exit();
}
Ayolo's avatar
Ayolo committed
259

Feu's avatar
wip    
Feu committed
260
if ( isset($_REQUEST["pattern"] ) )
Feu's avatar
wip    
Feu committed
261
{
mbriand's avatar
mbriand committed
262
263
  $site->start_page("forum","Recherche ".htmlentities($_REQUEST["pattern"],ENT_COMPAT,"UTF-8"));

mbriand's avatar
mbriand committed
264
  $url = "search.php?pattern=".urlencode($_REQUEST["pattern"]);
Feu's avatar
wip    
Feu committed
265

mbriand's avatar
mbriand committed
266
267
  $order_mess .= "ORDER BY date_message DESC ";
  $order_suj  .= "ORDER BY frm_last_message.date_message DESC ";
mbriand's avatar
mbriand committed
268
  if ( !empty($_REQUEST["pattern"]) )
Feu's avatar
wip    
Feu committed
269
  {
mbriand's avatar
mbriand committed
270
271
272
273
274
275
276
277
278
    /*
    // Pauvre mysql... trop lourd pour lui...
    if (isset($_REQUEST['regex']))
    {
      $url .= "&regex";
      $sql_conds = "WHERE (frm_message.titre_message REGEXP '".mysql_real_escape_string($_REQUEST["pattern"])."' OR contenu_message REGEXP '".mysql_real_escape_string($_REQUEST["pattern"])."') ";
    }
    else
      */
279
      $sql_conds = "WHERE MATCH (frm_message.titre_message,frm_message.contenu_message) AGAINST ('".mysql_real_escape_string($_REQUEST["pattern"])."' IN BOOLEAN MODE) ";
mbriand's avatar
mbriand committed
280
281
282
283
284
285

      if ($_REQUEST['order'] != "date")
      {
        $order_mess = "ORDER BY MATCH (frm_message.titre_message,frm_message.contenu_message) AGAINST ('".mysql_real_escape_string($_REQUEST["pattern"])."' IN BOOLEAN MODE) DESC, date_message DESC ";
        $order_suj = "ORDER BY MAX(MATCH (frm_message.titre_message,frm_message.contenu_message) AGAINST ('".mysql_real_escape_string($_REQUEST["pattern"])."' IN BOOLEAN MODE)) DESC, date_message DESC ";
      }
mbriand's avatar
mbriand committed
286
287
  }
  else
mbriand's avatar
mbriand committed
288
    $sql_conds = "WHERE 1 ";
289
290
291
292

  if ( !$forum->is_admin( $site->user ) )
  {
    $grps = $site->user->get_groups_csv();
mbriand's avatar
mbriand committed
293
    $sql_conds .= "AND ((droits_acces_forum & 0x1) OR " .
294
295
296
297
      "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
      "(id_groupe_admin IN ($grps)) OR " .
      "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$site->user->id."')) ";
  }
298

mbriand's avatar
mbriand committed
299
300
301
  if (!isset($_REQUEST['include_deleted']) || (!$site->user->is_in_group('root') && !$site->user->is_in_group('moderateur_forum')))
  {
    $url .= "&msg_supprime";
mbriand's avatar
mbriand committed
302
    $sql_conds .= "AND frm_message.msg_supprime='0' ";
mbriand's avatar
mbriand committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
  }
  if ($_REQUEST['begin_date'])
  {
    $url .= "&begin_date=".$_REQUEST['begin_date'];
    $sql_conds .= "AND frm_message.date_message > '".date("Y-m-d H:i",$_REQUEST['begin_date'])."' ";
  }
  if ($_REQUEST['end_date'])
  {
    $url .= "&end_date=".$_REQUEST['end_date'];
    $sql_conds .= "AND frm_message.date_message < '".date("Y-m-d H:i",$_REQUEST['end_date'])."' ";
  }
  if ($_REQUEST['id_utilisateur'])
  {
    $url .= "&id_utilisateur=".$_REQUEST['id_utilisateur'];
    $sql_conds .= "AND frm_message.id_utilisateur =  '".mysql_real_escape_string($_REQUEST['id_utilisateur'])."' ";
  }
  if ($_REQUEST['id_forum'])
  {
    $url .= "&id_forum=".$_REQUEST['id_forum'];
    $sql_conds .= "AND frm_sujet.id_forum = '".mysql_real_escape_string($_REQUEST['id_forum'])."' ";
  }
Feu's avatar
test    
Feu committed
324

mbriand's avatar
mbriand committed
325
  $url .= "&display_type=".$_REQUEST['display_type'];
mbriand's avatar
mbriand committed
326
  $url .= "&order=".$_REQUEST['order'];
mbriand's avatar
mbriand committed
327
  $cts_res = new contents("Résultats de la recherche");
328

mbriand's avatar
mbriand committed
329
330
331
  if ($_REQUEST['display_type'] == "sujets")
  {
    $sql = "SELECT frm_sujet.*, ".
mbriand's avatar
mbriand committed
332
333
        "frm_last_message.date_message, " .
        "frm_last_message.id_message, " .
mbriand's avatar
mbriand committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
        "COALESCE(
          dernier_auteur_etu_utbm.surnom_utbm,
          CONCAT(dernier_auteur.prenom_utl,' ',dernier_auteur.nom_utl)
        ) AS `nom_utilisateur_dernier_auteur`, " .
        "dernier_auteur.id_utilisateur AS `id_utilisateur_dernier`, " .
        "COALESCE(
            premier_auteur_etu_utbm.surnom_utbm,
            CONCAT(premier_auteur.prenom_utl,' ',premier_auteur.nom_utl)
          ) AS `nom_utilisateur_premier_auteur`, " .
        "premier_auteur.id_utilisateur AS `id_utilisateur_premier`, " .
        "IF(frm_sujet.id_message_dernier > frm_sujet_utilisateur.id_message_dernier_lu,1,0) AS `nonlu`, " .
        "titre_forum AS `soustitre_sujet`, " .
        "frm_sujet_utilisateur.etoile_sujet AS etoile, " .
        "frm_forum.droits_acces_forum, ".
        "frm_forum.id_groupe ".
mbriand's avatar
mbriand committed
349
350
        "FROM frm_message " .
        "LEFT JOIN frm_sujet USING (id_sujet) ".
mbriand's avatar
mbriand committed
351
        "INNER JOIN frm_forum USING(id_forum) ".
mbriand's avatar
mbriand committed
352
        "LEFT JOIN frm_message frm_last_message ON ( frm_last_message.id_message = frm_sujet.id_message_dernier ) " .
mbriand's avatar
mbriand committed
353
        "LEFT JOIN utilisateurs AS `dernier_auteur` ON ( dernier_auteur.id_utilisateur=frm_last_message.id_utilisateur ) " .
mbriand's avatar
mbriand committed
354
        "LEFT JOIN utilisateurs AS `premier_auteur` ON ( premier_auteur.id_utilisateur=frm_sujet.id_utilisateur ) ".
mbriand's avatar
mbriand committed
355
        "LEFT JOIN utl_etu_utbm AS `dernier_auteur_etu_utbm` ON ( dernier_auteur_etu_utbm.id_utilisateur=frm_last_message.id_utilisateur ) " .
mbriand's avatar
mbriand committed
356
357
358
359
360
361
362
        "LEFT JOIN utl_etu_utbm AS `premier_auteur_etu_utbm` ON ( premier_auteur_etu_utbm.id_utilisateur=frm_sujet.id_utilisateur )" .
        "LEFT JOIN frm_sujet_utilisateur ".
          "ON ( frm_sujet_utilisateur.id_sujet=frm_sujet.id_sujet ".
          "AND frm_sujet_utilisateur.id_utilisateur='".$site->user->id."' ) ";

    $sql .= $sql_conds;

mbriand's avatar
mbriand committed
363
364
    $sql .= "GROUP BY frm_sujet.id_sujet ";
    $sql .= $order_suj;
mbriand's avatar
mbriand committed
365

mbriand's avatar
mbriand committed
366
    $req = new requete($site->db,$sql);
mbriand's avatar
mbriand committed
367
368
369
370
371
372
373
374
375

    if ( $req->lines > 0 )
    {
      $rows = array();
      while ( $row = $req->get_row() )
      {
        if (($row['id_groupe'] != 7) || ($row['droits_acces_forum'] & 0x1) || ($site->user->is_in_group("root")))
          $rows[] = $row;
      }
376

mbriand's avatar
mbriand committed
377
378
      $cts_res->add(new sujetslist($rows, $site->user, "./", null, null,true));
      $cts_res->add_paragraph("&nbsp;");
mbriand's avatar
mbriand committed
379
380
    }
    else
mbriand's avatar
mbriand committed
381
      $cts_res->add_paragraph("Aucun résultat trouvé.");
mbriand's avatar
mbriand committed
382
383
384
  }
  else
  {
mbriand's avatar
mbriand committed
385
386
    $sql_count =  "SELECT COUNT(*) FROM frm_message ";
    $sql_count .= $sql_conds;
mbriand's avatar
mbriand committed
387
    $req = new requete($site->db,$sql_count);
mbriand's avatar
mbriand committed
388
389
390
    if ( $req->lines > 0 )
      list($mess_count) =  $req->get_row();

mbriand's avatar
mbriand committed
391
    $sql = "SELECT frm_sujet.*, frm_message.*, frm_forum.id_groupe, frm_forum.droits_acces_forum, ".
mbriand's avatar
mbriand committed
392
393
394
395
396
397
398
            "COALESCE( utl_etu_utbm.surnom_utbm, CONCAT(utilisateurs.prenom_utl,' ',utilisateurs.nom_utl)) AS alias_utl, " .
            "utilisateurs.id_utilisateur, utilisateurs.signature_utl " .
            "FROM frm_message " .
            "INNER JOIN frm_sujet USING ( id_sujet ) ".
            "INNER JOIN frm_forum USING (id_forum) ".
            "LEFT JOIN utilisateurs ON ( utilisateurs.id_utilisateur=frm_message.id_utilisateur ) ".
            "LEFT JOIN utl_etu_utbm ON ( utl_etu_utbm.id_utilisateur=frm_message.id_utilisateur ) ";
399

mbriand's avatar
mbriand committed
400
    $sql .= $sql_conds;
mbriand's avatar
mbriand committed
401
402
403

    $sql .= $order_mess;

mbriand's avatar
mbriand committed
404
405
406
407
408
409
410
411
412
413
    if (isset($_REQUEST['first']) && intval($_REQUEST['first']) > 0)
    {
      $sql .= "LIMIT ".intval($_REQUEST['first']).", 50";
      $first = intval($_REQUEST['first']);
    }
    else
    {
      $sql .= "LIMIT 50";
      $first = 0;
    }
414

mbriand's avatar
mbriand committed
415
    $req = new requete($site->db,$sql);
416

417
    $id_sujet=null;
418

mbriand's avatar
mbriand committed
419
    if ( $req->lines > 0 )
420
    {
mbriand's avatar
mbriand committed
421
422
      $n=0;
      $i=0;
mbriand's avatar
mbriand committed
423
      while ( $row = $req->get_row() )
424
      {
mbriand's avatar
mbriand committed
425
        $i++;
mbriand's avatar
mbriand committed
426
        if (($row['id_groupe'] != 7) || ($row['droits_acces_forum'] & 0x1) || ($site->user->is_in_group("root")))
427
        {
mbriand's avatar
mbriand committed
428
429
          if ( $id_sujet!=$row['id_sujet'] )
          {
mbriand's avatar
mbriand committed
430
431
            $cts_res->add_title(2, "<a href=\"".$wwwtopdir."forum2/?id_sujet=".$row['id_sujet']."\">".
              "<img src=\"".$wwwtopdir."images/icons/16/sujet.png\" class=\"icon\" alt=\"\" /> ".$row['titre_sujet']."</a>");
mbriand's avatar
mbriand committed
432
            $id_sujet = $row['id_sujet'];
mbriand's avatar
mbriand committed
433
434
          }

mbriand's avatar
mbriand committed
435
436
          $buffer = "";

mbriand's avatar
mbriand committed
437
          if ( $i == $req->lines )
mbriand's avatar
mbriand committed
438
            $buffer .= "<div id=\"lastmessage\"></div>";
mbriand's avatar
mbriand committed
439
440
441
442

          $t = strtotime($row['date_message']);

          if ($row['msg_supprime'])
mbriand's avatar
mbriand committed
443
            $buffer .= "<div class=\"fmsgentry deleted\" id=\"msg".$row['id_message']."\">\n";
mbriand's avatar
mbriand committed
444
          elseif ( $n )
mbriand's avatar
mbriand committed
445
            $buffer .= "<div class=\"fmsgentry pair\" id=\"msg".$row['id_message']."\">\n";
mbriand's avatar
mbriand committed
446
          else
mbriand's avatar
mbriand committed
447
            $buffer .= "<div class=\"fmsgentry\" id=\"msg".$row['id_message']."\">\n";
mbriand's avatar
mbriand committed
448
449
450
          $n=($n+1)%2;

          /* permalink */
mbriand's avatar
mbriand committed
451
          $buffer .= "<a href=\"./?id_message=".
mbriand's avatar
mbriand committed
452
453
454
455
456
          $row['id_message']."#msg".$row['id_message']."\">";

          if ($row['msg_supprime'])
          {
            if ( $row['titre_message'] )
mbriand's avatar
mbriand committed
457
              $buffer .= "<h2 class=\"frmt\">Message supprimé: ".htmlentities($row['titre_message'], ENT_NOQUOTES, "UTF-8")."</h2>\n";
mbriand's avatar
mbriand committed
458
            else
mbriand's avatar
mbriand committed
459
              $buffer .= "<h2 class=\"frmt\">Message supprimé</h2>\n";
mbriand's avatar
mbriand committed
460
          }
mbriand's avatar
mbriand committed
461
462
463
          else
          {
            if ( $row['titre_message'] )
mbriand's avatar
mbriand committed
464
              $buffer .= "<h2 class=\"frmt\">".htmlentities($row['titre_message'], ENT_NOQUOTES, "UTF-8")."</h2>\n";
mbriand's avatar
mbriand committed
465
            else
mbriand's avatar
mbriand committed
466
              $buffer .= "<h2 class=\"frmt\">&nbsp;</h2>\n";
mbriand's avatar
mbriand committed
467
468
          }

mbriand's avatar
mbriand committed
469
470
          $buffer .= "<p class=\"date\">".human_date($t)."</p>\n";
          $buffer .= "</a>";
mbriand's avatar
mbriand committed
471
472


mbriand's avatar
mbriand committed
473
          $buffer .= "<div class=\"auteur\">\n";
mbriand's avatar
mbriand committed
474

mbriand's avatar
mbriand committed
475
          $buffer .= "<p class=\"funame\"><a href=\"#top\"><img src=\"".$topdir."images/forum/top.png\" /></a>&nbsp;&nbsp;<a href=\"".$wwwtopdir."user.php?id_utilisateur=".$row['id_utilisateur']."\">".htmlentities($row['alias_utl'],ENT_NOQUOTES,"UTF-8")."</a></p>\n";
mbriand's avatar
mbriand committed
476
477

          $img=null;
Antoine Tenart's avatar
kwain    
Antoine Tenart committed
478
479
          if (file_exists($topdir."data/matmatronch/".$row['id_utilisateur'].".jpg"))
            $img = $wwwtopdir."data/matmatronch/".$row['id_utilisateur'].".jpg";
mbriand's avatar
mbriand committed
480
481

          if ( !is_null($img) )
mbriand's avatar
mbriand committed
482
            $buffer .= "<p class=\"fuimg\"><img src=\"".htmlentities($img,ENT_NOQUOTES,"UTF-8")."\" /></p>\n";
mbriand's avatar
mbriand committed
483

mbriand's avatar
mbriand committed
484
485
          $buffer .= "</div>\n";
          $buffer .= "<div class=\"fmsg\">\n";
mbriand's avatar
mbriand committed
486
487
488
489
490
491
492
493
494
495
496
497

          $msg_uid = "msg".$row['id_message'];

          if ( isset($_COOKIE["nosecret"]) && $_COOKIE["nosecret"] == 1 )
          {
            $msg_uid .= "nsc";
            $cache = new cachedcontents($msg_uid);
            if (! $cache->is_cached())
              $row['contenu_message'] = nosecret($row['contenu_message']);
          }

          if ( $row['syntaxengine_message'] == "bbcode" )
mbriand's avatar
mbriand committed
498
          //  $buffer .= bbcode($row['contenu_message']);
mbriand's avatar
mbriand committed
499
500
          {
            $cts = cachedcontents::autocache($msg_uid,new bbcontents("",$row['contenu_message'],false));
mbriand's avatar
mbriand committed
501
            $buffer .= $cts->html_render();
mbriand's avatar
mbriand committed
502
503
          }
          elseif ( $row['syntaxengine_message'] == "doku" )
mbriand's avatar
mbriand committed
504
          //  $buffer .= doku2xhtml($row['contenu_message']);
mbriand's avatar
mbriand committed
505
506
          {
            $cts = cachedcontents::autocache($msg_uid,new wikicontents("",$row['contenu_message'],false));
mbriand's avatar
mbriand committed
507
            $buffer .= $cts->html_render();
mbriand's avatar
mbriand committed
508
509
          }
          elseif ( $row['syntaxengine_message'] == "plain" )
mbriand's avatar
mbriand committed
510
            $buffer .= "<pre>".htmlentities($row['contenu_message'],ENT_NOQUOTES,"UTF-8")."</pre>";
mbriand's avatar
mbriand committed
511
512

          else // text
mbriand's avatar
mbriand committed
513
            $buffer .= nl2br(htmlentities($row['contenu_message'],ENT_NOQUOTES,"UTF-8"));
mbriand's avatar
mbriand committed
514

mbriand's avatar
mbriand committed
515
          if ($row['msg_modere_info'] && ($forum->is_admin($site->user)))
mbriand's avatar
mbriand committed
516
517
518
          {
            $modere_info = $forum->get_modere_info($row['id_message']);
            foreach($modere_info as $info)
mbriand's avatar
mbriand committed
519
              $buffer .= "<div class=\"".$info[0]."\">".$info[1]."</div>\n";
mbriand's avatar
mbriand committed
520
521
522
523
          }

          if ( !is_null($row['signature_utl']) )
          {
mbriand's avatar
mbriand committed
524
525
            $buffer .= "<div class=\"signature\">\n";
            //$buffer .= doku2xhtml($row['signature_utl']);
mbriand's avatar
mbriand committed
526
            $cts = cachedcontents::autocache("sig".$row['id_utilisateur'],new wikicontents("",$row['signature_utl'],false));
mbriand's avatar
mbriand committed
527
528
            $buffer .= $cts->html_render();
            $buffer .= "</div>\n";
mbriand's avatar
mbriand committed
529
          }
mbriand's avatar
mbriand committed
530

mbriand's avatar
mbriand committed
531
532
533
          $buffer .= "</div>\n";
          $buffer .= "<div class=\"clearboth\"></div>\n";
          $buffer .= "</div>\n";
mbriand's avatar
mbriand committed
534
          $cts_res->puts($buffer);
535
536
        }
      }
mbriand's avatar
mbriand committed
537
538
539
540
541

      $page_idx = 0;
      $tabs = array();
      while(50 * $page_idx < $mess_count)
      {
mbriand's avatar
mbriand committed
542
        $tabs[] = array("page_".$page_idx, "forum2/".$url."&first=".(50*$page_idx), $page_idx+1);
mbriand's avatar
mbriand committed
543
544
545
        $page_idx++;
      }

mbriand's avatar
mbriand committed
546
      $cts_res->add(new tabshead($tabs, "page_".$first/50, "_bottom"));
mbriand's avatar
mbriand committed
547
548
    }
    else
mbriand's avatar
mbriand committed
549
      $cts_res->add_paragraph("Aucun résultat trouvé.");
mbriand's avatar
mbriand committed
550
  }
Feu's avatar
wip    
Feu committed
551
}
552

Feu's avatar
test    
Feu committed
553
554
$site->start_page("forum","Recherche");

mbriand's avatar
mbriand committed
555
$cts = new contents($forum->get_html_link()." / <a href=\"search.php\">Recherche</a> / <a href=\"".$url."\">".htmlentities($_REQUEST["pattern"],ENT_COMPAT,"UTF-8")."</a>");
556

mbriand's avatar
mbriand committed
557
558
559
560
561
562
563
564
565
if ($site->user->is_in_group('root') || $site->user->is_in_group('moderateur_forum'))
  $sql = "SELECT id_forum, titre_forum FROM frm_forum ORDER BY titre_forum";
else
{
  $grps = $site->user->get_groups_csv();
  $sql = "SELECT id_forum, titre_forum FROM frm_forum ".
    "WHERE ((droits_acces_forum & 0x1) OR " .
    "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
    "(id_groupe_admin IN ($grps)) OR " .
mbriand's avatar
mbriand committed
566
    "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$site->user->id."')) ".
mbriand's avatar
mbriand committed
567
568
569
    "ORDER BY titre_forum";
}

mbriand's avatar
mbriand committed
570
571
572
573
574
575
576
577
$forum_cats = array(null=>"(Tous)");
$req = new requete($site->db, $sql);
while( list($value,$name) = $req->get_row()){
  $forum_cats[$value] = $name;
}

$frm = new form("frmsearch",$wwwtopdir."forum2/search.php", true);
$frm->add_text_field("pattern","Recherche");
578
//$frm->add_checkbox("regex", "Utiliser une expression régulière");
mbriand's avatar
mbriand committed
579
$frm->add_entity_smartselect("id_utilisateur", "Auteur", new utilisateur($site->db), true, false);
mbriand's avatar
mbriand committed
580
581
582
583
584
$frm->add_date_field("begin_date", "Posté après");
$frm->add_date_field("end_date", "Posté avant");
$frm->add_select_field('id_forum', 'Forum : ', $forum_cats);

if ($site->user->is_in_group('root') || $site->user->is_in_group('moderateur_forum'))
mbriand's avatar
mbriand committed
585
  $frm->add_checkbox("include_deleted", "Rechercher dans les messages supprimés", (!isset($_REQUEST["pattern"]) || isset($_REQUEST["include_deleted"])));
mbriand's avatar
mbriand committed
586
587

$frm->add_radiobox_field("display_type", "Type d'affichage", array("messages"=>"Afficher les messages", "sujets"=>"Afficher les sujets"), "messages");
mbriand's avatar
mbriand committed
588
$frm->add_radiobox_field("order", "Tri", array("pertinence"=>"Tri par pertinence", "date"=>"Tri par date"), "pertinence");
Feu's avatar
test    
Feu committed
589
$frm->add_submit("search","Rechercher");
gliss's avatar
gliss committed
590
$frm->set_focus("pattern");
591
592
$cts->add($frm);

Feu's avatar
test    
Feu committed
593
$site->add_contents($cts);
mbriand's avatar
mbriand committed
594
595
if (isset($cts_res))
  $site->add_contents($cts_res);
Ayolo's avatar
Ayolo committed
596

Feu's avatar
test    
Feu committed
597
598
$site->end_page();
exit();
Ayolo's avatar
Ayolo committed
599

BenC's avatar
Bleh    
BenC committed
600
?>