diff --git a/htdocs/admin/system/database-tables.php b/htdocs/admin/system/database-tables.php
index defb52235b7..14121aebab8 100644
--- a/htdocs/admin/system/database-tables.php
+++ b/htdocs/admin/system/database-tables.php
@@ -39,6 +39,7 @@ if (!$user->admin) {
accessforbidden();
}
+$table = GETPOST('table', 'aZ09');
$action = GETPOST('action', 'aZ09');
@@ -46,16 +47,20 @@ $action = GETPOST('action', 'aZ09');
* Actions
*/
-if ($action == 'convert') {
- $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ENGINE=INNODB";
+if ($action == 'convert') { // Convert engine into innodb
+ $sql = "ALTER TABLE ".$db->sanitize($table)." ENGINE=INNODB";
$db->query($sql);
}
if ($action == 'convertutf8') {
- $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
+ $sql = "ALTER TABLE ".$db->sanitize($table)." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
+ $db->query($sql);
+}
+if ($action == 'convertutf8mb4') {
+ $sql = "ALTER TABLE ".$db->sanitize($table)." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
$db->query($sql);
}
if ($action == 'convertdynamic') {
- $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ROW_FORMAT=DYNAMIC;";
+ $sql = "ALTER TABLE ".$db->sanitize($table)." ROW_FORMAT=DYNAMIC;";
$db->query($sql);
}
@@ -160,17 +165,24 @@ if (!$base) {
print '
'.$langs->trans("Convert").' Dynamic';
}
print '';
- print '
'.$obj->Rows.' | ';
- print ''.$obj->Avg_row_length.' | ';
- print ''.$obj->Data_length.' | ';
- print ''.$obj->Max_data_length.' | ';
- print ''.$obj->Index_length.' | ';
- print ''.$obj->Auto_increment.' | ';
- print ''.$obj->Check_time.' | ';
- print ''.$obj->Collation;
- // Accept utf8, utf8mb3_unicode_ci, utf8mb4_unicode_ci
- if (isset($obj->Collation) && (in_array($obj->Collation, array("utf8mb4_general_ci", "latin1_swedish_ci")))) {
- print ' '.$langs->trans("Convert").' UTF8';
+ print ' | '.$obj->Rows.' | ';
+ print ''.$obj->Avg_row_length.' | ';
+ print ''.$obj->Data_length.' | ';
+ print ''.$obj->Max_data_length.' | ';
+ print ''.$obj->Index_length.' | ';
+ print ''.$obj->Auto_increment.' | ';
+ print ''.$obj->Check_time.' | ';
+ print ''.$obj->Collation;
+ // Link to convert collation
+ if (isset($obj->Collation)) {
+ print ' '.$langs->trans("ConvertInto");
+ if (!in_array($obj->Collation, array("utf8_unicode_ci"))) {
+ print ' utf8';
+ }
+ if (!in_array($obj->Collation, array("utf8mb4_unicode_ci"))) {
+ print ' utf8mb4';
+ }
+ print '';
}
print ' | ';
print '';
diff --git a/htdocs/admin/system/dbtable.php b/htdocs/admin/system/dbtable.php
index c7e7c5baa5e..a47be52e386 100644
--- a/htdocs/admin/system/dbtable.php
+++ b/htdocs/admin/system/dbtable.php
@@ -33,7 +33,57 @@ if (!$user->admin) {
accessforbidden();
}
-$table = GETPOST('table', 'alpha');
+$table = GETPOST('table', 'aZ09');
+$field = GETPOST('field', 'aZ09');
+$action = GETPOST('action', 'aZ09');
+
+
+/*
+ * Actions
+ */
+
+if ($action == 'convertutf8') {
+ $sql = "SHOW FULL COLUMNS IN ".$db->sanitize($table);
+
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num) {
+ $row = $db->fetch_row($resql);
+ if ($row[0] == $field) {
+ $sql = 'ALTER TABLE '.$db->sanitize($table).' MODIFY '.$db->sanitize($row[0]).' '.$row[1].' CHARACTER SET utf8'; // We must not sanitize the $row[1]
+ $db->query($sql);
+
+ $sql = 'ALTER TABLE '.$db->sanitize($table).' MODIFY '.$db->sanitize($row[0]).' '.$row[1].' COLLATE utf8_unicode_ci'; // We must not sanitize the $row[1]
+ $db->query($sql);
+
+ break;
+ }
+ }
+ }
+}
+if ($action == 'convertutf8mb4') {
+ $sql = "SHOW FULL COLUMNS IN ".$db->sanitize($table);
+
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num) {
+ $row = $db->fetch_row($resql);
+ if ($row[0] == $field) {
+ $sql = 'ALTER TABLE '.$db->sanitize($table).' MODIFY '.$db->sanitize($row[0]).' '.$row[1].' CHARACTER SET utf8mb4'; // We must not sanitize the $row[1]
+ $db->query($sql);
+
+ $sql = 'ALTER TABLE '.$db->sanitize($table).' MODIFY '.$db->sanitize($row[0]).' '.$row[1].' COLLATE utf8mb4_unicode_ci'; // We must not sanitize the $row[1]
+ $db->query($sql);
+
+ break;
+ }
+ }
+ }
+}
/*
@@ -48,7 +98,7 @@ print load_fiche_titre($langs->trans("Table")." ".$table, '', 'title_setup');
// Define request to get table description
$base = 0;
if (preg_match('/mysql/i', $conf->db->type)) {
- $sql = "SHOW TABLE STATUS LIKE '".$db->escape($table)."'";
+ $sql = "SHOW TABLE STATUS LIKE '".$db->escape($db->escapeforlike($table))."'";
$base = 1;
} elseif ($conf->db->type == 'pgsql') {
$sql = "SELECT conname,contype FROM pg_constraint";
@@ -99,7 +149,7 @@ if (!$base) {
print '';
// $sql = "DESCRIBE ".$table;
- $sql = "SHOW FULL COLUMNS IN ".$db->escape($table);
+ $sql = "SHOW FULL COLUMNS IN ".$db->sanitize($table);
$resql = $db->query($sql);
if ($resql) {
@@ -109,12 +159,46 @@ if (!$base) {
$row = $db->fetch_row($resql);
print '';
+
// field
print "| ".$row[0]." | ";
+
// type
- print "".$row[1]." | ";
+ print "";
+ $proptype = $row[1];
+ $pictoType = '';
+ $matches = array();
+ if (preg_match('/^varchar/', $proptype, $matches)) {
+ $pictoType = 'varchar';
+ } elseif (strpos($proptype, 'int') === 0 || strpos($proptype, 'tinyint') === 0 || strpos($proptype, 'bigint') === 0) {
+ $pictoType = 'int';
+ } elseif (strpos($proptype, 'timestamp') === 0) {
+ $pictoType = 'datetime';
+ } elseif (strpos($proptype, 'real') === 0) {
+ $pictoType = 'double';
+ }
+ print(!empty($pictoType) ? getPictoForType($pictoType) : getPictoForType($proptype)).''.dol_escape_htmltag($proptype).'';
+ print " | ";
+
// collation
- print "".$row[2]." | ";
+ print "".(empty($row[2]) ? ' ' : $row[2]);
+
+ // Link to convert collation
+ if (isset($row[2])) {
+ print ' '.$langs->trans("ConvertInto");
+ if (!in_array($row[2], array("utf8_unicode_ci"))) {
+ print ' utf8';
+ }
+ if (!in_array($row[2], array("utf8mb4_unicode_ci"))) {
+ print ' utf8mb4';
+ }
+ print '';
+ } else {
+ print ' ';
+ }
+
+ print " | ";
+
// null
print "".$row[3]." | ";
// key
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 9b0d6cfaab4..4a1beee4bcf 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -5437,7 +5437,7 @@ function img_mime($file, $titlealt = '', $morecss = '')
*/
function img_search($titlealt = 'default', $other = '')
{
- global $conf, $langs;
+ global $langs;
if ($titlealt == 'default') {
$titlealt = $langs->trans('Search');
@@ -5460,7 +5460,7 @@ function img_search($titlealt = 'default', $other = '')
*/
function img_searchclear($titlealt = 'default', $other = '')
{
- global $conf, $langs;
+ global $langs;
if ($titlealt == 'default') {
$titlealt = $langs->trans('Search');
@@ -5682,7 +5682,7 @@ function dol_print_error($db = null, $error = '', $errors = null)
*/
function dol_print_error_email($prefixcode, $errormessage = '', $errormessages = array(), $morecss = 'error', $email = '')
{
- global $langs, $conf;
+ global $langs;
if (empty($email)) {
$email = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL');
@@ -5745,7 +5745,7 @@ function print_liste_field_titre($name, $file = "", $field = "", $begin = "", $m
*/
function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin = "", $moreparam = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $disablesortlink = 0, $tooltip = '', $forcenowrapcolumntitle = 0)
{
- global $conf, $langs, $form;
+ global $langs, $form;
//print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder
\n";
if ($moreattrib == 'class="right"') {