function batchDisplayMenu( $link_location, $current_page, $total_batch_size, $batch_step_size, $extra_get_params=array(), $menu_properties=array() )
{
/// display options
$display_all_pages = FALSE;
$page_display_range = 4;
$show_total_pages = TRUE;
$show_ellipses = TRUE;
$show_next = TRUE;
$show_previous = TRUE;
$show_last = TRUE;
$show_first = TRUE;
/// format templates for displaying menu
$total_pages_format_string = "%s results in %s page(s) : ";
$ellipse_format_string = "...";
$no_ellipse_format_string = " ";
$next_format_string = ">>";
$previous_format_string = "<<";
$first_format_string = "first";
$last_format_string = "last";
$current_page_format_string = "<b>%s</b>";
$blank_page_format_string = "  ";
$width = 20;
/// this should overwrite any previous variables
extract($menu_properties);
/// display ranges for pages
$total_pages = ceil( $total_batch_size / $batch_step_size );
$page_range_begin = max( ($current_page-$page_display_range), 1 );
$page_range_span = ($page_display_range*2);
$page_range_end = ($page_range_begin+$page_range_span);
/// pass along, via GET, anything in the extra_get_params array, when a user clicks on new page of results to view
$link_format_string = "<a href=\"{$link_location}?current_page=%s&batch_step_size={$batch_step_size}&total_batch_size={$total_batch_size}";
foreach ( $extra_get_params as $item=>$value ) {
$safe_value = str_replace( '%', '%%', urlencode($value) );
$link_format_string .= "&{$item}={$safe_value}";
}
$link_format_string .= "\">%s</a>";
/// show the X out of Y page results
if ( $show_total_pages ) {
$string .= '<center>';
$string .= sprintf($total_pages_format_string,$total_batch_size,$total_pages);
$string .= '</center>';
}
$string .= '<table border="0" class="batch_list"><tr align="center">';
$string .= '<td nowrap="nowrap">';
/// show link to jump to first page
if ( $show_first ) {
if ( $current_page > 1 ) {
$string .= sprintf($link_format_string,1,$first_format_string) ." ";
} else {
$string .= $first_format_string ." ";
}
}
/// show link to go back one page
if ( $show_previous ) {
if ( $current_page > 1 ) {
$string .= sprintf($link_format_string,max(($current_page-1),1),$previous_format_string) ." ";
} else {
$string .= $previous_format_string ." ";
}
}
/// to ellipse or not ellipse
$string .= ( $show_ellipses and $page_range_begin>1 ) ? sprintf($ellipse_format_string)." " : sprintf($no_ellipse_format_string)." ";
$string .= '</td>';
/// show either all pages on screen at once, or show only X at a time, like google, a batch of batch pages :)
if ( $display_all_pages ) {
$link_range = range( 1, $total_pages );
} else{
$link_range = range( $page_range_begin, $page_range_end );
}
/// them meat, show a link to each page of items we have
foreach ( $link_range as $index ) {
$string .= '<td width="'.$width.'" nowrap="nowrap">';
if ( $index == $current_page ) {
$string .= sprintf($current_page_format_string,$index) ." ";
} elseif ( $index <= $total_pages ) {
$string .= sprintf($link_format_string,$index,$index) ." ";
} elseif ( $index > $total_pages ) {
$string .= $blank_page_format_string ." ";
}
$string .= '</td>';
}
$string .= '<td nowrap="nowrap">';
$string .= ( $show_ellipses and $page_range_end<$total_pages ) ? $ellipse_format_string ." " : $no_ellipse_format_string ." ";
/// show a link to skip foreward on epage
if ( $show_next ) {
if ( $current_page < $total_pages ) {
$string .= sprintf($link_format_string,min(($current_page+1),$total_pages),$next_format_string) ." ";
} else {
$string .= $next_format_string ." ";
}
}
/// show a link to the last page
if ( $show_last ) {
if ( $current_page < $total_pages ){
$string .= sprintf($link_format_string,$total_pages,$last_format_string) ." ";
} else {
$string .= $last_format_string ." ";
}
}
$string .= '</td>';
$string .= '</tr></table>';
return $string;
}