Workshop07/HelloWorld Solution

Back to outline

<?php
/**
 * This is the main file for the Hello World module. Once the module is selected in the 
 * post all actions are passed to this file for processing.
 * <Description of file> 
 *
 * PHP version 4 and 5
 *
 * LICENSE: This source file is subject to LGPL license
 * that is available through the world-wide-web at the following URI:
 * http://www.gnu.org/copyleft/lesser.html
 *
 * @author	   Chamindra de Silva (http://www.linux.lk/~chamindra) 
 * @author	   Ralph Morelli (http://www.cs.trincoll.edu/~ram)
 * @copyright  Lanka Software Foundation - http://www.opensource.lk
 * @package    module
 * @subpackage skel
 * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
 *
 */

/**
 * Place all your dependent libraries below. Given are some typical ones
 * required for the module
 */
include_once $global['approot'].'/inc/lib_menu.inc';
include_once $global['approot'].'/inc/lib_form.inc';
include_once $global['approot'].'/inc/lib_validate.inc';
include_once $global['approot'].'/inc/lib_errors.inc';
include_once($global['approot'].'inc/lib_log.inc');


/**
 * This function allows you to override the mainmenu. This is often done 
 * to include the modules own menu
 * 
 * @access public
 * @return void
 */
function shn_hw_mainmenu() 
{
    global $global;
    $module = $global['module'];
    
    // Create the module menu
    shn_mod_menuopen(_('Hello World Module'));

    shn_mod_menuitem('default',_('Home'));
    shn_sub_mod_menuitem('about',_('About'));  // Calls the about() function    
    shn_sub_mod_menuopen(_('Greetings'));
    shn_sub_mod_menuitem('hello',_('Hello'));  // Calls the hello() function
    shn_sub_mod_menuitem('ciao',_('Ciao'));    // Calls the ciao() function
    shn_sub_mod_menuclose();

    shn_mod_menuclose();
   
    // include the main menu so that the user can navigate outside the module
    include $global['approot'].'/inc/handler_mainmenu.inc';

} 

/** 
 * Other sections you can override
 */
// function shn_skel_header() {}
// function shn_skel_footer() {}
// function shn_skel_html_head() {}

/**
 * This function displays the default page of the module when it is selected
 * This function has to exist! 
 *
 * @access public
 * @return void
 */
function shn_hw_default()
{
    global $global;
?>
<div id="home">
<?=_("<h2>Welcome to the Hello World Module<BR>Choose an item from the Greetings menu.</h2>")?>
<?=_("<h4>Features</h4> <ul><li>Saying hello in English<li>Saying ciao in Italian</ul>")?>
</div>

<?php
}

/**
 * This is the about call from the greeting sub menu
 *
 * @access public
 * @return void
 */
function shn_hw_about()
{
    echo '<center><h1>'._('This is a workshop exercise.').'</h1></center>';
    shn_hw_default();
}

/**
 * This is the call from the greeting sub menu
 *
 * @access public
 * @return void
 */
function shn_hw_hello()
{
    echo '<center><h1>'._('Hello World!').'</h1></center>';
    shn_hw_default();
}

/**
 * This is the call from the greeting sub menu
 *
 * @access public
 * @return void
 */
function shn_hw_ciao()
{
    echo '<center><h1>'._('Ciao Mondo!').'</h1></center>';
    shn_hw_default();
}