display_create_table.lib.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays form for creating a table (if user has privileges for that)
  5. *
  6. * for MySQL >= 4.1.0, we should be able to detect if user has a CREATE
  7. * privilege by looking at SHOW GRANTS output;
  8. * for < 4.1.0, it could be more difficult because the logic tries to
  9. * detect the current host and it might be expressed in many ways; also
  10. * on a shared server, the user might be unable to define a controluser
  11. * that has the proper rights to the "mysql" db;
  12. * so we give up and assume that user has the right to create a table
  13. *
  14. * Note: in this case we could even skip the following "foreach" logic
  15. *
  16. * Addendum, 2006-01-19: ok, I give up. We got some reports about servers
  17. * where the hostname field in mysql.user is not the same as the one
  18. * in mysql.db for a user. In this case, SHOW GRANTS does not return
  19. * the db-specific privileges. And probably, those users are on a shared
  20. * server, so can't set up a control user with rights to the "mysql" db.
  21. * We cannot reliably detect the db-specific privileges, so no more
  22. * warnings about the lack of privileges for CREATE TABLE. Tested
  23. * on MySQL 5.0.18.
  24. *
  25. * @package PhpMyAdmin
  26. */
  27. if (! defined('PHPMYADMIN')) {
  28. exit;
  29. }
  30. /**
  31. *
  32. */
  33. require_once './libraries/check_user_privileges.lib.php';
  34. $is_create_table_priv = true;
  35. /**
  36. * Returns the html for create table.
  37. *
  38. * @param string $db database name
  39. *
  40. * @return string
  41. */
  42. function PMA_getHtmlForCreateTable($db)
  43. {
  44. $html = '<form id="create_table_form_minimal" method="post" '
  45. . 'action="tbl_create.php">';
  46. $html .= '<fieldset>';
  47. $html .= '<legend>';
  48. if (PMA_Util::showIcons('ActionLinksMode')) {
  49. $html .= PMA_Util::getImage('b_newtbl.png');
  50. }
  51. $html .= __('Create table');
  52. $html .= ' </legend>';
  53. $html .= PMA_URL_getHiddenInputs($db);
  54. $html .= '<div class="formelement">';
  55. $html .= __('Name') . ":";
  56. $html .= ' <input type="text" name="table" maxlength="64" '
  57. . 'size="30" required="required" />';
  58. $html .= ' </div>';
  59. $html .= ' <div class="formelement">';
  60. $html .= __('Number of columns') . ":";
  61. $html .= ' <input type="number" min="1" name="num_fields" value="4" required="required" />';
  62. $html .= ' </div>';
  63. $html .= ' <div class="clearfloat"></div>';
  64. $html .= '</fieldset>';
  65. $html .= '<fieldset class="tblFooters">';
  66. $html .= ' <input type="submit" value="' . __('Go') . '" />';
  67. $html .= '</fieldset>';
  68. $html .= '</form>';
  69. return $html;
  70. }
  71. if (!defined('TESTSUITE')) {
  72. echo PMA_getHtmlForCreateTable($db);
  73. }
  74. ?>