From 64976f0b1c594bdeaac265743b82c2a4e97c9407 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 21 Nov 2004 09:44:02 +0000 Subject: [PATCH] support to set the client-encoding (charset) for the DB and select a system-charset (utf-8 or others) at installation time --- phpgwapi/inc/class.setup.inc.php | 15 ++++++- phpgwapi/inc/class.setup_translation.inc.php | 46 ++++++++++++++++++++ phpgwapi/inc/functions.inc.php | 6 +++ setup/index.php | 9 +++- setup/lang/phpgw_de.lang | 8 ++-- setup/lang/phpgw_en.lang | 9 ++-- setup/templates/default/setup_db_blocks.tpl | 2 +- 7 files changed, 84 insertions(+), 11 deletions(-) diff --git a/phpgwapi/inc/class.setup.inc.php b/phpgwapi/inc/class.setup.inc.php index a462b0f449..664cca4d4f 100644 --- a/phpgwapi/inc/class.setup.inc.php +++ b/phpgwapi/inc/class.setup.inc.php @@ -53,7 +53,7 @@ @function loaddb @abstract include api db class for the ConfigDomain and connect to the db */ - function loaddb() + function loaddb($connect_and_setcharset=true) { if(!isset($this->ConfigDomain) || empty($this->ConfigDomain)) { @@ -75,6 +75,19 @@ $this->db->Password = $GLOBALS['phpgw_domain'][$this->ConfigDomain]['db_pass']; $this->db->set_app('phpgwapi'); + + if ($connect_and_setcharset) + { + $this->Halt_On_Error = 'no'; // table might not be created at that stage + + // Set the DB's client charset if a system-charset is set + $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->db->f(0)) + { + $this->db->Link_ID->SetCharSet($this->db->f(0)); + } + $this->db->Halt_On_Error = 'yes'; // setting the default again + } } /** diff --git a/phpgwapi/inc/class.setup_translation.inc.php b/phpgwapi/inc/class.setup_translation.inc.php index ea7fd4a405..d9ea9b1358 100644 --- a/phpgwapi/inc/class.setup_translation.inc.php +++ b/phpgwapi/inc/class.setup_translation.inc.php @@ -131,5 +131,51 @@ } return $this->sql->install_langs($langs,'dumpold'); } + + /** + * List availible charsets and it's supported languages + * @param boolean/string $name=false name for selectbox or false to return an array + * @param string $selected selected charset + * @return string/array html for a selectbox or array with charset / languages pairs + */ + function get_charsets($name=false,$selected='') + { + $charsets = array( + 'utf-8' => 'utf-8: '.lang('all languages (incl. not listed ones)'), + ); + if (($f = fopen('lang/languages','r'))) + { + while(($line = fgets($f)) !== false) + { + list($lang,$language) = explode("\t",trim($line)); + if ($lang && ($lf = fopen("../phpgwapi/setup/phpgw_$lang.lang",'r'))) + { + while(($line = fgets($lf)) !== false) + { + list($phrase,,,$charset) = explode("\t",$line); + if ($phrase == 'charset') + { + $charset = trim(strtolower($charset)); + + if ($charset != 'utf-8') + { + $charsets[$charset] .= (isset($charsets[$charset]) ? ', ' : $charset.': ') . $language; + } + break; + } + } + fclose($lf); + } + } + fclose($f); + } + if (!$name) + { + return $charsets; + } + $html = CreateObject('phpgwapi.html'); + + return $html->select($name,strtolower($selected),$charsets,true); + } } ?> diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index fcceb7f369..d91906489b 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -167,6 +167,12 @@ } $GLOBALS['phpgw']->db->Halt_On_Error = 'yes'; + // Set the DB's client charset if a system-charset is set + $GLOBALS['phpgw']->db->query("select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='system_charset'",__LINE__,__FILE__); + if ($GLOBALS['phpgw']->db->next_record() && $GLOBALS['phpgw']->db->f(0)) + { + $GLOBALS['phpgw']->db->Link_ID->SetCharSet($GLOBALS['phpgw']->db->f(0)); + } /* Fill phpgw_info["server"] array */ // An Attempt to speed things up using cache premise $GLOBALS['phpgw']->db->query("select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='cache_phpgw_info'",__LINE__,__FILE__); diff --git a/setup/index.php b/setup/index.php index 07d82e09bc..396b4d4586 100644 --- a/setup/index.php +++ b/setup/index.php @@ -230,8 +230,8 @@ $setup_tpl->set_var('proceed',lang('We can proceed')); $setup_tpl->set_var('coreapps',lang('all applications')); $setup_tpl->set_var('lang_debug',lang('enable for extra debug-messages')); - $setup_tpl->set_var('lang_system_charset',lang('use utf-8 (unicode) as system-charset (recomended if you use languages with different charsets or your language uses utf-8 as charset)')); - $setup_tpl->set_var('utf8_checked',lang('charset') == 'uft-8' ? 'checked' : ''); + $setup_tpl->set_var('lang_system_charset',lang('charset to use (use utf-8 if you plan to use languages with different charsets):')); + $setup_tpl->set_var('system_charset',$GLOBALS['phpgw_setup']->translation->get_charsets('system_charset',lang('charset'))); $setup_tpl->set_var('lang_restore',lang('Or you can install a previous backup.')); $setup_tpl->set_var('upload','  '. ''); @@ -322,6 +322,11 @@ else { $setup_info = $GLOBALS['phpgw_setup']->detection->upgrade_exclude($setup_info); + // Set the DB's client charset if a system-charset is set + if ($_REQUEST['system_charset']) + { + $GLOBALS['phpgw_setup']->db->Link_ID->SetCharSet($_REQUEST['system_charset']); + } $setup_info = $GLOBALS['phpgw_setup']->process->pass($setup_info,'new',$_REQUEST['debug'],True,$_REQUEST['system_charset']); $GLOBALS['phpgw_info']['setup']['currentver']['phpgwapi'] = 'oldversion'; } diff --git a/setup/lang/phpgw_de.lang b/setup/lang/phpgw_de.lang index 94bcb7668d..6dbcd243d1 100644 --- a/setup/lang/phpgw_de.lang +++ b/setup/lang/phpgw_de.lang @@ -6,6 +6,7 @@ 00 (disable) setup de 00 (abgeschaltet/empfohlen) 13 (ntp) setup de 13 (ntp) 80 (http) setup de 80 (http) +charset to use (use utf-8 if you plan to use languages with different charsets): setup de Zeichensatz (benutzen sie utf-8 wenn sie planen Sprachen mit verschiedenen Zeichensätzen zu verwenden) this will create 1 admin account and 3 demo accounts
the username/passwords are: demo/guest, demo2/guest and demo3/guest. setup de Dies wird 1 Admin- und 3 Demo-Benutzerkonten anlegen.
Die Benutzernamen/Passwörter sind: demo/guest, demo2/guest und demo3/guest. accounts existing setup de Benutzerkonten existieren actions setup de Aktionen @@ -23,6 +24,7 @@ after backing up your tables first. setup de Nach einer Datensicherung Ihrer Tab after retrieving the file, put it into place as the header.inc.php. then, click "continue". setup de Datei nach dem Herunterladen als header.inc.php speichern. Danach auf "Weiter" klicken. all applications setup de Alle Anwendungen all core tables and the admin and preferences applications setup de Sie alle Kern-Tabellen und die Anwendungen Admin und Einstellungen +all languages (incl. not listed ones) setup de alle Sprachen (einschl. nicht aufgeführte) all users setup de Alle Benutzer analysis setup de Analyse and reload your webserver, so the above changes take effect !!! setup de UND reloaden Sie ihren Webserver, damit die obigen Änderungen in Kraft treten!!! @@ -194,6 +196,7 @@ go back setup de Zur go to setup de Gehen zu grant access setup de Zugriff gewähren has a version mismatch setup de hat eine falsche Versionsanpassung +header 0assword setup de Passwor Headerverwaltung header admin login setup de Login Headerverwaltung header password setup de Passwort der Headerverwaltung header username setup de Benutzername der Headerverwaltung @@ -358,6 +361,8 @@ safe_mode is turned on, which is generaly a good thing as it makes your install sample configuration not found. using built in defaults setup de Beispiel Konfiguration nicht gefunden, benutze eingebaute Voreinstellungen save setup de Speichern save this text as contents of your header.inc.php setup de Speichern Sie diesen Text als Datei header.inc.php +schedule setup de planen +scheduled backups setup de Regelmäßige Datensicherungen select an app, enter a target version, then submit to process to that version.
if you do not enter a version, only the baseline tables will be installed for the app.
this will drop all of the apps' tables first! setup de Wählen Sie eine Applikation, geben Sie eine Zielversion ein, dann bestätigen Sie den Vorgang.
Wenn Sie keine Version angeben, werden nur die Basis-Tabellen der Applikation installiert werden.
DIES WIRD ZUERST ALLE TABELLEN DER APPLI select one... setup de Einen auswählen... select the default applications to which your users will have access setup de Wählen Sie die voreingestellten Anwendungen, zu denen Ihre Benutzer Zugriff haben werden @@ -390,8 +395,6 @@ setup demo accounts in ldap setup de Demo-Benutzer in LDAP einrichten setup main menu setup de Setup-Hauptmenü setup the database setup de Datenbank einzurichten setup/config admin login setup de Setup-/Konfigurationsadmin-Login -schedule setup de planen -scheduled backups setup de Regelmäßige Datensicherungen show 'powered by' logo on setup de Zeige "powered by" Logo size setup de Größe some or all of its tables are missing setup de Einige oder alle Tabellen fehlen @@ -456,7 +459,6 @@ uploads a backup and installs it on your db setup de l uploads a backup to the backup-dir, from where you can restore it setup de Läde eine Datensicherung in das Datensicherungsverzeichnis, von wo sie diese zurücksichern können use cookies to pass sessionid setup de SitzungsId in einem Cookie speichern use pure html compliant code (not fully working yet) setup de Vollständig HTML kompatiblen Code verwenden (nicht vollständig implementiert) -use utf-8 (unicode) as system-charset (recomended if you use languages with different charsets or your language uses utf-8 as charset) setup de utf-8 (Unicode) als Systemzeichensatz benutzen (empfohlen wenn Sie Sprachen mit verschiedenem Zeichensätzen verwenden oder ihrer Sprache utf-8 als Zeichensatz verwendet) user account prefix setup de Präfix für Benutzernamen usernames are casesensitive setup de Benutzername mit Unterscheidung zwischen Groß- und Kleinschreibung users choice setup de Benutzerauswahl diff --git a/setup/lang/phpgw_en.lang b/setup/lang/phpgw_en.lang index 0d2ce2febd..9b32fdfdb1 100644 --- a/setup/lang/phpgw_en.lang +++ b/setup/lang/phpgw_en.lang @@ -6,6 +6,7 @@ 00 (disable) setup en 00 (disable / recomended) 13 (ntp) setup en 13 (ntp) 80 (http) setup en 80 (http) +charset to use (use utf-8 if you plan to use languages with different charsets): setup en charset to use (use utf-8 if you plan to use languages with different charsets): this will create 1 admin account and 3 demo accounts
the username/passwords are: demo/guest, demo2/guest and demo3/guest. setup en This will create 1 admin account and 3 demo accounts
The username/passwords are: demo/guest, demo2/guest and demo3/guest. accounts existing setup en Accounts existing actions setup en Actions @@ -23,6 +24,7 @@ after backing up your tables first. setup en After backing up your tables first. after retrieving the file, put it into place as the header.inc.php. then, click "continue". setup en After retrieving the file, put it into place as the header.inc.php. Then, click "continue". all applications setup en all applications all core tables and the admin and preferences applications setup en all core tables and the admin and preferences applications +all languages (incl. not listed ones) setup en all languages (incl. not listed ones) all users setup en All Users analysis setup en Analysis and reload your webserver, so the above changes take effect !!! setup en AND reload your webserver, so the above changes take effect !!! @@ -191,8 +193,8 @@ go back setup en Go back go to setup en Go to grant access setup en Grant Access has a version mismatch setup en has a version mismatch +header 0assword setup en Header Password header admin login setup en Header Admin Login -header password setup en Header Password header username setup en Header Username historylog removed setup en Historylog removed hooks deregistered setup en hooks deregistered @@ -355,6 +357,8 @@ safe_mode is turned on, which is generaly a good thing as it makes your install sample configuration not found. using built in defaults setup en Sample configuration not found. using built in defaults save setup en Save save this text as contents of your header.inc.php setup en Save this text as contents of your header.inc.php +schedule setup en schedule +scheduled backups setup en scheduled backups select an app, enter a target version, then submit to process to that version.
if you do not enter a version, only the baseline tables will be installed for the app.
this will drop all of the apps' tables first! setup en Select an app, enter a target version, then submit to process to that version.
If you do not enter a version, only the baseline tables will be installed for the app.
THIS WILL DROP ALL OF THE APPS' TABLES FIRST! select one... setup en select one... select the default applications to which your users will have access setup en Select the default applications to which your users will have access @@ -387,8 +391,6 @@ setup demo accounts in ldap setup en Setup demo accounts in LDAP setup main menu setup en Setup Main Menu setup the database setup en Setup the database setup/config admin login setup en Setup/Config Admin Login -schedule setup en schedule -scheduled backups setup en scheduled backups show 'powered by' logo on setup en Show 'powered by' logo on size setup en size some or all of its tables are missing setup en Some or all of its tables are missing @@ -452,7 +454,6 @@ uploads a backup and installs it on your db setup en uploads a backup and instal uploads a backup to the backup-dir, from where you can restore it setup en uploads a backup to the backup-dir, from where you can restore it use cookies to pass sessionid setup en Use cookies to pass sessionid use pure html compliant code (not fully working yet) setup en Use pure HTML compliant code (not fully working yet) -use utf-8 (unicode) as system-charset (recomended if you use languages with different charsets or your language uses utf-8 as charset) setup en use utf-8 (unicode) as system-charset (recomended if you use languages with different charsets or your language uses utf-8 as charset) user account prefix setup en User account prefix usernames are casesensitive setup en Usernames are casesensitive users choice setup en Users Choice diff --git a/setup/templates/default/setup_db_blocks.tpl b/setup/templates/default/setup_db_blocks.tpl index 936a714a78..1bcf452a8d 100644 --- a/setup/templates/default/setup_db_blocks.tpl +++ b/setup/templates/default/setup_db_blocks.tpl @@ -68,8 +68,8 @@ {dbexists}
+ {lang_system_charset} {system_charset}
{lang_debug}
- {lang_system_charset}
{coreapps}
{lang_restore}