Translated using Weblate (Persian)
[phpmyadmin.git] / tbl_change.php
blob9ac837b0be50411735ba88331929e6dc0487be9b
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 $insertEdit = new InsertEdit($GLOBALS['dbi']);
29 /**
30 * Determine whether Insert or Edit and set global variables
32 list(
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);
43 /**
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';
51 } else {
52 $GLOBALS['goto'] = 'db_sql.php';
57 $_url_params = $insertEdit->getUrlParameters($db, $table);
58 $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
59 unset($_url_params);
61 $comments_map = $insertEdit->getCommentsMap($db, $table);
63 /**
64 * START REGULAR OUTPUT
67 /**
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');
78 /**
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
98 /**
99 * Displays the form
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.
107 $html_output = '';
108 // Set if we passed the first timestamp field
109 $timestamp_seen = false;
110 $columns_cnt = count($table_columns);
112 $tabindex = 0;
113 $tabindex_for_function = +3000;
114 $tabindex_for_null = +6000;
115 $tabindex_for_value = 0;
116 $o_rows = 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
125 $has_blob_field = false;
126 foreach ($table_columns as $column) {
127 if ($insertEdit->isColumn(
128 $column,
129 array('blob', 'tinyblob', 'mediumblob', 'longblob')
130 )) {
131 $has_blob_field = true;
132 break;
136 //Insert/Edit form
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();
164 $jsvkey = $row_id;
165 $vkey = '[multi_edit][' . $jsvkey . ']';
167 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
168 ? $result[$row_id]
169 : $result);
170 $repopulate = array();
171 $checked = true;
172 if (isset($unsaved_values[$row_id])) {
173 $repopulate = $unsaved_values[$row_id];
174 $checked = false;
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';
196 //action panel
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) {
203 $html_output .= ' '
204 . Util::generateHiddenMaxFileSize(
205 $biggest_max_file_size
206 ) . "\n";
208 $html_output .= '</form>';
210 $html_output .= $insertEdit->getHtmlForGisEditor();
211 // end Insert/Edit form
213 if ($insert_mode) {
214 //Continue insertion form
215 $html_output .= $insertEdit->getContinueInsertionForm(
216 $table, $db, $where_clause_array, $err_url
220 $response->addHTML($html_output);