libdir.'/adminlib.php');
require_js(array('yui_dom-event', 'yui_connection', 'yui_json'));
$keyword = optional_param('keyword', '', PARAM_RAW);
$autodetect = optional_param('autodetect', '', PARAM_RAW);
$del = optional_param('del', '', PARAM_RAW);
$delall = optional_param('delall', '', PARAM_RAW);
$ignore = optional_param('ignore', '', PARAM_RAW);
$reset = optional_param('reset', '', PARAM_RAW);
$id = optional_param('id', '', PARAM_INT);
require_login();
admin_externalpage_setup('reportspamcleaner');
// Implement some AJAX calls
// Delete one user
if (!empty($del) && confirm_sesskey() && ($id != $USER->id)) {
if (isset($SESSION->users_result[$id])) {
$user = $SESSION->users_result[$id];
if (delete_user($user)) {
unset($SESSION->users_result[$id]);
echo json_encode(true);
} else {
echo json_encode(false);
}
} else {
echo json_encode(false);
}
exit;
}
// Delete lots of users
if (!empty($delall) && confirm_sesskey()) {
if (!empty($SESSION->users_result)) {
foreach ($SESSION->users_result as $userid => $user) {
if ($userid != $USER->id) {
if (delete_user($user)) {
unset($SESSION->users_result[$userid]);
}
}
}
}
echo json_encode(true);
exit;
}
if (!empty($ignore)) {
unset($SESSION->users_result[$id]);
echo json_encode(true);
exit;
}
admin_externalpage_print_header();
// Print headers and things
print_spamcleaner_javascript();
print_box(get_string('spamcleanerintro', 'report_spamcleaner'));
print_box_start(); // The forms section at the top
?>
';
// Print list of resulting profiles
if (!empty($keyword)) { // Use the keyword(s) supplied by the user
$keywords = explode(',', $keyword);
foreach ($keywords as $key => $keyword) {
$keywords[$key] = trim($keyword);
}
search_spammers($keywords);
} else if (!empty($autodetect)) { // Use the inbuilt keyword list to detect users
search_spammers($autokeywords);
}
echo '';
/////////////////////////////////////////////////////////////////////////////////
/// Functions
function search_spammers($keywords) {
global $CFG, $USER;
if (!is_array($keywords)) {
$keywords = array($keywords); // Make it into an array
}
$like = sql_ilike();
$keywordfull = array();
foreach ($keywords as $keyword) {
$keyword = addslashes($keyword); // Just to be safe
$keywordfull[] = " description $like '%$keyword%' ";
$keywordfull2[] = " p.summary $like '%$keyword%' ";
}
$conditions = '( '.implode(' OR ', $keywordfull).' )';
$conditions2 = '( '.implode(' OR ', $keywordfull2).' )';
$sql = "SELECT * FROM {$CFG->prefix}user WHERE deleted = 0 AND id <> {$USER->id} AND $conditions"; // Exclude oneself
$sql2= "SELECT u.*, p.summary FROM {$CFG->prefix}user AS u, {$CFG->prefix}post AS p WHERE $conditions2 AND u.deleted = 0 AND u.id=p.userid AND u.id <> {$USER->id}";
$spamusers_desc = get_recordset_sql($sql);
$spamusers_blog = get_recordset_sql($sql2);
$keywordlist = implode(', ', $keywords);
print_box(get_string('spamresult', 'report_spamcleaner').s($keywordlist)).' ...';
print_user_list(array($spamusers_desc, $spamusers_blog), $keywords);
}
function print_user_list($users_rs, $keywords) {
global $CFG, $SESSION;
// reset session everytime this function is called
$SESSION->users_result = array();
$count = 0;
foreach ($users_rs as $rs) {
while ($user = rs_fetch_next_record($rs)) {
if (!$count) {
echo '