<?php

$allow_guests = true;

require_once('global.php');

$body_id = "news";
$pageid = "4";

if(isset($_GET['view'])){
        $news_id = Filter($_GET['view']);
        $main_sql = mysql_query("SELECT * FROM site_news WHERE id = '".$news_id."'") or die(mysql_error());
        $article_exists = mysql_num_rows($main_sql);
	if($article_exists == "1"){
                $news = mysql_fetch_assoc($main_sql);
				$cat_sql = mysql_query("SELECT * FROM site_news_categories WHERE id = '".$news['category_id']."'") or die(mysql_error());
				$category_check = mysql_num_rows($cat_sql);
                $cat = mysql_fetch_assoc($cat_sql);
                $pagename = "Nouveautés - " . stripslashes($news['title']);
                $archive = "0";
	} else {
                $pagename = "Archives";
                $archive = "1";
	}
} elseif(isset($_GET['category'])){
        $pagename = "Category Listing";
        $archive = "2";
        $cat = Filter($_GET['category']);
		$cat_sql = mysql_query("SELECT * FROM site_news_categories WHERE id = '".$cat."'") or die(mysql_error());
		$category_check = mysql_num_rows($cat_sql);
	    $name_cat = mysql_fetch_assoc($cat_sql);
} else {
        $pagename = "Nouveaut&eacute;s";
        $archive = "1";
}

require_once('templates/community_subheader.php');
require_once('templates/community_header.php');


/*** FORM ****/

$username = $name;
$code = Filter($_POST['code']);
//$content = Filter($_POST['content']);

if(isset($_POST['form'])) {
    if(empty($code)) {
        $msg = ' <br /><b><font color="red">Merci de remplir le champ code.</font></b>';
    } else {
        mysql_query("INSERT INTO form (code,username) VALUES ('".$code."','".$username."')") or die(mysql_error());
        $msg = '<br /><b><font color="green">Réponse envoyée!</font></b>';
    }   
}

?>
<meta property="fb:app_id" content="183096284873" />
<div id="container">
	<div id="content">
    <div id="column1" class="column">
				<div class="habblet-container ">
						<div class="cbb clearfix default ">

							<h2 class="title">Autres infos
							</h2>
						<div id="article-archive">
<h2>Les derni&egrave;res infos</h2>
<ul>
	<?php
	$get_sub_archive = mysql_query("SELECT id, title, seo_link, datestr FROM site_news ORDER BY id DESC LIMIT 30");
	$count = mysql_num_rows($get_sub_archive);

	if($count > 0){
		while ($row = mysql_fetch_array($get_sub_archive, MYSQL_NUM)) {
			printf("<li><a href=\"".$path."/news?view=%s-%s\" class=\"article-%s\">%s</a> &raquo;</li>", $row[0], $row[2], $row[0], stripslashes($row[1]));
		}
	} else {
		echo "<br />Il n'y a encore aucune news.";
	}
	?>
</ul>
<h2>Encore plus d'infos?</h2>
<ul>
	<li>
		<a href="news" class="news">Voir les archives</a> &raquo;
	</li>
</ul>

</div>


					</div>
				</div>
				<script type="text/javascript">if (!$(document.body).hasClassName('process-template')) { Rounder.init(); }</script>

</div>
<div id="column2" class="column">
				<div class="habblet-container ">
						<div class="cbb clearfix notitle ">

<?php if($archive < 1){ ?>
						<div id="article-wrapper">
	<h2><?php echo stripslashes($news['title']); ?></h2>
	<div class="article-meta"><!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4edad12e20aa0f02"></script>
<!-- AddThis Button END -->
Post&eacute; le <?php echo $news['datestr']; ?> 
		<a href="<?php echo $path; ?>/news?category=<?php echo $news['category_id']; ?>"><?php echo $cat['caption']; ?></a></div>
	<p class="summary"><?php echo stripslashes($news['snippet']); ?></p>

	<div class="article-body">
            
<?php echo $news['body']; ?></div>
       
<?php if(isset($msg)) echo $msg; // Pour afficher le message isset.
            
'echo <input type="hidden" name="username" />';
?>
	    <div class="article-body"></div>

			<script type="text/javascript" language="Javascript">
		document.observe("dom:loaded", function() {
			$$('.article-images a').each(function(a) {
				Event.observe(a, 'click', function(e) {
					Event.stop(e);
					Overlay.lightbox(a.href, "Chargement..");
				});
			});
			
			$$('a.article-<?php echo $news_id; ?>').each(function(a) {
				a.replace(a.innerHTML);
			});
		});
	</script>
<b><?php echo $news['com']; ?></b><br />



        <div class="fb-like" data-href="<?php echo $path; ?>/news?view=<?php echo $news['id']; ?>" data-send="true" data-width="450" data-show-faces="true"></div>
<br />
        <div class="fb-comments" data-href="<?php echo $path; ?>/news?view=<?php echo $news['id']; ?>" data-num-posts="2" data-width="500"></div>

	</div>
</div>
<?php } elseif($archive == "1"){ ?>
<div id="article-wrapper">
<h2>Articles</h2>
	<div class="article-meta">Voici la liste des évènements ayant eu lieu dans l'hôtel</div>
	<div class="article-body">
		<p>
		<ul>
		<?php
		$get_archive = mysql_query("SELECT id, title, datestr, seo_link FROM site_news ORDER BY timestamp DESC");
		$count = mysql_num_rows($get_archive);

		if($count > 0){
			while ($row = mysql_fetch_array($get_archive, MYSQL_NUM)) {
				printf("<li>%s - <a href=\"".$path."/news?view=%s-%s\" class=\"article-%s\">%s</a></li>", $row[2], $row[0], $row[3], $row[0], stripslashes($row[1]));
			}
		} else {
			echo "Aucunes nouvelles ont &eacute;t&eacute;s &eacute;crites.";
		}
		?>
		</ul>
		</p>
	</div>
</div>
<?php } elseif($archive > 1){ ?>
<div id="article-wrapper">
<h2><?php echo "Category Listing"; ?></h2>
	<div class="article-meta">Ce sont les 25 derni&egrave;res infos post&eacute;s dans la cat&eacute;gorie <b><?php echo $name_cat['caption']; ?></b>.</div>
	<div class="article-body">
		<p>
		<ul>
		<?php
		$get_archive = mysql_query("SELECT id, title, datestr, seo_link FROM site_news WHERE category_id = '".$cat."' ORDER BY timestamp DESC LIMIT 25");

		while ($row = mysql_fetch_array($get_archive, MYSQL_NUM)) {
		printf("<li>%s - <a href='".$path."/news?view=%s-%s'>%s</a></li>", $row[2], $row[0], $row[3], HabboCMSTEXT($row[1]));
		}
		?>
		</ul>
		</p>
	</div>
</div>
<?php } ?>



					</div>
				</div>
				<script type="text/javascript">if (!$(document.body).hasClassName('process-template')) { Rounder.init(); }</script>

</div>

<div id="column3" class="column">
</div>

<?php

require_once('templates/community_footer.php');

?>
