<?php
$pagetype = "news";
if ($_GET["newsid"])
{
	list($pageid, $nothing) = explode("-",$_GET["newsid"]);
	$pagetitle = "News";
}
include("header.phtml.en");
?>
	<!--Commentaire:M'okay x)
		Mmpf how?Il est la otn div header :euh:On imrovisera ;)
		comme ça ?
		Vala :D-->
	<body>
      <?php include("menu.phtml.en");?>
		<div id="contenu">
			<h2><?php lien("index", "News")?></h2>
				<?php if (!isset($pageid))
				{
					//echo "<div id=\"nextnews\" style=\"display: none\"><a href=\"#prevnews\" onclick=\"javascript:previousNext(false)\">Next entries</a></div>";
				}?>
				<div id="news">
				<?php 
				if (isset($pageid))
				{
					$cond = "where id=\"$pageid\" ";
				}
				else
				{
					$cond = "";
					if ($countreq = mysqli_query($base,"SELECT page, count(*) FROM comments WHERE langue=\"en\" GROUP BY page"))
					{
						while ($data = mysqli_fetch_array($countreq))
						{
							$nbcoms[$data["page"]] = $data["count(*)"];
						}
					}
				}
				$newsreq = mysqli_query($base,"SELECT id, title_en, date, content_en FROM news ".$cond."ORDER BY date DESC") or $news_error = $sqlerrormsg;
				$nb_news = 0;
				if (isset($news_error)) {
					echo '<p class="warning">'.$news_error;
				} else {
					while ($data = mysqli_fetch_array($newsreq)) {
						if ($data['title_en'] == "" && $data['content_en'] == "") continue;
						$nb_news++;
						$urlparams = newsparams($data['id'],$data['title_en']);
						echo '<div class="news" id="news_'.$data['id'].'">'."\n".'<h3>';
						lien("$urlparams", $data['title_en']);
						echo "</h3>\n".'<p class="details">', ucfirst(strftime( "%A, %B %d %Y" , strtotime( $data['date'] ) )),'</p>', "\n";
						echo $data['content_en'];
						echo "\n";
						if (!$pageid)
						{
							echo("<p class=\"footnote\"><a href=\"$urlparams.phtml.en#comments\">");
							if ($thiscoms = $nbcoms["news_".$data['id']])
							{
								echo("Comment on this news ($thiscoms comment".($thiscoms > 1 ? "s" : "").")");
							}
							else
							{
								echo("Be first to comment!");
							}
							echo("</a></p>");
						}
						echo "</div>\n";
					}
					if ($nb_news == 0)
					{
						echo '<p>No news found.';
					}
				}
				mysqli_free_result ($newsreq);
			echo("</div>");
			if ($pageid && $nb_news == 1)
			{
				echo("<div id=\"comments\">\n");
				echo("<h4 id=\"commenttitle\">Comment on this news</h4>");
				$page="news_".$pageid;
				include("comments.phtml.en");
				echo("</div>\n");
			}
			if (!isset($pageid))
			{
				//echo "<div id=\"prevnews\"><a href=\"#nextnews\" onclick=\"javascript:previousNext(true)\">Previous entries</a></div>";
				//echo "<script>setNewsPerPage(5);</script>";
			}?>
		</div>
		<?php //include("stats.php");
		mysqli_close($base); ?>
	</body>
</html>