From d895b852a6e160496ffc760d46d3719a3d62ff86 Mon Sep 17 00:00:00 2001
From: Nathan Kinkade
Date: Sun, 3 Feb 2008 23:23:24 +0000
Subject: Initial checkin of nutridb.org and basic subversion directory
structure
---
lib/standard.lib.php | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
create mode 100644 lib/standard.lib.php
(limited to 'lib/standard.lib.php')
diff --git a/lib/standard.lib.php b/lib/standard.lib.php
new file mode 100644
index 0000000..503052e
--- /dev/null
+++ b/lib/standard.lib.php
@@ -0,0 +1,112 @@
+SelectOne($paginationSql);
+ $totalRecords = $db->_row['rowCount'];
+ $totalPages = ceil($totalRecords / $config->_recordsPerPage);
+
+ # if the total records are less than what we show per page, then
+ # just skip everything else below
+ if ( $totalRecords <= $config->_recordsPerPage ) {
+ $fromRecord = ($pageOffset + 1);
+ $pageNav .= <<
+ Displaying: $fromRecord to $totalRecords of $totalRecords results.
+HTML;
+
+ return $pageNav;
+ }
+
+ # either append the proper page with & or ? depending
+ # on whether the submitted URI already has a query
+ # string or not
+ if ( preg_match("/\?.+/", $uri) ) {
+ $uri = "$uri&";
+ } else {
+ $uri = "$uri?";
+ }
+
+ # create the navigation menu
+ if ( $page > 1 ) {
+ $pagePrev = ($page - 1);
+ # if the previous page isn't also the first page, show a link for first page.
+ if ( $pagePrev != 1 ) {
+ $pageNav .= " [First] \n";
+ }
+ $pageNav .= " Prev\n";
+ }
+
+ for ( $idx = 1; $idx <= $totalPages; $idx++ ) {
+ if ( $idx == $page ) {
+ $pageNav .= " $idx \n";
+ } else {
+ $pageNav .= " $idx \n";
+ }
+ }
+
+ if ( ($totalRecords - ($config->_recordsPerPage * $page)) > 0 ) {
+ $pageNext = ($page + 1);
+ $pageNav .= " Next\n";
+ # if the previous page isn't also the first page, show a link for first page.
+ if ( $pageNext != $totalPages ) {
+ $pageNav .= " [Last] \n";
+ }
+ }
+
+ $fromRecord = ($pageOffset + 1);
+ if ( $page == $totalPages ) {
+ $toRecord = $totalRecords;
+ } else {
+ $toRecord = ($pageOffset + $config->_recordsPerPage);
+ }
+
+ $pageNav .= <<
+ Displaying: $fromRecord to $toRecord of $totalRecords results.
+HTML;
+
+ return $pageNav;
+
+}
+
+?>
--
cgit v1.2.3