Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/erikdubbelboer/phpRedisAdmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Dubbelboer <erik@dubbelboer.com>2013-07-26 17:25:37 +0400
committerErik Dubbelboer <erik@dubbelboer.com>2013-07-26 17:25:37 +0400
commit907acc80086f50060147cd8e8d8dc134ce59c5dc (patch)
tree477c247a8874ae43a8979a822867f653973c47c0 /view.php
parent7e603a5feaf45ed5824d0c93e3221cbf9130e298 (diff)
Added list support to pagination
Diffstat (limited to 'view.php')
-rw-r--r--view.php74
1 files changed, 41 insertions, 33 deletions
diff --git a/view.php b/view.php
index e814e3f..a93d76c 100644
--- a/view.php
+++ b/view.php
@@ -2,10 +2,6 @@
require_once 'includes/common.inc.php';
-$count_elements_page = isset($config['count_elements_page']) ? $config['count_elements_page'] : false;
-$page_num_request = isset($_GET['page']) ? (int)$_GET['page'] : 1;
-$page_num_request = $page_num_request === 0 ? 1 : $page_num_request;
-
$page['css'][] = 'frame';
$page['js'][] = 'frame';
@@ -27,6 +23,11 @@ if (!isset($_GET['key'])) {
$type = $redis->type($_GET['key']);
$exists = $redis->exists($_GET['key']);
+$count_elements_page = isset($config['count_elements_page']) ? $config['count_elements_page'] : false;
+$page_num_request = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+$page_num_request = $page_num_request === 0 ? 1 : $page_num_request;
+
+
?>
<h2><?php echo format_html($_GET['key'])?>
@@ -68,9 +69,6 @@ switch ($type) {
case 'hash':
$values = $redis->hGetAll($_GET['key']);
$size = count($values);
- if($count_elements_page !== false) {
- $values = array_slice($values, $count_elements_page*($page_num_request-1), $count_elements_page);
- }
break;
case 'list':
@@ -80,20 +78,17 @@ switch ($type) {
case 'set':
$values = $redis->sMembers($_GET['key']);
$size = count($values);
- if($count_elements_page !== false) {
- $values = array_slice($values, $count_elements_page*($page_num_request-1), $count_elements_page);
- }
break;
case 'zset':
$values = $redis->zRange($_GET['key'], 0, -1);
$size = count($values);
- if($count_elements_page !== false) {
- $values = array_slice($values, $count_elements_page*($page_num_request-1), $count_elements_page);
- }
break;
}
-
+
+if (isset($values) && ($count_elements_page !== false)) {
+ $values = array_slice($values, $count_elements_page * ($page_num_request - 1), $count_elements_page);
+}
?>
<table>
@@ -113,27 +108,31 @@ switch ($type) {
<p>
<?php
-$pagging = '';
-// make pagging div
-if($count_elements_page !== false && in_array($type, array('hash', 'set', 'zset')) && $size > $count_elements_page) {
- $pagging .= '<div style="width: inherit; word-wrap: break-word;">';
- $url = preg_replace('/&page=(\d+)/i', '', $_SERVER['REQUEST_URI']);
- for ($i = 0; $i < ceil($size/$count_elements_page); ++$i) {
- $page_num = $i+1;
- if($page_num === $page_num_request) {
- $pagging .= $page_num.'&nbsp;';
- }
- else {
- $pagging .= '<a href="'.$url.'&page='.$page_num.'">'.$page_num."</a>&nbsp;";
+
+// Build pagination div.
+if (($count_elements_page !== false) && in_array($type, array('hash', 'list', 'set', 'zset')) && ($size > $count_elements_page)) {
+ $pagination = '<div style="width: inherit; word-wrap: break-word;">';
+ $url = preg_replace('/&page=(\d+)/i', '', $_SERVER['REQUEST_URI']);
+
+ for ($i = 0; $i < ceil($size / $count_elements_page); ++$i) {
+ $page_num = $i + 1;
+
+ if ($page_num === $page_num_request) {
+ $pagination .= $page_num . '&nbsp;';
+ } else {
+ $pagination .= '<a href="' . $url . '&page=' . $page_num . '">' . $page_num . "</a>&nbsp;";
}
}
- $pagging .= '</div>';
+
+ $pagination .= '</div>';
}
-if(!empty($pagging)) {
- echo $pagging;
+
+if (isset($pagination)) {
+ echo $pagination;
}
+
// String
if ($type == 'string') { ?>
@@ -172,8 +171,17 @@ else if ($type == 'list') { ?>
<table>
<tr><th><div>Index</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
-<?php for ($i = 0; $i < $size; ++$i) {
- $value = $redis->lIndex($_GET['key'], $i);
+<?php
+ if (($count_elements_page === false) && ($size > $count_elements_page)) {
+ $start = 0;
+ $end = $size;
+ } else {
+ $start = $count_elements_page * ($page_num_request - 1);
+ $end = min($start + $count_elements_page, $size);
+ }
+
+ for ($i = $start; $i < $end; ++$i) {
+ $value = $redis->lIndex($_GET['key'], $i);
?>
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
@@ -233,8 +241,8 @@ if ($type != 'string') { ?>
</p>
<?php }
-if(!empty($pagging)) {
- echo $pagging;
+if (isset($pagination)) {
+ echo $pagination;
}
require 'includes/footer.inc.php';