Drop-Down Category Block

Started by Chen Zhen, September 14, 2024, 12:57:41 AM

Previous topic - Next topic

Chen Zhen

Drop-Down categories PHP block code for SMF Arcade
Version: SMF-Arcade v2.7.0.2+



This will give you a nice drop-down category menu inside a PHP block.
You can check out the one in this arcade for the example.



Custom Display Options:
(For viewing on portal - leave this line blank)
~action|arcade
Main PHP Code:
// Category PHP block code for SMF Arcade
global $scripturl, $smcFunc;
/**************************
set $gameTypes
0 = Permission based
1 = Flash/HTML
2 = ROM only
3 = All game types
**************************/
$gameTypes = 0;
$selectCSS = 'font-size: 100%;';

switch($gameTypes) {
case 1:
$where = ' AND game.rom_flag = {int:romflag}';
$romflag = 0;
break;
case 2:
$where = ' AND game.rom_flag = {int:romflag}';
$romflag = 1;
$included_game_types[] = 'rom';
break;
case 3:
$where = '';
$romflag = 0;
break;
default:
$romflag = 0;
if (allowedTo('arcade_view_retro_arch')) {
$where = '';
}
else {
$where = ' AND game.rom_flag = {int:romflag}';
}
}
list($count, $cat_name, $cat_link, $cat_drop, $gameCats) = array(1, array(), array(), array(), array());

echo '
    <script type="text/javascript">
    function arcadeCatBlockSelect() {
        var arcadeNewFormSelectOpt = document.getElementById("arcCategoryBlockId");
        var arcadeNewFormCatId = arcadeNewFormSelectOpt.options[arcadeNewFormSelectOpt.selectedIndex].value;
        document.getElementById("arcadeBlockForm3").action += ";category=" + arcadeNewFormCatId;
        document.getElementById("arcadeBlockForm3").submit()
    }
    </script>
    <div class="centertext" style="width: 100%;margin: 0 auto;">
        <form id="arcadeBlockForm3" action="', $scripturl, '?action=arcade" method="post">
            <select id="arcCategoryBlockId" name="arcCategoryBlock" style="' . $selectCSS . '" onchange="arcadeCatBlockSelect()">
                <option value="">View By Category</option>';


$request = $smcFunc['db_query']('', '
    SELECT game.id_game, game.id_cat, game.enabled, game.rom_flag
    FROM {db_prefix}arcade_games as game
WHERE enabled = {int:enabled}' . $where . '
    ORDER BY game.id_game ASC',
    array('enabled' => 1,'romflag' => $romflag)
);
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$idCat = !empty($row['id_cat']) ? intval($row['id_cat']) : 0;
if (empty($gameTypes) && empty($row['rom_flag']) && !allowedTo('arcade_play'))
continue;
elseif (empty($gameTypes) && !empty($row['rom_flag']) && !allowedTo('arcade_view_retro_arch'))
continue;

$gameCats[$idCat][] = $row['id_game'];
}
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
    SELECT cat.id_cat, cat.cat_name, cat.num_games, cat.cat_order
    FROM {db_prefix}arcade_categories as cat
    ORDER BY cat_order',
    array('romflag' => $romflag)
);

while ($row = $smcFunc['db_fetch_assoc']($request)) {
if (empty($gameCats[$row['id_cat']]))
continue;

    $count = $row['id_cat'];
    $cat_name[$count] = $row['cat_name'];
    $cat_link[$count] = $scripturl . '?action=arcade;category=' . $count;
    $cat_drop[$count] = '<a href="' . $cat_link[$count] .'">'.$cat_name[$count].'</a>';

    echo '
                <option value="', $count, '">', $cat_name[$count], '</option>';
}
$smcFunc['db_free_result']($request);

echo '
            </select>
        </form>
    </div>';



Note: You can style your select box with this part of the above code:
$selectCSS = 'font-size: 100%;';