Multilingual Solution

 * * 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 dependant 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 {   // Display the title for the module

?>   <?= _('Multilingual Hello Module'); ?> <?    // Store a reference to the global database object a local variable global $global; $db = $global['db']; // Retrieve the various languages from the DB and store them in an array. $languages = array; $result = $db->Execute("select id, name from hw_language"); while(!$result->EOF) {           $languages[$result->fields['id']] = $result->fields['name']; $result->moveNext; }   // Retrieve the various greetings from the DB and store them in an array. $greetings = array; $result = $db->Execute("select distinct type from hw_greeting"); while(!$result->EOF) {           $greetings[$result->fields['type']] = $result->fields['type']; $result->moveNext; }   // Create the HTML form that, depending on what is chosen, will display the corresponding // greeting in the corresponding language. $endearments = array("dear"=>"dear","lovely"=>"lovely","caro"=>"caro"); shn_form_fopen("say_hello", null,array('req_message'=>true)); shn_form_fsopen("Multilingual Hello Form"); shn_form_text("Your name","name",null,array("req"=>true, "help"=>"testing help")); shn_form_select($languages,"Language", "language",$select_opts = "", $extra_opts = null); shn_form_select(       $greetings,"Greeting", "greeting",$select_opts = "", $extra_opts = null); shn_form_select($endearments,"Endearment","endearment",$select_opt="",$extra_opts=null); shn_form_submit("Submit", $submit_opts = null); shn_form_fsclose; shn_form_fclose; ?>   <? }

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

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

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

/** * This function acts on the inputs from the form created on the default page. Based on the * name, language, and greeting, it will output the appropriate response preceeding the user's * name. * * @access public * @return void */

function shn_hw_say_hello {       // First get the data from the form $name = $_REQUEST['name']; $language = $_REQUEST['language']; $greeting_type = $_REQUEST['greeting']; $endearment = $_REQUEST['endearment']; $error=false; if (!shn_validate_field($name, 'Name', $max_len=30, $check_null=true)){ // If name is null $error=true; }

// Query the database to retrieve a greeting. global $global; $db = $global['db']; $result = $db->Execute("select greeting from hw_greeting where type = '$greeting_type' and language = '$language'"); $greeting = $result->fields['greeting']; if ($error) { display_errors; } else { echo " $greeting "."$greeting $endearment  $name!"; }   echo '

Back'; }