Source for file locales.ctrl.php
Documentation is available at locales.ctrl.php
* This file implements the UI controller for settings management.
* This file is part of Quam Plures - {@link http://quamplures.net/}
* See also {@link https://launchpad.net/quam-plures}.
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* {@internal Open Source relicensing agreement:
* Daniel HAHLER grants Francois PLANQUE the right to license
* Daniel HAHLER's contributions to this file and the b2evolution project
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author blueyed: Daniel HAHLER
* @author fplanque: Francois PLANQUE
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
// Check minimum permission:
$current_User->check_perm( 'options', 'view', true );
$AdminUI->set_path( 'options', 'regional' );
param( 'action', 'string' );
param( 'edit_locale', 'string' );
param( 'loc_transinfo', 'integer', 0 );
// Load all available locale defintions:
if( in_array( $action, array( 'update', 'reset', 'updatelocale', 'createlocale', 'deletelocale', 'extract', 'prioup', 'priodown' )) )
{ // We have an action to do..
$current_User->check_perm( 'options', 'edit', true );
{ // switch between regional actions
// UPDATE regional settings
param( 'newdefault_locale', 'string', true);
$Settings->set( 'default_locale', $newdefault_locale );
param( 'newtime_difference', 'string', '' );
$newtime_difference = trim($newtime_difference);
if( $newtime_difference == '' )
if( strpos($newtime_difference, ':') !== false )
$ntd = explode(':', $newtime_difference);
$newtime_difference = $ntd[0]* 3600 + ($ntd[1]* 60);
$newtime_difference += $ntd[2];
$newtime_difference = $newtime_difference* 3600;
$Settings->set( 'time_difference', $newtime_difference );
if( ! $Messages->count('error') )
$Messages->add( T_('Regional settings updated.'), 'success' );
param( 'newloc_locale', 'string', true );
param( 'newloc_enabled', 'integer', 0);
param( 'newloc_name', 'string', true);
param( 'newloc_charset', 'string', true);
param( 'newloc_datefmt', 'string', true);
param( 'newloc_timefmt', 'string', true);
param( 'newloc_startofweek', 'integer', true);
param( 'newloc_priority', 'integer', 1);
param( 'newloc_messages', 'string', true);
if( $action == 'updatelocale' )
param( 'oldloc_locale', 'string', true);
$query = "SELECT loc_locale FROM T_locales WHERE loc_locale = '$oldloc_locale'";
if( $DB->get_var($query) )
{ // old locale exists in DB
if( $oldloc_locale != $newloc_locale )
{ // locale key was renamed, we delete the old locale in DB and remember to create the new one
$q = $DB->query( 'DELETE FROM T_locales
WHERE loc_locale = "'. $oldloc_locale. '"' );
$Messages->add( sprintf(T_('Deleted settings for locale «%s» in database.'), $oldloc_locale), 'success' );
{ // old locale is not in DB yet. Insert it.
$query = "INSERT INTO T_locales
( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_startofweek, loc_name, loc_messages, loc_priority, loc_enabled )
VALUES ( '$oldloc_locale',
'{$locales[$oldloc_locale]['charset']}', '{$locales[$oldloc_locale]['datefmt']}',
'{$locales[$oldloc_locale]['timefmt']}', '{$locales[$oldloc_locale]['startofweek']}',
'{$locales[$oldloc_locale]['name']}', '{$locales[$oldloc_locale]['messages']}',
'{$locales[$oldloc_locale]['priority']}',";
if( $oldloc_locale != $newloc_locale )
$Messages->add( sprintf(T_('Inserted (and disabled) locale «%s» into database.'), $oldloc_locale), 'success' );
$query .= ' '. $locales[$oldloc_locale]['enabled']. ')';
$Messages->add( sprintf(T_('Inserted locale «%s» into database.'), $oldloc_locale), 'success' );
$query = 'REPLACE INTO T_locales
( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_startofweek, loc_name, loc_messages, loc_priority, loc_enabled )
VALUES ( '. $DB->quote($newloc_locale). ', '. $DB->quote($newloc_charset). ', '. $DB->quote($newloc_datefmt). ', '
. $DB->quote($newloc_timefmt). ', '. $DB->quote($newloc_startofweek). ', '. $DB->quote($newloc_name). ', '
. $DB->quote($newloc_messages). ', '. $DB->quote($newloc_priority). ', '. $DB->quote($newloc_enabled). ' )';
$Messages->add( sprintf(T_('Saved locale «%s».'), $newloc_locale), 'success' );
// reload locales: an existing one could have been renamed (but we keep $evo_charset, which may have changed)
$old_evo_charset = $evo_charset;
* dummy docblock makes error-free autodocs
include $conf_path. '_locales.php';
{ // also overwrite settings again:
include $conf_path. '_overrides_TEST.php';
$evo_charset = $old_evo_charset;
// Load all available locale defintions:
// reload locales from files
include $conf_path. '_locales.php';
{ // also overwrite settings again:
include $conf_path. '_overrides_TEST.php';
// delete everything from locales table
$q = $DB->query( 'DELETE FROM T_locales WHERE 1=1' );
if( !isset ( $locales[$current_locale] ) )
{ // activate default locale
$Settings->set( 'default_locale', $default_locale );
// Load all available locale defintions:
$Messages->add( T_('Locale definitions reset to defaults. (<code>/qp_config/_locales.php</code>)'), 'success' );
// Get PO file for that edit_locale:
$AdminUI->append_to_titlearea( 'Extracting language file for '. $edit_locale. '...' );
$po_file = $locales_path. $locales[$edit_locale]['messages']. '.po';
$outfile = $locales_path. 'php/'. $locales[$edit_locale]['messages']. '/_global.php';
$POFile = new POFile($po_file);
$POFile->read(true); // adds info about sources to $Messages
$POFile->write_evo_trans($outfile, $locales[$edit_locale]['messages']);
// --- DELETE locale from DB
if( $DB->query( 'DELETE FROM T_locales WHERE loc_locale = "'. $DB->escape( $edit_locale ). '"' ) )
$Messages->add( sprintf(T_('Deleted locale «%s» from database.'), $edit_locale), 'success' );
require $conf_path. '_locales.php';
{ // also overwrite settings again:
include $conf_path. '_overrides_TEST.php';
// Load all available locale defintions:
// --- SWITCH PRIORITIES -----------------
if( $action == 'prioup' )
$switchcond = 'return ($lval[\'priority\'] > $i && $lval[\'priority\'] < $locales[ $edit_locale ][\'priority\']);';
elseif( $action == 'priodown' )
$switchcond = 'return ($lval[\'priority\'] < $i && $lval[\'priority\'] > $locales[ $edit_locale ][\'priority\']);';
if( !empty($switchcond) )
{ // we want to switch priorities
foreach( $locales as $lkey => $lval )
{ // find nearest priority
if( $i > - 1 && $i < 256 )
#echo 'Switching prio '.$locales[ $lswitchwith ]['priority'].' with '.$locales[ $lswitch ]['priority'].'<br />';
$locales[ $lswitchwith ]['priority'] = $locales[ $edit_locale ]['priority'];
$locales[ $edit_locale ]['priority'] = $i;
$query = "REPLACE INTO T_locales ( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_name, loc_messages, loc_priority, loc_enabled ) VALUES
( '$edit_locale', '{$locales[ $edit_locale ]['charset']}', '{$locales[ $edit_locale ]['datefmt']}', '{$locales[ $edit_locale ]['timefmt']}', '{$locales[ $edit_locale ]['name']}', '{$locales[ $edit_locale ]['messages']}', '{$locales[ $edit_locale ]['priority']}', '{$locales[ $edit_locale ]['enabled']}'),
( '$lswitchwith', '{$locales[ $lswitchwith ]['charset']}', '{$locales[ $lswitchwith ]['datefmt']}', '{$locales[ $lswitchwith ]['timefmt']}', '{$locales[ $lswitchwith ]['name']}', '{$locales[ $lswitchwith ]['messages']}', '{$locales[ $lswitchwith ]['priority']}', '{$locales[ $lswitchwith ]['enabled']}')";
$q = $DB->query( $query );
$Messages->add( T_('Switched priorities.'), 'success' );
// Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
$AdminUI->disp_html_head();
// Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
$AdminUI->disp_body_top();
$AdminUI->disp_payload_begin();
$AdminUI->disp_view( 'locales/_locale_settings.form.php' );
$AdminUI->disp_payload_end();
// Display body bottom, debug info and close </html>:
$AdminUI->disp_global_footer();
|