tbl_change.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. * register_globals_save (mark this file save for disabling register globals)
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. /**
  11. * Gets the variables sent or posted to this script and displays the header
  12. */
  13. require_once 'libraries/common.inc.php';
  14. /**
  15. * Ensures db and table are valid, else moves to the "parent" script
  16. */
  17. require_once 'libraries/db_table_exists.lib.php';
  18. /**
  19. * functions implementation for this script
  20. */
  21. require_once 'libraries/insert_edit.lib.php';
  22. /**
  23. * Determine whether Insert or Edit and set global variables
  24. */
  25. list(
  26. $insert_mode, $where_clause, $where_clause_array, $where_clauses,
  27. $result, $rows, $found_unique_key, $after_insert
  28. ) = PMA_determineInsertOrEdit(
  29. isset($where_clause) ? $where_clause : null, $db, $table
  30. );
  31. /**
  32. * file listing
  33. */
  34. require_once 'libraries/file_listing.lib.php';
  35. /**
  36. * Defines the url to return to in case of error in a sql statement
  37. * (at this point, $GLOBALS['goto'] will be set but could be empty)
  38. */
  39. if (empty($GLOBALS['goto'])) {
  40. if (strlen($table)) {
  41. // avoid a problem (see bug #2202709)
  42. $GLOBALS['goto'] = 'tbl_sql.php';
  43. } else {
  44. $GLOBALS['goto'] = 'db_sql.php';
  45. }
  46. }
  47. $_url_params = PMA_getUrlParameters($db, $table);
  48. $err_url = $GLOBALS['goto'] . PMA_URL_getCommon($_url_params);
  49. unset($_url_params);
  50. $comments_map = PMA_getCommentsMap($db, $table);
  51. /**
  52. * START REGULAR OUTPUT
  53. */
  54. /**
  55. * Load JavaScript files
  56. */
  57. $response = PMA_Response::getInstance();
  58. $header = $response->getHeader();
  59. $scripts = $header->getScripts();
  60. $scripts->addFile('functions.js');
  61. $scripts->addFile('tbl_change.js');
  62. $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
  63. $scripts->addFile('gis_data_editor.js');
  64. /**
  65. * Displays the query submitted and its result
  66. *
  67. * $disp_message come from tbl_replace.php
  68. */
  69. if (! empty($disp_message)) {
  70. $response->addHTML(PMA_Util::getMessage($disp_message, null));
  71. }
  72. // used as a global by PMA_Util::getDefaultFunctionForField()
  73. $analyzed_sql = PMA_Table::analyzeStructure($db, $table);
  74. $table_columns = PMA_getTableColumns($db, $table);
  75. // retrieve keys into foreign fields, if any
  76. $foreigners = PMA_getForeigners($db, $table);
  77. // Retrieve form parameters for insert/edit form
  78. $_form_params = PMA_getFormParametersForInsertForm(
  79. $db, $table, $where_clauses, $where_clause_array, $err_url
  80. );
  81. /**
  82. * Displays the form
  83. */
  84. // autocomplete feature of IE kills the "onchange" event handler and it
  85. // must be replaced by the "onpropertychange" one in this case
  86. $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE'
  87. && PMA_USR_BROWSER_VER >= 5
  88. && PMA_USR_BROWSER_VER < 7
  89. )
  90. ? 'onpropertychange'
  91. : 'onchange';
  92. // Had to put the URI because when hosted on an https server,
  93. // some browsers send wrongly this form to the http server.
  94. $html_output = '';
  95. // Set if we passed the first timestamp field
  96. $timestamp_seen = false;
  97. $columns_cnt = count($table_columns);
  98. $tabindex = 0;
  99. $tabindex_for_function = +3000;
  100. $tabindex_for_null = +6000;
  101. $tabindex_for_value = 0;
  102. $o_rows = 0;
  103. $biggest_max_file_size = 0;
  104. $url_params['db'] = $db;
  105. $url_params['table'] = $table;
  106. $url_params = PMA_urlParamsInEditMode(
  107. $url_params, $where_clause_array, $where_clause
  108. );
  109. $has_blob_field = false;
  110. foreach ($table_columns as $column) {
  111. if (PMA_isColumnBlob($column)) {
  112. $has_blob_field = true;
  113. break;
  114. }
  115. }
  116. //Insert/Edit form
  117. //If table has blob fields we have to disable ajax.
  118. $html_output .= PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
  119. $html_output .= PMA_URL_getHiddenInputs($_form_params);
  120. $titles['Browse'] = PMA_Util::getIcon('b_browse.png', __('Browse foreign values'));
  121. // user can toggle the display of Function column and column types
  122. // (currently does not work for multi-edits)
  123. if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
  124. $html_output .= __('Show');
  125. }
  126. if (! $cfg['ShowFunctionFields']) {
  127. $html_output .= PMA_showFunctionFieldsInEditMode($url_params, false);
  128. }
  129. if (! $cfg['ShowFieldTypesInDataEditView']) {
  130. $html_output .= PMA_showColumnTypesInDataEditView($url_params, false);
  131. }
  132. foreach ($rows as $row_id => $current_row) {
  133. if ($current_row === false) {
  134. unset($current_row);
  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. if ($insert_mode && $row_id > 0) {
  142. $html_output .= PMA_getHtmlForIgnoreOption($row_id);
  143. }
  144. $html_output .= PMA_getHtmlForInsertEditRow(
  145. $url_params, $table_columns, $column, $comments_map, $timestamp_seen,
  146. $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
  147. isset($current_row) ? $current_row : null, $o_rows, $tabindex, $columns_cnt,
  148. $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
  149. $tabindex_for_value, $table, $db, $row_id, $titles,
  150. $biggest_max_file_size, $text_dir
  151. );
  152. } // end foreach on multi-edit
  153. $html_output .= PMA_getHtmlForGisEditor();
  154. if (! isset($after_insert)) {
  155. $after_insert = 'back';
  156. }
  157. //action panel
  158. $html_output .= PMA_getActionsPanel(
  159. $where_clause, $after_insert, $tabindex,
  160. $tabindex_for_value, $found_unique_key
  161. );
  162. if ($biggest_max_file_size > 0) {
  163. $html_output .= ' '
  164. . PMA_Util::generateHiddenMaxFileSize(
  165. $biggest_max_file_size
  166. ) . "\n";
  167. }
  168. $html_output .= '</form>';
  169. // end Insert/Edit form
  170. if ($insert_mode) {
  171. //Continue insertion form
  172. $html_output .= PMA_getContinueInsertionForm(
  173. $table, $db, $where_clause_array, $err_url
  174. );
  175. }
  176. $response->addHTML($html_output);
  177. ?>