30require
'../../main.inc.php';
46$table =
GETPOST(
'table',
'aZ09');
47$field =
GETPOST(
'field',
'aZ09');
48$action =
GETPOST(
'action',
'aZ09');
59if ($action ==
'convertutf8') {
60 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
61 $logsql .= $sql.
'<br>';
63 $resql = $db->query($sql);
65 $num = $db->num_rows($resql);
68 $row = $db->fetch_row($resql);
69 if ($row[0] == $field) {
70 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" CHARACTER SET utf8";
71 $logsql .= $sql.
'<br>';
75 $collation =
'utf8_unicode_ci';
76 $defaultcollation = $db->getDefaultCollationDatabase();
77 if (preg_match(
'/general/', $defaultcollation)) {
78 $collation =
'utf8_general_ci';
81 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" COLLATE ".$db->sanitize($collation);
82 $logsql .= $sql.
'<br>';
84 $resql2 = $db->query($sql);
95if ($action ==
'convertutf8mb4') {
96 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
97 $logsql .= $sql.
'<br>';
99 $resql = $db->query($sql);
101 $num = $db->num_rows($resql);
104 $row = $db->fetch_row($resql);
105 if ($row[0] == $field) {
106 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" CHARACTER SET utf8mb4";
107 $logsql .= $sql.
'<br>';
111 $collation =
'utf8mb4_unicode_ci';
112 $defaultcollation = $db->getDefaultCollationDatabase();
113 if (preg_match(
'/general/', $defaultcollation)) {
114 $collation =
'utf8mb4_general_ci';
117 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" COLLATE ".$db->sanitize($collation);
118 $logsql .= $sql.
'<br>';
120 $resql2 = $db->query($sql);
137llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-system_dbtable');
139$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/system/database-tables.php?restore_lastsearch_values=1">'.
img_picto($langs->trans(
"GoBack"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"GoBack").
'</span></a>';
141print
load_fiche_titre($langs->trans(
"Table").
" ".$table, $linkback,
'title_setup');
144 print
info_admin($logsql.
' '.($resultsql ?
' => OK' :
' => KO '.$db->lasterror()));
150if (preg_match(
'/mysql/i', $conf->db->type)) {
151 $sql =
"SHOW TABLE STATUS LIKE '".$db->escape($db->escapeforlike($table)).
"'";
153} elseif ($conf->db->type ==
'pgsql') {
154 $sql =
"SELECT conname,contype FROM pg_constraint";
158if (!$base || $sql ===
null) {
159 print $langs->trans(
"FeatureNotAvailableWithThisDatabaseDriver");
161 $resql = $db->query($sql);
163 $num = $db->num_rows($resql);
166 $row = $db->fetch_row($resql);
173 $cons = explode(
";", $row[14]);
175 foreach ($cons as $cc) {
176 $cx = preg_replace(
"/\)\sREFER/",
"", $cc);
177 $cx = preg_replace(
"/\(`/",
"", $cx);
178 $cx = preg_replace(
"/`\)/",
"", $cx);
179 $cx = preg_replace(
"/`\s/",
"", $cx);
181 $val = explode(
"`", $cx);
183 $link[trim($val[0])][0] = (isset($val[1]) ? $val[1] :
'');
184 $link[trim($val[0])][1] = (isset($val[2]) ? $val[2] :
'');
188 print
'<div class="div-table-responsive-no-min">';
189 print
'<table class="noborder">';
190 print
'<tr class="liste_titre">';
191 print
'<td>'.$langs->trans(
"Fields").
'</td>';
192 print
'<td>'.$langs->trans(
"Type").
'</td>';
193 print
'<td>'.$langs->trans(
"Collation").
'</td>';
194 print
'<td>'.$langs->trans(
"Null").
'</td>';
195 print
'<td>'.$langs->trans(
"Index").
'</td>';
196 print
'<td>'.$langs->trans(
"Default").
'</td>';
197 print
'<td>'.$langs->trans(
"Extra").
'</td>';
198 print
'<td>'.$langs->trans(
"Privileges").
'</td>';
199 print
'<td>'.$langs->trans(
"FieldsLinked").
'</td>';
203 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
205 $resql = $db->query($sql);
207 $num = $db->num_rows($resql);
210 $row = $db->fetch_row($resql);
212 print
'<tr class="oddeven">';
215 print
"<td>".$row[0].
"</td>";
222 if (preg_match(
'/^varchar/', $proptype, $matches)) {
223 $pictoType =
'varchar';
224 } elseif (strpos($proptype,
'int') === 0 || strpos($proptype,
'tinyint') === 0 || strpos($proptype,
'bigint') === 0) {
226 } elseif (strpos($proptype,
'timestamp') === 0) {
227 $pictoType =
'datetime';
228 } elseif (strpos($proptype,
'real') === 0) {
229 $pictoType =
'double';
235 print
"<td>".(empty($row[2]) ?
' ' : $row[2]);
238 if (isset($row[2])) {
239 print
'<br><span class="opacitymedium small">'.$langs->trans(
"ConvertInto");
240 if (!in_array($row[2], array(
"utf8_unicode_ci"))) {
241 print
' <a class="reposition" href="dbtable.php?action=convertutf8&table='.urlencode($table).
'&field='.urlencode($row[0]).
'&token='.
newToken().
'">utf8</a>';
243 if (!in_array($row[2], array(
"utf8mb4_unicode_ci"))) {
244 print
' <a class="reposition" href="dbtable.php?action=convertutf8mb4&table='.urlencode($table).
'&field='.urlencode($row[0]).
'&token='.
newToken().
'">utf8mb4</a>';
254 print
"<td>".$row[3].
"</td>";
256 print
"<td>".(empty($row[4]) ?
'' : $row[4]).
"</td>";
258 print
"<td>".(empty($row[5]) ?
'' : $row[5]).
"</td>";
260 print
"<td>".(empty($row[6]) ?
'' : $row[6]).
"</td>";
262 print
"<td>".(empty($row[7]) ?
'' : $row[7]).
"</td>";
264 print
"<td>".(isset($link[$row[0]][0]) ? $link[$row[0]][0] :
'').
".";
265 print(isset($link[$row[0]][1]) ? $link[$row[0]][1] :
'').
"</td>";
267 print
'<!-- ALTER TABLE '.$table.
' MODIFY '.$row[0].
' '.$row[1].
' COLLATE utf8mb4_unicode_ci; -->';
268 print
'<!-- ALTER TABLE '.$table.
' MODIFY '.$row[0].
' '.$row[1].
' CHARACTER SET utf8mb4; -->';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getPictoForType($key, $morecss='')
Return the picto for a data type.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.