Commit 74cae021 authored by Richard Mansfield's avatar Richard Mansfield

Allow language selection on homepage; remember language between registration steps

parent fbb503e7
......@@ -34,6 +34,10 @@ define('TITLE', get_string('home'));
// this, we can guarantee whether the user is logged in or not for this page.
if (!$USER->is_logged_in()) {
$pagename = 'loggedouthome';
$lang = param_alphanumext('lang', null);
if (!empty($lang)) {
$SESSION->set('lang', $lang);
}
}
else {
$pagename = 'home';
......
......@@ -216,6 +216,7 @@ $string['membershipexpiry'] = 'Membership expires';
$string['institutionfull'] = 'The institution you have chosen is not accepting any more registrations.';
$string['registrationnotallowed'] = 'The institution you have chosen does not allow self-registration.';
$string['registrationcomplete'] = 'Thank you for registering at %s';
$string['language'] = 'Language';
// Forgot password
$string['cantchangepassword'] = 'Sorry, you are unable to change your password through this interface - please use your institution\'s interface instead';
......
......@@ -401,6 +401,7 @@
<FIELD NAME="firstname" TYPE="text" NOTNULL="true"/>
<FIELD NAME="lastname" TYPE="text" NOTNULL="true"/>
<FIELD NAME="email" TYPE="text" NOTNULL="true"/>
<FIELD NAME="lang" TYPE="text" NOTNULL="false"/>
<FIELD NAME="key" TYPE="char" LENGTH="16" NOTNULL="true"/>
<FIELD NAME="expiry" TYPE="datetime" NOTNULL="true"/>
</FIELDS>
......
......@@ -785,6 +785,10 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
}
if ($oldversion < 2008012400) {
table_column('usr_registration', null, 'lang', 'text', null, null, '', '');
}
return $status;
}
......
......@@ -700,13 +700,17 @@ function print_object($mixed) {
* @return string
*/
function current_language() {
global $USER, $CFG;
global $USER, $CFG, $SESSION;
if ($USER instanceof User) {
$lang = $USER->get_account_preference('lang');
if ($lang !== null && $lang != 'default') {
return $lang;
}
}
$sesslang = $SESSION->get('lang');
if (!empty($sesslang)) {
return $sesslang;
}
if (!empty($CFG->lang)) {
return $CFG->lang;
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008011400;
$config->version = 2008012400;
$config->release = '1.0.0alpha2dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
......@@ -348,6 +348,11 @@ EOF;
$smarty->assign('MAINNAV', main_nav());
$smarty->assign('LOGGEDINSTR', get_loggedin_string());
}
else {
$smarty->assign('sitedefaultlang', get_string('sitedefault', 'admin') . ' (' .
get_string_from_language('default', 'thislanguage') . ')');
$smarty->assign('LANGUAGES', get_languages());
}
$smarty->assign_by_ref('USER', $USER);
$smarty->assign('SESSKEY', $USER->get('sesskey'));
......
......@@ -67,6 +67,12 @@ if (isset($key)) {
die_info(get_string('registrationnosuchkey', 'auth.internal'));
}
// In case a new session has started, reset the session language
// to the one selected during registration
if (!empty($registration->lang)) {
$SESSION->set('lang', $registration->lang);
}
function create_registered_user($profilefields=array()) {
global $registration, $SESSION, $USER;
......@@ -107,6 +113,9 @@ if (isset($key)) {
set_profile_field($user->id, 'email', $registration->email);
set_profile_field($user->id, 'firstname', $registration->firstname);
set_profile_field($user->id, 'lastname', $registration->lastname);
if (!empty($registration->lang) && $registration->lang != 'default') {
set_account_preference($user->id, 'lang', $registration->lang);
}
// Delete the old registration record
delete_records('usr_registration', 'id', $registrationid);
......@@ -428,6 +437,7 @@ function register_submit(Pieform $form, $values) {
$values['key'] = get_random_key();
// @todo the expiry date should be configurable
$values['expiry'] = db_format_timestamp(time() + 86400);
$values['lang'] = $SESSION->get('lang');
try {
insert_record('usr_registration', $values);
......
......@@ -63,6 +63,23 @@
</tr>
*}
{/if}
{if defined('MENUITEM') && MENUITEM == '' && !$LOGGEDIN && (count($LANGUAGES) > 1)}
<tr class="headerlanguage">
<td>
<form method="post">
<label>{str tag=language}: </label>
<select name="lang">
<option value="default" selected>{$sitedefaultlang}</option>
{foreach from=$LANGUAGES key=k item=i}
<option value="{$k}">{$i}</option>
{/foreach}
</select>
<input type="submit" class="submit" name="changelang" value="{str tag=change}" />
</form>
</td>
</tr>
{/if}
<tr>
<td><div id="loggedinstring">{$LOGGEDINSTR}</div></td>
</tr>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment