dbtable.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /**
  22. * \file htdocs/admin/system/dbtable.php
  23. * \brief Page d'info des contraintes d'une table
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. $langs->load("admin");
  28. if (!$user->admin) {
  29. accessforbidden();
  30. }
  31. $table = GETPOST('table', 'alpha');
  32. /*
  33. * View
  34. */
  35. llxHeader();
  36. print load_fiche_titre($langs->trans("Table")." ".$table, '', 'title_setup');
  37. // Define request to get table description
  38. $base = 0;
  39. if (preg_match('/mysql/i', $conf->db->type)) {
  40. $sql = "SHOW TABLE STATUS LIKE '".$db->escape($table)."'";
  41. $base = 1;
  42. } elseif ($conf->db->type == 'pgsql') {
  43. $sql = "SELECT conname,contype FROM pg_constraint";
  44. $base = 2;
  45. }
  46. if (!$base) {
  47. print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
  48. } else {
  49. $resql = $db->query($sql);
  50. if ($resql) {
  51. $num = $db->num_rows($resql);
  52. $i = 0;
  53. while ($i < $num) {
  54. $row = $db->fetch_row($resql);
  55. $i++;
  56. }
  57. }
  58. if ($base == 1) { // mysql
  59. $link = array();
  60. $cons = explode(";", $row[14]);
  61. if (!empty($cons)) {
  62. foreach ($cons as $cc) {
  63. $cx = preg_replace("/\)\sREFER/", "", $cc);
  64. $cx = preg_replace("/\(`/", "", $cx);
  65. $cx = preg_replace("/`\)/", "", $cx);
  66. $cx = preg_replace("/`\s/", "", $cx);
  67. $val = explode("`", $cx);
  68. $link[trim($val[0])][0] = (isset($val[1]) ? $val[1] : '');
  69. $link[trim($val[0])][1] = (isset($val[2]) ? $val[2] : '');
  70. }
  71. }
  72. // var_dump($link);
  73. print '<table class="noborder">';
  74. print '<tr class="liste_titre">';
  75. print '<td>'.$langs->trans("Fields").'</td><td>'.$langs->trans("Type").'</td><td>'.$langs->trans("Index").'</td>';
  76. print '<td></td>';
  77. print '<td></td>';
  78. print '<td></td>';
  79. print '<td></td>';
  80. print '<td>'.$langs->trans("FieldsLinked").'</td>';
  81. print '</tr>';
  82. //$sql = "DESCRIBE ".$table;
  83. $sql = "SHOW FULL COLUMNS IN ".$db->escape($table);
  84. $resql = $db->query($sql);
  85. if ($resql) {
  86. $num = $db->num_rows($resql);
  87. $i = 0;
  88. while ($i < $num) {
  89. $row = $db->fetch_row($resql);
  90. print '<tr class="oddeven">';
  91. print "<td>".$row[0]."</td>";
  92. print "<td>".$row[1]."</td>";
  93. print "<td>".$row[3]."</td>";
  94. print "<td>".(empty($row[4]) ? '' : $row[4])."</td>";
  95. print "<td>".(empty($row[5]) ? '' : $row[5])."</td>";
  96. print "<td>".(empty($row[6]) ? '' : $row[6])."</td>";
  97. print "<td>".(empty($row[7]) ? '' : $row[7])."</td>";
  98. print "<td>".(isset($link[$row[0]][0]) ? $link[$row[0]][0] : '').".";
  99. print (isset($link[$row[0]][1]) ? $link[$row[0]][1] : '')."</td>";
  100. print '<!-- ALTER ALTER TABLE '.$table.' MODIFY '.$row[0].' '.$row[1].' COLLATE utf8_unicode_ci; -->';
  101. print '</tr>';
  102. $i++;
  103. }
  104. }
  105. print '</table>';
  106. }
  107. }
  108. // End of page
  109. llxFooter();
  110. $db->close();