$currentPage = $_SERVER['PHP_SELF']; } else { $currentPageParts = explode(PRODUCTIONHOMEDIRECTORY, $_SERVER['REQUEST_URI']); $currentPage = isset($currentPageParts[1]) ? $currentPageParts[1] : ''; //The path and filename, minus the domain, for the currently loaded page. } //Redirect for http or https. if (HTTPS) { if (FORCEHTTPS === false) { //Redirect to http (non-secure). header('Location: http://' . DOMAIN . PRODUCTIONHOMEDIRECTORY . $currentPage); } define('AUTOLINK', 'https://' . DOMAIN . PRODUCTIONHOMEDIRECTORY, true); define('CURRENTPAGE', 'https://' . DOMAIN . PRODUCTIONHOMEDIRECTORY . $currentPage, true); } else { $debug->add('PRODUCTIONHOMEDIRECTORY: ' . PRODUCTIONHOMEDIRECTORY); $debug->printArray($_SERVER, '$_SERVER'); //die($debug->output()); if (FORCEHTTPS !== false) { //Redirect to https (secure). header('Location: https://' . DOMAIN . PRODUCTIONHOMEDIRECTORY . $currentPage); } define('AUTOLINK', 'http://' . DOMAIN . PRODUCTIONHOMEDIRECTORY, true); define('CURRENTPAGE', 'http://' . DOMAIN . PRODUCTIONHOMEDIRECTORY . $currentPage, true); } set_include_path(PRODUCTIONINCLUDEDIRECTORY . '/'); define('COOKIEDOMAIN', '.' . DOMAIN, true); define('COOKIEPATH', '/', true); //The / is the default so the session cookie functions on all folders of the site. $dbHost = $rdbHost; $dbName = $remoteDbName;
public function output($mobileOptimizedId = false) { /* * Output the pagination. * * $mobileOptimizedId string If you want to hide all of the search and limit stuff, make a unique ID for the toggle hide function. * * @return string */ global $debug; $output = ''; $tempDebug = new Adrlist_Debug(); $tempDebug->add('$this->_defaultSearchValue at begining of output: ' . $this->_defaultSearchValue); try { $pageNumbersOutput = ''; if ($this->_itemCount === '' || !is_int($this->_itemCount)) { throw new Adrlist_CustomException('', '_itemCount is not valid: ' . $this->_itemCount . '.'); } elseif ($this->_offset === '' || !is_int($this->_offset)) { throw new Adrlist_CustomException('', '_offset is not valid: ' . $this->_offset . '.'); } elseif ($this->_limit === '' || !is_int($this->_limit)) { throw new Adrlist_CustomException('', '_limit is not valid: ' . $this->_limit . '.'); } elseif ($this->_uniqueId === '') { throw new Adrlist_CustomException('', '_uniqueId is not valid: ' . $this->_uniqueId . '.'); } $tempDebug->add('$this->_itemCount: ' . $this->_itemCount . '<br>$this->_offset: ' . $this->_offset . '<br>$this->_limit: ' . $this->_limit . '<br>$this->_uniqueId: ' . $this->_uniqueId . '<br>$this->_defaultSearchValue: ' . $this->_defaultSearchValue); $tempDebug->add('itemCount: ' . $this->_itemCount); //Build pagination. This is a numerical listing showing a user-selectable number of pages. if ($this->_itemCount > 0) { $totalPages = @ceil($this->_itemCount / $this->_limit); $currentPage = @ceil(($this->_offset + 1) / $this->_limit); $displayPages = empty($this->_displayPages) ? 11 : $this->_displayPages; $splitPoint = floor($displayPages / 2); //A halfway measurement. $preceedingDots = false; $trailingDots = false; //Determine where $currentPage is in relation to $totalPages. if ($totalPages - $currentPage < $splitPoint) { //$currentPage is near end. $tempDebug->add('1'); $endPage = $totalPages; if ($endPage - $displayPages < 1) { $tempDebug->add('1-1'); $startPage = 1; } else { $tempDebug->add('1-2'); $startPage = $endPage - ($displayPages - 1); $preceedingDots = true; } } else { //$currentPage is not near the end. $tempDebug->add('2'); $trailingDots = true; if ($currentPage - $splitPoint > 1) { //It is not near the beginning. $tempDebug->add('2-1'); $startPage = $currentPage - $splitPoint; $preceedingDots = true; $endPage = $currentPage + $splitPoint; if ($startPage + ($displayPages - 1) == $totalPages) { $tempDebug->add('2-1-1'); $trailingDots = false; } } else { $tempDebug->add('2-2'); $startPage = 1; if ($displayPages >= $totalPages) { $tempDebug->add('2-2-1'); $endPage = $totalPages; $trailingDots = false; } else { $tempDebug->add('2-2-2'); $endPage = $displayPages; } } } $tempDebug->add('$totalPages: ' . "{$totalPages}<br>" . '$displayPages: ' . "{$displayPages}<br>" . '$currentPage: ' . "{$currentPage}<br>" . '$splitPoint: ' . "{$splitPoint}<br>" . '$startPage: ' . "{$startPage}<br>" . '$endPage: ' . "{$endPage}"); if (empty($this->_limit)) { $pageNumbersOutput .= '<table class="table"><tr><td style="padding:2px 0px 2px 0px"> </td></tr></table>'; } else { $pageNumbersOutput = ' <div class="pagination"><table class="center"> <tr> '; $pageCount = $startPage; if ($preceedingDots) { $pageNumbersOutput .= '<td><button action="' . $this->_action . '" class="goToPage ui-btn ui-btn-c ui-btn-inline ui-shadow ui-corner-all ui-mini" limit="' . $this->_limit . '" offset="0" uniqueId="' . $this->_uniqueId . '">«</button></td><td class="backgroundWhite textLarge" style="border:none; padding:0px 0px 0px 0px">…</td>'; } while ($displayPages >= 1) { if ($pageCount > $totalPages) { $pageNumbersOutput .= '<td style="padding: 2px 6px"> </td>'; break; } $newOffset = ($pageCount - 1) * $this->_limit; if ($pageCount == $currentPage) { //The current page. $pageNumbersOutput .= ' <td><button action="' . $this->_action . '" class="ui-btn ui-btn-a ui-btn-inline ui-shadow ui-corner-all ui-mini" limit="' . $this->_limit . '" offset="' . $newOffset . '" uniqueId="' . $this->_uniqueId . '">' . $pageCount . '</button</td>'; } else { //Other pages. $pageNumbersOutput .= ' <td> <button action="' . $this->_action . '" class="goToPage ui-btn ui-btn-c ui-btn-inline ui-shadow ui-corner-all ui-mini" limit="' . $this->_limit . '" offset="' . $newOffset . '" uniqueId="' . $this->_uniqueId . '">' . $pageCount . '</button></td>'; } $pageCount++; $displayPages--; } if ($trailingDots) { $newOffset = ($totalPages - 1) * $this->_limit; $pageNumbersOutput .= '<td class="backgroundWhite textLarge" style="border:none; font-size:larger; padding:0px 0px 0px 3px">…</td><td><button action="' . $this->_action . '" class="goToPage ui-btn ui-btn-c ui-btn-inline ui-shadow ui-corner-all ui-mini" limit="' . $this->_limit . '" offset="' . $newOffset . '" uniqueId="' . $this->_uniqueId . '">»</button></td>'; } $pageNumbersOutput .= ' </tr> </table> </div> '; } } $debug->add('$this->_limit when $this->_uniqueId is ' . $this->_uniqueId . ': ' . $this->_limit); $searchOutput = '<div class="pagination textLeft"> <label class="ui-hidden-accessible" for="search' . $this->_uniqueId . '">Search Input:</label> <input class="searchfield" type="search" action="' . $this->_action . '" autocapitalize="off" autocorrect="off" autoreset="true" id="search' . $this->_uniqueId . '" placeholder="' . $this->_defaultSearchValue . '" goswitch="' . $this->_uniqueId . 'Goswitch"' . $this->_additionalSearchParams . ' name="search' . $this->_uniqueId . '"'; // default="' . $this->_defaultSearchValue . '" $searchOutput .= $this->_fromSearch ? ' value="' . $_POST['searchVal'] . '"' : ''; //hide $searchOutput .= '><button action="' . $this->_action . '" class="hide searchButton ui-btn ui-btn-inline ui-btn-cui-shadow ui-corner-all ui-mini" id="' . $this->_uniqueId . 'Goswitch" style="margin:0 .5em"><i class="fa fa-search" ></i>Search</button> </div>'; //<button class="clearSearch ui-btn ui-btn-inline ui-btn-b ui-icon-delete ui-btn-icon-left ui-shadow ui-corner-all ui-mini" default="' . $this->_defaultSearchValue . '" style="margin:0;">Clear</button> $limitOutput = '<div class="desktop pagination textRight" id="' . $mobileOptimizedId . '"> Show <input class="textRight" data-role="none" goswitch="setLimitButton' . $this->_uniqueId . '" offset="0" type="number" style="margin-right:.5em;width:3em;" value="' . $this->_limit . '"><button action="' . $this->_action . '" class="setLimitButton ui-btn ui-btn-inline ui-btn-c ui-shadow ui-corner-all ui-mini" id="setLimitButton' . $this->_uniqueId . '" uniqueId="' . $this->_uniqueId . '">Set</button><button action="' . $this->_action . '" class="limitShowAll ui-btn ui-btn-inline ui-btn-c ui-shadow ui-corner-all ui-mini" uniqueId="' . $this->_uniqueId . '">Show All</button> </div>'; //Build the output. if ($this->_searchOnly) { $output .= $searchOutput; } else { $output .= '<!-- begin pagination --><div class="break textCenter">' . $searchOutput . $pageNumbersOutput . $limitOutput . '</div>'; $output .= $mobileOptimizedId ? '<button class="mobile tablet ui-btn ui-mini ui-icon-carat-r ui-btn-inline ui-corner-all left" toggle="' . $mobileOptimizedId . '">View Options</button>' : ''; $output .= '<!-- end pagination -->'; } } catch (Adrlist_CustomException $e) { } //$debug->add($tempDebug->output()); return $output; }