1) implemented a share system-charset, which can be different from the charset of the lang-files

2) moved sql-specific part of setup_translation to translation_sql
3) TO-DO: get the translation-tools working in this setting
This commit is contained in:
Ralf Becker 2003-10-05 02:06:11 +00:00
parent 3a4d3d3f52
commit fd2d96d063
14 changed files with 431 additions and 134 deletions

View File

@ -275,7 +275,7 @@
$extra_vars = '?' . substr($extra_vars,1,strlen($extra_vars)); $extra_vars = '?' . substr($extra_vars,1,strlen($extra_vars));
} }
$tmpl->set_var('charset',lang('charset')); $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
$tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars); $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
$tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/'); $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
$tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']); $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);

View File

@ -28,9 +28,9 @@
var $appreg = ''; var $appreg = '';
/* table name vars */ /* table name vars */
var $tbl_apps; var $tbl_apps;
var $tbl_config; var $tbl_config;
var $tbl_hooks; var $tbl_hooks;
function setup($html=False, $translation=False) function setup($html=False, $translation=False)
{ {
@ -41,10 +41,10 @@
/* The setup application needs these */ /* The setup application needs these */
$this->html = $html ? CreateObject('phpgwapi.setup_html') : ''; $this->html = $html ? CreateObject('phpgwapi.setup_html') : '';
$this->translation = $translation ? CreateObject('phpgwapi.setup_translation') : ''; $this->translation = $translation ? CreateObject('phpgwapi.setup_translation') : '';
// $this->tbl_apps = $this->get_apps_table_name(); // $this->tbl_apps = $this->get_apps_table_name();
// $this->tbl_config = $this->get_config_table_name(); // $this->tbl_config = $this->get_config_table_name();
$this->tbl_hooks = $this->get_hooks_table_name(); $this->tbl_hooks = $this->get_hooks_table_name();
} }
/*! /*!

View File

@ -73,7 +73,7 @@
fclose($fp); fclose($fp);
} }
} }
/*! /*!
@function translate @function translate
@abstract Translate phrase to user selected lang @abstract Translate phrase to user selected lang
@ -112,125 +112,33 @@
return $ret; return $ret;
} }
/* Following functions are called for app (un)install */ // the following functions have been moved to phpgwapi/tanslation_sql
function setup_translation_sql()
{
if (!is_object($this->sql))
{
include_once(PHPGW_API_INC.'/class.translation_sql.inc.php');
$this->sql = new translation;
}
}
/*!
@function get_langs
@abstract return array of installed languages, e.g. array('de','en')
*/
function get_langs($DEBUG=False) function get_langs($DEBUG=False)
{ {
if($DEBUG) $this->setup_translation_sql();
{ return $this->sql->get_langs($DEBUG);
echo '<br>get_langs(): checking db...' . "\n";
}
$GLOBALS['phpgw_setup']->db->query("SELECT DISTINCT(lang) FROM phpgw_lang",__LINE__,__FILE__);
$langs = array();
while($GLOBALS['phpgw_setup']->db->next_record())
{
if($DEBUG)
{
echo '<br>get_langs(): found ' . $GLOBALS['phpgw_setup']->db->f(0);
}
$langs[] = $GLOBALS['phpgw_setup']->db->f(0);
}
return $langs;
} }
/*!
@function drop_langs
@abstract delete all lang entries for an application, return True if langs were found
@param $appname app_name whose translations you want to delete
*/
function drop_langs($appname,$DEBUG=False) function drop_langs($appname,$DEBUG=False)
{ {
if($DEBUG) $this->setup_translation_sql();
{ return $this->sql->drop_langs($appname,$DEBUG);
echo '<br>drop_langs(): Working on: ' . $appname;
}
$GLOBALS['phpgw_setup']->db->query("SELECT COUNT(message_id) FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
$GLOBALS['phpgw_setup']->db->next_record();
if($GLOBALS['phpgw_setup']->db->f(0))
{
$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
return True;
}
return False;
} }
/*!
@function add_langs
@abstract process an application's lang files, calling get_langs() to see what langs the admin installed already
@param $appname app_name of application to process
*/
function add_langs($appname,$DEBUG=False,$force_langs=False) function add_langs($appname,$DEBUG=False,$force_langs=False)
{ {
$langs = $this->get_langs($DEBUG); $this->setup_translation_sql();
if(is_array($force_langs)) return $this->sql->add_langs($appname,$DEBUG,$force_langs);
{
foreach($force_langs as $lang)
{
if (!in_array($lang,$langs))
{
$langs[] = $lang;
}
}
}
if($DEBUG)
{
echo '<br>add_langs(): chose these langs: ';
_debug_array($langs);
}
$GLOBALS['phpgw_setup']->db->transaction_begin();
while (list($null,$lang) = each($langs))
{
if($DEBUG)
{
echo '<br>add_langs(): Working on: ' . $lang . ' for ' . $appname;
}
$appfile = PHPGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang';
if(file_exists($appfile))
{
if($DEBUG)
{
echo '<br>add_langs(): Including: ' . $appfile;
}
$raw_file = file($appfile);
while (list($null,$line) = @each($raw_file))
{
list($message_id,$app_name,$GLOBALS['phpgw_setup']->db_lang,$content) = explode("\t",$line);
$message_id = $GLOBALS['phpgw_setup']->db->db_addslashes(strtolower(chop(substr($message_id,0,MAX_MESSAGE_ID_LENGTH))));
/* echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id; */
$app_name = $GLOBALS['phpgw_setup']->db->db_addslashes(chop($app_name));
$GLOBALS['phpgw_setup']->db_lang = $GLOBALS['phpgw_setup']->db->db_addslashes(chop($GLOBALS['phpgw_setup']->db_lang));
$content = $GLOBALS['phpgw_setup']->db->db_addslashes(chop($content));
$GLOBALS['phpgw_setup']->db->query("SELECT COUNT(*) FROM phpgw_lang WHERE message_id='$message_id' AND lang='"
. $GLOBALS['phpgw_setup']->db_lang . "' AND (app_name='$app_name' OR (app_name='common' AND content='$content'))",__LINE__,__FILE__);
$GLOBALS['phpgw_setup']->db->next_record();
if ($GLOBALS['phpgw_setup']->db->f(0) == 0)
{
if($message_id && $content)
{
if($DEBUG)
{
echo "<br>add_langs(): adding - INSERT INTO phpgw_lang VALUES ('$message_id','$app_name','"
. $GLOBALS['phpgw_setup']->db_lang . "','$content')";
}
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_lang VALUES ('$message_id','$app_name','"
. $GLOBALS['phpgw_setup']->db_lang . "','$content')",__LINE__,__FILE__);
}
}
}
}
}
$GLOBALS['phpgw_setup']->db->transaction_commit();
} }
} }
?> ?>

View File

@ -39,6 +39,36 @@
function translation() function translation()
{ {
$this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db; $this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db;
if (!isset($GLOBALS['phpgw_setup']))
{
$this->system_charset = $GLOBALS['phpgw_info']['server']['system_charset'];
}
else
{
$this->db->query("SELECT config_value FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__);
if ($this->db->next_record())
{
$this->system_charset = $this->db->f(0);
}
}
}
/*
@function charset
@abstract returns the charset to use
@note this is the system_charset if set and no lang given or the charset of the language
*/
function charset($lang=False)
{
if (!$lang && $this->system_charset)
{
return $this->system_charset;
}
if ($lang)
{
$this->add_app('common',$lang);
}
return $this->translate('charset');
} }
function init() function init()
@ -165,6 +195,23 @@
return $this->charsets; return $this->charsets;
} }
/*!
@function convert
@abstract converts a string $data from charset $from to charset $to
*/
function convert($data,$from='iso-8859-1',$to='utf8')
{
if ($from == 'iso-8859-1' && $to == 'utf8')
{
return utf8_encode($data);
}
if ($to == 'iso-8859-1' && $from == 'utf8')
{
return utf8_decode($data);
}
die("can't convert from '$from' to '$to' !!!");
}
/*! /*!
@function install_langs @function install_langs
@abstract installs translations for the selected langs into the database @abstract installs translations for the selected langs into the database
@ -172,7 +219,7 @@
@param $langs array of langs to install (as data NOT keys (!)) @param $langs array of langs to install (as data NOT keys (!))
@param $upgrademethod 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases @param $upgrademethod 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases
*/ */
function install_langs($langs,$upgrademethod='dumpold') function install_langs($langs,$upgrademethod='dumpold',$only_app=False)
{ {
@set_time_limit(0); // we might need some time @set_time_limit(0); // we might need some time
@ -225,12 +272,13 @@
$setup_info = $GLOBALS['phpgw_setup']->detection->get_versions(); $setup_info = $GLOBALS['phpgw_setup']->detection->get_versions();
$setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions($setup_info); $setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions($setup_info);
$raw = array(); $raw = array();
$apps = $only_app ? array($only_app) : array_keys($setup_info);
// Visit each app/setup dir, look for a phpgw_lang file // Visit each app/setup dir, look for a phpgw_lang file
foreach($setup_info as $key => $app) foreach($apps as $app)
{ {
$appfile = PHPGW_SERVER_ROOT . SEP . @$app['name'] . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang'; $appfile = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang';
//echo '<br>Checking in: ' . $app['name']; //echo '<br>Checking in: ' . $app['name'];
if($GLOBALS['phpgw_setup']->app_registered(@$app['name']) && file_exists($appfile)) if($GLOBALS['phpgw_setup']->app_registered($app) && file_exists($appfile))
{ {
//echo '<br>Including: ' . $appfile; //echo '<br>Including: ' . $appfile;
$lines = file($appfile); $lines = file($appfile);
@ -246,10 +294,17 @@
$GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang][$app['name']] = filectime($appfile); $GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang][$app['name']] = filectime($appfile);
} }
} }
$charset = @$raw['common']['charset'] ? $raw['common']['charset'] : $this->charset($lang);
//echo "<p>lang='$lang', charset='$charset', system_charset='$this->system_charset')</p>\n";
foreach($raw as $app_name => $ids) foreach($raw as $app_name => $ids)
{ {
foreach($ids as $message_id => $content) foreach($ids as $message_id => $content)
{ {
if ($this->system_charset && $charset && $charset != $this->system_charset)
{
$content = $this->convert($content,$charset,$this->system_charset);
}
$addit = False; $addit = False;
//echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id; //echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id;
if ($upgrademethod == 'addmissing') if ($upgrademethod == 'addmissing')
@ -325,4 +380,68 @@
} }
} }
} }
/* Following functions are called for app (un)install */
/*!
@function get_langs
@abstract return array of installed languages, e.g. array('de','en')
*/
function get_langs($DEBUG=False)
{
if($DEBUG)
{
echo '<br>get_langs(): checking db...' . "\n";
}
return array_keys($this->get_installed_langs());
}
/*!
@function drop_langs
@abstract delete all lang entries for an application, return True if langs were found
@param $appname app_name whose translations you want to delete
*/
function drop_langs($appname,$DEBUG=False)
{
if($DEBUG)
{
echo '<br>drop_langs(): Working on: ' . $appname;
}
$this->db->query("SELECT COUNT(message_id) FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
$this->db->next_record();
if($this->db->f(0))
{
$this->db->query("DELETE FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
return True;
}
return False;
}
/*!
@function add_langs
@abstract process an application's lang files, calling get_langs() to see what langs the admin installed already
@param $appname app_name of application to process
*/
function add_langs($appname,$DEBUG=False,$force_langs=False)
{
$langs = $this->get_langs($DEBUG);
if(is_array($force_langs))
{
foreach($force_langs as $lang)
{
if (!in_array($lang,$langs))
{
$langs[] = $lang;
}
}
}
if($DEBUG)
{
echo '<br>add_langs(): chose these langs: ';
_debug_array($langs);
}
$this->install_langs($langs,'addmissing',$appname);
}
} }

View File

@ -27,7 +27,7 @@
$var = Array ( $var = Array (
'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico',
'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico',
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'font_family' => $GLOBALS['phpgw_info']['theme']['font'], 'font_family' => $GLOBALS['phpgw_info']['theme']['font'],
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app, 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),

View File

@ -35,7 +35,7 @@
$var = Array ( $var = Array (
'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico',
'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico',
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'font_family' => $GLOBALS['phpgw_info']['theme']['font'], 'font_family' => $GLOBALS['phpgw_info']['theme']['font'],
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'].$app, 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'].$app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),

View File

@ -22,7 +22,7 @@
$var = Array ( $var = Array (
'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico',
'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico',
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'font_family' => $GLOBALS['phpgw_info']['theme']['font'], 'font_family' => $GLOBALS['phpgw_info']['theme']['font'],
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app, 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),

View File

@ -31,7 +31,7 @@
'email' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'email.uipreferences.preferences')), 'email' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'email.uipreferences.preferences')),
'calendar' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uipreferences.preferences')), 'calendar' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uipreferences.preferences')),
'addressbook' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'addressbook.uiaddressbook.preferences')), 'addressbook' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'addressbook.uiaddressbook.preferences')),
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app, 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),
'css' => $GLOBALS['phpgw']->common->get_css(), 'css' => $GLOBALS['phpgw']->common->get_css(),

View File

@ -35,7 +35,7 @@
$var = Array ( $var = Array (
'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico',
'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico',
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'], 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'],
'app_name' => $app, 'app_name' => $app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),

View File

@ -24,7 +24,7 @@
$var = Array ( $var = Array (
'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_icon' => PHPGW_IMAGES_DIR . '/favicon.ico',
'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico', 'img_shortcut' => PHPGW_IMAGES_DIR . '/favicon.ico',
'charset' => lang('charset'), 'charset' => $GLOBALS['phpgw']->translation->charset(),
'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app, 'website_title' => $GLOBALS['phpgw_info']['server']['site_title'] . $app,
'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(), 'body_tags' => $bodyheader .' '. $GLOBALS['phpgw']->common->get_body_attribs(),
'css' => $GLOBALS['phpgw']->common->get_css(), 'css' => $GLOBALS['phpgw']->common->get_css(),

View File

@ -418,6 +418,12 @@
'POST','lang.php', 'POST','lang.php',
'submit',lang('Manage Languages'), 'submit',lang('Manage Languages'),
''); '');
// show system-charset and offer conversation
include(PHPGW_API_INC.'/class.translation_sql.inc.php');
$translation = new translation;
$btn_manage_lang .= lang('Current system-charset is %1, click %2here%3 to change it.',
$translation->system_charset ? "'$translation->system_charset'" : lang('not set'),
'<a href="system_charset.php">','</a>');
$setup_tpl->set_var('lang_table_data',$btn_manage_lang); $setup_tpl->set_var('lang_table_data',$btn_manage_lang);
break; break;
default: default:

View File

@ -21,7 +21,7 @@
include('./inc/functions.inc.php'); include('./inc/functions.inc.php');
// Authorize the user to use setup app and load the database // Authorize the user to use setup app and load the database
// Does not return unless user is authorized // Does not return unless user is authorized
if (!$GLOBALS['phpgw_setup']->auth('Config')) if (!$GLOBALS['phpgw_setup']->auth('Config') || @$_POST['cancel'])
{ {
Header('Location: index.php'); Header('Location: index.php');
exit; exit;
@ -30,13 +30,9 @@
if (@$_POST['submit']) if (@$_POST['submit'])
{ {
include(PHPGW_API_INC.'/class.translation_sql.inc.php'); $GLOBALS['phpgw_setup']->translation->setup_translation_sql();
$translation = new translation; $GLOBALS['phpgw_setup']->translation->sql->install_langs(@$_POST['lang_selected'],@$_POST['upgrademethod']);
$translation->install_langs(@$_POST['lang_selected'],@$_POST['upgrademethod']);
}
if(@$_POST['submit'] || @$_POST['cancel'])
{
Header('Location: index.php'); Header('Location: index.php');
exit; exit;
} }

222
setup/system_charset.php Normal file
View File

@ -0,0 +1,222 @@
<?php
/**************************************************************************\
* eGroupWare - Setup - change / convert system-charset *
* http://www.eGroupWareare.org *
* Written by RalfBecker@outdoor-training.de *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info = array();
$GLOBALS['phpgw_info']['flags'] = array(
'noheader' => True,
'nonavbar' => True,
'currentapp' => 'home',
'noapi' => True
);
include('./inc/functions.inc.php');
// Authorize the user to use setup app and load the database
// Does not return unless user is authorized
if (!$GLOBALS['phpgw_setup']->auth('Config') || @$_POST['cancel'])
{
Header('Location: index.php');
exit;
}
$GLOBALS['phpgw_setup']->loaddb();
$translation = &$GLOBALS['phpgw_setup']->translation->sql;
$tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
$setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
$setup_tpl->set_file(array(
'T_head' => 'head.tpl',
'T_footer' => 'footer.tpl',
'T_system_charset' => 'system_charset.tpl',
));
$stage_title = lang('Change system-charset');
$stage_desc = lang('This program will convert your database to a new system-charset.');
$GLOBALS['phpgw_setup']->html->show_header($stage_title,False,'config',$ConfigDomain . '(' . $phpgw_domain[$ConfigDomain]['db_type'] . ')');
if (@$_POST['convert'])
{
if (empty($_POST['current_charset']))
{
$errors[] = lang('You need to select your current charset!');
}
else
{
$debug=1;
convert_db($_POST['current_charset'],$_POST['new_charset'],$debug);
if (!$debug)
{
Header('Location: index.php');
}
echo "<h3>Database successfully converted from '$_POST[current_charset]' to '$_POST[new_charset]'</h3>\n";
echo "<p>Click <a href=\"index.php\">here</a> to return to setup</p>\n";
exit;
}
}
function key_data_implode($glue,$array,$only=False,$use_key=True)
{
$pairs = array();
foreach($array as $key => $data)
{
if (!$only || in_array($key,$only))
{
$values[] = ($use_key ? $key.'=' : '')."'".addslashes($data)."'";
}
}
return implode($glue,$values);
}
function convert_db($from,$to,$debug=1)
{
if ($debug) echo "<h3>Converting database from '$from' to '$to'</h3>\n";
@set_time_limit(0); // this might take a while
$db2 = $GLOBALS['phpgw_setup']->db;
$setup_info = $GLOBALS['phpgw_setup']->detection->get_versions();
$setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions($setup_info);
// Visit each app/setup dir, look for a phpgw_lang file
foreach($setup_info as $app => $data)
{
$tables_current = PHPGW_SERVER_ROOT . "/$app/setup/tables_current.inc.php";
if ($debug) echo "<p><b>$app</b>: ";
if (!isset($data['tables']) || !count($data['tables']) ||
$GLOBALS['phpgw_setup']->app_registered($app) && !file_exists($tables_current))
{
if ($debug) echo "skipping (no tables or not installed)</p>\n";
continue;
}
include($tables_current);
foreach($phpgw_baseline as $table => $definition)
{
if ($debug) { echo "<br>start converting table '$table' ... "; flush(); }
$updates = 0;
$GLOBALS['phpgw_setup']->db->query("SELECT * FROM $table",__LINE__,__FILE__);
while($GLOBALS['phpgw_setup']->db->next_record())
{
$columns = $GLOBALS['phpgw_setup']->db->Record;
$update = array();
foreach($columns as $name => $data)
{
if (is_numeric($name))
{
unset($columns[$name]);
continue;
}
switch($definition['fd'][$name]['type'])
{
case 'char':
case 'varchar':
case 'text':
case 'longtext':
$converted = $GLOBALS['translation']->convert($data,$from,$to);
if ($converted != $data)
{
$update[$name] = $converted;
}
break;
}
}
if (count($update))
{
if (count($definition['pk']))
{
$db2->query($query="UPDATE $table SET ".key_data_implode(',',$update)." WHERE ".key_data_implode(' AND ',$columns,$definition['pk']),__LINE__,__FILE__);
}
else
{
$db2->query($query="DELETE FROM $table WHERE ".key_data_implode(' AND ',$columns),__LINE__,__FILE__);
if ($debug > 1) echo " &nbsp; $query<br>\n";
$db2->query($query="INSERT INTO $table (".implode(',',array_keys($columns)).") VALUES (".key_data_implode(',',array_merge($columns,$update),False,True).")",__LINE__,__FILE__);
}
if ($debug > 1) echo " &nbsp; $query<p>\n";
++$updates;
}
}
if ($debug)
{
$GLOBALS['phpgw_setup']->db->query("SELECT count(*) FROM $table",__LINE__,__FILE__);
$GLOBALS['phpgw_setup']->db->next_record();
$total = $GLOBALS['phpgw_setup']->db->f(0);
echo " done, $updates/$total rows updated";
}
}
}
@$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__);
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_config (config_app,config_name,config_value) VALUES ('phpgwapi','system_charset','$to')",__LINE__,__FILE__);
}
$setup_tpl->set_var('stage_title',$stage_title);
$setup_tpl->set_var('stage_desc',$stage_desc);
$setup_tpl->set_var('error_msg',is_array($errors) ? implode('<br>',$errors) : '&nbsp');
$setup_tpl->set_var('lang_convert',lang('Convert'));
$setup_tpl->set_var('lang_cancel',lang('Cancel'));
$setup_tpl->set_var('lang_current',lang('Current system-charset'));
$setup_tpl->set_var('lang_convert_to',lang('Charset to convert to'));
$setup_tpl->set_var('lang_warning',lang('<b>Warning</b>: Hopefully you know what you do ;-)'));
$installed_charsets = $translation->get_installed_charsets();
if ($translation->system_charset || count($installed_charsets) == 1)
{
reset($installed_charsets);
list($current_charset) = each($installed_charsets);
if ($translation->system_charset)
{
$current_charset = $translation->system_charset;
}
$setup_tpl->set_var('current_charset',"<b>$current_charset</b>".
"<input type=\"hidden\" name=\"current_charset\" value=\"$current_charset\">\n");
}
else
{
$options = '<option value="">'.lang('select one...')."</option>\n";
foreach($installed_charsets as $charset => $description)
{
$options .= "<option value=\"$charset\">$description</option>\n";
}
$setup_tpl->set_var('current_charset',"<select name=\"current_charset\">\n$options</select>\n");
}
if ($translation->system_charset == 'utf8' || count($installed_charsets) == 1)
{
reset($installed_charsets);
list($other_charset) = each($installed_charsets);
if (!$translation->system_charset || $other_charset == $translation->system_charset)
{
$other_charset = 'utf8';
}
$setup_tpl->set_var('new_charset',"<b>$other_charset</b><input type=\"hidden\" name=\"new_charset\" value=\"$other_charset\">\n");
}
else
{
if ($translation->system_charset != 'utf8')
{
$options = '<option value="utf8">'.lang('UTF8 (Unicode)')."</option>\n";
}
foreach($installed_charsets as $charset => $description)
{
if ($charset != $translation->system_charset)
{
$options .= "<option value=\"$charset\">$description</option>\n";
}
}
$setup_tpl->set_var('new_charset',"<select name=\"new_charset\">\n$options</select>\n");
}
$setup_tpl->pparse('out','T_system_charset');
$GLOBALS['phpgw_setup']->html->show_footer();
?>

View File

@ -0,0 +1,46 @@
<!-- begin system_chaset.tpl -->
<p align="center"><font color="red">{error_msg}</font></p>
<form method="POST" action="system_charset.php">
<table border="0" align="center" width="80%">
<tr bgcolor="#486591">
<td colspan="2">
&nbsp;<font color="#fefefe">{stage_title}</font>
</td>
</tr>
<tr bgcolor="#e6e6e6">
<td colspan="2">
{stage_desc}
</td>
</tr>
<tr bgcolor="#e6e6e6">
<td>
{lang_current}
</td>
<td>
{current_charset}
</td>
</tr>
<tr bgcolor="#e6e6e6">
<td>
{lang_convert_to}
</td>
<td>
{new_charset}
</td>
</tr>
<tr bgcolor="#e6e6e6">
<td colspan="2">
{lang_warning}
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="convert" value="{lang_convert}"> &nbsp;
<input type="submit" name="cancel" value="{lang_cancel}">
</td>
</tr>
</table>
</form>
<!-- end system_charset.tpl -->