forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayResults.php
5840 lines (4979 loc) · 206 KB
/
DisplayResults.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: */
/**
* Hold the PMA\libraries\DisplayResults class
*
* @package PhpMyAdmin
*/
namespace PMA\libraries;
use PhpMyAdmin\SqlParser\Utils\Query;
use PMA\libraries\plugins\transformations\Text_Plain_Link;
use PMA\libraries\URL;
use PMA\libraries\Sanitize;
require_once './libraries/transformations.lib.php';
/**
* Handle all the functionalities related to displaying results
* of sql queries, stored procedure, browsing sql processes or
* displaying binary log.
*
* @package PhpMyAdmin
*/
class DisplayResults
{
// Define constants
const NO_EDIT_OR_DELETE = 'nn';
const UPDATE_ROW = 'ur';
const DELETE_ROW = 'dr';
const KILL_PROCESS = 'kp';
const POSITION_LEFT = 'left';
const POSITION_RIGHT = 'right';
const POSITION_BOTH = 'both';
const POSITION_NONE = 'none';
const PLACE_TOP_DIRECTION_DROPDOWN = 'top_direction_dropdown';
const PLACE_BOTTOM_DIRECTION_DROPDOWN = 'bottom_direction_dropdown';
const DISPLAY_FULL_TEXT = 'F';
const DISPLAY_PARTIAL_TEXT = 'P';
const HEADER_FLIP_TYPE_AUTO = 'auto';
const HEADER_FLIP_TYPE_CSS = 'css';
const HEADER_FLIP_TYPE_FAKE = 'fake';
const DATE_FIELD = 'date';
const DATETIME_FIELD = 'datetime';
const TIMESTAMP_FIELD = 'timestamp';
const TIME_FIELD = 'time';
const STRING_FIELD = 'string';
const GEOMETRY_FIELD = 'geometry';
const BLOB_FIELD = 'BLOB';
const BINARY_FIELD = 'BINARY';
const RELATIONAL_KEY = 'K';
const RELATIONAL_DISPLAY_COLUMN = 'D';
const GEOMETRY_DISP_GEOM = 'GEOM';
const GEOMETRY_DISP_WKT = 'WKT';
const GEOMETRY_DISP_WKB = 'WKB';
const SMART_SORT_ORDER = 'SMART';
const ASCENDING_SORT_DIR = 'ASC';
const DESCENDING_SORT_DIR = 'DESC';
const TABLE_TYPE_INNO_DB = 'InnoDB';
const ALL_ROWS = 'all';
const QUERY_TYPE_SELECT = 'SELECT';
const ROUTINE_PROCEDURE = 'procedure';
const ROUTINE_FUNCTION = 'function';
const ACTION_LINK_CONTENT_ICONS = 'icons';
const ACTION_LINK_CONTENT_TEXT = 'text';
// Declare global fields
/** array with properties of the class */
private $_property_array = array(
/** string Database name */
'db' => null,
/** string Table name */
'table' => null,
/** string the URL to go back in case of errors */
'goto' => null,
/** string the SQL query */
'sql_query' => null,
/**
* integer the total number of rows returned by the SQL query without any
* appended "LIMIT" clause programmatically
*/
'unlim_num_rows' => null,
/** array meta information about fields */
'fields_meta' => null,
/** boolean */
'is_count' => null,
/** integer */
'is_export' => null,
/** boolean */
'is_func' => null,
/** integer */
'is_analyse' => null,
/** integer the total number of rows returned by the SQL query */
'num_rows' => null,
/** integer the total number of fields returned by the SQL query */
'fields_cnt' => null,
/** double time taken for execute the SQL query */
'querytime' => null,
/** string path for theme images directory */
'pma_theme_image' => null,
/** string */
'text_dir' => null,
/** boolean */
'is_maint' => null,
/** boolean */
'is_explain' => null,
/** boolean */
'is_show' => null,
/** boolean */
'is_browse_distinct' => null,
/** array table definitions */
'showtable' => null,
/** string */
'printview' => null,
/** string URL query */
'url_query' => null,
/** array column names to highlight */
'highlight_columns' => null,
/** array holding various display information */
'display_params' => null,
/** array mime types information of fields */
'mime_map' => null,
/** boolean */
'editable' => null,
/** random unique ID to distinguish result set */
'unique_id' => null,
/** where clauses for each row, each table in the row */
'whereClauseMap' => array(),
);
/**
* This variable contains the column transformation information
* for some of the system databases.
* One element of this array represent all relevant columns in all tables in
* one specific database
*/
public $transformation_info;
/**
* Get any property of this class
*
* @param string $property name of the property
*
* @return mixed|void if property exist, value of the relevant property
*/
public function __get($property)
{
if (array_key_exists($property, $this->_property_array)) {
return $this->_property_array[$property];
}
}
/**
* Set values for any property of this class
*
* @param string $property name of the property
* @param mixed $value value to set
*
* @return void
*/
public function __set($property, $value)
{
if (array_key_exists($property, $this->_property_array)) {
$this->_property_array[$property] = $value;
}
}
/**
* Constructor for DisplayResults class
*
* @param string $db the database name
* @param string $table the table name
* @param string $goto the URL to go back in case of errors
* @param string $sql_query the SQL query
*
* @access public
*/
public function __construct($db, $table, $goto, $sql_query)
{
$this->_setDefaultTransformations();
$this->__set('db', $db);
$this->__set('table', $table);
$this->__set('goto', $goto);
$this->__set('sql_query', $sql_query);
$this->__set('unique_id', rand());
}
/**
* Sets default transformations for some columns
*
* @return void
*/
private function _setDefaultTransformations()
{
$json_highlighting_data = array(
'libraries/plugins/transformations/output/Text_Plain_Json.php',
'PMA\libraries\plugins\transformations\output\Text_Plain_Json',
'Text_Plain'
);
$sql_highlighting_data = array(
'libraries/plugins/transformations/output/Text_Plain_Sql.php',
'PMA\libraries\plugins\transformations\output\Text_Plain_Sql',
'Text_Plain'
);
$blob_sql_highlighting_data = array(
'libraries/plugins/transformations/output/Text_Octetstream_Sql.php',
'PMA\libraries\plugins\transformations\output\Text_Octetstream_Sql',
'Text_Octetstream'
);
$link_data = array(
'libraries/plugins/transformations/Text_Plain_Link.php',
'PMA\libraries\plugins\transformations\Text_Plain_Link',
'Text_Plain'
);
$this->transformation_info = array(
'information_schema' => array(
'events' => array(
'event_definition' => $sql_highlighting_data
),
'processlist' => array(
'info' => $sql_highlighting_data
),
'routines' => array(
'routine_definition' => $sql_highlighting_data
),
'triggers' => array(
'action_statement' => $sql_highlighting_data
),
'views' => array(
'view_definition' => $sql_highlighting_data
)
),
'mysql' => array(
'event' => array(
'body' => $blob_sql_highlighting_data,
'body_utf8' => $blob_sql_highlighting_data
),
'general_log' => array(
'argument' => $sql_highlighting_data
),
'help_category' => array(
'url' => $link_data
),
'help_topic' => array(
'example' => $sql_highlighting_data,
'url' => $link_data
),
'proc' => array(
'param_list' => $blob_sql_highlighting_data,
'returns' => $blob_sql_highlighting_data,
'body' => $blob_sql_highlighting_data,
'body_utf8' => $blob_sql_highlighting_data
),
'slow_log' => array(
'sql_text' => $sql_highlighting_data
)
)
);
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['db']) {
$this->transformation_info[$cfgRelation['db']] = array();
$relDb = &$this->transformation_info[$cfgRelation['db']];
if (! empty($cfgRelation['history'])) {
$relDb[$cfgRelation['history']] = array(
'sqlquery' => $sql_highlighting_data
);
}
if (! empty($cfgRelation['bookmark'])) {
$relDb[$cfgRelation['bookmark']] = array(
'query' => $sql_highlighting_data
);
}
if (! empty($cfgRelation['tracking'])) {
$relDb[$cfgRelation['tracking']] = array(
'schema_sql' => $sql_highlighting_data,
'data_sql' => $sql_highlighting_data
);
}
if (! empty($cfgRelation['favorite'])) {
$relDb[$cfgRelation['favorite']] = array(
'tables' => $json_highlighting_data
);
}
if (! empty($cfgRelation['recent'])) {
$relDb[$cfgRelation['recent']] = array(
'tables' => $json_highlighting_data
);
}
if (! empty($cfgRelation['savedsearches'])) {
$relDb[$cfgRelation['savedsearches']] = array(
'search_data' => $json_highlighting_data
);
}
if (! empty($cfgRelation['designer_settings'])) {
$relDb[$cfgRelation['designer_settings']] = array(
'settings_data' => $json_highlighting_data
);
}
if (! empty($cfgRelation['table_uiprefs'])) {
$relDb[$cfgRelation['table_uiprefs']] = array(
'prefs' => $json_highlighting_data
);
}
if (! empty($cfgRelation['userconfig'])) {
$relDb[$cfgRelation['userconfig']] = array(
'config_data' => $json_highlighting_data
);
}
if (! empty($cfgRelation['export_templates'])) {
$relDb[$cfgRelation['export_templates']] = array(
'template_data' => $json_highlighting_data
);
}
}
}
/**
* Set properties which were not initialized at the constructor
*
* @param integer $unlim_num_rows the total number of rows returned by
* the SQL query without any appended
* "LIMIT" clause programmatically
* @param array $fields_meta meta information about fields
* @param boolean $is_count statement is SELECT COUNT
* @param integer $is_export statement contains INTO OUTFILE
* @param boolean $is_func statement contains a function like SUM()
* @param integer $is_analyse statement contains PROCEDURE ANALYSE
* @param integer $num_rows total no. of rows returned by SQL query
* @param integer $fields_cnt total no.of fields returned by SQL query
* @param double $querytime time taken for execute the SQL query
* @param string $pmaThemeImage path for theme images directory
* @param string $text_dir text direction
* @param boolean $is_maint statement contains a maintenance command
* @param boolean $is_explain statement contains EXPLAIN
* @param boolean $is_show statement contains SHOW
* @param array $showtable table definitions
* @param string $printview print view was requested
* @param string $url_query URL query
* @param boolean $editable whether the results set is editable
* @param boolean $is_browse_dist whether browsing distinct values
*
* @return void
*
* @see sql.php
*/
public function setProperties(
$unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
$is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir,
$is_maint, $is_explain, $is_show, $showtable, $printview, $url_query,
$editable, $is_browse_dist
) {
$this->__set('unlim_num_rows', $unlim_num_rows);
$this->__set('fields_meta', $fields_meta);
$this->__set('is_count', $is_count);
$this->__set('is_export', $is_export);
$this->__set('is_func', $is_func);
$this->__set('is_analyse', $is_analyse);
$this->__set('num_rows', $num_rows);
$this->__set('fields_cnt', $fields_cnt);
$this->__set('querytime', $querytime);
$this->__set('pma_theme_image', $pmaThemeImage);
$this->__set('text_dir', $text_dir);
$this->__set('is_maint', $is_maint);
$this->__set('is_explain', $is_explain);
$this->__set('is_show', $is_show);
$this->__set('showtable', $showtable);
$this->__set('printview', $printview);
$this->__set('url_query', $url_query);
$this->__set('editable', $editable);
$this->__set('is_browse_distinct', $is_browse_dist);
} // end of the 'setProperties()' function
/**
* Defines the parts to display for a print view
*
* @param array $displayParts the parts to display
*
* @return array $displayParts the modified display parts
*
* @access private
*
*/
private function _setDisplayPartsForPrintView($displayParts)
{
// set all elements to false!
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE; // no edit link
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE; // no delete link
$displayParts['sort_lnk'] = (string) '0';
$displayParts['nav_bar'] = (string) '0';
$displayParts['bkm_form'] = (string) '0';
$displayParts['text_btn'] = (string) '0';
$displayParts['pview_lnk'] = (string) '0';
return $displayParts;
}
/**
* Defines the parts to display for a SHOW statement
*
* @param array $displayParts the parts to display
*
* @return array $displayParts the modified display parts
*
* @access private
*
*/
private function _setDisplayPartsForShow($displayParts)
{
preg_match(
'@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?'
. 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS'
. ')@i',
$this->__get('sql_query'), $which
);
$bIsProcessList = isset($which[1]);
if ($bIsProcessList) {
$str = ' ' . strtoupper($which[1]);
$bIsProcessList = $bIsProcessList
&& strpos($str, 'PROCESSLIST') > 0;
}
if ($bIsProcessList) {
// no edit link
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// "kill process" type edit link
$displayParts['del_lnk'] = self::KILL_PROCESS;
} else {
// Default case -> no links
// no edit link
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// no delete link
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE;
}
// Other settings
$displayParts['sort_lnk'] = (string) '0';
$displayParts['nav_bar'] = (string) '0';
$displayParts['bkm_form'] = (string) '1';
$displayParts['text_btn'] = (string) '1';
$displayParts['pview_lnk'] = (string) '1';
return $displayParts;
}
/**
* Defines the parts to display for statements not related to data
*
* @param array $displayParts the parts to display
*
* @return array $displayParts the modified display parts
*
* @access private
*
*/
private function _setDisplayPartsForNonData($displayParts)
{
// Statement is a "SELECT COUNT", a
// "CHECK/ANALYZE/REPAIR/OPTIMIZE/CHECKSUM", an "EXPLAIN" one or
// contains a "PROC ANALYSE" part
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE; // no edit link
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE; // no delete link
$displayParts['sort_lnk'] = (string) '0';
$displayParts['nav_bar'] = (string) '0';
$displayParts['bkm_form'] = (string) '1';
if ($this->__get('is_maint')) {
$displayParts['text_btn'] = (string) '1';
} else {
$displayParts['text_btn'] = (string) '0';
}
$displayParts['pview_lnk'] = (string) '1';
return $displayParts;
}
/**
* Defines the parts to display for other statements (probably SELECT)
*
* @param array $displayParts the parts to display
*
* @return array $displayParts the modified display parts
*
* @access private
*
*/
private function _setDisplayPartsForSelect($displayParts)
{
// Other statements (ie "SELECT" ones) -> updates
// $displayParts['edit_lnk'], $displayParts['del_lnk'] and
// $displayParts['text_btn'] (keeps other default values)
$fields_meta = $this->__get('fields_meta');
$prev_table = '';
$displayParts['text_btn'] = (string) '1';
$number_of_columns = $this->__get('fields_cnt');
for ($i = 0; $i < $number_of_columns; $i++) {
$is_link = ($displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE)
|| ($displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE)
|| ($displayParts['sort_lnk'] != '0');
// Displays edit/delete/sort/insert links?
if ($is_link
&& $prev_table != ''
&& $fields_meta[$i]->table != ''
&& $fields_meta[$i]->table != $prev_table
) {
// don't display links
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE;
/**
* @todo May be problematic with same field names
* in two joined table.
*/
// $displayParts['sort_lnk'] = (string) '0';
if ($displayParts['text_btn'] == '1') {
break;
}
} // end if
// Always display print view link
$displayParts['pview_lnk'] = (string) '1';
if ($fields_meta[$i]->table != '') {
$prev_table = $fields_meta[$i]->table;
}
} // end for
if ($prev_table == '') { // no table for any of the columns
// don't display links
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE;
}
return $displayParts;
}
/**
* Defines the parts to display for the results of a SQL query
* and the total number of rows
*
* @param array $displayParts the parts to display (see a few
* lines above for explanations)
*
* @return array the first element is an array with explicit indexes
* for all the display elements
* the second element is the total number of rows returned
* by the SQL query without any programmatically appended
* LIMIT clause (just a copy of $unlim_num_rows if it exists,
* else computed inside this function)
*
*
* @access private
*
* @see getTable()
*/
private function _setDisplayPartsAndTotal($displayParts)
{
$the_total = 0;
// 1. Following variables are needed for use in isset/empty or
// use with array indexes or safe use in foreach
$db = $this->__get('db');
$table = $this->__get('table');
$unlim_num_rows = $this->__get('unlim_num_rows');
$num_rows = $this->__get('num_rows');
$printview = $this->__get('printview');
// 2. Updates the display parts
if ($printview == '1') {
$displayParts = $this->_setDisplayPartsForPrintView($displayParts);
} elseif ($this->__get('is_count') || $this->__get('is_analyse')
|| $this->__get('is_maint') || $this->__get('is_explain')
) {
$displayParts = $this->_setDisplayPartsForNonData($displayParts);
} elseif ($this->__get('is_show')) {
$displayParts = $this->_setDisplayPartsForShow($displayParts);
} else {
$displayParts = $this->_setDisplayPartsForSelect($displayParts);
} // end if..elseif...else
// 3. Gets the total number of rows if it is unknown
if (isset($unlim_num_rows) && $unlim_num_rows != '') {
$the_total = $unlim_num_rows;
} elseif ((($displayParts['nav_bar'] == '1')
|| ($displayParts['sort_lnk'] == '1'))
&& (strlen($db) > 0 && strlen($table) > 0)
) {
$the_total = $GLOBALS['dbi']->getTable($db, $table)->countRecords();
}
// if for COUNT query, number of rows returned more than 1
// (may be being used GROUP BY)
if ($this->__get('is_count') && isset($num_rows) && $num_rows > 1) {
$displayParts['nav_bar'] = (string) '1';
$displayParts['sort_lnk'] = (string) '1';
}
// 4. If navigation bar or sorting fields names URLs should be
// displayed but there is only one row, change these settings to
// false
if ($displayParts['nav_bar'] == '1' || $displayParts['sort_lnk'] == '1') {
// - Do not display sort links if less than 2 rows.
// - For a VIEW we (probably) did not count the number of rows
// so don't test this number here, it would remove the possibility
// of sorting VIEW results.
$_table = new Table($table, $db);
if (isset($unlim_num_rows)
&& ($unlim_num_rows < 2)
&& ! $_table->isView()
) {
$displayParts['sort_lnk'] = (string) '0';
}
} // end if (3)
return array($displayParts, $the_total);
} // end of the 'setDisplayPartsAndTotal()' function
/**
* Return true if we are executing a query in the form of
* "SELECT * FROM <a table> ..."
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return boolean
*
* @access private
*
* @see _getTableHeaders(), _getColumnParams()
*/
private function _isSelect($analyzed_sql_results)
{
return ! ($this->__get('is_count')
|| $this->__get('is_export')
|| $this->__get('is_func')
|| $this->__get('is_analyse'))
&& !empty($analyzed_sql_results['select_from'])
&& !empty($analyzed_sql_results['statement']->from)
&& (count($analyzed_sql_results['statement']->from) == 1)
&& !empty($analyzed_sql_results['statement']->from[0]->table);
}
/**
* Get a navigation button
*
* @param string $caption iconic caption for button
* @param string $title text for button
* @param integer $pos position for next query
* @param string $html_sql_query query ready for display
* @param boolean $back whether 'begin' or 'previous'
* @param string $onsubmit optional onsubmit clause
* @param string $input_for_real_end optional hidden field for special treatment
* @param string $onclick optional onclick clause
*
* @return string html content
*
* @access private
*
* @see _getMoveBackwardButtonsForTableNavigation(),
* _getMoveForwardButtonsForTableNavigation()
*/
private function _getTableNavigationButton(
$caption, $title, $pos, $html_sql_query, $back, $onsubmit = '',
$input_for_real_end = '', $onclick = ''
) {
$caption_output = '';
if ($back) {
if (Util::showIcons('TableNavigationLinksMode')) {
$caption_output .= $caption;
}
if (Util::showText('TableNavigationLinksMode')) {
$caption_output .= ' ' . $title;
}
} else {
if (Util::showText('TableNavigationLinksMode')) {
$caption_output .= $title;
}
if (Util::showIcons('TableNavigationLinksMode')) {
$caption_output .= ' ' . $caption;
}
}
$title_output = ' title="' . $title . '"';
return '<td>'
. '<form action="sql.php" method="post" ' . $onsubmit . '>'
. URL::getHiddenInputs(
$this->__get('db'), $this->__get('table')
)
. '<input type="hidden" name="sql_query" value="'
. $html_sql_query . '" />'
. '<input type="hidden" name="pos" value="' . $pos . '" />'
. '<input type="hidden" name="is_browse_distinct" value="'
. $this->__get('is_browse_distinct') . '" />'
. '<input type="hidden" name="goto" value="' . $this->__get('goto')
. '" />'
. $input_for_real_end
. '<input type="submit" name="navig"'
. ' class="ajax" '
. 'value="' . $caption_output . '" ' . $title_output . $onclick . ' />'
. '</form>'
. '</td>';
} // end function _getTableNavigationButton()
/**
* Possibly return a page selector for table navigation
*
* @param string $table_navigation_html the current navigation HTML
*
* @return array ($table_navigation_html, $nbTotalPage)
*
* @access private
*
*/
private function _getHtmlPageSelector($table_navigation_html)
{
$pageNow = @floor(
$_SESSION['tmpval']['pos']
/ $_SESSION['tmpval']['max_rows']
) + 1;
$nbTotalPage = @ceil(
$this->__get('unlim_num_rows')
/ $_SESSION['tmpval']['max_rows']
);
if ($nbTotalPage > 1) {
$table_navigation_html .= '<td>';
$_url_params = array(
'db' => $this->__get('db'),
'table' => $this->__get('table'),
'sql_query' => $this->__get('sql_query'),
'goto' => $this->__get('goto'),
'is_browse_distinct' => $this->__get('is_browse_distinct'),
);
//<form> to keep the form alignment of button < and <<
// and also to know what to execute when the selector changes
$table_navigation_html .= '<form action="sql.php" method="post">';
$table_navigation_html .= URL::getHiddenInputs($_url_params);
$table_navigation_html .= Util::pageselector(
'pos',
$_SESSION['tmpval']['max_rows'],
$pageNow, $nbTotalPage, 200, 5, 5, 20, 10
);
$table_navigation_html .= '</form>'
. '</td>';
}
return array($table_navigation_html, $nbTotalPage);
}
/**
* Get a navigation bar to browse among the results of a SQL query
*
* @param integer $pos_next the offset for the "next" page
* @param integer $pos_prev the offset for the "previous" page
* @param boolean $is_innodb whether its InnoDB or not
* @param string $sort_by_key_html the sort by key dialog
*
* @return string html content
*
* @access private
*
* @see _getTable()
*/
private function _getTableNavigation(
$pos_next, $pos_prev, $is_innodb, $sort_by_key_html
) {
$table_navigation_html = '';
// here, using htmlentities() would cause problems if the query
// contains accented characters
$html_sql_query = htmlspecialchars($this->__get('sql_query'));
// Navigation bar
$table_navigation_html
.= '<table class="navigation nospacing nopadding print_ignore">'
. '<tr>'
. '<td class="navigation_separator"></td>';
// Move to the beginning or to the previous page
if ($_SESSION['tmpval']['pos']
&& ($_SESSION['tmpval']['max_rows'] != self::ALL_ROWS)
) {
$table_navigation_html
.= $this->_getMoveBackwardButtonsForTableNavigation(
$html_sql_query, $pos_prev
);
} // end move back
$nbTotalPage = 1;
//page redirection
// (unless we are showing all records)
if ($_SESSION['tmpval']['max_rows'] != self::ALL_ROWS) {
list(
$table_navigation_html,
$nbTotalPage
) = $this->_getHtmlPageSelector($table_navigation_html);
}
$showing_all = false;
if ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS) {
$showing_all = true;
}
// Move to the next page or to the last one
if ($this->__get('unlim_num_rows') === false // view with unknown number of rows
|| ($_SESSION['tmpval']['max_rows'] != self::ALL_ROWS
&& $_SESSION['tmpval']['pos'] + $_SESSION['tmpval']['max_rows'] < $this->__get('unlim_num_rows')
&& $this->__get('num_rows') >= $_SESSION['tmpval']['max_rows'])
) {
$table_navigation_html
.= $this->_getMoveForwardButtonsForTableNavigation(
$html_sql_query, $pos_next, $is_innodb
);
} // end move toward
// show separator if pagination happen
if ($nbTotalPage > 1) {
$table_navigation_html
.= '<td><div class="navigation_separator">|</div></td>';
}
// Display the "Show all" button if allowed
if ($GLOBALS['cfg']['ShowAll'] || ($this->__get('unlim_num_rows') <= 500) ) {
$table_navigation_html .= $this->_getShowAllCheckboxForTableNavigation(
$showing_all, $html_sql_query
);
$table_navigation_html
.= '<td><div class="navigation_separator">|</div></td>';
} // end show all
$table_navigation_html .= '<td>'
. '<div class="save_edited hide">'
. '<input type="submit" value="' . __('Save edited data') . '" />'
. '<div class="navigation_separator">|</div>'
. '</div>'
. '</td>'
. '<td>'
. '<div class="restore_column hide">'
. '<input type="submit" value="' . __('Restore column order') . '" />'
. '<div class="navigation_separator">|</div>'
. '</div>'
. '</td>';
// if displaying a VIEW, $unlim_num_rows could be zero because
// of $cfg['MaxExactCountViews']; in this case, avoid passing
// the 5th parameter to checkFormElementInRange()
// (this means we can't validate the upper limit
$table_navigation_html .= '<td class="navigation_goto">';
$table_navigation_html .= '<form action="sql.php" method="post" '
. 'onsubmit="return '
. '(checkFormElementInRange('
. 'this, '
. '\'session_max_rows\', '
. '\''
. str_replace('\'', '\\\'', __('%d is not valid row number.'))
. '\', '
. '1)'
. ' && '
. 'checkFormElementInRange('
. 'this, '
. '\'pos\', '
. '\''
. str_replace('\'', '\\\'', __('%d is not valid row number.'))
. '\', '
. '0'
. (($this->__get('unlim_num_rows') > 0)
? ', ' . ($this->__get('unlim_num_rows') - 1)
: ''
)
. ')'
. ')'
. '">';
$table_navigation_html .= URL::getHiddenInputs(
$this->__get('db'), $this->__get('table')
);
$table_navigation_html .= $this->_getAdditionalFieldsForTableNavigation(
$html_sql_query
);
$table_navigation_html .= '</form>'
. '</td>'
. '<td class="navigation_separator"></td>'
. '<td>'
. '<span>' . __('Filter rows') . ':</span>'
. '<input type="text" class="filter_rows"'
. ' placeholder="' . __('Search this table') . '"'
. ' data-for="' . $this->__get('unique_id') . '" />'
. '</td>';
$table_navigation_html .= '<td>' . $sort_by_key_html . '</td>';
$table_navigation_html .= '<td class="navigation_separator"></td>'
. '</tr>'
. '</table>';
return $table_navigation_html;
} // end of the '_getTableNavigation()' function
/**
* Prepare move backward buttons - previous and first
*
* @param string $html_sql_query the sql encoded by html special characters
* @param integer $pos_prev the offset for the "previous" page
*
* @return string html content
*
* @access private
*
* @see _getTableNavigation()
*/
private function _getMoveBackwardButtonsForTableNavigation(
$html_sql_query, $pos_prev
) {
return $this->_getTableNavigationButton(
'<<', _pgettext('First page', 'Begin'), 0, $html_sql_query, true
)
. $this->_getTableNavigationButton(
'<', _pgettext('Previous page', 'Previous'), $pos_prev,
$html_sql_query, true
);
} // end of the '_getMoveBackwardButtonsForTableNavigation()' function
/**
* Prepare Show All checkbox for table navigation
*