<?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!
|+===================================================*/

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; }
if(function_exists(SendMUSData) !== true){ include('../includes/mus.php'); }

if(!isset($_POST['category'])){ // do not try to save when it's a category jump
		
			

			
			$msg = "Distintivi Tolti: ".$count."";
			}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 = "The badge ".$_POST['badgec']." is succesfully taken off.";
			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 = "Questi utenti non hanno questo distintivo";
			}
			}else{
			$msg = "Modifiche salvate con Successo!";
			}
		}elseif(isset($_POST['take'])) {
	$sql = mysql_query("SELECT * FROM user_badges WHERE badge_id='".$_POST['take']."'");
	$count = mysql_num_rows($sql);
	while($row = mysql_fetch_assoc($sql)) {
	mysql_query("DELETE FROM user_badges WHERE badge_id='".$_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 = "Badge inviato a: ".$count." utenti! ";
	}


$pagename = "Massa Crediti/badge";

$catId = FilterText($_POST['category']);

if(empty($catId) || !is_numeric($catId) || $catId < 3 || $catId > 5){
    $catId = 3;
} 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 -->
 
<?php if(isset($msg)){ ?><p><strong><?php echo $msg; ?></strong></p><?php } ?>

<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'>Seleziona l'Azione</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='3' <?php if($catId == "3"){ echo "selected='selected'"; } ?>>Rimuovi distintivo all'utente</option>
			<option value='4' <?php if($catId == "4"){ echo "selected='selected'"; } ?>>Rimuovi disintivo a Tutti</option>
        </select>
        &nbsp;
        <input type='submit' value='Seleziona' 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'>Massa staff</div>

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





<?php if($catId == 3) { ?>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><strong>Nome utente</strong>
  <div class='graytext'>Inserisci il nome dell'utente al quale vuoi rimuovere il distintivo!</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>Codice distintivo</strong>
  <div class='graytext'>Inserisci il codice distintivo che vuoi rimuovere all'utente. Ricorda i codici sono sempre in Maiuscolo :)</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>Codice distintivo</strong>
  <div class='graytext'>What badge do you want to take off, fill in the badge code.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='take' value="" size='3' maxlength='3' class='textinput'></td>
</tr>

<?php } ?>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='SALVA' 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('Ore: %.3f', $totaltime);
?>
</div>