tbl_change.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays form for editing and inserting new table rows
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Config\PageSettings;
  9. use PhpMyAdmin\InsertEdit;
  10. use PhpMyAdmin\Relation;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\Util;
  13. use PhpMyAdmin\Url;
  14. /**
  15. * Gets the variables sent or posted to this script and displays the header
  16. */
  17. require_once 'libraries/common.inc.php';
  18. PageSettings::showGroup('Edit');
  19. /**
  20. * Ensures db and table are valid, else moves to the "parent" script
  21. */
  22. require_once 'libraries/db_table_exists.inc.php';
  23. $insertEdit = new InsertEdit($GLOBALS['dbi']);
  24. /**
  25. * Determine whether Insert or Edit and set global variables
  26. */
  27. list(
  28. $insert_mode, $where_clause, $where_clause_array, $where_clauses,
  29. $result, $rows, $found_unique_key, $after_insert
  30. ) = $insertEdit->determineInsertOrEdit(
  31. isset($where_clause) ? $where_clause : null, $db, $table
  32. );
  33. // Increase number of rows if unsaved rows are more
  34. if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
  35. $rows = array_fill(0, count($unsaved_values), false);
  36. }
  37. /**
  38. * Defines the url to return to in case of error in a sql statement
  39. * (at this point, $GLOBALS['goto'] will be set but could be empty)
  40. */
  41. if (empty($GLOBALS['goto'])) {
  42. if (strlen($table) > 0) {
  43. // avoid a problem (see bug #2202709)
  44. $GLOBALS['goto'] = 'tbl_sql.php';
  45. } else {
  46. $GLOBALS['goto'] = 'db_sql.php';
  47. }
  48. }
  49. $_url_params = $insertEdit->getUrlParameters($db, $table);
  50. $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
  51. unset($_url_params);
  52. $comments_map = $insertEdit->getCommentsMap($db, $table);
  53. /**
  54. * START REGULAR OUTPUT
  55. */
  56. /**
  57. * Load JavaScript files
  58. */
  59. $response = Response::getInstance();
  60. $header = $response->getHeader();
  61. $scripts = $header->getScripts();
  62. $scripts->addFile('sql.js');
  63. $scripts->addFile('tbl_change.js');
  64. $scripts->addFile('vendor/jquery/additional-methods.js');
  65. $scripts->addFile('gis_data_editor.js');
  66. /**
  67. * Displays the query submitted and its result
  68. *
  69. * $disp_message come from tbl_replace.php
  70. */
  71. if (! empty($disp_message)) {
  72. $response->addHTML(Util::getMessage($disp_message, null));
  73. }
  74. $table_columns = $insertEdit->getTableColumns($db, $table);
  75. // retrieve keys into foreign fields, if any
  76. $relation = new Relation();
  77. $foreigners = $relation->getForeigners($db, $table);
  78. // Retrieve form parameters for insert/edit form
  79. $_form_params = $insertEdit->getFormParametersForInsertForm(
  80. $db, $table, $where_clauses, $where_clause_array, $err_url
  81. );
  82. /**
  83. * Displays the form
  84. */
  85. // autocomplete feature of IE kills the "onchange" event handler and it
  86. // must be replaced by the "onpropertychange" one in this case
  87. $chg_evt_handler = 'onchange';
  88. // Had to put the URI because when hosted on an https server,
  89. // some browsers send wrongly this form to the http server.
  90. $html_output = '';
  91. // Set if we passed the first timestamp field
  92. $timestamp_seen = false;
  93. $columns_cnt = count($table_columns);
  94. $tabindex = 0;
  95. $tabindex_for_function = +3000;
  96. $tabindex_for_null = +6000;
  97. $tabindex_for_value = 0;
  98. $o_rows = 0;
  99. $biggest_max_file_size = 0;
  100. $url_params['db'] = $db;
  101. $url_params['table'] = $table;
  102. $url_params = $insertEdit->urlParamsInEditMode(
  103. $url_params, $where_clause_array
  104. );
  105. $has_blob_field = false;
  106. foreach ($table_columns as $column) {
  107. if ($insertEdit->isColumn(
  108. $column,
  109. array('blob', 'tinyblob', 'mediumblob', 'longblob')
  110. )) {
  111. $has_blob_field = true;
  112. break;
  113. }
  114. }
  115. //Insert/Edit form
  116. //If table has blob fields we have to disable ajax.
  117. $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
  118. $html_output .= Url::getHiddenInputs($_form_params);
  119. $titles['Browse'] = Util::getIcon('b_browse', __('Browse foreign values'));
  120. // user can toggle the display of Function column and column types
  121. // (currently does not work for multi-edits)
  122. if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
  123. $html_output .= __('Show');
  124. }
  125. if (! $cfg['ShowFunctionFields']) {
  126. $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
  127. }
  128. if (! $cfg['ShowFieldTypesInDataEditView']) {
  129. $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
  130. }
  131. $GLOBALS['plugin_scripts'] = array();
  132. foreach ($rows as $row_id => $current_row) {
  133. if (empty($current_row)) {
  134. $current_row = array();
  135. }
  136. $jsvkey = $row_id;
  137. $vkey = '[multi_edit][' . $jsvkey . ']';
  138. $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
  139. ? $result[$row_id]
  140. : $result);
  141. $repopulate = array();
  142. $checked = true;
  143. if (isset($unsaved_values[$row_id])) {
  144. $repopulate = $unsaved_values[$row_id];
  145. $checked = false;
  146. }
  147. if ($insert_mode && $row_id > 0) {
  148. $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
  149. }
  150. $html_output .= $insertEdit->getHtmlForInsertEditRow(
  151. $url_params, $table_columns, $comments_map, $timestamp_seen,
  152. $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
  153. $current_row, $o_rows, $tabindex, $columns_cnt,
  154. $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
  155. $tabindex_for_value, $table, $db, $row_id, $titles,
  156. $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
  157. );
  158. } // end foreach on multi-edit
  159. $scripts->addFiles($GLOBALS['plugin_scripts']);
  160. unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
  161. if (! isset($after_insert)) {
  162. $after_insert = 'back';
  163. }
  164. //action panel
  165. $html_output .= $insertEdit->getActionsPanel(
  166. $where_clause, $after_insert, $tabindex,
  167. $tabindex_for_value, $found_unique_key
  168. );
  169. if ($biggest_max_file_size > 0) {
  170. $html_output .= ' '
  171. . Util::generateHiddenMaxFileSize(
  172. $biggest_max_file_size
  173. ) . "\n";
  174. }
  175. $html_output .= '</form>';
  176. $html_output .= $insertEdit->getHtmlForGisEditor();
  177. // end Insert/Edit form
  178. if ($insert_mode) {
  179. //Continue insertion form
  180. $html_output .= $insertEdit->getContinueInsertionForm(
  181. $table, $db, $where_clause_array, $err_url
  182. );
  183. }
  184. $response->addHTML($html_output);