/**
  * Checks to see if the page has the proper
  * display value to be included into the menu
  * rendering.
  *
  * The page must be pusblished and be set to display
  * in the course menu and not be locked with a
  * non-visible lock.
  *
  * @param object $page Page object
  * @return boolean
  **/
 protected function dont_display($page)
 {
     if (DISP_MENU & $page->display and DISP_PUBLISH & $page->display and !(page_is_locked($page) and !page_is_visible_lock($page))) {
         return false;
     }
     return true;
 }
/**
 * This function returns the page objects of the next/previous pages
 * relative to the passed page ID
 *
 * @param int $pageid Base next/previous off of this page ID
 * @param int $courseid (Optional) ID of the course
 */
function page_get_next_previous_pages($pageid, $courseid = NULL)
{
    global $COURSE;
    if ($courseid === NULL) {
        $courseid = $COURSE->id;
    }
    $return = new stdClass();
    $return->prev = false;
    $return->next = false;
    if ($pages = page_get_all_pages($courseid, 'flat')) {
        // Remove any unpublished pages
        foreach ($pages as $id => $page) {
            if (!($page->display & DISP_PUBLISH)) {
                unset($pages[$id]);
            }
        }
        if (!empty($pages)) {
            // Search for the pages
            $get = false;
            $locked = array();
            foreach ($pages as $id => $page) {
                if (in_array($page->parent, $locked) or page_is_locked($page) and !page_is_visible_lock($page)) {
                    $locked[] = $page->id;
                }
                if ($get and !in_array($page->id, $locked)) {
                    // We have seen the id we're looking for
                    $return->next = $page;
                    break;
                    // quit this business
                }
                if ($id == $pageid) {
                    // We've found the id that we are looking for
                    $get = true;
                }
                if (!$get and !in_array($page->id, $locked)) {
                    // Only if we haven't found what we're looking for
                    $return->prev = $page;
                }
            }
        }
    }
    return $return;
}