<?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 = "Evènements";


$ID_NEWS = Filter($_POST['id']);
$order_id = Filter($_POST['order_id']);
$enable = Filter($_POST['enabled']);
$img_url = Filter($_POST['image_url']);
$caption = addslashes($_POST['caption']);
$descr = addslashes($_POST['descr']);
$url = Filter($_POST['url']);



if(isset($_POST['add'])) {
    if(empty($img_url) && empty($caption) && empty($descr) && empty ($url)) { 
    $msg = "<div class=\"alert\">Merci de remplir tout les champs.</div>";
    
} else { 
	mysql_query("INSERT INTO site_hotcampaigns (order_id,enabled,image_url,caption,descr,url) VALUES ('".$order_id."','".$enable."','".$img_url."','".$caption."','".$descr."','".$url."')");
	$msg = "<div class=\"alert success\">Site campaing crée avec succès</div>";
	} }
        
	
	if(isset($_POST['edit'])) {
	mysql_query("UPDATE site_hotcampaigns SET order_id='".$order_id."',enabled='".$enable."',image_url='".$img_url."',caption='".$caption."',descr='".$descr."',url='".$url."' WHERE id='".$_POST['id']."'");
	$msg = "<div class=\"alert succes\">Modifications effectuées avec succès.</div>";
	}
	
	if(isset($_POST['delete'])) {
	mysql_query("DELETE FROM site_hotcampaigns WHERE id='".$ID_NEWS."'");
	$msg = "<div class=\"alert succes\">Campaign supprimée avec succès.</div>";
	}

require_once('subheader.php');
require_once('header.php');
?>
<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 -->
 
  <?php if(!isset($_GET['a'])) {
			if(!isset($_GET['d'])) { ?>
<form action='index.php?p=campaigns' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Ajouter un évènement</div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<?php if(isset($_POST['add'])) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b></b></div></td>
<td class='tablerow2'  width='60%'  valign='middle'></td>
</tr>
<?php } ?>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Titre</b><div class='graytext'>Titre de l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='caption' value="<?php echo Filter($_POST['caption']); ?>" size='30' maxlength="50" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Url de l'image</b><div class='graytext'>Lien de l'image</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='image_url' value="<?php echo Filter($_POST['image_url']); ?>" size='30' maxlength="255" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Lien de l'article</b><div class='graytext'>Ou sera redirigé le Habbo lors du clique</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='url' value="<?php echo Filter($_POST['url']); ?>" size='30' maxlength="255" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Description</b><div class='graytext'>Argumente l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='descr' value="<?php echo Filter($_POST['descr']); ?>" size='30' maxlength="255" class='textinput'></td>
</tr> 

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Ordre</b><div class='graytext'>Choisis l'ordre de l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='order_id' value="1" size='30' maxlength="255" class='textinput'></td>
</tr> 


<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Ajouter' name="add" class='realbutton' accesskey='s'></td></tr>
</form></table></div><br />	 </div>


<form action='index.php?p=campaigns' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Editer un évènement</div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<?php

$sql = mysql_query("SELECT * FROM site_hotcampaigns");
while($row = mysql_fetch_assoc($sql)) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Titre</b><br> <?php echo $row['caption']; ?><br><b>Url de l'image</b><br><img src="<?php echo $row['image_url']; ?>"><br><b>Lien de l'article</b><br> <?php echo $row['url']; ?><br><b>Description</b><br> <?php echo $row['descr']; ?><br><b>Ordre</b><br> <?php echo $row['order_id']; ?></div></td>
<td class='tablerow2'  width='60%'  valign='middle'><center><a href="index.php?p=campaigns&a=<?php echo $row['id']; ?>">Editer un évènement</a><br><a href="index.php?p=campaigns&d=<?php echo $row['id']; ?>">Supprimer un évènement</a></center></td>
</tr>
<?php } ?>
<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ></td></tr>
</form></table></div><br />	 </div><?php } } ?>


<?php if(isset($_GET['a']) OR isset($_GET['d'])) { ?>
<form action='index.php?p=campaigns<?php if(isset($_GET['a'])) { echo "&a=".Filter($_GET['a']).""; }else{ echo "&d=".Filter($_GET['d']).""; } ?>' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'><?php if(isset($_GET['a'])) { echo "Editer un évènement"; }else{ echo "Supprimer un évènement"; } ?></div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<?php if(isset($_GET['a'])) {
$sql = mysql_query("SELECT * FROM site_hotcampaigns WHERE id='".Filter($_GET['a'])."'");
$row = mysql_fetch_assoc($sql); ?>


<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Titre</b><div class='graytext'>Titre de l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='caption' value="<?php echo $row['caption']; ?>" size='30' maxlength="50" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Url de l'image</b><div class='graytext'>Lien de l'image<br></div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='image_url' value="<?php echo $row['image_url']; ?>" size='30' maxlength="255" class='textinput'> <img align="center" src="<?php echo $row['image_url']; ?>"</td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Lien de l'article</b><div class='graytext'>Ou sera redirigé le 
Habbo lors du clique</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='url' value="<?php echo $row['url']; ?>" size='30' maxlength="255" class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Description</b><div class='graytext'>Argumente l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='descr' value="<?php echo $row['descr']; ?>" size='30' maxlength="255" class='textinput'></td>
</tr> 

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Ordre</b><div class='graytext'>Choisis l'ordre de l'évènement</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='order_id' value="1" size='30' maxlength="255" class='textinput'></td>
</tr> 

<?php }else{
$sql = mysql_query("SELECT * FROM site_hotcampaigns WHERE id='".Filter($_GET['d'])."'");
$row = mysql_fetch_assoc($sql);
if(isset($_POST['delete'])) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b></b></div></td>
<td class='tablerow2'  width='60%'  valign='middle'></td>
</tr>
<?php } ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Supprimer</b><div class='graytext'>Veuillez comfirmer la suppression de l'évènement</div></td>
<td class='tablerow2'  width='40%'  valign='middle'><b>Titre</b><br> <?php echo $row['caption']; ?><br><b>Url de l'image</b><br><img src="<?php echo $row['image_url']; ?>"><br><b>Lien de l'article</b><br> <?php echo $row['url']; ?><br><b>Description</b><br> <?php echo $row['descr']; ?><br><b>Ordre</b><br> <?php echo $row['order_id']; ?></div></td>
</tr>
<?php } ?>

<tr>
<input type="hidden" name="id" value="<?php if(isset($_GET['a'])) { echo $_GET['a']; }else{ echo $_GET['d']; } ?>">
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='<?php if(isset($_GET['a'])) { echo "edit"; }else{ echo "Supprimer"; } ?>' name="<?php if(isset($_GET['a'])) { echo "edit"; }else{ echo "delete"; } ?>" class='realbutton' accesskey='s'></td></tr>
</form></table></div><br />	 </div><?php } ?>

<!-- / 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>