tbl_addfield.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays add field form and handles it
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Get some core libraries
  10. */
  11. require_once 'libraries/common.inc.php';
  12. $response = PMA_Response::getInstance();
  13. $header = $response->getHeader();
  14. $scripts = $header->getScripts();
  15. $scripts->addFile('tbl_structure.js');
  16. // Check parameters
  17. PMA_Util::checkParameters(array('db', 'table'));
  18. /**
  19. * Defines the url to return to in case of error in a sql statement
  20. */
  21. $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table);
  22. /**
  23. * The form used to define the field to add has been submitted
  24. */
  25. $abort = false;
  26. // check number of fields to be created
  27. if (isset($_REQUEST['submit_num_fields'])) {
  28. if (isset($_REQUEST['orig_after_field'])) {
  29. $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
  30. }
  31. if (isset($_REQUEST['orig_field_where'])) {
  32. $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
  33. }
  34. $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
  35. $regenerate = true;
  36. } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
  37. $num_fields = (int) $_REQUEST['num_fields'];
  38. } else {
  39. $num_fields = 1;
  40. }
  41. if (isset($_REQUEST['do_save_data'])) {
  42. //avoid an incorrect calling of PMA_updateColumns() via
  43. //tbl_structure.php below
  44. unset($_REQUEST['do_save_data']);
  45. include_once 'libraries/create_addfield.lib.php';
  46. list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
  47. if ($result === true) {
  48. // If comments were sent, enable relation stuff
  49. include_once 'libraries/transformations.lib.php';
  50. // Update comment table for mime types [MIME]
  51. if (isset($_REQUEST['field_mimetype'])
  52. && is_array($_REQUEST['field_mimetype'])
  53. && $cfg['BrowseMIME']
  54. ) {
  55. foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
  56. if (isset($_REQUEST['field_name'][$fieldindex])
  57. && strlen($_REQUEST['field_name'][$fieldindex])
  58. ) {
  59. PMA_setMIME(
  60. $db, $table,
  61. $_REQUEST['field_name'][$fieldindex],
  62. $mimetype,
  63. $_REQUEST['field_transformation'][$fieldindex],
  64. $_REQUEST['field_transformation_options'][$fieldindex]
  65. );
  66. }
  67. }
  68. }
  69. // Go back to the structure sub-page
  70. $message = PMA_Message::success(
  71. __('Table %1$s has been altered successfully.')
  72. );
  73. $message->addParam($table);
  74. $response->addJSON('message', $message);
  75. $response->addJSON(
  76. 'sql_query',
  77. PMA_Util::getMessage(null, $sql_query)
  78. );
  79. exit;
  80. } else {
  81. $error_message_html = PMA_Util::mysqlDie('', '', '', $err_url, false);
  82. $response->addHTML($error_message_html);
  83. exit;
  84. }
  85. } // end do alter table
  86. /**
  87. * Displays the form used to define the new field
  88. */
  89. if ($abort == false) {
  90. /**
  91. * Gets tables informations
  92. */
  93. include_once 'libraries/tbl_common.inc.php';
  94. include_once 'libraries/tbl_info.inc.php';
  95. $active_page = 'tbl_structure.php';
  96. /**
  97. * Display the form
  98. */
  99. $action = 'tbl_addfield.php';
  100. include_once 'libraries/tbl_columns_definition_form.inc.php';
  101. }
  102. ?>