2004-10-19 18:58:50 +00:00
< ? php
2024-10-03 13:43:04 +00:00
/* Copyright ( C ) 2003 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2025-03-24 21:01:55 +00:00
* Copyright ( C ) 2024 - 2025 Frédéric France < frederic . france @ free . fr >
2003-08-28 21:37:29 +00: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
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-28 21:37:29 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-08-28 21:37:29 +00:00
*/
2006-08-06 00:10:48 +00:00
/**
2008-12-20 18:37:30 +00:00
* \file htdocs / admin / system / database . php
2011-01-10 19:16:21 +00:00
* \brief Page with system information of database
2008-12-20 18:37:30 +00:00
*/
2004-02-15 00:06:47 +00:00
2022-09-07 18:08:59 +00:00
// Load Dolibarr environment
2012-08-22 21:24:21 +00:00
require '../../main.inc.php' ;
2004-02-15 00:06:47 +00:00
2024-11-04 22:53:20 +00:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
2024-11-06 18:39:46 +00:00
*
2025-03-24 21:01:55 +00:00
* @ var string $dolibarr_main_db_pass
* @ var string $dolibarr_main_db_collation
* @ var string $dolibarr_main_db_character_set
2024-11-04 22:53:20 +00:00
*/
2004-09-04 11:19:13 +00:00
$langs -> load ( " admin " );
2004-09-03 20:59:00 +00:00
2024-09-30 21:11:31 +00:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-02-26 21:04:03 +00:00
if ( ! $user -> admin ) {
accessforbidden ();
}
2008-12-20 18:37:30 +00:00
2006-08-06 00:10:48 +00:00
2024-09-30 21:11:31 +00:00
/*
* Actions
*/
2025-08-26 03:33:23 +00:00
$logsql = '' ;
2025-08-25 10:46:32 +00:00
$resultsql = null ;
2024-09-30 21:11:31 +00:00
if ( $action == 'convertutf8unicode' ) { // Test on permission already done.
2024-10-03 13:47:03 +00:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8 COLLATE utf8_unicode_ci " ;
2025-08-26 03:33:23 +00:00
$logsql .= $sql . '<br>' ;
2025-08-25 10:46:32 +00:00
$resultsql = $db -> query ( $sql );
2024-09-30 21:11:31 +00:00
}
if ( $action == 'convertutf8mb4unicode' ) { // Test on permission already done.
2025-08-25 10:46:32 +00:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci " ;
2025-08-26 03:33:23 +00:00
$logsql .= $sql . '<br>' ;
2025-08-25 10:46:32 +00:00
$resultsql = $db -> query ( $sql );
2024-09-30 21:11:31 +00:00
}
if ( $action == 'convertutf8general' ) { // Test on permission already done.
2024-10-03 13:47:03 +00:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8 COLLATE utf8_general_ci " ;
2025-08-26 03:33:23 +00:00
$logsql .= $sql . '<br>' ;
2025-08-25 10:46:32 +00:00
$resultsql = $db -> query ( $sql );
2024-09-30 21:11:31 +00:00
}
if ( $action == 'convertutf8mb4general' ) { // Test on permission already done.
2024-10-03 13:47:03 +00:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci " ;
2025-08-26 03:33:23 +00:00
$logsql .= $sql . '<br>' ;
2025-08-25 10:46:32 +00:00
$resultsql = $db -> query ( $sql );
2024-09-30 21:11:31 +00:00
}
2007-03-28 11:55:15 +00:00
/*
2009-04-17 15:43:28 +00:00
* View
2008-12-20 18:37:30 +00:00
*/
2020-04-10 08:59:32 +00:00
$form = new Form ( $db );
2008-12-20 18:37:30 +00:00
2024-06-08 15:03:08 +00:00
llxHeader ( '' , '' , '' , '' , 0 , 0 , '' , '' , '' , 'mod-admin page-system_database' );
2003-08-28 21:37:29 +00:00
2019-01-27 10:55:16 +00:00
print load_fiche_titre ( $langs -> trans ( " InfoDatabase " ), '' , 'title_setup' );
2009-04-17 15:43:28 +00:00
2025-08-26 03:33:23 +00:00
if ( $logsql ) {
print info_admin ( $logsql . ' ' . ( empty ( $resultsql ) ? ' => KO ' . $db -> lasterror () : ' => OK' ));
2025-08-25 10:46:32 +00:00
}
2009-04-17 15:43:28 +00:00
// Database
2017-01-17 19:04:41 +00:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 20:24:41 +00:00
print '<table class="noborder centpercent">' ;
2011-02-07 13:55:53 +00:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Database " ) . '</td></tr>' . " \n " ;
2020-12-21 00:40:15 +00:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " Version " ) . '</td><td>' . $db :: LABEL . ' ' . $db -> getVersion () . '</td></tr>' . " \n " ;
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DatabaseServer " ) . '</td><td>' . $conf -> db -> host . '</td></tr>' . " \n " ;
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DatabasePort " ) . '</td><td>' . ( empty ( $conf -> db -> port ) ? $langs -> trans ( " Default " ) : $conf -> db -> port ) . '</td></tr>' . " \n " ;
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DatabaseName " ) . '</td><td>' . $conf -> db -> name . '</td></tr>' . " \n " ;
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DriverType " ) . '</td><td>' . $conf -> db -> type . ( $db -> getDriverInfo () ? ' (' . $db -> getDriverInfo () . ')' : '' ) . '</td></tr>' . " \n " ;
2024-03-16 01:09:12 +00:00
// @phan-suppress-next-line PhanTypeSuspiciousStringExpression (user is defined in the stdClass)
2020-12-21 00:40:15 +00:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " User " ) . '</td><td>' . $conf -> db -> user . '</td></tr>' . " \n " ;
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " Password " ) . '</td><td>' . preg_replace ( '/./i' , '*' , $dolibarr_main_db_pass ) . '</td></tr>' . " \n " ;
2024-09-11 23:41:30 +00:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DBStoringCharset " ) . '</td><td>' . $db -> getDefaultCharacterSetDatabase ();
if ( $db -> type == 'mysqli' ) {
2024-10-01 08:20:05 +00:00
$tooltipexample = " <br>SHOW VARIABLES LIKE 'character_set_database' (cached)<br>You can avoid cache effect with:<br>SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = ' " . $db -> escape ( $conf -> db -> name ) . " ' " ;
2025-08-25 10:46:32 +00:00
print ' ' . $form -> textwithpicto ( '' , $langs -> transnoentitiesnoconv ( " HelpMariaDBToGetValue " , $tooltipexample . '<br>' . $langs -> transnoentitiesnoconv ( " HelpMariaDBToGetPossibleValues " , " <br>SHOW CHARSET " ) . " <br><br>Example to change value: ALTER DATABASE " . $conf -> db -> name . " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; " ), 1 , 'help' , 'valignmiddle' , 0 , 3 , 'tooltipcharset' );
2024-09-12 00:21:14 +00:00
// We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
2024-09-11 23:41:30 +00:00
}
print '</td></tr>' . " \n " ;
2024-09-30 21:11:31 +00:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DBSortingCharset " ) . '</td><td>' ;
$defaultcollation = $db -> getDefaultCollationDatabase ();
print dolPrintHTML ( $defaultcollation );
2024-10-03 13:43:04 +00:00
global $dolibarr_main_db_collation ;
2024-09-11 23:41:30 +00:00
if ( $db -> type == 'mysqli' ) {
2024-10-03 13:54:30 +00:00
if ( $defaultcollation != $conf -> db -> dolibarr_main_db_collation ) {
print img_warning ( 'The database default value of collation ' . $defaultcollation . ' differs from conf setup ' . $conf -> db -> dolibarr_main_db_collation );
2024-09-30 21:11:31 +00:00
}
2024-10-01 08:20:05 +00:00
$tooltipexample = " <br>SHOW VARIABLES LIKE 'collation_database' (cached)<br>You can avoid cache effect with:<br>SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = ' " . $db -> escape ( $conf -> db -> name ) . " ' " ;
2025-08-25 10:46:32 +00:00
print ' ' . $form -> textwithpicto ( '' , $langs -> transnoentitiesnoconv ( " HelpMariaDBToGetValue " , $tooltipexample . '<br>' . $langs -> transnoentitiesnoconv ( " HelpMariaDBToGetPossibleValues " , " <br>SHOW COLLATION " ) . " <br><br>Example to change value: ALTER DATABASE " . $conf -> db -> name . " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; " ), 1 , 'help' , 'valignmiddle' , 0 , 3 , 'tooltipcollation' );
2024-09-12 00:21:14 +00:00
// We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
2024-09-30 21:11:31 +00:00
print ' <span class="opacitymedium small">' . $langs -> trans ( " ConvertInto " );
if ( ! in_array ( $defaultcollation , array ( " utf8_unicode_ci " ))) {
print ' <a class="reposition" href="' . DOL_URL_ROOT . '/admin/system/database.php?action=convertutf8unicode&token=' . newToken () . '">utf8 unicode</a>' ;
}
if ( ! in_array ( $defaultcollation , array ( " utf8_general_ci " ))) {
print ' <a class="reposition" href="' . DOL_URL_ROOT . '/admin/system/database.php?action=convertutf8general&token=' . newToken () . '">utf8 general</a>' ;
}
if ( ! in_array ( $defaultcollation , array ( " utf8mb4_unicode_ci " ))) {
print ' <a class="reposition" href="' . DOL_URL_ROOT . '/admin/system/database.php?action=convertutf8mb4unicode&&token=' . newToken () . '">utf8mb4 unicode</a>' ;
}
if ( ! in_array ( $defaultcollation , array ( " utf8mb4_general_ci " ))) {
print ' <a class="reposition" href="' . DOL_URL_ROOT . '/admin/system/database.php?action=convertutf8mb4general&&token=' . newToken () . '">utf8mb4 general</a>' ;
}
2024-09-11 23:41:30 +00:00
}
print '</td></tr>' . " \n " ;
2009-04-17 15:43:28 +00:00
print '</table>' ;
2017-01-17 19:04:41 +00:00
print '</div>' ;
2007-03-28 11:55:15 +00:00
2012-09-07 22:52:44 +00:00
// Tables
2012-09-09 14:32:03 +00:00
print '<br>' ;
2017-01-17 19:04:41 +00:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 20:24:41 +00:00
print '<table class="noborder centpercent">' ;
2012-09-09 14:32:03 +00:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Tables " ) . '</td></tr>' . " \n " ;
2022-09-11 13:17:10 +00:00
print '<tr class="oddeven"><td class=""><a href="' . DOL_URL_ROOT . '/admin/system/database-tables.php?mainmenu=home">' . img_picto ( '' , 'list' , 'class="pictofixedwidth"' ) . $langs -> trans ( " List " ) . '</a></td></tr>' . " \n " ;
2012-09-09 14:32:03 +00:00
print '</table>' ;
2017-01-17 19:04:41 +00:00
print '</div>' ;
2007-03-28 11:55:15 +00:00
2020-04-10 08:59:32 +00:00
$listofvars = $db -> getServerParametersValues ();
$listofstatus = $db -> getServerStatusValues ();
$arraylist = array ( 'listofvars' , 'listofstatus' );
2003-08-28 21:37:29 +00:00
2021-02-26 21:04:03 +00:00
if ( ! count ( $listofvars ) && ! count ( $listofstatus )) {
2008-12-20 18:37:30 +00:00
print $langs -> trans ( " FeatureNotAvailableWithThisDatabaseDriver " );
2020-05-21 07:35:30 +00:00
} else {
2021-02-26 21:04:03 +00:00
foreach ( $arraylist as $listname ) {
2008-12-20 18:37:30 +00:00
print '<br>' ;
2020-10-31 13:32:18 +00:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 20:24:41 +00:00
print '<table class="noborder centpercent">' ;
2008-12-20 18:37:30 +00:00
print '<tr class="liste_titre">' ;
2012-09-07 22:52:44 +00:00
print '<td width="300">' . $langs -> trans ( " Parameters " ) . '</td>' ;
2024-09-03 09:19:01 +00:00
print '<td></td>' ;
2011-02-07 13:55:53 +00:00
print '</tr>' . " \n " ;
2014-07-07 23:02:30 +00:00
2008-12-20 18:37:30 +00:00
// arraytest is an array of test to do
2020-04-10 08:59:32 +00:00
$arraytest = array ();
2021-02-26 21:04:03 +00:00
if ( preg_match ( '/mysql/i' , $db -> type )) {
2020-04-10 08:59:32 +00:00
$arraytest = array (
2024-03-07 19:16:48 +00:00
'character_set_database' => array ( 'var' => 'dolibarr_main_db_character_set' , 'valifempty' => 'utf8' ),
'collation_database' => array ( 'var' => 'dolibarr_main_db_collation' , 'valifempty' => 'utf8_unicode_ci' )
2008-12-20 18:37:30 +00:00
);
}
2014-07-07 23:02:30 +00:00
2020-04-10 08:59:32 +00:00
$listtouse = array ();
2021-02-26 21:04:03 +00:00
if ( $listname == 'listofvars' ) {
$listtouse = $listofvars ;
}
if ( $listname == 'listofstatus' ) {
$listtouse = $listofstatus ;
}
2009-01-15 22:49:06 +00:00
2021-02-26 21:04:03 +00:00
foreach ( $listtouse as $param => $paramval ) {
2017-04-12 15:44:01 +00:00
print '<tr class="oddeven">' ;
2014-02-25 17:25:17 +00:00
print '<td>' ;
print $param ;
print '</td>' ;
2020-12-21 00:40:15 +00:00
print '<td class="wordbreak">' ;
2023-12-04 10:41:14 +00:00
$show = 0 ;
$text = '' ;
2021-02-26 21:04:03 +00:00
foreach ( $arraytest as $key => $val ) {
if ( $key != $param ) {
continue ;
}
2022-12-30 17:43:43 +00:00
$tmpvar = $val [ 'var' ];
$val2 = ${$tmpvar} ;
2020-04-10 08:59:32 +00:00
$text = 'Should be in line with value of param <b>' . $val [ 'var' ] . '</b> thas is <b>' . ( $val2 ? $val2 : " '' (= " . $val [ 'valifempty' ] . " ) " ) . '</b>' ;
$show = 1 ;
2008-12-20 18:37:30 +00:00
}
2021-02-26 21:04:03 +00:00
if ( $show == 0 ) {
print $paramval ;
}
if ( $show == 1 ) {
2024-03-07 19:16:48 +00:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2021-02-26 21:04:03 +00:00
print $form -> textwithpicto ( $paramval , $text );
}
if ( $show == 2 ) {
2024-03-07 19:16:48 +00:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2021-02-26 21:04:03 +00:00
print $form -> textwithpicto ( $paramval , $text , 1 , 'warning' );
}
2014-02-25 17:25:17 +00:00
print '</td>' ;
print '</tr>' . " \n " ;
2008-12-20 18:37:30 +00:00
}
2011-02-07 13:55:53 +00:00
print '</table>' . " \n " ;
2017-01-17 19:04:41 +00:00
print '</div>' ;
2006-08-06 00:10:48 +00:00
}
2003-08-28 21:37:29 +00:00
}
2018-07-28 12:29:28 +00:00
// End of page
2011-08-27 14:24:16 +00:00
llxFooter ();
2014-07-07 23:02:30 +00:00
$db -> close ();