2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
8 use PhpMyAdmin\Config\PageSettings
;
9 use PhpMyAdmin\InsertEdit
;
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
16 * Gets the variables sent or posted to this script and displays the header
18 require_once 'libraries/common.inc.php';
20 PageSettings
::showGroup('Edit');
23 * Ensures db and table are valid, else moves to the "parent" script
25 require_once 'libraries/db_table_exists.inc.php';
27 $insertEdit = new InsertEdit($GLOBALS['dbi']);
30 * Determine whether Insert or Edit and set global variables
33 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
34 $result, $rows, $found_unique_key, $after_insert
35 ) = $insertEdit->determineInsertOrEdit(
36 isset($where_clause) ?
$where_clause : null, $db, $table
38 // Increase number of rows if unsaved rows are more
39 if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
40 $rows = array_fill(0, count($unsaved_values), false);
44 * Defines the url to return to in case of error in a sql statement
45 * (at this point, $GLOBALS['goto'] will be set but could be empty)
47 if (empty($GLOBALS['goto'])) {
48 if (strlen($table) > 0) {
49 // avoid a problem (see bug #2202709)
50 $GLOBALS['goto'] = 'tbl_sql.php';
52 $GLOBALS['goto'] = 'db_sql.php';
57 $_url_params = $insertEdit->getUrlParameters($db, $table);
58 $err_url = $GLOBALS['goto'] . Url
::getCommon($_url_params);
61 $comments_map = $insertEdit->getCommentsMap($db, $table);
64 * START REGULAR OUTPUT
68 * Load JavaScript files
70 $response = Response
::getInstance();
71 $header = $response->getHeader();
72 $scripts = $header->getScripts();
73 $scripts->addFile('sql.js');
74 $scripts->addFile('tbl_change.js');
75 $scripts->addFile('vendor/jquery/additional-methods.js');
76 $scripts->addFile('gis_data_editor.js');
79 * Displays the query submitted and its result
81 * $disp_message come from tbl_replace.php
83 if (! empty($disp_message)) {
84 $response->addHTML(Util
::getMessage($disp_message, null));
87 $table_columns = $insertEdit->getTableColumns($db, $table);
89 // retrieve keys into foreign fields, if any
90 $relation = new Relation();
91 $foreigners = $relation->getForeigners($db, $table);
93 // Retrieve form parameters for insert/edit form
94 $_form_params = $insertEdit->getFormParametersForInsertForm(
95 $db, $table, $where_clauses, $where_clause_array, $err_url
101 // autocomplete feature of IE kills the "onchange" event handler and it
102 // must be replaced by the "onpropertychange" one in this case
103 $chg_evt_handler = 'onchange';
104 // Had to put the URI because when hosted on an https server,
105 // some browsers send wrongly this form to the http server.
108 // Set if we passed the first timestamp field
109 $timestamp_seen = false;
110 $columns_cnt = count($table_columns);
113 $tabindex_for_function = +
3000;
114 $tabindex_for_null = +
6000;
115 $tabindex_for_value = 0;
117 $biggest_max_file_size = 0;
119 $url_params['db'] = $db;
120 $url_params['table'] = $table;
121 $url_params = $insertEdit->urlParamsInEditMode(
122 $url_params, $where_clause_array, $where_clause
125 $has_blob_field = false;
126 foreach ($table_columns as $column) {
127 if ($insertEdit->isColumn(
129 array('blob', 'tinyblob', 'mediumblob', 'longblob')
131 $has_blob_field = true;
137 //If table has blob fields we have to disable ajax.
138 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
140 $html_output .= Url
::getHiddenInputs($_form_params);
142 $titles['Browse'] = Util
::getIcon('b_browse', __('Browse foreign values'));
144 // user can toggle the display of Function column and column types
145 // (currently does not work for multi-edits)
146 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
147 $html_output .= __('Show');
150 if (! $cfg['ShowFunctionFields']) {
151 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
154 if (! $cfg['ShowFieldTypesInDataEditView']) {
155 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
158 $GLOBALS['plugin_scripts'] = array();
159 foreach ($rows as $row_id => $current_row) {
160 if (empty($current_row)) {
161 $current_row = array();
165 $vkey = '[multi_edit][' . $jsvkey . ']';
167 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
170 $repopulate = array();
172 if (isset($unsaved_values[$row_id])) {
173 $repopulate = $unsaved_values[$row_id];
176 if ($insert_mode && $row_id > 0) {
177 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
180 $html_output .= $insertEdit->getHtmlForInsertEditRow(
181 $url_params, $table_columns, $comments_map, $timestamp_seen,
182 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
183 $current_row, $o_rows, $tabindex, $columns_cnt,
184 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
185 $tabindex_for_value, $table, $db, $row_id, $titles,
186 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
188 } // end foreach on multi-edit
189 $scripts->addFiles($GLOBALS['plugin_scripts']);
190 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
192 if (! isset($after_insert)) {
193 $after_insert = 'back';
197 $html_output .= $insertEdit->getActionsPanel(
198 $where_clause, $after_insert, $tabindex,
199 $tabindex_for_value, $found_unique_key
202 if ($biggest_max_file_size > 0) {
204 . Util
::generateHiddenMaxFileSize(
205 $biggest_max_file_size
208 $html_output .= '</form>';
210 $html_output .= $insertEdit->getHtmlForGisEditor();
211 // end Insert/Edit form
214 //Continue insertion form
215 $html_output .= $insertEdit->getContinueInsertionForm(
216 $table, $db, $where_clause_array, $err_url
220 $response->addHTML($html_output);