if (!$isteacher && !$isstudent) {
    echo 'false';
    exit;
}
$permissions = get_record_sql("SELECT id, userid, rights\n                                   FROM {$CFG->prefix}netpublish_articles\n                                   WHERE id = {$articleid}");
if ($isteacher) {
    $canedit = true;
}
if (!empty($permissions) && intval($permissions->userid) == intval($USER->id)) {
    $canedit = true;
}
if (!empty($permissions) && !empty($permissions[$USER->id]) && $nperm->can_write($permissions[$USER->id])) {
    $canedit = true;
}
if (!$canedit) {
    echo 'false';
    exit;
}
if ($data = data_submitted()) {
    if (confirm_sesskey($skey)) {
        if (netpublish_set_lock($articleid, $USER->id, $publishid)) {
            echo 'OK';
        } else {
            echo 'false';
        }
    } else {
        echo 'false';
    }
} else {
    echo 'false';
}
        } else {
            // Add new record
            $statcount = new stdClass();
            $statcount->articleid = $data->id;
            $statcount->statusid = $data->statusid;
            $statcount->counter = !$isteacher ? 1 : 0;
            insert_record('netpublish_status_records', $statcount);
        }
    }
    $timemessage = 2;
    $streditsuccess = get_string("editsuccessful", "netpublish", stripslashes($data->title));
    redirect($CFG->wwwroot . "/mod/netpublish/view.php?id={$cm->id}", $streditsuccess, $timemessage);
} else {
    // Lock article for editing
    if (!empty($mod->locktime)) {
        if (!netpublish_set_lock($form->id, $USER->id, $form->publishid)) {
            $strerror = get_string('lockingfailed', 'netpublish', $form->title);
            error($strerror, $CFG->wwwroot . '/mod/netpublish/view.php?id=' . $cm->id);
        }
    }
    if (has_capability('moodle/legacy:teacher', get_context_instance(CONTEXT_COURSE, $course->id))) {
        $toplevel = true;
        $publish = true;
    }
    if (!empty($mod->statuscount) && !has_capability('moodle/legacy:teacher', get_context_instance(CONTEXT_COURSE, $course->id))) {
        $statcount = get_record("netpublish_status_records", "articleid", $getthis);
        if (!empty($statcount)) {
            $statcount->statusid = intval($statcount->statusid);
            $statcount->counter = intval($statcount->counter);
            $mod->statuscount = intval($mod->statuscount);
            if ($statcount->statusid < 4 && $statcount->counter < $mod->statuscount) {