Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[How-To] Collapsible Tables within AdminCP (vb3.5)
Antivirus's Avatar
Antivirus
Join Date: Sep 2004
Posts: 1,090

 

Black Lagoon
Show Printable Version Email this Page Subscription
Antivirus Antivirus is offline 06-14-2006, 10:00 PM

So you already know how to Create Custom Pages in the AdminCP for that awesome hack you're working on, but your pages are either very long and you're too lazy to hit that scroll wheel to get to the bottom, or (like myself) you love clicking on collapsible tables and making things disappear and reappear upon your command. The following tuitorial (hopefully) should help you achieve this.

First off, if you're not already familiar with Dream's tuitorial on how to Create Custom Pages in the AdminCP, please get familiar with it, as this tuitorial assumes you already know how to do everything he explains therein.

Basically what we need to do is create three new functions to handle collapsible tables on custom pages within the AdminCP:
  • print_claps_table_header
  • print_claps_submit_row
  • print_claps_table_footer

The above functions are almost identical to the original functions written by Jelsoft, except for the fact that the code needed to handle collapsible tables has been added.

These functions need to be written into a file which we will call "antivirus_adminfunctions.php" so we can call them from our custom AdminCP page. The first function "print_claps_table_header" is the most important, containing the bulk of the code for collapsing the table as well as the all-important $collapseid parameter which we will need to assign giving each collapsible table it's own unique tag.
PHP Code:
function print_claps_table_header($title$collapseid ''$colspan 2$htmlise false$align 'center')
{
    global 
$bgcounter$stylevar$vbulletin;

    if (
$htmlise)
    {
        
$title htmlspecialchars_uni($title);
    }
    
$title "<b>$title</b>";
    if (
$collapseid != '')
    {
        
$title "\n\t\t<a style=\"float:$stylevar[right]\" href=\"#top\" onclick=\"return toggle_collapse('$collapseid')\"><img id=\"collapseimg_$collapseid\" src=\"../cpstyles/" $vbulletin->options['cpstylefolder'] . "/cp_collapse{$vbcollapse['collapseimg_'.$collapseid]}.gif\" alt=\"\" border=\"0\" /></a>\n\t\t$title\n\t";

    }

    echo 
"<thead>\n";
    echo 
"<tr>\n\t<td class=\"tcat\" align=\"$align\"" iif($colspan != 1" colspan=\"$colspan\"") . ">$title</td>\n</tr>\n";
    echo 
"</thead>\n";
    echo 
"<tbody id=\"collapseobj_$collapseid\" style=\"{$vbcollapse['collapseobj_'.$collapseid]}\">\n";

    
$bgcounter 0;

The second function "print_claps_submit_row" is only used if you require a submit button for your form. Almost nothing has changed other than the call to the function "print_claps_table_footer" way at the bottom...
PHP Code:
function print_claps_submit_row($submitname ''$resetname '_default_'$colspan 2$goback ''$extra ''$alt false)
{
    global 
$vbphrase$vbulletin;

    
// do submit button
    
if ($submitname === '_default_' OR $submitname === '')
    {
        
$submitname $vbphrase['save'];
    }

    
$button1 "\t<input type=\"submit\" class=\"button\" tabindex=\"1\" value=\"" str_pad($submitname8' 'STR_PAD_BOTH) . "\" accesskey=\"s\" />\n";

    
// do extra stuff
    
if ($extra)
    {
        
$extrabutton "\t$extra\n";
    }

    
// do reset button
    
if ($resetname)
    {
        if (
$resetname === '_default_')
        {
            
$resetname $vbphrase['reset'];
        }

        
$resetbutton .= "\t<input type=\"reset\" class=\"button\" tabindex=\"1\" value=\"" str_pad($resetname8' 'STR_PAD_BOTH) . "\" accesskey=\"r\" />\n";
    }

    
// do goback button
    
if ($goback)
    {
        
$button2 .= "\t<input type=\"button\" class=\"button\" value=\"" str_pad($goback8' 'STR_PAD_BOTH) . "\" tabindex=\"1\" onclick=\"history.back(1);\" />\n";
    }

    if (
$alt)
    {
        
$tfoot $button2 $extrabutton $resetbutton $button1;
    }
    else
    {
        
$tfoot $button1 $extrabutton $resetbutton $button2;
    }

    
// do debug tooltip
    
if ($vbulletin->debug AND is_array($GLOBALS['_HIDDENFIELDS']))
    {
        
$tooltip "HIDDEN FIELDS:";
        foreach(
$GLOBALS['_HIDDENFIELDS'] AS $key => $val)
        {
            
$tooltip .= "\n\$$key = &quot;$val&quot;";
        }
    }
    else
    {
        
$tooltip '';
    }

    
print_claps_table_footer($colspan$tfoot$tooltip);

Third, we'll need the new "print_claps_table_footer" function which closes the <tbody> tag which was opened within the "print_claps_table_header" function above...
PHP Code:
function print_claps_table_footer($colspan 2$rowhtml ''$tooltip ''$echoform true)
{
    global 
$tableadded$vbulletin;

    if (
$rowhtml)
    {
        
$tooltip iif($tooltip != ''" title=\"$tooltip\""'');
        if (
$tableadded)
        {
            echo 
"<tr>\n\t<td class=\"tfoot\"" iif($colspan != ," colspan=\"$colspan\"") . " align=\"center\"$tooltip>$rowhtml</td>\n</tr>\n";
        }
        else
        {
            echo 
"<p align=\"center\"$tooltip>$extra</p>\n";
        }
    }

    if (
$tableadded)
    {
        echo 
"</tbody>\n";
        echo 
"</table>\n";
    }

    if (
$echoform)
    {
        
print_hidden_fields();

        echo 
"</form>\n<!-- form ended: " $vbulletin->db->querycount ." queries executed -->\n\n";
    }

Last thing, make sure you have both "cp_collapse.gif" and "cp_collapse_collapsed.gif" residing within your CP Style directory (i.e: forumroot/cpstyles/xxx) where cpstylename is the name of the folder for your cpstyle. You probably already have the first in there by default, however you may need to make the latter image.

Now that we have our functions within the new "antivirus_adminfunctions.php" script, place this file within your forum/includes/ directory and we'll call it later in our custom AdminCP script.

Now, when creating your new page in the AdminCP, aside from all the usual bluff, you have to require our new functions for the back-end, like this:
PHP Code:
// ############# REQUIRE BACK-END #############
require_once('./global.php');
require_once(
DIR '/includes/antivirus_adminfunctions.php'); 
Now, everything else you would normally do is the same, except for the tables you're printing to the browser which you want to collapse, and in this case, you would use the following:

instead of function "print_table_header", use the new "print_claps_table_header" but DON'T FORGET to assign the new parameter $collapseid to a unique value (such as 'foo' for this table, like so:
PHP Code:
print_claps_table_header($vbphrase['whatever'], 'foo'); 
instead of function "print_submit_row", use the new "print_claps_submit_row" function (it's got no new parameters).

and instead of function "print_table_footer", use the new "print_claps_table_footer" function (it's got no new parameters).

Now, your tables which have used the new functions should be able to collapse as long as you use a unique $collapseid for each table group. You can also make more than one table collapse individually on the same page so long as each table you define in your script has a unique $collapseid

Thanks to SirAdrian, alan@cit and Paul M for helping me figure this out \m/
Attached Files
File Type: php antivirus_adminfunctions.php (4.7 KB, 23 views)
Reply With Quote
  #2  
Old 07-03-2006, 04:47 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice very useful. Makes me wanna go make an admincp mod just so I can put collapsable tables in it, he he.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:27 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03601 seconds
  • Memory Usage 2,266KB
  • Queries Executed 16 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_attachment
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete