<?php
#######################################################|#
#|                    HabboMCMS - TheRox
#|                    Powered by HoloCMS 
#|            Copyright 2011-2012 ALL RIGHTS RESERVED
#######################################################|#

require_once('../global.php');
if($hkzone !== true){ header("Location: index.php?throwBack=true"); exit; }
if(!session_is_registered(acp)){ header("Location: index.php?p=login"); exit; }

$pagename = "Ecrire un nouveau article";

if($do == "save" && isset($_POST['topstory'])){

	$num = $key;

	$title = Filter($_POST['title']);
	$category = Filter($_POST['category']);
	$seoUrl = Filter($_POST['url']);
	$topstory = Filter($_POST['topstory']);
	$short_story = Filter($_POST['short_story']);
	$story = $_POST['story'];
	$com = Filter($_POST['com']);


	if(empty($title) and empty($short_story) and empty($short)) {
		header("Location: index.php?p=news_compose&do=error");
	}  else {


	mysql_query("INSERT INTO site_news (title,category_id,seo_link,topstory_image,body,snippet,staff,fonction,com,datestr,timestamp) VALUES ('".$title."','".$category."','".$seoUrl."','".$topstory."','".addslashes($story)."','".$short_story."','".$name."','".$fonction."','".$com."','".$date_reversed."','".time()."')") or die(mysql_error());

	header("Location: index.php?p=news_manage&do=bounce");

			} 

}

if($do == "error"){
	$msg = "<div class=\"alert\">Merci de remplir tout les champs.</div>";
}

require_once('subheader.php');
require_once('header.php');
?>
	
<script type="text/javascript">
function previewTS(el)
{
	document.getElementById('ts-preview').innerHTML = '<img src="<?php echo WWW; ?>/images/ts/' + el + '" />';
}

function suggestSEO(el)
{
	var suggested = el;
	
	suggested = suggested.toLowerCase();
	suggested = suggested.replace(/^\s+/, ''); 
	suggested = suggested.replace(/\s+$/, '');
	suggested = suggested.replace(/[^a-z 0-9]+/g, '');
	
	while (suggested.indexOf(' ') > -1)
	{
		suggested = suggested.replace(' ', '-');
	}
	
	document.getElementById('url').value = suggested;
}
</script>
	
<table cellpadding='0' cellspacing='8' width='100%' id='tablewrap'>
<tr> <td width='22%' valign='top' id='leftblock'>
 <div>
 <!-- LEFT CONTEXT SENSITIVE MENU -->
<?php require_once('sitemenu.php'); ?>
 <!-- / LEFT CONTEXT SENSITIVE MENU -->
 </div>
 </td>
 <td width='78%' valign='top' id='rightblock'>
 <div><!-- RIGHT CONTENT BLOCK -->
<form action='index.php?p=news_compose&do=save' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Publier une News</div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Titre</b><div class='graytext'>Le titre complet de votre article.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='title' value="<?php echo $article['title']; ?>" size='30' onkeyup="suggestSEO(this.value);" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Articles Category</b></td>
<td class='tablerow2'  width='60%'  valign='middle'><select name='category' class='dropdown'>
<?php

$getOptions = mysql_query("SELECT * FROM site_news_categories ORDER BY caption ASC");

while ($option = mysql_fetch_assoc($getOptions))
{
	echo '<option value="' . $option['id'] . '" ' . (($option['id'] == $_POST['category']) ? 'selected' : '') . '>' . $option['caption'] . '</option>';
}

?>
</td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Topstory Image</b><div class='graytext'>L'URL de l'image topstory.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='topstory' value="http://images.habbohotel.co.uk/c_images/Top_Story_Images/top_story_web60.png" size='30' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>SEO URL</b><div class='graytext'>L'aper&ccedil;u de l'URL de l'article.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'>
<textarea id="url" name="url" value="<?php if (isset($_POST['url'])) { echo clean($_POST['url']); } ?>" cols='60' rows='1' wrap='soft' class='multitext'><?php if (isset($_POST['url'])) { echo clean($_POST['url']); } ?></textarea></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Introduction</b><div class='graytext'>Une petite introduction &agrave; l'article.<br />Le language HTML n'est pas autoris&eacute; ici.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><textarea name='short_story' cols='60' rows='5' wrap='soft' id='sub_desc'   class='multitext'><?php echo HabboCMSTEXT($article['short_story']); ?></textarea></td>
</tr>

<tr>
<script type="text/javascript" src="./tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	mode : "exact",
	elements : "story",
	theme : "advanced",
	plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "",
	theme_advanced_buttons4 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_resizing : true,
	theme_advanced_statusbar_location : "bottom"
});
</script>
<td class='tablerow1'  width='40%'  valign='middle'><b>Contenu</b><div class='graytext'>Votre news...<br /><u>Le language HTML est autoris&eacute; ici</u>.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><textarea id='story' name='story' cols='100' rows='20' wrap='soft' id='sub_desc'   class='multitext'><?php echo HabboCMSTEXT($article['story']); ?></textarea></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Commentaire</b><div class='graytext'>Exemple: (<?php echo $name ?>, <?php echo $fonction ?> "Votre commentaire"</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='com' value="<?php echo $article['com']; ?>" size='30' class='textinput'></td>
</tr>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Validier' class='realbutton' accesskey='s'></td></tr>
</form></table></div><br />
	 </div><!-- / RIGHT CONTENT BLOCK -->
	 </td></tr>
</table>
</div><!-- / OUTERDIV -->
<div align='center'><br />
<?php
$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
printf('Time: %.3f', $totaltime);
?>
</div>