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

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

disableRegisterGlobals();

$data   = array('msg' => '', 'status' => 0, 'debug' => '');
if ( isset($_POST['type']) && isset($_POST['parent_id']) && isset($_POST['comment_id']) ) {
    if ( isset($_SESSION['uid']) ) {
        $filter     = new VFilter();
        $uid        = intval($_SESSION['uid']);
        $type       = $filter->get('type');
        $cid        = $filter->get('comment_id', 'INTEGER');
        $pid        = $filter->get('parent_id', 'INTEGER');
        $sql        = "INSERT INTO spam (UID, type, comment_id, parent_id, addtime)
                       VALUES (" .$uid. ", '" .mysql_real_escape_string($type). "', " .$cid. ", " .$pid. ", '" .time(). "')";
        $data['debug'] = $sql;
        $conn->execute($sql);
        if ( $conn->Affected_Rows() == 1 ) {
            $data['status'] = 1;
        } else { 
            $data['msg']    = 'Failed to mark comment as spam!?';   
        }
    } else {
        $data['msg'] = 'Please login to flag comments as spam!';
    }
} else {
    $data['msg'] = 'Invalid request!?';
}

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