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)
12 * Gets the variables sent or posted to this script and displays the header
14 require_once 'libraries/common.inc.php';
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once 'libraries/db_table_exists.lib.php';
22 * functions implementation for this script
24 require_once 'libraries/insert_edit.lib.php';
25 require_once 'libraries/transformations.lib.php';
28 * Determine whether Insert or Edit and set global variables
31 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
32 $result, $rows, $found_unique_key, $after_insert
33 ) = PMA_determineInsertOrEdit(
34 isset($where_clause) ?
$where_clause : null, $db, $table
36 // Increase number of rows if unsaved rows are more
37 if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
38 $rows = array_fill(0, count($unsaved_values), false);
43 require_once 'libraries/file_listing.lib.php';
46 * Defines the url to return to in case of error in a sql statement
47 * (at this point, $GLOBALS['goto'] will be set but could be empty)
49 if (empty($GLOBALS['goto'])) {
50 if (/*overload*/mb_strlen($table)) {
51 // avoid a problem (see bug #2202709)
52 $GLOBALS['goto'] = 'tbl_sql.php';
54 $GLOBALS['goto'] = 'db_sql.php';
59 $_url_params = PMA_getUrlParameters($db, $table);
60 $err_url = $GLOBALS['goto'] . PMA_URL_getCommon($_url_params);
63 $comments_map = PMA_getCommentsMap($db, $table);
66 * START REGULAR OUTPUT
70 * Load JavaScript files
72 $response = PMA_Response
::getInstance();
73 $header = $response->getHeader();
74 $scripts = $header->getScripts();
75 $scripts->addFile('functions.js');
76 $scripts->addFile('sql.js');
77 $scripts->addFile('tbl_change.js');
78 $scripts->addFile('big_ints.js');
79 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
80 $scripts->addFile('gis_data_editor.js');
83 * Displays the query submitted and its result
85 * $disp_message come from tbl_replace.php
87 if (! empty($disp_message)) {
88 $response->addHTML(PMA_Util
::getMessage($disp_message, null));
91 // used as a global by PMA_Util::getDefaultFunctionForField()
92 $analyzed_sql = PMA_Table
::analyzeStructure($db, $table);
94 $table_columns = PMA_getTableColumns($db, $table);
96 // retrieve keys into foreign fields, if any
97 $foreigners = PMA_getForeigners($db, $table);
99 // Retrieve form parameters for insert/edit form
100 $_form_params = PMA_getFormParametersForInsertForm(
101 $db, $table, $where_clauses, $where_clause_array, $err_url
107 // autocomplete feature of IE kills the "onchange" event handler and it
108 // must be replaced by the "onpropertychange" one in this case
109 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE'
110 && PMA_USR_BROWSER_VER
>= 5
111 && PMA_USR_BROWSER_VER
< 7
115 // Had to put the URI because when hosted on an https server,
116 // some browsers send wrongly this form to the http server.
119 // Set if we passed the first timestamp field
120 $timestamp_seen = false;
121 $columns_cnt = count($table_columns);
124 $tabindex_for_function = +
3000;
125 $tabindex_for_null = +
6000;
126 $tabindex_for_value = 0;
128 $biggest_max_file_size = 0;
130 $url_params['db'] = $db;
131 $url_params['table'] = $table;
132 $url_params = PMA_urlParamsInEditMode(
133 $url_params, $where_clause_array, $where_clause
136 $has_blob_field = false;
137 foreach ($table_columns as $column) {
140 array('blob', 'tinyblob', 'mediumblob', 'longblob')
142 $has_blob_field = true;
148 //If table has blob fields we have to disable ajax.
149 $html_output .= PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
151 $html_output .= PMA_URL_getHiddenInputs($_form_params);
153 $titles['Browse'] = PMA_Util
::getIcon('b_browse.png', __('Browse foreign values'));
155 // user can toggle the display of Function column and column types
156 // (currently does not work for multi-edits)
157 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
158 $html_output .= __('Show');
161 if (! $cfg['ShowFunctionFields']) {
162 $html_output .= PMA_showTypeOrFunction('function', $url_params, false);
165 if (! $cfg['ShowFieldTypesInDataEditView']) {
166 $html_output .= PMA_showTypeOrFunction('type', $url_params, false);
169 $GLOBALS['plugin_scripts'] = array();
170 foreach ($rows as $row_id => $current_row) {
171 if (empty($current_row)) {
172 $current_row = array();
176 $vkey = '[multi_edit][' . $jsvkey . ']';
178 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
181 $repopulate = array();
183 if (isset($unsaved_values[$row_id])) {
184 $repopulate = $unsaved_values[$row_id];
187 if ($insert_mode && $row_id > 0) {
188 $html_output .= PMA_getHtmlForIgnoreOption($row_id, $checked);
191 $html_output .= PMA_getHtmlForInsertEditRow(
192 $url_params, $table_columns, $column, $comments_map, $timestamp_seen,
193 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
194 $current_row, $o_rows, $tabindex, $columns_cnt,
195 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
196 $tabindex_for_value, $table, $db, $row_id, $titles,
197 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
199 } // end foreach on multi-edit
200 $scripts->addFiles($GLOBALS['plugin_scripts']);
201 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
203 $html_output .= PMA_getHtmlForGisEditor();
205 if (! isset($after_insert)) {
206 $after_insert = 'back';
210 $html_output .= PMA_getActionsPanel(
211 $where_clause, $after_insert, $tabindex,
212 $tabindex_for_value, $found_unique_key
215 if ($biggest_max_file_size > 0) {
217 . PMA_Util
::generateHiddenMaxFileSize(
218 $biggest_max_file_size
221 $html_output .= '</form>';
222 // end Insert/Edit form
225 //Continue insertion form
226 $html_output .= PMA_getContinueInsertionForm(
227 $table, $db, $where_clause_array, $err_url
231 $response->addHTML($html_output);