2004-10-19 20:58:50 +02:00
< ? php
2024-10-03 15:43:04 +02: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 >
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2003-08-28 23:37:29 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-28 23:37:29 +02: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 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-08-28 23:37:29 +02:00
*/
2006-08-06 02:10:48 +02:00
/**
2008-12-20 19:37:30 +01:00
* \file htdocs / admin / system / database . php
2011-01-10 20:16:21 +01:00
* \brief Page with system information of database
2008-12-20 19:37:30 +01:00
*/
2004-02-15 01:06:47 +01:00
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2004-02-15 01:06:47 +01:00
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
2024-11-06 19:39:46 +01:00
*
* @ var string $dolibarr_main_db_pass
2024-11-04 23:53:20 +01:00
*/
2004-09-04 13:19:13 +02:00
$langs -> load ( " admin " );
2004-09-03 22:59:00 +02:00
2024-09-30 23:11:31 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-02-26 22:04:03 +01:00
if ( ! $user -> admin ) {
accessforbidden ();
}
2008-12-20 19:37:30 +01:00
2006-08-06 02:10:48 +02:00
2024-09-30 23:11:31 +02:00
/*
* Actions
*/
if ( $action == 'convertutf8unicode' ) { // Test on permission already done.
2024-10-03 15:47:03 +02:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8 COLLATE utf8_unicode_ci " ;
2024-09-30 23:11:31 +02:00
$db -> query ( $sql );
}
if ( $action == 'convertutf8mb4unicode' ) { // Test on permission already done.
2024-10-03 15:43:04 +02:00
$sql = " ALTER DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci " ;
2024-09-30 23:11:31 +02:00
$db -> query ( $sql );
}
if ( $action == 'convertutf8general' ) { // Test on permission already done.
2024-10-03 15:47:03 +02:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8 COLLATE utf8_general_ci " ;
2024-09-30 23:11:31 +02:00
$db -> query ( $sql );
}
if ( $action == 'convertutf8mb4general' ) { // Test on permission already done.
2024-10-03 15:47:03 +02:00
$sql = " ALTER DATABASE " . $db -> sanitize ( $db -> database_name ) . " CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci " ;
2024-09-30 23:11:31 +02:00
$db -> query ( $sql );
}
2007-03-28 13:55:15 +02:00
/*
2009-04-17 17:43:28 +02:00
* View
2008-12-20 19:37:30 +01:00
*/
2020-04-10 10:59:32 +02:00
$form = new Form ( $db );
2008-12-20 19:37:30 +01:00
2024-06-08 17:03:08 +02:00
llxHeader ( '' , '' , '' , '' , 0 , 0 , '' , '' , '' , 'mod-admin page-system_database' );
2003-08-28 23:37:29 +02:00
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $langs -> trans ( " InfoDatabase " ), '' , 'title_setup' );
2009-04-17 17:43:28 +02:00
// Database
2017-01-17 20:04:41 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2011-02-07 14:55:53 +01:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Database " ) . '</td></tr>' . " \n " ;
2020-12-21 01:40:15 +01: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 02:09:12 +01:00
// @phan-suppress-next-line PhanTypeSuspiciousStringExpression (user is defined in the stdClass)
2020-12-21 01:40:15 +01: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-12 01:41:30 +02:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DBStoringCharset " ) . '</td><td>' . $db -> getDefaultCharacterSetDatabase ();
if ( $db -> type == 'mysqli' ) {
2024-10-01 10:20:05 +02: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-02-13 11:06:20 +01: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_general_ci; " ));
2024-09-12 02:21:14 +02:00
// We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
2024-09-12 01:41:30 +02:00
}
print '</td></tr>' . " \n " ;
2024-09-30 23:11:31 +02:00
print '<tr class="oddeven"><td width="300">' . $langs -> trans ( " DBSortingCharset " ) . '</td><td>' ;
$defaultcollation = $db -> getDefaultCollationDatabase ();
print dolPrintHTML ( $defaultcollation );
2024-10-03 15:43:04 +02:00
global $dolibarr_main_db_collation ;
2024-09-12 01:41:30 +02:00
if ( $db -> type == 'mysqli' ) {
2024-10-03 15:54:30 +02: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 23:11:31 +02:00
}
2024-10-01 10:20:05 +02: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-02-13 11:06:20 +01: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_general_ci; " ));
2024-09-12 02:21:14 +02:00
// We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
2024-09-30 23:11:31 +02: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-12 01:41:30 +02:00
}
print '</td></tr>' . " \n " ;
2009-04-17 17:43:28 +02:00
print '</table>' ;
2017-01-17 20:04:41 +01:00
print '</div>' ;
2007-03-28 13:55:15 +02:00
2012-09-08 00:52:44 +02:00
// Tables
2012-09-09 16:32:03 +02:00
print '<br>' ;
2017-01-17 20:04:41 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2012-09-09 16:32:03 +02:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Tables " ) . '</td></tr>' . " \n " ;
2022-09-11 15:17:10 +02: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 16:32:03 +02:00
print '</table>' ;
2017-01-17 20:04:41 +01:00
print '</div>' ;
2007-03-28 13:55:15 +02:00
2020-04-10 10:59:32 +02:00
$listofvars = $db -> getServerParametersValues ();
$listofstatus = $db -> getServerStatusValues ();
$arraylist = array ( 'listofvars' , 'listofstatus' );
2003-08-28 23:37:29 +02:00
2021-02-26 22:04:03 +01:00
if ( ! count ( $listofvars ) && ! count ( $listofstatus )) {
2008-12-20 19:37:30 +01:00
print $langs -> trans ( " FeatureNotAvailableWithThisDatabaseDriver " );
2020-05-21 09:35:30 +02:00
} else {
2021-02-26 22:04:03 +01:00
foreach ( $arraylist as $listname ) {
2008-12-20 19:37:30 +01:00
print '<br>' ;
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2008-12-20 19:37:30 +01:00
print '<tr class="liste_titre">' ;
2012-09-08 00:52:44 +02:00
print '<td width="300">' . $langs -> trans ( " Parameters " ) . '</td>' ;
2024-09-03 11:19:01 +02:00
print '<td></td>' ;
2011-02-07 14:55:53 +01:00
print '</tr>' . " \n " ;
2014-07-08 01:02:30 +02:00
2008-12-20 19:37:30 +01:00
// arraytest is an array of test to do
2020-04-10 10:59:32 +02:00
$arraytest = array ();
2021-02-26 22:04:03 +01:00
if ( preg_match ( '/mysql/i' , $db -> type )) {
2020-04-10 10:59:32 +02:00
$arraytest = array (
2024-03-07 20:16:48 +01: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 19:37:30 +01:00
);
}
2014-07-08 01:02:30 +02:00
2020-04-10 10:59:32 +02:00
$listtouse = array ();
2021-02-26 22:04:03 +01:00
if ( $listname == 'listofvars' ) {
$listtouse = $listofvars ;
}
if ( $listname == 'listofstatus' ) {
$listtouse = $listofstatus ;
}
2009-01-15 23:49:06 +01:00
2021-02-26 22:04:03 +01:00
foreach ( $listtouse as $param => $paramval ) {
2017-04-12 17:44:01 +02:00
print '<tr class="oddeven">' ;
2014-02-25 18:25:17 +01:00
print '<td>' ;
print $param ;
print '</td>' ;
2020-12-21 01:40:15 +01:00
print '<td class="wordbreak">' ;
2023-12-04 11:41:14 +01:00
$show = 0 ;
$text = '' ;
2021-02-26 22:04:03 +01:00
foreach ( $arraytest as $key => $val ) {
if ( $key != $param ) {
continue ;
}
2022-12-30 18:43:43 +01:00
$tmpvar = $val [ 'var' ];
$val2 = ${$tmpvar} ;
2020-04-10 10:59:32 +02: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 19:37:30 +01:00
}
2021-02-26 22:04:03 +01:00
if ( $show == 0 ) {
print $paramval ;
}
if ( $show == 1 ) {
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2021-02-26 22:04:03 +01:00
print $form -> textwithpicto ( $paramval , $text );
}
if ( $show == 2 ) {
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2021-02-26 22:04:03 +01:00
print $form -> textwithpicto ( $paramval , $text , 1 , 'warning' );
}
2014-02-25 18:25:17 +01:00
print '</td>' ;
print '</tr>' . " \n " ;
2008-12-20 19:37:30 +01:00
}
2011-02-07 14:55:53 +01:00
print '</table>' . " \n " ;
2017-01-17 20:04:41 +01:00
print '</div>' ;
2006-08-06 02:10:48 +02:00
}
2003-08-28 23:37:29 +02:00
}
2018-07-28 14:29:28 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2014-07-08 01:02:30 +02:00
$db -> close ();