Undefined offset: 2

You will have those notices, if either of those $pages indexes are not set. Check for the existence of the key before trying to use it.

if (isset($pages[$current-1])) $prevID = $pages[$current-1];
if (isset($pages[$current+1])) $nextID = $pages[$current+1];

Or something along these lines …

$prevID = (isset($pages[$current-1])) ? $pages[$current-1] : '';
$nextID = (isset($pages[$current+1])) ? $pages[$current+1] : '';

… so that you don’t have other notices later when you try to use those variables.