diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-09-24 17:22:38 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-09-24 17:22:38 +0000 |
commit | ab076e07058f75de17cfdbe311d35753f9da7b43 (patch) | |
tree | 2b67d2bf550901db2bdff3835bc126865145bed2 | |
parent | aa16b0a34a4713e0b215746bd4a2c4ba02c1f2c0 (diff) | |
download | ampache-ab076e07058f75de17cfdbe311d35753f9da7b43.tar.gz ampache-ab076e07058f75de17cfdbe311d35753f9da7b43.tar.bz2 ampache-ab076e07058f75de17cfdbe311d35753f9da7b43.zip |
changelog dont lie, truth change... list header stuff actually exists now
-rw-r--r-- | templates/default.css | 9 | ||||
-rw-r--r-- | templates/list_header.inc | 164 |
2 files changed, 122 insertions, 51 deletions
diff --git a/templates/default.css b/templates/default.css index d94cd4f0..5939425a 100644 --- a/templates/default.css +++ b/templates/default.css @@ -535,6 +535,15 @@ li.current-rating{ .box-top { background: url(../themes/classic/images/top.gif); } +/* List Header Styles */ +.list-header { + text-decoration: none; +} +.list-header:hover { + color:#071fd4; +} + + .confirmation-box { padding-left:5px; padding-top:5px; diff --git a/templates/list_header.inc b/templates/list_header.inc index 793e1703..7be4ca35 100644 --- a/templates/list_header.inc +++ b/templates/list_header.inc @@ -20,40 +20,75 @@ */ -/*! - @header - The default pager widget for moving through a list of many items. +/** + * List Header + * The default pager widget for moving through a list of many items. + * This relies heavily on the View object to get pieces about how + * to layout this page. + */ - This relies heavily on the View object to get pieces about how - to layout this page. +/* We must have Some Items, if none passed use sesison information */ +if (!$total_items) { $total_items = $_SESSION['view_total_items']; } -*/ -if (!$total_items) { $total_items = $_SESSION['view_total_items']; } -// do some math here -if ($GLOBALS['view']->offset >= $GLOBALS['view']->offset_limit) { - $offset2 = $GLOBALS['view']->offset - 25; -} -else { - $offset2 = $GLOBALS['view']->offset; - if (!$GLOBALS['view']->offset) { $offset2 = "0"; } -} +/* Calculate the Next/Prev Pages */ + +// Next +$next_offset = $GLOBALS['view']->offset + $GLOBALS['view']->offset_limit; +if ($next_offset > $total_items) { $next_offset = $GLOBALS['view']->offset; } -// Get the prev page offset -$offset1 = $GLOBALS['view']->offset - $GLOBALS['view']->offset_limit; -if ($offset1 < 1) { $offset1 = 0; } +// Prev +$prev_offset = $GLOBALS['view']->offset - $GLOBALS['view']->offset_limit; +if ($prev_offset < 0) { $prev_offset = '0'; } -// since we have an array of objects, let's build a purdy thingie +/* Calculate how many pages total exist */ $pages = ceil($total_items/$GLOBALS['view']->offset_limit); -$offset4 = ($pages - 1); -$offset4 = ($offset4 * $GLOBALS['view']->offset_limit); -//We do this one last to make sure we don't go beyond offset4 -$offset3 = $GLOBALS['view']->offset + $GLOBALS['view']->offset_limit; -if ($offset3 >= $offset4) { $offset3 = $offset4; } +/* Calculate current page and how many we have on each side */ +$page_data = array(); +// Can't Divide by 0 +if ($GLOBALS['view']->offset > 0) { + $current_page = floor($GLOBALS['view']->offset/$GLOBALS['view']->offset_limit); +} +else { + $current_page = 0; +} + +/* Create 10 pages in either direction */ +// Down First +$page = $current_page; +$i = 0; +/* While we have pages left */ +while ($page > 0) { + if ($i == '15') { $page_data['down'][1] = '...'; $page_data['down'][0] = '0'; break; } + $i++; + $page = $page - 1; + $page_data['down'][$page] = $page * $GLOBALS['view']->offset_limit; +} // while page > 0 -//setup the next action +// Up Next +$page = $current_page+1; +$i = 0; +/* While we have pages left */ +while ($page <= $pages) { + if ($page * $GLOBALS['view']->offset_limit > $total_items) { break; } + if ($i == '15') { + $key = $pages - 1; + if (!$page_data['up'][$key]) { $page_data['up'][$key] = '...'; } + $page_data['up'][$pages] = ($pages-1) * $GLOBALS['view']->offset_limit; + break; + } + $i++; + $page = $page + 1; + $page_data['up'][$page] = ($page-1) * $GLOBALS['view']->offset_limit; +} // end while + +// Sort These Arrays of Hotness +ksort($page_data['up']); +ksort($page_data['down']); + +/* Take the script name and passed action and setup the next action */ preg_match("/.*\/(.+\.php)$/", $_SERVER['SCRIPT_NAME'], $matches); $action = "action=" . scrub_in($_REQUEST['action']); $script = conf('web_path') . "/" . $admin_menu . $matches[1]; @@ -61,32 +96,59 @@ $script = conf('web_path') . "/" . $admin_menu . $matches[1]; // are there enough items to even need this view? if (($pages > 1) && ($_SESSION['view_script'])) { ?> - <table border="0" cellpadding="2" cellspacing="0" width="100%"> - <tr> - <td align="center" valign="top"> - <a href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $offset1; ?>&keep_view=true">[ <?php echo _("Prev"); ?> ]</a> - </td> - <td align="center"> - <?php - $counter = 1; - $offset_pages = 0; - while ($counter <= $pages) { - if ($GLOBALS['view']->offset == $offset_pages) { - ?> <a href="<?php echo $script; ?>?<?php echo $action ; ?>&sort_type=<?php echo $GLOBALS['view']->sort_type ; ?>&offset=<?php echo $offset_pages ; ?>&keep_view=true"><b><?php echo $counter; ?></b></a> - <?php - } else { ?> - <a href="<?php echo $script; ?>?<?php echo $action; ?>&sort_type=<?php echo $GLOBALS['view']->sort_type; ?>&offset=<?php echo $offset_pages; ?>&keep_view=true"><?php echo $counter; ?></a> - <?php - } // end if ($GLOBALS['view']->offset == $offset_pages) and else - $offset_pages += $GLOBALS['view']->offset_limit; - $counter++; - } // end while ($counter <= $pages) ?> - </td> - <td align="center" valign="top"> - <a href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $offset3; ?>&keep_view=true">[ <?php echo _("Next"); ?> ]</a> - </td> - </tr> - </table> +<table cellpadding="1" cellspacing="0" width="100%"> +<tr> + <td valign="top"> + <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $prev_offset; ?>&keep_view=true">[<?php echo _('Prev'); ?>]</a> + </td> + <td align="center"> + <?php + /* Echo Everything below us */ + foreach ($page_data['down'] as $page => $offset) { + if ($offset === '...') { echo '... '; } + else { + // Hack Alert + $page++; + ?> + <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&sort_type=<?php echo $GLOBALS['view']->sort_type; ?>&offset=<?php echo $offset; ?>&keep_view=true"><?php echo $page; ?></a> + <?php + } + } // end foreach down + + /* Echo Out current Page */ + $current_page = $current_page +1; + ?> + <span class="list-header"><strong><?php echo $current_page; ?></strong></span> + <?php + + /* Echo Out Everything Above Us */ + foreach ($page_data['up'] as $page=>$offset) { + if ($offset === '...') { echo '... '; } + else { + ?> + <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&sort_type=<?php echo $GLOBALS['view']->sort_type; ?>&offset=<?php echo $offset; ?>&keep_view=true"><?php echo $page; ?></a> + <?php + } // end else + } // end foreach up + /* + $counter = 1; + $offset_pages = 0; + while ($counter <= $pages) { + if ($GLOBALS['view']->offset == $offset_pages) { ?> + <?php } else { ?> + <?php + } // end if ($GLOBALS['view']->offset == $offset_pages) and else + $offset_pages += $GLOBALS['view']->offset_limit; + $counter++; + } // end while ($counter <= $pages) + */ + ?> + </td> + <td valign="top"> + <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $next_offset; ?>&keep_view=true">[<?php echo _('Next'); ?>]</a> + </td> +</tr> +</table> <?php } // if (($pages > 1) && ($_SESSION['view_script'])) ?> |