<?PHP
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//   Copyright (C) 2000  Phorum Development Team                              //
//   http://www.phorum.org                                                    //
//                                                                            //
//   This program is free software. You can redistribute it and/or modify     //
//   it under the terms of the Phorum License Version 1.0.                    //
//                                                                            //
//   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.                     //
//                                                                            //
//   You should have received a copy of the Phorum License                    //
//   along with this program.                                                 //
////////////////////////////////////////////////////////////////////////////////

  require "./common.php";
  require "$include_path/post.php";

  $thread=$t;
  $action=$a;
  $id=$i;
  $parent=$p;

if($num==0 || $ForumName=='')
{
	Header("Location: $forum_url?$GetVars");
	exit;
}

$ip = getenv('REMOTE_HOST');
if(!$ip)
{
	$ip = getenv('REMOTE_ADDR');
}

if(!$ip)
{
	$ip = $REMOTE_ADDR;
}

if(!$ip)
{
	$ip = $REMOTE_HOST;
}

$host = @GetHostByAddr($ip);

$IsError = @check_data($host, $author, $subject, $body, $email);

if ($ForumAllowUploads == 'Y' && trim($attachment_name) != '' && trim($uploadDir != ''))
{
	if (!ereg("^[-A-Za-z0-9_.]+$", trim($attachment_name)))
	{
		$IsError=$lInvalidFile;
	} 
	elseif (file_exists($uploadDir.'/'.$ForumTableName.'/'.$attachment_name))
	{
		$IsError=$lFileExists;
	}
}

##############################################################
######## VIRALGAMES ############
# post.php n'utilise pas le header
//include("../config.inc.php3");
//include("../config.php3");
//include($DOCUMENT_ROOT."/config.php3");
/*
if (file_exists("../config.php3"))
{
	include("../config.php3");
}
else
{
	include("/var/www/htdocs/kestufoot_v4/config.php3");
}

include_once($BIB."bib_generic.php3");
include_once($BIB."bib_constants.php3");
include_once($BIB."bib_webmaster_forums.php3");*/

$sess = open_page($sessid, 1);
if ($sess->memberid == -1) $sess->reinit("Error: invalid access");

$post_autorise = false;
$isConnectedStr = $isBlackListStr = "";
$player = getplayer($sess->memberid);

// il n'est pas connecté, on
// vérifie s'il s'est connecté dans la journée
$CookVal=$HTTP_COOKIE_VARS[$COOKIE_NAME];
if ((!($CookVal)) || ($CookVal == ""))
{
	if ((!isset($sess->memberid)) || ($sess->memberid <= 0))
	{
		$isConnectedStr =  "<br><br><div class=stdDark>Pour laisser un message dans le forum, il vous suffit d'être inscrit au jeu, et de vous être connecté au jeu au moins une fois dans les dernières 24 heures.</div><br>";
		//	$sess->redirect($LOGIN_PAGE, "errorLogin=".urlencode("Pour laisser un message dans le forum, vous devez être inscrit, et avoir été connecté au moins une fois dans les 24 heures"));
		$post_autorise = false;
	}
	else
	{
		// il est connecté
		$post_autorise = true;
		$Nom = $player['NickName'];
	}
}
else
{
	// il s'est connecté dans les dernières 24 heures
	$Nom = $CookVal;
	$post_autorise = true;
}

if ($post_autorise == true)
{
	$sSQL = "Select * from blacklist WHERE PlayerName='".$Nom."' AND ForumId='".$f."'";
	$res = new query($DB, $sSQL);

	if($res->numrows()>0)
	{
		$isBlackListStr = "<br><br><div class=stdDark>Vous n'avez plus l'autorisation de déposer des messages dans ce forum. Pour plus d'informations, envoyez un mail au webmestre.</div><br>";
		$post_autorise = false;
	}
}

$Nom = setAuthor($Nom, "NickName", false);
##############################################################

if($IsError || !$action)
{
	if(file_exists("$include_path/header_$ForumConfigSuffix.php"))
	{
		include "$include_path/header_$ForumConfigSuffix.php";
	}
	else
	{
		include "$include_path/header.php";
	}

	if(count($forums)>1)
	{
		$nav = "<div class=navforum><a href=\"$forum_page.$ext?f=$Parent$GetVars\">".$lForumList."</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"$list_page.$ext?f=$num$GetVars\">".$lGoToTop."</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a  href=\"$search_page.$ext?f=$num$GetVars\">".$lSearch."</font></a>&nbsp;</div>";
	}
	else
	{
		$nav = "<div class=navforum><a href=\"".$sess->link3($FORUM_URL."$list_page.$ext", "f=$num$GetVars")."\">".$lGoToTop."</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a  href=\"".$sess->link3($FORUM_URL."$search_page.$ext", "f=$num$GetVars")."\">".$lSearch."</a>&nbsp;</div>";
	}

##############################################################
// début modif DG sur les cookies

	echo $isConnectedStr;
	
	if ($post_autorise == true)
	{
		
		echo $isBlackListStr;
		include "$include_path/form.php";
	}

// fin modif DG sur les cookies
##############################################################
	
	if(file_exists("$include_path/footer_$ForumConfigSuffix.php"))
	{
		include "$include_path/footer_$ForumConfigSuffix.php";
	}
	else
	{
		include "$include_path/footer.php";
	}
	
	exit();	
}

  //$author=trim($author);
  $author=$Nom;
  $subject=trim($subject);
  $email=trim($email);
  $body=chop($body);

  if($UseCookies){
    $name_cookie="phorum_name";
    $email_cookie="phorum_email";

    if((!IsSet($$name_cookie)) || ($$name_cookie != $author)) {
      SetCookie($name_cookie,stripslashes($author),time()+ 31536000);
    }
    if((!IsSet($$email_cookie)) || ($$email_cookie != $email)) {
      SetCookie($email_cookie,stripslashes($email),time()+ 31536000);
    }
  }

  list($author, $subject, $email, $body) = censor($author, $subject, $email, $body);

  if(!get_magic_quotes_gpc()){
    $author = addslashes($author);
    $email = addslashes($email);
    $subject = addslashes($subject);
    $body = addslashes($body);
  }

  $datestamp = date("Y-m-d H:i:s");

  $plain_author=stripslashes($author);
  $plain_subject=stripslashes(ereg_replace("<[^>]+>", "", $subject));
  $plain_body=stripslashes(ereg_replace("<[^>]+>", "", $body));

  $author = htmlspecialchars($author);
  $email = htmlspecialchars($email);
  $subject = htmlspecialchars($subject);

  // Attachment handling:
  if ($ForumAllowUploads == 'Y' && trim($attachment_name) != '' && trim($uploadDir != '')) {
    $org_attachment = $attachment_name;
    $new_name = $uploadDir.'/'.$ForumTableName.'/'.$org_attachment;
    if (!file_exists($new_name)) {
      copy($attachment, $new_name);
    } else {
      print $lFileExists;
      exit();
    }
  } else {
    $org_attachment = '';
  }

  if(($email==$ForumModPass && $ForumModPass!="") || ($email==$Password && $Password!="")){
    $ForumModeration='';
    $email=$ForumModEmail;
    $author = "<b>$author</b>";
    $subject = "<b>$subject</b>";
    $body="<HTML>$body</HTML>";
    $host="<b>$ForumStaffHost</b>";
  }
  else{
    $body=eregi_replace("</*HTML>", "", $body);
    if($ForumAllowHTML=="Y"){
      $body="<HTML>$body</HTML>";
    }
  }

  if (!check_dup()) {
    // generate a message id for the email if needed.
    $msgid="<".md5(uniqid(rand())).".$ForumModEmail>";
    // This will add the message to the database, and email the
    // moderator if required.
    $error = post_to_database();
    if (!empty($error)) {
      echo $error;
      exit();
    }

    // This will send email to the mailing list, if applicable,
    // and send email replies to earlier posters, if necessary.
    // Note that when posting to a mailing list, active moderation
    // does not apply.
    post_to_email();
  }



//  Header ("Location: $forum_url/$list_page.$ext?f=$num$more$GetVars");
  Header ("Location: ".$sess->link3($FORUM_URL."$list_page.$ext","f=$num$more$GetVars"));
close_page($sess);
?>