<?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(!isset($_POST['category'])){ // do not try to save when it's a category jump
			if(isset($_POST['credits'])) {
				if(is_numeric($_POST['credits'])) {
				$sql = mysql_query("SELECT id,credits FROM users");
				$count = mysql_num_rows($sql);
				while($row = mysql_fetch_assoc($sql)) {
				mysql_query("UPDATE users SET credits = credits + '".$_POST['credits']."' WHERE id='".$row['id']."' LIMIT 1");
				}
				mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Gave credits to every user, total users: ".$count." (Amount ".$_POST['credits'].")','massa.php','".$my_id."','','".$date_full."')") or die(mysql_error());
				$msg = "<div class='alert success'>Distribution de Credits &agrave; : ".$count." Habbos.</div>";
				}else{
				$msg = "<div class='alert'>Oups, s'il vous plaît utilisez uniquement des chiffres et pas de caractères !</div>";
				}
				
				
			}elseif(isset($_POST['code']) || isset($_POST['type'])) {
			$sql = mysql_query("SELECT id FROM users");
			$count = mysql_num_rows($sql);
			while($row = mysql_fetch_assoc($sql)) {
			mysql_query("UPDATE user_badges SET badge_slot = '0' WHERE user_id='".$row['userid']."' AND badge_slot = '1'") or die(mysql_error());
			mysql_query("INSERT INTO user_badges (user_id,badge_id,badge_slot) VALUES('".$row['id']."','".$_POST['code']."','1')") or die(mysql_error());
			}
			
			if($_POST['type'] == 2) {
			$sql = mysql_query("SELECT id FROM users");
			$count = mysql_num_rows($sql);
			while($row = mysql_fetch_assoc($sql)) {
			$time = time() + ($_POST['time'] * 24 * 60 * 60);
			mysql_query("INSERT INTO cms_badges (userid,days,badgeid) VALUES ('".$row['id']."','".date('Y-m-d', $time)."','".$_POST['code']."')");
			}
			mysql_query("INSERT INTO system_stafflog (action,message,note,userid,timestamp) VALUES ('Housekeeping','Gave badge to every user (for ".$_POST['time']." days), total users: ".$count." (Badge id: ".$_POST['code'].").','massa.php','".$my_id."','".$date_full."')") or die(mysql_error());
			}else{
			mysql_query("INSERT INTO system_stafflog (action,message,note,userid,timestamp) VALUES ('Housekeeping','Gave badge to every user (perm.), total users: ".$count." (Badge id: ".$_POST['code'].").','massa.php','".$my_id."','".$date_full."')") or die(mysql_error());
			}
			
			$msg = "<div class='alert success'>Le badge a &eacute;t&eacute; donn&eacute; pour ".$count." Habbo.</div>";
			}elseif(isset($_POST['user']) || isset($_POST['badgec'])) {
			$sql = mysql_query("SELECT id FROM users WHERE username='".$_POST['user']."'");
			if(mysql_num_rows($sql) == 1) {
			$sql = mysql_query("SELECT id FROM users WHERE username='".$_POST['user']."'");
			$row = mysql_fetch_assoc($sql);
			mysql_query("DELETE FROM user_badges WHERE user_id='".$row['id']."' AND badge_id='".$_POST['badgec']."'");
			if(mysql_error == 0) {
			$msg = "<div class='alert success'>Le badge ".Filter($_POST['badgec'])." est enlev&eacute; avec succès.</div>";
			mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Badge (".$_POST['badgec'].") taken off','massa.php','".$my_id."','".$row['id']."','".$date_full."')") or die(mysql_error());
			}else{
			$msg = "<div class='alert '>Cet utilisateur n'a pas ce badge!</div>";
			}
			}else{
			$msg = "<div class='alert'>L'utilisateur n'existe pas</div>";
			}
		}elseif(isset($_POST['take'])) {
	$sql = mysql_query("SELECT * FROM user_badges WHERE badge_id='".Filter($_POST['take'])."'");
	$count = mysql_num_rows($sql);
	while($row = mysql_fetch_assoc($sql)) {
	mysql_query("DELETE FROM user_badges WHERE badge_id='".Filter($_POST['take'])."'");
	}
	mysql_query("INSERT INTO system_stafflog (action,message,note,userid,timestamp) VALUES ('Housekeeping','Badge taken off from all users who had the badge ".$_POST['take'].". Users processed: ".$count."','massa.php','".$my_id."','".$date_full."')") or die(mysql_error());
	$msg = "<div class='alert success'>Les badges sont retir&eacute;s avec succès! Utilisateurs trait&eacute;es: ".$count."</div>";
	}
}

$pagename = "Modification g&eacute;n&eacute;ral";

$catId = $_POST['category'];

if(empty($catId) || !is_numeric($catId) || $catId < 1 || $catId > 5){
    $catId = 1;
} else {
    $catId = $catId;
}

@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 -->
 

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

<form action='index.php?p=massa_stuff&do=jumpCategory' method='post' name='Jumper!' id='Jumper!'>
<div class='tableborder'>
<div class='tableheaderalt'>Choisis une Categorie</div>
<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<tr>
    <td class='tablerow2'  width='100%'  valign='middle'  align='center'>
        <select name='category' class='dropdown'>
            <option value='1' <?php if($catId == "1"){ echo "selected='selected'"; } ?>>Mass credits</option>
            <option value='2' <?php if($catId == "2"){ echo "selected='selected'"; } ?>>Mass badge (period/perm.)</option>
            <option value='3' <?php if($catId == "3"){ echo "selected='selected'"; } ?>>Retirer badges &agrave; partir d'un certain utilisateur</option>
			<option value='4' <?php if($catId == "4"){ echo "selected='selected'"; } ?>>Retirer badge de tous les utilisateurs avec le code de badge [...]</option>
        </select>
        &nbsp;
        <input type='submit' value='Go' class='realbutton' accesskey='s'>
    </td>
</tr>
</table>
</div>
</form>

<br />
 
<form action='index.php?p=massa_stuff&do=save' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Mass stuff</div>

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

<?php if($catId == 1) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Montant</strong><div class='graytext'>Le montant des cr&eacute;dits tout le monde reçoit.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='credits' value="" size='3' maxlength='5' class='textinput'></td>
</tr>
<?php }elseif($catId == 2) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Badge</strong><div class='graytext'>Code de badge</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='code' value="" size='3' maxlength='3' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Permanente ou pour un moment sp&eacute;cial?</strong><div class='graytext'>Tout le monde reçoit le badge permanent ou pour un moment sp&eacute;cial?</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='radio' name='type' value='1'> Permanent <input type='radio' name='type' value='2'> Pour un moment privil&eacute;gi&eacute;</td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Combien de temps est-il obtenu?</strong><div class='graytext'>Pour combien de temps vont-ils obtenir le badge? <b>Note:</b> si vous avez choisi "permanent" ce n'est pas grave.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><SELECT style="COLOR: black; FONT-FAMILY: Verdana" name=time> <OPTION value="1" selected>1 day</OPTION><OPTION value="2">2 days</OPTION><OPTION value="3">3 days</OPTION><OPTION value="4">4 days</OPTION><OPTION value="5">5 days</OPTION><OPTION value="6">6 days</OPTION><OPTION value="7">1 week</OPTION><OPTION value="14">2 weeks</OPTION><OPTION value="21">3 weeks</OPTION><OPTION value="30">1 month</OPTION><OPTION value="60">2 months</OPTION><OPTION value="90">3 months</OPTION><OPTION value="120">4 months</OPTION><OPTION value="150">5 months</OPTION><OPTION value="180">6 months</OPTION><OPTION value="210">7 months</OPTION><OPTION value="240">8 months</OPTION><OPTION value="270">9 months</OPTION><OPTION value="300">10 months</OPTION><OPTION value="330">11 months</OPTION><OPTION value="365">1 year</OPTION><OPTION value="730">2 year</OPTION><OPTION value="1095">3 year</OPTION><OPTION value="1460">4 year</OPTION><OPTION value="1825">5 year</OPTION><OPTION value="3650">10 year</OPTION> <OPTION value="5475">15 year</OPTION><OPTION value="7300">20 year</OPTION><OPTION value="9125">25 year</OPTION></SELECT></td>
</tr>
<?php }elseif($catId == 3) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Pseudo</strong><div class='graytext'>De qui voulez-vous d'enlever un badge?</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='user' value="" size='3' maxlength='100' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>code du badge</strong><div class='graytext'>Que voulez-vous de badge &agrave; d&eacute;coller, veuillez remplir le code du badge.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='badgec' value="" size='3' maxlength='3' class='textinput'></td>
</tr>
<?php }elseif($catId == 4) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>code du badge</strong><div class='graytext'>Que voulez-vous de badge &agrave; d&eacute;coller, veuillez remplir le code du badge.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='take' value="" size='3' maxlength='3' class='textinput'></td>
</tr>
<?php }else{ ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Montant</strong><div class='graytext'>Le montant des cr&eacute;dits tout le monde reçoit.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='credits' value="" size='3' maxlength='5' class='textinput'></td>
</tr>
<?php } ?>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='OK' class='realbutton' accesskey='s' name='massa'></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>