dolibarr  x.y.z
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 // Load Dolibarr environment
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35 
36 $langs->load("admin");
37 
38 if (!$user->admin) {
40 }
41 
42 $action = GETPOST('action', 'aZ09');
43 
44 
45 /*
46  * Actions
47  */
48 
49 if ($action == 'convert') {
50  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ENGINE=INNODB";
51  $db->query($sql);
52 }
53 if ($action == 'convertutf8') {
54  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
55  $db->query($sql);
56 }
57 if ($action == 'convertdynamic') {
58  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ROW_FORMAT=DYNAMIC;";
59  $db->query($sql);
60 }
61 
62 
63 /*
64  * View
65  */
66 
67 llxHeader();
68 
69 print load_fiche_titre($langs->trans("Tables")." ".ucfirst($conf->db->type), '', 'title_setup');
70 
71 
72 // Define request to get table description
73 $base = 0;
74 if (preg_match('/mysql/i', $conf->db->type)) {
75  $sql = "SHOW TABLE STATUS";
76  $base = 1;
77 } elseif ($conf->db->type == 'pgsql') {
78  $sql = "SELECT conname, contype FROM pg_constraint;";
79  $base = 2;
80 } elseif ($conf->db->type == 'mssql') {
81  //$sqls[0] = "";
82  //$base=3;
83 } elseif ($conf->db->type == 'sqlite' || $conf->db->type == 'sqlite3') {
84  //$sql = "SELECT name, type FROM sqlite_master";
85  $base = 4;
86 }
87 
88 
89 if (!$base) {
90  print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
91 } else {
92  if ($base == 1) {
93  print '<div class="div-table-responsive-no-min">';
94  print '<table class="noborder">';
95  print '<tr class="liste_titre">';
96  print '<td>#</td>';
97  print '<td>'.$langs->trans("TableName").'</td>';
98  print '<td colspan="2">'.$langs->trans("Type").'</td>';
99  print '<td>'.$langs->trans("Format").'</td>';
100  print '<td class="right">'.$langs->trans("NbOfRecord").'</td>';
101  print '<td class="right">Avg_row_length</td>';
102  print '<td class="right">Data_length</td>';
103  print '<td class="right">Max_Data_length</td>';
104  print '<td class="right">Index_length</td>';
105  print '<td class="right">Increment</td>';
106  print '<td class="right">Last check</td>';
107  print '<td class="right">Collation</td>';
108  print "</tr>\n";
109 
110  $arrayoffilesrich = dol_dir_list(DOL_DOCUMENT_ROOT.'/install/mysql/tables/', 'files', 0, '\.sql$');
111  $arrayoffiles = array();
112  foreach ($arrayoffilesrich as $value) {
113  //print $shortsqlfilename.' ';
114  $shortsqlfilename = preg_replace('/\-[a-z]+\./', '.', $value['name']);
115  $arrayoffiles[] = $shortsqlfilename;
116  }
117 
118  $sql = "SHOW TABLE STATUS";
119 
120  $resql = $db->query($sql);
121  if ($resql) {
122  $num = $db->num_rows($resql);
123  $i = 0;
124  while ($i < $num) {
125  $obj = $db->fetch_object($resql);
126  print '<tr class="oddeven">';
127 
128  print '<td>'.($i+1).'</td>';
129  print '<td><a href="dbtable.php?table='.$obj->Name.'">'.$obj->Name.'</a>';
130  $tablename = preg_replace('/^'.MAIN_DB_PREFIX.'/', 'llx_', $obj->Name);
131 
132  if (in_array($tablename.'.sql', $arrayoffiles)) {
133  $img = "info";
134  //print img_picto($langs->trans("ExternalModule"), $img);
135  } else {
136  $img = "info_black";
137  //print DOL_DOCUMENT_ROOT.'/install/mysql/tables/'.$tablename.'.sql';
138  print img_picto($langs->trans("ExternalModule"), $img, 'class="small"');
139  }
140  print '</td>';
141  print '<td>'.$obj->Engine.'</td>';
142  if (isset($obj->Engine) && $obj->Engine == "MyISAM") {
143  print '<td><a class="reposition" href="database-tables.php?action=convert&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' InnoDb</a></td>';
144  } else {
145  print '<td>&nbsp;</td>';
146  }
147  print '<td>';
148  print $obj->Row_format;
149  if (isset($obj->Row_format) && (in_array($obj->Row_format, array("Compact")))) {
150  print '<br><a class="reposition" href="database-tables.php?action=convertdynamic&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' Dynamic</a>';
151  }
152  print '</td>';
153  print '<td align="right">'.$obj->Rows.'</td>';
154  print '<td align="right">'.$obj->Avg_row_length.'</td>';
155  print '<td align="right">'.$obj->Data_length.'</td>';
156  print '<td align="right">'.$obj->Max_data_length.'</td>';
157  print '<td align="right">'.$obj->Index_length.'</td>';
158  print '<td align="right">'.$obj->Auto_increment.'</td>';
159  print '<td align="right">'.$obj->Check_time.'</td>';
160  print '<td align="right">'.$obj->Collation;
161  if (isset($obj->Collation) && (in_array($obj->Collation, array("utf8mb4_general_ci", "utf8mb4_unicode_ci", "latin1_swedish_ci")))) {
162  print '<br><a class="reposition" href="database-tables.php?action=convertutf8&table='.urlencode($obj->Name).'&token='.newToken().'">'.$langs->trans("Convert").' UTF8</a>';
163  }
164  print '</td>';
165  print '</tr>';
166  $i++;
167  }
168  }
169  print '</table>';
170  print '</div>';
171  }
172 
173  if ($base == 2) {
174  print '<div class="div-table-responsive-no-min">';
175  print '<table class="noborder">';
176  print '<tr class="liste_titre">';
177 
178  print '<td>#</td>';
179  print '<td>'.$langs->trans("TableName").'</td>';
180  print '<td>Nb of tuples</td>';
181  print '<td>Nb index fetcher.</td>';
182  print '<td>Nb tuples insert</td>';
183  print '<td>Nb tuples modify</td>';
184  print '<td>Nb tuples delete</td>';
185  print "</tr>\n";
186 
187  $sql = "SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
188  $sql .= " FROM pg_stat_user_tables";
189 
190  $resql = $db->query($sql);
191  if ($resql) {
192  $num = $db->num_rows($resql);
193  $i = 0;
194  while ($i < $num) {
195  $row = $db->fetch_row($resql);
196  print '<tr class="oddeven">';
197  print '<td>'.($i+1).'</td>';
198  print '<td>'.$row[0].'</td>';
199  print '<td class="right">'.$row[1].'</td>';
200  print '<td class="right">'.$row[2].'</td>';
201  print '<td class="right">'.$row[3].'</td>';
202  print '<td class="right">'.$row[4].'</td>';
203  print '<td class="right">'.$row[5].'</td>';
204  print '</tr>';
205  $i++;
206  }
207  }
208  print '</table>';
209  print '</div>';
210  }
211 
212  if ($base == 4) {
213  // Sqlite by PDO or by Sqlite3
214  print '<div class="div-table-responsive-no-min">';
215  print '<table class="noborder">';
216  print '<tr class="liste_titre">';
217  print '<td>#</td>';
218  print '<td>'.$langs->trans("TableName").'</td>';
219  print '<td>'.$langs->trans("NbOfRecord").'</td>';
220  print "</tr>\n";
221 
222  $sql = "SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
223  $resql = $db->query($sql);
224 
225  if ($resql) {
226  while ($row = $db->fetch_row($resql)) {
227  $rescount = $db->query("SELECT COUNT(*) FROM ".$row[0]);
228  if ($rescount) {
229  $row_count = $db->fetch_row($rescount);
230  $count = $row_count[0];
231  } else {
232  $count = '?';
233  }
234 
235  print '<tr class="oddeven">';
236  print '<td>'.($i+1).'</td>';
237  print '<td>'.$row[0].'</td>';
238  print '<td>'.$count.'</td>';
239  print '</tr>';
240  }
241  }
242 
243  print '</table>';
244  print '</div>';
245  }
246 }
247 
248 // End of page
249 llxFooter();
250 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with 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)
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.