2001-07-30 18:05:42 +02:00
< ? php
/************************************************************************** \
* phpGroupWare - Setup *
* http :// www . phpgroupware . org *
* -------------------------------------------- *
* 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$ */
2002-09-16 01:21:01 +02:00
$phpgw_info = array ();
2003-05-29 09:58:45 +02:00
if ( !@ $included )
2001-07-30 18:05:42 +02:00
{
2002-09-16 01:21:01 +02:00
$GLOBALS [ 'phpgw_info' ][ 'flags' ] = array (
2001-07-30 18:05:42 +02:00
'noheader' => True ,
'nonavbar' => True ,
2001-09-12 16:20:54 +02:00
'currentapp' => 'home' ,
2001-07-30 18:05:42 +02:00
'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
2002-03-03 22:53:00 +01:00
if ( ! $GLOBALS [ 'phpgw_setup' ] -> auth ( 'Config' ))
2001-07-30 18:05:42 +02:00
{
2001-09-12 16:20:54 +02:00
Header ( 'Location: index.php' );
2001-07-30 18:05:42 +02:00
exit ;
}
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> loaddb ();
2002-09-16 01:21:01 +02:00
2001-07-30 18:05:42 +02:00
include ( PHPGW_API_INC . '/class.common.inc.php' );
$common = new common ;
// this is not used
//$sep = $common->filesystem_separator();
}
2003-03-22 02:32:43 +01:00
elseif ( $included != 'from_login' )
2001-07-30 18:05:42 +02:00
{
$newinstall = True ;
$lang_selected [ 'en' ] = 'en' ;
$submit = True ;
}
2003-04-02 19:46:37 +02:00
if ( ! defined ( 'MAX_MESSAGE_ID_LENGTH' ))
{
define ( 'MAX_MESSAGE_ID_LENGTH' , 230 );
}
2003-05-29 09:58:45 +02:00
if ( @ $_POST [ 'submit' ])
2001-07-30 18:05:42 +02:00
{
2003-05-29 09:58:45 +02:00
$lang_selected = @ $_POST [ 'lang_selected' ];
$upgrademethod = @ $_POST [ 'upgrademethod' ];
2003-03-22 02:32:43 +01:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'server' ]) && $upgrademethod != 'dumpold' )
{
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " select * from phpgw_config WHERE config_app='phpgwapi' AND config_name='lang_ctimes' " , __LINE__ , __FILE__ );
if ( $GLOBALS [ 'phpgw_setup' ] -> db -> next_record ())
{
$GLOBALS [ 'phpgw_info' ][ 'server' ][ 'lang_ctimes' ] = unserialize ( stripslashes ( $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 'config_value' )));
}
}
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> transaction_begin ();
2001-07-30 18:05:42 +02:00
if ( count ( $lang_selected ))
{
if ( $upgrademethod == 'dumpold' )
{
2002-11-23 13:32:16 +01:00
// dont delete the custom main- & loginscreen messages every time
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE FROM phpgw_lang where app_name != 'mainscreen' AND app_name != 'loginscreen' " , __LINE__ , __FILE__ );
2001-09-12 16:20:54 +02:00
//echo '<br>Test: dumpold';
2003-03-22 02:32:43 +01:00
$GLOBALS [ 'phpgw_info' ][ 'server' ][ 'lang_ctimes' ] = array ();
2001-07-30 18:05:42 +02:00
}
2003-04-02 19:46:37 +02:00
foreach ( $lang_selected as $lang )
2001-07-30 18:05:42 +02:00
{
//echo '<br>Working on: ' . $lang;
$addlang = False ;
if ( $upgrademethod == 'addonlynew' )
{
2002-10-18 16:44:10 +02:00
//echo "<br>Test: addonlynew - select count(*) from phpgw_lang where lang='".$lang."'";
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " SELECT COUNT(*) FROM phpgw_lang WHERE lang=' " . $lang . " ' " , __LINE__ , __FILE__ );
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> next_record ();
2001-07-30 18:05:42 +02:00
2002-03-03 22:53:00 +01:00
if ( $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 0 ) == 0 )
2001-07-30 18:05:42 +02:00
{
2001-09-12 16:20:54 +02:00
//echo '<br>Test: addonlynew - True';
2001-07-30 18:05:42 +02:00
$addlang = True ;
}
}
if (( $addlang && $upgrademethod == 'addonlynew' ) || ( $upgrademethod != 'addonlynew' ))
{
//echo '<br>Test: loop above file()';
2002-10-18 16:44:10 +02:00
$setup_info = $GLOBALS [ 'phpgw_setup' ] -> detection -> get_versions ();
$setup_info = $GLOBALS [ 'phpgw_setup' ] -> detection -> get_db_versions ( $setup_info );
2003-04-02 19:46:37 +02:00
$raw = array ();
// Visit each app/setup dir, look for a phpgw_lang file
2001-07-30 18:05:42 +02:00
while ( list ( $key , $app ) = each ( $setup_info ))
{
2003-05-29 09:58:45 +02:00
$appfile = PHPGW_SERVER_ROOT . SEP . @ $app [ 'name' ] . SEP . 'setup' . SEP . 'phpgw_' . strtolower ( $lang ) . '.lang' ;
2001-07-30 18:05:42 +02:00
//echo '<br>Checking in: ' . $app['name'];
2003-05-29 09:58:45 +02:00
if ( $GLOBALS [ 'phpgw_setup' ] -> app_registered ( @ $app [ 'name' ]) && file_exists ( $appfile ))
2001-07-30 18:05:42 +02:00
{
//echo '<br>Including: ' . $appfile;
2003-04-02 19:46:37 +02:00
$lines = file ( $appfile );
foreach ( $lines as $line )
{
list ( $message_id , $app_name ,, $content ) = explode ( " \t " , $line );
2003-09-23 15:08:40 +02:00
$message_id = $GLOBALS [ 'phpgw_setup' ] -> db -> db_addslashes ( substr ( strtolower ( chop ( $message_id )), 0 , MAX_MESSAGE_ID_LENGTH ));
2003-04-02 19:46:37 +02:00
$app_name = $GLOBALS [ 'phpgw_setup' ] -> db -> db_addslashes ( chop ( $app_name ));
$content = $GLOBALS [ 'phpgw_setup' ] -> db -> db_addslashes ( chop ( $content ));
$raw [ $app_name ][ $message_id ] = $content ;
}
2003-03-22 02:32:43 +01:00
$GLOBALS [ 'phpgw_info' ][ 'server' ][ 'lang_ctimes' ][ $lang ][ $app [ 'name' ]] = filectime ( $appfile );
2001-07-30 18:05:42 +02:00
}
}
2003-04-02 19:46:37 +02:00
foreach ( $raw as $app_name => $ids )
2001-07-30 18:05:42 +02:00
{
2003-04-02 19:46:37 +02:00
foreach ( $ids as $message_id => $content )
2001-07-30 18:05:42 +02:00
{
$addit = False ;
//echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id;
2003-03-22 02:32:43 +01:00
if ( $upgrademethod == 'addmissing' )
2001-07-30 18:05:42 +02:00
{
2001-09-12 16:20:54 +02:00
//echo '<br>Test: addmissing';
2003-09-23 15:08:40 +02:00
$GLOBALS [ 'phpgw_setup' ] -> 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__ );
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> next_record ();
2001-07-30 18:05:42 +02:00
2002-03-03 22:53:00 +01:00
if ( $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 0 ) == 0 )
2001-07-30 18:05:42 +02:00
{
2002-03-03 22:53:00 +01:00
//echo '<br>Test: addmissing - True - Total: ' . $GLOBALS['phpgw_setup']->db->f(0);
2001-07-30 18:05:42 +02:00
$addit = True ;
}
}
2003-05-29 09:58:45 +02:00
if ( $addit || @ $newinstall || $upgrademethod == 'addonlynew' || $upgrademethod == 'dumpold' )
2001-07-30 18:05:42 +02:00
{
if ( $message_id && $content )
{
2003-04-02 19:46:37 +02:00
//echo "<br>adding - insert into phpgw_lang values ('$message_id','$app_name','$lang','$content')";
$result = $GLOBALS [ 'phpgw_setup' ] -> db -> query ( " INSERT INTO phpgw_lang (message_id,app_name,lang,content) VALUES(' $message_id ',' $app_name ',' $lang ',' $content ') " , __LINE__ , __FILE__ );
2002-09-16 01:21:01 +02:00
if ( intval ( $result ) <= 0 )
{
2003-04-02 19:46:37 +02:00
echo " <br>Error inserting record: phpgw_lang values (' $message_id ',' $app_name ',' $lang ',' $content ') " ;
2002-09-16 01:21:01 +02:00
}
2001-07-30 18:05:42 +02:00
}
}
}
}
}
}
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> transaction_commit ();
2003-03-22 02:32:43 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE from phpgw_config WHERE config_app='phpgwapi' AND config_name='lang_ctimes' " , __LINE__ , __FILE__ );
$GLOBALS [ 'phpgw_setup' ] -> 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__ );
2001-07-30 18:05:42 +02:00
}
2003-05-29 09:58:45 +02:00
if ( !@ $included )
2001-07-30 18:05:42 +02:00
{
2001-09-12 16:20:54 +02:00
Header ( 'Location: index.php' );
2001-07-30 18:05:42 +02:00
exit ;
}
}
else
{
2003-05-29 09:58:45 +02:00
if ( @ $_POST [ 'cancel' ])
2001-07-30 18:05:42 +02:00
{
2001-09-12 16:20:54 +02:00
Header ( 'Location: index.php' );
2001-07-30 18:05:42 +02:00
exit ;
}
2003-05-29 09:58:45 +02:00
if ( !@ $included )
2001-07-30 18:05:42 +02:00
{
2002-10-18 16:44:10 +02:00
$tpl_root = $GLOBALS [ 'phpgw_setup' ] -> html -> setup_tpl_dir ( 'setup' );
2002-09-16 01:21:01 +02:00
$setup_tpl = CreateObject ( 'phpgwapi.Template' , $tpl_root );
2001-07-30 18:05:42 +02:00
$setup_tpl -> set_file ( array (
'T_head' => 'head.tpl' ,
'T_footer' => 'footer.tpl' ,
'T_alert_msg' => 'msg_alert_msg.tpl' ,
'T_lang_main' => 'lang_main.tpl'
));
$setup_tpl -> set_block ( 'T_lang_main' , 'B_choose_method' , 'V_choose_method' );
$stage_title = lang ( 'Multi-Language support setup' );
2001-09-12 16:20:54 +02:00
$stage_desc = lang ( 'This program will help you upgrade or install different languages for phpGroupWare' );
2003-05-29 09:58:45 +02:00
$tbl_width = @ $newinstall ? '60%' : '80%' ;
$td_colspan = @ $newinstall ? '1' : '2' ;
$td_align = @ $newinstall ? ' align="center"' : '' ;
$hidden_var1 = @ $newinstall ? '<input type="hidden" name="newinstall" value="True">' : '' ;
2001-07-30 18:05:42 +02:00
2003-05-29 09:58:45 +02:00
if ( !@ $newinstall && ! isset ( $GLOBALS [ 'phpgw_info' ][ 'setup' ][ 'installed_langs' ]))
2003-03-22 02:32:43 +01:00
{
$GLOBALS [ 'phpgw_setup' ] -> detection -> check_lang ( false ); // get installed langs
}
2001-07-30 18:05:42 +02:00
$select_box_desc = lang ( 'Select which languages you would like to use' );
2002-09-16 01:21:01 +02:00
$select_box = '' ;
2003-09-23 15:08:40 +02:00
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( $q = " SELECT lang_id,lang_name FROM phpgw_languages WHERE available='Yes' ORDER BY lang_name " );
2002-03-03 22:53:00 +01:00
while ( $GLOBALS [ 'phpgw_setup' ] -> db -> next_record ())
2001-07-30 18:05:42 +02:00
{
2003-03-22 02:32:43 +01:00
$id = $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 'lang_id' );
2002-09-16 01:21:01 +02:00
$select_box_langs =
2003-05-29 09:58:45 +02:00
@ $select_box_langs
2003-03-22 02:32:43 +01:00
. '<option value="' . $id . '"'
2003-05-29 09:58:45 +02:00
. ( @ $GLOBALS [ 'phpgw_info' ][ 'setup' ][ 'installed_langs' ][ $id ] ? ' SELECTED' : '' ) . '>'
2002-09-16 01:21:01 +02:00
. $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 'lang_name' ) . '</option>'
. " \n " ;
2001-07-30 18:05:42 +02:00
}
2003-05-29 09:58:45 +02:00
if ( !@ $newinstall )
2001-07-30 18:05:42 +02:00
{
$meth_desc = lang ( 'Select which method of upgrade you would like to do' );
$blurb_addonlynew = lang ( 'Only add languages that are not in the database already' );
$blurb_addmissing = lang ( 'Only add new phrases' );
$blurb_dumpold = lang ( 'Delete all old languages and install new ones' );
$setup_tpl -> set_var ( 'meth_desc' , $meth_desc );
$setup_tpl -> set_var ( 'blurb_addonlynew' , $blurb_addonlynew );
$setup_tpl -> set_var ( 'blurb_addmissing' , $blurb_addmissing );
$setup_tpl -> set_var ( 'blurb_dumpold' , $blurb_dumpold );
$setup_tpl -> parse ( 'V_choose_method' , 'B_choose_method' );
}
else
{
$setup_tpl -> set_var ( 'V_choose_method' , '' );
}
$setup_tpl -> set_var ( 'stage_title' , $stage_title );
$setup_tpl -> set_var ( 'stage_desc' , $stage_desc );
$setup_tpl -> set_var ( 'tbl_width' , $tbl_width );
$setup_tpl -> set_var ( 'td_colspan' , $td_colspan );
$setup_tpl -> set_var ( 'td_align' , $td_align );
$setup_tpl -> set_var ( 'hidden_var1' , $hidden_var1 );
$setup_tpl -> set_var ( 'select_box_desc' , $select_box_desc );
$setup_tpl -> set_var ( 'select_box_langs' , $select_box_langs );
$setup_tpl -> set_var ( 'lang_install' , lang ( 'install' ));
$setup_tpl -> set_var ( 'lang_cancel' , lang ( 'cancel' ));
2003-05-29 09:58:45 +02:00
$ConfigDomain = $GLOBALS [ 'HTTP_COOKIE_VARS' ][ 'ConfigDomain' ] ? $GLOBALS [ 'HTTP_COOKIE_VARS' ][ 'ConfigDomain' ] : $_POST [ 'ConfigDomain' ];
2002-10-18 16:44:10 +02:00
$GLOBALS [ 'phpgw_setup' ] -> html -> show_header ( " $stage_title " , False , 'config' , $ConfigDomain . '(' . $phpgw_domain [ $ConfigDomain ][ 'db_type' ] . ')' );
2001-07-30 18:05:42 +02:00
$setup_tpl -> pparse ( 'out' , 'T_lang_main' );
2002-10-18 16:44:10 +02:00
$GLOBALS [ 'phpgw_setup' ] -> html -> show_footer ();
2001-07-30 18:05:42 +02:00
}
}
?>