added japanese language
[openemr.git] / phpmyadmin / libraries / insert_edit.lib.php
blob2a6415d96544317521a4ca46f440c44cc5f741a3
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 $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 $where_clause where clause
50 * @return array|void whereClauseArray array of where clauses
52 function PMA_getWhereClauseArray($where_clause)
54 if (!isset($where_clause)) {
55 return;
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], count($meta), $meta, $rows[$key_id], true
140 if (! empty($unique_condition)) {
141 $has_unique_condition = true;
143 unset($unique_condition, $tmp_clause_is_unique);
145 return $has_unique_condition;
149 * No primary key given, just load first row
151 * @param string $table name of the table
152 * @param string $db name of the database
154 * @return array containing $result and $rows arrays
156 function PMA_loadFirstRow($table, $db)
158 $result = $GLOBALS['dbi']->query(
159 'SELECT * FROM ' . PMA_Util::backquote($db)
160 . '.' . PMA_Util::backquote($table) . ' LIMIT 1;',
161 null,
162 PMA_DatabaseInterface::QUERY_STORE
164 $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false);
165 return array($result, $rows);
169 * Add some url parameters
171 * @param array $url_params containing $db and $table as url parameters
172 * @param array $where_clause_array where clauses array
173 * @param string $where_clause where clause
175 * @return array Add some url parameters to $url_params array and return it
177 function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause)
179 if (isset($where_clause)) {
180 foreach ($where_clause_array as $where_clause) {
181 $url_params['where_clause'] = trim($where_clause);
184 if (! empty($_REQUEST['sql_query'])) {
185 $url_params['sql_query'] = $_REQUEST['sql_query'];
187 return $url_params;
191 * Show function fields in data edit view in pma
193 * @param array $url_params containing url parameters
194 * @param boolean $showFuncFields whether to show function field
196 * @return string an html snippet
198 function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields)
200 $params = array();
201 if (! $showFuncFields) {
202 $params['ShowFunctionFields'] = 1;
203 } else {
204 $params['ShowFunctionFields'] = 0;
206 $params['ShowFieldTypesInDataEditView']
207 = $GLOBALS['cfg']['ShowFieldTypesInDataEditView'];
208 $params['goto'] = 'sql.php';
209 $this_url_params = array_merge($url_params, $params);
210 if (! $showFuncFields) {
211 return ' : <a href="tbl_change.php'
212 . PMA_URL_getCommon($this_url_params) . '">'
213 . __('Function')
214 . '</a>' . "\n";
216 return '<th><a href="tbl_change.php'
217 . PMA_URL_getCommon($this_url_params)
218 . '" title="' . __('Hide') . '">'
219 . __('Function')
220 . '</a></th>' . "\n";
224 * Show field types in data edit view in pma
226 * @param array $url_params containing url parameters
227 * @param boolean $showColumnType whether to show column type
229 * @return string an html snippet
231 function PMA_showColumnTypesInDataEditView($url_params, $showColumnType)
233 $params = array();
234 if (! $showColumnType) {
235 $params['ShowFieldTypesInDataEditView'] = 1;
236 } else {
237 $params['ShowFieldTypesInDataEditView'] = 0;
239 $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields'];
240 $params['goto'] = 'sql.php';
241 $this_other_url_params = array_merge($url_params, $params);
242 if (! $showColumnType) {
243 return ' : <a href="tbl_change.php'
244 . PMA_URL_getCommon($this_other_url_params) . '">'
245 . __('Type') . '</a>' . "\n";
247 return '<th><a href="tbl_change.php'
248 . PMA_URL_getCommon($this_other_url_params)
249 . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
254 * Retrieve the default for datetime data type
256 * @param array $column containing column type, Default and null
258 * @return void
260 function PMA_getDefaultForDatetime($column)
262 // d a t e t i m e
264 // Current date should not be set as default if the field is NULL
265 // for the current row, but do not put here the current datetime
266 // if there is a default value (the real default value will be set
267 // in the Default value logic below)
269 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
270 // $column['Default'] is not set if it contains NULL:
271 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
272 // [Extra] => [True_Type] => datetime)
273 // but, look what we get if we switch to iso: (Default is NULL)
274 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
275 // [Default] => [Extra] => [True_Type] => datetime)
276 // so I force a NULL into it (I don't think it's possible
277 // to have an empty default value for DATETIME)
278 // then, the "if" after this one will work
279 if ($column['Type'] == 'datetime'
280 && ! isset($column['Default'])
281 && isset($column['Null'])
282 && $column['Null'] == 'YES'
284 $column['Default'] = null;
289 * Analyze the table column array
291 * @param array $column description of column in given table
292 * @param array $comments_map comments for every column that has a comment
293 * @param boolean $timestamp_seen whether a timestamp has been seen
295 * @return array description of column in given table
297 function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen)
299 $column['Field_html'] = htmlspecialchars($column['Field']);
300 $column['Field_md5'] = md5($column['Field']);
301 // True_Type contains only the type (stops at first bracket)
302 $column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']);
303 PMA_getDefaultForDatetime($column);
304 $column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1;
305 $column['Field_title'] = PMA_getColumnTitle($column, $comments_map);
306 $column['is_binary'] = PMA_isColumnBinary($column);
307 $column['is_blob'] = PMA_isColumnBlob($column);
308 $column['is_char'] = PMA_isColumnChar($column);
309 list($column['pma_type'], $column['wrap'], $column['first_timestamp'])
310 = PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen);
312 return $column;
316 * Retrieve the column title
318 * @param array $column description of column in given table
319 * @param array $comments_map comments for every column that has a comment
321 * @return string column title
323 function PMA_getColumnTitle($column, $comments_map)
325 if (isset($comments_map[$column['Field']])) {
326 return '<span style="border-bottom: 1px dashed black;" title="'
327 . htmlspecialchars($comments_map[$column['Field']]) . '">'
328 . $column['Field_html'] . '</span>';
329 } else {
330 return $column['Field_html'];
335 * check whether the column is a bainary
337 * @param array $column description of column in given table
339 * @return boolean If check to ensure types such as "enum('one','two','binary',..)"
340 * or "enum('one','two','varbinary',..)" are not categorized as
341 * binary.
343 function PMA_isColumnBinary($column)
345 // The type column.
346 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
347 if (stripos($column['Type'], 'binary') === 0
348 || stripos($column['Type'], 'varbinary') === 0
350 return stristr($column['Type'], 'binary');
351 } else {
352 return false;
358 * check whether the column is a blob
360 * @param array $column description of column in given table
362 * @return boolean If check to ensure types such as "enum('one','two','blob',..)"
363 * or "enum('one','two','tinyblob',..)" etc. are not categorized
364 * as blob.
366 function PMA_isColumnBlob($column)
368 if (stripos($column['Type'], 'blob') === 0
369 || stripos($column['Type'], 'tinyblob') === 0
370 || stripos($column['Type'], 'mediumblob') === 0
371 || stripos($column['Type'], 'longblob') === 0
373 return stristr($column['Type'], 'blob');
374 } else {
375 return false;
380 * check is table column char
382 * @param array $column description of column in given table
384 * @return boolean If check to ensure types such as "enum('one','two','char',..)" or
385 * "enum('one','two','varchar',..)" are not categorized as char.
387 function PMA_isColumnChar($column)
389 if (stripos($column['Type'], 'char') === 0
390 || stripos($column['Type'], 'varchar') === 0
392 return stristr($column['Type'], 'char');
393 } else {
394 return false;
398 * Retrieve set, enum, timestamp table columns
400 * @param array $column description of column in given table
401 * @param boolean $timestamp_seen whether a timestamp has been seen
403 * @return array $column['pma_type'], $column['wrap'], $column['first_timestamp']
405 function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen)
407 $column['first_timestamp'] = false;
408 switch ($column['True_Type']) {
409 case 'set':
410 $column['pma_type'] = 'set';
411 $column['wrap'] = '';
412 break;
413 case 'enum':
414 $column['pma_type'] = 'enum';
415 $column['wrap'] = '';
416 break;
417 case 'timestamp':
418 if (! $timestamp_seen) { // can only occur once per table
419 $timestamp_seen = true;
420 $column['first_timestamp'] = true;
422 $column['pma_type'] = $column['Type'];
423 $column['wrap'] = ' nowrap';
424 break;
426 default:
427 $column['pma_type'] = $column['Type'];
428 $column['wrap'] = ' nowrap';
429 break;
431 return array($column['pma_type'], $column['wrap'], $column['first_timestamp']);
435 * The function column
436 * We don't want binary data to be destroyed
437 * Note: from the MySQL manual: "BINARY doesn't affect how the column is
438 * stored or retrieved" so it does not mean that the contents is binary
440 * @param array $column description of column in given table
441 * @param boolean $is_upload upload or no
442 * @param string $column_name_appendix the name atttibute
443 * @param string $unnullify_trigger validation string
444 * @param array $no_support_types list of datatypes that are not (yet)
445 * handled by PMA
446 * @param integer $tabindex_for_function +3000
447 * @param integer $tabindex tab index
448 * @param integer $idindex id index
449 * @param boolean $insert_mode insert mode or edit mode
451 * @return string an html sippet
453 function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix,
454 $unnullify_trigger, $no_support_types, $tabindex_for_function,
455 $tabindex, $idindex, $insert_mode
457 $html_output = '';
458 if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && ! $is_upload)
459 || ($GLOBALS['cfg']['ProtectBinary'] === 'all' && $column['is_binary'])
460 || ($GLOBALS['cfg']['ProtectBinary'] === 'noblob' && ! $column['is_blob'])
462 $html_output .= '<td class="center">' . __('Binary') . '</td>' . "\n";
463 } elseif (strstr($column['True_Type'], 'enum')
464 || strstr($column['True_Type'], 'set')
465 || in_array($column['pma_type'], $no_support_types)
467 $html_output .= '<td class="center">--</td>' . "\n";
468 } else {
469 $html_output .= '<td>' . "\n";
471 $html_output .= '<select name="funcs' . $column_name_appendix . '"'
472 . ' ' . $unnullify_trigger
473 . ' tabindex="' . ($tabindex + $tabindex_for_function) . '"'
474 . ' id="field_' . $idindex . '_1">';
475 $html_output .= PMA_Util::getFunctionsForField($column, $insert_mode) . "\n";
477 $html_output .= '</select>' . "\n";
478 $html_output .= '</td>' . "\n";
480 return $html_output;
484 * The null column
486 * @param array $column description of column in given table
487 * @param string $column_name_appendix the name atttibute
488 * @param array $real_null_value is column value null or not null
489 * @param integer $tabindex tab index
490 * @param integer $tabindex_for_null +6000
491 * @param integer $idindex id index
492 * @param string $vkey [multi_edit]['row_id']
493 * @param array $foreigners keys into foreign fields
494 * @param array $foreignData data about the foreign keys
496 * @return string an html snippet
498 function PMA_getNullColumn($column, $column_name_appendix, $real_null_value,
499 $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData
501 if ($column['Null'] != 'YES') {
502 return "<td></td>\n";
504 $html_output = '';
505 $html_output .= '<td>' . "\n";
506 $html_output .= '<input type="hidden" name="fields_null_prev'
507 . $column_name_appendix . '"';
508 if ($real_null_value && !$column['first_timestamp']) {
509 $html_output .= ' value="on"';
511 $html_output .= ' />' . "\n";
513 $html_output .= '<input type="checkbox" class="checkbox_null" tabindex="'
514 . ($tabindex + $tabindex_for_null) . '"'
515 . ' name="fields_null' . $column_name_appendix . '"';
516 if ($real_null_value) {
517 $html_output .= ' checked="checked"';
519 $html_output .= ' id="field_' . ($idindex) . '_2" />';
521 // nullify_code is needed by the js nullify() function
522 $nullify_code = PMA_getNullifyCodeForNullColumn(
523 $column, $foreigners, $foreignData
525 // to be able to generate calls to nullify() in jQuery
526 $html_output .= '<input type="hidden" class="nullify_code" name="nullify_code'
527 . $column_name_appendix . '" value="' . $nullify_code . '" />';
528 $html_output .= '<input type="hidden" class="hashed_field" name="hashed_field'
529 . $column_name_appendix . '" value="' . $column['Field_md5'] . '" />';
530 $html_output .= '<input type="hidden" class="multi_edit" name="multi_edit'
531 . $column_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
532 $html_output .= '</td>' . "\n";
534 return $html_output;
538 * Retrieve the nullify code for the null column
540 * @param array $column description of column in given table
541 * @param array $foreigners keys into foreign fields
542 * @param array $foreignData data about the foreign keys
544 * @return integer $nullify_code
546 function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData)
548 if (strstr($column['True_Type'], 'enum')) {
549 if (strlen($column['Type']) > 20) {
550 $nullify_code = '1';
551 } else {
552 $nullify_code = '2';
554 } elseif (strstr($column['True_Type'], 'set')) {
555 $nullify_code = '3';
556 } elseif ($foreigners
557 && isset($foreigners[$column['Field']])
558 && $foreignData['foreign_link'] == false
560 // foreign key in a drop-down
561 $nullify_code = '4';
562 } elseif ($foreigners
563 && isset($foreigners[$column['Field']])
564 && $foreignData['foreign_link'] == true
566 // foreign key with a browsing icon
567 $nullify_code = '6';
568 } else {
569 $nullify_code = '5';
571 return $nullify_code;
575 * Get the HTML elements for value column in insert form
576 * (here, "column" is used in the sense of HTML column in HTML table)
578 * @param array $column description of column in given table
579 * @param string $backup_field hidden input field
580 * @param string $column_name_appendix the name atttibute
581 * @param string $unnullify_trigger validation string
582 * @param integer $tabindex tab index
583 * @param integer $tabindex_for_value offset for the values tabindex
584 * @param integer $idindex id index
585 * @param array $data description of the column field
586 * @param string $special_chars special characters
587 * @param array $foreignData data about the foreign keys
588 * @param boolean $odd_row whether row is odd
589 * @param array $paramTableDbArray array containing $table and $db
590 * @param int $rownumber the row number
591 * @param array $titles An HTML IMG tag for a particular icon from
592 * a theme, which may be an actual file or
593 * an icon from a sprite
594 * @param string $text_dir text direction
595 * @param string $special_chars_encoded replaced char if the string starts
596 * with a \r\n pair (0x0d0a) add an extra \n
597 * @param string $vkey [multi_edit]['row_id']
598 * @param boolean $is_upload is upload or not
599 * @param integer $biggest_max_file_size 0 intger
600 * @param string $default_char_editing default char editing mode which is stroe
601 * in the config.inc.php script
602 * @param array $no_support_types list of datatypes that are not (yet)
603 * handled by PMA
604 * @param array $gis_data_types list of GIS data types
605 * @param array $extracted_columnspec associative array containing type,
606 * spec_in_brackets and possibly
607 * enum_set_values (another array)
609 * @return string an html snippet
611 function PMA_getValueColumn($column, $backup_field, $column_name_appendix,
612 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
613 $special_chars, $foreignData, $odd_row, $paramTableDbArray, $rownumber,
614 $titles, $text_dir, $special_chars_encoded, $vkey,
615 $is_upload, $biggest_max_file_size,
616 $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec
618 $html_output = '';
620 if ($foreignData['foreign_link'] == true) {
621 $html_output .= PMA_getForeignLink(
622 $column, $backup_field, $column_name_appendix,
623 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
624 $paramTableDbArray, $rownumber, $titles
627 } elseif (is_array($foreignData['disp_row'])) {
628 $html_output .= PMA_dispRowForeignData(
629 $backup_field, $column_name_appendix,
630 $unnullify_trigger, $tabindex, $tabindex_for_value,
631 $idindex, $data, $foreignData
634 } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
635 && strstr($column['pma_type'], 'longtext')
637 $html_output = '&nbsp;</td>';
638 $html_output .= '</tr>';
639 $html_output .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
640 . '<td colspan="5" class="right">';
641 $html_output .= PMA_getTextarea(
642 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
643 $tabindex, $tabindex_for_value, $idindex, $text_dir,
644 $special_chars_encoded
647 } elseif (strstr($column['pma_type'], 'text')) {
649 $html_output .= PMA_getTextarea(
650 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
651 $tabindex, $tabindex_for_value, $idindex, $text_dir,
652 $special_chars_encoded
654 $html_output .= "\n";
655 if (strlen($special_chars) > 32000) {
656 $html_output .= "</td>\n";
657 $html_output .= '<td>' . __(
658 'Because of its length,<br /> this column might not be editable.'
662 } elseif ($column['pma_type'] == 'enum') {
663 $html_output .= PMA_getPmaTypeEnum(
664 $column, $backup_field, $column_name_appendix, $extracted_columnspec,
665 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data
668 } elseif ($column['pma_type'] == 'set') {
669 $html_output .= PMA_getPmaTypeSet(
670 $column, $extracted_columnspec, $backup_field,
671 $column_name_appendix, $unnullify_trigger, $tabindex,
672 $tabindex_for_value, $idindex, $data
675 } elseif ($column['is_binary'] || $column['is_blob']) {
676 $html_output .= PMA_getBinaryAndBlobColumn(
677 $column, $data, $special_chars, $biggest_max_file_size,
678 $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex,
679 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
680 $vkey, $is_upload
683 } elseif (! in_array($column['pma_type'], $no_support_types)) {
684 $html_output .= PMA_getValueColumnForOtherDatatypes(
685 $column, $default_char_editing, $backup_field,
686 $column_name_appendix, $unnullify_trigger, $tabindex, $special_chars,
687 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
688 $data, $extracted_columnspec
692 if (in_array($column['pma_type'], $gis_data_types)) {
693 $html_output .= PMA_getHTMLforGisDataTypes();
696 return $html_output;
700 * Get HTML for foreign link in insert form
702 * @param array $column description of column in given table
703 * @param string $backup_field hidden input field
704 * @param string $column_name_appendix the name atttibute
705 * @param string $unnullify_trigger validation string
706 * @param integer $tabindex tab index
707 * @param integer $tabindex_for_value offset for the values tabindex
708 * @param integer $idindex id index
709 * @param string $data data to edit
710 * @param array $paramTableDbArray array containing $table and $db
711 * @param int $rownumber the row number
712 * @param array $titles An HTML IMG tag for a particular icon from
713 * a theme, which may be an actual file or
714 * an icon from a sprite
716 * @return string an html snippet
718 function PMA_getForeignLink($column, $backup_field, $column_name_appendix,
719 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
720 $paramTableDbArray, $rownumber, $titles
722 list($table, $db) = $paramTableDbArray;
723 $html_output = '';
724 $html_output .= $backup_field . "\n";
726 $html_output .= '<input type="hidden" name="fields_type'
727 . $column_name_appendix . '" value="foreign" />';
729 $html_output .= '<input type="text" name="fields' . $column_name_appendix . '" '
730 . 'class="textfield" '
731 . $unnullify_trigger . ' '
732 . 'tabindex="' . ($tabindex + $tabindex_for_value) . '" '
733 . 'id="field_' . ($idindex) . '_3" '
734 . 'value="' . htmlspecialchars($data) . '" />';
736 $html_output .= '<a class="foreign_values_anchor" target="_blank" '
737 . 'onclick="window.open(this.href,\'foreigners\', \'width=640,height=240,'
738 . 'scrollbars=yes,resizable=yes\'); return false;" '
739 . 'href="browse_foreigners.php'
740 . PMA_URL_getCommon(
741 array(
742 'db' => $db,
743 'table' => $table,
744 'field' => $column['Field'],
745 'rownumber' => $rownumber,
746 'data' => $data
748 ) . '">'
749 . str_replace("'", "\'", $titles['Browse']) . '</a>';
750 return $html_output;
754 * Get HTML to display foreign data
756 * @param string $backup_field hidden input field
757 * @param string $column_name_appendix the name atttibute
758 * @param string $unnullify_trigger validation string
759 * @param integer $tabindex tab index
760 * @param integer $tabindex_for_value offset for the values tabindex
761 * @param integer $idindex id index
762 * @param string $data data to edit
763 * @param array $foreignData data about the foreign keys
765 * @return string an html snippet
767 function PMA_dispRowForeignData($backup_field, $column_name_appendix,
768 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
769 $foreignData
771 $html_output = '';
772 $html_output .= $backup_field . "\n";
773 $html_output .= '<input type="hidden"'
774 . ' name="fields_type' . $column_name_appendix . '"'
775 . ' value="foreign" />';
777 $html_output .= '<select name="fields' . $column_name_appendix . '"'
778 . ' ' . $unnullify_trigger
779 . ' class="textfield"'
780 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
781 . ' id="field_' . $idindex . '_3">';
782 $html_output .= PMA_foreignDropdown(
783 $foreignData['disp_row'], $foreignData['foreign_field'],
784 $foreignData['foreign_display'], $data,
785 $GLOBALS['cfg']['ForeignKeyMaxLimit']
787 $html_output .= '</select>';
789 return $html_output;
793 * Get HTML textarea for insert form
795 * @param array $column column information
796 * @param string $backup_field hidden input field
797 * @param string $column_name_appendix the name atttibute
798 * @param string $unnullify_trigger validation string
799 * @param integer $tabindex tab index
800 * @param integer $tabindex_for_value offset for the values tabindex
801 * @param integer $idindex id index
802 * @param array $text_dir text direction
803 * @param string $special_chars_encoded replaced char if the string starts
804 * with a \r\n pair (0x0d0a) add an extra \n
806 * @return string an html snippet
808 function PMA_getTextarea($column, $backup_field, $column_name_appendix,
809 $unnullify_trigger,
810 $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded
812 $the_class = '';
813 $textAreaRows = $GLOBALS['cfg']['TextareaRows'];
814 $textareaCols = $GLOBALS['cfg']['TextareaCols'];
816 if ($column['is_char']) {
818 * @todo clarify the meaning of the "textfield" class and explain
819 * why character columns have the "char" class instead
821 $the_class = 'char';
822 $textAreaRows = $GLOBALS['cfg']['CharTextareaRows'];
823 $textareaCols = $GLOBALS['cfg']['CharTextareaCols'];
824 $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
825 $maxlength = $extracted_columnspec['spec_in_brackets'];
826 } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
827 && strstr($column['pma_type'], 'longtext')
829 $textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2;
830 $textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2;
832 $html_output = $backup_field . "\n"
833 . '<textarea name="fields' . $column_name_appendix . '"'
834 . ' class="' . $the_class . '"'
835 . (isset($maxlength) ? ' maxlength="' . $maxlength . '"' : '')
836 . ' rows="' . $textAreaRows . '"'
837 . ' cols="' . $textareaCols . '"'
838 . ' dir="' . $text_dir . '"'
839 . ' id="field_' . ($idindex) . '_3"'
840 . ' ' . $unnullify_trigger
841 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '">'
842 . $special_chars_encoded
843 . '</textarea>';
845 return $html_output;
849 * Get HTML for enum type
851 * @param array $column description of column in given table
852 * @param string $backup_field hidden input field
853 * @param string $column_name_appendix the name atttibute
854 * @param array $extracted_columnspec associative array containing type,
855 * spec_in_brackets and possibly
856 * enum_set_values (another array)
857 * @param string $unnullify_trigger validation string
858 * @param int $tabindex tab index
859 * @param int $tabindex_for_value offset for the values tabindex
860 * @param int $idindex id index
861 * @param array $data data to edit
863 * @return string an html snippet
865 function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix,
866 $extracted_columnspec, $unnullify_trigger, $tabindex, $tabindex_for_value,
867 $idindex, $data
869 $html_output = '';
870 if (! isset($column['values'])) {
871 $column['values'] = PMA_getColumnEnumValues(
872 $column, $extracted_columnspec
875 $column_enum_values = $column['values'];
876 $html_output .= '<input type="hidden" name="fields_type'
877 . $column_name_appendix . '" value="enum" />';
878 $html_output .= '<input type="hidden" name="fields'
879 . $column_name_appendix . '" value="" />';
880 $html_output .= "\n" . ' ' . $backup_field . "\n";
881 if (strlen($column['Type']) > 20) {
882 $html_output .= PMA_getDropDownDependingOnLength(
883 $column, $column_name_appendix, $unnullify_trigger,
884 $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
886 } else {
887 $html_output .= PMA_getRadioButtonDependingOnLength(
888 $column_name_appendix, $unnullify_trigger,
889 $tabindex, $column, $tabindex_for_value,
890 $idindex, $data, $column_enum_values
893 return $html_output;
897 * Get column values
899 * @param array $column description of column in given table
900 * @param array $extracted_columnspec associative array containing type,
901 * spec_in_brackets and possibly enum_set_values
902 * (another array)
904 * @return array column values as an associative array
906 function PMA_getColumnEnumValues($column, $extracted_columnspec)
908 $column['values'] = array();
909 foreach ($extracted_columnspec['enum_set_values'] as $val) {
910 $column['values'][] = array(
911 'plain' => $val,
912 'html' => htmlspecialchars($val),
915 return $column['values'];
919 * Get HTML drop down for more than 20 string length
921 * @param array $column description of column in given table
922 * @param string $column_name_appendix the name atttibute
923 * @param string $unnullify_trigger validation string
924 * @param integer $tabindex tab index
925 * @param integer $tabindex_for_value offset for the values tabindex
926 * @param integer $idindex id index
927 * @param array $data data to edit
928 * @param array $column_enum_values $column['values']
930 * @return string an html snippet
932 function PMA_getDropDownDependingOnLength(
933 $column, $column_name_appendix, $unnullify_trigger,
934 $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
936 $html_output = '<select name="fields' . $column_name_appendix . '"'
937 . ' ' . $unnullify_trigger
938 . ' class="textfield"'
939 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
940 . ' id="field_' . ($idindex) . '_3">';
941 $html_output .= '<option value="">&nbsp;</option>' . "\n";
943 foreach ($column_enum_values as $enum_value) {
944 $html_output .= '<option value="' . $enum_value['html'] . '"';
945 if ($data == $enum_value['plain']
946 || ($data == ''
947 && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
948 && isset($column['Default'])
949 && $enum_value['plain'] == $column['Default'])
951 $html_output .= ' selected="selected"';
953 $html_output .= '>' . $enum_value['html'] . '</option>' . "\n";
955 $html_output .= '</select>';
956 return $html_output;
960 * Get HTML radio button for less than 20 string length
962 * @param string $column_name_appendix the name atttibute
963 * @param string $unnullify_trigger validation string
964 * @param integer $tabindex tab index
965 * @param array $column description of column in given table
966 * @param integer $tabindex_for_value offset for the values tabindex
967 * @param integer $idindex id index
968 * @param array $data data to edit
969 * @param array $column_enum_values $column['values']
971 * @return string an html snippet
973 function PMA_getRadioButtonDependingOnLength(
974 $column_name_appendix, $unnullify_trigger,
975 $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
977 $j = 0;
978 $html_output = '';
979 foreach ($column_enum_values as $enum_value) {
980 $html_output .= ' '
981 . '<input type="radio" name="fields' . $column_name_appendix . '"'
982 . ' class="textfield"'
983 . ' value="' . $enum_value['html'] . '"'
984 . ' id="field_' . ($idindex) . '_3_' . $j . '"'
985 . ' ' . $unnullify_trigger;
986 if ($data == $enum_value['plain']
987 || ($data == ''
988 && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
989 && isset($column['Default'])
990 && $enum_value['plain'] == $column['Default'])
992 $html_output .= ' checked="checked"';
994 $html_output .= ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
995 $html_output .= '<label for="field_' . $idindex . '_3_' . $j . '">'
996 . $enum_value['html'] . '</label>' . "\n";
997 $j++;
999 return $html_output;
1003 * Get the HTML for 'set' pma type
1005 * @param array $column description of column in given table
1006 * @param array $extracted_columnspec associative array containing type,
1007 * spec_in_brackets and possibly
1008 * enum_set_values (another array)
1009 * @param string $backup_field hidden input field
1010 * @param string $column_name_appendix the name atttibute
1011 * @param string $unnullify_trigger validation string
1012 * @param integer $tabindex tab index
1013 * @param integer $tabindex_for_value offset for the values tabindex
1014 * @param integer $idindex id index
1015 * @param string $data description of the column field
1017 * @return string an html snippet
1019 function PMA_getPmaTypeSet(
1020 $column, $extracted_columnspec, $backup_field,
1021 $column_name_appendix, $unnullify_trigger, $tabindex,
1022 $tabindex_for_value, $idindex, $data
1024 list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize(
1025 $column, $extracted_columnspec
1027 $vset = array_flip(explode(',', $data));
1028 $html_output = $backup_field . "\n";
1029 $html_output .= '<input type="hidden" name="fields_type'
1030 . $column_name_appendix . '" value="set" />';
1031 $html_output .= '<select name="fields' . $column_name_appendix . '[]' . '"'
1032 . ' class="textfield"'
1033 . ' size="' . $select_size . '"'
1034 . ' multiple="multiple"'
1035 . ' ' . $unnullify_trigger
1036 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
1037 . ' id="field_' . ($idindex) . '_3">';
1038 foreach ($column_set_values as $column_set_value) {
1039 $html_output .= '<option value="' . $column_set_value['html'] . '"';
1040 if (isset($vset[$column_set_value['plain']])) {
1041 $html_output .= ' selected="selected"';
1043 $html_output .= '>' . $column_set_value['html'] . '</option>' . "\n";
1045 $html_output .= '</select>';
1046 return $html_output;
1050 * Retrieve column 'set' value and select size
1052 * @param array $column description of column in given table
1053 * @param array $extracted_columnspec associative array containing type,
1054 * spec_in_brackets and possibly enum_set_values
1055 * (another array)
1057 * @return array $column['values'], $column['select_size']
1059 function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec)
1061 if (! isset($column['values'])) {
1062 $column['values'] = array();
1063 foreach ($extracted_columnspec['enum_set_values'] as $val) {
1064 $column['values'][] = array(
1065 'plain' => $val,
1066 'html' => htmlspecialchars($val),
1069 $column['select_size'] = min(4, count($column['values']));
1071 return array($column['values'], $column['select_size']);
1075 * Get HTML for binary and blob column
1077 * @param array $column description of column in given table
1078 * @param string $data data to edit
1079 * @param string $special_chars special characters
1080 * @param integer $biggest_max_file_size biggest max file size for uploading
1081 * @param string $backup_field hidden input field
1082 * @param string $column_name_appendix the name atttibute
1083 * @param string $unnullify_trigger validation string
1084 * @param integer $tabindex tab index
1085 * @param integer $tabindex_for_value offset for the values tabindex
1086 * @param integer $idindex id index
1087 * @param string $text_dir text direction
1088 * @param string $special_chars_encoded replaced char if the string starts
1089 * with a \r\n pair (0x0d0a) add an extra \n
1090 * @param string $vkey [multi_edit]['row_id']
1091 * @param boolean $is_upload is upload or not
1093 * @return string an html snippet
1095 function PMA_getBinaryAndBlobColumn(
1096 $column, $data, $special_chars, $biggest_max_file_size,
1097 $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex,
1098 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
1099 $vkey, $is_upload
1101 $html_output = '';
1102 if (($GLOBALS['cfg']['ProtectBinary'] === 'blob' && $column['is_blob'])
1103 || ($GLOBALS['cfg']['ProtectBinary'] === 'all')
1104 || ($GLOBALS['cfg']['ProtectBinary'] === 'noblob' && !$column['is_blob'])
1106 $html_output .= __('Binary - do not edit');
1107 if (isset($data)) {
1108 $data_size = PMA_Util::formatByteDown(
1109 strlen(stripslashes($data)), 3, 1
1111 $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')';
1112 unset($data_size);
1114 $html_output .= '<input type="hidden" name="fields_type'
1115 . $column_name_appendix . '" value="protected" />'
1116 . '<input type="hidden" name="fields'
1117 . $column_name_appendix . '" value="" />';
1118 } elseif ($column['is_blob']
1119 || ($column['len'] > $GLOBALS['cfg']['LimitChars'])
1121 $html_output .= "\n" . PMA_getTextarea(
1122 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
1123 $tabindex, $tabindex_for_value, $idindex, $text_dir,
1124 $special_chars_encoded
1126 } else {
1127 // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
1128 $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
1129 $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput(
1130 $column, $column_name_appendix, $special_chars, $fieldsize,
1131 $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
1135 if ($is_upload && $column['is_blob']) {
1136 $html_output .= '<br />'
1137 . '<input type="file"'
1138 . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"'
1139 . ' class="textfield" id="field_' . $idindex . '_3" size="10"'
1140 . ' ' . $unnullify_trigger . '/>&nbsp;';
1141 list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize(
1142 $column, $biggest_max_file_size
1144 $html_output .= $html_out;
1147 if (!empty($GLOBALS['cfg']['UploadDir'])) {
1148 $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
1151 return $html_output;
1155 * Get HTML input type
1157 * @param array $column description of column in given table
1158 * @param string $column_name_appendix the name attribute
1159 * @param string $special_chars special characters
1160 * @param integer $fieldsize html field size
1161 * @param string $unnullify_trigger validation string
1162 * @param integer $tabindex tab index
1163 * @param integer $tabindex_for_value offset for the values tabindex
1164 * @param integer $idindex id index
1166 * @return string an html snippet
1168 function PMA_getHTMLinput($column, $column_name_appendix, $special_chars,
1169 $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
1171 $input_type = 'text';
1172 // do not use the 'date' or 'time' types here; they have no effect on some
1173 // browsers and create side effects (see bug #4218)
1175 $the_class = 'textfield';
1176 // verify True_Type which does not contain the parentheses and length
1177 if ($column['True_Type'] === 'date') {
1178 $the_class .= ' datefield';
1179 } else if ($column['True_Type'] === 'time') {
1180 $the_class .= ' timefield';
1181 } else if ($column['True_Type'] === 'datetime'
1182 || $column['True_Type'] === 'timestamp'
1184 $the_class .= ' datetimefield';
1186 $input_min_max = false;
1187 if (!$GLOBALS['cfg']['ShowFunctionFields']) {
1188 if (in_array(
1189 $column['True_Type'],
1190 $GLOBALS['PMA_Types']->getIntegerTypes()
1191 )) {
1192 $input_type = 'number';
1193 $is_unsigned = substr($column['pma_type'], -9) === ' unsigned';
1194 $min_max_values = $GLOBALS['PMA_Types']->getIntegerRange(
1195 $column['True_Type'], ! $is_unsigned
1197 $input_min_max = 'min="' . $min_max_values[0] . '" '
1198 . 'max="' . $min_max_values[1] . '" ';
1201 return '<input type="' . $input_type . '"'
1202 . ' name="fields' . $column_name_appendix . '"'
1203 . ' value="' . $special_chars . '" size="' . $fieldsize . '"'
1204 . ((isset($column['is_char']) && $column['is_char']) ? ' maxlength="' . $fieldsize . '"' : '')
1205 . ($input_min_max !== false ? ' ' . $input_min_max : '')
1206 . ($input_type === 'time' ? ' step="1"' : '')
1207 . ' class="' . $the_class . '" ' . $unnullify_trigger
1208 . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
1209 . ' id="field_' . ($idindex) . '_3" />';
1213 * Get HTML select option for upload
1215 * @param string $vkey [multi_edit]['row_id']
1216 * @param array $column description of column in given table
1218 * @return string|void an html snippet
1220 function PMA_getSelectOptionForUpload($vkey, $column)
1222 $files = PMA_getFileSelectOptions(
1223 PMA_Util::userDir($GLOBALS['cfg']['UploadDir'])
1226 if ($files === false) {
1227 return '<font color="red">' . __('Error') . '</font><br />' . "\n"
1228 . __('The directory you set for upload work cannot be reached.') . "\n";
1229 } elseif (!empty($files)) {
1230 return "<br />\n"
1231 . '<i>' . __('Or') . '</i>' . ' '
1232 . __('web server upload directory:') . '<br />' . "\n"
1233 . '<select size="1" name="fields_uploadlocal'
1234 . $vkey . '[' . $column['Field_md5'] . ']">' . "\n"
1235 . '<option value="" selected="selected"></option>' . "\n"
1236 . $files
1237 . '</select>' . "\n";
1242 * Retrieve the maximum upload file size
1244 * @param array $column description of column in given table
1245 * @param integer $biggest_max_file_size biggest max file size for uploading
1247 * @return array an html snippet and $biggest_max_file_size
1249 function PMA_getMaxUploadSize($column, $biggest_max_file_size)
1251 // find maximum upload size, based on field type
1253 * @todo with functions this is not so easy, as you can basically
1254 * process any data with function like MD5
1256 global $max_upload_size;
1257 $max_field_sizes = array(
1258 'tinyblob' => '256',
1259 'blob' => '65536',
1260 'mediumblob' => '16777216',
1261 'longblob' => '4294967296' // yeah, really
1264 $this_field_max_size = $max_upload_size; // from PHP max
1265 if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) {
1266 $this_field_max_size = $max_field_sizes[$column['pma_type']];
1268 $html_output
1269 = PMA_Util::getFormattedMaximumUploadSize(
1270 $this_field_max_size
1271 ) . "\n";
1272 // do not generate here the MAX_FILE_SIZE, because we should
1273 // put only one in the form to accommodate the biggest field
1274 if ($this_field_max_size > $biggest_max_file_size) {
1275 $biggest_max_file_size = $this_field_max_size;
1277 return array($html_output, $biggest_max_file_size);
1281 * Get HTML for the Value column of other datatypes
1282 * (here, "column" is used in the sense of HTML column in HTML table)
1284 * @param array $column description of column in given table
1285 * @param string $default_char_editing default char editing mode which is stroe
1286 * in the config.inc.php script
1287 * @param string $backup_field hidden input field
1288 * @param string $column_name_appendix the name atttibute
1289 * @param string $unnullify_trigger validation string
1290 * @param integer $tabindex tab index
1291 * @param array $special_chars special characters
1292 * @param integer $tabindex_for_value offset for the values tabindex
1293 * @param integer $idindex id index
1294 * @param string $text_dir text direction
1295 * @param array $special_chars_encoded replaced char if the string starts
1296 * with a \r\n pair (0x0d0a) add an extra \n
1297 * @param strign $data data to edit
1298 * @param array $extracted_columnspec associative array containing type,
1299 * spec_in_brackets and possibly
1300 * enum_set_values (another array)
1302 * @return string an html snippet
1304 function PMA_getValueColumnForOtherDatatypes($column, $default_char_editing,
1305 $backup_field,
1306 $column_name_appendix, $unnullify_trigger, $tabindex, $special_chars,
1307 $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data,
1308 $extracted_columnspec
1310 $fieldsize = PMA_getColumnSize($column, $extracted_columnspec);
1311 $html_output = $backup_field . "\n";
1312 if ($column['is_char']
1313 && ($GLOBALS['cfg']['CharEditing'] == 'textarea'
1314 || strpos($data, "\n") !== false)
1316 $html_output .= "\n";
1317 $GLOBALS['cfg']['CharEditing'] = $default_char_editing;
1318 $html_output .= PMA_getTextarea(
1319 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
1320 $tabindex, $tabindex_for_value, $idindex, $text_dir,
1321 $special_chars_encoded
1323 } else {
1324 $html_output .= PMA_getHTMLinput(
1325 $column, $column_name_appendix, $special_chars,
1326 $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
1329 if ($column['Extra'] == 'auto_increment') {
1330 $html_output .= '<input type="hidden" name="auto_increment'
1331 . $column_name_appendix . '" value="1" />';
1333 if (substr($column['pma_type'], 0, 9) == 'timestamp') {
1334 $html_output .= '<input type="hidden" name="fields_type'
1335 . $column_name_appendix . '" value="timestamp" />';
1337 if (substr($column['pma_type'], 0, 8) == 'datetime') {
1338 $html_output .= '<input type="hidden" name="fields_type'
1339 . $column_name_appendix . '" value="datetime" />';
1341 if ($column['True_Type'] == 'bit') {
1342 $html_output .= '<input type="hidden" name="fields_type'
1343 . $column_name_appendix . '" value="bit" />';
1345 if ($column['pma_type'] == 'date'
1346 || $column['pma_type'] == 'datetime'
1347 || substr($column['pma_type'], 0, 9) == 'timestamp'
1349 // the _3 suffix points to the date field
1350 // the _2 suffix points to the corresponding NULL checkbox
1351 // in dateFormat, 'yy' means the year with 4 digits
1354 return $html_output;
1358 * Get the field size
1360 * @param array $column description of column in given table
1361 * @param array $extracted_columnspec associative array containing type,
1362 * spec_in_brackets and possibly enum_set_values
1363 * (another array)
1365 * @return integer field size
1367 function PMA_getColumnSize($column, $extracted_columnspec)
1369 if ($column['is_char']) {
1370 $fieldsize = $extracted_columnspec['spec_in_brackets'];
1371 if ($fieldsize > $GLOBALS['cfg']['MaxSizeForInputField']) {
1373 * This case happens for CHAR or VARCHAR columns which have
1374 * a size larger than the maximum size for input field.
1376 $GLOBALS['cfg']['CharEditing'] = 'textarea';
1378 } else {
1380 * This case happens for example for INT or DATE columns;
1381 * in these situations, the value returned in $column['len']
1382 * seems appropriate.
1384 $fieldsize = $column['len'];
1386 return min(
1387 max($fieldsize, $GLOBALS['cfg']['MinSizeForInputField']),
1388 $GLOBALS['cfg']['MaxSizeForInputField']
1393 * Get HTML for gis data types
1395 * @return string an html snippet
1397 function PMA_getHTMLforGisDataTypes()
1399 $edit_str = PMA_Util::getIcon('b_edit.png', __('Edit/Insert'));
1400 return '<span class="open_gis_editor">'
1401 . PMA_Util::linkOrButton(
1402 '#', $edit_str, array(), false, false, '_blank'
1404 . '</span>';
1408 * get html for continue insertion form
1410 * @param string $table name of the table
1411 * @param string $db name of the database
1412 * @param array $where_clause_array array of where clauses
1413 * @param string $err_url error url
1415 * @return string an html snippet
1417 function PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url)
1419 $html_output = '<form id="continueForm" method="post"'
1420 . ' action="tbl_replace.php" name="continueForm">'
1421 . PMA_URL_getHiddenInputs($db, $table)
1422 . '<input type="hidden" name="goto"'
1423 . ' value="' . htmlspecialchars($GLOBALS['goto']) . '" />'
1424 . '<input type="hidden" name="err_url"'
1425 . ' value="' . htmlspecialchars($err_url) . '" />'
1426 . '<input type="hidden" name="sql_query"'
1427 . ' value="' . htmlspecialchars($_REQUEST['sql_query']) . '" />';
1429 if (isset($_REQUEST['where_clause'])) {
1430 foreach ($where_clause_array as $key_id => $where_clause) {
1432 $html_output .= '<input type="hidden"'
1433 . ' name="where_clause[' . $key_id . ']"'
1434 . ' value="' . htmlspecialchars(trim($where_clause)) . '" />' . "\n";
1437 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1438 $option_values = array(1, 2, 5, 10, 15, 20, 30, 40);
1440 foreach ($option_values as $value) {
1441 $tmp .= '<option value="' . $value . '"';
1442 if ($value == $GLOBALS['cfg']['InsertRows']) {
1443 $tmp .= ' selected="selected"';
1445 $tmp .= '>' . $value . '</option>' . "\n";
1448 $tmp .= '</select>' . "\n";
1449 $html_output .= "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1450 unset($tmp);
1451 $html_output .= '</form>' . "\n";
1452 return $html_output;
1456 * Get action panel
1458 * @param array $where_clause where clause
1459 * @param string $after_insert insert mode, e.g. new_insert, same_insert
1460 * @param integer $tabindex tab index
1461 * @param integer $tabindex_for_value offset for the values tabindex
1462 * @param boolean $found_unique_key boolean variable for unique key
1464 * @return string an html snippet
1466 function PMA_getActionsPanel($where_clause, $after_insert, $tabindex,
1467 $tabindex_for_value, $found_unique_key
1469 $html_output = '<fieldset id="actions_panel">'
1470 . '<table cellpadding="5" cellspacing="0">'
1471 . '<tr>'
1472 . '<td class="nowrap vmiddle">'
1473 . PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
1474 . "\n";
1476 $html_output .= '</td>'
1477 . '<td class="vmiddle">'
1478 . '&nbsp;&nbsp;&nbsp;<strong>'
1479 . __('and then') . '</strong>&nbsp;&nbsp;&nbsp;'
1480 . '</td>'
1481 . '<td class="nowrap vmiddle">'
1482 . PMA_getAfterInsertDropDown(
1483 $where_clause, $after_insert, $found_unique_key
1485 . '</td>'
1486 . '</tr>';
1487 $html_output .='<tr>'
1488 . PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
1489 . '</tr>'
1490 . '</table>'
1491 . '</fieldset>';
1492 return $html_output;
1496 * Get a HTML drop down for submit types
1498 * @param array $where_clause where clause
1499 * @param integer $tabindex tab index
1500 * @param integer $tabindex_for_value offset for the values tabindex
1502 * @return string an html snippet
1504 function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
1506 $html_output = '<select name="submit_type" class="control_at_footer" tabindex="'
1507 . ($tabindex + $tabindex_for_value + 1) . '">';
1508 if (isset($where_clause)) {
1509 $html_output .= '<option value="save">' . __('Save') . '</option>';
1511 $html_output .= '<option value="insert">'
1512 . __('Insert as new row')
1513 . '</option>'
1514 . '<option value="insertignore">'
1515 . __('Insert as new row and ignore errors')
1516 . '</option>'
1517 . '<option value="showinsert">'
1518 . __('Show insert query')
1519 . '</option>'
1520 . '</select>';
1521 return $html_output;
1525 * Get HTML drop down for after insert
1527 * @param array $where_clause where clause
1528 * @param string $after_insert insert mode, e.g. new_insert, same_insert
1529 * @param boolean $found_unique_key boolean variable for unique key
1531 * @return string an html snippet
1533 function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key)
1535 $html_output = '<select name="after_insert" class="control_at_footer">'
1536 . '<option value="back" '
1537 . ($after_insert == 'back' ? 'selected="selected"' : '') . '>'
1538 . __('Go back to previous page') . '</option>'
1539 . '<option value="new_insert" '
1540 . ($after_insert == 'new_insert' ? 'selected="selected"' : '') . '>'
1541 . __('Insert another new row') . '</option>';
1543 if (isset($where_clause)) {
1544 $html_output .= '<option value="same_insert" '
1545 . ($after_insert == 'same_insert' ? 'selected="selected"' : '') . '>'
1546 . __('Go back to this page') . '</option>';
1548 // If we have just numeric primary key, we can also edit next
1549 // in 2.8.2, we were looking for `field_name` = numeric_value
1550 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1551 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1552 $is_numeric = false;
1553 if (! is_array($where_clause)) {
1554 $where_clause = array($where_clause);
1556 for ($i = 0, $nb = count($where_clause); $i < $nb; $i++) {
1557 $is_numeric = preg_match(
1558 '@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@',
1559 $where_clause[$i]
1561 if ($is_numeric == true) {
1562 break;
1565 if ($found_unique_key && $is_numeric) {
1566 $html_output .= '<option value="edit_next" '
1567 . ($after_insert == 'edit_next' ? 'selected="selected"' : '') . '>'
1568 . __('Edit next row') . '</option>';
1572 $html_output .= '</select>';
1573 return $html_output;
1578 * get Submit button and Reset button for action panel
1580 * @param integer $tabindex tab index
1581 * @param integer $tabindex_for_value offset for the values tabindex
1583 * @return string an html snippet
1585 function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
1587 return '<td>'
1588 . PMA_Util::showHint(
1590 'Use TAB key to move from value to value,'
1591 . ' or CTRL+arrows to move anywhere'
1594 . '</td>'
1595 . '<td colspan="3" class="right vmiddle">'
1596 . '<input type="submit" class="control_at_footer" value="' . __('Go') . '"'
1597 . ' tabindex="' . ($tabindex + $tabindex_for_value + 6) . '" id="buttonYes" />'
1598 . '<input type="reset" class="control_at_footer" value="' . __('Reset') . '"'
1599 . ' tabindex="' . ($tabindex + $tabindex_for_value + 7) . '" />'
1600 . '</td>';
1604 * Get table head and table foot for insert row table
1606 * @param array $url_params url parameters
1608 * @return string an html snippet
1610 function PMA_getHeadAndFootOfInsertRowTable($url_params)
1612 $html_output = '<table class="insertRowTable">'
1613 . '<thead>'
1614 . '<tr>'
1615 . '<th>' . __('Column') . '</th>';
1617 if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
1618 $html_output .= PMA_showColumnTypesInDataEditView($url_params, true);
1620 if ($GLOBALS['cfg']['ShowFunctionFields']) {
1621 $html_output .= PMA_showFunctionFieldsInEditMode($url_params, true);
1624 $html_output .= '<th>' . __('Null') . '</th>'
1625 . '<th>' . __('Value') . '</th>'
1626 . '</tr>'
1627 . '</thead>'
1628 . ' <tfoot>'
1629 . '<tr>'
1630 . '<th colspan="5" class="tblFooters right">'
1631 . '<input type="submit" value="' . __('Go') . '" />'
1632 . '</th>'
1633 . '</tr>'
1634 . '</tfoot>';
1635 return $html_output;
1639 * Prepares the field value and retrieve special chars, backup field and data array
1641 * @param array $current_row a row of the table
1642 * @param array $column description of column in given table
1643 * @param array $extracted_columnspec associative array containing type,
1644 * spec_in_brackets and possibly
1645 * enum_set_values (another array)
1646 * @param boolean $real_null_value whether column value null or not null
1647 * @param array $gis_data_types list of GIS data types
1648 * @param string $column_name_appendix string to append to column name in input
1650 * @return array $real_null_value, $data, $special_chars, $backup_field,
1651 * $special_chars_encoded
1653 function PMA_getSpecialCharsAndBackupFieldForExistingRow(
1654 $current_row, $column, $extracted_columnspec,
1655 $real_null_value, $gis_data_types, $column_name_appendix
1657 $special_chars_encoded = '';
1658 $data = null;
1659 // (we are editing)
1660 if (is_null($current_row[$column['Field']])) {
1661 $real_null_value = true;
1662 $current_row[$column['Field']] = '';
1663 $special_chars = '';
1664 $data = $current_row[$column['Field']];
1665 } elseif ($column['True_Type'] == 'bit') {
1666 $special_chars = PMA_Util::printableBitValue(
1667 $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets']
1669 } elseif ((substr($column['True_Type'], 0, 9) == 'timestamp'
1670 || $column['True_Type'] == 'datetime'
1671 || $column['True_Type'] == 'time')
1672 && (strpos($current_row[$column['Field']], ".") === true)
1674 $current_row[$column['Field']] = PMA_Util::addMicroseconds(
1675 $current_row[$column['Field']]
1677 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1678 } elseif (in_array($column['True_Type'], $gis_data_types)) {
1679 // Convert gis data to Well Know Text format
1680 $current_row[$column['Field']] = PMA_Util::asWKT(
1681 $current_row[$column['Field']], true
1683 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1684 } else {
1685 // special binary "characters"
1686 if ($column['is_binary']
1687 || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary'])
1689 if ($_SESSION['tmpval']['display_binary_as_hex']
1690 && $GLOBALS['cfg']['ShowFunctionFields']
1692 $current_row[$column['Field']] = bin2hex(
1693 $current_row[$column['Field']]
1695 $column['display_binary_as_hex'] = true;
1696 } else {
1697 $current_row[$column['Field']]
1698 = PMA_Util::replaceBinaryContents(
1699 $current_row[$column['Field']]
1702 } // end if
1703 $special_chars = htmlspecialchars($current_row[$column['Field']]);
1705 //We need to duplicate the first \n or otherwise we will lose
1706 //the first newline entered in a VARCHAR or TEXT column
1707 $special_chars_encoded
1708 = PMA_Util::duplicateFirstNewline($special_chars);
1710 $data = $current_row[$column['Field']];
1711 } // end if... else...
1713 //when copying row, it is useful to empty auto-increment column
1714 // to prevent duplicate key error
1715 if (isset($_REQUEST['default_action'])
1716 && $_REQUEST['default_action'] === 'insert'
1718 if ($column['Key'] === 'PRI'
1719 && strpos($column['Extra'], 'auto_increment') !== false
1721 $data = $special_chars_encoded = $special_chars = null;
1724 // If a timestamp field value is not included in an update
1725 // statement MySQL auto-update it to the current timestamp;
1726 // however, things have changed since MySQL 4.1, so
1727 // it's better to set a fields_prev in this situation
1728 $backup_field = '<input type="hidden" name="fields_prev'
1729 . $column_name_appendix . '" value="'
1730 . htmlspecialchars($current_row[$column['Field']]) . '" />';
1732 return array(
1733 $real_null_value,
1734 $special_chars_encoded,
1735 $special_chars,
1736 $data,
1737 $backup_field
1742 * display default values
1744 * @param array $column description of column in given table
1745 * @param boolean $real_null_value whether column value null or not null
1747 * @return array $real_null_value, $data, $special_chars,
1748 * $backup_field, $special_chars_encoded
1750 function PMA_getSpecialCharsAndBackupFieldForInsertingMode(
1751 $column, $real_null_value
1753 if (! isset($column['Default'])) {
1754 $column['Default'] = '';
1755 $real_null_value = true;
1756 $data = '';
1757 } else {
1758 $data = $column['Default'];
1761 if ($column['True_Type'] == 'bit') {
1762 $special_chars = PMA_Util::convertBitDefaultValue($column['Default']);
1763 } elseif (substr($column['True_Type'], 0, 9) == 'timestamp'
1764 || $column['True_Type'] == 'datetime'
1765 || $column['True_Type'] == 'time'
1767 $special_chars = PMA_Util::addMicroseconds($column['Default']);
1768 } else {
1769 $special_chars = htmlspecialchars($column['Default']);
1771 $backup_field = '';
1772 $special_chars_encoded = PMA_Util::duplicateFirstNewline($special_chars);
1773 // this will select the UNHEX function while inserting
1774 if (($column['is_binary']
1775 || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary']))
1776 && (isset($_SESSION['tmpval']['display_binary_as_hex'])
1777 && $_SESSION['tmpval']['display_binary_as_hex'])
1778 && $GLOBALS['cfg']['ShowFunctionFields']
1780 $column['display_binary_as_hex'] = true;
1782 return array(
1783 $real_null_value, $data, $special_chars,
1784 $backup_field, $special_chars_encoded
1789 * Prepares the update/insert of a row
1791 * @return array $loop_array, $using_key, $is_insert, $is_insertignore
1793 function PMA_getParamsForUpdateOrInsert()
1795 if (isset($_REQUEST['where_clause'])) {
1796 // we were editing something => use the WHERE clause
1797 $loop_array = is_array($_REQUEST['where_clause'])
1798 ? $_REQUEST['where_clause']
1799 : array($_REQUEST['where_clause']);
1800 $using_key = true;
1801 $is_insert = $_REQUEST['submit_type'] == 'insert'
1802 || $_REQUEST['submit_type'] == 'showinsert'
1803 || $_REQUEST['submit_type'] == 'insertignore';
1804 } else {
1805 // new row => use indexes
1806 $loop_array = array();
1807 foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) {
1808 $loop_array[] = $key;
1810 $using_key = false;
1811 $is_insert = true;
1813 $is_insertignore = $_REQUEST['submit_type'] == 'insertignore';
1814 return array($loop_array, $using_key, $is_insert, $is_insertignore);
1818 * Check wether insert row mode and if so include tbl_changen script and set
1819 * global variables.
1821 * @return void
1823 function PMA_isInsertRow()
1825 if (isset($_REQUEST['insert_rows'])
1826 && is_numeric($_REQUEST['insert_rows'])
1827 && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows']
1829 $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows'];
1830 $response = PMA_Response::getInstance();
1831 $header = $response->getHeader();
1832 $scripts = $header->getScripts();
1833 $scripts->addFile('tbl_change.js');
1834 if (!defined('TESTSUITE')) {
1835 include 'tbl_change.php';
1836 exit;
1842 * set $_SESSION for edit_next
1844 * @param string $one_where_clause one where clause from where clauses array
1846 * @return void
1848 function PMA_setSessionForEditNext($one_where_clause)
1850 $local_query = 'SELECT * FROM ' . PMA_Util::backquote($GLOBALS['db'])
1851 . '.' . PMA_Util::backquote($GLOBALS['table']) . ' WHERE '
1852 . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;';
1854 $res = $GLOBALS['dbi']->query($local_query);
1855 $row = $GLOBALS['dbi']->fetchRow($res);
1856 $meta = $GLOBALS['dbi']->getFieldsMeta($res);
1857 // must find a unique condition based on unique key,
1858 // not a combination of all fields
1859 list($unique_condition, $clause_is_unique)
1860 = PMA_Util::getUniqueCondition(
1861 $res, count($meta), $meta, $row, true
1863 if (! empty($unique_condition)) {
1864 $_SESSION['edit_next'] = $unique_condition;
1866 unset($unique_condition, $clause_is_unique);
1870 * set $goto_include variable for different cases and retrieve like,
1871 * if $GLOBALS['goto'] empty, if $goto_include previously not defined
1872 * and new_insert, same_insert, edit_next
1874 * @param string $goto_include store some script for include, otherwise it is
1875 * boolean false
1877 * @return string $goto_include
1879 function PMA_getGotoInclude($goto_include)
1881 $valid_options = array('new_insert', 'same_insert', 'edit_next');
1882 if (isset($_REQUEST['after_insert'])
1883 && in_array($_REQUEST['after_insert'], $valid_options)
1885 $goto_include = 'tbl_change.php';
1886 } elseif (! empty($GLOBALS['goto'])) {
1887 if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) {
1888 // this should NOT happen
1889 //$GLOBALS['goto'] = false;
1890 $goto_include = false;
1891 } else {
1892 $goto_include = $GLOBALS['goto'];
1894 if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) {
1895 $GLOBALS['table'] = '';
1898 if (! $goto_include) {
1899 if (! strlen($GLOBALS['table'])) {
1900 $goto_include = 'db_sql.php';
1901 } else {
1902 $goto_include = 'tbl_sql.php';
1905 return $goto_include;
1909 * Defines the url to return in case of failure of the query
1911 * @param array $url_params url parameters
1913 * @return string error url for query failure
1915 function PMA_getErrorUrl($url_params)
1917 if (isset($_REQUEST['err_url'])) {
1918 return $_REQUEST['err_url'];
1919 } else {
1920 return 'tbl_change.php' . PMA_URL_getCommon($url_params);
1925 * Builds the sql query
1927 * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore'
1928 * @param array $query_fields column names array
1929 * @param array $value_sets array of query values
1931 * @return string a query
1933 function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets)
1935 if ($is_insertignore) {
1936 $insert_command = 'INSERT IGNORE ';
1937 } else {
1938 $insert_command = 'INSERT ';
1940 $query = array(
1941 $insert_command . 'INTO '
1942 . PMA_Util::backquote($GLOBALS['db']) . '.'
1943 . PMA_Util::backquote($GLOBALS['table'])
1944 . ' (' . implode(', ', $query_fields) . ') VALUES ('
1945 . implode('), (', $value_sets) . ')'
1947 unset($insert_command, $query_fields);
1948 return $query;
1952 * Executes the sql query and get the result, then move back to the calling page
1954 * @param array $url_params url parameters array
1955 * @param array $query built query from PMA_buildSqlQuery()
1957 * @return array $url_params, $total_affected_rows, $last_messages
1958 * $warning_messages, $error_messages, $return_to_sql_query
1960 function PMA_executeSqlQuery($url_params, $query)
1962 $return_to_sql_query = '';
1963 if (! empty($GLOBALS['sql_query'])) {
1964 $url_params['sql_query'] = $GLOBALS['sql_query'];
1965 $return_to_sql_query = $GLOBALS['sql_query'];
1967 $GLOBALS['sql_query'] = implode('; ', $query) . ';';
1968 // to ensure that the query is displayed in case of
1969 // "insert as new row" and then "insert another new row"
1970 $GLOBALS['display_query'] = $GLOBALS['sql_query'];
1972 $total_affected_rows = 0;
1973 $last_messages = array();
1974 $warning_messages = array();
1975 $error_messages = array();
1977 foreach ($query as $single_query) {
1978 if ($_REQUEST['submit_type'] == 'showinsert') {
1979 $last_messages[] = PMA_Message::notice(__('Showing SQL query'));
1980 continue;
1982 if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
1983 $result = $GLOBALS['dbi']->tryQuery($single_query);
1984 } else {
1985 $result = $GLOBALS['dbi']->query($single_query);
1987 if (! $result) {
1988 $error_messages[] = PMA_Message::sanitize($GLOBALS['dbi']->getError());
1989 } else {
1990 // The next line contains a real assignment, it's not a typo
1991 if ($tmp = @$GLOBALS['dbi']->affectedRows()) {
1992 $total_affected_rows += $tmp;
1994 unset($tmp);
1996 $insert_id = $GLOBALS['dbi']->insertId();
1997 if ($insert_id != 0) {
1998 // insert_id is id of FIRST record inserted in one insert, so if we
1999 // inserted multiple rows, we had to increment this
2001 if ($total_affected_rows > 0) {
2002 $insert_id = $insert_id + $total_affected_rows - 1;
2004 $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
2005 $last_message->addParam($insert_id);
2006 $last_messages[] = $last_message;
2008 $GLOBALS['dbi']->freeResult($result);
2010 $warning_messages = PMA_getWarningMessages();
2012 return array(
2013 $url_params,
2014 $total_affected_rows,
2015 $last_messages,
2016 $warning_messages,
2017 $error_messages,
2018 $return_to_sql_query
2023 * get the warning messages array
2025 * @return array $warning_essages
2027 function PMA_getWarningMessages()
2029 $warning_essages = array();
2030 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
2031 $warning_essages[] = PMA_Message::sanitize(
2032 $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message']
2035 return $warning_essages;
2039 * Column to display from the foreign table?
2041 * @param string $where_comparison string that contain relation field value
2042 * @param string $relation_field_value relation field value
2043 * @param array $map all Relations to foreign tables for a given
2044 * table or optionally a given column in a table
2045 * @param string $relation_field relation field
2047 * @return string $dispval display value from the foreign table
2049 function PMA_getDisplayValueForForeignTableColumn($where_comparison,
2050 $relation_field_value, $map, $relation_field
2052 $display_field = PMA_getDisplayField(
2053 $map[$relation_field]['foreign_db'],
2054 $map[$relation_field]['foreign_table']
2056 // Field to display from the foreign table?
2057 if (isset($display_field) && strlen($display_field)) {
2058 $dispsql = 'SELECT ' . PMA_Util::backquote($display_field)
2059 . ' FROM ' . PMA_Util::backquote($map[$relation_field]['foreign_db'])
2060 . '.' . PMA_Util::backquote($map[$relation_field]['foreign_table'])
2061 . ' WHERE ' . PMA_Util::backquote($map[$relation_field]['foreign_field'])
2062 . $where_comparison;
2063 $dispresult = $GLOBALS['dbi']->tryQuery(
2064 $dispsql, null, PMA_DatabaseInterface::QUERY_STORE
2066 if ($dispresult && $GLOBALS['dbi']->numRows($dispresult) > 0) {
2067 list($dispval) = $GLOBALS['dbi']->fetchRow($dispresult, 0);
2069 @$GLOBALS['dbi']->freeResult($dispresult);
2070 return $dispval;
2072 return '';
2076 * Display option in the cell according to user choises
2078 * @param array $map all Relations to foreign tables for a given
2079 * table or optionally a given column in a table
2080 * @param string $relation_field relation field
2081 * @param string $where_comparison string that contain relation field value
2082 * @param string $dispval display value from the foreign table
2083 * @param string $relation_field_value relation field value
2085 * @return string $output HTML <a> tag
2087 function PMA_getLinkForRelationalDisplayField($map, $relation_field,
2088 $where_comparison, $dispval, $relation_field_value
2090 if ('K' == $_SESSION['tmpval']['relational_display']) {
2091 // user chose "relational key" in the display options, so
2092 // the title contains the display field
2093 $title = (! empty($dispval))
2094 ? ' title="' . htmlspecialchars($dispval) . '"'
2095 : '';
2096 } else {
2097 $title = ' title="' . htmlspecialchars($relation_field_value) . '"';
2099 $_url_params = array(
2100 'db' => $map[$relation_field]['foreign_db'],
2101 'table' => $map[$relation_field]['foreign_table'],
2102 'pos' => '0',
2103 'sql_query' => 'SELECT * FROM '
2104 . PMA_Util::backquote($map[$relation_field]['foreign_db'])
2105 . '.' . PMA_Util::backquote($map[$relation_field]['foreign_table'])
2106 . ' WHERE ' . PMA_Util::backquote($map[$relation_field]['foreign_field'])
2107 . $where_comparison
2109 $output = '<a href="sql.php'
2110 . PMA_URL_getCommon($_url_params) . '"' . $title . '>';
2112 if ('D' == $_SESSION['tmpval']['relational_display']) {
2113 // user chose "relational display field" in the
2114 // display options, so show display field in the cell
2115 $output .= (!empty($dispval)) ? htmlspecialchars($dispval) : '';
2116 } else {
2117 // otherwise display data in the cell
2118 $output .= htmlspecialchars($relation_field_value);
2120 $output .= '</a>';
2121 return $output;
2125 * Transform edited values
2127 * @param string $db db name
2128 * @param string $table table name
2129 * @param array $transformation mimetypes for all columns of a table
2130 * [field_name][field_key]
2131 * @param array $edited_values transform columns list and new values
2132 * @param string $file file containing the transformation plugin
2133 * @param string $column_name column name
2134 * @param array $extra_data extra data array
2136 * @return array $extra_data
2138 function PMA_transformEditedValues($db, $table,
2139 $transformation, $edited_values, $file, $column_name, $extra_data
2141 foreach ($edited_values as $cell_index => $curr_cell_edited_values) {
2142 if (isset($curr_cell_edited_values[$column_name])) {
2143 $column_data = $curr_cell_edited_values[$column_name];
2145 $_url_params = array(
2146 'db' => $db,
2147 'table' => $table,
2148 'where_clause' => $_REQUEST['where_clause'],
2149 'transform_key' => $column_name
2152 $include_file = 'libraries/plugins/transformations/' . $file;
2153 if (file_exists($include_file)) {
2154 include_once $include_file;
2156 $transform_options = PMA_Transformation_getOptions(
2157 isset($transformation['transformation_options'])
2158 ? $transformation['transformation_options']
2159 : ''
2161 $transform_options['wrapper_link']
2162 = PMA_URL_getCommon($_url_params);
2163 $class_name = str_replace('.class.php', '', $file);
2164 $plugin_manager = null;
2165 $transformation_plugin = new $class_name(
2166 $plugin_manager
2170 $extra_data['transformations'][$cell_index]
2171 = $transformation_plugin->applyTransformation(
2172 $column_data,
2173 $transform_options,
2177 } // end of loop for each transformation cell
2178 return $extra_data;
2182 * Get current value in multi edit mode
2184 * @param array $multi_edit_colummns multiple edit column array
2185 * @param array $multi_edit_columns_name multiple edit columns name array
2186 * @param array $multi_edit_funcs multiple edit functions array
2187 * @param array $multi_edit_salt multiple edit array with encryption salt
2188 * @param array $gis_from_text_functions array that contains gis from text functions
2189 * @param string $current_value current value in the column
2190 * @param array $gis_from_wkb_functions initialy $val is $multi_edit_colummns[$key]
2191 * @param array $func_optional_param array('RAND','UNIX_TIMESTAMP')
2192 * @param array $func_no_param array of set of string
2193 * @param string $key an md5 of the column name
2195 * @return array $cur_value
2197 function PMA_getCurrentValueAsAnArrayForMultipleEdit($multi_edit_colummns,
2198 $multi_edit_columns_name, $multi_edit_funcs, $multi_edit_salt,
2199 $gis_from_text_functions, $current_value, $gis_from_wkb_functions,
2200 $func_optional_param, $func_no_param, $key
2202 if (empty($multi_edit_funcs[$key])) {
2203 return $current_value;
2204 } elseif ('UUID' === $multi_edit_funcs[$key]) {
2205 /* This way user will know what UUID new row has */
2206 $uuid = $GLOBALS['dbi']->fetchValue('SELECT UUID()');
2207 return "'" . $uuid . "'";
2208 } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions)
2209 && substr($current_value, 0, 3) == "'''")
2210 || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions)
2212 // Remove enclosing apostrophes
2213 $current_value = substr($current_value, 1, strlen($current_value) - 2);
2214 // Remove escaping apostrophes
2215 $current_value = str_replace("''", "'", $current_value);
2216 return $multi_edit_funcs[$key] . '(' . $current_value . ')';
2217 } elseif (! in_array($multi_edit_funcs[$key], $func_no_param)
2218 || ($current_value != "''"
2219 && in_array($multi_edit_funcs[$key], $func_optional_param))
2221 if (isset($multi_edit_salt[$key])
2222 && ($multi_edit_funcs[$key] == "AES_ENCRYPT" || $multi_edit_funcs[$key] == "AES_DECRYPT")
2224 return $multi_edit_funcs[$key] . '(' . $current_value . ",'"
2225 . PMA_Util::sqlAddSlashes($multi_edit_salt[$key]) . "')";
2226 } else {
2227 return $multi_edit_funcs[$key] . '(' . $current_value . ')';
2229 } else {
2230 return $multi_edit_funcs[$key] . '()';
2235 * Get query values array and query fields array for insert and update in multi edit
2237 * @param array $multi_edit_columns_name multiple edit columns name array
2238 * @param array $multi_edit_columns_null multiple edit columns null array
2239 * @param string $current_value current value in the column in loop
2240 * @param array $multi_edit_columns_prev multiple edit previous columns array
2241 * @param array $multi_edit_funcs multiple edit functions array
2242 * @param boolean $is_insert boolean value whether insert or not
2243 * @param array $query_values SET part of the sql query
2244 * @param array $query_fields array of query fields
2245 * @param string $current_value_as_an_array current value in the column
2246 * as an array
2247 * @param array $value_sets array of valu sets
2248 * @param string $key an md5 of the column name
2249 * @param array $multi_edit_columns_null_prev array of multiple edit columns
2250 * null previous
2252 * @return array ($query_values, $query_fields)
2254 function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_name,
2255 $multi_edit_columns_null, $current_value, $multi_edit_columns_prev,
2256 $multi_edit_funcs,$is_insert, $query_values, $query_fields,
2257 $current_value_as_an_array, $value_sets, $key, $multi_edit_columns_null_prev
2259 // i n s e r t
2260 if ($is_insert) {
2261 // no need to add column into the valuelist
2262 if (strlen($current_value_as_an_array)) {
2263 $query_values[] = $current_value_as_an_array;
2264 // first inserted row so prepare the list of fields
2265 if (empty($value_sets)) {
2266 $query_fields[] = PMA_Util::backquote(
2267 $multi_edit_columns_name[$key]
2272 } elseif (! empty($multi_edit_columns_null_prev[$key])
2273 && ! isset($multi_edit_columns_null[$key])
2275 // u p d a t e
2277 // field had the null checkbox before the update
2278 // field no longer has the null checkbox
2279 $query_values[]
2280 = PMA_Util::backquote($multi_edit_columns_name[$key])
2281 . ' = ' . $current_value_as_an_array;
2282 } elseif (empty($multi_edit_funcs[$key])
2283 && isset($multi_edit_columns_prev[$key])
2284 && ("'" . PMA_Util::sqlAddSlashes($multi_edit_columns_prev[$key]) . "'"
2285 == $current_value)
2287 // No change for this column and no MySQL function is used -> next column
2288 } elseif (! empty($current_value)) {
2289 // avoid setting a field to NULL when it's already NULL
2290 // (field had the null checkbox before the update
2291 // field still has the null checkbox)
2292 if (empty($multi_edit_columns_null_prev[$key])
2293 || empty($multi_edit_columns_null[$key])
2295 $query_values[]
2296 = PMA_Util::backquote($multi_edit_columns_name[$key])
2297 . ' = ' . $current_value_as_an_array;
2300 return array($query_values, $query_fields);
2304 * Get the current column value in the form for different data types
2306 * @param string $possibly_uploaded_val uploaded file content
2307 * @param string $key an md5 of the column name
2308 * @param array $multi_edit_columns_type array of multi edit column types
2309 * @param string $current_value current column value in the form
2310 * @param array $multi_edit_auto_increment multi edit auto increment
2311 * @param string $rownumber index of where clause array
2312 * @param array $multi_edit_columns_name multi edit column names array
2313 * @param array $multi_edit_columns_null multi edit columns null array
2314 * @param array $multi_edit_columns_null_prev multi edit columns previous null
2315 * @param boolean $is_insert whether insert or not
2316 * @param boolean $using_key whether editing or new row
2317 * @param array $where_clause where clauses
2318 * @param string $table table name
2320 * @return string $current_value current column value in the form
2322 function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key,
2323 $multi_edit_columns_type, $current_value, $multi_edit_auto_increment,
2324 $rownumber, $multi_edit_columns_name, $multi_edit_columns_null,
2325 $multi_edit_columns_null_prev, $is_insert, $using_key, $where_clause, $table
2327 // Fetch the current values of a row to use in case we have a protected field
2328 if ($is_insert
2329 && $using_key && isset($multi_edit_columns_type)
2330 && is_array($multi_edit_columns_type) && isset($where_clause)
2332 $protected_row = $GLOBALS['dbi']->fetchSingleRow(
2333 'SELECT * FROM ' . PMA_Util::backquote($table)
2334 . ' WHERE ' . $where_clause . ';'
2338 if (false !== $possibly_uploaded_val) {
2339 $current_value = $possibly_uploaded_val;
2340 } else {
2341 // c o l u m n v a l u e i n t h e f o r m
2342 if (isset($multi_edit_columns_type[$key])) {
2343 $type = $multi_edit_columns_type[$key];
2344 } else {
2345 $type = '';
2348 if ($type != 'protected' && $type != 'set' && 0 === strlen($current_value)) {
2349 // best way to avoid problems in strict mode
2350 // (works also in non-strict mode)
2351 if (isset($multi_edit_auto_increment)
2352 && isset($multi_edit_auto_increment[$key])
2354 $current_value = 'NULL';
2355 } else {
2356 $current_value = "''";
2358 } elseif ($type == 'set') {
2359 if (! empty($_REQUEST['fields']['multi_edit'][$rownumber][$key])) {
2360 $current_value = implode(
2361 ',', $_REQUEST['fields']['multi_edit'][$rownumber][$key]
2363 $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2364 } else {
2365 $current_value = "''";
2367 } elseif ($type == 'protected') {
2368 // here we are in protected mode (asked in the config)
2369 // so tbl_change has put this special value in the
2370 // columns array, so we do not change the column value
2371 // but we can still handle column upload
2373 // when in UPDATE mode, do not alter field's contents. When in INSERT
2374 // mode, insert empty field because no values were submitted.
2375 // If protected blobs where set, insert original fields content.
2376 if (! empty($protected_row[$multi_edit_columns_name[$key]])) {
2377 $current_value = '0x'
2378 . bin2hex($protected_row[$multi_edit_columns_name[$key]]);
2379 } else {
2380 $current_value = '';
2382 } elseif ($type == 'bit') {
2383 $current_value = preg_replace('/[^01]/', '0', $current_value);
2384 $current_value = "b'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2385 } elseif (! ($type == 'datetime' || $type == 'timestamp')
2386 || $current_value != 'CURRENT_TIMESTAMP'
2388 $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
2391 // Was the Null checkbox checked for this field?
2392 // (if there is a value, we ignore the Null checkbox: this could
2393 // be possible if Javascript is disabled in the browser)
2394 if (! empty($multi_edit_columns_null[$key])
2395 && ($current_value == "''" || $current_value == '')
2397 $current_value = 'NULL';
2400 // The Null checkbox was unchecked for this field
2401 if (empty($current_value)
2402 && ! empty($multi_edit_columns_null_prev[$key])
2403 && ! isset($multi_edit_columns_null[$key])
2405 $current_value = "''";
2407 } // end else (column value in the form)
2408 return $current_value;
2413 * Check whether inline edited value can be truncated or not,
2414 * and add additional parameters for extra_data array if needed
2416 * @param string $db Database name
2417 * @param string $table Table name
2418 * @param string $column_name Column name
2419 * @param array &$extra_data Extra data for ajax response
2421 * @return void
2423 function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData(
2424 $db, $table, $column_name, &$extra_data
2427 $extra_data['isNeedToRecheck'] = true;
2429 $sql_for_real_value = 'SELECT ' . PMA_Util::backquote($table) . '.'
2430 . PMA_Util::backquote($column_name)
2431 . ' FROM ' . PMA_Util::backquote($db) . '.'
2432 . PMA_Util::backquote($table)
2433 . ' WHERE ' . $_REQUEST['where_clause'][0];
2435 $result = $GLOBALS['dbi']->tryQuery($sql_for_real_value);
2436 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
2437 $meta = $fields_meta[0];
2438 $new_value = $GLOBALS['dbi']->fetchValue($result);
2439 if ($new_value !== false) {
2440 if ((substr($meta->type, 0, 9) == 'timestamp')
2441 || ($meta->type == 'datetime')
2442 || ($meta->type == 'time')
2444 $new_value = PMA_Util::addMicroseconds($new_value);
2446 $extra_data['truncatableFieldValue'] = $new_value;
2447 } else {
2448 $extra_data['isNeedToRecheck'] = false;
2454 * Function to get the columns of a table
2456 * @param string $db current db
2457 * @param string $table current table
2459 * @return array
2461 function PMA_getTableColumns($db, $table)
2463 $GLOBALS['dbi']->selectDb($db);
2464 return array_values($GLOBALS['dbi']->getColumns($db, $table));
2469 * Function to determine Insert/Edit rows
2471 * @param string $where_clause where clause
2472 * @param string $db current database
2473 * @param string $table current table
2475 * @return mixed
2477 function PMA_determineInsertOrEdit($where_clause, $db, $table)
2479 if (isset($_REQUEST['where_clause'])) {
2480 $where_clause = $_REQUEST['where_clause'];
2482 if (isset($_SESSION['edit_next'])) {
2483 $where_clause = $_SESSION['edit_next'];
2484 unset($_SESSION['edit_next']);
2485 $after_insert = 'edit_next';
2487 if (isset($_REQUEST['ShowFunctionFields'])) {
2488 $GLOBALS['cfg']['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
2490 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
2491 $GLOBALS['cfg']['ShowFieldTypesInDataEditView']
2492 = $_REQUEST['ShowFieldTypesInDataEditView'];
2494 if (isset($_REQUEST['after_insert'])) {
2495 $after_insert = $_REQUEST['after_insert'];
2498 if (isset($where_clause)) {
2499 // we are editing
2500 $insert_mode = false;
2501 $where_clause_array = PMA_getWhereClauseArray($where_clause);
2502 list($where_clauses, $result, $rows, $found_unique_key)
2503 = PMA_analyzeWhereClauses(
2504 $where_clause_array, $table, $db
2506 } else {
2507 // we are inserting
2508 $insert_mode = true;
2509 $where_clause = null;
2510 list($result, $rows) = PMA_loadFirstRow($table, $db);
2511 $where_clauses = null;
2512 $where_clause_array = null;
2513 $found_unique_key = false;
2516 // Copying a row - fetched data will be inserted as a new row,
2517 // therefore the where clause is needless.
2518 if (isset($_REQUEST['default_action'])
2519 && $_REQUEST['default_action'] === 'insert'
2521 $where_clause = $where_clauses = null;
2524 return array(
2525 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
2526 $result, $rows, $found_unique_key,
2527 isset($after_insert) ? $after_insert : null
2532 * Function to get comments for the table columns
2534 * @param string $db current database
2535 * @param string $table current table
2537 * @return array $comments_map comments for columns
2539 function PMA_getCommentsMap($db, $table)
2542 * get table information
2543 * @todo should be done by a Table object
2545 include 'libraries/tbl_info.inc.php';
2548 * Get comments for table fields/columns
2550 $comments_map = array();
2552 if ($GLOBALS['cfg']['ShowPropertyComments']) {
2553 $comments_map = PMA_getComments($db, $table);
2556 return $comments_map;
2560 * Function to get URL parameters
2562 * @param string $db current database
2563 * @param string $table current table
2565 * @return array $url_params url parameters
2567 function PMA_getUrlParameters($db, $table)
2570 * @todo check if we could replace by "db_|tbl_" - please clarify!?
2572 $url_params = array(
2573 'db' => $db,
2574 'sql_query' => $_REQUEST['sql_query']
2577 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
2578 $url_params['table'] = $table;
2581 return $url_params;
2585 * Function to get html for the gis editor div
2587 * @return string
2589 function PMA_getHtmlForGisEditor()
2591 return '<div id="gis_editor"></div>'
2592 . '<div id="popup_background"></div>'
2593 . '<br />';
2597 * Function to get html for the ignore option in insert mode
2599 * @param int $row_id row id
2601 * @return string
2603 function PMA_getHtmlForIgnoreOption($row_id)
2605 return '<input type="checkbox" checked="checked"'
2606 . ' name="insert_ignore_' . $row_id . '"'
2607 . ' id="insert_ignore_' . $row_id . '" />'
2608 . '<label for="insert_ignore_' . $row_id . '">'
2609 . __('Ignore')
2610 . '</label><br />' . "\n";
2614 * Function to get html for the function option
2616 * @param bool $odd_row whether odd row or not
2617 * @param array $column column
2618 * @param string $column_name_appendix column name appendix
2620 * @return String
2622 function PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix)
2624 $longDoubleTextArea = $GLOBALS['cfg']['LongtextDoubleTextarea'];
2625 return '<tr class="noclick ' . ($odd_row ? 'odd' : 'even' ) . '">'
2626 . '<td '
2627 . ($longDoubleTextArea && strstr($column['True_Type'], 'longtext')
2628 ? 'rowspan="2"'
2629 : ''
2631 . 'class="center">'
2632 . $column['Field_title']
2633 . '<input type="hidden" name="fields_name' . $column_name_appendix
2634 . '" value="' . $column['Field_html'] . '"/>'
2635 . '</td>';
2640 * Function to get html for the column type
2642 * @param array $column column
2644 * @return string
2646 function PMA_getHtmlForInsertEditColumnType($column)
2648 return '<td class="center' . $column['wrap'] . '">'
2649 . '<span class="column_type">' . $column['pma_type'] . '</span>'
2650 . '</td>';
2655 * Function to get html for the insert edit form header
2657 * @param bool $has_blob_field whether has blob field
2658 * @param bool $is_upload whether is upload
2660 * @return string
2662 function PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload)
2664 $html_output ='<form id="insertForm" ';
2665 if ($has_blob_field && $is_upload) {
2666 $html_output .='class="disableAjax" ';
2668 $html_output .='method="post" action="tbl_replace.php" name="insertForm" ';
2669 if ($is_upload) {
2670 $html_output .= ' enctype="multipart/form-data"';
2672 $html_output .= '>';
2674 return $html_output;
2678 * Function to get html for each insert/edit column
2680 * @param array $table_columns table columns
2681 * @param int $i row counter
2682 * @param array $column column
2683 * @param array $comments_map comments map
2684 * @param bool $timestamp_seen whether timestamp seen
2685 * @param array $current_result current result
2686 * @param string $chg_evt_handler javascript change event handler
2687 * @param string $jsvkey javascript validation key
2688 * @param string $vkey validation key
2689 * @param bool $insert_mode whether insert mode
2690 * @param array $current_row current row
2691 * @param bool $odd_row whether odd row
2692 * @param int &$o_rows row offset
2693 * @param int &$tabindex tab index
2694 * @param int $columns_cnt columns count
2695 * @param bool $is_upload whether upload
2696 * @param int $tabindex_for_function tab index offset for function
2697 * @param array $foreigners foreigners
2698 * @param int $tabindex_for_null tab index offset for null
2699 * @param int $tabindex_for_value tab index offset for value
2700 * @param string $table table
2701 * @param string $db database
2702 * @param int $row_id row id
2703 * @param array $titles titles
2704 * @param int $biggest_max_file_size biggest max file size
2705 * @param string $default_char_editing default char editing mode which is stroe
2706 * in the config.inc.php script
2707 * @param string $text_dir text direction
2709 * @return string
2711 function PMA_getHtmlForInsertEditFormColumn($table_columns, $i, $column,
2712 $comments_map, $timestamp_seen, $current_result, $chg_evt_handler,
2713 $jsvkey, $vkey, $insert_mode, $current_row, $odd_row, &$o_rows,
2714 &$tabindex, $columns_cnt, $is_upload, $tabindex_for_function,
2715 $foreigners, $tabindex_for_null, $tabindex_for_value,
2716 $table, $db, $row_id, $titles, $biggest_max_file_size,
2717 $default_char_editing, $text_dir
2719 if (! isset($table_columns[$i]['processed'])) {
2720 $column = $table_columns[$i];
2721 $column = PMA_analyzeTableColumnsArray(
2722 $column, $comments_map, $timestamp_seen
2726 $extracted_columnspec
2727 = PMA_Util::extractColumnSpec($column['Type']);
2729 if (-1 === $column['len']) {
2730 $column['len'] = $GLOBALS['dbi']->fieldLen($current_result, $i);
2731 // length is unknown for geometry fields,
2732 // make enough space to edit very simple WKTs
2733 if (-1 === $column['len']) {
2734 $column['len'] = 30;
2737 //Call validation when the form submitted...
2738 $unnullify_trigger = $chg_evt_handler
2739 . "=\"return verificationsAfterFieldChange('"
2740 . PMA_escapeJsString($column['Field_md5']) . "', '"
2741 . PMA_escapeJsString($jsvkey) . "','" . $column['pma_type'] . "')\"";
2743 // Use an MD5 as an array index to avoid having special characters
2744 // in the name atttibute (see bug #1746964 )
2745 $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']';
2747 if ($column['Type'] == 'datetime'
2748 && ! isset($column['Default'])
2749 && ! is_null($column['Default'])
2750 && ($insert_mode || ! isset($current_row[$column['Field']]))
2752 // INSERT case or
2753 // UPDATE case with an NULL value
2754 $current_row[$column['Field']] = date('Y-m-d H:i:s', time());
2757 $html_output = PMA_getHtmlForFunctionOption(
2758 $odd_row, $column, $column_name_appendix
2761 if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
2762 $html_output .= PMA_getHtmlForInsertEditColumnType($column);
2763 } //End if
2765 // Get a list of GIS data types.
2766 $gis_data_types = PMA_Util::getGISDatatypes();
2768 // Prepares the field value
2769 $real_null_value = false;
2770 $special_chars_encoded = '';
2771 if (isset($current_row)) {
2772 // (we are editing)
2773 list(
2774 $real_null_value, $special_chars_encoded, $special_chars,
2775 $data, $backup_field
2777 = PMA_getSpecialCharsAndBackupFieldForExistingRow(
2778 $current_row, $column, $extracted_columnspec,
2779 $real_null_value, $gis_data_types, $column_name_appendix
2781 } else {
2782 // (we are inserting)
2783 // display default values
2784 list($real_null_value, $data, $special_chars, $backup_field,
2785 $special_chars_encoded
2787 = PMA_getSpecialCharsAndBackupFieldForInsertingMode(
2788 $column, $real_null_value
2792 $idindex = ($o_rows * $columns_cnt) + $i + 1;
2793 $tabindex = $idindex;
2795 // Get a list of data types that are not yet supported.
2796 $no_support_types = PMA_Util::unsupportedDatatypes();
2798 // The function column
2799 // -------------------
2800 if ($GLOBALS['cfg']['ShowFunctionFields']) {
2801 $html_output .= PMA_getFunctionColumn(
2802 $column, $is_upload, $column_name_appendix,
2803 $unnullify_trigger, $no_support_types, $tabindex_for_function,
2804 $tabindex, $idindex, $insert_mode
2808 // The null column
2809 // ---------------
2810 $foreignData = PMA_getForeignData(
2811 $foreigners, $column['Field'], false, '', ''
2813 $html_output .= PMA_getNullColumn(
2814 $column, $column_name_appendix, $real_null_value,
2815 $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners,
2816 $foreignData
2819 // The value column (depends on type)
2820 // ----------------
2821 // See bug #1667887 for the reason why we don't use the maxlength
2822 // HTML attribute
2824 //add data attributes "no of decimals" and "data type"
2825 $no_decimals=0;
2826 $type = current(explode("(", $column['pma_type']));
2827 if (preg_match('/\(([^()]+)\)/', $column['pma_type'], $match)) {
2828 $match[0] = trim($match[0], '()');
2829 $no_decimals=$match[0];
2831 $html_output .= '<td' . ' data-type="' . $type . '"' . ' data-decimals="'
2832 . $no_decimals . '">' . "\n";
2833 // Will be used by js/tbl_change.js to set the default value
2834 // for the "Continue insertion" feature
2835 $html_output .= '<span class="default_value hide">'
2836 . $special_chars . '</span>';
2838 $html_output .= PMA_getValueColumn(
2839 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
2840 $tabindex, $tabindex_for_value, $idindex, $data, $special_chars,
2841 $foreignData, $odd_row, array($table, $db), $row_id, $titles,
2842 $text_dir, $special_chars_encoded, $vkey, $is_upload,
2843 $biggest_max_file_size, $default_char_editing,
2844 $no_support_types, $gis_data_types, $extracted_columnspec
2847 $html_output .= '</td>'
2848 . '</tr>';
2850 return $html_output;
2854 * Function to get html for each insert/edit row
2856 * @param array $url_params url parameters
2857 * @param array $table_columns table columns
2858 * @param array $column column
2859 * @param array $comments_map comments map
2860 * @param bool $timestamp_seen whether timestamp seen
2861 * @param array $current_result current result
2862 * @param string $chg_evt_handler javascript change event handler
2863 * @param string $jsvkey javascript validation key
2864 * @param string $vkey validation key
2865 * @param bool $insert_mode whether insert mode
2866 * @param array $current_row current row
2867 * @param int &$o_rows row offset
2868 * @param int &$tabindex tab index
2869 * @param int $columns_cnt columns count
2870 * @param bool $is_upload whether upload
2871 * @param int $tabindex_for_function tab index offset for function
2872 * @param array $foreigners foreigners
2873 * @param int $tabindex_for_null tab index offset for null
2874 * @param int $tabindex_for_value tab index offset for value
2875 * @param string $table table
2876 * @param string $db database
2877 * @param int $row_id row id
2878 * @param array $titles titles
2879 * @param int $biggest_max_file_size biggest max file size
2880 * @param string $text_dir text direction
2882 * @return string
2884 function PMA_getHtmlForInsertEditRow($url_params, $table_columns,
2885 $column, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler,
2886 $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, &$tabindex, $columns_cnt,
2887 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
2888 $tabindex_for_value, $table, $db, $row_id, $titles,
2889 $biggest_max_file_size, $text_dir
2891 $html_output = PMA_getHeadAndFootOfInsertRowTable($url_params)
2892 . '<tbody>';
2894 //store the default value for CharEditing
2895 $default_char_editing = $GLOBALS['cfg']['CharEditing'];
2897 $odd_row = true;
2898 for ($i = 0; $i < $columns_cnt; $i++) {
2899 $html_output .= PMA_getHtmlForInsertEditFormColumn(
2900 $table_columns, $i, $column, $comments_map, $timestamp_seen,
2901 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
2902 $current_row, $odd_row, $o_rows, $tabindex, $columns_cnt, $is_upload,
2903 $tabindex_for_function, $foreigners, $tabindex_for_null,
2904 $tabindex_for_value, $table, $db, $row_id, $titles,
2905 $biggest_max_file_size, $default_char_editing, $text_dir
2907 $odd_row = !$odd_row;
2908 } // end for
2909 $o_rows++;
2910 $html_output .= ' </tbody>'
2911 . '</table><br />'
2912 . '<div class="clearfloat"></div>';
2914 return $html_output;