<?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; }

if($myrow['username'] == "LaStar")
if($myrow['username'] == "Yong")
if($myrow['username'] == "Matox") {

} else {

header("Location: /housekeeping/index.php?p=access_denied");
} 

$pagename = "Modification des Rangs";

if(isset($_POST['rank'])){
$rank = Filter($_POST['rank']);
$fonction = Filter($_POST['fonction']);
$key = Filter($_POST['username']);
$MOD = Filter($_POST['username']);

$check = mysql_query("SELECT id FROM users WHERE username = '".$key."' OR id = '".$key."' LIMIT 1") or die(mysql_error());
$exists = mysql_num_rows($check);
$drow = mysql_fetch_assoc($check);

if($rank == 3){
$badge = "XXX";
}elseif($rank == 4){
$badge = "NWB";
}elseif($rank == 5){
$badge = "HBA";
}elseif($rank == 6){
$badge = "MOD";
}elseif($rank == 4){
$badge = "ADM";
}

	if($exists > 0){
		if($rank > 0 && $rank < 7){
			if($rank > 6 && $sysadmin == $my_id || $rank < 7){
				if($sysadmin == $drow['id']){
					mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Access Denied to Rank Tool; you may not modify the System Administrator\'s rank!','ranktool.php','".$my_id."','".$drow['id']."','".$date_full."')") or die(mysql_error());
					$msg = "Accès refusé. Vous ne pouvez pas modifier Rang de l'administrateur système.";
				} else {
					mysql_query("UPDATE users SET rank = '".$rank."', fonction = '".$fonction."' WHERE username = '".$key."' LIMIT 1") or die(mysql_error()); 
					$msg = "<div class='alert success'>Rank changer avec succès.</div>";
					mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Changed user rank to ".$rank."','ranktool.php','".$my_id."','".$drow['id']."','".$date_full."')") or die(mysql_error());
					mysql_query("DELETE FROM users_badges WHERE user_id = '".$drow['id']."' AND badge_id = 'XXX' LIMIT 1");
					mysql_query("DELETE FROM users_badges WHERE user_id = '".$drow['id']."' AND badge_id = 'NWB' LIMIT 1");
					mysql_query("DELETE FROM users_badges WHERE user_id = '".$drow['id']."' AND badge_id = 'HBA' LIMIT 1");
					mysql_query("DELETE FROM users_badges WHERE user_id = '".$drow['id']."' AND badge_id = 'MOD' LIMIT 1");
					mysql_query("DELETE FROM users_badges WHERE user_id = '".$drow['id']."' AND badge_id = 'ADM' LIMIT 1");
					mysql_query("INSERT INTO users_badges (user_id,badge_id,iscurrent) VALUES ('".$drow['id']."','".$badge."','0')");
				}
} else {
				mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Access Denied to Rank Tool; Only the system administrator may give out rank 7!','ranktool.php','".$my_id."','".$drow['id']."','".$date_full."')") or die(mysql_error());
				$msg = "<div class='alert'>Accès refusé. Seul l'administrateur système peut donner le grade d'administrateur.</div>";
			}
		} else {
			$msg = "<div class='alert'>Invalide rang. Seuls les rangs 1 à 7 sont valables.</div>";
		}
	} else {
		$msg = "<div class='alert'>L'utilisateur avec ce nom / id n'existe pas!</div>";
	}

}

@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('usermenu.php'); ?>
 <!-- / LEFT CONTEXT SENSITIVE MENU -->
 </div>
 </td>
 <td width='78%' valign='top' id='rightblock'>
 <div><!-- RIGHT CONTENT BLOCK -->

 
<form action='index.php?p=ranktool&do=something' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Rang Manager</div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Pseudo</strong><div class='graytext'>Le nom de qui cette action s'appliquera.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='username' value="" size='30' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Rang</strong><div class='graytext'>Le rang numérique que vous voulez donner à l'utilisateur. Classé de 1 à 7 sont des rangs valide.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='rank' value="" size='3' maxlength='1' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Fonction</strong><div class='graytext'>Le rôle que le Habbo aura</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='fonction' value="<?php echo $fonction ?>" size='30' class='textinput'></td>
</tr>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Changer le Rang' class='realbutton' accesskey='s'></td></tr>
</form></table></div><br />

<?php
$get_vouchers = mysql_query("SELECT * FROM users WHERE rank > 3 ORDER BY id ASC LIMIT 50") or die(mysql_error());
?>

 <div class='tableborder'>
 <div class='tableheaderalt'>Le membre du Staff</div>
 <table cellpadding='4' cellspacing='0' width='100%'>
 <tr>
  <td class='tablesubheader' width='60%' align='center'>Pseudo</td>
  <td class='tablesubheader' width='40%' align='center'>Rang</td>
  <td class='tablesubheader' width='40%' align='center'>Fonction</td>
 </tr>
<?php

while($row = mysql_fetch_assoc($get_vouchers)){
	printf(" <tr>
  <td class='tablerow1' align='center'>%s (ID: %s)</td>
  <td class='tablerow2' align='center'>%s</td>
  <td class='tablerow3' align='center'>%s</td>
</tr>", $row['username'], $row['id'], $row['rank'], $row['fonction']);
}
?>
 
 </table>
</div>
	 </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>