/
structure.lib.php
2760 lines (2573 loc) · 93.7 KB
/
structure.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 for structure section in pma
*
* @package PhpMyAdmin
*/
if (!defined('PHPMYADMIN')) {
exit;
}
/**
* Get the HTML links for action links
* Actions are, Browse, Search, Browse table label, empty table
*
* @param array $current_table current table
* @param boolean $table_is_view Is table view or not
* @param string $tbl_url_query table url query
* @param array $titles titles and icons for action links
* @param string $truename table name
* @param boolean $db_is_system_schema is database information schema or not
* @param string $url_query url query
*
* @return array ($browse_table, $search_table, $browse_table_label, $empty_table,
* $tracking_icon)
*/
function PMA_getHtmlForActionLinks($current_table, $table_is_view, $tbl_url_query,
$titles, $truename, $db_is_system_schema, $url_query
) {
$empty_table = '';
if ($current_table['TABLE_ROWS'] > 0 || $table_is_view) {
$may_have_rows = true;
} else {
$may_have_rows = false;
}
$browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">';
if ($may_have_rows) {
$browse_table .= $titles['Browse'];
} else {
$browse_table .= $titles['NoBrowse'];
}
$browse_table .= '</a>';
$search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">';
if ($may_have_rows) {
$search_table .= $titles['Search'];
} else {
$search_table .= $titles['NoSearch'];
}
$search_table .= '</a>';
$browse_table_label = '<a href="sql.php?' . $tbl_url_query
. '&pos=0" title="' . $current_table['TABLE_COMMENT'] . '">'
. $truename . '</a>';
if (!$db_is_system_schema) {
$empty_table = '<a class="truncate_table_anchor ajax"';
$empty_table .= ' href="sql.php?' . $tbl_url_query
. '&sql_query=';
$empty_table .= urlencode(
'TRUNCATE ' . PMA_Util::backquote($current_table['TABLE_NAME'])
);
$empty_table .= '&message_to_show='
. urlencode(
sprintf(
__('Table %s has been emptied.'),
htmlspecialchars($current_table['TABLE_NAME'])
)
)
. '">';
if ($may_have_rows) {
$empty_table .= $titles['Empty'];
} else {
$empty_table .= $titles['NoEmpty'];
}
$empty_table .= '</a>';
// truncating views doesn't work
if ($table_is_view) {
$empty_table = ' ';
}
}
$tracking_icon = '';
if (PMA_Tracker::isActive()) {
if (PMA_Tracker::isTracked($GLOBALS["db"], $truename)) {
$tracking_icon = '<a href="tbl_tracking.php?' . $url_query
. '&table=' . $truename . '">'
. PMA_Util::getImage(
'eye.png', __('Tracking is active.')
)
. '</a>';
} elseif (PMA_Tracker::getVersion($GLOBALS["db"], $truename) > 0) {
$tracking_icon = '<a href="tbl_tracking.php?' . $url_query
. '&table=' . $truename . '">'
. PMA_Util::getImage(
'eye_grey.png', __('Tracking is not active.')
)
. '</a>';
}
}
return array($browse_table,
$search_table,
$browse_table_label,
$empty_table,
$tracking_icon
);
}
/**
* Get table drop query and drop message
*
* @param boolean $table_is_view Is table view or not
* @param string $current_table current table
*
* @return array ($drop_query, $drop_message)
*/
function PMA_getTableDropQueryAndMessage($table_is_view, $current_table)
{
$drop_query = 'DROP '
. (($table_is_view || $current_table['ENGINE'] == null) ? 'VIEW' : 'TABLE')
. ' ' . PMA_Util::backquote(
$current_table['TABLE_NAME']
);
$drop_message = sprintf(
(($table_is_view || $current_table['ENGINE'] == null)
? __('View %s has been dropped.')
: __('Table %s has been dropped.')),
str_replace(
' ',
' ',
htmlspecialchars($current_table['TABLE_NAME'])
)
);
return array($drop_query, $drop_message);
}
/**
* Get HTML body for table summery
*
* @param integer $num_tables number of tables
* @param boolean $server_slave_status server slave state
* @param boolean $db_is_system_schema whether database is information schema or not
* @param integer $sum_entries sum entries
* @param string $db_collation collation of given db
* @param boolean $is_show_stats whether stats is show or not
* @param double $sum_size sum size
* @param double $overhead_size overhead size
* @param string $create_time_all create time
* @param string $update_time_all update time
* @param string $check_time_all check time
* @param integer $sum_row_count_pre sum row count pre
*
* @return string $html_output
*/
function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status,
$db_is_system_schema, $sum_entries, $db_collation, $is_show_stats,
$sum_size, $overhead_size, $create_time_all, $update_time_all,
$check_time_all, $sum_row_count_pre
) {
if ($is_show_stats) {
list($sum_formatted, $unit) = PMA_Util::formatByteDown(
$sum_size, 3, 1
);
list($overhead_formatted, $overhead_unit)
= PMA_Util::formatByteDown($overhead_size, 3, 1);
}
$html_output = '<tbody id="tbl_summary_row">'
. '<tr><th></th>';
$html_output .= '<th class="tbl_num nowrap">';
$html_output .= sprintf(
_ngettext('%s table', '%s tables', $num_tables),
PMA_Util::formatNumber($num_tables, 0)
);
$html_output .= '</th>';
if ($server_slave_status) {
$html_output .= '<th>' . __('Replication') . '</th>' . "\n";
}
$html_output .= '<th colspan="' . ($db_is_system_schema ? 3 : 7) . '">'
. __('Sum')
. '</th>';
$html_output .= '<th class="value tbl_rows">'
. $sum_row_count_pre . PMA_Util::formatNumber($sum_entries, 0)
. '</th>';
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$default_engine = $GLOBALS['dbi']->fetchValue(
'SHOW VARIABLES LIKE \'storage_engine\';',
0,
1
);
$html_output .= '<th class="center">' . "\n"
. '<dfn title="'
. sprintf(
__('%s is the default storage engine on this MySQL server.'),
$default_engine
)
. '">' . $default_engine . '</dfn></th>' . "\n";
// we got a case where $db_collation was empty
$html_output .= '<th>' . "\n";
if (! empty($db_collation)) {
$html_output .= '<dfn title="'
. PMA_getCollationDescr($db_collation)
. ' (' . __('Default') . ')">'
. $db_collation
. '</dfn>';
}
$html_output .= '</th>';
}
if ($is_show_stats) {
$html_output .= '<th class="value tbl_size">'
. $sum_formatted . ' ' . $unit
. '</th>';
$html_output .= '<th class="value tbl_overhead">'
. $overhead_formatted . ' ' . $overhead_unit
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
$html_output .= '<th class="value tbl_creation">' . "\n"
. ' '
. ($create_time_all
? PMA_Util::localisedDate(strtotime($create_time_all))
: '-'
)
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
$html_output .= '<th class="value tbl_last_update">' . "\n"
. ' '
. ($update_time_all
? PMA_Util::localisedDate(strtotime($update_time_all))
: '-'
)
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
$html_output .= '<th class="value tbl_last_check">' . "\n"
. ' '
. ($check_time_all
? PMA_Util::localisedDate(strtotime($check_time_all))
: '-'
)
. '</th>';
}
$html_output .= '</tr>'
. '</tbody>';
return $html_output;
}
/**
* Get HTML for "check all" check box with "with selected" dropdown
*
* @param string $pmaThemeImage pma theme image url
* @param string $text_dir url for text directory
* @param string $overhead_check overhead check
* @param boolean $db_is_system_schema whether database is information schema or not
* @param string $hidden_fields hidden fields
*
* @return string $html_output
*/
function PMA_getHtmlForCheckAllTables($pmaThemeImage, $text_dir,
$overhead_check, $db_is_system_schema, $hidden_fields
) {
$html_output = '<div class="clearfloat">';
$html_output .= '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
$html_output .= '<input type="checkbox" id="tablesForm_checkall" '
. 'class="checkall_box" title="' . __('Check All') . '" />';
$html_output .= '<label for="tablesForm_checkall">' . __('Check All')
. '</label>';
if ($overhead_check != '') {
$html_output .= PMA_getHtmlForCheckTablesHavingOverheadlink(
$overhead_check
);
}
$html_output .= '<select name="submit_mult" class="autosubmit" '
. 'style="margin: 0 3em 0 3em;">';
$html_output .= '<option value="' . __('With selected:')
. '" selected="selected">'
. __('With selected:') . '</option>' . "\n";
$html_output .= '<option value="export" >'
. __('Export') . '</option>' . "\n";
$html_output .= '<option value="print" >'
. __('Print view') . '</option>' . "\n";
if (!$db_is_system_schema
&& !$GLOBALS['cfg']['DisableMultiTableMaintenance']
) {
$html_output .= '<option value="empty_tbl" >'
. __('Empty') . '</option>' . "\n";
$html_output .= '<option value="drop_tbl" >'
. __('Drop') . '</option>' . "\n";
$html_output .= '<option value="check_tbl" >'
. __('Check table') . '</option>' . "\n";
if (!PMA_DRIZZLE) {
$html_output .= '<option value="optimize_tbl" >'
. __('Optimize table') . '</option>' . "\n";
$html_output .= '<option value="repair_tbl" >'
. __('Repair table') . '</option>' . "\n";
}
$html_output .= '<option value="analyze_tbl" >'
. __('Analyze table') . '</option>' . "\n";
$html_output .= '<option value="add_prefix_tbl" >'
. __('Add prefix to table') . '</option>' . "\n";
$html_output .= '<option value="replace_prefix_tbl" >'
. __('Replace table prefix') . '</option>' . "\n";
$html_output .= '<option value="copy_tbl_change_prefix" >'
. __('Copy table with prefix') . '</option>' . "\n";
}
$html_output .= '</select>'
. implode("\n", $hidden_fields) . "\n";
$html_output .= '</div>';
return $html_output;
}
/**
* Get HTML code for "Check tables having overhead" link
*
* @param string $overhead_check overhead check
*
* @return string $html_output
*/
function PMA_getHtmlForCheckTablesHavingOverheadlink($overhead_check)
{
return ' / '
. '<a href="#" onclick="unMarkAllRows(\'tablesForm\');'
. $overhead_check . 'return false;">'
. __('Check tables having overhead')
. '</a>';
}
/**
* Get HTML links for "Print view" options
*
* @param string $url_query url query
*
* @return string $html_output
*/
function PMA_getHtmlForTablePrintViewLink($url_query)
{
return '<p>'
. '<a href="db_printview.php?' . $url_query . '" target="print_view">'
. PMA_Util::getIcon(
'b_print.png',
__('Print view'),
true
) . '</a>';
}
/**
* Get HTML links "Data Dictionary" options
*
* @param string $url_query url query
*
* @return string $html_output
*/
function PMA_getHtmlForDataDictionaryLink($url_query)
{
return '<a href="db_datadict.php?' . $url_query . '" target="print_view">'
. PMA_Util::getIcon(
'b_tblanalyse.png',
__('Data Dictionary'),
true
) . '</a>'
. '</p>';
}
/**
* Get Time for Create time, update time and check time
*
* @param array $current_table current table
* @param string $time_label Create_time, Update_time, Check_time
* @param integer $time_all time
*
* @return array ($time, $time_all)
*/
function PMA_getTimeForCreateUpdateCheck($current_table, $time_label, $time_all)
{
$showtable = PMA_Table::sGetStatusInfo(
$GLOBALS['db'],
$current_table['TABLE_NAME'],
null,
true
);
$time = isset($showtable[$time_label])
? $showtable[$time_label]
: false;
// show oldest creation date in summary row
if ($time && (!$time_all || $time < $time_all)) {
$time_all = $time;
}
return array($time, $time_all);
}
/**
* Get HTML for each table row of the database structure table,
* And this function returns $odd_row param also
*
* @param integer $curr current entry
* @param boolean $odd_row whether row is odd or not
* @param boolean $table_is_view whether table is view or not
* @param array $current_table current table
* @param string $browse_table_label browse table label action link
* @param string $tracking_icon tracking icon
* @param boolean $server_slave_status server slave state
* @param string $browse_table browse table action link
* @param string $tbl_url_query table url query
* @param string $search_table search table action link
* @param boolean $db_is_system_schema whether db is information schema or not
* @param array $titles titles array
* @param string $empty_table empty table action link
* @param string $drop_query table dropt query
* @param string $drop_message table drop message
* @param string $collation collation
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
* @param string $create_time create time
* @param string $update_time last update time
* @param string $check_time last check time
* @param boolean $is_show_stats whether stats is show or not
* @param boolean $ignored ignored
* @param boolean $do do
* @param integer $colspan_for_structure colspan for structure
*
* @return array $html_output, $odd_row
*/
function PMA_getHtmlForStructureTableRow(
$curr, $odd_row, $table_is_view, $current_table,
$browse_table_label, $tracking_icon,$server_slave_status,
$browse_table, $tbl_url_query, $search_table,
$db_is_system_schema,$titles, $empty_table, $drop_query, $drop_message,
$collation, $formatted_size, $unit, $overhead, $create_time, $update_time,
$check_time,$is_show_stats, $ignored, $do, $colspan_for_structure
) {
global $db;
$html_output = '<tr class="' . ($odd_row ? 'odd' : 'even');
$odd_row = ! $odd_row;
$html_output .= ($table_is_view ? ' is_view' : '')
. '" id="row_tbl_' . $curr . '">';
$html_output .= '<td class="center">'
. '<input type="checkbox" name="selected_tbl[]" class="checkall" '
. 'value="' . htmlspecialchars($current_table['TABLE_NAME']) . '" '
. 'id="checkbox_tbl_' . $curr . '" /></td>';
$html_output .= '<th>'
. $browse_table_label
. (! empty($tracking_icon) ? $tracking_icon : '')
. '</th>';
if ($server_slave_status) {
$html_output .= '<td class="center">'
. ($ignored
? PMA_Util::getImage('s_cancel.png', 'NOT REPLICATED')
: '')
. ($do
? PMA_Util::getImage('s_success.png', 'REPLICATED')
: '')
. '</td>';
}
//Favorite table anchor.
$html_output .= '<td class="center">'
. PMA_getHtmlForFavoriteAnchor($db, $current_table, $titles)
. '</td>';
$html_output .= '<td class="center">' . $browse_table . '</td>';
$html_output .= '<td class="center">'
. '<a href="tbl_structure.php?' . $tbl_url_query . '">'
. $titles['Structure'] . '</a></td>';
$html_output .= '<td class="center">' . $search_table . '</td>';
if (! $db_is_system_schema) {
$html_output .= PMA_getHtmlForInsertEmptyDropActionLinks(
$tbl_url_query, $table_is_view,
$titles, $empty_table, $current_table, $drop_query, $drop_message
);
} // end if (! $db_is_system_schema)
// there is a null value in the ENGINE
// - when the table needs to be repaired, or
// - when it's a view
// so ensure that we'll display "in use" below for a table
// that needs to be repaired
if (isset($current_table['TABLE_ROWS'])
&& ($current_table['ENGINE'] != null
|| $table_is_view)
) {
$html_output .= PMA_getHtmlForNotNullEngineViewTable(
$table_is_view, $current_table, $collation, $is_show_stats,
$tbl_url_query, $formatted_size, $unit, $overhead, $create_time,
$update_time, $check_time
);
} elseif ($table_is_view) {
$html_output .= PMA_getHtmlForViewTable($is_show_stats);
} else {
$html_output .= PMA_getHtmlForRepairtable(
$colspan_for_structure,
$db_is_system_schema
);
} // end if (isset($current_table['TABLE_ROWS'])) else
$html_output .= '</tr>';
return array($html_output, $odd_row);
}
/**
* Get HTML for Insert/Empty/Drop action links
*
* @param string $tbl_url_query table url query
* @param boolean $table_is_view whether table is view or not
* @param array $titles titles array
* @param string $empty_table HTML link for empty table
* @param array $current_table current table
* @param string $drop_query query for drop table
* @param string $drop_message table drop message
*
* @return string $html_output
*/
function PMA_getHtmlForInsertEmptyDropActionLinks($tbl_url_query, $table_is_view,
$titles, $empty_table, $current_table, $drop_query, $drop_message
) {
$html_output = '<td class="insert_table center">'
. '<a href="tbl_change.php?' . $tbl_url_query . '">'
. $titles['Insert']
. '</a></td>';
$html_output .= '<td class="center">' . $empty_table . '</td>';
$html_output .= '<td class="center">';
$html_output .= '<a ';
$html_output .= 'class="ajax drop_table_anchor';
if ($table_is_view || $current_table['ENGINE'] == null) {
// this class is used in db_structure.js to display the
// correct confirmation message
$html_output .= ' view';
}
$html_output .= '" ';
$html_output .= 'href="sql.php?' . $tbl_url_query
. '&reload=1&purge=1&sql_query='
. urlencode($drop_query) . '&message_to_show='
. urlencode($drop_message) . '" >'
. $titles['Drop'] . '</a></td>';
return $html_output;
}
/**
* Get HTML for show stats
*
* @param string $tbl_url_query tabel url query
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
*
* @return string $html_output
*/
function PMA_getHtmlForShowStats($tbl_url_query, $formatted_size,
$unit, $overhead
) {
$html_output = '<td class="value tbl_size"><a '
. 'href="tbl_structure.php?' . $tbl_url_query . '#showusage" >'
. '<span>' . $formatted_size . '</span> '
. '<span class="unit">' . $unit . '</span>'
. '</a></td>';
$html_output .= '<td class="value tbl_overhead">' . $overhead . '</td>';
return $html_output;
}
/**
* Get HTML to show database structure creation, last update and last checkx time
*
* @param string $create_time create time
* @param string $update_time last update time
* @param string $check_time last check time
*
* @return string $html_output
*/
function PMA_getHtmlForStructureTimes($create_time, $update_time, $check_time)
{
$html_output = '';
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
$html_output .= '<td class="value tbl_creation">'
. ($create_time
? PMA_Util::localisedDate(strtotime($create_time))
: '-' )
. '</td>';
} // end if
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
$html_output .= '<td class="value tbl_last_update">'
. ($update_time
? PMA_Util::localisedDate(strtotime($update_time))
: '-' )
. '</td>';
} // end if
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
$html_output .= '<td class="value tbl_last_check">'
. ($check_time
? PMA_Util::localisedDate(strtotime($check_time))
: '-' )
. '</td>';
}
return $html_output;
}
/**
* Get HTML for ENGINE value not null or view tables that are not empty tables
*
* @param boolean $table_is_view whether table is view
* @param array $current_table current table
* @param string $collation collation
* @param boolean $is_show_stats whether atats show or not
* @param string $tbl_url_query table url query
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
* @param string $create_time create time
* @param string $update_time update time
* @param string $check_time check time
*
* @return string $html_output
*/
function PMA_getHtmlForNotNullEngineViewTable($table_is_view, $current_table,
$collation, $is_show_stats, $tbl_url_query, $formatted_size, $unit,
$overhead, $create_time, $update_time, $check_time
) {
$html_output = '';
$row_count_pre = '';
$show_superscript = '';
if ($table_is_view) {
// Drizzle views use FunctionEngine, and the only place where they are
// available are I_S and D_D schemas, where we do exact counting
if ($current_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
&& $current_table['ENGINE'] != 'FunctionEngine'
) {
$row_count_pre = '~';
$sum_row_count_pre = '~';
$show_superscript = PMA_Util::showHint(
PMA_sanitize(
sprintf(
__('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
'[doc@cfg_MaxExactCountViews]',
'[/doc]'
)
)
);
}
} elseif ($current_table['ENGINE'] == 'InnoDB'
&& (! $current_table['COUNTED'])
) {
// InnoDB table: we did not get an accurate row count
$row_count_pre = '~';
$sum_row_count_pre = '~';
$show_superscript = '';
}
$html_output .= '<td class="value tbl_rows">'
. $row_count_pre . PMA_Util::formatNumber(
$current_table['TABLE_ROWS'], 0
)
. $show_superscript . '</td>';
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$html_output .= '<td class="nowrap">'
. ($table_is_view ? __('View') : $current_table['ENGINE'])
. '</td>';
if (strlen($collation)) {
$html_output .= '<td class="nowrap">' . $collation . '</td>';
}
}
if ($is_show_stats) {
$html_output .= PMA_getHtmlForShowStats(
$tbl_url_query, $formatted_size, $unit, $overhead
);
}
$html_output .= PMA_getHtmlForStructureTimes(
$create_time, $update_time, $check_time
);
return $html_output;
}
/**
* Get HTML snippet view table
*
* @param boolean $is_show_stats whether stats show or not
*
* @return string $html_output
*/
function PMA_getHtmlForViewTable($is_show_stats)
{
$html_output = '<td class="value">-</td>'
. '<td>' . __('View') . '</td>'
. '<td>---</td>';
if ($is_show_stats) {
$html_output .= '<td class="value">-</td>'
. '<td class="value">-</td>';
}
return $html_output;
}
/**
* display "in use" below for a table that needs to be repaired
*
* @param integer $colspan_for_structure colspan for structure
* @param boolean $db_is_system_schema whether db is information schema or not
*
* @return string HTML snippet
*/
function PMA_getHtmlForRepairtable(
$colspan_for_structure,
$db_is_system_schema
) {
return '<td colspan="'
. ($colspan_for_structure - ($db_is_system_schema ? 5 : 8)) . '"'
. 'class="center">'
. __('in use')
. '</td>';
}
/**
* display table header (<table><thead>...</thead><tbody>)
*
* @param boolean $db_is_system_schema whether db is information schema or not
* @param boolean $replication whether to sho replication status
*
* @return string html data
*/
function PMA_tableHeader($db_is_system_schema = false, $replication = false)
{
$cnt = 0; // Let's count the columns...
if ($db_is_system_schema) {
$action_colspan = 3;
} else {
$action_colspan = 7;
}
$html_output = '<table class="data">' . "\n"
. '<thead>' . "\n"
. '<tr><th></th>' . "\n"
. '<th>'
. PMA_sortableTableHeader(__('Table'), 'table')
. '</th>' . "\n";
if ($replication) {
$html_output .= '<th>' . "\n"
. ' ' . __('Replication') . "\n"
. '</th>';
}
$html_output .= '<th colspan="' . $action_colspan . '">' . "\n"
. ' ' . __('Action') . "\n"
. '</th>'
// larger values are more interesting so default sort order is DESC
. '<th>' . PMA_sortableTableHeader(__('Rows'), 'records', 'DESC')
. PMA_Util::showHint(
PMA_sanitize(
__('May be approximate. See [doc@faq3-11]FAQ 3.11[/doc].')
)
) . "\n"
. '</th>' . "\n";
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$html_output .= '<th>' . PMA_sortableTableHeader(__('Type'), 'type')
. '</th>' . "\n";
$cnt++;
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Collation'), 'collation')
. '</th>' . "\n";
$cnt++;
}
if ($GLOBALS['is_show_stats']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Size'), 'size', 'DESC')
. '</th>' . "\n"
// larger values are more interesting so default sort order is DESC
. '<th>'
. PMA_sortableTableHeader(__('Overhead'), 'overhead', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Creation'), 'creation', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Last update'), 'last_update', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Last check'), 'last_check', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
$html_output .= '</tr>' . "\n";
$html_output .= '</thead>' . "\n";
$html_output .= '<tbody>' . "\n";
$GLOBALS['colspan_for_structure'] = $cnt + $action_colspan + 3;
return $html_output;
}
/**
* Creates a clickable column header for table information
*
* @param string $title title to use for the link
* @param string $sort corresponds to sortable data name mapped in
* libraries/db_info.inc.php
* @param string $initial_sort_order initial sort order
*
* @return string link to be displayed in the table header
*/
function PMA_sortableTableHeader($title, $sort, $initial_sort_order = 'ASC')
{
// Set some defaults
$requested_sort = 'table';
$requested_sort_order = $future_sort_order = $initial_sort_order;
// If the user requested a sort
if (isset($_REQUEST['sort'])) {
$requested_sort = $_REQUEST['sort'];
if (isset($_REQUEST['sort_order'])) {
$requested_sort_order = $_REQUEST['sort_order'];
}
}
$order_img = '';
$order_link_params = array();
$order_link_params['title'] = __('Sort');
// If this column was requested to be sorted.
if ($requested_sort == $sort) {
if ($requested_sort_order == 'ASC') {
$future_sort_order = 'DESC';
// current sort order is ASC
$order_img = ' ' . PMA_Util::getImage(
's_asc.png',
__('Ascending'),
array('class' => 'sort_arrow', 'title' => '')
);
$order_img .= ' ' . PMA_Util::getImage(
's_desc.png',
__('Descending'),
array('class' => 'sort_arrow hide', 'title' => '')
);
// but on mouse over, show the reverse order (DESC)
$order_link_params['onmouseover'] = "$('.sort_arrow').toggle();";
// on mouse out, show current sort order (ASC)
$order_link_params['onmouseout'] = "$('.sort_arrow').toggle();";
} else {
$future_sort_order = 'ASC';
// current sort order is DESC
$order_img = ' ' . PMA_Util::getImage(
's_asc.png',
__('Ascending'),
array('class' => 'sort_arrow hide', 'title' => '')
);
$order_img .= ' ' . PMA_Util::getImage(
's_desc.png',
__('Descending'),
array('class' => 'sort_arrow', 'title' => '')
);
// but on mouse over, show the reverse order (ASC)
$order_link_params['onmouseover'] = "$('.sort_arrow').toggle();";
// on mouse out, show current sort order (DESC)
$order_link_params['onmouseout'] = "$('.sort_arrow').toggle();";
}
}
$_url_params = array(
'db' => $_REQUEST['db'],
);
$url = 'db_structure.php' . PMA_URL_getCommon($_url_params);
// We set the position back to 0 every time they sort.
$url .= "&pos=0&sort=$sort&sort_order=$future_sort_order";
if (! empty($_REQUEST['tbl_type'])) {
$url .= "&tbl_type=" . $_REQUEST['tbl_type'];
}
if (! empty($_REQUEST['tbl_group'])) {
$url .= "&tbl_group=" . $_REQUEST['tbl_group'];
}
return PMA_Util::linkOrButton(
$url, $title . $order_img, $order_link_params
);
}
/**
* Get the alias ant truname
*
* @param string $tooltip_aliasname tooltip alias name
* @param array $current_table current table
* @param string $tooltip_truename tooltip true name
*
* @return array ($alias, $truename)
*/
function PMA_getAliasAndTrueName($tooltip_aliasname, $current_table,
$tooltip_truename
) {
$alias = (! empty($tooltip_aliasname)
&& isset($tooltip_aliasname[$current_table['TABLE_NAME']])
)
? str_replace(
' ', ' ',
htmlspecialchars($tooltip_truename[$current_table['TABLE_NAME']])
)
: str_replace(
' ', ' ',
htmlspecialchars($current_table['TABLE_NAME'])
);
$truename = (! empty($tooltip_truename)
&& isset($tooltip_truename[$current_table['TABLE_NAME']])
)
? str_replace(
' ', ' ',
htmlspecialchars($tooltip_truename[$current_table['TABLE_NAME']])
)
: str_replace(
' ', ' ',
htmlspecialchars($current_table['TABLE_NAME'])
);
return array($alias, $truename);
}
/**
* Get the server slave state
*
* @param boolean $server_slave_status server slave state
* @param string $truename true name
*
* @return array ($do, $ignored)
*/
function PMA_getServerSlaveStatus($server_slave_status, $truename)
{
$ignored = false;
$do = false;
include_once 'libraries/replication.inc.php';
if ($server_slave_status) {
$nbServerSlaveDoDb = count($server_slave_Do_DB);
$nbServerSlaveIgnoreDb = count($server_slave_Ignore_DB);
if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
|| (strlen(array_search($GLOBALS['db'], $server_slave_Do_DB)) > 0)
|| ($nbServerSlaveDoDb == 1 && $nbServerSlaveIgnoreDb == 1)
) {
$do = true;
}
foreach ($server_slave_Wild_Do_Table as $db_table) {
$table_part = PMA_extractDbOrTable($db_table, 'table');
$pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@";
if (($GLOBALS['db'] == PMA_extractDbOrTable($db_table, 'db'))
&& (preg_match($pattern, $truename))
) {
$do = true;
}
}
if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
|| (strlen(array_search($GLOBALS['db'], $server_slave_Ignore_DB)) > 0)
) {
$ignored = true;
}
foreach ($server_slave_Wild_Ignore_Table as $db_table) {
$table_part = PMA_extractDbOrTable($db_table, 'table');
$pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@";
if (($db == PMA_extractDbOrTable($db_table))
&& (preg_match($pattern, $truename))
) {
$ignored = true;
}
}
}