Knowledge Base

Creating a new Admin Page
Article ID: 85
Written By: Graham
Written On: Sat Jun 09, 2007 8:25 am
Description: This article explains how to create a new page within the admin panel with links in the left-hand menu pane.
Link to this article: Select All
[url=http://www.phpbb.com/kb/article/creating-a-new-admin-page/]Knowledge Base - Creating a new Admin Page[/url]

Creating a new Admin Page
  • In phpBB, the contents of the Admin Control Panel menu is generated dynamically each time it is visited. The admin/ directory is scanned for all files whose name begins "admin_". This file is then include()'ed in the script which builds the menu. In order to appear in the menu (and to avoid errors), the first few lines of the script should be as follows.
    Code: Select all
    define('IN_PHPBB', 1);

    if( !empty($setmodules) )
    {
       $filename = basename(__FILE__);
       $module['Section_Name']['Menu_Text'] = $filename;

       return;
    }
  • Where "Section_Name" is the name of the entry in the language pack which should be used as the caption of the section where this page is to be displayed. "Menu_Text" is again the entry in the language pack which should be used as the link to this page.
    These values should be defined as language entries within the lang_admin.php file as follows. If no matching language pack entry exists, then the supplied text (minus any underscore characters) will be used, but ideally a language entry should be used to allow for easy translation of your MOD into other languages.
    Code: Select all
    $lang['Section_Name'] = 'Your Section Name Here';
    $lang['Menu_Text'] = 'Your Menu Item Text Here';
  • If your page can be used for several different actions and you wish it to have multiple entries in the menu, then you can do this by adding extra $module lines as shown below. (Note that the section name for each entry does not need to be the same)
    Code: Select all
    define('IN_PHPBB', 1);

    if( !empty($setmodules) )
    {
       $filename = basename(__FILE__);
       $module['Section_Name']['Menu_Text1'] = $filename . "?mode=user";
       $module['Section_Name']['Menu_Text2'] = $filename . "?mode=group";

       return;
    }
  • Following this code which determines the menu location of the page, you should then include the following items at minimum to ensure that all the common admin files are included ready for use in the main body of your page. These entries ensure that only administrators will be able to access your page and that all the common variables are instantiated.
    Code: Select all
    //
    // Load default header
    //
    $no_page_header = TRUE;
    $phpbb_root_path = './../';
    require($phpbb_root_path . 'extension.inc');
    require('./pagestart.' . $phpEx);
  • Following this, you can code the page as you would any other page within phpBB, with all the usual global variables being available for use.
    As a final point to note, you should ensure that all URI's generated by your page to other phpBB pages (or back to itself) are passed through the append_sid() function as a security measure. Failure to do this could lead to your script not performing as expected.