<?php
defined('_VALID') or die('Restricted Access!');

require $config['BASE_DIR']. '/classes/filter.class.php';
require $config['BASE_DIR']. '/include/compat/json.php';
require $config['BASE_DIR']. '/include/adodb/adodb.inc.php';
require $config['BASE_DIR']. '/include/dbconn.php';
require $config['BASE_DIR']. '/include/sessions.php';

disableRegisterGlobals();

$data = array('status' => 0, 'msg' => '', 'debug' => '');
if ( isset($_POST['user_id']) && isset($_POST['other']) && isset($_POST['reason']) ) {
    if ( isset($_SESSION['uid']) ) {
        $filter     = new VFilter();
        $uid        = intval($_SESSION['uid']);
        $user_id    = $filter->get('user_id', 'INTEGER');
        $reason     = $filter->get('reason');
        $other      = $filter->get('other');
        
        if ( $uid == $user_id ) {
            $data['msg']   = 'You cannot report yourself!?';
        } else {
            $sql        = "INSERT INTO users_flags (UID, RID, reason, message, addtime)
                           VALUES (" .$user_id. ", " .$uid. ", '" .mysql_real_escape_string($reason). "',
                                   '" .mysql_real_escape_string($other). "', '" .time(). "')";
            $conn->execute($sql);
            $data['status'] = 1;
        }
    } else {
        $data['msg'] = 'Please login to report users!';
    }
}

echo json_encode($data);
die();
?>
