2001-07-30 17:59:25 +02:00
< ? php
/************************************************************************** \
2004-01-27 21:49:25 +01:00
* eGroupWare - Setup - Developer tools *
* http :// www . egroupware . org *
2001-07-30 17:59:25 +02:00
* -------------------------------------------- *
* 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-02-18 17:18:34 +01:00
$GLOBALS [ 'DEBUG' ] = True ;
2001-12-18 03:25:55 +01:00
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'egw_info' ] = array (
'flags' => array (
'noheader' => True ,
'nonavbar' => True ,
'currentapp' => 'home' ,
'noapi' => True
));
2007-02-14 15:08:55 +01:00
include ( './inc/functions.inc.php' );
2001-07-30 17:59:25 +02:00
2001-12-18 03:20:31 +01:00
// Check header and authentication
2007-02-14 15:08:55 +01:00
if ( ! $GLOBALS [ 'egw_setup' ] -> auth ( 'Config' ))
2001-12-18 03:20:31 +01:00
{
Header ( 'Location: index.php' );
exit ;
}
// Does not return unless user is authorized
2005-03-04 13:40:28 +01:00
$tpl_root = $GLOBALS [ 'egw_setup' ] -> html -> setup_tpl_dir ( 'setup' );
2007-12-09 09:03:56 +01:00
$GLOBALS [ 'setup_tpl' ] = CreateObject ( 'phpgwapi.Template' , $tpl_root );
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_file ( array (
2001-07-30 17:59:25 +02:00
'T_head' => 'head.tpl' ,
'T_footer' => 'footer.tpl' ,
'T_alert_msg' => 'msg_alert_msg.tpl' ,
'T_login_main' => 'login_main.tpl' ,
'T_login_stage_header' => 'login_stage_header.tpl' ,
'T_setup_main' => 'schema.tpl'
));
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_login_stage_header' , 'B_multi_domain' , 'V_multi_domain' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_login_stage_header' , 'B_single_domain' , 'V_single_domain' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'header' , 'header' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'app_header' , 'app_header' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'apps' , 'apps' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( ' T_setup_main ',' detail ',' detail ' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'table' , 'table' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'hook' , 'hook' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'dep' , 'dep' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'app_footer' , 'app_footer' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'submit' , 'submit' );
$GLOBALS [ 'setup_tpl' ] -> set_block ( 'T_setup_main' , 'footer' , 'footer' );
2001-07-30 17:59:25 +02:00
$bgcolor = array ( 'DDDDDD' , 'EEEEEE' );
function parsedep ( $depends , $main = True )
{
$depstring = '(' ;
2007-02-14 15:08:55 +01:00
foreach ( $depends as $a => $b )
2001-07-30 17:59:25 +02:00
{
2007-02-14 15:08:55 +01:00
foreach ( $b as $c => $d )
2001-07-30 17:59:25 +02:00
{
2007-02-14 15:08:55 +01:00
if ( is_array ( $d ))
2001-07-30 17:59:25 +02:00
{
$depstring .= $c . ': ' . implode ( ',' , $d ) . '; ' ;
$depver [] = $d ;
}
else
{
$depstring .= $c . ': ' . $d . '; ' ;
$depapp [] = $d ;
}
}
}
$depstring .= ')' ;
2007-02-14 15:08:55 +01:00
if ( $main )
2001-07-30 17:59:25 +02:00
{
return $depstring ;
}
else
{
return array ( $depapp , $depver );
}
}
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'egw_setup' ] -> loaddb ();
$GLOBALS [ 'egw_info' ][ 'setup' ][ 'stage' ][ 'db' ] = $GLOBALS [ 'egw_setup' ] -> detection -> check_db ();
2001-07-30 17:59:25 +02:00
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'setup_info' ] = $GLOBALS [ 'egw_setup' ] -> detection -> get_versions ();
2001-11-21 16:01:43 +01:00
//var_dump($GLOBALS['setup_info']);exit;
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'setup_info' ] = $GLOBALS [ 'egw_setup' ] -> detection -> get_db_versions ( $GLOBALS [ 'setup_info' ]);
2001-11-21 16:01:43 +01:00
//var_dump($GLOBALS['setup_info']);exit;
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'setup_info' ] = $GLOBALS [ 'egw_setup' ] -> detection -> compare_versions ( $GLOBALS [ 'setup_info' ]);
2001-11-21 16:01:43 +01:00
//var_dump($GLOBALS['setup_info']);exit;
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'setup_info' ] = $GLOBALS [ 'egw_setup' ] -> detection -> check_depends ( $GLOBALS [ 'setup_info' ]);
2001-11-21 16:01:43 +01:00
//var_dump($GLOBALS['setup_info']);exit;
@ ksort ( $GLOBALS [ 'setup_info' ]);
2001-07-30 17:59:25 +02:00
2016-05-03 00:26:40 +02:00
if ( $_POST [ 'cancel' ])
2001-07-30 17:59:25 +02:00
{
2001-11-21 16:01:43 +01:00
Header ( 'Location: index.php' );
2001-07-30 17:59:25 +02:00
exit ;
}
2007-02-14 15:08:55 +01:00
$GLOBALS [ 'egw_setup' ] -> html -> show_header ( lang ( " Developers' Table Schema Toy " ), False , 'config' , $GLOBALS [ 'egw_setup' ] -> ConfigDomain );
2001-07-30 17:59:25 +02:00
2016-05-03 00:26:40 +02:00
if ( $_POST [ 'submit' ])
2001-07-30 17:59:25 +02:00
{
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'description' , lang ( 'App process' ) . ':' );
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'header' );
2001-07-30 17:59:25 +02:00
2016-05-03 00:26:40 +02:00
$appname = $_POST [ 'appname' ];
$install = $_POST [ 'install' ];
$version = $_POST [ 'version' ];
2001-10-17 20:10:17 +02:00
2007-02-14 15:08:55 +01:00
foreach ( $install as $appname => $key )
2001-07-30 17:59:25 +02:00
{
$terror = array ();
$terror [ $appname ][ 'name' ] = $appname ;
$terror [ $appname ][ 'version' ] = $version [ $appname ];
$terror [ $appname ][ 'status' ] = 'U' ;
2016-05-03 00:26:40 +02:00
$appdir = EGW_SERVER_ROOT . '/' . $appname . '/setup/' ;
2001-07-30 17:59:25 +02:00
// Drop newest tables
2001-11-21 16:01:43 +01:00
$terror [ $appname ][ 'tables' ] = $GLOBALS [ 'setup_info' ][ $appname ][ 'tables' ];
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'egw_setup' ] -> process -> droptables ( $terror , $GLOBALS [ 'DEBUG' ]);
2001-07-30 17:59:25 +02:00
$terror [ $appname ][ 'tables' ] = array ();
// Reset tables field to baseline table names
2007-02-14 15:08:55 +01:00
if ( file_exists ( $appdir . 'tables_baseline.inc.php' ))
2001-07-30 17:59:25 +02:00
{
include ( $appdir . 'tables_baseline.inc.php' );
2007-02-14 15:08:55 +01:00
foreach ( $phpgw_baseline as $table => $null )
2001-07-30 17:59:25 +02:00
{
$terror [ $appname ][ 'tables' ][] = $table ;
2005-07-11 20:02:19 +02:00
echo '<br />Adding app table: ' . $table ;
2001-07-30 17:59:25 +02:00
}
}
if ( $version [ $appname ])
{
2005-07-11 20:02:19 +02:00
echo '<br />Processing ' . $terror [ $appname ][ 'name' ] . ' to ' . $version [ $appname ];
2001-07-30 17:59:25 +02:00
2005-03-04 13:40:28 +01:00
$terror = $GLOBALS [ 'egw_setup' ] -> process -> droptables ( $terror , $GLOBALS [ 'DEBUG' ]);
$GLOBALS [ 'egw_setup' ] -> deregister_app ( $terror [ $appname ][ 'name' ]);
2001-07-30 17:59:25 +02:00
2005-03-04 13:40:28 +01:00
$terror = $GLOBALS [ 'egw_setup' ] -> process -> baseline ( $terror , $GLOBALS [ 'DEBUG' ]);
$terror = $GLOBALS [ 'egw_setup' ] -> process -> test_data ( $terror , $GLOBALS [ 'DEBUG' ]);
2001-07-30 17:59:25 +02:00
2005-03-04 13:40:28 +01:00
$terror = $GLOBALS [ 'egw_setup' ] -> process -> upgrade ( $terror , $GLOBALS [ 'DEBUG' ]);
2003-12-17 13:11:38 +01:00
$terror [ $appname ][ 'version' ] = $version [ $appname ];
2001-07-30 17:59:25 +02:00
}
else
{
2005-07-11 20:02:19 +02:00
echo '<br />Baseline-only completed for ' . $terror [ $appname ][ 'name' ];
2001-07-30 17:59:25 +02:00
}
2005-07-11 20:02:19 +02:00
echo '<br />' . $GLOBALS [ 'setup_info' ][ $appname ][ 'title' ] . ' '
2001-07-30 17:59:25 +02:00
. lang ( 'tables installed, unless there are errors printed above' ) . '.' ;
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_info' ][ $appname ][ 'version' ] = $terror [ $appname ][ 'version' ];
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'egw_setup' ] -> register_app ( $appname );
2005-07-11 20:02:19 +02:00
echo '<br />' . $terror [ $appname ][ 'title' ] . ' ' . lang ( 'registered' ) . '.' ;
2001-07-30 17:59:25 +02:00
}
2005-07-11 20:02:19 +02:00
echo '<br /><a href="schematoy.php">' . lang ( 'Go back' ) . '</a>' ;
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'footer' );
2001-07-30 17:59:25 +02:00
exit ;
}
2016-05-03 00:26:40 +02:00
$detail = $_REQUEST [ 'detail' ];
2002-04-29 21:49:24 +02:00
if ( $detail )
2001-07-30 17:59:25 +02:00
{
2001-11-21 16:01:43 +01:00
@ ksort ( $GLOBALS [ 'setup_info' ][ $detail ]);
@ reset ( $GLOBALS [ 'setup_info' ][ $detail ]);
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'description' , lang ( 'App details' ) . ':' );
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'header' );
2005-09-03 20:20:11 +02:00
2007-02-14 15:08:55 +01:00
foreach ( $GLOBALS [ 'setup_info' ][ $detail ] as $key => $val )
2001-07-30 17:59:25 +02:00
{
2007-02-14 15:08:55 +01:00
$i = $i ? 0 : 1 ;
2001-07-30 17:59:25 +02:00
//if(!$val) { $val = 'none'; }
2007-02-14 15:08:55 +01:00
if ( $key == 'tables' )
2001-07-30 17:59:25 +02:00
{
if ( is_array ( $val ))
{
$key = '<a href="sqltoarray.php?appname=' . $detail . '&submit=True">' . $key . '</a>' . " \n " ;
$val = implode ( ',' , $val );
}
}
2007-02-14 15:08:55 +01:00
if ( $key == 'hooks' )
{
$val = implode ( ',' , $val );
}
if ( $key == 'depends' )
{
$val = parsedep ( $val );
}
if ( is_array ( $val ))
{
$val = implode ( ',' , $val );
}
2001-07-30 17:59:25 +02:00
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'bg_color' , $bgcolor [ $i ]);
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'name' , $key );
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'details' , $val );
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'detail' );
2001-07-30 17:59:25 +02:00
}
2005-07-11 20:02:19 +02:00
echo '<br /><a href="schematoy.php">' . lang ( 'Go back' ) . '</a>' ;
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'footer' );
2001-07-30 17:59:25 +02:00
exit ;
}
else
{
2005-07-11 20:02:19 +02:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'description' , lang ( " Select an app, enter a target version, then submit to process to that version.<br />If you do not enter a version, only the baseline tables will be installed for the app.<br /><blink>THIS WILL DROP ALL OF THE APPS' TABLES FIRST!</blink> " ));
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'header' );
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'appdata' , lang ( 'Application Data' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'actions' , lang ( 'Actions' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'action_url' , 'schematoy.php' );
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'app_info' , lang ( 'Application Name and Status' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'app_title' , lang ( 'Application Title' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'app_version' , lang ( 'Target Version' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'app_install' , lang ( 'Process' ));
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'app_header' );
2007-02-14 15:08:55 +01:00
foreach ( $GLOBALS [ 'setup_info' ] as $key => $value )
2001-07-30 17:59:25 +02:00
{
2001-08-08 10:41:28 +02:00
unset ( $test );
2007-02-14 15:08:55 +01:00
if ( file_exists ( EGW_SERVER_ROOT . '/' . $value [ 'name' ] . '/setup/tables_update.inc.php' ))
2001-08-08 10:41:28 +02:00
{
2005-09-03 20:20:11 +02:00
include ( EGW_SERVER_ROOT . '/' . $value [ 'name' ] . '/setup/tables_update.inc.php' );
2001-08-08 10:41:28 +02:00
2007-02-14 15:08:55 +01:00
if ( is_array ( $test ))
2001-07-30 17:59:25 +02:00
{
2007-02-14 15:08:55 +01:00
reset ( $test );
2001-07-30 17:59:25 +02:00
}
2007-02-14 15:08:55 +01:00
$s = '<option value=""> </option>' ;
while ( is_array ( $test ) && list (, $versionnumber ) = each ( $test ))
2001-07-30 17:59:25 +02:00
{
2007-02-14 15:08:55 +01:00
$s .= '<option value="' . $versionnumber . '">' . $versionnumber . '</option>' ;
2001-07-30 17:59:25 +02:00
}
2007-02-14 15:08:55 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'select_version' , $s );
if ( $value [ 'name' ])
{
$i = $i ? 0 : 1 ;
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'apptitle' , $value [ 'title' ]);
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'currentver' , $value [ 'currentver' ]);
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'bg_color' , $bgcolor [ $i ]);
2001-07-30 17:59:25 +02:00
2007-02-14 15:08:55 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'instimg' , 'completed.png' );
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'instalt' , lang ( 'Completed' ));
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'install' , '<input type="checkbox" name="install[' . $value [ 'name' ] . ']" />' );
$status = lang ( 'OK' ) . ' - ' . $value [ 'status' ];
2001-07-30 17:59:25 +02:00
2007-02-14 15:08:55 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'appinfo' , $value [ 'name' ] . '-' . $status );
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'appname' , $value [ 'name' ]);
2001-07-30 17:59:25 +02:00
2007-02-14 15:08:55 +01:00
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'apps' , True );
}
2001-07-30 17:59:25 +02:00
}
}
}
2003-08-28 16:31:11 +02:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'submit' , lang ( 'Save' ));
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'setup_tpl' ] -> set_var ( 'cancel' , lang ( 'Cancel' ));
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'app_footer' );
$GLOBALS [ 'setup_tpl' ] -> pparse ( 'out' , 'footer' );
2005-03-04 13:40:28 +01:00
$GLOBALS [ 'egw_setup' ] -> html -> show_footer ();
2001-07-30 17:59:25 +02:00
?>