From: <ral...@us...> - 2003-10-04 13:23:17
|
Update of /cvsroot/egroupware/phpgwapi/inc In directory sc8-pr-cvs1:/tmp/cvs-serv8625 Modified Files: class.setup_process.inc.php class.setup_translation.inc.php class.translation_sql.inc.php Log Message: restructured setup a bit: - move most of the lang-code from setup/lang.php to phpgwapi/inc/class.translation_sql.inc.php - added a minimal-auto-configuration, so one does not need to enter the config-step at all for a running installation - added the language of the admin to the installed languages Index: class.setup_process.inc.php =================================================================== RCS file: /cvsroot/egroupware/phpgwapi/inc/class.setup_process.inc.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** class.setup_process.inc.php 27 Mar 2003 18:39:49 -0000 1.8 --- class.setup_process.inc.php 4 Oct 2003 13:23:13 -0000 1.9 *************** *** 118,122 **** $passing = $this->current($pass,$DEBUG); $passing = $this->default_records($passing,$DEBUG); ! $passing = $this->add_langs($passing,$DEBUG,$force_en); break; case 'upgrade': --- 118,124 ---- $passing = $this->current($pass,$DEBUG); $passing = $this->default_records($passing,$DEBUG); ! $my_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2); ! $passing = $this->add_langs($passing,$DEBUG,array($my_lang,'en')); ! $this->save_minimal_config(); break; case 'upgrade': *************** *** 183,186 **** --- 185,226 ---- /*! + @function save_minimal_config + @abstract saves a minimal default config, so you get a running install without entering and saveing Step #2 config + */ + function save_minimal_config() + { + $GLOBALS['current_config']['site_title'] = 'eGroupWare'; + $GLOBALS['current_config']['hostname'] = $_SERVER['HTTP_HOST']; + // files-dir is not longer allowed in document root, for security reasons !!! + $GLOBALS['current_config']['files_dir'] = '/outside/webserver/docroot'; + + if(@is_dir('/tmp')) + { + $GLOBALS['current_config']['temp_dir'] = '/tmp'; + } + else + { + $GLOBALS['current_config']['temp_dir'] = '/path/to/temp/dir'; + } + // guessing the phpGW url + $parts = explode('/',$_SERVER['PHP_SELF']); + array_pop($parts); // remove config.php + array_pop($parts); // remove setup + $GLOBALS['current_config']['webserver_url'] = implode('/',$parts); + + $datetime = CreateObject('phpgwapi.datetime'); + $GLOBALS['current_config']['tz_offset'] = $datetime->getbestguess(); + unset($datetime); + + foreach($GLOBALS['current_config'] as $setting => $value) + { + $setting = $GLOBALS['phpgw_setup']->db->db_addslashes($setting); + $value = $GLOBALS['phpgw_setup']->db->db_addslashes($value); + @$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='$setting'",__LINE__,__FILE__); + $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_config (config_app,config_name, config_value) VALUES ('phpgwapi','$setting','$value')"); + } + } + + /*! @function droptables @abstract drop tables per application, check that they are in the db first *************** *** 351,355 **** @param $setup_info array of application info from setup.inc.php files, etc. */ ! function add_langs($setup_info,$DEBUG=False,$force_en=False) { @reset($setup_info); --- 391,395 ---- @param $setup_info array of application info from setup.inc.php files, etc. */ ! function add_langs($setup_info,$DEBUG=False,$force_langs=False) { @reset($setup_info); *************** *** 357,361 **** { $appname = $setup_info[$key]['name']; ! $this->translation->add_langs($appname,$DEBUG,$force_en); if($DEBUG) { --- 397,401 ---- { $appname = $setup_info[$key]['name']; ! $this->translation->add_langs($appname,$DEBUG,$force_langs); if($DEBUG) { Index: class.setup_translation.inc.php =================================================================== RCS file: /cvsroot/egroupware/phpgwapi/inc/class.setup_translation.inc.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** class.setup_translation.inc.php 23 Sep 2003 13:06:12 -0000 1.5 --- class.setup_translation.inc.php 4 Oct 2003 13:23:13 -0000 1.6 *************** *** 165,174 **** @param $appname app_name of application to process */ ! function add_langs($appname,$DEBUG=False,$force_en=False) { $langs = $this->get_langs($DEBUG); ! if($force_en && !@in_array('en',$langs)) { ! $langs[] = 'en'; } --- 165,180 ---- @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; ! } ! } } Index: class.translation_sql.inc.php =================================================================== RCS file: /cvsroot/egroupware/phpgwapi/inc/class.translation_sql.inc.php,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** class.translation_sql.inc.php 23 Sep 2003 21:26:58 -0000 1.21 --- class.translation_sql.inc.php 4 Oct 2003 13:23:13 -0000 1.22 *************** *** 25,32 **** /* $Id$ */ ! // define the maximal length of a message_id, all message_ids have to be unique // in this length, our column is varchar 255, but addslashes might add some length ! define('MAX_MESSAGE_ID_LENGTH',230); ! class translation { --- 25,35 ---- /* $Id$ */ ! // define the maximal length of a message_id, all message_ids have to be unique // in this length, our column is varchar 255, but addslashes might add some length ! if (!defined('MAX_MESSAGE_ID_LENGTH')) ! { ! define('MAX_MESSAGE_ID_LENGTH',230); ! } ! class translation { *************** *** 34,37 **** --- 37,45 ---- var $loaded_apps = array(); + function translation() + { + $this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db; + } + function init() { *************** *** 57,60 **** --- 65,73 ---- } + /*! + @function translate + @abstract translates a phrase and evtl. substitute some variables + @returns the translation + */ function translate($key, $vars=false ) { *************** *** 84,87 **** --- 97,107 ---- } + /*! + @function add_app + @abstract adds translations for an application from the database to the lang-array + @syntax add_app($app,$lang=False) + @param $app name of the application to add (or 'common' for the general translations) + @param $lang 2-char code of the language to use or False if the users language should be used + */ function add_app($app,$lang=False) { *************** *** 91,98 **** { $sql = "select message_id,content from phpgw_lang where lang='".$lang."' and app_name='".$app."'"; ! $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__); ! while ($GLOBALS['phpgw']->db->next_record()) { ! $GLOBALS['lang'][strtolower ($GLOBALS['phpgw']->db->f('message_id'))] = $GLOBALS['phpgw']->db->f('content'); } $this->loaded_apps[$app] = $lang; --- 111,118 ---- { $sql = "select message_id,content from phpgw_lang where lang='".$lang."' and app_name='".$app."'"; ! $this->db->query($sql,__LINE__,__FILE__); ! while ($this->db->next_record()) { ! $GLOBALS['lang'][strtolower ($this->db->f('message_id'))] = $this->db->f('content'); } $this->loaded_apps[$app] = $lang; *************** *** 100,118 **** } function get_installed_langs() { if (!is_array($this->langs)) { ! $GLOBALS['phpgw']->db->query("SELECT DISTINCT l.lang,ln.lang_name FROM phpgw_lang l,phpgw_languages ln WHERE l.lang = ln.lang_id",__LINE__,__FILE__); ! if (!$GLOBALS['phpgw']->db->num_rows()) { return False; } ! while ($GLOBALS['phpgw']->db->next_record()) { ! $this->langs[$GLOBALS['phpgw']->db->f('lang')] = $GLOBALS['phpgw']->db->f('lang_name'); } } return $this->langs; } } --- 120,328 ---- } + /*! + @function get_installed_langs + @abstract returns a list of installed langs + @returns array with 2-character lang-code as key and descriptiv lang-name as data + */ function get_installed_langs() { if (!is_array($this->langs)) { ! $this->db->query("SELECT DISTINCT l.lang,ln.lang_name FROM phpgw_lang l,phpgw_languages ln WHERE l.lang = ln.lang_id",__LINE__,__FILE__); ! if (!$this->db->num_rows()) { return False; } ! while ($this->db->next_record()) { ! $this->langs[$this->db->f('lang')] = $this->db->f('lang_name'); } } return $this->langs; + } + + /*! + @function get_installed_charsets + @abstract returns a list of installed charsets + @returns array with charset as key and comma-separated list of langs useing the charset as data + */ + function get_installed_charsets() + { + if (!is_array($this->charsets)) + { + $this->db->query("SELECT DISTINCT l.lang,ln.lang_name,l.content AS charset FROM phpgw_lang l,phpgw_languages ln WHERE l.lang = ln.lang_id AND l.message_id='charset'",__LINE__,__FILE__); + if (!$this->db->num_rows()) + { + return False; + } + while ($this->db->next_record()) + { + $data = &$this->charsets[$charset = $this->db->f('charset')]; + $data .= ($data ? ', ' : $charset.': '). + $this->db->f('lang_name').' ('.$this->db->f('lang').')'; + } + } + return $this->charsets; + } + + /*! + @function install_langs + @abstract installs translations for the selected langs into the database + @syntax install_langs($langs,$upgrademethod='dumpold') + @param $langs array of langs to install (as data NOT keys (!)) + @param $upgrademethod 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases + */ + function install_langs($langs,$upgrademethod='dumpold') + { + @set_time_limit(0); // we might need some time + + if (!isset($GLOBALS['phpgw_info']['server']) && $upgrademethod != 'dumpold') + { + $this->db->query("select * from phpgw_config WHERE config_app='phpgwapi' AND config_name='lang_ctimes'",__LINE__,__FILE__); + if ($this->db->next_record()) + { + $GLOBALS['phpgw_info']['server']['lang_ctimes'] = unserialize(stripslashes($this->db->f('config_value'))); + } + } + + if (!is_array($langs) || !count($langs)) + { + return; + } + $this->db->transaction_begin(); + + if ($upgrademethod == 'dumpold') + { + // dont delete the custom main- & loginscreen messages every time + $this->db->query("DELETE FROM phpgw_lang where app_name != 'mainscreen' AND app_name != 'loginscreen'",__LINE__,__FILE__); + //echo '<br>Test: dumpold'; + $GLOBALS['phpgw_info']['server']['lang_ctimes'] = array(); + } + foreach($langs as $lang) + { + //echo '<br>Working on: ' . $lang; + $addlang = False; + if ($upgrademethod == 'addonlynew') + { + //echo "<br>Test: addonlynew - select count(*) from phpgw_lang where lang='".$lang."'"; + $this->db->query("SELECT COUNT(*) FROM phpgw_lang WHERE lang='".$lang."'",__LINE__,__FILE__); + $this->db->next_record(); + + if ($this->db->f(0) == 0) + { + //echo '<br>Test: addonlynew - True'; + $addlang = True; + } + } + if (($addlang && $upgrademethod == 'addonlynew') || ($upgrademethod != 'addonlynew')) + { + //echo '<br>Test: loop above file()'; + if (!is_object($GLOBALS['phpgw_setup'])) + { + $GLOBALS['phpgw_setup'] = CreateObject('phpgwapi.setup'); + $GLOBALS['phpgw_setup']->db = $this->db; + } + $setup_info = $GLOBALS['phpgw_setup']->detection->get_versions(); + $setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions($setup_info); + $raw = array(); + // Visit each app/setup dir, look for a phpgw_lang file + foreach($setup_info as $key => $app) + { + $appfile = PHPGW_SERVER_ROOT . SEP . @$app['name'] . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang'; + //echo '<br>Checking in: ' . $app['name']; + if($GLOBALS['phpgw_setup']->app_registered(@$app['name']) && file_exists($appfile)) + { + //echo '<br>Including: ' . $appfile; + $lines = file($appfile); + foreach($lines as $line) + { + list($message_id,$app_name,,$content) = explode("\t",$line); + $message_id = $this->db->db_addslashes(substr(strtolower(chop($message_id)),0,MAX_MESSAGE_ID_LENGTH)); + $app_name = $this->db->db_addslashes(chop($app_name)); + $content = $this->db->db_addslashes(chop($content)); + + $raw[$app_name][$message_id] = $content; + } + $GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang][$app['name']] = filectime($appfile); + } + } + foreach($raw as $app_name => $ids) + { + foreach($ids as $message_id => $content) + { + $addit = False; + //echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id; + if ($upgrademethod == 'addmissing') + { + //echo '<br>Test: addmissing'; + $this->db->query("SELECT COUNT(*) FROM phpgw_lang WHERE message_id='$message_id' AND lang='$lang' AND (app_name='$app_name' OR app_name='common') AND content='$content'",__LINE__,__FILE__); + $this->db->next_record(); + + if ($this->db->f(0) == 0) + { + //echo '<br>Test: addmissing - True - Total: ' . $this->db->f(0); + $addit = True; + } + } + + if ($addit || $upgrademethod == 'addonlynew' || $upgrademethod == 'dumpold') + { + if($message_id && $content) + { + //echo "<br>adding - insert into phpgw_lang values ('$message_id','$app_name','$lang','$content')"; + $result = $this->db->query("INSERT INTO phpgw_lang (message_id,app_name,lang,content) VALUES('$message_id','$app_name','$lang','$content')",__LINE__,__FILE__); + if (intval($result) <= 0) + { + echo "<br>Error inserting record: phpgw_lang values ('$message_id','$app_name','$lang','$content')"; + } + } + } + } + } + } + } + $this->db->transaction_commit(); + + // update the ctimes of the installed langsfiles for the autoloading of the lang-files + // + $this->db->query("DELETE from phpgw_config WHERE config_app='phpgwapi' AND config_name='lang_ctimes'",__LINE__,__FILE__); + $this->db->query($query="INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES ('phpgwapi','lang_ctimes','". + addslashes(serialize($GLOBALS['phpgw_info']['server']['lang_ctimes']))."')",__LINE__,__FILE__); + } + + /*! + @function autolaod_changed_langfiles + @abstract re-loads all (!) langfiles if one langfile for the an app and the language of the user has changed + */ + function autoload_changed_langfiles() + { + //echo "<h1>check_langs()</h1>\n"; + if ($GLOBALS['phpgw_info']['server']['lang_ctimes'] && !is_array($GLOBALS['phpgw_info']['server']['lang_ctimes'])) + { + $GLOBALS['phpgw_info']['server']['lang_ctimes'] = unserialize($GLOBALS['phpgw_info']['server']['lang_ctimes']); + } + //_debug_array($GLOBALS['phpgw_info']['server']['lang_ctimes']); + + $lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; + $apps = $GLOBALS['phpgw_info']['user']['apps']; + $apps['phpgwapi'] = True; // check the api too + foreach($apps as $app => $data) + { + $fname = PHPGW_SERVER_ROOT . "/$app/setup/phpgw_$lang.lang"; + + if (file_exists($fname)) + { + $ctime = filectime($fname); + $ltime = intval($GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang][$app]); + //echo "checking lang='$lang', app='$app', ctime='$ctime', ltime='$ltime'<br>\n"; + + if ($ctime != $ltime) + { + // update all langs + $this->install_langs(array_keys($this->get_installed_langs())); + break; + } + } + } } } |