29require
'../../main.inc.php';
37$table =
GETPOST(
'table',
'aZ09');
38$field =
GETPOST(
'field',
'aZ09');
39$action =
GETPOST(
'action',
'aZ09');
46if ($action ==
'convertutf8') {
47 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
49 $resql = $db->query($sql);
51 $num = $db->num_rows($resql);
54 $row = $db->fetch_row($resql);
55 if ($row[0] == $field) {
56 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" CHARACTER SET utf8";
59 $collation =
'utf8_unicode_ci';
60 $defaultcollation = $db->getDefaultCollationDatabase();
61 if (preg_match(
'/general/', $defaultcollation)) {
62 $collation =
'utf8_general_ci';
65 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" COLLATE ".$db->sanitize($collation);
66 $reslq2 = $db->query($sql);
76if ($action ==
'convertutf8mb4') {
77 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
79 $resql = $db->query($sql);
81 $num = $db->num_rows($resql);
84 $row = $db->fetch_row($resql);
85 if ($row[0] == $field) {
86 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" CHARACTER SET utf8mb4";
89 $collation =
'utf8mb4_unicode_ci';
90 $defaultcollation = $db->getDefaultCollationDatabase();
91 if (preg_match(
'/general/', $defaultcollation)) {
92 $collation =
'utf8mb4_general_ci';
95 $sql =
"ALTER TABLE ".$db->sanitize($table).
" MODIFY ".$db->sanitize($row[0]).
" ".$row[1].
" COLLATE ".$db->sanitize($collation);
96 $resql2 = $db->query($sql);
112llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-system_dbtable');
115print
load_fiche_titre($langs->trans(
"Table").
" ".$table,
'',
'title_setup');
120if (preg_match(
'/mysql/i', $conf->db->type)) {
121 $sql =
"SHOW TABLE STATUS LIKE '".$db->escape($db->escapeforlike($table)).
"'";
123} elseif ($conf->db->type ==
'pgsql') {
124 $sql =
"SELECT conname,contype FROM pg_constraint";
128if (!$base || $sql ===
null) {
129 print $langs->trans(
"FeatureNotAvailableWithThisDatabaseDriver");
131 $resql = $db->query($sql);
133 $num = $db->num_rows($resql);
136 $row = $db->fetch_row($resql);
143 $cons = explode(
";", $row[14]);
145 foreach ($cons as $cc) {
146 $cx = preg_replace(
"/\)\sREFER/",
"", $cc);
147 $cx = preg_replace(
"/\(`/",
"", $cx);
148 $cx = preg_replace(
"/`\)/",
"", $cx);
149 $cx = preg_replace(
"/`\s/",
"", $cx);
151 $val = explode(
"`", $cx);
153 $link[trim($val[0])][0] = (isset($val[1]) ? $val[1] :
'');
154 $link[trim($val[0])][1] = (isset($val[2]) ? $val[2] :
'');
158 print
'<table class="noborder">';
159 print
'<tr class="liste_titre">';
160 print
'<td>'.$langs->trans(
"Fields").
'</td>';
161 print
'<td>'.$langs->trans(
"Type").
'</td>';
162 print
'<td>'.$langs->trans(
"Collation").
'</td>';
163 print
'<td>'.$langs->trans(
"Null").
'</td>';
164 print
'<td>'.$langs->trans(
"Index").
'</td>';
165 print
'<td>'.$langs->trans(
"Default").
'</td>';
166 print
'<td>'.$langs->trans(
"Extra").
'</td>';
167 print
'<td>'.$langs->trans(
"Privileges").
'</td>';
168 print
'<td>'.$langs->trans(
"FieldsLinked").
'</td>';
172 $sql =
"SHOW FULL COLUMNS IN ".$db->sanitize($table);
174 $resql = $db->query($sql);
176 $num = $db->num_rows($resql);
179 $row = $db->fetch_row($resql);
181 print
'<tr class="oddeven">';
184 print
"<td>".$row[0].
"</td>";
191 if (preg_match(
'/^varchar/', $proptype, $matches)) {
192 $pictoType =
'varchar';
193 } elseif (strpos($proptype,
'int') === 0 || strpos($proptype,
'tinyint') === 0 || strpos($proptype,
'bigint') === 0) {
195 } elseif (strpos($proptype,
'timestamp') === 0) {
196 $pictoType =
'datetime';
197 } elseif (strpos($proptype,
'real') === 0) {
198 $pictoType =
'double';
204 print
"<td>".(empty($row[2]) ?
' ' : $row[2]);
207 if (isset($row[2])) {
208 print
'<br><span class="opacitymedium small">'.$langs->trans(
"ConvertInto");
209 if (!in_array($row[2], array(
"utf8_unicode_ci"))) {
210 print
' <a class="reposition" href="dbtable.php?action=convertutf8&table='.urlencode($table).
'&field='.urlencode($row[0]).
'&token='.
newToken().
'">utf8</a>';
212 if (!in_array($row[2], array(
"utf8mb4_unicode_ci"))) {
213 print
' <a class="reposition" href="dbtable.php?action=convertutf8mb4&table='.urlencode($table).
'&field='.urlencode($row[0]).
'&token='.
newToken().
'">utf8mb4</a>';
223 print
"<td>".$row[3].
"</td>";
225 print
"<td>".(empty($row[4]) ?
'' : $row[4]).
"</td>";
227 print
"<td>".(empty($row[5]) ?
'' : $row[5]).
"</td>";
229 print
"<td>".(empty($row[6]) ?
'' : $row[6]).
"</td>";
231 print
"<td>".(empty($row[7]) ?
'' : $row[7]).
"</td>";
233 print
"<td>".(isset($link[$row[0]][0]) ? $link[$row[0]][0] :
'').
".";
234 print(isset($link[$row[0]][1]) ? $link[$row[0]][1] :
'').
"</td>";
236 print
'<!-- ALTER TABLE '.$table.
' MODIFY '.$row[0].
' '.$row[1].
' COLLATE utf8_unicode_ci; -->';
237 print
'<!-- ALTER TABLE '.$table.
' MODIFY '.$row[0].
' '.$row[1].
' CHARACTER SET utf8; -->';
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.