dolibarr  16.0.5
database-tables.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 if (! defined('CSRFCHECK_WITH_TOKEN')) {
28  define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
29 }
30 
31 require '../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 
35 $langs->load("admin");
36 
37 if (!$user->admin) {
39 }
40 
41 $action = GETPOST('action', 'aZ09');
42 
43 
44 /*
45  * Actions
46  */
47 
48 if ($action == 'convert') {
49  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ENGINE=INNODB";
50  $db->query($sql);
51 }
52 if ($action == 'convertutf8') {
53  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
54  $db->query($sql);
55 }
56 if ($action == 'convertdynamic') {
57  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ROW_FORMAT=DYNAMIC;";
58  $db->query($sql);
59 }
60 
61 
62 /*
63  * View
64  */
65 
66 llxHeader();
67 
68 print load_fiche_titre($langs->trans("Tables")." ".ucfirst($conf->db->type), '', 'title_setup');
69 
70 
71 // Define request to get table description
72 $base = 0;
73 if (preg_match('/mysql/i', $conf->db->type)) {
74  $sql = "SHOW TABLE STATUS";
75  $base = 1;
76 } elseif ($conf->db->type == 'pgsql') {
77  $sql = "SELECT conname, contype FROM pg_constraint;";
78  $base = 2;
79 } elseif ($conf->db->type == 'mssql') {
80  //$sqls[0] = "";
81  //$base=3;
82 } elseif ($conf->db->type == 'sqlite' || $conf->db->type == 'sqlite3') {
83  //$sql = "SELECT name, type FROM sqlite_master";
84  $base = 4;
85 }
86 
87 
88 if (!$base) {
89  print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
90 } else {
91  if ($base == 1) {
92  print '<div class="div-table-responsive-no-min">';
93  print '<table class="noborder">';
94  print '<tr class="liste_titre">';
95  print '<td>#</td>';
96  print '<td>'.$langs->trans("TableName").'</td>';
97  print '<td colspan="2">'.$langs->trans("Type").'</td>';
98  print '<td>'.$langs->trans("Format").'</td>';
99  print '<td class="right">'.$langs->trans("NbOfRecord").'</td>';
100  print '<td class="right">Avg_row_length</td>';
101  print '<td class="right">Data_length</td>';
102  print '<td class="right">Max_Data_length</td>';
103  print '<td class="right">Index_length</td>';
104  print '<td class="right">Increment</td>';
105  print '<td class="right">Last check</td>';
106  print '<td class="right">Collation</td>';
107  print "</tr>\n";
108 
109  $arrayoffilesrich = dol_dir_list(DOL_DOCUMENT_ROOT.'/install/mysql/tables/', 'files', 0, '\.sql$');
110  $arrayoffiles = array();
111  foreach ($arrayoffilesrich as $value) {
112  //print $shortsqlfilename.' ';
113  $shortsqlfilename = preg_replace('/\-[a-z]+\./', '.', $value['name']);
114  $arrayoffiles[] = $shortsqlfilename;
115  }
116 
117  $sql = "SHOW TABLE STATUS";
118 
119  $resql = $db->query($sql);
120  if ($resql) {
121  $num = $db->num_rows($resql);
122  $i = 0;
123  while ($i < $num) {
124  $obj = $db->fetch_object($resql);
125  print '<tr class="oddeven">';
126 
127  print '<td>'.($i+1).'</td>';
128  print '<td><a href="dbtable.php?table='.$obj->Name.'">'.$obj->Name.'</a>';
129  $tablename = preg_replace('/^'.MAIN_DB_PREFIX.'/', 'llx_', $obj->Name);
130 
131  if (in_array($tablename.'.sql', $arrayoffiles)) {
132  $img = "info";
133  //print img_picto($langs->trans("ExternalModule"), $img);
134  } else {
135  $img = "info_black";
136  //print DOL_DOCUMENT_ROOT.'/install/mysql/tables/'.$tablename.'.sql';
137  print img_picto($langs->trans("ExternalModule"), $img, 'class="small"');
138  }
139  print '</td>';
140  print '<td>'.$obj->Engine.'</td>';
141  if (isset($obj->Engine) && $obj->Engine == "MyISAM") {
142  print '<td><a class="reposition" href="database-tables.php?action=convert&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' InnoDb</a></td>';
143  } else {
144  print '<td>&nbsp;</td>';
145  }
146  print '<td>';
147  print $obj->Row_format;
148  if (isset($obj->Row_format) && (in_array($obj->Row_format, array("Compact")))) {
149  print '<br><a class="reposition" href="database-tables.php?action=convertdynamic&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' Dynamic</a>';
150  }
151  print '</td>';
152  print '<td align="right">'.$obj->Rows.'</td>';
153  print '<td align="right">'.$obj->Avg_row_length.'</td>';
154  print '<td align="right">'.$obj->Data_length.'</td>';
155  print '<td align="right">'.$obj->Max_data_length.'</td>';
156  print '<td align="right">'.$obj->Index_length.'</td>';
157  print '<td align="right">'.$obj->Auto_increment.'</td>';
158  print '<td align="right">'.$obj->Check_time.'</td>';
159  print '<td align="right">'.$obj->Collation;
160  if (isset($obj->Collation) && (in_array($obj->Collation, array("utf8mb4_general_ci", "utf8mb4_unicode_ci", "latin1_swedish_ci")))) {
161  print '<br><a class="reposition" href="database-tables.php?action=convertutf8&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' UTF8</a>';
162  }
163  print '</td>';
164  print '</tr>';
165  $i++;
166  }
167  }
168  print '</table>';
169  print '</div>';
170  }
171 
172  if ($base == 2) {
173  print '<div class="div-table-responsive-no-min">';
174  print '<table class="noborder">';
175  print '<tr class="liste_titre">';
176 
177  print '<td>#</td>';
178  print '<td>'.$langs->trans("TableName").'</td>';
179  print '<td>Nb of tuples</td>';
180  print '<td>Nb index fetcher.</td>';
181  print '<td>Nb tuples insert</td>';
182  print '<td>Nb tuples modify</td>';
183  print '<td>Nb tuples delete</td>';
184  print "</tr>\n";
185 
186  $sql = "SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
187  $sql .= " FROM pg_stat_user_tables";
188 
189  $resql = $db->query($sql);
190  if ($resql) {
191  $num = $db->num_rows($resql);
192  $i = 0;
193  while ($i < $num) {
194  $row = $db->fetch_row($resql);
195  print '<tr class="oddeven">';
196  print '<td>'.($i+1).'</td>';
197  print '<td>'.$row[0].'</td>';
198  print '<td class="right">'.$row[1].'</td>';
199  print '<td class="right">'.$row[2].'</td>';
200  print '<td class="right">'.$row[3].'</td>';
201  print '<td class="right">'.$row[4].'</td>';
202  print '<td class="right">'.$row[5].'</td>';
203  print '</tr>';
204  $i++;
205  }
206  }
207  print '</table>';
208  print '</div>';
209  }
210 
211  if ($base == 4) {
212  // Sqlite by PDO or by Sqlite3
213  print '<div class="div-table-responsive-no-min">';
214  print '<table class="noborder">';
215  print '<tr class="liste_titre">';
216  print '<td>#</td>';
217  print '<td>'.$langs->trans("TableName").'</td>';
218  print '<td>'.$langs->trans("NbOfRecord").'</td>';
219  print "</tr>\n";
220 
221  $sql = "SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
222  $resql = $db->query($sql);
223 
224  if ($resql) {
225  while ($row = $db->fetch_row($resql)) {
226  $rescount = $db->query("SELECT COUNT(*) FROM ".$row[0]);
227  if ($rescount) {
228  $row_count = $db->fetch_row($rescount);
229  $count = $row_count[0];
230  } else {
231  $count = '?';
232  }
233 
234  print '<tr class="oddeven">';
235  print '<td>'.($i+1).'</td>';
236  print '<td>'.$row[0].'</td>';
237  print '<td>'.$count.'</td>';
238  print '</tr>';
239  }
240  }
241 
242  print '</table>';
243  print '</div>';
244  }
245 }
246 
247 // End of page
248 llxFooter();
249 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59