forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_edit.lib.php
2347 lines (2215 loc) · 87.8 KB
/
insert_edit.lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of functions with the insert/edit features in pma
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Retrieve form parameters for insert/edit form
*
* @param string $db name of the database
* @param string $table name of the table
* @param array $where_clauses where clauses
* @param array $where_clause_array array of where clauses
* @param string $err_url error url
*
* @return array $_form_params array of insert/edit form parameters
*/
function PMA_getFormParametersForInsertForm($db, $table, $where_clauses,
$where_clause_array, $err_url
) {
$_form_params = array(
'db' => $db,
'table' => $table,
'goto' => $GLOBALS['goto'],
'err_url' => $err_url,
'sql_query' => $_REQUEST['sql_query'],
);
if (isset($where_clauses)) {
foreach ($where_clause_array as $key_id => $where_clause) {
$_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
}
}
if (isset($_REQUEST['clause_is_unique'])) {
$_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique'];
}
return $_form_params;
}
/**
* Retrieve the values for pma edit mode
*
* @param type $where_clause where clauses
* @param type $table name of the table
* @param type $db name of the database
*
* @return type containing insert_mode,whereClauses, result array
* where_clauses_array and found_unique_key boolean value
*/
function PMA_getStuffForEditMode($where_clause, $table, $db)
{
if (isset($where_clause)) {
$where_clause_array = PMA_getWhereClauseArray($where_clause);
list($whereClauses, $resultArray, $rowsArray, $found_unique_key)
= PMA_analyzeWhereClauses(
$where_clause_array, $table, $db
);
return array(
false, $whereClauses,
$resultArray, $rowsArray,
$where_clause_array, $found_unique_key
);
} else {
list($results, $row) = PMA_loadFirstRowInEditMode($table, $db);
return array(true, null, $results, $row, null, false);
}
}
/**
* Creates array of where clauses
*
* @param array $where_clause where clause
*
* @return whereClauseArray array of where clauses
*/
function PMA_getWhereClauseArray($where_clause)
{
if (isset ($where_clause)) {
if (is_array($where_clause)) {
return $where_clause;
} else {
return array(0 => $where_clause);
}
}
}
/**
* Analysing where clauses array
*
* @param array $where_clause_array array of where clauses
* @param string $table name of the table
* @param string $db name of the database
*
* @return array $where_clauses, $result, $rows
*/
function PMA_analyzeWhereClauses(
$where_clause_array, $table, $db
) {
$rows = array();
$result = array();
$where_clauses = array();
$found_unique_key = false;
foreach ($where_clause_array as $key_id => $where_clause) {
$local_query = 'SELECT * FROM '
. PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($table)
. ' WHERE ' . $where_clause . ';';
$result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
$rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
$where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
$has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition(
$rows, $key_id, $where_clause_array, $local_query, $result
);
if ($has_unique_condition) {
$found_unique_key = true;
}
}
return array($where_clauses, $result, $rows, $found_unique_key);
}
/**
* Show message for empty reult or set the unique_condition
*
* @param array $rows MySQL returned rows
* @param string $key_id ID in current key
* @param array $where_clause_array array of where clauses
* @param string $local_query query performed
* @param array $result MySQL result handle
*
* @return boolean $has_unique_condition
*/
function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id,
$where_clause_array, $local_query, $result
) {
$has_unique_condition = false;
// No row returned
if (! $rows[$key_id]) {
unset($rows[$key_id], $where_clause_array[$key_id]);
PMA_Response::getInstance()->addHtml(
PMA_Util::getMessage(
__('MySQL returned an empty result set (i.e. zero rows).'),
$local_query
)
);
/**
* @todo not sure what should be done at this point, but we must not
* exit if we want the message to be displayed
*/
} else {// end if (no row returned)
$meta = PMA_DBI_get_fields_meta($result[$key_id]);
list($unique_condition, $tmp_clause_is_unique)
= PMA_Util::getUniqueCondition(
$result[$key_id], count($meta), $meta, $rows[$key_id], true
);
if (! empty($unique_condition)) {
$has_unique_condition = true;
}
unset($unique_condition, $tmp_clause_is_unique);
}
return $has_unique_condition;
}
/**
* No primary key given, just load first row
*
* @param string $table name of the table
* @param string $db name of the database
*
* @return array containing $result and $rows arrays
*/
function PMA_loadFirstRowInEditMode($table, $db)
{
$result = PMA_DBI_query(
'SELECT * FROM ' . PMA_Util::backquote($db)
. '.' . PMA_Util::backquote($table) . ' LIMIT 1;',
null,
PMA_DBI_QUERY_STORE
);
$rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false);
return array($result, $rows);
}
/**
* Add some url parameters
*
* @param array $url_params containing $db and $table as url parameters
*
* @return array Add some url parameters to $url_params array and return it
*/
function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause)
{
if (isset($where_clause)) {
foreach ($where_clause_array as $key_id => $where_clause) {
$url_params['where_clause'] = trim($where_clause);
}
}
if (! empty($_REQUEST['sql_query'])) {
$url_params['sql_query'] = $_REQUEST['sql_query'];
}
return $url_params;
}
/**
* Show function fields in data edit view in pma
*
* @param array $url_params containing url parameters
* @param boolean $showFuncFields whether to show function field
*
* @return string an html snippet
*/
function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields)
{
$params = array();
if (! $showFuncFields) {
$params['ShowFunctionFields'] = 1;
} else {
$params['ShowFunctionFields'] = 0;
}
$params['ShowFieldTypesInDataEditView']
= $GLOBALS['cfg']['ShowFieldTypesInDataEditView'];
$params['goto'] = 'sql.php';
$this_url_params = array_merge($url_params, $params);
if (! $showFuncFields) {
return ' : <a href="tbl_change.php'
. PMA_generate_common_url($this_url_params) . '">'
. __('Function')
. '</a>' . "\n";
}
return '<th><a href="tbl_change.php'
. PMA_generate_common_url($this_url_params)
. '" title="' . __('Hide') . '">'
. __('Function')
. '</a></th>' . "\n";
}
/**
* Show field types in data edit view in pma
*
* @param array $url_params containing url parameters
* @param boolean $showColumnType whether to show column type
*
* @return string an html snippet
*/
function PMA_showColumnTypesInDataEditView($url_params, $showColumnType)
{
$params = array();
if (! $showColumnType) {
$params['ShowFieldTypesInDataEditView'] = 1;
} else {
$params['ShowFieldTypesInDataEditView'] = 0;
}
$params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields'];
$params['goto'] = 'sql.php';
$this_other_url_params = array_merge($url_params, $params);
if (! $showColumnType) {
return ' : <a href="tbl_change.php'
. PMA_generate_common_url($this_other_url_params) . '">'
. __('Type') . '</a>' . "\n";
}
return '<th><a href="tbl_change.php'
. PMA_generate_common_url($this_other_url_params)
. '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
}
/**
* Retrieve the default for datetime data type
*
* @param array $column containing column type, Default and null
*
* @return nothing
*/
function PMA_getDefaultForDatetime($column)
{
// d a t e t i m e
//
// Current date should not be set as default if the field is NULL
// for the current row, but do not put here the current datetime
// if there is a default value (the real default value will be set
// in the Default value logic below)
// Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
// $column['Default'] is not set if it contains NULL:
// Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
// [Extra] => [True_Type] => datetime)
// but, look what we get if we switch to iso: (Default is NULL)
// Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
// [Default] => [Extra] => [True_Type] => datetime)
// so I force a NULL into it (I don't think it's possible
// to have an empty default value for DATETIME)
// then, the "if" after this one will work
if ($column['Type'] == 'datetime'
&& ! isset($column['Default'])
&& isset($column['Null'])
&& $column['Null'] == 'YES'
) {
$column['Default'] = null;
}
}
/**
* Analyze the table column array
*
* @param array $column description of column in given table
* @param array $comments_map comments for every column that has a comment
* @param boolean $timestamp_seen whether a timestamp has been seen
*
* @return array description of column in given table
*/
function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen)
{
$column['Field_html'] = htmlspecialchars($column['Field']);
$column['Field_md5'] = md5($column['Field']);
// True_Type contains only the type (stops at first bracket)
$column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']);
PMA_getDefaultForDatetime($column);
$column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1;
$column['Field_title'] = PMA_getColumnTitle($column, $comments_map);
$column['is_binary'] = PMA_isColumnBinary($column);
$column['is_blob'] = PMA_isColumnBlob($column);
$column['is_char'] = PMA_isColumnChar($column);
list($column['pma_type'], $column['wrap'], $column['first_timestamp'])
= PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen);
return $column;
}
/**
* Retrieve the column title
*
* @param array $column description of column in given table
* @param array $comments_map comments for every column that has a comment
*
* @return string column title
*/
function PMA_getColumnTitle($column, $comments_map)
{
if (isset($comments_map[$column['Field']])) {
return '<span style="border-bottom: 1px dashed black;" title="'
. htmlspecialchars($comments_map[$column['Field']]) . '">'
. $column['Field_html'] . '</span>';
} else {
return $column['Field_html'];
}
}
/**
* check whether the column is a bainary
*
* @param array $column description of column in given table
*
* @return boolean If check to ensure types such as "enum('one','two','binary',..)"
* or "enum('one','two','varbinary',..)" are not categorized as
* binary.
*/
function PMA_isColumnBinary($column)
{
// The type column.
// Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
if (stripos($column['Type'], 'binary') === 0
|| stripos($column['Type'], 'varbinary') === 0
) {
return stristr($column['Type'], 'binary');
} else {
return false;
}
}
/**
* check whether the column is a blob
*
* @param array $column description of column in given table
*
* @return boolean If check to ensure types such as "enum('one','two','blob',..)"
* or "enum('one','two','tinyblob',..)" etc. are not categorized
* as blob.
*/
function PMA_isColumnBlob($column)
{
if (stripos($column['Type'], 'blob') === 0
|| stripos($column['Type'], 'tinyblob') === 0
|| stripos($column['Type'], 'mediumblob') === 0
|| stripos($column['Type'], 'longblob') === 0
) {
return stristr($column['Type'], 'blob');
} else {
return false;
}
}
/**
* check is table column char
*
* @param array $column description of column in given table
*
* @return boolean If check to ensure types such as "enum('one','two','char',..)" or
* "enum('one','two','varchar',..)" are not categorized as char.
*/
function PMA_isColumnChar($column)
{
if (stripos($column['Type'], 'char') === 0
|| stripos($column['Type'], 'varchar') === 0
) {
return stristr($column['Type'], 'char');
} else {
return false;
}
}
/**
* Retrieve set, enum, timestamp table columns
*
* @param array $column description of column in given table
* @param boolean $timestamp_seen whether a timestamp has been seen
*
* @return array $column['pma_type'], $column['wrap'], $column['first_timestamp']
*/
function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen)
{
$column['first_timestamp'] = false;
switch ($column['True_Type']) {
case 'set':
$column['pma_type'] = 'set';
$column['wrap'] = '';
break;
case 'enum':
$column['pma_type'] = 'enum';
$column['wrap'] = '';
break;
case 'timestamp':
if (! $timestamp_seen) { // can only occur once per table
$timestamp_seen = true;
$column['first_timestamp'] = true;
}
$column['pma_type'] = $column['Type'];
$column['wrap'] = ' nowrap';
break;
default:
$column['pma_type'] = $column['Type'];
$column['wrap'] = ' nowrap';
break;
}
return array($column['pma_type'], $column['wrap'], $column['first_timestamp']);
}
/**
* The function column
* We don't want binary data to be destroyed
* Note: from the MySQL manual: "BINARY doesn't affect how the column is
* stored or retrieved" so it does not mean that the contents is binary
*
* @param array $column description of column in given table
* @param boolean $is_upload upload or no
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param array $no_support_types list of datatypes that are not (yet)
* handled by PMA
* @param integer $tabindex_for_function +3000
* @param integer $tabindex tab index
* @param integer $idindex id index
* @param boolean $insert_mode insert mode or edit mode
*
* @return string an html sippet
*/
function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix,
$unnullify_trigger, $no_support_types, $tabindex_for_function,
$tabindex, $idindex, $insert_mode
) {
$html_output = '';
if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && ! $is_upload)
|| ($GLOBALS['cfg']['ProtectBinary'] === 'all' && $column['is_binary'])
|| ($GLOBALS['cfg']['ProtectBinary'] === 'noblob' && ! $column['is_blob'])
) {
$html_output .= '<td class="center">' . __('Binary') . '</td>' . "\n";
} elseif (strstr($column['True_Type'], 'enum')
|| strstr($column['True_Type'], 'set')
|| in_array($column['pma_type'], $no_support_types)
) {
$html_output .= '<td class="center">--</td>' . "\n";
} else {
$html_output .= '<td>' . "\n";
$html_output .= '<select name="funcs' . $column_name_appendix . '"'
. ' ' . $unnullify_trigger
. ' tabindex="' . ($tabindex + $tabindex_for_function) . '"'
. ' id="field_' . $idindex . '_1">';
$html_output .= PMA_Util::getFunctionsForField($column, $insert_mode) . "\n";
$html_output .= '</select>' . "\n";
$html_output .= '</td>' . "\n";
}
return $html_output;
}
/**
* The null column
*
* @param array $column description of column in given table
* @param string $column_name_appendix the name atttibute
* @param array $real_null_value is column value null or not null
* @param integer $tabindex tab index
* @param integer $tabindex_for_null +6000
* @param integer $idindex id index
* @param array $vkey [multi_edit]['row_id']
* @param array $foreigners keys into foreign fields
* @param array $foreignData data about the foreign keys
*
* @return string an html snippet
*/
function PMA_getNullColumn($column, $column_name_appendix, $real_null_value,
$tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData
) {
if ($column['Null'] != 'YES') {
return "<td></td>\n";
}
$html_output = '';
$html_output .= '<td>' . "\n";
$html_output .= '<input type="hidden" name="fields_null_prev'
. $column_name_appendix . '"';
if ($real_null_value && !$column['first_timestamp']) {
$html_output .= ' value="on"';
}
$html_output .= ' />' . "\n";
$html_output .= '<input type="checkbox" class="checkbox_null" tabindex="'
. ($tabindex + $tabindex_for_null) . '"'
. ' name="fields_null' . $column_name_appendix . '"';
if ($real_null_value && !$column['first_timestamp']) {
$html_output .= ' checked="checked"';
}
$html_output .= ' id="field_' . ($idindex) . '_2" />';
// nullify_code is needed by the js nullify() function
$nullify_code = PMA_getNullifyCodeForNullColumn(
$column, $foreigners, $foreignData
);
// to be able to generate calls to nullify() in jQuery
$html_output .= '<input type="hidden" class="nullify_code" name="nullify_code'
. $column_name_appendix . '" value="' . $nullify_code . '" />';
$html_output .= '<input type="hidden" class="hashed_field" name="hashed_field'
. $column_name_appendix . '" value="' . $column['Field_md5'] . '" />';
$html_output .= '<input type="hidden" class="multi_edit" name="multi_edit'
. $column_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
$html_output .= '</td>' . "\n";
return $html_output;
}
/**
* Retrieve the nullify code for the null column
*
* @param array $column description of column in given table
* @param array $foreigners keys into foreign fields
* @param array $foreignData data about the foreign keys
*
* @return integer $nullify_code
*/
function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData)
{
if (strstr($column['True_Type'], 'enum')) {
if (strlen($column['Type']) > 20) {
$nullify_code = '1';
} else {
$nullify_code = '2';
}
} elseif (strstr($column['True_Type'], 'set')) {
$nullify_code = '3';
} elseif ($foreigners
&& isset($foreigners[$column['Field']])
&& $foreignData['foreign_link'] == false
) {
// foreign key in a drop-down
$nullify_code = '4';
} elseif ($foreigners
&& isset($foreigners[$column['Field']])
&& $foreignData['foreign_link'] == true
) {
// foreign key with a browsing icon
$nullify_code = '6';
} else {
$nullify_code = '5';
}
return $nullify_code;
}
/**
* Get the HTML elements for value column in inert form
*
* @param array $column description of column in given table
* @param string $backup_field hidden input field
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $data description of the column field
* @param array $special_chars special characters
* @param array $foreignData data about the foreign keys
* @param boolean $odd_row whether row is odd
* @param array $paramTableDbArray array containing $db and $table
* @param array $rownumber_param &rownumber=row_id
* @param array $titles An HTML IMG tag for a particular icon from
* a theme, which may be an actual file or
* an icon from a sprite
* @param array $text_dir text direction
* @param string $special_chars_encoded replaced char if the string starts
* with a \r\n pair (0x0d0a) add an extra \n
* @param string $vkey [multi_edit]['row_id']
* @param boolean $is_upload is upload or not
* @param integer $biggest_max_file_size 0 intger
* @param string $default_char_editing default char editing mode which is stroe
* in the config.inc.php script
* @param array $no_support_types list of datatypes that are not (yet)
* handled by PMA
* @param array $gis_data_types list of GIS data types
* @param array $extracted_columnspec associative array containing type,
* spec_in_brackets and possibly
* enum_set_values (another array)
*
* @return string an html snippet
*/
function PMA_getValueColumn($column, $backup_field, $column_name_appendix,
$unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
$special_chars, $foreignData, $odd_row, $paramTableDbArray, $rownumber_param,
$titles, $text_dir, $special_chars_encoded, $vkey,
$is_upload, $biggest_max_file_size,
$default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec
) {
$html_output = '';
if ($foreignData['foreign_link'] == true) {
$html_output .= PMA_getForeignLink(
$column, $backup_field, $column_name_appendix,
$unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
$paramTableDbArray, $rownumber_param, $titles
);
} elseif (is_array($foreignData['disp_row'])) {
$html_output .= PMA_dispRowForeignData(
$backup_field, $column_name_appendix,
$unnullify_trigger, $tabindex, $tabindex_for_value,
$idindex, $data, $foreignData
);
} elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
&& strstr($column['pma_type'], 'longtext')
) {
$html_output = ' </td>';
$html_output .= '</tr>';
$html_output .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
. '<td colspan="5" class="right">';
$html_output .= PMA_getTextarea(
$column, $backup_field, $column_name_appendix, $unnullify_trigger,
$tabindex, $tabindex_for_value, $idindex, $text_dir,
$special_chars_encoded
);
} elseif (strstr($column['pma_type'], 'text')) {
$html_output .= PMA_getTextarea(
$column, $backup_field, $column_name_appendix, $unnullify_trigger,
$tabindex, $tabindex_for_value, $idindex, $text_dir,
$special_chars_encoded
);
$html_output .= "\n";
if (strlen($special_chars) > 32000) {
$html_output .= "</td>\n";
$html_output .= '<td>' . __('Because of its length,<br /> this column might not be editable');
}
} elseif ($column['pma_type'] == 'enum') {
$html_output .= PMA_getPmaTypeEnum(
$column, $backup_field, $column_name_appendix, $extracted_columnspec,
$unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data
);
} elseif ($column['pma_type'] == 'set') {
$html_output .= PMA_getPmaTypeSet(
$column, $extracted_columnspec, $backup_field,
$column_name_appendix, $unnullify_trigger, $tabindex,
$tabindex_for_value, $idindex, $data
);
} elseif ($column['is_binary'] || $column['is_blob']) {
$html_output .= PMA_getBinaryAndBlobColumn(
$column, $data, $special_chars, $biggest_max_file_size,
$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex,
$tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
$vkey, $is_upload
);
} elseif (! in_array($column['pma_type'], $no_support_types)) {
$html_output .= PMA_getNoSupportTypes(
$column, $default_char_editing, $backup_field,
$column_name_appendix, $unnullify_trigger, $tabindex, $special_chars,
$tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
$data, $extracted_columnspec
);
}
if (in_array($column['pma_type'], $gis_data_types)) {
$html_output .= PMA_getHTMLforGisDataTypes();
}
return $html_output;
}
/**
* Get HTML for foreign link in insert form
*
* @param array $column description of column in given table
* @param string $backup_field hidden input field
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $data data to edit
* @param array $paramTableDbArray array containing $db and $table
* @param array $rownumber_param &rownumber=row_id
* @param array $titles An HTML IMG tag for a particular icon from
* a theme, which may be an actual file or
* an icon from a sprite
*
* @return string an html snippet
*/
function PMA_getForeignLink($column, $backup_field, $column_name_appendix,
$unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
$paramTableDbArray, $rownumber_param, $titles
) {
list($db, $table) = $paramTableDbArray;
$html_output = '';
$html_output .= $backup_field . "\n";
$html_output .= '<input type="hidden" name="fields_type'
. $column_name_appendix . '" value="foreign" />';
$html_output .= '<input type="text" name="fields' . $column_name_appendix . '" '
. 'class="textfield" '
. $unnullify_trigger . ' '
. 'tabindex="' . ($tabindex + $tabindex_for_value) . '" '
. 'id="field_' . ($idindex) . '_3" '
. 'value="' . htmlspecialchars($data) . '" />';
$html_output .= '<a class="hide foreign_values_anchor" target="_blank" '
. 'onclick="window.open(this.href,\'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false;" '
. 'href="browse_foreigners.php?'
. PMA_generate_common_url($db, $table) . '&field='
. PMA_escapeJsString(urlencode($column['Field']) . $rownumber_param) . '">'
. str_replace("'", "\'", $titles['Browse']) . '</a>';
return $html_output;
}
/**
* Get HTML to display foreign data
*
* @param string $backup_field hidden input field
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $data data to edit
* @param array $foreignData data about the foreign keys
*
* @return string an html snippet
*/
function PMA_dispRowForeignData($backup_field, $column_name_appendix,
$unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
$foreignData
) {
$html_output = '';
$html_output .= $backup_field . "\n";
$html_output .= '<input type="hidden"'
. ' name="fields_type' . $column_name_appendix . '"'
. ' value="foreign" />';
$html_output .= '<select name="fields' . $column_name_appendix . '"'
. ' ' . $unnullify_trigger
. ' class="textfield"'
. ' tabindex="' . ($tabindex + $tabindex_for_value). '"'
. ' id="field_' . $idindex . '_3">';
$html_output .= PMA_foreignDropdown(
$foreignData['disp_row'], $foreignData['foreign_field'],
$foreignData['foreign_display'], $data,
$GLOBALS['cfg']['ForeignKeyMaxLimit']
);
$html_output .= '</select>';
return $html_output;
}
/**
* Get HTML textarea for insert form
*
* @param array $column column information
* @param string $backup_field hidden input field
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $text_dir text direction
* @param array $special_chars_encoded replaced char if the string starts
* with a \r\n pair (0x0d0a) add an extra \n
*
* @return string an html snippet
*/
function PMA_getTextarea($column, $backup_field, $column_name_appendix,
$unnullify_trigger,
$tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded
) {
$the_class = '';
$textAreaRows = $GLOBALS['cfg']['TextareaRows'];
$textareaCols = $GLOBALS['cfg']['TextareaCols'];
if ($column['is_char']) {
$the_class = 'char';
$textAreaRows = $GLOBALS['cfg']['CharTextareaRows'];
$textareaCols = $GLOBALS['cfg']['CharTextareaCols'];
} elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
&& strstr($column['pma_type'], 'longtext')
) {
$textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2;
$textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2;
}
$html_output = $backup_field . "\n"
. '<textarea name="fields' . $column_name_appendix . '"'
. ' class="' . $the_class . '"'
. ' rows="' . $textAreaRows . '"'
. ' cols="' . $textareaCols . '"'
. ' dir="' . $text_dir . '"'
. ' id="field_' . ($idindex) . '_3"'
. ' ' . $unnullify_trigger
. ' tabindex="' . ($tabindex + $tabindex_for_value) . '">'
. $special_chars_encoded
. '</textarea>';
return $html_output;
}
/**
* Get HTML for enum type
*
* @param type $column description of column in given table
* @param type $backup_field hidden input field
* @param type $column_name_appendix the name atttibute
* @param type $extracted_columnspec associative array containing type,
* spec_in_brackets and possibly
* enum_set_values (another array)
* @param type $unnullify_trigger validation string
* @param type $tabindex tab index
* @param type $tabindex_for_value offset for the values tabindex
* @param type $idindex id index
* @param type $data data to edit
*
* @return type string an html snippet
*/
function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix,
$extracted_columnspec, $unnullify_trigger, $tabindex, $tabindex_for_value,
$idindex, $data
) {
$html_output = '';
if (! isset($column['values'])) {
$column['values'] = PMA_getColumnEnumValues(
$column, $extracted_columnspec
);
}
$column_enum_values = $column['values'];
$html_output .= '<input type="hidden" name="fields_type'
. $column_name_appendix. '" value="enum" />';
$html_output .= '<input type="hidden" name="fields'
. $column_name_appendix . '" value="" />';
$html_output .= "\n" . ' ' . $backup_field . "\n";
if (strlen($column['Type']) > 20) {
$html_output .= PMA_getDropDownDependingOnLength(
$column, $column_name_appendix, $unnullify_trigger,
$tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
);
} else {
$html_output .= PMA_getRadioButtonDependingOnLength(
$column_name_appendix, $unnullify_trigger,
$tabindex, $column, $tabindex_for_value,
$idindex, $data, $column_enum_values
);
}
return $html_output;
}
/**
* Get column values
*
* @param array $column description of column in given table
* @param array $extracted_columnspec associative array containing type,
* spec_in_brackets and possibly enum_set_values
* (another array)
*
* @return array column values as an associative array
*/
function PMA_getColumnEnumValues($column, $extracted_columnspec)
{
$column['values'] = array();
foreach ($extracted_columnspec['enum_set_values'] as $val) {
// Removes automatic MySQL escape format
$val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
$column['values'][] = array(
'plain' => $val,
'html' => htmlspecialchars($val),
);
}
return $column['values'];
}
/**
* Get HTML drop down for more than 20 string length
*
* @param array $column description of column in given table
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $data data to edit
* @param array $column_enum_values $column['values']
*
* @return string an html snippet
*/
function PMA_getDropDownDependingOnLength(
$column, $column_name_appendix, $unnullify_trigger,
$tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
) {
$html_output = '<select name="fields' . $column_name_appendix . '"'
. ' ' . $unnullify_trigger
. ' class="textfield"'
. ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
. ' id="field_' . ($idindex) . '_3">';
$html_output .= '<option value=""> </option>' . "\n";
foreach ($column_enum_values as $enum_value) {
$html_output .= '<option value="' . $enum_value['html'] . '"';
if ($data == $enum_value['plain']
|| ($data == ''
&& (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
&& isset($column['Default'])
&& $enum_value['plain'] == $column['Default'])
) {
$html_output .= ' selected="selected"';
}
$html_output .= '>' . $enum_value['html'] . '</option>' . "\n";
}
$html_output .= '</select>';
return $html_output;
}
/**
* Get HTML radio button for less than 20 string length
*
* @param string $column_name_appendix the name atttibute
* @param string $unnullify_trigger validation string
* @param integer $tabindex tab index
* @param array $column description of column in given table
* @param integer $tabindex_for_value offset for the values tabindex
* @param integer $idindex id index
* @param array $data data to edit
* @param array $column_enum_values $column['values']
*
* @return string an html snippet
*/
function PMA_getRadioButtonDependingOnLength(
$column_name_appendix, $unnullify_trigger,
$tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
) {
$j = 0;
$html_output = '';
foreach ($column_enum_values as $enum_value) {
$html_output .= ' '
. '<input type="radio" name="fields' . $column_name_appendix . '"'
. ' class="textfield"'
. ' value="' . $enum_value['html'] . '"'
. ' id="field_' . ($idindex) . '_3_' . $j . '"'
. ' ' . $unnullify_trigger;
if ($data == $enum_value['plain']
|| ($data == ''
&& (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
&& isset($column['Default'])
&& $enum_value['plain'] == $column['Default'])
) {
$html_output .= ' checked="checked"';
}