/**
 * Removes a shout from the shoutbox by id
 *
 * @param int $shoutbox_id
 * @param int[]|int $shouts
 * @param boolean $prune
 */
function sportal_delete_shout($shoutbox_id, $shouts, $prune = false)
{
    $db = database();
    if (!is_array($shouts)) {
        $shouts = array($shouts);
    }
    // Remove it
    $db->query('', '
		DELETE FROM {db_prefix}sp_shouts
		WHERE id_shout IN ({array_int:shouts})', array('shouts' => $shouts));
    // Update the view
    sportal_update_shoutbox($shoutbox_id, $prune ? count($shouts) - 1 : count($shouts));
}
function sportal_admin_shoutbox_prune()
{
    global $smcFunc, $context, $txt;
    $shoutbox_id = empty($_REQUEST['shoutbox_id']) ? 0 : (int) $_REQUEST['shoutbox_id'];
    $context['shoutbox'] = sportal_get_shoutbox($shoutbox_id);
    if (empty($context['shoutbox'])) {
        fatal_lang_error('error_sp_shoutbox_not_exist', false);
    }
    if (!empty($_POST['submit'])) {
        checkSession();
        if (!empty($_POST['type'])) {
            $where = array('id_shoutbox = {int:shoutbox_id}');
            $parameters = array('shoutbox_id' => $shoutbox_id);
            if ($_POST['type'] == 'days' && !empty($_POST['days'])) {
                $where[] = 'log_time < {int:time_limit}';
                $parameters['time_limit'] = time() - $_POST['days'] * 86400;
            } elseif ($_POST['type'] == 'member' && !empty($_POST['member'])) {
                $request = $smcFunc['db_query']('', '
					SELECT id_member
					FROM {db_prefix}members
					WHERE member_name = {string:member}
						OR real_name = {string:member}
					LIMIT {int:limit}', array('member' => strtr(trim($smcFunc['htmlspecialchars']($_POST['member'], ENT_QUOTES)), array('\'' => '&#039;')), 'limit' => 1));
                list($member_id) = $smcFunc['db_fetch_row']($request);
                $smcFunc['db_free_result']($request);
                if (!empty($member_id)) {
                    $where[] = 'id_member = {int:member_id}';
                    $parameters['member_id'] = $member_id;
                }
            }
            if ($_POST['type'] == 'all' || count($where) > 1) {
                $smcFunc['db_query']('', '
					DELETE FROM {db_prefix}sp_shouts
					WHERE ' . implode(' AND ', $where), $parameters);
                if ($_POST['type'] != 'all') {
                    $request = $smcFunc['db_query']('', '
						SELECT COUNT(*)
						FROM {db_prefix}sp_shouts
						WHERE id_shoutbox = {int:shoutbox_id}
						LIMIT {int:limit}', array('shoutbox_id' => $shoutbox_id, 'limit' => 1));
                    list($total_shouts) = $smcFunc['db_fetch_row']($request);
                    $smcFunc['db_free_result']($request);
                } else {
                    $total_shouts = 0;
                }
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}sp_shoutboxes
					SET num_shouts = {int:total_shouts}
					WHERE id_shoutbox = {int:shoutbox_id}', array('shoutbox_id' => $shoutbox_id, 'total_shouts' => $total_shouts));
                sportal_update_shoutbox($shoutbox_id);
            }
        }
        redirectexit('action=admin;area=portalshoutbox');
    }
    $context['page_title'] = $txt['sp_admin_shoutbox_prune'];
    $context['sub_template'] = 'shoutbox_prune';
}
function sportal_delete_shout($shoutbox_id, $shouts, $prune = false)
{
    global $smcFunc;
    if (!is_array($shouts)) {
        $shouts = array($shouts);
    }
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}sp_shouts
		WHERE id_shout IN ({array_int:shouts})', array('shouts' => $shouts));
    sportal_update_shoutbox($shoutbox_id, $prune ? count($shouts) - 1 : count($shouts));
}
 /**
  * Who does not like prunes .. or maybe cut down the shout list
  */
 public function action_sportal_admin_shoutbox_prune()
 {
     global $context, $txt;
     $shoutbox_id = empty($_REQUEST['shoutbox_id']) ? 0 : (int) $_REQUEST['shoutbox_id'];
     $context['shoutbox'] = sportal_get_shoutbox($shoutbox_id);
     if (empty($context['shoutbox'])) {
         fatal_lang_error('error_sp_shoutbox_not_exist', false);
     }
     // Time to remove some chitta-chatta
     if (!empty($_POST['submit'])) {
         checkSession();
         if (!empty($_POST['type'])) {
             $where = array('id_shoutbox = {int:shoutbox_id}');
             $parameters = array('shoutbox_id' => $shoutbox_id);
             // Prune by days
             if ($_POST['type'] === 'days' && !empty($_POST['days'])) {
                 $where[] = 'log_time < {int:time_limit}';
                 $parameters['time_limit'] = time() - $_POST['days'] * 86400;
             } elseif ($_POST['type'] === 'member' && !empty($_POST['member'])) {
                 $member_id = sp_shoutbox_prune_member($_POST['member']);
                 if (!empty($member_id)) {
                     $where[] = 'id_member = {int:member_id}';
                     $parameters['member_id'] = $member_id;
                 }
             }
             // Execute the selective prune or clear the entire box
             if ($_POST['type'] === 'all' || count($where) > 1) {
                 sp_prune_shoutbox($shoutbox_id, $where, $parameters, $_POST['type'] === 'all');
                 sportal_update_shoutbox($shoutbox_id);
             }
         }
         redirectexit('action=admin;area=portalshoutbox');
     }
     loadJavascriptFile('suggest.js');
     $context['page_title'] = $txt['sp_admin_shoutbox_prune'];
     $context['sub_template'] = 'shoutbox_prune';
 }