News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Need some help with adding remove checkboxes code

Started by tareko, September 15, 2020, 10:10:55 AM

Previous topic - Next topic

tareko

I have a mod coded for me by someone that lists the names of the games and their players in the acp. I am trying to add a checkbox list that will delete selected players but I can't seem to get it right. When I press delete selected players it does nothing at all. It just redirects to the players list page. Can someone please look at the code and tell me how can I implement it right?

function Players()
{
global $txt, $sourcedir, $scripturl, $context, $smcFunc;

isAllowedTo('admin_forum');

// User pressed the 'remove selection button'.
if (!empty($_POST['removePlayers']) && !empty($_POST['remove']) && is_array($_POST['remove']))
{
checkSession();

// Make sure every entry is a proper integer.
foreach ($_POST['remove'] as $index => $spider_id)
$_POST['remove'][(int) $index] = (int) $spider_id;

// Delete them all!
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_players
WHERE id_player IN ({array_int:remove_list})',
array(
'remove_list' => $_POST['remove'],
)
);
}

$listOptions = array(
'id' => 'player_list',
'items_per_page' => 20,
'base_href' => $scripturl . '?action=admin;area=players;sa=list',
'default_sort_col' => 'subject',
'no_items_label' => $txt['no_players_yet'],
'get_items' => array(
'function' => 'list_getPlayers',
),
'get_count' => array(
'function' => 'list_countPlayers',
),
'columns' => array(
'game' => array(
'header' => array(
'value' => $txt['players_list'],
),
'data' => array(
'db' => 'game',
'class' => 'mediumtext',
'style' => 'width: 40%; text-align: left;',
),
'sort' =>  array(
'default' => 'game DESC',
'reverse' => 'game',
),
),
'player_username' => array(
'header' => array(
'value' => $txt['players'],
'style' => 'text-align: left;',
),
'data' => array(
'db' => 'player_username',
'style' => 'width: 60%; text-align: left;',
),
'sort' =>  array(
'default' => 'player_username DESC',
'reverse' => 'player_username',
),
),

  'check' => array(
'header' => array(
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
),
'data' => array(
'sprintf' => array(
'format' => '<input type="checkbox" name="remove[]" value="%1$d" class="input_check" />',
'params' => array(
'id_player' => false,
),
),
'style' => 'text-align: center',
),
),
),
'form' => array(
'href' => $scripturl . '?action=admin;area=players;sa=list',
),
'additional_rows' => array(
array(
'position' => 'below_table_data',
'value' => '
<input type="submit" name="removePlayers" value="' . $txt['remove_selected_players'] . '" onclick="return confirm(\'' . $txt['remove_selected_players_confirm'] . '\');" class="button_submit" />
',
'style' => 'text-align: right;',
),
),
);

require_once($sourcedir . '/Subs-List.php');
createList($listOptions);

$context['sub_template'] = 'show_list';
$context['default_list'] = 'player_list';
}

SychO

try checking the contents of the posted data to make sure they are correct

past var_dump($_POST['remove']);
die();


inside the condition block.
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

tareko

Quote from: SychO on September 15, 2020, 10:26:56 AM
try checking the contents of the posted data to make sure they are correct

past var_dump($_POST['remove']);
die();


inside the condition block.

Thanks. I got this.

array(2) { [0]=> string(1) "0" [1]=> string(1) "0" }


What does it mean?

SychO

seems like the checkbox values aren't correctly set.

I don't remember the last time I used the createList function, so I'm not sure how that's supposed to work exactly.
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze



Advertisement: