if (!has_capability('mod/netpublish:editarticle', $context)) {
    echo 'false';
    exit;
}
$permissions = get_record_sql("SELECT id, userid, rights\n                                   FROM {$CFG->prefix}netpublish_articles\n                                   WHERE id = {$articleid}");
if (has_capability('moodle/legacy:teacher', get_context_instance(CONTEXT_COURSE, $course->id))) {
    $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_unset_lock($articleid)) {
            echo 'OK';
        } else {
            echo 'false';
        }
    } else {
        echo 'false';
    }
} else {
    echo 'false';
}
             }
         }
         if ($article->nextarticle != 0) {
             if (!set_field('netpublish_articles', 'prevarticle', $article->prevarticle, 'id', $article->nextarticle)) {
                 error("Could not move article!");
             }
         }
         $data->prevarticle = 0;
         $data->nextarticle = 0;
     }
 }
 if (!update_record("netpublish_articles", $data)) {
     error("Couldn't update article {$data->title}", $CFG->wwwroot . "/mod/netpublish/view.php?id={$cm->id}");
 }
 if (!empty($mod->locktime)) {
     netpublish_unset_lock($data->id);
 }
 // Statuscounter stuff
 if (!empty($mod->statuscount)) {
     // Get current status
     $statcount = get_record("netpublish_status_records", "articleid", $data->id);
     if (!empty($statcount)) {
         $mod->statuscount = (int) $mod->statuscount;
         $statcount->counter = (int) $statcount->counter;
         $statcount->statusid = (int) $statcount->statusid;
         if (!has_capability('mod/netpublish:changestatus', $context)) {
             if ($mod->statuscount > $statcount->counter) {
                 $statcount->counter++;
             } else {
                 if ($mod->statuscount <= $statcount->counter) {
                     $statcount->counter = 0;