dolibarr  13.0.2
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-2005 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 require '../../main.inc.php';
28 
29 $langs->load("admin");
30 
31 if (!$user->admin) {
33 }
34 
35 $action = GETPOST('action', 'aZ09');
36 
37 
38 if ($action == 'convert')
39 {
40  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ENGINE=INNODB";
41  $db->query($sql);
42 }
43 if ($action == 'convertutf8')
44 {
45  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
46  $db->query($sql);
47 }
48 if ($action == 'convertdynamic')
49 {
50  $sql = "ALTER TABLE ".$db->escape(GETPOST("table", "aZ09"))." ROW_FORMAT=DYNAMIC;";
51  $db->query($sql);
52 }
53 
54 
55 /*
56  * View
57  */
58 
59 llxHeader();
60 
61 print load_fiche_titre($langs->trans("Tables")." ".ucfirst($conf->db->type), '', 'title_setup');
62 
63 
64 // Define request to get table description
65 $base = 0;
66 if (preg_match('/mysql/i', $conf->db->type))
67 {
68  $sql = "SHOW TABLE STATUS";
69  $base = 1;
70 } elseif ($conf->db->type == 'pgsql')
71 {
72  $sql = "SELECT conname, contype FROM pg_constraint;";
73  $base = 2;
74 } elseif ($conf->db->type == 'mssql')
75 {
76  //$sqls[0] = "";
77  //$base=3;
78 } elseif ($conf->db->type == 'sqlite' || $conf->db->type == 'sqlite3')
79 {
80  //$sql = "SELECT name, type FROM sqlite_master";
81  $base = 4;
82 }
83 
84 
85 if (!$base)
86 {
87  print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
88 } else {
89  if ($base == 1)
90  {
91  print '<div class="div-table-responsive-no-min">';
92  print '<table class="noborder">';
93  print '<tr class="liste_titre">';
94  print '<td>'.$langs->trans("TableName").'</td>';
95  print '<td colspan="2">'.$langs->trans("Type").'</td>';
96  print '<td>'.$langs->trans("Format").'</td>';
97  print '<td class="right">'.$langs->trans("NbOfRecord").'</td>';
98  print '<td class="right">Avg_row_length</td>';
99  print '<td class="right">Data_length</td>';
100  print '<td class="right">Max_Data_length</td>';
101  print '<td class="right">Index_length</td>';
102  print '<td class="right">Increment</td>';
103  print '<td class="right">Last check</td>';
104  print '<td class="right">Collation</td>';
105  print "</tr>\n";
106 
107  $sql = "SHOW TABLE STATUS";
108 
109  $resql = $db->query($sql);
110  if ($resql)
111  {
112  $num = $db->num_rows($resql);
113  $i = 0;
114  while ($i < $num)
115  {
116  $obj = $db->fetch_object($resql);
117  print '<tr class="oddeven">';
118 
119  print '<td><a href="dbtable.php?table='.$obj->Name.'">'.$obj->Name.'</a></td>';
120  print '<td>'.$obj->Engine.'</td>';
121  if (isset($obj->Engine) && $obj->Engine == "MyISAM") {
122  print '<td><a class="reposition" href="database-tables.php?action=convert&amp;table='.$obj->Name.'">'.$langs->trans("Convert").' InnoDb</a></td>';
123  } else {
124  print '<td>&nbsp;</td>';
125  }
126  print '<td>';
127  print $obj->Row_format;
128  if (isset($obj->Row_format) && (in_array($obj->Row_format, array("Compact")))) {
129  print '<br><a class="reposition" href="database-tables.php?action=convertdynamic&amp;table='.$obj->Name.'">'.$langs->trans("Convert").' Dynamic</a>';
130  }
131  print '</td>';
132  print '<td align="right">'.$obj->Rows.'</td>';
133  print '<td align="right">'.$obj->Avg_row_length.'</td>';
134  print '<td align="right">'.$obj->Data_length.'</td>';
135  print '<td align="right">'.$obj->Max_data_length.'</td>';
136  print '<td align="right">'.$obj->Index_length.'</td>';
137  print '<td align="right">'.$obj->Auto_increment.'</td>';
138  print '<td align="right">'.$obj->Check_time.'</td>';
139  print '<td align="right">'.$obj->Collation;
140  if (isset($obj->Collation) && (in_array($obj->Collation, array("utf8mb4_general_ci", "utf8mb4_unicode_ci", "latin1_swedish_ci")))) {
141  print '<br><a class="reposition" href="database-tables.php?action=convertutf8&amp;table='.$obj->Name.'">'.$langs->trans("Convert").' UTF8</a>';
142  }
143  print '</td>';
144  print '</tr>';
145  $i++;
146  }
147  }
148  print '</table>';
149  print '</div>';
150  }
151 
152  if ($base == 2)
153  {
154  print '<div class="div-table-responsive-no-min">';
155  print '<table class="noborder">';
156  print '<tr class="liste_titre">';
157  print '<td>'.$langs->trans("TableName").'</td>';
158  print '<td>Nb of tuples</td>';
159  print '<td>Nb index fetcher.</td>';
160  print '<td>Nb tuples insert</td>';
161  print '<td>Nb tuples modify</td>';
162  print '<td>Nb tuples delete</td>';
163  print "</tr>\n";
164 
165  $sql = "SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
166  $sql .= " FROM pg_stat_user_tables";
167 
168  $resql = $db->query($sql);
169  if ($resql)
170  {
171  $num = $db->num_rows($resql);
172  $i = 0;
173  while ($i < $num)
174  {
175  $row = $db->fetch_row($resql);
176  print '<tr class="oddeven">';
177  print '<td>'.$row[0].'</td>';
178  print '<td class="right">'.$row[1].'</td>';
179  print '<td class="right">'.$row[2].'</td>';
180  print '<td class="right">'.$row[3].'</td>';
181  print '<td class="right">'.$row[4].'</td>';
182  print '<td class="right">'.$row[5].'</td>';
183  print '</tr>';
184  $i++;
185  }
186  }
187  print '</table>';
188  print '</div>';
189  }
190 
191  if ($base == 4)
192  {
193  // Sqlite by PDO or by Sqlite3
194  print '<div class="div-table-responsive-no-min">';
195  print '<table class="noborder">';
196  print '<tr class="liste_titre">';
197  print '<td>'.$langs->trans("TableName").'</td>';
198  print '<td>'.$langs->trans("NbOfRecord").'</td>';
199  print "</tr>\n";
200 
201  $sql = "SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
202  $resql = $db->query($sql);
203 
204  if ($resql)
205  {
206  while ($row = $db->fetch_row($resql)) {
207  $rescount = $db->query("SELECT COUNT(*) FROM ".$row[0]);
208  if ($rescount) {
209  $row_count = $db->fetch_row($rescount);
210  $count = $row_count[0];
211  } else {
212  $count = '?';
213  }
214 
215  print '<tr class="oddeven">';
216  print '<td>'.$row[0].'</td>';
217  print '<td>'.$count.'</td>';
218  print '</tr>';
219  }
220  }
221 
222  print '</table>';
223  print '</div>';
224  }
225 }
226 
227 // End of page
228 llxFooter();
229 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 ...
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
llxFooter()
Empty footer.
Definition: wrapper.php:59