<?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 = "Alert";

if(isset($_POST['alert'])){
    $alert = Filter($_POST['alert']);
	$staff = Filter($_POST['username']);
    $username = Filter($_POST['username']);
    $check = mysql_query("SELECT id FROM users WHERE username = '".$username."' LIMIT 1") or die(mysql_error());
    $valid = mysql_num_rows($check);
    if($valid > 0){
        $tmp = mysql_fetch_assoc($check);
        $userid = $tmp['id'];
        if(is_numeric($userid)){
            mysql_query("INSERT INTO cms_alerts (userid,template,alert,staff) VALUES ('".$userid."','2','".$alert."','".$staff."')") or die(mysql_error());
            mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Sent alert to user','alert.php','".$my_id."','".$userid."','".$date_full."')") or die(mysql_error());
            $msg = "<div class='alert success'>L'alerte a été envoyé a l'utilisateur.</div>";
        } else {
            $msg = "<div class='alert'>Erreur...</div>";
        }
    } else {
        $msg = "<div class='alert'>Cet Utilisateur n'existe pas.</div>";
    }
} elseif($_GET['do'] == "quickreply" && is_numeric($_GET['key'])){
    $check = mysql_query("SELECT * FROM cms_help WHERE id = '".$_GET['key']."' LIMIT 1") or die(mysql_error());
    $tmp = mysql_fetch_assoc($check);
    if($tmp['picked_up'] !== "1"){
        mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Automaticly picked up help query (ID: ".$_GET['key'].")','alert.php','".$my_id."','','".$date_full."')") or die(mysql_error());
        mysql_query("UPDATE cms_help SET picked_up = '1' WHERE id = '".$_GET['key']."' LIMIT 1") or die(mysql_error());
    }
    $_POST['alert'] = "Hello, my name is ".$name.". I am sending you this message in reply to your help inquiry sent on ".$tmp['date'].", with the subject '".HabboCMSTEXT($tmp['subject'])."'.\n\n".$name."\n".$shortname." Player Support";
    $_POST['username'] = $tmp['username'];
}

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 @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=alert&do=placeAlert' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Alert Utilisateur</div>

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

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Pseudo</b><div class='graytext'>Le nom de l'utilisateur que vous souhaitez envoyé cette alerte.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='username' value="<?php echo $_POST['username']; ?>" size='50' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Alerte</b><div class='graytext'>Le message réel qui sera présentée à l'utilisateur.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><textarea name='alert' cols='60' rows='5' wrap='soft' id='sub_desc' class='multitext'><?php echo HabboCMSTEXT($_POST['alert']); ?></textarea></td>
</tr>

<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Envoyer l&#39;alerte' class='realbutton' accesskey='s'></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>