2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
10 use PMA\libraries\config\PageSettings
;
11 use PMA\libraries\Response
;
12 use PMA\libraries\Util
;
15 * Gets the variables sent or posted to this script and displays the header
17 require_once 'libraries/common.inc.php';
18 require_once 'libraries/config/user_preferences.forms.php';
19 require_once 'libraries/config/page_settings.forms.php';
21 PageSettings
::showGroup('Edit');
24 * Ensures db and table are valid, else moves to the "parent" script
26 require_once 'libraries/db_table_exists.lib.php';
29 * functions implementation for this script
31 require_once 'libraries/insert_edit.lib.php';
32 require_once 'libraries/transformations.lib.php';
35 * Determine whether Insert or Edit and set global variables
38 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
39 $result, $rows, $found_unique_key, $after_insert
40 ) = PMA_determineInsertOrEdit(
41 isset($where_clause) ?
$where_clause : null, $db, $table
43 // Increase number of rows if unsaved rows are more
44 if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
45 $rows = array_fill(0, count($unsaved_values), false);
50 require_once 'libraries/file_listing.lib.php';
53 * Defines the url to return to in case of error in a sql statement
54 * (at this point, $GLOBALS['goto'] will be set but could be empty)
56 if (empty($GLOBALS['goto'])) {
57 if (mb_strlen($table)) {
58 // avoid a problem (see bug #2202709)
59 $GLOBALS['goto'] = 'tbl_sql.php';
61 $GLOBALS['goto'] = 'db_sql.php';
66 $_url_params = PMA_getUrlParameters($db, $table);
67 $err_url = $GLOBALS['goto'] . PMA_URL_getCommon($_url_params);
70 $comments_map = PMA_getCommentsMap($db, $table);
73 * START REGULAR OUTPUT
77 * Load JavaScript files
79 $response = Response
::getInstance();
80 $header = $response->getHeader();
81 $scripts = $header->getScripts();
82 $scripts->addFile('functions.js');
83 $scripts->addFile('sql.js');
84 $scripts->addFile('tbl_change.js');
85 $scripts->addFile('big_ints.js');
86 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
87 $scripts->addFile('jquery/jquery.validate.js');
88 $scripts->addFile('jquery/additional-methods.js');
89 $scripts->addFile('gis_data_editor.js');
92 * Displays the query submitted and its result
94 * $disp_message come from tbl_replace.php
96 if (! empty($disp_message)) {
97 $response->addHTML(Util
::getMessage($disp_message, null));
100 $table_columns = PMA_getTableColumns($db, $table);
102 // retrieve keys into foreign fields, if any
103 $foreigners = PMA_getForeigners($db, $table);
105 // Retrieve form parameters for insert/edit form
106 $_form_params = PMA_getFormParametersForInsertForm(
107 $db, $table, $where_clauses, $where_clause_array, $err_url
113 // autocomplete feature of IE kills the "onchange" event handler and it
114 // must be replaced by the "onpropertychange" one in this case
115 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE'
116 && PMA_USR_BROWSER_VER
>= 5
117 && PMA_USR_BROWSER_VER
< 7
121 // Had to put the URI because when hosted on an https server,
122 // some browsers send wrongly this form to the http server.
125 // Set if we passed the first timestamp field
126 $timestamp_seen = false;
127 $columns_cnt = count($table_columns);
130 $tabindex_for_function = +
3000;
131 $tabindex_for_null = +
6000;
132 $tabindex_for_value = 0;
134 $biggest_max_file_size = 0;
136 $url_params['db'] = $db;
137 $url_params['table'] = $table;
138 $url_params = PMA_urlParamsInEditMode(
139 $url_params, $where_clause_array, $where_clause
142 $has_blob_field = false;
143 foreach ($table_columns as $column) {
146 array('blob', 'tinyblob', 'mediumblob', 'longblob')
148 $has_blob_field = true;
154 //If table has blob fields we have to disable ajax.
155 $html_output .= PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
157 $html_output .= PMA_URL_getHiddenInputs($_form_params);
159 $titles['Browse'] = Util
::getIcon('b_browse.png', __('Browse foreign values'));
161 // user can toggle the display of Function column and column types
162 // (currently does not work for multi-edits)
163 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
164 $html_output .= __('Show');
167 if (! $cfg['ShowFunctionFields']) {
168 $html_output .= PMA_showTypeOrFunction('function', $url_params, false);
171 if (! $cfg['ShowFieldTypesInDataEditView']) {
172 $html_output .= PMA_showTypeOrFunction('type', $url_params, false);
175 $GLOBALS['plugin_scripts'] = array();
176 foreach ($rows as $row_id => $current_row) {
177 if (empty($current_row)) {
178 $current_row = array();
182 $vkey = '[multi_edit][' . $jsvkey . ']';
184 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
187 $repopulate = array();
189 if (isset($unsaved_values[$row_id])) {
190 $repopulate = $unsaved_values[$row_id];
193 if ($insert_mode && $row_id > 0) {
194 $html_output .= PMA_getHtmlForIgnoreOption($row_id, $checked);
197 $html_output .= PMA_getHtmlForInsertEditRow(
198 $url_params, $table_columns, $comments_map, $timestamp_seen,
199 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
200 $current_row, $o_rows, $tabindex, $columns_cnt,
201 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
202 $tabindex_for_value, $table, $db, $row_id, $titles,
203 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
205 } // end foreach on multi-edit
206 $scripts->addFiles($GLOBALS['plugin_scripts']);
207 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
209 if (! isset($after_insert)) {
210 $after_insert = 'back';
214 $html_output .= PMA_getActionsPanel(
215 $where_clause, $after_insert, $tabindex,
216 $tabindex_for_value, $found_unique_key
219 if ($biggest_max_file_size > 0) {
221 . Util
::generateHiddenMaxFileSize(
222 $biggest_max_file_size
225 $html_output .= '</form>';
227 $html_output .= PMA_getHtmlForGisEditor();
228 // end Insert/Edit form
231 //Continue insertion form
232 $html_output .= PMA_getContinueInsertionForm(
233 $table, $db, $where_clause_array, $err_url
237 $response->addHTML($html_output);