dbtable.php 3.6 KB

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