index.php 42.2 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
<?php
2
/*
Feu's avatar
wip  
Feu committed
3
 * FORUM2
4
 *
5
 * Copyright 2007 - 2010
Feu's avatar
wip  
Feu committed
6 7
 * - Julien Etelain < julien dot etelain at gmail dot com >
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
8
 * - Benjamin Collet <bcollet at oxynux dot org>
Feu's avatar
wip  
Feu committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * 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.
 */
Krophil's avatar
Krophil committed
28 29
header("Location: https://ae2.utbm.fr/forum")

Ayolo's avatar
Ayolo committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
$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 ();
Antoine Tenart's avatar
Antoine Tenart committed
45

Antoine Tenart's avatar
Antoine Tenart committed
46
if (!$site->get_param ("forum_open", false)) {
Antoine Tenart's avatar
Antoine Tenart committed
47 48
  if (!$site->user->is_in_group ("moderateur_forum") &&
      !$site->user->is_in_group ("root")) {
Antoine Tenart's avatar
Antoine Tenart committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62
    $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
$site->add_css("css/forum.css");
Ayolo's avatar
bleh  
Ayolo committed
64
$site->add_css("css/doku.css");
Bate's avatar
Bate committed
65
$site->add_css("css/planning2.css");
pedrov's avatar
pedrov committed
66

Ayolo's avatar
Ayolo committed
67 68
if($site->user->is_in_group("ban_forum"))
{
Ayolo's avatar
bleh  
Ayolo committed
69
  $site->add_contents(new error("Vous n'avez pas respecté la charte de publication, votre présence n'est désormais plus souhaitée.",false));
Ayolo's avatar
Ayolo committed
70 71 72 73 74
  $site->end_page();
  exit();
}


Ayolo's avatar
Ayolo committed
75 76 77 78 79 80 81 82 83 84 85
$forum = new forum($site->db,$site->dbrw);
$pforum = new forum($site->db);
$sujet = new sujet($site->db,$site->dbrw);
$message = new message($site->db,$site->dbrw);

// Chargement des objets
if ( isset($_REQUEST["id_message"]) )
{
  $message->load_by_id($_REQUEST["id_message"]);
  if ( $message->is_valid() )
  {
86 87
    $sujet->load_by_id($message->id_sujet);
    $forum->load_by_id($sujet->id_forum);
Ayolo's avatar
Ayolo committed
88 89 90 91
  }
}
elseif ( isset($_REQUEST["id_sujet"]) )
{
92
  $sujet->load_by_id($_REQUEST["id_sujet"]);
Ayolo's avatar
Ayolo committed
93
  if ( $sujet->is_valid() )
Ayolo's avatar
Ayolo committed
94
  {
95
    $forum->load_by_id($sujet->id_forum);
Ayolo's avatar
Ayolo committed
96 97 98 99
  }
}
elseif ( isset($_REQUEST["id_forum"]) )
{
100
  $forum->load_by_id($_REQUEST["id_forum"]);
Ayolo's avatar
Ayolo committed
101
}
Feu's avatar
test  
Feu committed
102 103
elseif ( isset($_REQUEST["react"]) )
{
104

Feu's avatar
test  
Feu committed
105
  $conds=array();
106

Feu's avatar
test  
Feu committed
107 108
  if ( isset($_REQUEST["id_nouvelle"]) )
    $conds[]= "(`frm_sujet`.`id_nouvelle`='" . mysql_escape_string($_REQUEST["id_nouvelle"]) . "')";
109

Feu's avatar
wip  
Feu committed
110 111
  if ( isset($_REQUEST["id_catph"]) )
    $conds[]= "(`frm_sujet`.`id_catph`='" . mysql_escape_string($_REQUEST["id_catph"]) . "')";
112

Feu's avatar
wip  
Feu committed
113 114
  if ( isset($_REQUEST["id_sondage"]) )
    $conds[]= "(`frm_sujet`.`id_sondage`='" . mysql_escape_string($_REQUEST["id_sondage"]) . "')";
115

Feu's avatar
test  
Feu committed
116
  if ( count($conds) > 0 )
Feu's avatar
test  
Feu committed
117
  {
Feu's avatar
test  
Feu committed
118
    $sqlconds = implode(" AND ",$conds);
119

Feu's avatar
test  
Feu committed
120 121 122 123 124 125
    if ( $site->user->is_valid() )
    {
      $grps = $site->user->get_groups_csv();
      $req = new requete($site->db,"SELECT frm_sujet.* ".
        "FROM frm_sujet ".
        "INNER JOIN frm_forum USING(`id_forum`) ".
Ayolo's avatar
Ayolo committed
126 127
        "WHERE ((droits_acces_forum & 0x1) OR " .
        "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
Feu's avatar
test  
Feu committed
128 129 130 131 132 133 134 135 136 137
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_forum & 0x100) AND id_utilisateur='".$site->user->id."')) ".
        "AND $sqlconds");
    }
    else
      $req = new requete($site->db,"SELECT frm_sujet.* ".
        "FROM frm_sujet ".
        "INNER JOIN frm_forum USING(`id_forum`) ".
        "WHERE (droits_acces_forum & 0x1) ".
        "AND $sqlconds");
138

Feu's avatar
test  
Feu committed
139 140 141
    if ( $req->lines > 0 )
    {
      $sujet->_load($req->get_row());
142
      $forum->load_by_id($sujet->id_forum);
Feu's avatar
test  
Feu committed
143 144
    }
    else
Feu's avatar
test  
Feu committed
145
    {
Feu's avatar
test  
Feu committed
146 147 148 149 150 151 152 153
      $forum->load_by_id(3);
      if ( isset($_REQUEST["id_asso"]) && !is_null($_REQUEST["id_asso"]) )
      {
        $req = new requete($site->db,"SELECT * FROM frm_forum WHERE id_asso='".mysql_escape_string($_REQUEST["id_asso"])."' AND categorie_forum=0");
        if ( $req->lines > 0 )
          $forum->_load($req->get_row());
      }
      $_REQUEST["page"]="post";
Feu's avatar
test  
Feu committed
154 155 156 157
    }
  }
}

Feu's avatar
Feu committed
158 159
if ( isset($_REQUEST["setnosecret"]) )
  setcookie ("nosecret", $_REQUEST["setnosecret"], time() + 31536000, "/", $domain, 0);
Feu's avatar
test  
Feu committed
160

Ayolo's avatar
Ayolo committed
161

Skia's avatar
Skia committed
162 163 164
if ( !$forum->is_valid() ) {
  $site->add_rss("Les 40 derniers messages du forum de l'AE",
             "rss.php?id_utilisateur=".$site->user->id."&serviceident=".$site->user->serviceident);
Ayolo's avatar
Ayolo committed
165
  $forum->load_by_id(1); // Le forum id=1 est la racine
Skia's avatar
Skia committed
166 167 168 169
} else {
  $site->add_rss("Les 40 derniers messages du forum de l'AE",
             "rss.php?id_utilisateur=".$site->user->id."&serviceident=".$site->user->serviceident."&id_forum=".$forum->id);
}
Ayolo's avatar
Ayolo committed
170 171 172

if ( !$forum->is_right($site->user,DROIT_LECTURE) )
{
mbriand's avatar
mbriand committed
173
  $site->error_forbidden("forum");
Ayolo's avatar
Ayolo committed
174 175
}

gliss's avatar
wip  
gliss committed
176
if( isset($_REQUEST['get_preview']) )
gliss's avatar
gliss committed
177
{
Ayolo's avatar
utf8  
Ayolo committed
178 179
  $message->titre = html_entity_decode($_REQUEST['title'], ENT_NOQUOTES, 'UTF-8');
  $message->contenu = html_entity_decode($_REQUEST['content'], ENT_NOQUOTES, 'UTF-8');
gliss's avatar
wip  
gliss committed
180 181
  $message->id_utilisateur = $_REQUEST['user'];
  $message->syntaxengine = $_REQUEST['syntaxengine'];
gliss's avatar
gliss committed
182
  $message->date = time();
183 184


gliss's avatar
wip  
gliss committed
185
  $preview = new simplemessageforum($message);
186
  header("Content-Type: text/javascript; charset=utf-8");
gliss's avatar
gliss committed
187
  echo "<h2>Prévisualisation</h2>";
gliss's avatar
wip  
gliss committed
188
  echo( $preview->html_render() );
189
  echo "<h2>Historique</h2>";
190

191
  exit();
gliss's avatar
gliss committed
192
}
Ayolo's avatar
Ayolo committed
193 194 195 196

if ( $_REQUEST["action"] == "setallread" )
{
  $site->allow_only_logged_users("forum");
Feu's avatar
wip  
Feu committed
197 198
  $site->user->set_all_read( );
  header("Location: ".$wwwtopdir."forum2/index.php");
199
  exit();
Ayolo's avatar
Ayolo committed
200 201 202 203 204 205 206
}


/* postage d'un nouveau sujet */
if ( $_REQUEST["action"] == "post" && !$forum->categorie )
{
  $site->allow_only_logged_users("forum");
207

Ayolo's avatar
Ayolo committed
208
  $_REQUEST["page"]="post";
209

Ayolo's avatar
Ayolo committed
210 211
  if ( !$_REQUEST["titre_sujet"] )
    $Erreur="Veuillez préciser un titre";
212

Ayolo's avatar
Ayolo committed
213 214
  elseif ( !$_REQUEST["subjtext"] )
    $Erreur="Veuillez saisir le texte du message";
215

Ayolo's avatar
Ayolo committed
216 217
  elseif ( $GLOBALS['svalid_call'] )
  {
218

Ayolo's avatar
Ayolo committed
219 220
    $type=SUJET_NORMAL;
    $date_fin_annonce=null;
221

Ayolo's avatar
Ayolo committed
222 223 224
    if ( $forum->is_admin($site->user) )
    {
      $type = $_REQUEST["subj_type"];
225 226
      if ( $type == SUJET_ANNONCESITE &&
        !$site->user->is_in_group("moderateur_forum") &&
Ayolo's avatar
Ayolo committed
227 228 229 230
        !$site->user->is_in_group("root") )
      {
        $type = SUJET_ANNONCE;
        $date_fin_annonce=$_REQUEST["date_fin_announce_site"];
231
      }
Ayolo's avatar
Ayolo committed
232 233
      elseif ( $type == SUJET_ANNONCE )
        $date_fin_annonce=$_REQUEST["date_fin_announce"];
234

Ayolo's avatar
Ayolo committed
235 236 237
      elseif ( $type == SUJET_ANNONCESITE )
        $date_fin_annonce=$_REQUEST["date_fin_announce_site"];
    }
238

Ayolo's avatar
Ayolo committed
239 240 241
    $news = new nouvelle($site->db);
    $catph = new catphoto($site->db);
    $sdn = new sondage($site->db);
242

Ayolo's avatar
Ayolo committed
243 244
    if ( isset($_REQUEST["id_nouvelle"]) )
      $news->load_by_id($_REQUEST["id_nouvelle"]);
245

Ayolo's avatar
Ayolo committed
246 247
    elseif ( isset($_REQUEST["id_catph"]) )
      $catph->load_by_id($_REQUEST["id_catph"]);
248

Ayolo's avatar
Ayolo committed
249 250
    elseif ( isset($_REQUEST["id_sondage"]) )
      $sdn->load_by_id($_REQUEST["id_sondage"]);
251

Ayolo's avatar
Ayolo committed
252 253 254
    $sujet->create ( $forum, $site->user->id, $_REQUEST["titre_sujet"], $_REQUEST["soustitre_sujet"],
        $type,null,$date_fin_annonce,
        $news->id,$catph->id,$sdn->id );
255

Ayolo's avatar
Ayolo committed
256
    $subjtext = $message->commit_replace($_REQUEST['subjtext'],$site->user);
257

Ayolo's avatar
Ayolo committed
258
    $message->create($forum,
Ayolo's avatar
Ayolo committed
259 260 261 262 263
            $sujet,
            $site->user->id,
            $_REQUEST['titre_sujet'],
            $subjtext,
            $_REQUEST['synengine']);
264

Feu's avatar
wip  
Feu committed
265 266
    if ( isset($_REQUEST['star']) )
      $sujet->set_user_star($site->user->id,true);
267

Ayolo's avatar
Ayolo committed
268 269
  }
}
270

Ayolo's avatar
Ayolo committed
271 272
if ( $_REQUEST['page'] == 'delete' )
{
Feu's avatar
fix  
Feu committed
273
  $site->allow_only_logged_users("forum");
Skia's avatar
Skia committed
274

Bate's avatar
Bate committed
275

Ayolo's avatar
Ayolo committed
276 277
  if ( $message->is_valid() )
  {
278 279 280
    $user = new utilisateur($site->db);
    $user->load_by_id($message->id_utilisateur);

Bate's avatar
Bate committed
281 282 283 284 285 286 287 288 289 290
	if ( !isset($_POST["___i_am_really_sure"]) && !isset($_POST["___finally_i_want_to_cancel"]) )
	  {
	    $site->start_page($section,"Êtes vous sûr ?");

	    $cts = new contents("Confirmation");

	    $cts->add_paragraph("Suppression du message ".$message->id." de ".$user->prenom." ".$user->nom." du ".human_date($message->date).".");

	    $cts->add_paragraph("Êtes vous sûr ?");

Bate's avatar
Bate committed
291
	    $frm = new form("suppressmess","?");
Bate's avatar
Bate committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
	    $frm->allow_only_one_usage();
	     foreach ( $_POST as $key => $val )
	      if ( $key != "magicform" )
	      {
		if($key=="__script__")
		  $frm->add_hidden($key,htmlspecialchars($val));
		else if (is_array($val))
		{
		  foreach ( $val as $k => $v )
		    $frm->add_hidden($key.'['.$k.']',$v);
		}
		else
		  $frm->add_hidden($key,$val);
	      }
	    foreach ( $_GET as $key => $val )
	      if ( $key != "magicform" )
	      {
		if (is_array($val))
		{
		  foreach ( $val as $k => $v )
		    $frm->add_hidden($key.'['.$k.']',$v);
		}
		else
		  $frm->add_hidden($key,$val);
	      }

Bate's avatar
Bate committed
318
	    if($message->id_utilisateur != $site->user->id)
Bate's avatar
Bate committed
319 320 321
		    $frm->add_text_area("raison",
			"Raison de la modération (obligatoire)",
			"",40,4,true, true);
Bate's avatar
Bate committed
322

Bate's avatar
Bate committed
323 324
	    $frm->add_submit("___i_am_really_sure","Valider");
	    $frm->add_submit("___finally_i_want_to_cancel","Annuler");
Bate's avatar
Bate committed
325 326 327 328 329 330 331 332 333 334

	    $cts->add($frm);

	    $site->add_contents($cts);

	    $site->end_page();
	    exit();
	  }
	elseif ((($forum->is_admin($site->user)) || ($message->id_utilisateur == $site->user->id))
      && isset($_POST["___i_am_really_sure"]))
Bate's avatar
Bate committed
335
	{
Skia's avatar
Skia committed
336
	  $raison = trim($_REQUEST["raison"]);
Bate's avatar
Bate committed
337
	  if( empty($raison) && ($message->id_utilisateur != $site->user->id))
Bate's avatar
Bate committed
338
	  {
Bate's avatar
Bate committed
339 340
                $cts = new contents("Raison manquante",
                        "La raison pour la suppression est obligatoire.");
Bate's avatar
Bate committed
341 342
		$site->add_contents($cts);
		$site->end_page();
Bate's avatar
Bate committed
343 344
		exit();
	  }
Ayolo's avatar
Ayolo committed
345
      $message_initial = new message($site->db);
346 347
      $message_initial->load_initial_of_sujet($sujet->id);

Ayolo's avatar
Ayolo committed
348 349 350
      if ( $message_initial->id == $message->id ) // La supression du message initial, entraine la supression du sujet
        $sujet->delete($forum);
      else
351
        $ret =$message->delete($forum, $sujet, $site->user->id);
352

Bate's avatar
Bate committed
353
      $utl_concerne = new utilisateur($site->db);
Bate's avatar
Bate committed
354
      $utl_concerne->load_by_id($message->id_utilisateur);
Bate's avatar
Bate committed
355
      if($utl_concerne->is_valid() && $message->id_utilisateur != $site->user->id)
Bate's avatar
Bate committed
356
	      $utl_concerne->send_email("Suppression d'un de vos message",
Bate's avatar
Bate committed
357
		      "Votre message\n\n\"$message->contenu\"\n\na été modéré par "
Bate's avatar
Bate committed
358 359 360
		      .$site->user->prenom." ".$site->user->nom." pour la raison".
		      " suivante:\n\n$raison");

Ayolo's avatar
Ayolo committed
361
      $cts = new contents("Suppression d'un message",
Ayolo's avatar
Ayolo committed
362
        "Message supprimé avec succès.");
Ayolo's avatar
Ayolo committed
363 364 365
    }
    else
      $cts = new contents("Suppression d'un message",
Ayolo's avatar
Ayolo committed
366
        "Vous n'avez pas les autorisations nécessaires pour supprimer ce message.");
367

Ayolo's avatar
Ayolo committed
368 369 370 371
    $site->add_contents($cts);
  }
  elseif ( $sujet->is_valid() )
  {
372 373 374 375
    $user = new utilisateur($site->db);
    $user->load_by_id($sujet->id_utilisateur);

    if ((($forum->is_admin($site->user))
Ayolo's avatar
Ayolo committed
376
        || ($sujet->id_utilisateur == $site->user->id))
377
        && $site->is_sure("", "Suppression du sujet ".$sujet->id." de ".$user->prenom." ".$user->nom." du ".human_date($sujet->date).". Ceci est irréversible.", 1))
Ayolo's avatar
Ayolo committed
378
    {
379
      $ret =$sujet->delete($forum, $site->user->id);
Ayolo's avatar
Ayolo committed
380
      $cts = new contents("Suppression d'un sujet",
Ayolo's avatar
Ayolo committed
381
        "Sujet supprimé avec succès.");
Ayolo's avatar
Ayolo committed
382 383 384
    }
    else
      $cts = new contents("Suppression d'un Sujet",
Ayolo's avatar
Ayolo committed
385
        "Vous n'avez pas les autorisations nécessaires pour supprimer ce sujet.");
386

Ayolo's avatar
Ayolo committed
387 388 389
    $site->add_contents($cts);
  }
}
390 391 392 393 394 395 396 397
if ( $_REQUEST['page'] == 'undelete' )
{
  $site->allow_only_logged_users("forum");
  if ( $message->is_valid() )
  {
    $user = new utilisateur($site->db);
    $user->load_by_id($message->id_utilisateur);

398
      if ($site->user->is_in_group("moderateur_forum")
399 400
      && $site->is_sure("", "Rétablir le message ".$message->id." de ".$user->prenom." ".$user->nom." du ".human_date($message->date).".", 1))
    {
401
      $ret =$message->undelete($forum, $sujet, $site->user->id);
402 403 404 405 406 407 408 409 410 411 412

      $cts = new contents("Suppression d'un message",
        "Message supprimé avec succès.");
    }
    else
      $cts = new contents("Suppression d'un message",
        "Vous n'avez pas les autorisations nécessaires pour rétablir ce message.");

    $site->add_contents($cts);
  }
}
Ayolo's avatar
Ayolo committed
413 414 415 416 417 418 419 420 421 422 423 424

if ( $sujet->is_valid() )
  $path = $forum->get_html_link()." / ".$sujet->get_html_link();
else
  $path = $forum->get_html_link();

$pforum->load_by_id($forum->id_forum_parent);
while ( $pforum->is_valid() )
{
  $path = $pforum->get_html_link()." / ".$path;
  $pforum->load_by_id($pforum->id_forum_parent);
}
425

Ayolo's avatar
Ayolo committed
426 427
if ( $sujet->is_valid() )
{
Feu's avatar
wip  
Feu committed
428 429 430 431 432 433 434 435 436 437 438
  if ($_REQUEST['action'] == 'star')
  {
    $site->allow_only_logged_users("forum");
    $sujet->set_user_star($site->user->id,true);
  }
  elseif ($_REQUEST['action'] == 'unstar')
  {
    $site->allow_only_logged_users("forum");
    $sujet->set_user_star($site->user->id,false);
  }
  elseif ($_REQUEST['page'] == 'edit')
Ayolo's avatar
Ayolo committed
439
  {
Feu's avatar
fix  
Feu committed
440
    $site->allow_only_logged_users("forum");
441

Ayolo's avatar
Ayolo committed
442 443
    if ( $message->is_valid() ) // On edite un message
    {
444
      if ($message->id_utilisateur != $site->user->id && !$forum->is_admin($site->user))
Ayolo's avatar
Ayolo committed
445
        $site->error_forbidden("forum","group");
446

Ayolo's avatar
Ayolo committed
447 448
      $site->start_page("forum",$sujet->titre);

449
      $frm = new form("frmedit",
Ayolo's avatar
Ayolo committed
450 451
          "?page=commitedit&amp;id_sujet=".
          $sujet->id."&amp;".
452
          "id_message=".$message->id."#msg".$message->id,
Ayolo's avatar
Ayolo committed
453
          true);
454

Ayolo's avatar
Ayolo committed
455 456
      $frm->add_text_field("title", "Titre du message : ", $message->titre,false,80);
      $frm->add_select_field('synengine',
Ayolo's avatar
Ayolo committed
457 458 459
           'Moteur de rendu : ',
           array('bbcode' => 'bbcode (type phpBB)','doku' => 'Doku Wiki (recommandé)'),
           $message->syntaxengine);
460
      if ( $message->syntaxengine == "doku" )
Ayolo's avatar
bleh  
Ayolo committed
461
        $frm->add_dokuwiki_toolbar('text',$forum->id_asso,null,true);
Ayolo's avatar
Ayolo committed
462 463
      $frm->add_text_area("text", "Texte du message : ",$message->contenu,80,20);
      $frm->add_submit("submit", "Modifier");
gliss's avatar
gliss committed
464
      $frm->puts("<div class=\"formrow\"><div class=\"formlabel\"></div><div class=\"formfield\"><input type=\"button\" id=\"preview\" name=\"preview\" value=\"Prévisualiser\" class=\"isubmit\" onClick=\"javascript:make_preview();\" /></div></div>\n");
Ayolo's avatar
Ayolo committed
465
      $frm->allow_only_one_usage();
466

Ayolo's avatar
Ayolo committed
467
      $cts = new contents($path." / Edition");
468

gliss's avatar
gliss committed
469 470 471
      $cts->add_paragraph("<script language=\"javascript\">
      function make_preview()
      {
gliss's avatar
fix  
gliss committed
472 473
        title = document.frmedit.title.value;
        content = document.frmedit.text.value;
gliss's avatar
gliss committed
474
        user = ".$site->user->id.";
gliss's avatar
fix  
gliss committed
475
        syntaxengine = document.frmedit.synengine.value;
476

Ayolo's avatar
utf8  
Ayolo committed
477
        openInContents('msg_preview', './index.php', 'get_preview&title='+encodeURIComponent(title)+'&content='+encodeURIComponent(content)+'&user='+user+'&syntaxengine='+syntaxengine);
gliss's avatar
gliss committed
478 479
      }
      </script>\n");
480

Ayolo's avatar
Ayolo committed
481
      $cts->add($frm);
482

gliss's avatar
gliss committed
483
      $cts->puts("<div id=\"msg_preview\"></div>");
484

Ayolo's avatar
Ayolo committed
485 486 487 488
      $site->add_contents($cts);
      $site->end_page();
      exit();
    }
489

Ayolo's avatar
Ayolo committed
490
    // On edite le sujet
491 492

    if ($sujet->id_utilisateur != $site->user->id && !$forum->is_admin($site->user))
Ayolo's avatar
Ayolo committed
493
      $site->error_forbidden("forum","group");
494

Ayolo's avatar
Ayolo committed
495
    // Recupération du premier message du sujet
496 497
    $message->load_initial_of_sujet($sujet->id);

Ayolo's avatar
Ayolo committed
498 499
    $site->start_page("forum",$sujet->titre);
    $cts = new contents($path." / Edition");
500 501 502

    $frm = new form("frmedit",
        "?page=commitedit&amp;id_sujet=".$sujet->id,
Ayolo's avatar
Ayolo committed
503
        true);
504

Ayolo's avatar
Ayolo committed
505 506
    if ( $forum->is_admin($site->user) )
    {
507
      if ( !$sujet->type )
Ayolo's avatar
Ayolo committed
508
        $sujet->type = SUJET_NORMAL;
509

Ayolo's avatar
Ayolo committed
510 511
      $sfrm = new form("subj_type",null,null,null,"Sujet normal");
      $frm->add($sfrm,false,true, $sujet->type==SUJET_NORMAL ,SUJET_NORMAL ,false,true);
512

Ayolo's avatar
Ayolo committed
513 514
      $sfrm = new form("subj_type",null,null,null,"Sujet épinglé, il sera toujours affiché en haut");
      $frm->add($sfrm,false,true, $sujet->type==SUJET_STICK ,SUJET_STICK ,false,true);
515

Ayolo's avatar
Ayolo committed
516
      $sfrm = new form("subj_type",null,null,null,"Annonce, le message sera affiché en haut dans un cadre séparé");
517
      $sfrm->add_datetime_field('date_fin_announce',
Ayolo's avatar
Ayolo committed
518 519
             'Date de fin de l\'annonce',
             $sujet->date_fin_annonce);
Ayolo's avatar
Ayolo committed
520
      $frm->add($sfrm,false,true, $sujet->type==SUJET_ANNONCE ,SUJET_ANNONCE ,false,true);
521

Ayolo's avatar
Ayolo committed
522 523 524
      if ( $site->user->is_in_group("moderateur_forum") || $site->user->is_in_group("root") )
      {
        $sfrm = new form("subj_type",null,null,null,"Annonce du site, le message sera affiché en haut sur la première page du forum");
525
        $sfrm->add_datetime_field('date_fin_announce_site',
Ayolo's avatar
Ayolo committed
526 527
               'Date de fin de l\'annonce',
               $sujet->date_fin_annonce);
Ayolo's avatar
Ayolo committed
528 529 530
        $frm->add($sfrm,false,true, $sujet->type==SUJET_ANNONCESITE ,SUJET_ANNONCESITE ,false,true);
      }
    }
531

Ayolo's avatar
Ayolo committed
532 533 534
    /**
     * @todo : edition des metas données
     */
mbriand's avatar
mbriand committed
535 536 537 538 539 540
    $forum_cats = array();
    $sql = "SELECT id_forum, titre_forum FROM frm_forum ORDER BY titre_forum";
    $req = new requete($site->db, $sql);
    while( list($value,$name) = $req->get_row()){
      $forum_cats[$value] = $name;
    }
541

mbriand's avatar
mbriand committed
542
    $frm->add_select_field('id_dst_forum', 'Forum : ', $forum_cats, $sujet->id_forum);
Ayolo's avatar
Ayolo committed
543
    $frm->add_text_field("titre", "Titre : ", $sujet->titre,true,80);
544 545
    $frm->add_text_field("soustitre","Sous-titre du message (optionel) : ",$sujet->soustitre,false,80);

Ayolo's avatar
Ayolo committed
546
    $frm->add_select_field('synengine',
Ayolo's avatar
Ayolo committed
547 548 549
         'Moteur de rendu : ',
         array('bbcode' => 'bbcode (type phpBB)','doku' => 'Doku Wiki (recommandé)'),
         $message->syntaxengine);
Ayolo's avatar
bleh  
Ayolo committed
550
    $frm->add_dokuwiki_toolbar('text',$forum->id_asso,null,true);
Ayolo's avatar
Ayolo committed
551 552
    $frm->add_text_area("text", "Texte du message : ",$message->contenu,80,20);
    $frm->add_submit("submit", "Modifier");
553
    $frm->puts("<div class=\"formrow\"><div class=\"formlabel\"></div><div class=\"formfield\"><input type=\"button\" id=\"preview\" name=\"preview\" value=\"Prévisualiser\" class=\"isubmit\" onClick=\"javascript:make_preview();\" /></div></div>\n");
Ayolo's avatar
Ayolo committed
554
    $frm->allow_only_one_usage();
555

556 557 558 559 560 561 562
    $cts->add_paragraph("<script language=\"javascript\">
      function make_preview()
      {
        title = document.frmedit.title.value;
        content = document.frmedit.text.value;
        user = ".$site->user->id.";
        syntaxengine = document.frmedit.synengine.value;
563

Ayolo's avatar
utf8  
Ayolo committed
564
        openInContents('msg_preview', './index.php', 'get_preview&title='+encodeURIComponent(title)+'&content='+encodeURIComponent(content)+'&user='+user+'&syntaxengine='+syntaxengine);
565 566
      }
      </script>\n");
567

Ayolo's avatar
Ayolo committed
568
    $cts->add($frm);
569
    $cts->puts("<div id=\"msg_preview\"></div>");
570

Ayolo's avatar
Ayolo committed
571 572 573
    /**@todo*/
    $site->add_contents($cts);
    $site->end_page();
574

Ayolo's avatar
Ayolo committed
575 576 577 578 579
    exit();
  }

  if ($_REQUEST['page'] == 'commitedit')
  {
Feu's avatar
fix  
Feu committed
580
    $site->allow_only_logged_users("forum");
581

Ayolo's avatar
Ayolo committed
582 583 584 585 586 587 588
    //$site->start_page("forum",$sujet->titre);
    if ( $message->is_valid() )
    {
      if ((($message->id_utilisateur == $site->user->id)
        || ($forum->is_admin($site->user)))
        && ($GLOBALS['svalid_call'] == true))
      {
Ayolo's avatar
Ayolo committed
589
        $text = $message->commit_replace($_REQUEST['text'],$site->user);
590
        $ret = $message->update($forum,
Ayolo's avatar
Ayolo committed
591 592 593
              $sujet,
              $_REQUEST['title'],
              $text,
594
              $_REQUEST['synengine'], $site->user->id);
Ayolo's avatar
Ayolo committed
595 596 597
        $cts = new contents("Modification d'un message", "Message modifié");
      }
      else
598
        $cts = new contents("Modification d'un message",
Ayolo's avatar
Ayolo committed
599
          "Erreur lors de la modification du message. Assurez-vous d'avoir les privilèges suffisants.");
600

Ayolo's avatar
Ayolo committed
601 602 603 604
      $site->add_contents($cts);
    }
    elseif ($GLOBALS['svalid_call'] == true)
    {
605
      if ($sujet->id_utilisateur != $site->user->id && !$forum->is_admin($site->user))
Ayolo's avatar
Ayolo committed
606
        $site->error_forbidden("forum","group");
607 608 609

      $message->load_initial_of_sujet($sujet->id);

Ayolo's avatar
Ayolo committed
610
      $text = $message->commit_replace($_REQUEST['text'],$site->user);
611

612
      $message->update($forum,
Ayolo's avatar
Ayolo committed
613 614 615
              $sujet,
              $_REQUEST['titre'],
              $text,
616
              $_REQUEST['synengine'], $site->user->id);
617

Ayolo's avatar
Ayolo committed
618 619
      $type=SUJET_NORMAL;
      $date_fin_annonce=null;
620

Ayolo's avatar
Ayolo committed
621 622 623
      if ( $forum->is_admin($site->user) )
      {
        $type = $_REQUEST["subj_type"];
624 625
        if ( $type == SUJET_ANNONCESITE &&
          !$site->user->is_in_group("moderateur_forum") &&
Ayolo's avatar
Ayolo committed
626 627 628 629
          !$site->user->is_in_group("root") )
        {
          $type = SUJET_ANNONCE;
          $date_fin_annonce=$_REQUEST["date_fin_announce_site"];
630
        }
Ayolo's avatar
Ayolo committed
631 632
        elseif ( $type == SUJET_ANNONCE )
          $date_fin_annonce=$_REQUEST["date_fin_announce"];
633

Ayolo's avatar
Ayolo committed
634 635
        elseif ( $type == SUJET_ANNONCESITE )
          $date_fin_annonce=$_REQUEST["date_fin_announce_site"];
mbriand's avatar
mbriand committed
636 637 638 639 640

        if ($_REQUEST['id_dst_forum'] != $message->id_forum)
        {
          $dst_forum = new forum($site->db);
          $dst_forum->load_by_id($_REQUEST['id_dst_forum']);
mbriand's avatar
mbriand committed
641
          $sujet->move_to($forum, $dst_forum);
mbriand's avatar
mbriand committed
642
          $forum = $dst_forum;
mbriand's avatar
mbriand committed
643
        }
Ayolo's avatar
Ayolo committed
644 645 646 647 648
      }

      $sujet->update ($_REQUEST["titre"], $_REQUEST["soustitre"],
          $type,null,$date_fin_annonce,
          $sujet->id_nouvelle,$sujet->id_catph,$sujet->id_sondage );
649

Ayolo's avatar
Ayolo committed
650 651 652
    }
    //$site->end_page();
    //exit();
653
  }
Ayolo's avatar
Ayolo committed
654 655 656 657 658 659 660

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

    $site->start_page("forum",$sujet->titre);

661 662
    $cts = new contents($path." / <a href=\"?id_sujet=".$sujet->id."&amp;page=reply\">Répondre</a>");

gliss's avatar
test  
gliss committed
663 664 665
    $cts->add_paragraph("<script language=\"javascript\">
      function make_preview()
      {
gliss's avatar
gliss committed
666 667
        title = document.frmreply.rpltitle.value;
        content = document.frmreply.rpltext.value;
gliss's avatar
test  
gliss committed
668 669
        user = ".$site->user->id.";
        syntaxengine = document.frmreply.synengine.value;
670

Ayolo's avatar
utf8  
Ayolo committed
671
        openInContents('msg_preview', './index.php', 'get_preview&title='+encodeURIComponent(title)+'&content='+encodeURIComponent(content)+'&user='+user+'&syntaxengine='+syntaxengine);
gliss's avatar
test  
gliss committed
672 673
      }
      </script>\n");
674

Ayolo's avatar
Ayolo committed
675
    /* formulaire d'invite à postage de réponse */
Feu's avatar
wip  
Feu committed
676
    $frm = new form("frmreply", "?page=commit&amp;id_sujet=".$sujet->id."#lastmessage", true);
677

Ayolo's avatar
Ayolo committed
678
    if (intval($_REQUEST['quote']) == 1)
Ayolo's avatar
Ayolo committed
679 680 681 682 683 684 685
    {
      $_auteur="";
      /* l'objet message doit alors etre chargé */
      if($message->id_utilisateur>0)
      {
        $_auteur=new utilisateur($site->db,$site->dbrw);
        $_auteur->load_by_id($message->id_utilisateur);
furtif's avatar
debug  
furtif committed
686
        if(!is_null($_auteur->id)){
687
          $req = new requete($site->db, "SELECT * FROM `utl_etu_utbm` WHERE `id_utilisateur` =".$_auteur->id." ;");
furtif's avatar
furtif committed
688
          $_auteur->_load_extras($req->get_row());
furtif's avatar
furtif committed
689
          $_auteur="=".($_auteur->surnom!=null ? $_auteur->surnom : $_auteur->alias);
690
        }
Ayolo's avatar
Ayolo committed
691
      }
692

furtif's avatar
furtif committed
693
      $rpltext = "[quote".$_auteur."]".$message->contenu . "[/quote]";
Ayolo's avatar
Ayolo committed
694
      $rpltitle = "Re : " . $message->titre;
Ayolo's avatar
Ayolo committed
695
    }
696
    else
Ayolo's avatar
Ayolo committed
697
    {
Ayolo's avatar
Ayolo committed
698
      $rpltext = '';
699
      $rpltitle = '';
Ayolo's avatar
Ayolo committed
700
    }
Ayolo's avatar
Ayolo committed
701 702 703

    $frm->add_text_field("rpltitle", "Titre du message : ", $rpltitle,false,80);
    $frm->add_select_field('synengine',
Ayolo's avatar
Ayolo committed
704 705
         'Moteur de rendu : ',
         array('bbcode' => 'bbcode (type phpBB)','doku' => 'Doku Wiki (recommandé)'),'doku');
Ayolo's avatar
bleh  
Ayolo committed
706
    $frm->add_dokuwiki_toolbar('rpltext',$forum->id_asso,null,true);
Ayolo's avatar
Ayolo committed
707
    $frm->add_text_area("rpltext", "Texte du message : ",$rpltext,80,20);
Feu's avatar
fix  
Feu committed
708
    $frm->add_checkbox ( "star", "Ajouter à mes sujets favoris.", true );
Ayolo's avatar
Ayolo committed
709
    $frm->add_submit("rplsubmit", "Poster");
gliss's avatar
gliss committed
710
    $frm->puts("<div class=\"formrow\"><div class=\"formlabel\"></div><div class=\"formfield\"><input type=\"button\" id=\"preview\" name=\"preview\" value=\"Prévisualiser\" class=\"isubmit\" onClick=\"javascript:make_preview();\" /></div></div>\n");
711

Ayolo's avatar
Ayolo committed
712 713
    $frm->allow_only_one_usage();
    $cts->add($frm);
gliss's avatar
gliss committed
714

gliss's avatar
gliss committed
715
    $cts->puts("<div id=\"msg_preview\"></div>");
716

Ayolo's avatar
Ayolo committed
717 718 719
    $npp=40;
    $nbpages = ceil($sujet->nb_messages / $npp);
    $start = ($nbpages - 1) * $npp;
720 721 722 723 724 725 726

    $cts->add(new sujetforum ($forum,
          $sujet,
          $site->user,
          "./",
          0,
          40,
Ayolo's avatar
Ayolo committed
727
          "DESC" ));
728

Feu's avatar
wip  
Feu committed
729

Ayolo's avatar
Ayolo committed
730 731
    $site->add_contents($cts);
    $site->end_page();
732
    exit();
Ayolo's avatar
Ayolo committed
733 734
  }

735

Ayolo's avatar
Ayolo committed
736 737 738
  /* réponse postée */
  if ($_REQUEST['page'] == 'commit')
  {
Feu's avatar
FIX  
Feu committed
739
    $site->allow_only_logged_users("forum");
740

Feu's avatar
wip  
Feu committed
741 742
    if ( isset($_REQUEST['star']) )
      $sujet->set_user_star($site->user->id,true);
743

Ayolo's avatar
Ayolo committed
744 745 746
    $site->start_page("forum",$sujet->titre);

    $cts = new contents($path.
Ayolo's avatar
Ayolo committed
747 748
      " / <a href=\"?id_sujet=".
      $sujet->id.
749 750
      "&amp;page=reply\">Répondre</a>");

Ayolo's avatar
Ayolo committed
751
    /*  sujet */
752

Ayolo's avatar
Ayolo committed
753 754 755
    /* nombre de posts par page */
    $npp=40;

Ayolo's avatar
Ayolo committed
756
    $rpltext = $message->commit_replace($_REQUEST['rpltext'],$site->user);
BenC's avatar
wip  
BenC committed
757

Ayolo's avatar
Ayolo committed
758
    if (($GLOBALS['svalid_call'] == true) && ($_REQUEST['rpltext'] != ''))
Ayolo's avatar
Ayolo committed
759 760 761 762 763 764
      $retpost = $message->create($forum,
            $sujet,
            $site->user->id,
            $_REQUEST['rpltitle'],
            $rpltext,
            $_REQUEST['synengine']);
Ayolo's avatar
Ayolo committed
765 766
    else
      $retpost = false;
767

Ayolo's avatar
Ayolo committed
768 769 770 771
    /* nombre de pages */
    $nbpages = ceil($sujet->nb_messages / $npp);
    /* on va à la derniere */
    $start = ($nbpages - 1) * $npp;
772 773 774 775 776 777

    $cts->add(new sujetforum ($forum,
      $sujet,
      $site->user,
      "./",
      $start,
Ayolo's avatar
Ayolo committed
778
      $npp));
779

Ayolo's avatar
Ayolo committed
780
    if ($retpost == true)
Ayolo's avatar
Ayolo committed
781
      $answ = new contents("Poster une réponse",
782
           "<b>Réponse postée avec succès.</b>");
Ayolo's avatar
Ayolo committed
783
    else
784
      $answ = new contents("Poster une réponse",
Ayolo's avatar
Ayolo committed
785
           "<b>Echec lors de la tentative de postage de la réponse.</b>");
Ayolo's avatar
Ayolo committed
786 787

    if ($GLOBALS['svalid_call'] == false)
Ayolo's avatar
Ayolo committed
788
      $answ->add_paragraph('Votre réponse a déjà été postée.');
Ayolo's avatar
Ayolo committed
789 790 791 792 793

    $site->add_contents($answ);

    for($n=0 ; $n<$nbpages ; $n++)
      $entries[]=array($n,"forum2/?id_sujet=".$sujet->id."&spage=".$n,$n+1);
794

Ayolo's avatar
Ayolo committed
795
    $cts->add(new tabshead($entries, floor($start/$npp), "_bottom"));
796

Feu's avatar
fix  
Feu committed
797 798
    $cts->add_paragraph("<a href=\"?id_sujet=".$sujet->id."&amp;page=reply\"><img src=\"".$wwwtopdir."images/icons/16/message.png\" class=\"icon\" alt=\"\" />Répondre</a>","frmtools");
    $cts->add_paragraph($path);
799

Feu's avatar
fix  
Feu committed
800
    $site->add_contents($cts);
801

Ayolo's avatar
Ayolo committed
802 803 804
    $site->end_page();
    exit();
  }
805

Ayolo's avatar
Ayolo committed
806 807

  $site->start_page("forum",$sujet->titre);
808

Ayolo's avatar
Ayolo committed
809 810 811 812
  $cts = new contents($path);

  $npp=40;
  $start=0;
Feu's avatar
fix  
Feu committed
813
  $delta=0;
Ayolo's avatar
Ayolo committed
814 815
  $nbpages = ceil($sujet->nb_messages/$npp);

Feu's avatar
test  
Feu committed
816
  if ( isset($_REQUEST["spage"]) && $_REQUEST["spage"] == "firstunread" && $site->user->is_valid() )
817
  {
Feu's avatar
test  
Feu committed
818 819
    $last_read = $sujet->get_last_read_message ( $site->user->id );
    if ( !is_null($last_read) )
Feu's avatar
fix  
Feu committed
820
    {
Feu's avatar
test  
Feu committed
821
      $message->load_by_id($last_read);
Feu's avatar
fix  
Feu committed
822 823
      $delta=1;
    }
Feu's avatar
fix  
Feu committed
824 825 826 827
    elseif( !is_null($site->user->tout_lu_avant) )
    {
      $req = new requete($site->db,"SELECT id_message FROM frm_message ".
        "WHERE id_sujet='".mysql_real_escape_string($sujet->id)."' ".
Feu's avatar
fix  
Feu committed
828
        "AND date_message > '".date("Y-m-d H:i:s",$site->user->tout_lu_avant)."' ".
Feu's avatar
fix  
Feu committed
829 830 831 832 833
        "ORDER BY date_message LIMIT 1");
      if ( $req->lines == 1 )
      {
        list($last_read) = $req->get_row();
        $message->load_by_id($last_read);
Feu's avatar
fix  
Feu committed
834
        $delta=0;
Feu's avatar
fix  
Feu committed
835 836
      }
    }
Feu's avatar
test  
Feu committed
837 838 839
    unset($_REQUEST["spage"]);
  }

Ayolo's avatar
Ayolo committed
840 841
  if ( $message->is_valid() )
  {
842 843 844
    $req = new requete($site->db,"SELECT id_message FROM frm_message WHERE id_sujet='"
	.mysql_real_escape_string($sujet->id).
	"' AND msg_supprime='0' ORDER BY date_message");
845

Ayolo's avatar
Ayolo committed
846 847 848
    $ids = array();
    while ( list($id) = $req->get_row() )
      $ids[] = $id;
849

Ayolo's avatar
Ayolo committed
850
    list($start) = array_keys($ids, $message->id);
Feu's avatar
fix  
Feu committed
851
    $start += $delta;
Ayolo's avatar
Ayolo committed
852 853 854 855 856 857 858 859 860 861 862
    $start -= $start%$npp;
  }
  elseif ( isset($_REQUEST["spage"]) )
  {
    $start = intval($_REQUEST["spage"])*$npp;
    if ( $start > $sujet->nb_messages )
    {
      $start = $sujet->nb_messages;
      $start -= $start%$npp;
    }
  }
863

Ayolo's avatar
Ayolo committed
864
  /**@todo:bouttons+infos*/
865

866
  $buttons= "<a href=\"?id_sujet=".$sujet->id."&amp;page=reply\"><img src=\"".$wwwtopdir."images/icons/16/message.png\" class=\"icon\" alt=\"\" />Répondre</a>";
867

Feu's avatar
wip  
Feu committed
868 869 870
  if ( $site->user->is_valid() )
  {
    $row = $sujet->get_user_infos($site->user->id);
Feu's avatar
wip  
Feu committed
871
    if ( is_null($row) || !$row['etoile_sujet'] )
872
      $buttons .= " <a href=\"?id_sujet=".$sujet->id."&amp;action=star\"><img src=\"".$wwwtopdir."images/icons/16/star.png\" class=\"icon\" alt=\"\" />Ajouter aux sujets favoris</a>";
Feu's avatar
wip  
Feu committed
873
    else
874
      $buttons .= " <a href=\"?id_sujet=".$sujet->id."&amp;action=unstar\"><img src=\"".$wwwtopdir."images/icons/16/unstar.png\" class=\"icon\" alt=\"\" />Enlever des sujets favoris</a>";
Feu's avatar
wip  
Feu committed
875
  }
876 877

  $cts->add_paragraph($buttons,"frmtools");
Ayolo's avatar
Ayolo committed
878 879 880 881 882

  if ( $start == 0 )
  {
    if ( !is_null($sujet->id_sondage) )
    {
883
      $sdn = new sondage($site->db);
Ayolo's avatar
Ayolo committed
884
      $sdn->load_by_id($sujet->id_sondage);
885

Ayolo's avatar
Ayolo committed
886
      $cts->puts("<div class=\"sujetcontext\">");
887

Ayolo's avatar
Ayolo committed
888
      $cts->add_title(2,"Sondage : resultats");
889

Ayolo's avatar
Ayolo committed
890
      $cts->add_paragraph($sdn->question);
891

Ayolo's avatar
Ayolo committed
892
      $cts->puts("<p>");
893

Ayolo's avatar
Ayolo committed
894
      $res = $sdn->get_results();
895

Ayolo's avatar
Ayolo committed
896 897 898 899
      foreach ( $res as $re )
      {
        $cumul+=$re[1];
        $pc = $re[1]*100/$sdn->total;
900

Ayolo's avatar
Ayolo committed
901
        $cts->puts($re[0]."<br/>");
902

Ayolo's avatar
Ayolo committed
903 904 905 906 907
        $wpx = floor($pc);
        if ( $wpx != 0 )
          $cts->puts("<div class=\"activebar\" style=\"width: ".$wpx."px\"></div>");
        if ( $wpx != 100 )
          $cts->puts("<div class=\"inactivebar\" style=\"width: ".(100-$wpx)."px\"></div>");
908

Ayolo's avatar
Ayolo committed
909 910
        $cts->puts("<div class=\"percentbar\">".round($pc,1)."%</div>");
        $cts->puts("<div class=\"clearboth\"></div>\n");
911

Ayolo's avatar
Ayolo committed
912
      }
913

Ayolo's avatar
Ayolo committed
914 915 916 917 918 919 920
      if ( $cumul < $sdn->total )
      {
        $pc = ( $sdn->total-$cumul)*100/$sdn->total;
        $cts->puts("<br/>Blanc ou nul : ".round($pc,1)."%");
      }
      $cts->puts("</p>");
      $cts->puts("</div>");
Ayolo's avatar
Ayolo committed
921 922 923 924 925
    }
    if ( !is_null($sujet->id_nouvelle) )
    {
      $news = new nouvelle ($site->db);
      $news->load_by_id($sujet->id_nouvelle);
BenC's avatar
BenC committed
926
      $cts->add($news->get_contents(false),true,true,"newsboxed","sujetcontext");
Ayolo's avatar
Ayolo committed
927 928 929 930 931 932
    }
    if ( !is_null($sujet->id_catph) )
    {
      $cat = new catphoto($site->db);
      $catpr = new catphoto($site->db);
      $cat->load_by_id($sujet->id_catph);
933

934
      $path = $cat->get_html_link();
Ayolo's avatar
Ayolo committed
935 936 937
      $catpr->load_by_id($cat->id_catph_parent);
      while ( $catpr->is_valid() )
      {
938
        $path = $catpr->get_html_link()." / ".$path;
Ayolo's avatar
Ayolo committed
939 940
        $catpr->load_by_id($catpr->id_catph_parent);
      }
941

Ayolo's avatar
Ayolo committed
942 943 944 945 946 947 948 949 950 951
      if ( !$cat->is_right($site->user,DROIT_LECTURE) )
      {
        $cts->add(new contents($path),true,true,"sasboxed","sujetcontext");
      }
      else
      {
        require_once($topdir."include/cts/gallery.inc.php");
        $site->add_css("css/sas.css");

        $sqlph = $cat->get_photos ( $cat->id, $site->user, $site->user->get_groups_csv(), "sas_photos.*", " LIMIT 5");
952

Ayolo's avatar
Ayolo committed
953 954 955 956 957 958 959 960 961 962
        $gal = new gallery($path,"photos","phlist","../sas2/?id_catph=".$cat->id,"id_photo",array());
        while ( $row = $sqlph->get_row() )
        {
          $img = "../sas2/images.php?/".$row['id_photo'].".vignette.jpg";
          if ( $row['type_media_ph'] == 1 )
            $gal->add_item("<a href=\"../sas2/?id_photo=".$row['id_photo']."\"><img src=\"$img\" alt=\"Photo\">".
                "<img src=\"".$wwwtopdir."images/icons/32/multimedia.png\" alt=\"Video\" class=\"ovideo\" /></a>","");
          else
            $gal->add_item("<a href=\"../sas2/?id_photo=".$row['id_photo']."\"><img src=\"$img\" alt=\"Photo\"></a>","");
        }
963

Ayolo's avatar
Ayolo committed
964
        $img = $topdir."images/misc/sas-default.png";
965

Ayolo's avatar
Ayolo committed
966 967
        if ( $cat->id_photo )
          $img = "../sas2/images.php?/".$cat->id_photo.".vignette.jpg";
968

Ayolo's avatar
Ayolo committed
969
        $gal->add_item("<a href=\"../sas2/?id_catph=".$cat->id."\"><img src=\"$img\" alt=\"Photo\"></a>",$cat->nom." : suite..." );
970

Ayolo's avatar
Ayolo committed
971 972 973 974
        $cts->add($gal,true,true,"sasboxed","sujetcontext");
      }
    }
  }
975 976


Feu's avatar
wip  
Feu committed
977
  $entries=array();
978

Feu's avatar
wip  
Feu committed
979 980
  for( $n=0;$n<$nbpages;$n++)
    $entries[]=array($n,"forum2/?id_sujet=".$sujet->id."&spage=".$n,$n+1);
981

Ayolo's avatar
Ayolo committed
982
  $cts->add(new tabshead($entries, floor($start/$npp), "_top"));
983 984 985 986 987 988

  $cts->add(new sujetforum ($forum,
          $sujet,
          $site->user,
          "./",
          $start,
Ayolo's avatar
Ayolo committed
989
          $npp ));
990

Ayolo's avatar
Ayolo committed
991
  $cts->add(new tabshead($entries, floor($start/$npp), "_bottom"));
Ayolo's avatar
Ayolo committed
992

993 994
  $cts->add_paragraph($buttons,"frmtools");

Feu's avatar
wip  
Feu committed
995
  $cts->add_paragraph($path