3333use PhpMyAdmin \Utils \Gis ;
3434
3535use function __ ;
36- use function _pgettext ;
3736use function array_filter ;
3837use function array_keys ;
3938use function array_merge ;
@@ -659,64 +658,6 @@ private function isSelect(array $analyzedSqlResults): bool
659658 && ! empty ($ analyzedSqlResults ['statement ' ]->from [0 ]->table );
660659 }
661660
662- /**
663- * Get a navigation button
664- *
665- * @see getMoveBackwardButtonsForTableNavigation(),
666- * getMoveForwardButtonsForTableNavigation()
667- *
668- * @param string $caption iconic caption for button
669- * @param string $title text for button
670- * @param int $pos position for next query
671- * @param string $htmlSqlQuery query ready for display
672- * @param bool $back whether 'begin' or 'previous'
673- * @param string $onsubmit optional onsubmit clause
674- * @param string $inputForRealEnd optional hidden field for special treatment
675- *
676- * @return string html content
677- */
678- private function getTableNavigationButton (
679- $ caption ,
680- $ title ,
681- $ pos ,
682- $ htmlSqlQuery ,
683- $ back ,
684- $ onsubmit = '' ,
685- $ inputForRealEnd = ''
686- ): string {
687- $ captionOutput = '' ;
688- if ($ back ) {
689- if (Util::showIcons ('TableNavigationLinksMode ' )) {
690- $ captionOutput .= $ caption ;
691- }
692-
693- if (Util::showText ('TableNavigationLinksMode ' )) {
694- $ captionOutput .= ' ' . $ title ;
695- }
696- } else {
697- if (Util::showText ('TableNavigationLinksMode ' )) {
698- $ captionOutput .= $ title ;
699- }
700-
701- if (Util::showIcons ('TableNavigationLinksMode ' )) {
702- $ captionOutput .= ' ' . $ caption ;
703- }
704- }
705-
706- return $ this ->template ->render ('display/results/table_navigation_button ' , [
707- 'db ' => $ this ->properties ['db ' ],
708- 'table ' => $ this ->properties ['table ' ],
709- 'sql_query ' => $ htmlSqlQuery ,
710- 'pos ' => $ pos ,
711- 'is_browse_distinct ' => $ this ->properties ['is_browse_distinct ' ],
712- 'goto ' => $ this ->properties ['goto ' ],
713- 'input_for_real_end ' => $ inputForRealEnd ,
714- 'caption_output ' => $ captionOutput ,
715- 'title ' => $ title ,
716- 'onsubmit ' => $ onsubmit ,
717- ]);
718- }
719-
720661 /**
721662 * Possibly return a page selector for table navigation
722663 *
@@ -775,15 +716,6 @@ private function getTableNavigation(
775716 ): array {
776717 $ isShowingAll = $ _SESSION ['tmpval ' ]['max_rows ' ] === self ::ALL_ROWS ;
777718
778- // Move to the beginning or to the previous page
779- $ moveBackwardButtons = '' ;
780- if ($ _SESSION ['tmpval ' ]['pos ' ] && ! $ isShowingAll ) {
781- $ moveBackwardButtons = $ this ->getMoveBackwardButtonsForTableNavigation (
782- htmlspecialchars ($ this ->properties ['sql_query ' ]),
783- $ posPrevious
784- );
785- }
786-
787719 $ pageSelector = '' ;
788720 $ numberTotalPage = 1 ;
789721 if (! $ isShowingAll ) {
@@ -793,22 +725,24 @@ private function getTableNavigation(
793725 ] = $ this ->getHtmlPageSelector ();
794726 }
795727
796- // Move to the next page or to the last one
797- $ moveForwardButtons = '' ;
798- if (
799- // view with unknown number of rows
800- ($ this ->properties ['unlim_num_rows ' ] === -1 || $ this ->properties ['unlim_num_rows ' ] === false )
801- || (! $ isShowingAll
802- && intval ($ _SESSION ['tmpval ' ]['pos ' ]) + intval ($ _SESSION ['tmpval ' ]['max_rows ' ])
803- < $ this ->properties ['unlim_num_rows ' ]
804- && $ this ->properties ['num_rows ' ] >= $ _SESSION ['tmpval ' ]['max_rows ' ])
805- ) {
806- $ moveForwardButtons = $ this ->getMoveForwardButtonsForTableNavigation (
807- htmlspecialchars ($ this ->properties ['sql_query ' ]),
808- $ posNext ,
809- $ isInnodb
810- );
811- }
728+ $ isLastPage = $ this ->properties ['unlim_num_rows ' ] !== -1 && $ this ->properties ['unlim_num_rows ' ] !== false
729+ && ($ isShowingAll
730+ || intval ($ _SESSION ['tmpval ' ]['pos ' ]) + intval ($ _SESSION ['tmpval ' ]['max_rows ' ])
731+ >= $ this ->properties ['unlim_num_rows ' ]
732+ || $ this ->properties ['num_rows ' ] < $ _SESSION ['tmpval ' ]['max_rows ' ]);
733+
734+ $ onsubmit = ' onsubmit="return '
735+ . (intval ($ _SESSION ['tmpval ' ]['pos ' ])
736+ + intval ($ _SESSION ['tmpval ' ]['max_rows ' ])
737+ < $ this ->properties ['unlim_num_rows ' ]
738+ && $ this ->properties ['num_rows ' ] >= intval ($ _SESSION ['tmpval ' ]['max_rows ' ])
739+ ? 'true '
740+ : 'false ' ) . ';" ' ;
741+
742+ $ hasRealEndInput = $ isInnodb && $ this ->properties ['unlim_num_rows ' ] > $ GLOBALS ['cfg ' ]['MaxExactCount ' ];
743+ $ posLast = @((int ) ceil (
744+ (int ) $ this ->properties ['unlim_num_rows ' ] / $ _SESSION ['tmpval ' ]['max_rows ' ]
745+ ) - 1 ) * intval ($ _SESSION ['tmpval ' ]['max_rows ' ]);
812746
813747 $ hiddenFields = [
814748 'db ' => $ this ->properties ['db ' ],
@@ -820,9 +754,7 @@ private function getTableNavigation(
820754 ];
821755
822756 return [
823- 'move_backward_buttons ' => $ moveBackwardButtons ,
824757 'page_selector ' => $ pageSelector ,
825- 'move_forward_buttons ' => $ moveForwardButtons ,
826758 'number_total_page ' => $ numberTotalPage ,
827759 'has_show_all ' => $ GLOBALS ['cfg ' ]['ShowAll ' ] || ($ this ->properties ['unlim_num_rows ' ] <= 500 ),
828760 'hidden_fields ' => $ hiddenFields ,
@@ -831,95 +763,15 @@ private function getTableNavigation(
831763 'max_rows ' => $ _SESSION ['tmpval ' ]['max_rows ' ],
832764 'pos ' => $ _SESSION ['tmpval ' ]['pos ' ],
833765 'sort_by_key ' => $ sortByKeyData ,
766+ 'pos_previous ' => $ posPrevious ,
767+ 'pos_next ' => $ posNext ,
768+ 'pos_last ' => $ posLast ,
769+ 'is_last_page ' => $ isLastPage ,
770+ 'has_real_end_input ' => $ hasRealEndInput ,
771+ 'onsubmit ' => $ onsubmit ,
834772 ];
835773 }
836774
837- /**
838- * Prepare move backward buttons - previous and first
839- *
840- * @see getTableNavigation()
841- *
842- * @param string $htmlSqlQuery the sql encoded by html special characters
843- * @param int $posPrev the offset for the "previous" page
844- *
845- * @return string html content
846- */
847- private function getMoveBackwardButtonsForTableNavigation (
848- string $ htmlSqlQuery ,
849- int $ posPrev
850- ): string {
851- return $ this ->getTableNavigationButton (
852- '<< ' ,
853- _pgettext ('First page ' , 'Begin ' ),
854- 0 ,
855- $ htmlSqlQuery ,
856- true
857- )
858- . $ this ->getTableNavigationButton (
859- '< ' ,
860- _pgettext ('Previous page ' , 'Previous ' ),
861- $ posPrev ,
862- $ htmlSqlQuery ,
863- true
864- );
865- }
866-
867- /**
868- * Prepare move forward buttons - next and last
869- *
870- * @see getTableNavigation()
871- *
872- * @param string $htmlSqlQuery the sql encoded by htmlspecialchars()
873- * @param int $posNext the offset for the "next" page
874- * @param bool $isInnodb whether it's InnoDB or not
875- *
876- * @return string html content
877- */
878- private function getMoveForwardButtonsForTableNavigation (
879- string $ htmlSqlQuery ,
880- int $ posNext ,
881- bool $ isInnodb
882- ): string {
883- // display the Next button
884- $ buttonsHtml = $ this ->getTableNavigationButton (
885- '> ' ,
886- _pgettext ('Next page ' , 'Next ' ),
887- $ posNext ,
888- $ htmlSqlQuery ,
889- false
890- );
891-
892- $ inputForRealEnd = '' ;
893- // prepare some options for the End button
894- if ($ isInnodb && $ this ->properties ['unlim_num_rows ' ] > $ GLOBALS ['cfg ' ]['MaxExactCount ' ]) {
895- $ inputForRealEnd = '<input id="real_end_input" type="hidden" name="find_real_end" value="1"> ' ;
896- // no backquote around this message
897- }
898-
899- $ maxRows = (int ) $ _SESSION ['tmpval ' ]['max_rows ' ];
900- $ onsubmit = 'onsubmit="return '
901- . (intval ($ _SESSION ['tmpval ' ]['pos ' ])
902- + $ maxRows
903- < $ this ->properties ['unlim_num_rows ' ]
904- && $ this ->properties ['num_rows ' ] >= $ maxRows
905- ? 'true '
906- : 'false ' ) . '" ' ;
907-
908- // display the End button
909- return $ buttonsHtml . $ this ->getTableNavigationButton (
910- '>> ' ,
911- _pgettext ('Last page ' , 'End ' ),
912- @((int ) ceil (
913- (int ) $ this ->properties ['unlim_num_rows ' ]
914- / $ _SESSION ['tmpval ' ]['max_rows ' ]
915- ) - 1 ) * $ maxRows ,
916- $ htmlSqlQuery ,
917- false ,
918- $ onsubmit ,
919- $ inputForRealEnd
920- );
921- }
922-
923775 /**
924776 * Get the headers of the results table, for all of the columns
925777 *
@@ -3728,6 +3580,7 @@ public function getTable(
37283580 'save_cells_at_once ' => $ GLOBALS ['cfg ' ]['SaveCellsAtOnce ' ],
37293581 'default_sliders_state ' => $ GLOBALS ['cfg ' ]['InitialSlidersState ' ],
37303582 'text_dir ' => $ this ->properties ['text_dir ' ],
3583+ 'is_browse_distinct ' => $ this ->properties ['is_browse_distinct ' ],
37313584 ]);
37323585 }
37333586
0 commit comments