Location: PHPKode > projects > MyPHPBib > bib_search_display.php
<?php

require_once ('login/user.inc.php');
include ('phpbib/phpbib.inc.php');

?>

<?php include ('header.inc.php'); ?>

<body>

<?php include ('top.inc.php'); ?>

<script language="Javascript" type="application/x-javascript">
function validatePageForm(form, currentPage, maxPages)
{
	// Did user enter a number?
	var str = form.page.value; 
	var re = /^[0-9]*$/; 
	if (form.page.value == "")
	{
			form.page.value = currentPage;
			return false;
	}
	if (re.test(str))
	{
		if (form.page.value	> maxPages)
		{	
			form.page.value = currentPage;
			return false;
		}
	}
	else
	{
			form.page.value = currentPage;
			return false;
	}
	return true;
}
</script>


<div id="content">

<?php

class Pager {
	var $id;
	var $page;
	var $results_per_page;
	var $total_pages;
	var $num_results;
	var $r;
	

	function Pager ($search_id, $current_page, $results_per_page = 5)
	{
		$this->id = $search_id;

		if (!$current_page || $current_page < 0)
			$this->page = 1;
		else
			$this->page = $current_page;
		$this->results_per_page = $results_per_page;

		$this->r = new ReferenceManager();
		$this->num_results = $this->r->GetNumHits($this->id);
		$this->total_pages = ceil($this->num_results 
			/ $this->results_per_page);
	}

	function print_paged_results ()
	{
		// Display results here
		$start = ($this->page - 1) * $this->results_per_page;

		$reference_ids = array();
		$reference_ids = $this->r->GetHits ($this->id, $start, $this->results_per_page);

		echo "<table>";
		for ($i=0; $i < sizeof($reference_ids); $i++)
		{
			$r = new Reference();
			echo $r->GetFormattedReference ($reference_ids[$i]);
		}	
		echo "</table>";

		
		//echo $start, "|", $end;
	}


	function print_navigation()
	{
		global $PHP_SELF;

		echo "<div >";

		if (1)
		{
				echo "<table width=\"100%\"><tr>";

				echo "<td align=\"left\">";
			
				$start = ($this->page - 1) * $this->results_per_page + 1;
				$end = $start + $this->results_per_page-1;
				if ($end >= $this->num_results) { $end = $this->num_results; }
				echo "Items " . $start . "-" . $end . " of " . $this->num_results;

					echo "</td>";

			
			if ($this->total_pages > 0) // fix
			{

				echo "<td align=\"right\">";

				echo "<table><tr>";

				if ($this->page > 1)
				{
					// Prints link to goto the previous page
						echo "<td valign=\"middle\"><a href=\"" . $PHP_SELF . "?search_id=" . $this->id
						 . "&amp;page=" . ($this->page - 1) . "\"" 
						 . " title = \"Previous page\">Previous</a></td>";
				}
				echo "<td>";			
				echo "<form name=\"page\" id=\"page\" method=\"get\" action=\"" . $PHP_SELF . "\" onsubmit=\"return validatePageForm(this, " . $this->page, ", " . $this->total_pages. ")\">";
				echo "<input type=\"hidden\" name=\"search_id\" value=\"" . $this->id . "\" />";

				echo "<input type=\"submit\" name=\"Submit\" value=\"Page\" />";
  			echo "<input name=\"page\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"" . $this->page . "\" />";
	  		echo "<label> of " . $this->total_pages . "</label>";
	  		echo "</form>";
				echo "</td>";				
					
			if ($this->page != $this->total_pages)
			{
				// Link for next page (not on last page)
				echo "<td middle=\"top\"><a href=\"" . $PHP_SELF . "?search_id=" . $this->id
				 . "&amp;page=" . ($this->page + 1) . "\"" 
				 . " title = \"Go to next page\">Next</a></td>";
			}
			echo "</tr></table>";

			echo "</td>";



			}

			echo "</tr></table>";
		}
		else
		{
			// Previous code << 1 2 3 4 >>, which breaks if there are a lot of
			// search results.
		for ($i = 1; $i <= $this->total_pages; $i++)
		{
			if ($i == 1 && $this->page > 1)
			{
				// Prints the << first to goto the previous page
				echo "<a href=\"" . $PHP_SELF . "?search_id=" . $this->id
				 . "&amp;page=" . ($this->page - 1) . "\"" 
				 . " title = \"Previous page\">&#0171;</a>&nbsp;";
			}
			if ($i == $this->page)
			{
				// Don't make a link, just display page number
				echo "&nbsp;$i&nbsp;";
			}
			if ($i != $this->page)
			{
				// Link to another page
				echo "&nbsp;<a href=\"" . $PHP_SELF . "?search_id=" . $this->id
				 . "&amp;page=" . $i . "\"" 
				 . " title = \"Go to page $i\">$i</a>&nbsp;";
			}
			if ($i == $this->total_pages && $this->page != $this->total_pages)
			{
				// Link for next page >> (not on last page)
				echo "<a href=\"" . $PHP_SELF . "?search_id=" . $this->id
				 . "&amp;page=" . ($this->page + 1) . "\"" 
				 . " title = \"Go to next page\">&#0187;</a>&nbsp;";
			}
		}
		}
		echo "</div>";
	}

}

//echo $_GET['search_id'], "|", $_GET['page'];


$p = new Pager ($_GET['search_id'], $_GET['page']);


$p->print_navigation();
$p->print_paged_results();
$p->print_navigation();


?>

</div> 

<?php include ('footer.inc.php'); ?>


</body>
</html>
Return current item: MyPHPBib