9.5. Modules

Userpanel is built with modularity principle, which means that each module, which represents one menu entry is contained in separate subdirectory of modules directory.

9.5.1. Construction of module

This graph represents directory structure of typical module:

module_name
    |---locale
    |     |---en
    |          |---strings.php
    |---style
    |     |---default
    |          |---image.gif
    |---templates
    |     |---template1.html
    |     |---template2.html
    |---upgradedb
    |     |---mysql.2005081901.php
    |     |---postgres.2005081901.php
    |---configuration.php
    |---functions.php

This requires a few words of explanation:

9.5.2. Mandatory files

9.5.2.1. configuration.php

This file contains configuration of given module and is always included during Userpanel initialization. Usually it's built as follows:

<?php
$USERPANEL->AddModule(trans('Help'),      // Name in menu
                    'help',             // Module name (must be identical as module dir)
                    trans('Runs problems solving creator'), // Tip (on menu hover)
                    5,                  // Priority (lower first)
                    trans('This module shows solving problems creator'), // Description
                    2005081901,         // DB version (similar to LMS, see 
                                        // lms/lib/upgradedb.php)
		    array(		// Array of submenus im LMS-UI Userpanel menu
		        array(		// (see lib/LMS.menu.php)
			    'name' => trans('Submenu'),
			    'link' => '?m=userpanel&module=help',
			    'tip' => trans('Tooltip'),
			),
		    )
);
?>

9.5.2.2. functions.php

This file contains given module functions. There is special function, named module_main() executed first when module is called. If any function is intended to be accessible from Userpanel UI, it should be prefixed with module_, ie. module_function1(), which will be available from the following URL: http://userpanel/?m=module&f=function1. Function named module_setup() is being called from configuration panel of LMS-UI.