}
    if (!($cm = get_coursemodule_from_instance("netpublish", $mod->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
}
require_login($course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$isteacher = has_capability('moodle/legacy:teacher', get_context_instance(CONTEXT_COURSE, $course->id));
$isguest = has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM, SITEID), $USER->id, false);
$npsections = netpublish_count_sections($mod->id);
if (empty($npsections)) {
    if ($isteacher) {
        netpublish_create_first_section($mod->id);
        redirect("sections.php?id={$cm->id}");
    } else {
        netpublish_create_first_section($mod->id);
    }
}
if (!empty($article)) {
    $strtolog = get_string("articleview", "netpublish");
    add_to_log($course->id, "netpublish", $strtolog, "view.php?id={$cm->id}&section={$section}&article={$article}", "{$mod->name}");
} else {
    add_to_log($course->id, "netpublish", "view", "view.php?id={$cm->id}", "{$mod->name}");
}
/// Print the page header
if ($course->category) {
    $navigation = "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->";
}
// Get strings
$strnetpublishes = get_string("modulenameplural", "netpublish");
$strnetpublish = get_string("modulename", "netpublish");
function netpublish_print_section_list($instance, $name, $toplevel = true, $selected = "")
{
    /// this function need to be recursive
    /// D'oh
    ///
    $sections = netpublish_get_sections($instance);
    // There is only main section so make it
    // visible to students also.
    if (empty($sections)) {
        $toplevel = true;
    }
    $frontpageid = !empty($sections) && !empty($sections[key($sections)]->frontpageid) ? $sections[key($sections)]->frontpageid : netpublish_create_first_section($instance);
    $frontpagename = !empty($sections) && !empty($sections[key($sections)]->frontpagename) ? $sections[key($sections)]->frontpagename : (!($frontpage = get_record("netpublish_first_section_names", "publishid", $instance)) ? get_string("frontpage", "netpublish") : $frontpage->name);
    if (empty($name)) {
        $name = "parentid";
    }
    if (!empty($frontpageid)) {
        printf("<input type=\"hidden\" name=\"frontpageid\" value=\"%d\" />\n", $frontpageid);
    }
    printf("<select id=\"%s\" name=\"%s\">\n", $name, $name);
    if ($toplevel) {
        printf("\t<option value=\"0\">%s</option>\n", $frontpagename);
    }
    if (!empty($sections)) {
        netpublish_section_options(0, $sections, $selected);
    }
    print "</select>\n";
}