Translated using Weblate (Catalan)
[phpmyadmin.git] / tbl_change.php
blob1d5428f9832973422e3a16e3e19f82a28e73083d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for editing and inserting new table rows
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;
15 /**
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');
22 /**
23 * Ensures db and table are valid, else moves to the "parent" script
25 require_once 'libraries/db_table_exists.inc.php';
27 /**
28 * Determine whether Insert or Edit and set global variables
30 list(
31 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
32 $result, $rows, $found_unique_key, $after_insert
33 ) = InsertEdit::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);
41 /**
42 * Defines the url to return to in case of error in a sql statement
43 * (at this point, $GLOBALS['goto'] will be set but could be empty)
45 if (empty($GLOBALS['goto'])) {
46 if (strlen($table) > 0) {
47 // avoid a problem (see bug #2202709)
48 $GLOBALS['goto'] = 'tbl_sql.php';
49 } else {
50 $GLOBALS['goto'] = 'db_sql.php';
55 $_url_params = InsertEdit::getUrlParameters($db, $table);
56 $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
57 unset($_url_params);
59 $comments_map = InsertEdit::getCommentsMap($db, $table);
61 /**
62 * START REGULAR OUTPUT
65 /**
66 * Load JavaScript files
68 $response = Response::getInstance();
69 $header = $response->getHeader();
70 $scripts = $header->getScripts();
71 $scripts->addFile('sql.js');
72 $scripts->addFile('tbl_change.js');
73 $scripts->addFile('vendor/jquery/additional-methods.js');
74 $scripts->addFile('gis_data_editor.js');
76 /**
77 * Displays the query submitted and its result
79 * $disp_message come from tbl_replace.php
81 if (! empty($disp_message)) {
82 $response->addHTML(Util::getMessage($disp_message, null));
85 $table_columns = InsertEdit::getTableColumns($db, $table);
87 // retrieve keys into foreign fields, if any
88 $foreigners = Relation::getForeigners($db, $table);
90 // Retrieve form parameters for insert/edit form
91 $_form_params = InsertEdit::getFormParametersForInsertForm(
92 $db, $table, $where_clauses, $where_clause_array, $err_url
95 /**
96 * Displays the form
98 // autocomplete feature of IE kills the "onchange" event handler and it
99 // must be replaced by the "onpropertychange" one in this case
100 $chg_evt_handler = 'onchange';
101 // Had to put the URI because when hosted on an https server,
102 // some browsers send wrongly this form to the http server.
104 $html_output = '';
105 // Set if we passed the first timestamp field
106 $timestamp_seen = false;
107 $columns_cnt = count($table_columns);
109 $tabindex = 0;
110 $tabindex_for_function = +3000;
111 $tabindex_for_null = +6000;
112 $tabindex_for_value = 0;
113 $o_rows = 0;
114 $biggest_max_file_size = 0;
116 $url_params['db'] = $db;
117 $url_params['table'] = $table;
118 $url_params = InsertEdit::urlParamsInEditMode(
119 $url_params, $where_clause_array, $where_clause
122 $has_blob_field = false;
123 foreach ($table_columns as $column) {
124 if (InsertEdit::isColumn(
125 $column,
126 array('blob', 'tinyblob', 'mediumblob', 'longblob')
127 )) {
128 $has_blob_field = true;
129 break;
133 //Insert/Edit form
134 //If table has blob fields we have to disable ajax.
135 $html_output .= InsertEdit::getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
137 $html_output .= Url::getHiddenInputs($_form_params);
139 $titles['Browse'] = Util::getIcon('b_browse', __('Browse foreign values'));
141 // user can toggle the display of Function column and column types
142 // (currently does not work for multi-edits)
143 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
144 $html_output .= __('Show');
147 if (! $cfg['ShowFunctionFields']) {
148 $html_output .= InsertEdit::showTypeOrFunction('function', $url_params, false);
151 if (! $cfg['ShowFieldTypesInDataEditView']) {
152 $html_output .= InsertEdit::showTypeOrFunction('type', $url_params, false);
155 $GLOBALS['plugin_scripts'] = array();
156 foreach ($rows as $row_id => $current_row) {
157 if (empty($current_row)) {
158 $current_row = array();
161 $jsvkey = $row_id;
162 $vkey = '[multi_edit][' . $jsvkey . ']';
164 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
165 ? $result[$row_id]
166 : $result);
167 $repopulate = array();
168 $checked = true;
169 if (isset($unsaved_values[$row_id])) {
170 $repopulate = $unsaved_values[$row_id];
171 $checked = false;
173 if ($insert_mode && $row_id > 0) {
174 $html_output .= InsertEdit::getHtmlForIgnoreOption($row_id, $checked);
177 $html_output .= InsertEdit::getHtmlForInsertEditRow(
178 $url_params, $table_columns, $comments_map, $timestamp_seen,
179 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
180 $current_row, $o_rows, $tabindex, $columns_cnt,
181 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
182 $tabindex_for_value, $table, $db, $row_id, $titles,
183 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
185 } // end foreach on multi-edit
186 $scripts->addFiles($GLOBALS['plugin_scripts']);
187 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
189 if (! isset($after_insert)) {
190 $after_insert = 'back';
193 //action panel
194 $html_output .= InsertEdit::getActionsPanel(
195 $where_clause, $after_insert, $tabindex,
196 $tabindex_for_value, $found_unique_key
199 if ($biggest_max_file_size > 0) {
200 $html_output .= ' '
201 . Util::generateHiddenMaxFileSize(
202 $biggest_max_file_size
203 ) . "\n";
205 $html_output .= '</form>';
207 $html_output .= InsertEdit::getHtmlForGisEditor();
208 // end Insert/Edit form
210 if ($insert_mode) {
211 //Continue insertion form
212 $html_output .= InsertEdit::getContinueInsertionForm(
213 $table, $db, $where_clause_array, $err_url
217 $response->addHTML($html_output);