<?php
/*===================================================+
|| # HoloCMS - Website and Content Management System
|+===================================================+
|| # Copyright © 2008 Meth0d. All rights reserved.
|| # http://www.meth0d.org
|+===================================================+
|| # HoloCMS is provided "as is" and comes without
|| # warrenty of any kind. HoloCMS is free software!
|+===================================================
|| # Badgeshop by Superfun
|+===================================================
*/
$minrank = "7";
if($user_rank >= $minrank){
require_once('../core.php');
if($hkzone !== true){ header("Location: index.php?throwBack=true"); exit; }
if(!session_is_registered(acp)){ header("Location: index.php?p=login"); exit; }

$pagename = "Badgeshop";

@include('subheader.php');
@include('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 @include('sitemenu.php'); ?>
 <!-- / LEFT CONTEXT SENSITIVE MENU -->
 </div>
 </td>
 <td width='78%' valign='top' id='rightblock'>
 <div><!-- RIGHT CONTENT BLOCK -->
 <?php
 if($_GET['la'] == "edit"){
	if($_POST['submit']){
	if(!empty($_POST['badgeid']) AND !empty($_POST['cost']) AND is_numeric($_POST['cost'])){
	mysql_query("UPDATE badgeshop SET cost = '".$_POST['cost']."' WHERE ID = '".$_POST['id']."'");
	mysql_query("UPDATE badgeshop SET badgeid = '".$_POST['badgeid']."' WHERE ID = '".$_POST['id']."'");
	echo 'Le badge a été edité!<br><a href="index.php?p=badgeshop">Procéder</a>';
	}else{
	echo 'Il y a eu une erreur.<br><a href="index.php?p=badgeshop">Retour</a>';
	}
	}else{
	$get_articles = mysql_query("SELECT * FROM badgeshop WHERE id = '".$_GET['id']."'") or die(mysql_error());
	if(mysql_num_rows($get_articles) != 1){
	echo 'Ce badge n\'existe pas!<br><a href="index.php?p=badgeshop">Retour</a>';
	}else{
	$row = mysql_fetch_assoc($get_articles);
 ?>
<form action='index.php?p=badgeshop&la=edit' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Modifier un badge</div>

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

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>ID:</b><div class='graytext'>Juste un ID pour mysql.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='id' value="<?php echo $row['id'] ?>" size='3' class='textinput' READONLY></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>badge Actuel:</b><div class='graytext'>Le badge actuel.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><img src="../Badges/<?php echo $row['badgeid']; ?>.gif"></td>
</tr>

<tr>
<td class='tablerow1' width='40%' valign='middle'><strong>ID du badge Actuel</strong><div class='graytext'>Vous pouvez le modifier si vous voulez un autre badge (ADM, XM8)</div></td>
<td class='tablerow1' width='60%' valign='middle'><input type='text' name='badgeid' value="<?php echo $row['badgeid'] ?>" size='5' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1' width='40%' valign='middle'><strong>Crédits</strong><div class='graytext'>Combien il coûte?</div></td>
<td class='tablerow1' width='60%' valign='middle'><input type='text' name='cost' value="<?php echo $row['cost'] ?>" size='5' class='textinput'></td>
</tr>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Changer' class='realbutton' name='submit'></td></tr>
</form></table></div><br />	
<?php
 }
 }
 }elseif($_GET['la'] == "add"){
 if($_POST['submit']){
 if(!empty($_POST['badgeid']) AND !empty($_POST['cost']) AND is_numeric($_POST['cost'])){
 mysql_query("INSERT INTO badgeshop (id, badgeid, cost) VALUES ('', '".$_POST['badgeid']."', '".$_POST['cost']."')");
echo 'Le badge a été edité!<br><a href="index.php?p=badgeshop">Procéder</a>';
}else{
echo 'Il y a eu une erreur.<br><a href="index.php?p=badgeshop">Retour</a>';
 }
 }else{
 ?>
 <form action='index.php?p=badgeshop&la=add' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Ajouter un badge</div>

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

<tr>
<td class='tablerow1' width='40%' valign='middle'><strong>ID du badge</strong><div class='graytext'>L'ID du badge (ADM, XM8)</div></td>
<td class='tablerow1' width='60%' valign='middle'><input type='text' name='badgeid'  size='5' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1' width='40%' valign='middle'><strong>Crédits</strong><div class='graytext'>Combien il coûte.</div></td>
<td class='tablerow1' width='60%' valign='middle'><input type='text' name='cost' size='5' class='textinput'></td>
</tr>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Add' class='realbutton' name='submit'></td></tr>
</form></table></div><br />	
<?php
 }
 }elseif($_GET['la'] == "del"){
 $aaa = mysql_num_rows(mysql_query("SELECT * FROM badgeshop WHERE id = '".$_GET['id']."'"));
 if($aaa != 1){
 echo 'Ce badge n\'existe pas!<br><a href="index.php?p=badgeshop">Retour</a>';
 }else{
 mysql_query("DELETE FROM badgeshop WHERE id = '".$_GET['id']."'");
 echo 'Le badge a été supprimé!<br><a href="index.php?p=badgeshop">Procéder</a>';
 }
 }else{
 ?>
 <div class='tableborder'>
 <div class='tableheaderalt'>Badgeshop</div>
 <table cellpadding='4' cellspacing='0' width='100%'>
 <tr>
  <td class='tablesubheader' width='1%' align='center'>ID</td>
  <td class='tablesubheader' width='5%'>Badge</td>
  <td class='tablesubheader' width='5%' align='center'>Crédits</td>
  <td class='tablesubheader' width='1%'>Modifier</td>
  <td class='tablesubheader' width='1%' align='center'>Supprimer</td>
 </tr>
<?php
$get_articles = mysql_query("SELECT * FROM badgeshop ORDER BY id") or die(mysql_error());

while($row = mysql_fetch_assoc($get_articles)){

echo "<tr>";
echo "<td class='tablerow1' align='center'>".$row['id']."</td>";
echo "<td class='tablerow2' align='center'><img src=\"../Badges/".$row['badgeid'].".gif\"></td>";
echo "<td class='tablerow2' align='center'>".$row['cost']."</td>";
echo "<td class='tablerow2' align='center'><a href=\"index.php?p=badgeshop&la=edit&id=".$row['id']."\"><img src=\"images/edit.gif\" border=\"0\"></a></td>";
echo "<td class='tablerow2' align='center'><a href=\"index.php?p=badgeshop&la=del&id=".$row['id']."\"><img src=\"images/delete.gif\" border=\"0\"></a></td>";
echo "</tr>";
}
?>
 
 </table>
 <div class='tablefooter' align='center'><div class='fauxbutton-wrapper'><a href="index.php?p=badgeshop&la=add">ajouter un badge</a></div></div>
</div>
<?php
}
?> 
	 </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>
<?php
}else{
include('access_denied.php');
exit;
}
?>