<?php

if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

//For Deletion of profiles
if ( $_GET['txtdelete'] ) {
	deleteUser($_GET['txtdelete']);
}



$spamwords='';
$rs =& $osDB->getAll( 'SELECT word FROM !', array( 'osdate_spamwords' ) );
foreach ( $rs as $row ) {
	if( $spamwords != '' )
		$spamwords = $spamwords . ' OR ';
	$spamwords = $spamwords . 'm.message LIKE \'%' . $row['word'] . '%\'';
}


$sql = 'SELECT u.id, u.username, DATE_FORMAT( FROM_UNIXTIME( m.sendtime ), \'%Y%m%d\' ) send_time, m.message, count(*) copies FROM ! u INNER JOIN ! m ON u.id = m.senderid AND m.folder = \'sent_item\' AND ( ' . $spamwords . ' ) GROUP BY 1, 2, 3, 4 HAVING count(*) > 1 ORDER BY 3 DESC LIMIT 300 ';

$rs =& $osDB->getAll( $sql, array( USER_TABLE, MAILBOX_TABLE ) );

$spammers = array();

foreach ( $rs as $row ) {
	$spammers[] = $row;
}

$t->assign ( 'spammers', $spammers );

unset($spammers, $rs);

$t->assign('rendered_page', $t->fetch('admin/spammers.tpl'));

$t->display( 'admin/index.tpl' );

$osDB->disconnect();


?>
