search.php 8.66 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

$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");

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 ();
$site->add_css("css/forum.css");

Feu's avatar
Feu committed
20
21
22
$cts = new contents();
$cts->cssclass="liner";
if ( $site->user->is_valid() )
23
  $cts->buffer = "<p class=\"center\">Connecté en tant que ".($site->user->surnom!=null ? $site->user->surnom : $site->user->alias )." - <a href=\"../user.php?page=edit\">Mon profil</a> - <a href=\"search.php?page=unread\">Messages non lus</a></p>";
Feu's avatar
Feu committed
24
else
Feu's avatar
FIX    
Feu committed
25
  $cts->buffer = "<p class=\"center\">Non connecté - <a href=\"../index.php\">Se connecter</a> - <a href=\"../newaccount.php\">Creer un compte</a></p>";
Feu's avatar
Feu committed
26
27
28
$site->add_contents($cts);
unset($cts);

Ayolo's avatar
Ayolo committed
29
30
31
32
33
34
$forum = new forum($site->db);
$forum->load_by_id(1);

if ( $_REQUEST["page"] == "unread" )
{
  $site->allow_only_logged_users("forum");
35

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

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

Feu's avatar
wip    
Feu committed
40
  $cts->add_paragraph(
Feu's avatar
Feu committed
41
  "<a href=\"search.php?page=unread\">".
Feu's avatar
Feu committed
42
    "<img src=\"".$wwwtopdir."images/icons/16/reload.png\" class=\"icon\" alt=\"\" />Actualiser".
Feu's avatar
Feu committed
43
  "</a> ".
Feu's avatar
wip    
Feu committed
44
45
46
47
48
49
50
  "<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");
51
52


Ayolo's avatar
Ayolo committed
53
54
55
  $query = "SELECT frm_sujet.*, ".
      "frm_message.date_message, " .
      "frm_message.id_message, " .
Feu's avatar
Feu committed
56
      "COALESCE(
BenC's avatar
Bleh    
BenC committed
57
58
59
        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
60
      "dernier_auteur.id_utilisateur AS `id_utilisateur_dernier`, " .
Feu's avatar
Feu committed
61
      "COALESCE(
BenC's avatar
Bleh    
BenC committed
62
63
64
          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
65
      "premier_auteur.id_utilisateur AS `id_utilisateur_premier`, " .
Feu's avatar
wip    
Feu committed
66
      "1 AS `nonlu`, " .
Feu's avatar
wip    
Feu committed
67
68
      "titre_forum AS `soustitre_sujet`, " .
      "frm_sujet_utilisateur.etoile_sujet AS `etoile` " .
Ayolo's avatar
Ayolo committed
69
70
71
72
73
      "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
74
75
      "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
76
77
78
79
      "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 ";
80

Ayolo's avatar
Ayolo committed
81
82
  if( is_null($site->user->tout_lu_avant))
    $query .= "(frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
83
              "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ";
Ayolo's avatar
Ayolo committed
84
85
86
  else
    $query .= "((frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
              "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ".
87
              "AND frm_message.date_message > '".date("Y-m-d H:i:s",$site->user->tout_lu_avant)."') ";
Ayolo's avatar
Ayolo committed
88
89
90
91
92
93
94

  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 " .
Feu's avatar
fix    
Feu committed
95
      "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$site->user->id."')) ";
Ayolo's avatar
Ayolo committed
96
97
  }

Feu's avatar
wip    
Feu committed
98
99
100
101

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

Feu's avatar
wip    
Feu committed
103
  $query .= "AND ( frm_sujet_utilisateur.etoile_sujet IS NULL OR frm_sujet_utilisateur.etoile_sujet!='1' ) ";
Ayolo's avatar
Ayolo committed
104
  $query .= "ORDER BY frm_message.date_message DESC ";
Feu's avatar
wip    
Feu committed
105
106
107
108
  $query .= "LIMIT 75 ";

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

Feu's avatar
wip    
Feu committed
110
111
112
113
  $req = new requete($site->db,$query_fav);
  if ( $req->lines > 0 )
  {
    $cts->add_title(2,"Sujets favoris avec des messages non lus");
114
115
116
    $rows = array();
    while ( $row = $req->get_row() )
      $rows[] = $row;
117

118
119
    $cts->add(new sujetslist($rows, $site->user, "./", null, null,true));
    $cts->add_paragraph("&nbsp;");
Feu's avatar
wip    
Feu committed
120
  }
121
122


Ayolo's avatar
Ayolo committed
123
  $req = new requete($site->db,$query);
Feu's avatar
wip    
Feu committed
124
125
126
  if ( $req->lines > 0 )
  {
    $cts->add_title(2,"Sujets avec des messages non lus");
127
128
129
    $rows = array();
    while ( $row = $req->get_row() )
      $rows[] = $row;
130

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

Ayolo's avatar
Ayolo committed
134
  $site->add_contents($cts);
135

Ayolo's avatar
Ayolo committed
136
137
138
139
  $site->end_page();
  exit();
}

Feu's avatar
wip    
Feu committed
140
if ( isset($_REQUEST["pattern"] ) )
Feu's avatar
wip    
Feu committed
141
{
142
143
144
145
146
147
148
  /*$pattern = ereg_replace("(e|é|è|ê|ë|É|È|Ê|Ë)","(e|é|è|ê|ë|É|È|Ê|Ë)",$_REQUEST["pattern"]);
  $pattern = ereg_replace("(a|à|â|ä|À|Â|Ä)","(a|à|â|ä|À|Â|Ä)",$pattern);
  $pattern = ereg_replace("(i|ï|î|Ï|Î)","(i|ï|î|Ï|Î)",$pattern);
  $pattern = ereg_replace("(c|ç|Ç)","(c|ç|Ç)",$pattern);
  $pattern = ereg_replace("(u|ù|ü|û|Ü|Û|Ù)","(u|ù|ü|û|Ü|Û|Ù)",$pattern);
  $pattern = ereg_replace("(n|ñ|Ñ)","(n|ñ|Ñ)",$pattern);
  $sqlpattern = mysql_real_escape_string($pattern);
149

Feu's avatar
test    
Feu committed
150
  $sql = "SELECT frm_sujet.*, frm_message.id_message, frm_message.contenu_message, frm_message.date_message ".
Feu's avatar
wip    
Feu committed
151
152
153
154
155
156
157
158
         "FROM frm_message INNER JOIN frm_sujet USING ( id_sujet ) WHERE ";

  $first=true;

  $words = explode(" ",$sqlpattern);
  foreach ( $words as $word )
  {
    if ( $first )
159
      $first=false;
Feu's avatar
wip    
Feu committed
160
161
    else
      $sql .= " AND ";
162

Feu's avatar
wip    
Feu committed
163
    $sql .= "(contenu_message REGEXP '$word' OR titre_sujet REGEXP '$word' OR soustitre_sujet REGEXP '$word')";
164

Feu's avatar
wip    
Feu committed
165
  }
166

Feu's avatar
test    
Feu committed
167
168
  $sql .= " ORDER BY frm_message.id_message DESC ";
  $sql .= "LIMIT 50";
Feu's avatar
Feu committed
169
  */
170

Feu's avatar
fix    
Feu committed
171
  $sql = "SELECT MATCH (titre_message,contenu_message) AGAINST ('".mysql_real_escape_string($_REQUEST["pattern"])."') AS deg, frm_sujet.*, frm_message.id_message, frm_message.contenu_message, frm_message.date_message ".
Feu's avatar
Feu committed
172
         "FROM frm_message INNER JOIN frm_sujet USING ( id_sujet ) WHERE ";
Feu's avatar
Feu committed
173
  $sql .= "MATCH (titre_message,contenu_message) AGAINST ('".mysql_real_escape_string($_REQUEST["pattern"])."') ";
Feu's avatar
fix    
Feu committed
174
  $sql .= "ORDER BY 1 DESC ";
Feu's avatar
Feu committed
175
  $sql .= "LIMIT 50";
176

Feu's avatar
wip    
Feu committed
177
  $req = new requete($site->db,$sql);
Feu's avatar
test    
Feu committed
178

179
180


Feu's avatar
wip    
Feu committed
181
  $site->start_page("forum","Recherche ".htmlentities($_REQUEST["pattern"],ENT_COMPAT,"UTF-8"));
182

Feu's avatar
test    
Feu committed
183
  $cts = new contents($forum->get_html_link()." / <a href=\"search.php\">Recherche</a> / <a href=\"search.php?pattern=".urlencode($_REQUEST["pattern"])."\">".htmlentities($_REQUEST["pattern"],ENT_COMPAT,"UTF-8")."</a>");
184
185


186
  //$cts->add(new sujetslist($rows, $site->user, "./", null, null, false));
187

188
    $id_sujet=null;
189

190
    $cts->buffer .= "<ul class=\"frmsujetres\">";
191

192
193
194
195
196
197
198
199
200
201
202
203
    while ( $row = $req->get_row() )
    {
      if (   $id_sujet!=$row['id_sujet'] )
      {
        if ( !is_null($id_sujet) )
          $cts->buffer .= "</ul>";
        $cts->buffer .=
        "<li class=\"sujet\"><a href=\"".$wwwtopdir."forum2/?id_sujet=".$row['id_sujet']."\">".
        "<img src=\"".$wwwtopdir."images/icons/16/sujet.png\" class=\"icon\" alt=\"\" /> <b>".
        $row['titre_sujet']."</b></a></li>";
        $cts->buffer .= "<ul class=\"frmmessagesres\">";
      }
204

205
      $cts->buffer .= "<li><a href=\"".$wwwtopdir."forum2/?id_message=".$row['id_message']."#msg".$row['id_message']."\">".substr($row['contenu_message'],0,120)."...</a> <span>- ".human_date(strtotime($row['date_message']))."</span></li>";
206

207
208
209
210
211
      $id_sujet=$row['id_sujet'];
    }
    if ( !is_null($id_sujet) )
      $cts->buffer .= "</ul>";
    $cts->buffer .= "</ul>";
212
213
214



Feu's avatar
wip    
Feu committed
215
  $site->add_contents($cts);
216

Feu's avatar
wip    
Feu committed
217
218
219
220
  $site->end_page();
  exit();

}
221

Feu's avatar
test    
Feu committed
222
223
224
$site->start_page("forum","Recherche");

$cts = new contents($forum->get_html_link()." / <a href=\"search.php\">Recherche</a>");
225

Feu's avatar
test    
Feu committed
226
227
228
$frm = new form("frmsearch",$wwwtopdir."forum2/search.php");
$frm->add_text_field("pattern","");
$frm->add_submit("search","Rechercher");
gliss's avatar
gliss committed
229
$frm->set_focus("pattern");
230
231
$cts->add($frm);

Feu's avatar
test    
Feu committed
232
$site->add_contents($cts);
Ayolo's avatar
Ayolo committed
233

Feu's avatar
test    
Feu committed
234
235
$site->end_page();
exit();
Ayolo's avatar
Ayolo committed
236

BenC's avatar
Bleh    
BenC committed
237
?>