Clear display on session timeout even when unsaved changes are pending.
[openemr.git] / phpmyadmin / libraries / insert_edit.lib.php
blobc277091156be74adb1b2e534c88a839f58ac1662
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * set of functions with the insert/edit features in pma
6 * @package PhpMyAdmin
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Retrieve form parameters for insert/edit form
16 * @param string $db name of the database
17 * @param string $table name of the table
18 * @param array|null $where_clauses where clauses
19 * @param array $where_clause_array array of where clauses
20 * @param string $err_url error url
22 * @return array $form_params array of insert/edit form parameters
24 function PMA_getFormParametersForInsertForm($db, $table, $where_clauses,
25 $where_clause_array, $err_url
26 ) {
27 $_form_params = array(
28 'db' => $db,
29 'table' => $table,
30 'goto' => $GLOBALS['goto'],
31 'err_url' => $err_url,
32 'sql_query' => $_REQUEST['sql_query'],
34 if (isset($where_clauses)) {
35 foreach ($where_clause_array as $key_id => $where_clause) {
36 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
39 if (isset($_REQUEST['clause_is_unique'])) {
40 $_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique'];
42 return $_form_params;
45 /**
46 * Creates array of where clauses
48 * @param array|string|null $where_clause where clause
50 * @return array whereClauseArray array of where clauses
52 function PMA_getWhereClauseArray($where_clause)
54 if (!isset($where_clause)) {
55 return array();
58 if (is_array($where_clause)) {
59 return $where_clause;
62 return array(0 => $where_clause);
65 /**
66 * Analysing where clauses array
68 * @param array $where_clause_array array of where clauses
69 * @param string $table name of the table
70 * @param string $db name of the database
72 * @return array $where_clauses, $result, $rows
74 function PMA_analyzeWhereClauses(
75 $where_clause_array, $table, $db
76 ) {
77 $rows = array();
78 $result = array();
79 $where_clauses = array();
80 $found_unique_key = false;
81 foreach ($where_clause_array as $key_id => $where_clause) {
83 $local_query = 'SELECT * FROM '
84 . PMA_Util::backquote($db) . '.'
85 . PMA_Util::backquote($table)
86 . ' WHERE ' . $where_clause . ';';
87 $result[$key_id] = $GLOBALS['dbi']->query(
88 $local_query, null, PMA_DatabaseInterface::QUERY_STORE
90 $rows[$key_id] = $GLOBALS['dbi']->fetchAssoc($result[$key_id]);
92 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
93 $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition(
94 $rows, $key_id, $where_clause_array, $local_query, $result
96 if ($has_unique_condition) {
97 $found_unique_key = true;
100 return array($where_clauses, $result, $rows, $found_unique_key);
104 * Show message for empty result or set the unique_condition
106 * @param array $rows MySQL returned rows
107 * @param string $key_id ID in current key
108 * @param array $where_clause_array array of where clauses
109 * @param string $local_query query performed
110 * @param array $result MySQL result handle
112 * @return boolean $has_unique_condition
114 function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id,
115 $where_clause_array, $local_query, $result
117 $has_unique_condition = false;
119 // No row returned
120 if (! $rows[$key_id]) {
121 unset($rows[$key_id], $where_clause_array[$key_id]);
122 PMA_Response::getInstance()->addHtml(
123 PMA_Util::getMessage(
124 __('MySQL returned an empty result set (i.e. zero rows).'),
125 $local_query
129 * @todo not sure what should be done at this point, but we must not
130 * exit if we want the message to be displayed
132 } else {// end if (no row returned)
133 $meta = $GLOBALS['dbi']->getFieldsMeta($result[$key_id]);
135 list($unique_condition, $tmp_clause_is_unique)
136 = PMA_Util::getUniqueCondition(
137 $result[$key_id], // handle
138 count($meta), // fields_cnt
139 $meta, // fields_meta
140 $rows[$key_id], // row
141 true, // force_unique
142 false, // restrict_to_table
143 null // analyzed_sql_results
146 if (! empty($unique_condition)) {
147 $has_unique_condition = true;
149 unset($unique_condition, $tmp_clause_is_unique);
151 return $has_unique_condition;
155 * No primary key given, just load first row
157 * @param string $table name of the table
158 * @param string $db name of the database
160 * @return array containing $result and $rows arrays
162 function PMA_loadFirstRow($table, $db)
164 $result = $GLOBALS['dbi']->query(
165 'SELECT * FROM ' . PMA_Util::backquote($db)
166 . '.' . PMA_Util::backquote($table) . ' LIMIT 1;',
167 null,
168 PMA_DatabaseInterface::QUERY_STORE
170 $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false);
171 return array($result, $rows);
175 * Add some url parameters
177 * @param array $url_params containing $db and $table as url parameters
178 * @param array $where_clause_array where clauses array
179 * @param string $where_clause where clause
181 * @return array Add some url parameters to $url_params array and return it
183 function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause)
185 if (isset($where_clause)) {
186 foreach ($where_clause_array as $where_clause) {
187 $url_params['where_clause'] = trim($where_clause);
190 if (! empty($_REQUEST['sql_query'])) {
191 $url_params['sql_query'] = $_REQUEST['sql_query'];
193 return $url_params;
197 * Show type information or function selectors in Insert/Edit
199 * @param string $which function|type
200 * @param array $url_params containing url parameters
201 * @param boolean $is_show whether to show the element in $which
203 * @return string an HTML snippet
205 function PMA_showTypeOrFunction($which, $url_params, $is_show)
207 $params = array();
209 switch($which) {
210 case 'function':
211 $params['ShowFunctionFields'] = ($is_show ? 0 : 1);
212 $params['ShowFieldTypesInDataEditView']
213 = $GLOBALS['cfg']['ShowFieldTypesInDataEditView'];
214 break;
215 case 'type':
216 $params['ShowFieldTypesInDataEditView'] = ($is_show ? 0 : 1);
217 $params['ShowFunctionFields']
218 = $GLOBALS['cfg']['ShowFunctionFields'];
219 break;
222 $params['goto'] = 'sql.php';
223 $this_url_params = array_merge($url_params, $params);
225 if (! $is_show) {
226 return ' : <a href="tbl_change.php'
227 . PMA_URL_getCommon($this_url_params) . '">'
228 . PMA_showTypeOrFunctionLabel($which)
229 . '</a>';
231 return '<th><a href="tbl_change.php'
232 . PMA_URL_getCommon($this_url_params)
233 . '" title="' . __('Hide') . '">'
234 . PMA_showTypeOrFunctionLabel($which)
235 . '</a></th>';
239 * Show type information or function selectors labels in Insert/Edit
241 * @param string $which function|type
243 * @return string an HTML snippet
245 function PMA_showTypeOrFunctionLabel($which)
247 switch($which) {
248 case 'function':
249 return __('Function');
250 case 'type':
251 return __('Type');
254 return null;
258 * Analyze the table column array
260 * @param array $column description of column in given table
261 * @param array $comments_map comments for every column that has a comment
262 * @param boolean $timestamp_seen whether a timestamp has been seen
264 * @return array description of column in given table
266 function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen)
268 $column['Field_html'] = htmlspecialchars($column['Field']);
269 $column['Field_md5'] = md5($column['Field']);
270 // True_Type contains only the type (stops at first bracket)
271 $column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']);
272 $column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1;
273 $column['Field_title'] = PMA_getColumnTitle($column, $comments_map);
274 $column['is_binary'] = PMA_isColumn(
275 $column,
276 array('binary', 'varbinary')
278 $column['is_blob'] = PMA_isColumn(
279 $column,
280 array('blob', 'tinyblob', 'mediumblob', 'longblob')
282 $column['is_char'] = PMA_isColumn(
283 $column,
284 array('char', 'varchar')
287 list($column['pma_type'], $column['wrap'], $column['first_timestamp'])
288 = PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen);
290 return $column;
294 * Retrieve the column title
296 * @param array $column description of column in given table
297 * @param array $comments_map comments for every column that has a comment
299 * @return string column title
301 function PMA_getColumnTitle($column, $comments_map)
303 if (isset($comments_map[$column['Field']])) {
304 return '<span style="border-bottom: 1px dashed black;" title="'
305 . htmlspecialchars($comments_map[$column['Field']]) . '">'
306 . $column['Field_html'] . '</span>';
307 } else {
308 return $column['Field_html'];
313 * check whether the column is of a certain type
314 * the goal is to ensure that types such as "enum('one','two','binary',..)"
315 * or "enum('one','two','varbinary',..)" are not categorized as binary
317 * @param array $column description of column in given table
318 * @param array $types the types to verify
320 * @return boolean whether the column's type if one of the $types
322 function PMA_isColumn($column, $types)
324 foreach ($types as $one_type) {
325 if (/*overload*/mb_stripos($column['Type'], $one_type) === 0) {
326 return true;
329 return false;
333 * Retrieve set, enum, timestamp table columns
335 * @param array $column description of column in given table
336 * @param boolean $timestamp_seen whether a timestamp has been seen
338 * @return array $column['pma_type'], $column['wrap'], $column['first_timestamp']
340 function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen)
342 $column['first_timestamp'] = false;
343 switch ($column['True_Type']) {
344 case 'set':
345 $column['pma_type'] = 'set';
346 $column['wrap'] = '';
347 break;
348 case 'enum':
349 $column['pma_type'] = 'enum';
350 $column['wrap'] = '';
351 break;
352 case 'timestamp':
353 if (! $timestamp_seen) { // can only occur once per table
354 $column['first_timestamp'] = true;
356 $column['pma_type'] = $column['Type'];
357 $column['wrap'] = ' nowrap';
358 break;
360 default:
361 $column['pma_type'] = $column['Type'];
362 $column['wrap'] = ' nowrap';
363 break;
365 return array($column['pma_type'], $column['wrap'], $column['first_timestamp']);
369 * The function column
370 * We don't want binary data to be destroyed
371 * Note: from the MySQL manual: "BINARY doesn't affect how the column is
372 * stored or retrieved" so it does not mean that the contents is binary
374 * @param array $column description of column in given table
375 * @param boolean $is_upload upload or no
376 * @param string $column_name_appendix the name attribute
377 * @param string $onChangeClause onchange clause for fields
378 * @param array $no_support_types list of datatypes that are not (yet)
379 * handled by PMA
380 * @param integer $tabindex_for_function +3000
381 * @param integer $tabindex tab index
382 * @param integer $idindex id index
383 * @param boolean $insert_mode insert mode or edit mode
385 * @return string an html snippet
387 function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix,
388 $onChangeClause, $no_support_types, $tabindex_for_function,
389 $tabindex, $idindex, $insert_mode
391 $html_output = '';
392 if (($GLOBALS['cfg']['ProtectBinary'] === 'blob'
393 && $column['is_blob'] && !$is_upload)
394 || ($GLOBALS['cfg']['ProtectBinary'] === 'all'
395 && $column['is_binary'])
396 || ($GLOBALS['cfg']['ProtectBinary'] === 'noblob'
397 && $column['is_binary'])
399 $html_output .= '<td class="center">' . __('Binary') . '</td>' . "\n";
400 } elseif (/*overload*/mb_strstr($column['True_Type'], 'enum')
401 || /*overload*/mb_strstr($column['True_Type'], 'set')
402 || in_array($column['pma_type'], $no_support_types)
404 $html_output .= '<td class="center">--</td>' . "\n";
405 } else {
406 $html_output .= '<td>' . "\n";
408 $html_output .= '<select name="funcs' . $column_name_appendix . '"'
409 . ' ' . $onChangeClause
410 . ' tabindex="' . ($tabindex + $tabindex_for_function) . '"'
411 . ' id="field_' . $idindex . '_1">';
412 $html_output .= PMA_Util::getFunctionsForField($column, $insert_mode) . "\n";
414 $html_output .= '</select>' . "\n";
415 $html_output .= '</td>' . "\n";
417 return $html_output;
421 * The null column
423 * @param array $column description of column in given table
424 * @param string $column_name_appendix the name attribute
425 * @param boolean $real_null_value is column value null or not null
426 * @param integer $tabindex tab index
427 * @param integer $tabindex_for_null +6000
428 * @param integer $idindex id index
429 * @param string $vkey [multi_edit]['row_id']
430 * @param array $foreigners keys into foreign fields
431 * @param array $foreignData data about the foreign keys
433 * @return string an html snippet
435 function PMA_getNullColumn($column, $column_name_appendix, $real_null_value,
436 $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData
438 if ($column['Null'] != 'YES') {
439 return "<td></td>\n";
441 $html_output = '';
442 $html_output .= '<td>' . "\n";
443 $html_output .= '<input type="hidden" name="fields_null_prev'
444 . $column_name_appendix . '"';
445 if ($real_null_value && !$column['first_timestamp']) {
446 $html_output .= ' value="on"';
448 $html_output .= ' />' . "\n";
450 $html_output .= '<input type="checkbox" class="checkbox_null" tabindex="'
451 . ($tabindex + $tabindex_for_null) . '"'
452 . ' name="fields_null' . $column_name_appendix . '"';
453 if ($real_null_value) {
454 $html_output .= ' checked="checked"';
456 $html_output .= ' id="field_' . ($idindex) . '_2" />';
458 // nullify_code is needed by the js nullify() function
459 $nullify_code = PMA_getNullifyCodeForNullColumn(
460 $column, $foreigners, $foreignData
462 // to be able to generate calls to nullify() in jQuery
463 $html_output .= '<input type="hidden" class="nullify_code" name="nullify_code'
464 . $column_name_appendix . '" value="' . $nullify_code . '" />';
465 $html_output .= '<input type="hidden" class="hashed_field" name="hashed_field'
466 . $column_name_appendix . '" value="' . $column['Field_md5'] . '" />';
467 $html_output .= '<input type="hidden" class="multi_edit" name="multi_edit'
468 . $column_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
469 $html_output .= '</td>' . "\n";
471 return $html_output;
475 * Retrieve the nullify code for the null column
477 * @param array $column description of column in given table
478 * @param array $foreigners keys into foreign fields
479 * @param array $foreignData data about the foreign keys
481 * @return integer $nullify_code
483 function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData)
485 $foreigner = PMA_searchColumnInForeigners($foreigners, $column['Field']);
486 if (/*overload*/mb_strstr($column['True_Type'], 'enum')) {
487 if (/*overload*/mb_strlen($column['Type']) > 20) {
488 $nullify_code = '1';
489 } else {
490 $nullify_code = '2';
492 } elseif (/*overload*/mb_strstr($column['True_Type'], 'set')) {
493 $nullify_code = '3';
494 } elseif (!empty($foreigners)
495 && !empty($foreigner)
496 && $foreignData['foreign_link'] == false
498 // foreign key in a drop-down
499 $nullify_code = '4';
500 } elseif (!empty($foreigners)
501 && !empty($foreigner)
502 && $foreignData['foreign_link'] == true
504 // foreign key with a browsing icon
505 $nullify_code = '6';
506 } else {
507 $nullify_code = '5';
509 return $nullify_code;
513 * Get the HTML elements for value column in insert form
514 * (here, "column" is used in the sense of HTML column in HTML table)
516 * @param array $column description of column in given table
517 * @param string $backup_field hidden input field
518 * @param string $column_name_appendix the name attribute
519 * @param string $onChangeClause onchange clause for fields
520 * @param integer $tabindex tab index
521 * @param integer $tabindex_for_value offset for the values tabindex
522 * @param integer $idindex id index
523 * @param string $data description of the column field
524 * @param string $special_chars special characters
525 * @param array $foreignData data about the foreign keys
526 * @param boolean $odd_row whether row is odd
527 * @param array $paramTableDbArray array containing $table and $db
528 * @param integer $rownumber the row number
529 * @param array $titles An HTML IMG tag for a particular icon from
530 * a theme, which may be an actual file or
531 * an icon from a sprite
532 * @param string $text_dir text direction
533 * @param string $special_chars_encoded replaced char if the string starts
534 * with a \r\n pair (0x0d0a) add an extra \n
535 * @param string $vkey [multi_edit]['row_id']
536 * @param boolean $is_upload is upload or not
537 * @param integer $biggest_max_file_size 0 integer
538 * @param string $default_char_editing default char editing mode which is stored
539 * in the config.inc.php script
540 * @param array $no_support_types list of datatypes that are not (yet)
541 * handled by PMA
542 * @param array $gis_data_types list of GIS data types
543 * @param array $extracted_columnspec associative array containing type,
544 * spec_in_brackets and possibly
545 * enum_set_values (another array)
547 * @return string an html snippet
549 function PMA_getValueColumn($column, $backup_field, $column_name_appendix,
550 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data,
551 $special_chars, $foreignData, $odd_row, $paramTableDbArray, $rownumber,
552 $titles, $text_dir, $special_chars_encoded, $vkey,
553 $is_upload, $biggest_max_file_size,
554 $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec
556 // HTML5 data-* attribute data-type
557 $data_type = $GLOBALS['PMA_Types']->getTypeClass($column['True_Type']);
558 $html_output = '';
560 if ($foreignData['foreign_link'] == true) {
561 $html_output .= PMA_getForeignLink(
562 $column, $backup_field, $column_name_appendix,
563 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data,
564 $paramTableDbArray, $rownumber, $titles
567 } elseif (is_array($foreignData['disp_row'])) {
568 $html_output .= PMA_dispRowForeignData(
569 $backup_field, $column_name_appendix,
570 $onChangeClause, $tabindex, $tabindex_for_value,
571 $idindex, $data, $foreignData
574 } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
575 && /*overload*/mb_strstr($column['pma_type'], 'longtext')
577 $html_output = '&nbsp;</td>';
578 $html_output .= '</tr>';
579 $html_output .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
580 . '<td colspan="5" class="right">';
581 $html_output .= PMA_getTextarea(
582 $column, $backup_field, $column_name_appendix, $onChangeClause,
583 $tabindex, $tabindex_for_value, $idindex, $text_dir,
584 $special_chars_encoded, $data_type
587 } elseif (/*overload*/mb_strstr($column['pma_type'], 'text')) {
589 $html_output .= PMA_getTextarea(
590 $column, $backup_field, $column_name_appendix, $onChangeClause,
591 $tabindex, $tabindex_for_value, $idindex, $text_dir,
592 $special_chars_encoded, $data_type
594 $html_output .= "\n";
595 if (/*overload*/mb_strlen($special_chars) > 32000) {
596 $html_output .= "</td>\n";
597 $html_output .= '<td>' . __(
598 'Because of its length,<br /> this column might not be editable.'
602 } elseif ($column['pma_type'] == 'enum') {
603 $html_output .= PMA_getPmaTypeEnum(
604 $column, $backup_field, $column_name_appendix, $extracted_columnspec,
605 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data
608 } elseif ($column['pma_type'] == 'set') {
609 $html_output .= PMA_getPmaTypeSet(
610 $column, $extracted_columnspec, $backup_field,
611 $column_name_appendix, $onChangeClause, $tabindex,
612 $tabindex_for_value, $idindex, $data
615 } elseif ($column['is_binary'] || $column['is_blob']) {
616 $html_output .= PMA_getBinaryAndBlobColumn(
617 $column, $data, $special_chars, $biggest_max_file_size,
618 $backup_field, $column_name_appendix, $onChangeClause, $tabindex,
619 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
620 $vkey, $is_upload
623 } elseif (! in_array($column['pma_type'], $no_support_types)) {
624 $html_output .= PMA_getValueColumnForOtherDatatypes(
625 $column, $default_char_editing, $backup_field,
626 $column_name_appendix, $onChangeClause, $tabindex, $special_chars,
627 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
628 $data, $extracted_columnspec
632 if (in_array($column['pma_type'], $gis_data_types)) {
633 $html_output .= PMA_getHTMLforGisDataTypes();
636 return $html_output;
640 * Get HTML for foreign link in insert form
642 * @param array $column description of column in given table
643 * @param string $backup_field hidden input field
644 * @param string $column_name_appendix the name attribute
645 * @param string $onChangeClause onchange clause for fields
646 * @param integer $tabindex tab index
647 * @param integer $tabindex_for_value offset for the values tabindex
648 * @param integer $idindex id index
649 * @param string $data data to edit
650 * @param array $paramTableDbArray array containing $table and $db
651 * @param integer $rownumber the row number
652 * @param array $titles An HTML IMG tag for a particular icon from
653 * a theme, which may be an actual file or
654 * an icon from a sprite
656 * @return string an html snippet
658 function PMA_getForeignLink($column, $backup_field, $column_name_appendix,
659 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data,
660 $paramTableDbArray, $rownumber, $titles
662 list($table, $db) = $paramTableDbArray;
663 $html_output = '';
664 $html_output .= $backup_field . "\n";
666 $html_output .= '<input type="hidden" name="fields_type'
667 . $column_name_appendix . '" value="foreign" />';
669 $html_output .= '<input type="text" name="fields' . $column_name_appendix . '" '
670 . 'class="textfield" '
671 . $onChangeClause . ' '
672 . 'tabindex="' . ($tabindex + $tabindex_for_value) . '" '
673 . 'id="field_' . ($idindex) . '_3" '
674 . 'value="' . htmlspecialchars($data) . '" />';
676 $html_output .= '<a class="ajax browse_foreign" href="browse_foreigners.php'
677 . PMA_URL_getCommon(
678 array(
679 'db' => $db,
680 'table' => $table,
681 'field' => $column['Field'],
682 'rownumber' => $rownumber,
683 'data' => $data
685 ) . '">'
686 . str_replace("'", "\'", $titles['Browse']) . '</a>';
687 return $html_output;
691 * Get HTML to display foreign data
693 * @param string $backup_field hidden input field
694 * @param string $column_name_appendix the name attribute
695 * @param string $onChangeClause onchange clause for fields
696 * @param integer $tabindex tab index
697 * @param integer $tabindex_for_value offset for the values tabindex
698 * @param integer $idindex id index
699 * @param string $data data to edit
700 * @param array $foreignData data about the foreign keys
702 * @return string an html snippet
704 function PMA_dispRowForeignData($backup_field, $column_name_appendix,
705 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data,
706 $foreignData
708 $html_output = '';
709 $html_output .= $backup_field . "\n";
710 $html_output .= '<input type="hidden"'
711 . ' name="fields_type' . $column_name_appendix . '"'
712 . ' value="foreign" />';
714 $html_output .= '<select name="fields' . $column_name_appendix . '"'
715 . ' ' . $onChangeClause
716 . ' class="textfield"'
717 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
718 . ' id="field_' . $idindex . '_3">';
719 $html_output .= PMA_foreignDropdown(
720 $foreignData['disp_row'], $foreignData['foreign_field'],
721 $foreignData['foreign_display'], $data,
722 $GLOBALS['cfg']['ForeignKeyMaxLimit']
724 $html_output .= '</select>';
726 return $html_output;
730 * Get HTML textarea for insert form
732 * @param array $column column information
733 * @param string $backup_field hidden input field
734 * @param string $column_name_appendix the name attribute
735 * @param string $onChangeClause onchange clause for fields
736 * @param integer $tabindex tab index
737 * @param integer $tabindex_for_value offset for the values tabindex
738 * @param integer $idindex id index
739 * @param string $text_dir text direction
740 * @param string $special_chars_encoded replaced char if the string starts
741 * with a \r\n pair (0x0d0a) add an extra \n
742 * @param string $data_type the html5 data-* attribute type
744 * @return string an html snippet
746 function PMA_getTextarea($column, $backup_field, $column_name_appendix,
747 $onChangeClause, $tabindex, $tabindex_for_value, $idindex,
748 $text_dir, $special_chars_encoded, $data_type
750 $the_class = '';
751 $textAreaRows = $GLOBALS['cfg']['TextareaRows'];
752 $textareaCols = $GLOBALS['cfg']['TextareaCols'];
754 if ($column['is_char']) {
756 * @todo clarify the meaning of the "textfield" class and explain
757 * why character columns have the "char" class instead
759 $the_class = 'char';
760 $textAreaRows = $GLOBALS['cfg']['CharTextareaRows'];
761 $textareaCols = $GLOBALS['cfg']['CharTextareaCols'];
762 $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
763 $maxlength = $extracted_columnspec['spec_in_brackets'];
764 } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
765 && /*overload*/mb_strstr($column['pma_type'], 'longtext')
767 $textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2;
768 $textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2;
770 $html_output = $backup_field . "\n"
771 . '<textarea name="fields' . $column_name_appendix . '"'
772 . ' class="' . $the_class . '"'
773 . (isset($maxlength) ? ' data-maxlength="' . $maxlength . '"' : '')
774 . ' rows="' . $textAreaRows . '"'
775 . ' cols="' . $textareaCols . '"'
776 . ' dir="' . $text_dir . '"'
777 . ' id="field_' . ($idindex) . '_3"'
778 . (! empty($onChangeClause) ? ' ' . $onChangeClause : '')
779 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
780 . ' data-type="' . $data_type . '">'
781 . $special_chars_encoded
782 . '</textarea>';
784 return $html_output;
788 * Get HTML for enum type
790 * @param array $column description of column in given table
791 * @param string $backup_field hidden input field
792 * @param string $column_name_appendix the name attribute
793 * @param array $extracted_columnspec associative array containing type,
794 * spec_in_brackets and possibly
795 * enum_set_values (another array)
796 * @param string $onChangeClause onchange clause for fields
797 * @param integer $tabindex tab index
798 * @param integer $tabindex_for_value offset for the values tabindex
799 * @param integer $idindex id index
800 * @param mixed $data data to edit
802 * @return string an html snippet
804 function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix,
805 $extracted_columnspec, $onChangeClause, $tabindex, $tabindex_for_value,
806 $idindex, $data
808 $html_output = '';
809 if (! isset($column['values'])) {
810 $column['values'] = PMA_getColumnEnumValues(
811 $column, $extracted_columnspec
814 $column_enum_values = $column['values'];
815 $html_output .= '<input type="hidden" name="fields_type'
816 . $column_name_appendix . '" value="enum" />';
817 $html_output .= "\n" . ' ' . $backup_field . "\n";
818 if (/*overload*/mb_strlen($column['Type']) > 20) {
819 $html_output .= PMA_getDropDownDependingOnLength(
820 $column, $column_name_appendix, $onChangeClause,
821 $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
823 } else {
824 $html_output .= PMA_getRadioButtonDependingOnLength(
825 $column_name_appendix, $onChangeClause,
826 $tabindex, $column, $tabindex_for_value,
827 $idindex, $data, $column_enum_values
830 return $html_output;
834 * Get column values
836 * @param array $column description of column in given table
837 * @param array $extracted_columnspec associative array containing type,
838 * spec_in_brackets and possibly enum_set_values
839 * (another array)
841 * @return array column values as an associative array
843 function PMA_getColumnEnumValues($column, $extracted_columnspec)
845 $column['values'] = array();
846 foreach ($extracted_columnspec['enum_set_values'] as $val) {
847 $column['values'][] = array(
848 'plain' => $val,
849 'html' => htmlspecialchars($val),
852 return $column['values'];
856 * Get HTML drop down for more than 20 string length
858 * @param array $column description of column in given table
859 * @param string $column_name_appendix the name attribute
860 * @param string $onChangeClause onchange clause for fields
861 * @param integer $tabindex tab index
862 * @param integer $tabindex_for_value offset for the values tabindex
863 * @param integer $idindex id index
864 * @param string $data data to edit
865 * @param array $column_enum_values $column['values']
867 * @return string an html snippet
869 function PMA_getDropDownDependingOnLength(
870 $column, $column_name_appendix, $onChangeClause,
871 $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
873 $html_output = '<select name="fields' . $column_name_appendix . '"'
874 . ' ' . $onChangeClause
875 . ' class="textfield"'
876 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
877 . ' id="field_' . ($idindex) . '_3">';
878 $html_output .= '<option value="">&nbsp;</option>' . "\n";
880 foreach ($column_enum_values as $enum_value) {
881 $html_output .= '<option value="' . $enum_value['html'] . '"';
882 if ($data == $enum_value['plain']
883 || ($data == ''
884 && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
885 && isset($column['Default'])
886 && $enum_value['plain'] == $column['Default'])
888 $html_output .= ' selected="selected"';
890 $html_output .= '>' . $enum_value['html'] . '</option>' . "\n";
892 $html_output .= '</select>';
893 return $html_output;
897 * Get HTML radio button for less than 20 string length
899 * @param string $column_name_appendix the name attribute
900 * @param string $onChangeClause onchange clause for fields
901 * @param integer $tabindex tab index
902 * @param array $column description of column in given table
903 * @param integer $tabindex_for_value offset for the values tabindex
904 * @param integer $idindex id index
905 * @param string $data data to edit
906 * @param array $column_enum_values $column['values']
908 * @return string an html snippet
910 function PMA_getRadioButtonDependingOnLength(
911 $column_name_appendix, $onChangeClause,
912 $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
914 $j = 0;
915 $html_output = '';
916 foreach ($column_enum_values as $enum_value) {
917 $html_output .= ' '
918 . '<input type="radio" name="fields' . $column_name_appendix . '"'
919 . ' class="textfield"'
920 . ' value="' . $enum_value['html'] . '"'
921 . ' id="field_' . ($idindex) . '_3_' . $j . '"'
922 . ' ' . $onChangeClause;
923 if ($data == $enum_value['plain']
924 || ($data == ''
925 && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
926 && isset($column['Default'])
927 && $enum_value['plain'] == $column['Default'])
929 $html_output .= ' checked="checked"';
931 $html_output .= ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
932 $html_output .= '<label for="field_' . $idindex . '_3_' . $j . '">'
933 . $enum_value['html'] . '</label>' . "\n";
934 $j++;
936 return $html_output;
940 * Get the HTML for 'set' pma type
942 * @param array $column description of column in given table
943 * @param array $extracted_columnspec associative array containing type,
944 * spec_in_brackets and possibly
945 * enum_set_values (another array)
946 * @param string $backup_field hidden input field
947 * @param string $column_name_appendix the name attribute
948 * @param string $onChangeClause onchange clause for fields
949 * @param integer $tabindex tab index
950 * @param integer $tabindex_for_value offset for the values tabindex
951 * @param integer $idindex id index
952 * @param string $data description of the column field
954 * @return string an html snippet
956 function PMA_getPmaTypeSet(
957 $column, $extracted_columnspec, $backup_field,
958 $column_name_appendix, $onChangeClause, $tabindex,
959 $tabindex_for_value, $idindex, $data
961 list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize(
962 $column, $extracted_columnspec
964 $vset = array_flip(explode(',', $data));
965 $html_output = $backup_field . "\n";
966 $html_output .= '<input type="hidden" name="fields_type'
967 . $column_name_appendix . '" value="set" />';
968 $html_output .= '<select name="fields' . $column_name_appendix . '[]' . '"'
969 . ' class="textfield"'
970 . ' size="' . $select_size . '"'
971 . ' multiple="multiple"'
972 . ' ' . $onChangeClause
973 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
974 . ' id="field_' . ($idindex) . '_3">';
975 foreach ($column_set_values as $column_set_value) {
976 $html_output .= '<option value="' . $column_set_value['html'] . '"';
977 if (isset($vset[$column_set_value['plain']])) {
978 $html_output .= ' selected="selected"';
980 $html_output .= '>' . $column_set_value['html'] . '</option>' . "\n";
982 $html_output .= '</select>';
983 return $html_output;
987 * Retrieve column 'set' value and select size
989 * @param array $column description of column in given table
990 * @param array $extracted_columnspec associative array containing type,
991 * spec_in_brackets and possibly enum_set_values
992 * (another array)
994 * @return array $column['values'], $column['select_size']
996 function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec)
998 if (! isset($column['values'])) {
999 $column['values'] = array();
1000 foreach ($extracted_columnspec['enum_set_values'] as $val) {
1001 $column['values'][] = array(
1002 'plain' => $val,
1003 'html' => htmlspecialchars($val),
1006 $column['select_size'] = min(4, count($column['values']));
1008 return array($column['values'], $column['select_size']);
1012 * Get HTML for binary and blob column
1014 * @param array $column description of column in given table
1015 * @param string $data data to edit
1016 * @param string $special_chars special characters
1017 * @param integer $biggest_max_file_size biggest max file size for uploading
1018 * @param string $backup_field hidden input field
1019 * @param string $column_name_appendix the name attribute
1020 * @param string $onChangeClause onchange clause for fields
1021 * @param integer $tabindex tab index
1022 * @param integer $tabindex_for_value offset for the values tabindex
1023 * @param integer $idindex id index
1024 * @param string $text_dir text direction
1025 * @param string $special_chars_encoded replaced char if the string starts
1026 * with a \r\n pair (0x0d0a) add an extra \n
1027 * @param string $vkey [multi_edit]['row_id']
1028 * @param boolean $is_upload is upload or not
1030 * @return string an html snippet
1032 function PMA_getBinaryAndBlobColumn(
1033 $column, $data, $special_chars, $biggest_max_file_size,
1034 $backup_field, $column_name_appendix, $onChangeClause, $tabindex,
1035 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
1036 $vkey, $is_upload
1038 $html_output = '';
1039 // Add field type : Protected or Hexadecimal
1040 $fields_type_html = '<input type="hidden" name="fields_type'
1041 . $column_name_appendix . '" value="%s" />';
1042 // Default value : hex
1043 $fields_type_val = 'hex';
1044 if (($GLOBALS['cfg']['ProtectBinary'] === 'blob' && $column['is_blob'])
1045 || ($GLOBALS['cfg']['ProtectBinary'] === 'all')
1046 || ($GLOBALS['cfg']['ProtectBinary'] === 'noblob' && !$column['is_blob'])
1048 $html_output .= __('Binary - do not edit');
1049 if (isset($data)) {
1050 $data_size = PMA_Util::formatByteDown(
1051 /*overload*/mb_strlen(stripslashes($data)), 3, 1
1053 $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')';
1054 unset($data_size);
1056 $fields_type_val = 'protected';
1057 $html_output .= '<input type="hidden" name="fields'
1058 . $column_name_appendix . '" value="" />';
1059 } elseif ($column['is_blob']
1060 || ($column['len'] > $GLOBALS['cfg']['LimitChars'])
1062 $html_output .= "\n" . PMA_getTextarea(
1063 $column, $backup_field, $column_name_appendix, $onChangeClause,
1064 $tabindex, $tabindex_for_value, $idindex, $text_dir,
1065 $special_chars_encoded, 'HEX'
1067 } else {
1068 // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
1069 $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
1070 $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput(
1071 $column, $column_name_appendix, $special_chars, $fieldsize,
1072 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, 'HEX'
1075 $html_output .= sprintf($fields_type_html, $fields_type_val);
1077 if ($is_upload && $column['is_blob']) {
1078 $html_output .= '<br />'
1079 . '<input type="file"'
1080 . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"'
1081 . ' class="textfield" id="field_' . $idindex . '_3" size="10"'
1082 . ' ' . $onChangeClause . '/>&nbsp;';
1083 list($html_out,) = PMA_getMaxUploadSize(
1084 $column, $biggest_max_file_size
1086 $html_output .= $html_out;
1089 if (!empty($GLOBALS['cfg']['UploadDir'])) {
1090 $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
1093 return $html_output;
1097 * Get HTML input type
1099 * @param array $column description of column in given table
1100 * @param string $column_name_appendix the name attribute
1101 * @param string $special_chars special characters
1102 * @param integer $fieldsize html field size
1103 * @param string $onChangeClause onchange clause for fields
1104 * @param integer $tabindex tab index
1105 * @param integer $tabindex_for_value offset for the values tabindex
1106 * @param integer $idindex id index
1107 * @param string $data_type the html5 data-* attribute type
1109 * @return string an html snippet
1111 function PMA_getHTMLinput(
1112 $column, $column_name_appendix, $special_chars, $fieldsize, $onChangeClause,
1113 $tabindex, $tabindex_for_value, $idindex, $data_type
1115 $input_type = 'text';
1116 // do not use the 'date' or 'time' types here; they have no effect on some
1117 // browsers and create side effects (see bug #4218)
1119 $the_class = 'textfield';
1120 // verify True_Type which does not contain the parentheses and length
1121 if ($column['True_Type'] === 'date') {
1122 $the_class .= ' datefield';
1123 } else if ($column['True_Type'] === 'time') {
1124 $the_class .= ' timefield';
1125 } else if ($column['True_Type'] === 'datetime'
1126 || $column['True_Type'] === 'timestamp'
1128 $the_class .= ' datetimefield';
1130 $input_min_max = false;
1131 if (in_array($column['True_Type'], $GLOBALS['PMA_Types']->getIntegerTypes())) {
1132 $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
1133 $is_unsigned = $extracted_columnspec['unsigned'];
1134 $min_max_values = $GLOBALS['PMA_Types']->getIntegerRange(
1135 $column['True_Type'], ! $is_unsigned
1137 $input_min_max = 'min="' . $min_max_values[0] . '" '
1138 . 'max="' . $min_max_values[1] . '"';
1139 $data_type = 'INT';
1141 return '<input type="' . $input_type . '"'
1142 . ' name="fields' . $column_name_appendix . '"'
1143 . ' value="' . $special_chars . '" size="' . $fieldsize . '"'
1144 . ((isset($column['is_char']) && $column['is_char'])
1145 ? ' data-maxlength="' . $fieldsize . '"'
1146 : '')
1147 . ($input_min_max !== false ? ' ' . $input_min_max : '')
1148 . ' data-type="' . $data_type . '"'
1149 . ($input_type === 'time' ? ' step="1"' : '')
1150 . ' class="' . $the_class . '" ' . $onChangeClause
1151 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
1152 . ' id="field_' . ($idindex) . '_3" />';
1156 * Get HTML select option for upload
1158 * @param string $vkey [multi_edit]['row_id']
1159 * @param array $column description of column in given table
1161 * @return string|void an html snippet
1163 function PMA_getSelectOptionForUpload($vkey, $column)
1165 $files = PMA_getFileSelectOptions(
1166 PMA_Util::userDir($GLOBALS['cfg']['UploadDir'])
1169 if ($files === false) {
1170 return '<font color="red">' . __('Error') . '</font><br />' . "\n"
1171 . __('The directory you set for upload work cannot be reached.') . "\n";
1172 } elseif (!empty($files)) {
1173 return "<br />\n"
1174 . '<i>' . __('Or') . '</i>' . ' '
1175 . __('web server upload directory:') . '<br />' . "\n"
1176 . '<select size="1" name="fields_uploadlocal'
1177 . $vkey . '[' . $column['Field_md5'] . ']">' . "\n"
1178 . '<option value="" selected="selected"></option>' . "\n"
1179 . $files
1180 . '</select>' . "\n";
1183 return null;
1187 * Retrieve the maximum upload file size
1189 * @param array $column description of column in given table
1190 * @param integer $biggest_max_file_size biggest max file size for uploading
1192 * @return array an html snippet and $biggest_max_file_size
1194 function PMA_getMaxUploadSize($column, $biggest_max_file_size)
1196 // find maximum upload size, based on field type
1198 * @todo with functions this is not so easy, as you can basically
1199 * process any data with function like MD5
1201 global $max_upload_size;
1202 $max_field_sizes = array(
1203 'tinyblob' => '256',
1204 'blob' => '65536',
1205 'mediumblob' => '16777216',
1206 'longblob' => '4294967296' // yeah, really
1209 $this_field_max_size = $max_upload_size; // from PHP max
1210 if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) {
1211 $this_field_max_size = $max_field_sizes[$column['pma_type']];
1213 $html_output
1214 = PMA_Util::getFormattedMaximumUploadSize(
1215 $this_field_max_size
1216 ) . "\n";
1217 // do not generate here the MAX_FILE_SIZE, because we should
1218 // put only one in the form to accommodate the biggest field
1219 if ($this_field_max_size > $biggest_max_file_size) {
1220 $biggest_max_file_size = $this_field_max_size;
1222 return array($html_output, $biggest_max_file_size);
1226 * Get HTML for the Value column of other datatypes
1227 * (here, "column" is used in the sense of HTML column in HTML table)
1229 * @param array $column description of column in given table
1230 * @param string $default_char_editing default char editing mode which is stored
1231 * in the config.inc.php script
1232 * @param string $backup_field hidden input field
1233 * @param string $column_name_appendix the name attribute
1234 * @param string $onChangeClause onchange clause for fields
1235 * @param integer $tabindex tab index
1236 * @param string $special_chars special characters
1237 * @param integer $tabindex_for_value offset for the values tabindex
1238 * @param integer $idindex id index
1239 * @param string $text_dir text direction
1240 * @param string $special_chars_encoded replaced char if the string starts
1241 * with a \r\n pair (0x0d0a) add an extra \n
1242 * @param string $data data to edit
1243 * @param array $extracted_columnspec associative array containing type,
1244 * spec_in_brackets and possibly
1245 * enum_set_values (another array)
1247 * @return string an html snippet
1249 function PMA_getValueColumnForOtherDatatypes($column, $default_char_editing,
1250 $backup_field,
1251 $column_name_appendix, $onChangeClause, $tabindex, $special_chars,
1252 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data,
1253 $extracted_columnspec
1255 // HTML5 data-* attribute data-type
1256 $data_type = $GLOBALS['PMA_Types']->getTypeClass($column['True_Type']);
1257 $fieldsize = PMA_getColumnSize($column, $extracted_columnspec);
1258 $html_output = $backup_field . "\n";
1259 if ($column['is_char']
1260 && ($GLOBALS['cfg']['CharEditing'] == 'textarea'
1261 || /*overload*/mb_strpos($data, "\n") !== false)
1263 $html_output .= "\n";
1264 $GLOBALS['cfg']['CharEditing'] = $default_char_editing;
1265 $html_output .= PMA_getTextarea(
1266 $column, $backup_field, $column_name_appendix, $onChangeClause,
1267 $tabindex, $tabindex_for_value, $idindex, $text_dir,
1268 $special_chars_encoded, $data_type
1270 } else {
1271 $html_output .= PMA_getHTMLinput(
1272 $column, $column_name_appendix, $special_chars, $fieldsize,
1273 $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data_type
1276 if ($column['Extra'] == 'auto_increment') {
1277 $html_output .= '<input type="hidden" name="auto_increment'
1278 . $column_name_appendix . '" value="1" />';
1280 if (substr($column['pma_type'], 0, 9) == 'timestamp') {
1281 $html_output .= '<input type="hidden" name="fields_type'
1282 . $column_name_appendix . '" value="timestamp" />';
1284 if (substr($column['pma_type'], 0, 8) == 'datetime') {
1285 $html_output .= '<input type="hidden" name="fields_type'
1286 . $column_name_appendix . '" value="datetime" />';
1288 if ($column['True_Type'] == 'bit') {
1289 $html_output .= '<input type="hidden" name="fields_type'
1290 . $column_name_appendix . '" value="bit" />';
1292 if ($column['pma_type'] == 'date'
1293 || $column['pma_type'] == 'datetime'
1294 || substr($column['pma_type'], 0, 9) == 'timestamp'
1296 // the _3 suffix points to the date field
1297 // the _2 suffix points to the corresponding NULL checkbox
1298 // in dateFormat, 'yy' means the year with 4 digits
1301 return $html_output;
1305 * Get the field size
1307 * @param array $column description of column in given table
1308 * @param array $extracted_columnspec associative array containing type,
1309 * spec_in_brackets and possibly enum_set_values
1310 * (another array)
1312 * @return integer field size
1314 function PMA_getColumnSize($column, $extracted_columnspec)
1316 if ($column['is_char']) {
1317 $fieldsize = $extracted_columnspec['spec_in_brackets'];
1318 if ($fieldsize > $GLOBALS['cfg']['MaxSizeForInputField']) {
1320 * This case happens for CHAR or VARCHAR columns which have
1321 * a size larger than the maximum size for input field.
1323 $GLOBALS['cfg']['CharEditing'] = 'textarea';
1325 } else {
1327 * This case happens for example for INT or DATE columns;
1328 * in these situations, the value returned in $column['len']
1329 * seems appropriate.
1331 $fieldsize = $column['len'];
1333 return min(
1334 max($fieldsize, $GLOBALS['cfg']['MinSizeForInputField']),
1335 $GLOBALS['cfg']['MaxSizeForInputField']
1340 * Get HTML for gis data types
1342 * @return string an html snippet
1344 function PMA_getHTMLforGisDataTypes()
1346 $edit_str = PMA_Util::getIcon('b_edit.png', __('Edit/Insert'));
1347 return '<span class="open_gis_editor">'
1348 . PMA_Util::linkOrButton(
1349 '#', $edit_str, array(), false, false, '_blank'
1351 . '</span>';
1355 * get html for continue insertion form
1357 * @param string $table name of the table
1358 * @param string $db name of the database
1359 * @param array $where_clause_array array of where clauses
1360 * @param string $err_url error url
1362 * @return string an html snippet
1364 function PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url)
1366 $html_output = '<form id="continueForm" method="post"'
1367 . ' action="tbl_replace.php" name="continueForm">'
1368 . PMA_URL_getHiddenInputs($db, $table)
1369 . '<input type="hidden" name="goto"'
1370 . ' value="' . htmlspecialchars($GLOBALS['goto']) . '" />'
1371 . '<input type="hidden" name="err_url"'
1372 . ' value="' . htmlspecialchars($err_url) . '" />'
1373 . '<input type="hidden" name="sql_query"'
1374 . ' value="' . htmlspecialchars($_REQUEST['sql_query']) . '" />';
1376 if (isset($_REQUEST['where_clause'])) {
1377 foreach ($where_clause_array as $key_id => $where_clause) {
1379 $html_output .= '<input type="hidden"'
1380 . ' name="where_clause[' . $key_id . ']"'
1381 . ' value="' . htmlspecialchars(trim($where_clause)) . '" />' . "\n";
1384 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1385 $option_values = array(1, 2, 5, 10, 15, 20, 30, 40);
1387 foreach ($option_values as $value) {
1388 $tmp .= '<option value="' . $value . '"';
1389 if ($value == $GLOBALS['cfg']['InsertRows']) {
1390 $tmp .= ' selected="selected"';
1392 $tmp .= '>' . $value . '</option>' . "\n";
1395 $tmp .= '</select>' . "\n";
1396 $html_output .= "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1397 unset($tmp);
1398 $html_output .= '</form>' . "\n";
1399 return $html_output;
1403 * Get action panel
1405 * @param array $where_clause where clause
1406 * @param string $after_insert insert mode, e.g. new_insert, same_insert
1407 * @param integer $tabindex tab index
1408 * @param integer $tabindex_for_value offset for the values tabindex
1409 * @param boolean $found_unique_key boolean variable for unique key
1411 * @return string an html snippet
1413 function PMA_getActionsPanel($where_clause, $after_insert, $tabindex,
1414 $tabindex_for_value, $found_unique_key
1416 $html_output = '<fieldset id="actions_panel">'
1417 . '<table cellpadding="5" cellspacing="0">'
1418 . '<tr>'
1419 . '<td class="nowrap vmiddle">'
1420 . PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
1421 . "\n";
1423 $html_output .= '</td>'
1424 . '<td class="vmiddle">'
1425 . '&nbsp;&nbsp;&nbsp;<strong>'
1426 . __('and then') . '</strong>&nbsp;&nbsp;&nbsp;'
1427 . '</td>'
1428 . '<td class="nowrap vmiddle">'
1429 . PMA_getAfterInsertDropDown(
1430 $where_clause, $after_insert, $found_unique_key
1432 . '</td>'
1433 . '</tr>';
1434 $html_output .='<tr>'
1435 . PMA_getSubmitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
1436 . '</tr>'
1437 . '</table>'
1438 . '</fieldset>';
1439 return $html_output;
1443 * Get a HTML drop down for submit types
1445 * @param array $where_clause where clause
1446 * @param integer $tabindex tab index
1447 * @param integer $tabindex_for_value offset for the values tabindex
1449 * @return string an html snippet
1451 function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
1453 $html_output = '<select name="submit_type" class="control_at_footer" tabindex="'
1454 . ($tabindex + $tabindex_for_value + 1) . '">';
1455 if (isset($where_clause)) {
1456 $html_output .= '<option value="save">' . __('Save') . '</option>';
1458 $html_output .= '<option value="insert">'
1459 . __('Insert as new row')
1460 . '</option>'
1461 . '<option value="insertignore">'
1462 . __('Insert as new row and ignore errors')
1463 . '</option>'
1464 . '<option value="showinsert">'
1465 . __('Show insert query')
1466 . '</option>'
1467 . '</select>';
1468 return $html_output;
1472 * Get HTML drop down for after insert
1474 * @param array $where_clause where clause
1475 * @param string $after_insert insert mode, e.g. new_insert, same_insert
1476 * @param boolean $found_unique_key boolean variable for unique key
1478 * @return string an html snippet
1480 function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key)
1482 $html_output = '<select name="after_insert" class="control_at_footer">'
1483 . '<option value="back" '
1484 . ($after_insert == 'back' ? 'selected="selected"' : '') . '>'
1485 . __('Go back to previous page') . '</option>'
1486 . '<option value="new_insert" '
1487 . ($after_insert == 'new_insert' ? 'selected="selected"' : '') . '>'
1488 . __('Insert another new row') . '</option>';
1490 if (isset($where_clause)) {
1491 $html_output .= '<option value="same_insert" '
1492 . ($after_insert == 'same_insert' ? 'selected="selected"' : '') . '>'
1493 . __('Go back to this page') . '</option>';
1495 // If we have just numeric primary key, we can also edit next
1496 // in 2.8.2, we were looking for `field_name` = numeric_value
1497 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1498 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1499 $is_numeric = false;
1500 if (! is_array($where_clause)) {
1501 $where_clause = array($where_clause);
1503 for ($i = 0, $nb = count($where_clause); $i < $nb; $i++) {
1504 // preg_match() returns 1 if there is a match
1505 $is_numeric = (preg_match(
1506 '@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@',
1507 $where_clause[$i]
1508 ) == 1);
1509 if ($is_numeric === true) {
1510 break;
1513 if ($found_unique_key && $is_numeric) {
1514 $html_output .= '<option value="edit_next" '
1515 . ($after_insert == 'edit_next' ? 'selected="selected"' : '') . '>'
1516 . __('Edit next row') . '</option>';
1520 $html_output .= '</select>';
1521 return $html_output;
1526 * get Submit button and Reset button for action panel
1528 * @param integer $tabindex tab index
1529 * @param integer $tabindex_for_value offset for the values tabindex
1531 * @return string an html snippet
1533 function PMA_getSubmitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
1535 return '<td>'
1536 . PMA_Util::showHint(
1538 'Use TAB key to move from value to value,'
1539 . ' or CTRL+arrows to move anywhere'
1542 . '</td>'
1543 . '<td colspan="3" class="right vmiddle">'
1544 . '<input type="submit" class="control_at_footer" value="' . __('Go') . '"'
1545 . ' tabindex="' . ($tabindex + $tabindex_for_value + 6) . '" id="buttonYes" />'
1546 . '<input type="button" class="preview_sql" value="' . __('Preview SQL') . '"'
1547 . ' tabindex="' . ($tabindex + $tabindex_for_value + 7) . '" />'
1548 . '<input type="reset" class="control_at_footer" value="' . __('Reset') . '"'
1549 . ' tabindex="' . ($tabindex + $tabindex_for_value + 8) . '" />'
1550 . '</td>';
1554 * Get table head and table foot for insert row table
1556 * @param array $url_params url parameters
1558 * @return string an html snippet
1560 function PMA_getHeadAndFootOfInsertRowTable($url_params)
1562 $html_output = '<table class="insertRowTable topmargin">'
1563 . '<thead>'
1564 . '<tr>'
1565 . '<th>' . __('Column') . '</th>';
1567 if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
1568 $html_output .= PMA_showTypeOrFunction('type', $url_params, true);
1570 if ($GLOBALS['cfg']['ShowFunctionFields']) {
1571 $html_output .= PMA_showTypeOrFunction('function', $url_params, true);
1574 $html_output .= '<th>' . __('Null') . '</th>'
1575 . '<th>' . __('Value') . '</th>'
1576 . '</tr>'
1577 . '</thead>'
1578 . ' <tfoot>'
1579 . '<tr>'
1580 . '<th colspan="5" class="tblFooters right">'
1581 . '<input type="submit" value="' . __('Go') . '" />'
1582 . '</th>'
1583 . '</tr>'
1584 . '</tfoot>';
1585 return $html_output;
1589 * Prepares the field value and retrieve special chars, backup field and data array
1591 * @param array $current_row a row of the table
1592 * @param array $column description of column in given table
1593 * @param array $extracted_columnspec associative array containing type,
1594 * spec_in_brackets and possibly
1595 * enum_set_values (another array)
1596 * @param boolean $real_null_value whether column value null or not null
1597 * @param array $gis_data_types list of GIS data types
1598 * @param string $column_name_appendix string to append to column name in input
1599 * @param bool $as_is use the data as is, used in repopulating
1601 * @return array $real_null_value, $data, $special_chars, $backup_field,
1602 * $special_chars_encoded
1604 function PMA_getSpecialCharsAndBackupFieldForExistingRow(
1605 $current_row, $column, $extracted_columnspec,
1606 $real_null_value, $gis_data_types, $column_name_appendix, $as_is
1608 $special_chars_encoded = '';
1609 $data = null;
1610 // (we are editing)
1611 if (!isset($current_row[$column['Field']])) {
1612 $real_null_value = true;
1613 $current_row[$column['Field']] = '';
1614 $special_chars = '';
1615 $data = $current_row[$column['Field']];
1616 } elseif ($column['True_Type'] == 'bit') {
1617 $special_chars = $as_is
1618 ? $current_row[$column['Field']]
1619 : PMA_Util::printableBitValue(
1620 $current_row[$column['Field']],
1621 $extracted_columnspec['spec_in_brackets']
1623 } elseif ((substr($column['True_Type'], 0, 9) == 'timestamp'
1624 || $column['True_Type'] == 'datetime'
1625 || $column['True_Type'] == 'time')
1626 && (/*overload*/mb_strpos($current_row[$column['Field']], ".") !== false)
1628 $current_row[$column['Field']] = $as_is
1629 ? $current_row[$column['Field']]
1630 : PMA_Util::addMicroseconds(
1631 $current_row[$column['Field']]
1633 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1634 } elseif (in_array($column['True_Type'], $gis_data_types)) {
1635 // Convert gis data to Well Know Text format
1636 $current_row[$column['Field']] = $as_is
1637 ? $current_row[$column['Field']]
1638 : PMA_Util::asWKT(
1639 $current_row[$column['Field']], true
1641 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1642 } else {
1643 // special binary "characters"
1644 if ($column['is_binary']
1645 || ($column['is_blob'] && $GLOBALS['cfg']['ProtectBinary'] !== 'all')
1647 $current_row[$column['Field']] = $as_is
1648 ? $current_row[$column['Field']]
1649 : bin2hex(
1650 $current_row[$column['Field']]
1652 } // end if
1653 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1655 //We need to duplicate the first \n or otherwise we will lose
1656 //the first newline entered in a VARCHAR or TEXT column
1657 $special_chars_encoded
1658 = PMA_Util::duplicateFirstNewline($special_chars);
1660 $data = $current_row[$column['Field']];
1661 } // end if... else...
1663 //when copying row, it is useful to empty auto-increment column
1664 // to prevent duplicate key error
1665 if (isset($_REQUEST['default_action'])
1666 && $_REQUEST['default_action'] === 'insert'
1668 if ($column['Key'] === 'PRI'
1669 && /*overload*/mb_strpos($column['Extra'], 'auto_increment') !== false
1671 $data = $special_chars_encoded = $special_chars = null;
1674 // If a timestamp field value is not included in an update
1675 // statement MySQL auto-update it to the current timestamp;
1676 // however, things have changed since MySQL 4.1, so
1677 // it's better to set a fields_prev in this situation
1678 $backup_field = '<input type="hidden" name="fields_prev'
1679 . $column_name_appendix . '" value="'
1680 . htmlspecialchars($current_row[$column['Field']]) . '" />';
1682 return array(
1683 $real_null_value,
1684 $special_chars_encoded,
1685 $special_chars,
1686 $data,
1687 $backup_field
1692 * display default values
1694 * @param array $column description of column in given table
1695 * @param boolean $real_null_value whether column value null or not null
1697 * @return array $real_null_value, $data, $special_chars,
1698 * $backup_field, $special_chars_encoded
1700 function PMA_getSpecialCharsAndBackupFieldForInsertingMode(
1701 $column, $real_null_value
1703 if (! isset($column['Default'])) {
1704 $column['Default'] = '';
1705 $real_null_value = true;
1706 $data = '';
1707 } else {
1708 $data = $column['Default'];
1711 $trueType = $column['True_Type'];
1713 if ($trueType == 'bit') {
1714 $special_chars = PMA_Util::convertBitDefaultValue($column['Default']);
1715 } elseif (substr($trueType, 0, 9) == 'timestamp'
1716 || $trueType == 'datetime'
1717 || $trueType == 'time'
1719 $special_chars = PMA_Util::addMicroseconds($column['Default']);
1720 } elseif ($trueType == 'binary' || $trueType == 'varbinary') {
1721 $special_chars = bin2hex($column['Default']);
1722 } else {
1723 $special_chars = htmlspecialchars($column['Default']);
1725 $backup_field = '';
1726 $special_chars_encoded = PMA_Util::duplicateFirstNewline($special_chars);
1727 return array(
1728 $real_null_value, $data, $special_chars,
1729 $backup_field, $special_chars_encoded
1734 * Prepares the update/insert of a row
1736 * @return array $loop_array, $using_key, $is_insert, $is_insertignore
1738 function PMA_getParamsForUpdateOrInsert()
1740 if (isset($_REQUEST['where_clause'])) {
1741 // we were editing something => use the WHERE clause
1742 $loop_array = is_array($_REQUEST['where_clause'])
1743 ? $_REQUEST['where_clause']
1744 : array($_REQUEST['where_clause']);
1745 $using_key = true;
1746 $is_insert = isset($_REQUEST['submit_type'])
1747 && ($_REQUEST['submit_type'] == 'insert'
1748 || $_REQUEST['submit_type'] == 'showinsert'
1749 || $_REQUEST['submit_type'] == 'insertignore');
1750 } else {
1751 // new row => use indexes
1752 $loop_array = array();
1753 if (! empty($_REQUEST['fields'])) {
1754 foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) {
1755 $loop_array[] = $key;
1758 $using_key = false;
1759 $is_insert = true;
1761 $is_insertignore = isset($_REQUEST['submit_type'])
1762 && $_REQUEST['submit_type'] == 'insertignore';
1763 return array($loop_array, $using_key, $is_insert, $is_insertignore);
1767 * Check wether insert row mode and if so include tbl_changen script and set
1768 * global variables.
1770 * @return void
1772 function PMA_isInsertRow()
1774 if (isset($_REQUEST['insert_rows'])
1775 && is_numeric($_REQUEST['insert_rows'])
1776 && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows']
1778 $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows'];
1779 $response = PMA_Response::getInstance();
1780 $header = $response->getHeader();
1781 $scripts = $header->getScripts();
1782 $scripts->addFile('tbl_change.js');
1783 if (!defined('TESTSUITE')) {
1784 include 'tbl_change.php';
1785 exit;
1791 * set $_SESSION for edit_next
1793 * @param string $one_where_clause one where clause from where clauses array
1795 * @return void
1797 function PMA_setSessionForEditNext($one_where_clause)
1799 $local_query = 'SELECT * FROM ' . PMA_Util::backquote($GLOBALS['db'])
1800 . '.' . PMA_Util::backquote($GLOBALS['table']) . ' WHERE '
1801 . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;';
1803 $res = $GLOBALS['dbi']->query($local_query);
1804 $row = $GLOBALS['dbi']->fetchRow($res);
1805 $meta = $GLOBALS['dbi']->getFieldsMeta($res);
1806 // must find a unique condition based on unique key,
1807 // not a combination of all fields
1808 list($unique_condition, $clause_is_unique)
1809 = PMA_Util::getUniqueCondition(
1810 $res, // handle
1811 count($meta), // fields_cnt
1812 $meta, // fields_meta
1813 $row, // row
1814 true, // force_unique
1815 false, // restrict_to_table
1816 null // analyzed_sql_results
1818 if (! empty($unique_condition)) {
1819 $_SESSION['edit_next'] = $unique_condition;
1821 unset($unique_condition, $clause_is_unique);
1825 * set $goto_include variable for different cases and retrieve like,
1826 * if $GLOBALS['goto'] empty, if $goto_include previously not defined
1827 * and new_insert, same_insert, edit_next
1829 * @param string $goto_include store some script for include, otherwise it is
1830 * boolean false
1832 * @return string $goto_include
1834 function PMA_getGotoInclude($goto_include)
1836 $valid_options = array('new_insert', 'same_insert', 'edit_next');
1837 if (isset($_REQUEST['after_insert'])
1838 && in_array($_REQUEST['after_insert'], $valid_options)
1840 $goto_include = 'tbl_change.php';
1841 } elseif (! empty($GLOBALS['goto'])) {
1842 if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) {
1843 // this should NOT happen
1844 //$GLOBALS['goto'] = false;
1845 $goto_include = false;
1846 } else {
1847 $goto_include = $GLOBALS['goto'];
1849 if ($GLOBALS['goto'] == 'db_sql.php'
1850 && /*overload*/mb_strlen($GLOBALS['table'])
1852 $GLOBALS['table'] = '';
1855 if (! $goto_include) {
1856 if (! /*overload*/mb_strlen($GLOBALS['table'])) {
1857 $goto_include = 'db_sql.php';
1858 } else {
1859 $goto_include = 'tbl_sql.php';
1862 return $goto_include;
1866 * Defines the url to return in case of failure of the query
1868 * @param array $url_params url parameters
1870 * @return string error url for query failure
1872 function PMA_getErrorUrl($url_params)
1874 if (isset($_REQUEST['err_url'])) {
1875 return $_REQUEST['err_url'];
1876 } else {
1877 return 'tbl_change.php' . PMA_URL_getCommon($url_params);
1882 * Builds the sql query
1884 * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore'
1885 * @param array $query_fields column names array
1886 * @param array $value_sets array of query values
1888 * @return array of query
1890 function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets)
1892 if ($is_insertignore) {
1893 $insert_command = 'INSERT IGNORE ';
1894 } else {
1895 $insert_command = 'INSERT ';
1897 $query = array(
1898 $insert_command . 'INTO '
1899 . PMA_Util::backquote($GLOBALS['table'])
1900 . ' (' . implode(', ', $query_fields) . ') VALUES ('
1901 . implode('), (', $value_sets) . ')'
1903 unset($insert_command, $query_fields);
1904 return $query;
1908 * Executes the sql query and get the result, then move back to the calling page
1910 * @param array $url_params url parameters array
1911 * @param array $query built query from PMA_buildSqlQuery()
1913 * @return array $url_params, $total_affected_rows, $last_messages
1914 * $warning_messages, $error_messages, $return_to_sql_query
1916 function PMA_executeSqlQuery($url_params, $query)
1918 $return_to_sql_query = '';
1919 if (! empty($GLOBALS['sql_query'])) {
1920 $url_params['sql_query'] = $GLOBALS['sql_query'];
1921 $return_to_sql_query = $GLOBALS['sql_query'];
1923 $GLOBALS['sql_query'] = implode('; ', $query) . ';';
1924 // to ensure that the query is displayed in case of
1925 // "insert as new row" and then "insert another new row"
1926 $GLOBALS['display_query'] = $GLOBALS['sql_query'];
1928 $total_affected_rows = 0;
1929 $last_messages = array();
1930 $warning_messages = array();
1931 $error_messages = array();
1933 foreach ($query as $single_query) {
1934 if ($_REQUEST['submit_type'] == 'showinsert') {
1935 $last_messages[] = PMA_Message::notice(__('Showing SQL query'));
1936 continue;
1938 if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
1939 $result = $GLOBALS['dbi']->tryQuery($single_query);
1940 } else {
1941 $result = $GLOBALS['dbi']->query($single_query);
1943 if (! $result) {
1944 $error_messages[] = PMA_Message::sanitize($GLOBALS['dbi']->getError());
1945 } else {
1946 // The next line contains a real assignment, it's not a typo
1947 if ($tmp = @$GLOBALS['dbi']->affectedRows()) {
1948 $total_affected_rows += $tmp;
1950 unset($tmp);
1952 $insert_id = $GLOBALS['dbi']->insertId();
1953 if ($insert_id != 0) {
1954 // insert_id is id of FIRST record inserted in one insert, so if we
1955 // inserted multiple rows, we had to increment this
1957 if ($total_affected_rows > 0) {
1958 $insert_id = $insert_id + $total_affected_rows - 1;
1960 $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
1961 $last_message->addParam($insert_id);
1962 $last_messages[] = $last_message;
1964 $GLOBALS['dbi']->freeResult($result);
1966 $warning_messages = PMA_getWarningMessages();
1968 return array(
1969 $url_params,
1970 $total_affected_rows,
1971 $last_messages,
1972 $warning_messages,
1973 $error_messages,
1974 $return_to_sql_query
1979 * get the warning messages array
1981 * @return array $warning_essages
1983 function PMA_getWarningMessages()
1985 $warning_essages = array();
1986 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1987 $warning_essages[] = PMA_Message::sanitize(
1988 $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message']
1991 return $warning_essages;
1995 * Column to display from the foreign table?
1997 * @param string $where_comparison string that contain relation field value
1998 * @param array $map all Relations to foreign tables for a given
1999 * table or optionally a given column in a table
2000 * @param string $relation_field relation field
2002 * @return string $dispval display value from the foreign table
2004 function PMA_getDisplayValueForForeignTableColumn($where_comparison,
2005 $map, $relation_field
2007 $foreigner = PMA_searchColumnInForeigners($map, $relation_field);
2008 $display_field = PMA_getDisplayField(
2009 $foreigner['foreign_db'],
2010 $foreigner['foreign_table']
2012 // Field to display from the foreign table?
2013 if (isset($display_field) && /*overload*/mb_strlen($display_field)) {
2014 $dispsql = 'SELECT ' . PMA_Util::backquote($display_field)
2015 . ' FROM ' . PMA_Util::backquote($foreigner['foreign_db'])
2016 . '.' . PMA_Util::backquote($foreigner['foreign_table'])
2017 . ' WHERE ' . PMA_Util::backquote($foreigner['foreign_field'])
2018 . $where_comparison;
2019 $dispresult = $GLOBALS['dbi']->tryQuery(
2020 $dispsql, null, PMA_DatabaseInterface::QUERY_STORE
2022 if ($dispresult && $GLOBALS['dbi']->numRows($dispresult) > 0) {
2023 list($dispval) = $GLOBALS['dbi']->fetchRow($dispresult, 0);
2024 } else {
2025 $dispval = '';
2027 @$GLOBALS['dbi']->freeResult($dispresult);
2028 return $dispval;
2030 return '';
2034 * Display option in the cell according to user choices
2036 * @param array $map all Relations to foreign tables for a given
2037 * table or optionally a given column in a table
2038 * @param string $relation_field relation field
2039 * @param string $where_comparison string that contain relation field value
2040 * @param string $dispval display value from the foreign table
2041 * @param string $relation_field_value relation field value
2043 * @return string $output HTML <a> tag
2045 function PMA_getLinkForRelationalDisplayField($map, $relation_field,
2046 $where_comparison, $dispval, $relation_field_value
2048 $foreigner = PMA_searchColumnInForeigners($map, $relation_field);
2049 if ('K' == $_SESSION['tmpval']['relational_display']) {
2050 // user chose "relational key" in the display options, so
2051 // the title contains the display field
2052 $title = (! empty($dispval))
2053 ? ' title="' . htmlspecialchars($dispval) . '"'
2054 : '';
2055 } else {
2056 $title = ' title="' . htmlspecialchars($relation_field_value) . '"';
2058 $_url_params = array(
2059 'db' => $foreigner['foreign_db'],
2060 'table' => $foreigner['foreign_table'],
2061 'pos' => '0',
2062 'sql_query' => 'SELECT * FROM '
2063 . PMA_Util::backquote($foreigner['foreign_db'])
2064 . '.' . PMA_Util::backquote($foreigner['foreign_table'])
2065 . ' WHERE ' . PMA_Util::backquote($foreigner['foreign_field'])
2066 . $where_comparison
2068 $output = '<a href="sql.php'
2069 . PMA_URL_getCommon($_url_params) . '"' . $title . '>';
2071 if ('D' == $_SESSION['tmpval']['relational_display']) {
2072 // user chose "relational display field" in the
2073 // display options, so show display field in the cell
2074 $output .= (!empty($dispval)) ? htmlspecialchars($dispval) : '';
2075 } else {
2076 // otherwise display data in the cell
2077 $output .= htmlspecialchars($relation_field_value);
2079 $output .= '</a>';
2080 return $output;
2084 * Transform edited values
2086 * @param string $db db name
2087 * @param string $table table name
2088 * @param array $transformation mimetypes for all columns of a table
2089 * [field_name][field_key]
2090 * @param array &$edited_values transform columns list and new values
2091 * @param string $file file containing the transformation plugin
2092 * @param string $column_name column name
2093 * @param array $extra_data extra data array
2094 * @param string $type the type of transformation
2096 * @return array $extra_data
2098 function PMA_transformEditedValues($db, $table,
2099 $transformation, &$edited_values, $file, $column_name, $extra_data, $type
2101 $include_file = 'libraries/plugins/transformations/' . $file;
2102 if (is_file($include_file)) {
2103 include_once $include_file;
2104 $_url_params = array(
2105 'db' => $db,
2106 'table' => $table,
2107 'where_clause' => $_REQUEST['where_clause'],
2108 'transform_key' => $column_name
2110 $transform_options = PMA_Transformation_getOptions(
2111 isset($transformation[$type . '_options'])
2112 ? $transformation[$type . '_options']
2113 : ''
2115 $transform_options['wrapper_link']
2116 = PMA_URL_getCommon($_url_params);
2117 $class_name = PMA_getTransformationClassName($file);
2118 /** @var TransformationsPlugin $transformation_plugin */
2119 $transformation_plugin = new $class_name();
2121 foreach ($edited_values as $cell_index => $curr_cell_edited_values) {
2122 if (isset($curr_cell_edited_values[$column_name])) {
2123 $edited_values[$cell_index][$column_name]
2124 = $extra_data['transformations'][$cell_index]
2125 = $transformation_plugin->applyTransformation(
2126 $curr_cell_edited_values[$column_name],
2127 $transform_options,
2131 } // end of loop for each transformation cell
2133 return $extra_data;
2137 * Get current value in multi edit mode
2139 * @param array $multi_edit_funcs multiple edit functions array
2140 * @param array $multi_edit_salt multiple edit array with encryption salt
2141 * @param array $gis_from_text_functions array that contains gis from text functions
2142 * @param string $current_value current value in the column
2143 * @param array $gis_from_wkb_functions initially $val is $multi_edit_columns[$key]
2144 * @param array $func_optional_param array('RAND','UNIX_TIMESTAMP')
2145 * @param array $func_no_param array of set of string
2146 * @param string $key an md5 of the column name
2148 * @return array $cur_value
2150 function PMA_getCurrentValueAsAnArrayForMultipleEdit( $multi_edit_funcs,
2151 $multi_edit_salt,
2152 $gis_from_text_functions, $current_value, $gis_from_wkb_functions,
2153 $func_optional_param, $func_no_param, $key
2155 if (empty($multi_edit_funcs[$key])) {
2156 return $current_value;
2157 } elseif ('UUID' === $multi_edit_funcs[$key]) {
2158 /* This way user will know what UUID new row has */
2159 $uuid = $GLOBALS['dbi']->fetchValue('SELECT UUID()');
2160 return "'" . $uuid . "'";
2161 } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions)
2162 && substr($current_value, 0, 3) == "'''")
2163 || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions)
2165 // Remove enclosing apostrophes
2166 $current_value = /*overload*/mb_substr($current_value, 1, -1);
2167 // Remove escaping apostrophes
2168 $current_value = str_replace("''", "'", $current_value);
2169 return $multi_edit_funcs[$key] . '(' . $current_value . ')';
2170 } elseif (! in_array($multi_edit_funcs[$key], $func_no_param)
2171 || ($current_value != "''"
2172 && in_array($multi_edit_funcs[$key], $func_optional_param))
2174 if ((isset($multi_edit_salt[$key])
2175 && ($multi_edit_funcs[$key] == "AES_ENCRYPT"
2176 || $multi_edit_funcs[$key] == "AES_DECRYPT"))
2177 || (! empty($multi_edit_salt[$key])
2178 && ($multi_edit_funcs[$key] == "DES_ENCRYPT"
2179 || $multi_edit_funcs[$key] == "DES_DECRYPT"
2180 || $multi_edit_funcs[$key] == "ENCRYPT"))
2182 return $multi_edit_funcs[$key] . '(' . $current_value . ",'"
2183 . PMA_Util::sqlAddSlashes($multi_edit_salt[$key]) . "')";
2184 } else {
2185 return $multi_edit_funcs[$key] . '(' . $current_value . ')';
2187 } else {
2188 return $multi_edit_funcs[$key] . '()';
2193 * Get query values array and query fields array for insert and update in multi edit
2195 * @param array $multi_edit_columns_name multiple edit columns name array
2196 * @param array $multi_edit_columns_null multiple edit columns null array
2197 * @param string $current_value current value in the column in loop
2198 * @param array $multi_edit_columns_prev multiple edit previous columns array
2199 * @param array $multi_edit_funcs multiple edit functions array
2200 * @param boolean $is_insert boolean value whether insert or not
2201 * @param array $query_values SET part of the sql query
2202 * @param array $query_fields array of query fields
2203 * @param string $current_value_as_an_array current value in the column
2204 * as an array
2205 * @param array $value_sets array of valu sets
2206 * @param string $key an md5 of the column name
2207 * @param array $multi_edit_columns_null_prev array of multiple edit columns
2208 * null previous
2210 * @return array ($query_values, $query_fields)
2212 function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_name,
2213 $multi_edit_columns_null, $current_value, $multi_edit_columns_prev,
2214 $multi_edit_funcs,$is_insert, $query_values, $query_fields,
2215 $current_value_as_an_array, $value_sets, $key, $multi_edit_columns_null_prev
2217 // i n s e r t
2218 if ($is_insert) {
2219 // no need to add column into the valuelist
2220 if (/*overload*/mb_strlen($current_value_as_an_array)) {
2221 $query_values[] = $current_value_as_an_array;
2222 // first inserted row so prepare the list of fields
2223 if (empty($value_sets)) {
2224 $query_fields[] = PMA_Util::backquote(
2225 $multi_edit_columns_name[$key]
2230 } elseif (! empty($multi_edit_columns_null_prev[$key])
2231 && ! isset($multi_edit_columns_null[$key])
2233 // u p d a t e
2235 // field had the null checkbox before the update
2236 // field no longer has the null checkbox
2237 $query_values[]
2238 = PMA_Util::backquote($multi_edit_columns_name[$key])
2239 . ' = ' . $current_value_as_an_array;
2240 } elseif (empty($multi_edit_funcs[$key])
2241 && isset($multi_edit_columns_prev[$key])
2242 && (("'" . PMA_Util::sqlAddSlashes($multi_edit_columns_prev[$key]) . "'" === $current_value)
2243 || ('0x' . $multi_edit_columns_prev[$key] === $current_value))
2245 // No change for this column and no MySQL function is used -> next column
2246 } elseif (! empty($current_value)) {
2247 // avoid setting a field to NULL when it's already NULL
2248 // (field had the null checkbox before the update
2249 // field still has the null checkbox)
2250 if (empty($multi_edit_columns_null_prev[$key])
2251 || empty($multi_edit_columns_null[$key])
2253 $query_values[]
2254 = PMA_Util::backquote($multi_edit_columns_name[$key])
2255 . ' = ' . $current_value_as_an_array;
2258 return array($query_values, $query_fields);
2262 * Get the current column value in the form for different data types
2264 * @param string|false $possibly_uploaded_val uploaded file content
2265 * @param string $key an md5 of the column name
2266 * @param array $multi_edit_columns_type array of multi edit column types
2267 * @param string $current_value current column value in the form
2268 * @param array $multi_edit_auto_increment multi edit auto increment
2269 * @param integer $rownumber index of where clause array
2270 * @param array $multi_edit_columns_name multi edit column names array
2271 * @param array $multi_edit_columns_null multi edit columns null array
2272 * @param array $multi_edit_columns_null_prev multi edit columns previous null
2273 * @param boolean $is_insert whether insert or not
2274 * @param boolean $using_key whether editing or new row
2275 * @param string $where_clause where clause
2276 * @param string $table table name
2278 * @return string $current_value current column value in the form
2280 function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key,
2281 $multi_edit_columns_type, $current_value, $multi_edit_auto_increment,
2282 $rownumber, $multi_edit_columns_name, $multi_edit_columns_null,
2283 $multi_edit_columns_null_prev, $is_insert, $using_key, $where_clause, $table
2285 // Fetch the current values of a row to use in case we have a protected field
2286 if ($is_insert
2287 && $using_key && isset($multi_edit_columns_type)
2288 && is_array($multi_edit_columns_type) && !empty($where_clause)
2290 $protected_row = $GLOBALS['dbi']->fetchSingleRow(
2291 'SELECT * FROM ' . PMA_Util::backquote($table)
2292 . ' WHERE ' . $where_clause . ';'
2296 if (false !== $possibly_uploaded_val) {
2297 $current_value = $possibly_uploaded_val;
2298 } else {
2299 // c o l u m n v a l u e i n t h e f o r m
2300 if (isset($multi_edit_columns_type[$key])) {
2301 $type = $multi_edit_columns_type[$key];
2302 } else {
2303 $type = '';
2306 if ($type != 'protected' && $type != 'set'
2307 && 0 === /*overload*/mb_strlen($current_value)
2309 // best way to avoid problems in strict mode
2310 // (works also in non-strict mode)
2311 if (isset($multi_edit_auto_increment)
2312 && isset($multi_edit_auto_increment[$key])
2314 $current_value = 'NULL';
2315 } else {
2316 $current_value = "''";
2318 } elseif ($type == 'set') {
2319 if (! empty($_REQUEST['fields']['multi_edit'][$rownumber][$key])) {
2320 $current_value = implode(
2321 ',', $_REQUEST['fields']['multi_edit'][$rownumber][$key]
2323 $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2324 } else {
2325 $current_value = "''";
2327 } elseif ($type == 'protected') {
2328 // here we are in protected mode (asked in the config)
2329 // so tbl_change has put this special value in the
2330 // columns array, so we do not change the column value
2331 // but we can still handle column upload
2333 // when in UPDATE mode, do not alter field's contents. When in INSERT
2334 // mode, insert empty field because no values were submitted.
2335 // If protected blobs where set, insert original fields content.
2336 if (! empty($protected_row[$multi_edit_columns_name[$key]])) {
2337 $current_value = '0x'
2338 . bin2hex($protected_row[$multi_edit_columns_name[$key]]);
2339 } else {
2340 $current_value = '';
2342 } elseif ($type === 'hex') {
2343 $current_value = '0x' . $current_value;
2344 } elseif ($type == 'bit') {
2345 $current_value = preg_replace('/[^01]/', '0', $current_value);
2346 $current_value = "b'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2347 } elseif (! ($type == 'datetime' || $type == 'timestamp')
2348 || $current_value != 'CURRENT_TIMESTAMP'
2350 $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2353 // Was the Null checkbox checked for this field?
2354 // (if there is a value, we ignore the Null checkbox: this could
2355 // be possible if Javascript is disabled in the browser)
2356 if (! empty($multi_edit_columns_null[$key])
2357 && ($current_value == "''" || $current_value == '')
2359 $current_value = 'NULL';
2362 // The Null checkbox was unchecked for this field
2363 if (empty($current_value)
2364 && ! empty($multi_edit_columns_null_prev[$key])
2365 && ! isset($multi_edit_columns_null[$key])
2367 $current_value = "''";
2369 } // end else (column value in the form)
2370 return $current_value;
2375 * Check whether inline edited value can be truncated or not,
2376 * and add additional parameters for extra_data array if needed
2378 * @param string $db Database name
2379 * @param string $table Table name
2380 * @param string $column_name Column name
2381 * @param array &$extra_data Extra data for ajax response
2383 * @return void
2385 function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData(
2386 $db, $table, $column_name, &$extra_data
2389 $extra_data['isNeedToRecheck'] = false;
2391 $sql_for_real_value = 'SELECT ' . PMA_Util::backquote($table) . '.'
2392 . PMA_Util::backquote($column_name)
2393 . ' FROM ' . PMA_Util::backquote($db) . '.'
2394 . PMA_Util::backquote($table)
2395 . ' WHERE ' . $_REQUEST['where_clause'][0];
2397 $result = $GLOBALS['dbi']->tryQuery($sql_for_real_value);
2398 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
2399 $meta = $fields_meta[0];
2400 if ($row = $GLOBALS['dbi']->fetchRow($result)) {
2401 $new_value = $row[0];
2402 if ((substr($meta->type, 0, 9) == 'timestamp')
2403 || ($meta->type == 'datetime')
2404 || ($meta->type == 'time')
2406 $new_value = PMA_Util::addMicroseconds($new_value);
2408 $extra_data['isNeedToRecheck'] = true;
2409 $extra_data['truncatableFieldValue'] = $new_value;
2411 $GLOBALS['dbi']->freeResult($result);
2415 * Function to get the columns of a table
2417 * @param string $db current db
2418 * @param string $table current table
2420 * @return array
2422 function PMA_getTableColumns($db, $table)
2424 $GLOBALS['dbi']->selectDb($db);
2425 return array_values($GLOBALS['dbi']->getColumns($db, $table, null, true));
2430 * Function to determine Insert/Edit rows
2432 * @param string $where_clause where clause
2433 * @param string $db current database
2434 * @param string $table current table
2436 * @return mixed
2438 function PMA_determineInsertOrEdit($where_clause, $db, $table)
2440 if (isset($_REQUEST['where_clause'])) {
2441 $where_clause = $_REQUEST['where_clause'];
2443 if (isset($_SESSION['edit_next'])) {
2444 $where_clause = $_SESSION['edit_next'];
2445 unset($_SESSION['edit_next']);
2446 $after_insert = 'edit_next';
2448 if (isset($_REQUEST['ShowFunctionFields'])) {
2449 $GLOBALS['cfg']['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
2451 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
2452 $GLOBALS['cfg']['ShowFieldTypesInDataEditView']
2453 = $_REQUEST['ShowFieldTypesInDataEditView'];
2455 if (isset($_REQUEST['after_insert'])) {
2456 $after_insert = $_REQUEST['after_insert'];
2459 if (isset($where_clause)) {
2460 // we are editing
2461 $insert_mode = false;
2462 $where_clause_array = PMA_getWhereClauseArray($where_clause);
2463 list($where_clauses, $result, $rows, $found_unique_key)
2464 = PMA_analyzeWhereClauses(
2465 $where_clause_array, $table, $db
2467 } else {
2468 // we are inserting
2469 $insert_mode = true;
2470 $where_clause = null;
2471 list($result, $rows) = PMA_loadFirstRow($table, $db);
2472 $where_clauses = null;
2473 $where_clause_array = array();
2474 $found_unique_key = false;
2477 // Copying a row - fetched data will be inserted as a new row,
2478 // therefore the where clause is needless.
2479 if (isset($_REQUEST['default_action'])
2480 && $_REQUEST['default_action'] === 'insert'
2482 $where_clause = $where_clauses = null;
2485 return array(
2486 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
2487 $result, $rows, $found_unique_key,
2488 isset($after_insert) ? $after_insert : null
2493 * Function to get comments for the table columns
2495 * @param string $db current database
2496 * @param string $table current table
2498 * @return array $comments_map comments for columns
2500 function PMA_getCommentsMap($db, $table)
2503 * get table information
2504 * @todo should be done by a Table object
2506 include 'libraries/tbl_info.inc.php';
2509 * Get comments for table fields/columns
2511 $comments_map = array();
2513 if ($GLOBALS['cfg']['ShowPropertyComments']) {
2514 $comments_map = PMA_getComments($db, $table);
2517 return $comments_map;
2521 * Function to get URL parameters
2523 * @param string $db current database
2524 * @param string $table current table
2526 * @return array $url_params url parameters
2528 function PMA_getUrlParameters($db, $table)
2531 * @todo check if we could replace by "db_|tbl_" - please clarify!?
2533 $url_params = array(
2534 'db' => $db,
2535 'sql_query' => $_REQUEST['sql_query']
2538 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
2539 $url_params['table'] = $table;
2542 return $url_params;
2546 * Function to get html for the gis editor div
2548 * @return string
2550 function PMA_getHtmlForGisEditor()
2552 return '<div id="gis_editor"></div>'
2553 . '<div id="popup_background"></div>'
2554 . '<br />';
2558 * Function to get html for the ignore option in insert mode
2560 * @param int $row_id row id
2561 * @param bool $checked ignore option is checked or not
2563 * @return string
2565 function PMA_getHtmlForIgnoreOption($row_id, $checked = true)
2567 return '<input type="checkbox"'
2568 . ($checked ? ' checked="checked"' : '')
2569 . ' name="insert_ignore_' . $row_id . '"'
2570 . ' id="insert_ignore_' . $row_id . '" />'
2571 . '<label for="insert_ignore_' . $row_id . '">'
2572 . __('Ignore')
2573 . '</label><br />' . "\n";
2577 * Function to get html for the function option
2579 * @param bool $odd_row whether odd row or not
2580 * @param array $column column
2581 * @param string $column_name_appendix column name appendix
2583 * @return String
2585 function PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix)
2587 $longDoubleTextArea = $GLOBALS['cfg']['LongtextDoubleTextarea'];
2588 return '<tr class="noclick ' . ($odd_row ? 'odd' : 'even' ) . '">'
2589 . '<td '
2590 . ($longDoubleTextArea
2591 && /*overload*/mb_strstr($column['True_Type'], 'longtext')
2592 ? 'rowspan="2"'
2593 : ''
2595 . 'class="center">'
2596 . $column['Field_title']
2597 . '<input type="hidden" name="fields_name' . $column_name_appendix
2598 . '" value="' . $column['Field_html'] . '"/>'
2599 . '</td>';
2604 * Function to get html for the column type
2606 * @param array $column column
2608 * @return string
2610 function PMA_getHtmlForInsertEditColumnType($column)
2612 return '<td class="center' . $column['wrap'] . '">'
2613 . '<span class="column_type" dir="ltr">' . $column['pma_type'] . '</span>'
2614 . '</td>';
2619 * Function to get html for the insert edit form header
2621 * @param bool $has_blob_field whether has blob field
2622 * @param bool $is_upload whether is upload
2624 * @return string
2626 function PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload)
2628 $html_output ='<form id="insertForm" class="lock-page ';
2629 if ($has_blob_field && $is_upload) {
2630 $html_output .='disableAjax';
2632 $html_output .='" method="post" action="tbl_replace.php" name="insertForm" ';
2633 if ($is_upload) {
2634 $html_output .= ' enctype="multipart/form-data"';
2636 $html_output .= '>';
2638 return $html_output;
2642 * Function to get html for each insert/edit column
2644 * @param array $table_columns table columns
2645 * @param int $column_number column index in table_columns
2646 * @param array $comments_map comments map
2647 * @param bool $timestamp_seen whether timestamp seen
2648 * @param array $current_result current result
2649 * @param string $chg_evt_handler javascript change event handler
2650 * @param string $jsvkey javascript validation key
2651 * @param string $vkey validation key
2652 * @param bool $insert_mode whether insert mode
2653 * @param array $current_row current row
2654 * @param bool $odd_row whether odd row
2655 * @param int &$o_rows row offset
2656 * @param int &$tabindex tab index
2657 * @param int $columns_cnt columns count
2658 * @param bool $is_upload whether upload
2659 * @param int $tabindex_for_function tab index offset for function
2660 * @param array $foreigners foreigners
2661 * @param int $tabindex_for_null tab index offset for null
2662 * @param int $tabindex_for_value tab index offset for value
2663 * @param string $table table
2664 * @param string $db database
2665 * @param int $row_id row id
2666 * @param array $titles titles
2667 * @param int $biggest_max_file_size biggest max file size
2668 * @param string $default_char_editing default char editing mode which is stored
2669 * in the config.inc.php script
2670 * @param string $text_dir text direction
2671 * @param array $repopulate the data to be repopulated
2672 * @param array $column_mime the mime information of column
2673 * @param string $where_clause the where clause
2675 * @return string
2677 function PMA_getHtmlForInsertEditFormColumn($table_columns, $column_number,
2678 $comments_map, $timestamp_seen, $current_result, $chg_evt_handler,
2679 $jsvkey, $vkey, $insert_mode, $current_row, $odd_row, &$o_rows,
2680 &$tabindex, $columns_cnt, $is_upload, $tabindex_for_function,
2681 $foreigners, $tabindex_for_null, $tabindex_for_value, $table, $db,
2682 $row_id, $titles, $biggest_max_file_size, $default_char_editing,
2683 $text_dir, $repopulate, $column_mime, $where_clause
2685 $column = $table_columns[$column_number];
2686 if (! isset($column['processed'])) {
2687 $column = PMA_analyzeTableColumnsArray(
2688 $column, $comments_map, $timestamp_seen
2691 $as_is = false;
2692 if (!empty($repopulate) && !empty($current_row)) {
2693 $current_row[$column['Field']] = $repopulate[$column['Field_md5']];
2694 $as_is = true;
2697 $extracted_columnspec
2698 = PMA_Util::extractColumnSpec($column['Type']);
2700 if (-1 === $column['len']) {
2701 $column['len'] = $GLOBALS['dbi']->fieldLen(
2702 $current_result, $column_number
2704 // length is unknown for geometry fields,
2705 // make enough space to edit very simple WKTs
2706 if (-1 === $column['len']) {
2707 $column['len'] = 30;
2710 //Call validation when the form submitted...
2711 $onChangeClause = $chg_evt_handler
2712 . "=\"return verificationsAfterFieldChange('"
2713 . PMA_escapeJsString($column['Field_md5']) . "', '"
2714 . PMA_escapeJsString($jsvkey) . "','" . $column['pma_type'] . "')\"";
2716 // Use an MD5 as an array index to avoid having special characters
2717 // in the name attribute (see bug #1746964 )
2718 $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']';
2720 if ($column['Type'] === 'datetime'
2721 && ! isset($column['Default'])
2722 && ! is_null($column['Default'])
2723 && $insert_mode
2725 $column['Default'] = date('Y-m-d H:i:s', time());
2728 $html_output = PMA_getHtmlForFunctionOption(
2729 $odd_row, $column, $column_name_appendix
2732 if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
2733 $html_output .= PMA_getHtmlForInsertEditColumnType($column);
2734 } //End if
2736 // Get a list of GIS data types.
2737 $gis_data_types = PMA_Util::getGISDatatypes();
2739 // Prepares the field value
2740 $real_null_value = false;
2741 $special_chars_encoded = '';
2742 if (!empty($current_row)) {
2743 // (we are editing)
2744 list(
2745 $real_null_value, $special_chars_encoded, $special_chars,
2746 $data, $backup_field
2748 = PMA_getSpecialCharsAndBackupFieldForExistingRow(
2749 $current_row, $column, $extracted_columnspec,
2750 $real_null_value, $gis_data_types, $column_name_appendix, $as_is
2752 } else {
2753 // (we are inserting)
2754 // display default values
2755 $tmp = $column;
2756 if (isset($repopulate[$column['Field_md5']])) {
2757 $tmp['Default'] = $repopulate[$column['Field_md5']];
2759 list($real_null_value, $data, $special_chars, $backup_field,
2760 $special_chars_encoded
2762 = PMA_getSpecialCharsAndBackupFieldForInsertingMode(
2763 $tmp, $real_null_value
2765 unset($tmp);
2768 $idindex = ($o_rows * $columns_cnt) + $column_number + 1;
2769 $tabindex = $idindex;
2771 // Get a list of data types that are not yet supported.
2772 $no_support_types = PMA_Util::unsupportedDatatypes();
2774 // The function column
2775 // -------------------
2776 if ($GLOBALS['cfg']['ShowFunctionFields']) {
2777 $html_output .= PMA_getFunctionColumn(
2778 $column, $is_upload, $column_name_appendix,
2779 $onChangeClause, $no_support_types, $tabindex_for_function,
2780 $tabindex, $idindex, $insert_mode
2784 // The null column
2785 // ---------------
2786 $foreignData = PMA_getForeignData(
2787 $foreigners, $column['Field'], false, '', ''
2789 $html_output .= PMA_getNullColumn(
2790 $column, $column_name_appendix, $real_null_value,
2791 $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners,
2792 $foreignData
2795 // The value column (depends on type)
2796 // ----------------
2797 // See bug #1667887 for the reason why we don't use the maxlength
2798 // HTML attribute
2800 //add data attributes "no of decimals" and "data type"
2801 $no_decimals = 0;
2802 $type = current(explode("(", $column['pma_type']));
2803 if (preg_match('/\(([^()]+)\)/', $column['pma_type'], $match)) {
2804 $match[0] = trim($match[0], '()');
2805 $no_decimals = $match[0];
2807 $html_output .= '<td' . ' data-type="' . $type . '"' . ' data-decimals="'
2808 . $no_decimals . '">' . "\n";
2809 // Will be used by js/tbl_change.js to set the default value
2810 // for the "Continue insertion" feature
2811 $html_output .= '<span class="default_value hide">'
2812 . $special_chars . '</span>';
2814 // Check input transformation of column
2815 $transformed_html = '';
2816 if (!empty($column_mime['input_transformation'])) {
2817 $file = $column_mime['input_transformation'];
2818 $include_file = 'libraries/plugins/transformations/' . $file;
2819 if (is_file($include_file)) {
2820 include_once $include_file;
2821 $class_name = PMA_getTransformationClassName($file);
2822 $transformation_plugin = new $class_name();
2823 $transformation_options = PMA_Transformation_getOptions(
2824 $column_mime['input_transformation_options']
2826 $_url_params = array(
2827 'db' => $db,
2828 'table' => $table,
2829 'transform_key' => $column['Field'],
2830 'where_clause' => $where_clause
2832 $transformation_options['wrapper_link']
2833 = PMA_URL_getCommon($_url_params);
2834 $current_value = '';
2835 if (isset($current_row[$column['Field']])) {
2836 $current_value = $current_row[$column['Field']];
2838 if (method_exists($transformation_plugin, 'getInputHtml')) {
2839 $transformed_html = $transformation_plugin->getInputHtml(
2840 $column, $row_id, $column_name_appendix,
2841 $transformation_options, $current_value, $text_dir,
2842 $tabindex, $tabindex_for_value, $idindex
2845 if (method_exists($transformation_plugin, 'getScripts')) {
2846 $GLOBALS['plugin_scripts'] = array_merge(
2847 $GLOBALS['plugin_scripts'], $transformation_plugin->getScripts()
2852 if (!empty($transformed_html)) {
2853 $html_output .= $transformed_html;
2854 } else {
2855 $html_output .= PMA_getValueColumn(
2856 $column, $backup_field, $column_name_appendix, $onChangeClause,
2857 $tabindex, $tabindex_for_value, $idindex, $data, $special_chars,
2858 $foreignData, $odd_row, array($table, $db), $row_id, $titles,
2859 $text_dir, $special_chars_encoded, $vkey, $is_upload,
2860 $biggest_max_file_size, $default_char_editing,
2861 $no_support_types, $gis_data_types, $extracted_columnspec
2864 $html_output .= '</td>'
2865 . '</tr>';
2867 return $html_output;
2871 * Function to get html for each insert/edit row
2873 * @param array $url_params url parameters
2874 * @param array $table_columns table columns
2875 * @param array $comments_map comments map
2876 * @param bool $timestamp_seen whether timestamp seen
2877 * @param array $current_result current result
2878 * @param string $chg_evt_handler javascript change event handler
2879 * @param string $jsvkey javascript validation key
2880 * @param string $vkey validation key
2881 * @param bool $insert_mode whether insert mode
2882 * @param array $current_row current row
2883 * @param int &$o_rows row offset
2884 * @param int &$tabindex tab index
2885 * @param int $columns_cnt columns count
2886 * @param bool $is_upload whether upload
2887 * @param int $tabindex_for_function tab index offset for function
2888 * @param array $foreigners foreigners
2889 * @param int $tabindex_for_null tab index offset for null
2890 * @param int $tabindex_for_value tab index offset for value
2891 * @param string $table table
2892 * @param string $db database
2893 * @param int $row_id row id
2894 * @param array $titles titles
2895 * @param int $biggest_max_file_size biggest max file size
2896 * @param string $text_dir text direction
2897 * @param array $repopulate the data to be repopulated
2898 * @param array $where_clause_array the array of where clauses
2900 * @return string
2902 function PMA_getHtmlForInsertEditRow($url_params, $table_columns,
2903 $comments_map, $timestamp_seen, $current_result, $chg_evt_handler,
2904 $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, &$tabindex, $columns_cnt,
2905 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
2906 $tabindex_for_value, $table, $db, $row_id, $titles,
2907 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
2909 $html_output = PMA_getHeadAndFootOfInsertRowTable($url_params)
2910 . '<tbody>';
2912 //store the default value for CharEditing
2913 $default_char_editing = $GLOBALS['cfg']['CharEditing'];
2914 $mime_map = PMA_getMIME($db, $table);
2915 $odd_row = true;
2916 $where_clause = '';
2917 if (isset($where_clause_array[$row_id])) {
2918 $where_clause = $where_clause_array[$row_id];
2920 for ($column_number = 0; $column_number < $columns_cnt; $column_number++) {
2921 $table_column = $table_columns[$column_number];
2922 // skip this column if user does not have necessary column privilges
2923 if (! PMA_userHasColumnPrivileges($table_column, $insert_mode)) {
2924 continue;
2926 $column_mime = array();
2927 if (isset($mime_map[$table_column['Field']])) {
2928 $column_mime = $mime_map[$table_column['Field']];
2930 $html_output .= PMA_getHtmlForInsertEditFormColumn(
2931 $table_columns, $column_number, $comments_map, $timestamp_seen,
2932 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
2933 $current_row, $odd_row, $o_rows, $tabindex, $columns_cnt, $is_upload,
2934 $tabindex_for_function, $foreigners, $tabindex_for_null,
2935 $tabindex_for_value, $table, $db, $row_id, $titles,
2936 $biggest_max_file_size, $default_char_editing, $text_dir, $repopulate,
2937 $column_mime, $where_clause
2939 $odd_row = !$odd_row;
2940 } // end for
2941 $o_rows++;
2942 $html_output .= ' </tbody>'
2943 . '</table><br />'
2944 . '<div class="clearfloat"></div>';
2946 return $html_output;
2950 * Returns whether the user has necessary insert/update privileges for the column
2952 * @param array $table_column array of column details
2953 * @param bool $insert_mode whether on insert mode
2955 * @return boolean whether user has necessary privileges
2957 function PMA_userHasColumnPrivileges($table_column, $insert_mode)
2959 $privileges = $table_column['Privileges'];
2960 return ($insert_mode && strstr($privileges, 'insert') !== false)
2961 || (! $insert_mode && strstr($privileges, 'update') !== false)
2962 || is_null($privileges); // Drizzle