<?php $Page = v('Page'); ?>
<div class="un-article un-article-seul">
	<h2 class="titre"><?php echo href($Page->get_CMS_TITRE(),array('controleur'=>'accueil','action'=>'page','params'=>$Page->get_CMS_CLE())); ?> 
	<span class="infos">(<?php echo sprintf(__('com.txt.news.infos'),date_fr($Page->get_CMS_DATE(),3),zk_joueur($Page)); ?>)</span>

	</h2>
	<div class="article">
		<?php echo $Page->get_CMS_TEXTE(); ?>
	</div>
</div>

<?php if ( OPT_PAG_COM && $Page->get_CMS_COM()) {
	?><div id="commentaires"><a name="commentaires"></a><?php
	
	
	if ( is_logued() ){
		?>
		<h2><?php echo __('ac.page.com.post'); ?></h2>
		<form method="post" class="com-form" action="<?php echo WWW_ROOT; ?>tabcommentaires/compage/<?php echo $Page->get_CMS_CLE(); ?>" >
			<textarea name="commentaire" class="com-zone-com"></textarea>
			<input type="submit" class="btn btn-primary" value="<?php echo __('com.action.val'); ?>" />
		</form>
		<?php
	}
	
	if ( sizeof((array)v('tCommentaires')) == 0 ){
		?><h2><?php echo __('ac.page.com'); ?></h2><?php
	} else {
		?><h2><?php echo sprintf(__('ac.page.com.nb'),sizeof((array)v('tCommentaires'))); ?></h2><?php 
	}
	
	$i = sizeof((array)v('tCommentaires'));
	foreach((array)v('tCommentaires') as $cle=>$com) {?>

		<div class="com-block <?php echo $i%2==0?'com-block-pair':'com-block-impair'; ?>">
            <span class="com-num label label-info">#<?php echo $i; ?></span>
			<span class="com-auteur"><?php echo zk_joueur($com['Auteur']); ?></span> - <span class="com-date"><?php echo date_avec_delai($com['Date']); ?></span>
			<?php echo v('is_admin')==true? href(img('icons/cross.png'),array('controleur'=>'tabcommentaires','action'=>'supprimer','params'=>$cle,'class'=>'com-delete', 'onclick'=>'return false')):''; ?>

			
			<p><?php echo $com['Commentaire']; ?></p>
		</div>
		
	<?php
        $i--;
    } ?>
	<script type="text/javascript">
		
		$(".com-form").submit(function(){
			if ( $(this).children(".com-zone-com").val() == "" ){
				alert("<?php echo __('ac.page.com.err'); ?>");
				return false;
			}	
			$.ajax({
				type: "POST",
				url: $(this).attr("action"),
				data: "commentaire="+encodeURIComponent($(this).children(".com-zone-com").val()),
				success: function(data, text){
					//Rafraichir la page
					document.location.reload();
				},
				error: function (request, status, error) {
			        alert("Erreur : "+request.responseText);
			    }
			});
			return false;
		});
		
		$(".com-delete").click(function(){
			$.ajax({
				type: "POST",
				url: this.href,
				success: function(data, text){
					//Rafraichir la page
					document.location.reload();
				},
				error: function (request, status, error) {
			        alert("Erreur : "+request.responseText);
			    }
			});
			return false;
		});
		
	</script>
	
	 </div>
<?php } ?>