/**
 * Display threads results table
 *
 * @param array Params
 */
function threads_results_block($params = array())
{
    // Make sure we are not missing any param:
    $params = array_merge(array('edited_User' => NULL, 'results_param_prefix' => 'actv_thrd_', 'results_title' => T_('Threads with private messages sent by the user'), 'results_no_text' => T_('User has not sent any private messages')), $params);
    if (!is_logged_in()) {
        // Only logged in users can access to this function
        return;
    }
    global $current_User;
    if (!$current_User->check_perm('users', 'edit') || !$current_User->check_perm('perm_messaging', 'reply')) {
        // Check minimum permission:
        return;
    }
    $edited_User = $params['edited_User'];
    if (!$edited_User) {
        // No defined User, probably the function is calling from AJAX request
        $user_ID = param('user_ID', 'integer', 0);
        if (empty($user_ID)) {
            // Bad request, Exit here
            return;
        }
        $UserCache =& get_UserCache();
        if (($edited_User =& $UserCache->get_by_ID($user_ID, false)) === false) {
            // Bad request, Exit here
            return;
        }
    }
    global $DB, $current_User;
    param('user_tab', 'string', '', true);
    param('user_ID', 'integer', 0, true);
    // Check permission:
    if ($current_User->check_perm('perm_messaging', 'abuse')) {
        // Create result set:
        $threads_Results = get_threads_results(array('results_param_prefix' => $params['results_param_prefix'], 'user_ID' => $edited_User->ID, 'sent_user_ID' => $edited_User->ID));
        $threads_Results->Cache =& get_ThreadCache();
        $threads_Results->title = $params['results_title'];
        $threads_Results->no_results_text = $params['results_no_text'];
        if ($threads_Results->total_rows > 0) {
            // Display action icon to delete all records if at least one record exists
            $threads_Results->global_icon(sprintf(T_('Delete all private messages sent by %s'), $edited_User->login), 'delete', '?ctrl=user&user_tab=activity&action=delete_all_messages&user_ID=' . $edited_User->ID . '&' . url_crumb('user'), ' ' . T_('Delete all'), 3, 4);
        }
        // Load classes
        load_class('messaging/model/_thread.class.php', 'Thread');
        // Initialize Results object
        threads_results($threads_Results, array('abuse_management' => 1, 'show_only_date' => 1));
        if (is_ajax_content()) {
            // init results param by template name
            if (!isset($params['skin_type']) || !isset($params['skin_name'])) {
                debug_die('Invalid ajax results request!');
            }
            $threads_Results->init_params_by_skin($params['skin_type'], $params['skin_name']);
        }
        $display_params = array('before' => '<div class="results" style="margin-top:25px" id="threads_result">');
        $threads_Results->display($display_params);
        if (!is_ajax_content()) {
            // Create this hidden div to get a function name for AJAX request
            echo '<div id="' . $params['results_param_prefix'] . 'ajax_callback" style="display:none">' . __FUNCTION__ . '</div>';
        }
    } else {
        // No permission for abuse management
        echo '<div style="margin-top:25px;font-weight:bold">' . sprintf(T_('User has sent %s private messages'), $edited_User->get_num_messages('sent')) . '</div>';
    }
}
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
global $current_User;
global $unread_messages_count;
global $DB, $Blog;
global $perm_abuse_management;
// TRUE if we go from Abuse Management
if (!isset($display_params)) {
    // init display_params
    $display_params = array();
}
// set default values
$display_params = array_merge(array('show_only_date' => 0), $display_params);
// Create result set:
$Results = get_threads_results(array('results_param_prefix' => $perm_abuse_management ? 'abuse_' : 'thrd_', 'search_word' => param('s', 'string', '', true), 'search_user' => param('u', 'string', '', true), 'show_closed_threads' => param('show_closed', 'boolean', false, true)));
$Results->Cache =& get_ThreadCache();
$Results->title = T_('Conversations list');
if (is_admin_page()) {
    $Results->title .= get_manual_link('messaging');
}
if ($unread_messages_count > 0 && !$perm_abuse_management) {
    $Results->title = $Results->title . ' <span class="badge">' . $unread_messages_count . '</span></b>';
}
/**
 * Callback to add filters on top of the result set
 *
 * @param Form
 */
function filter_recipients(&$Form)
{