tbl_addfield.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. use PhpMyAdmin\CreateAddField;
  9. use PhpMyAdmin\Message;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Transformations;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\Util;
  14. /**
  15. * Get some core libraries
  16. */
  17. require_once 'libraries/common.inc.php';
  18. $response = Response::getInstance();
  19. $header = $response->getHeader();
  20. $scripts = $header->getScripts();
  21. $scripts->addFile('tbl_structure.js');
  22. // Check parameters
  23. Util::checkParameters(array('db', 'table'));
  24. /**
  25. * Defines the url to return to in case of error in a sql statement
  26. */
  27. $err_url = 'tbl_sql.php' . Url::getCommon(
  28. array(
  29. 'db' => $db, 'table' => $table
  30. )
  31. );
  32. /**
  33. * The form used to define the field to add has been submitted
  34. */
  35. $abort = false;
  36. // check number of fields to be created
  37. if (isset($_POST['submit_num_fields'])) {
  38. if (isset($_POST['orig_after_field'])) {
  39. $_POST['after_field'] = $_POST['orig_after_field'];
  40. }
  41. if (isset($_POST['orig_field_where'])) {
  42. $_POST['field_where'] = $_POST['orig_field_where'];
  43. }
  44. $num_fields = min(
  45. intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
  46. 4096
  47. );
  48. $regenerate = true;
  49. } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
  50. $num_fields = min(4096, intval($_POST['num_fields']));
  51. } else {
  52. $num_fields = 1;
  53. }
  54. if (isset($_POST['do_save_data'])) {
  55. //avoid an incorrect calling of PMA_updateColumns() via
  56. //tbl_structure.php below
  57. unset($_POST['do_save_data']);
  58. $createAddField = new CreateAddField($GLOBALS['dbi']);
  59. list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
  60. if ($result === true) {
  61. // Update comment table for mime types [MIME]
  62. if (isset($_POST['field_mimetype'])
  63. && is_array($_POST['field_mimetype'])
  64. && $cfg['BrowseMIME']
  65. ) {
  66. foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
  67. if (isset($_POST['field_name'][$fieldindex])
  68. && strlen($_POST['field_name'][$fieldindex]) > 0
  69. ) {
  70. Transformations::setMIME(
  71. $db, $table,
  72. $_POST['field_name'][$fieldindex],
  73. $mimetype,
  74. $_POST['field_transformation'][$fieldindex],
  75. $_POST['field_transformation_options'][$fieldindex],
  76. $_POST['field_input_transformation'][$fieldindex],
  77. $_POST['field_input_transformation_options'][$fieldindex]
  78. );
  79. }
  80. }
  81. }
  82. // Go back to the structure sub-page
  83. $message = Message::success(
  84. __('Table %1$s has been altered successfully.')
  85. );
  86. $message->addParam($table);
  87. $response->addJSON(
  88. 'message',
  89. Util::getMessage($message, $sql_query, 'success')
  90. );
  91. exit;
  92. } else {
  93. $error_message_html = Util::mysqlDie(
  94. '',
  95. '',
  96. false,
  97. $err_url,
  98. false
  99. );
  100. $response->addHTML($error_message_html);
  101. $response->setRequestStatus(false);
  102. exit;
  103. }
  104. } // end do alter table
  105. /**
  106. * Displays the form used to define the new field
  107. */
  108. if ($abort == false) {
  109. /**
  110. * Gets tables information
  111. */
  112. include_once 'libraries/tbl_common.inc.php';
  113. $active_page = 'tbl_structure.php';
  114. /**
  115. * Display the form
  116. */
  117. $action = 'tbl_addfield.php';
  118. include_once 'libraries/tbl_columns_definition_form.inc.php';
  119. }