Ver código fonte

fixed bugs in next/previous

Luke Ehresman 25 anos atrás
pai
commit
2d2ced9ec8
1 arquivos alterados com 21 adições e 6 exclusões
  1. 21 6
      src/read_body.php

+ 21 - 6
src/read_body.php

@@ -19,27 +19,42 @@
 
    // returns the index of the next valid message from the array
    function findNextMessage() {
-      global $currentArrayIndex, $msgs;
-      if ($currentArrayIndex < (count($msgs)-1))
-         return $msgs[$currentArrayIndex+1]["ID"];
+      global $msort, $currentArrayIndex, $msgs;
+		for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { 
+   	   if ($currentArrayIndex == $msgs[$key]["ID"]) {
+				next($msort); 
+				$key = key($msort);
+				if (isset($key)) 
+					return $msgs[$key]["ID"];
+			}
+		}
       return -1;
    }
 
    // returns the index of the previous message from the array
    function findPreviousMessage() {
-      global $currentArrayIndex, $msgs;
-      if ($currentArrayIndex > 0)
-         return $msgs[$currentArrayIndex-1]["ID"];
+      global $msort, $currentArrayIndex, $msgs;
+		for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { 
+   	   if ($currentArrayIndex == $msgs[$key]["ID"]) {
+				prev($msort);
+				$key = key($msort);
+				if (isset($key))
+					return $msgs[$key]["ID"];
+			}
+		}
       return -1;
    }
 
    if (isset($msgs)) {
+		$currentArrayIndex = $passed_id;
+		/*
       for ($i=0; $i < count($msgs); $i++) {
          if ($msgs[$i]["ID"] == $passed_id) {
             $currentArrayIndex = $i;
             break;
          }
       }
+		*/
    } else {
       $currentArrayIndex = -1;
    }