$data->timepublished = time();
 }
 if (!empty($data->authors)) {
     $authorids = explode(",", $data->authors);
     $authorstmp = array();
     foreach ($authorids as $authorid) {
         $authorid = clean_param($authorid, PARAM_INT);
         array_push($authorstmp, $authorid);
     }
     $data->authors = implode(",", $authorstmp);
     unset($authorids, $authorstmp);
 }
 // Clean user input
 $data = netpublish_clean_userinput($data);
 $data->timemodified = time();
 $data->rights = !empty($data->rights) ? netpublish_set_rights($data->rights) : '';
 $article = get_record('netpublish_articles', 'id', $articleid);
 if ($data->statusid == 4 and $article->statusid != 4) {
     // getting published, put it at the end of the list
     if ($lastarticle = netpublish_get_last_article($article->sectionid, $mod->id)) {
         $data->prevarticle = $lastarticle->id;
         if (!set_field('netpublish_articles', 'nextarticle', $articleid, 'id', $lastarticle->id)) {
             error("Could not move article!");
         }
     } else {
         $data->prevarticle = 0;
     }
     $data->nextarticle = 0;
 } else {
     if ($data->statusid != 4 and $article->statusid == 4) {
         // removing article from publish status
     error("Session error!", sprintf("%s/mod/netpublish/view.php?id=%d", $CFG->wwwroot, $cm->id));
 }
 if (intval($form->publishid) != intval($cm->instance)) {
     error("You cannot add article in other netpublish instance!", sprintf("%s/mod/netpublish/view.php?id=%d", $CFG->wwwroot, $cm->id));
 }
 $cm->id = clean_param($form->id, PARAM_INT);
 $form->id = '';
 // Check and clean user input
 $form = netpublish_clean_userinput($form);
 // Atleast there must be a title for this article
 if (strlen($form->title) < 3) {
     $err['missingtitle'] = get_string("missingtitle", "netpublish");
 }
 $form->timecreated = time();
 $form->timemodified = time();
 $form->rights = !empty($form->rights) ? netpublish_set_rights($form->rights) : '';
 // add this article to the end of the linked list
 if ($form->statusid == 4 and $lastarticle = netpublish_get_last_article($form->sectionid, $mod->id)) {
     $form->prevarticle = $lastarticle->id;
 } else {
     $form->prevarticle = 0;
 }
 $form->nextarticle = 0;
 if (has_capability('mod/netpublish:changestatus', $context)) {
     // Test publish status if author is a teacher.
     if ($form->statusid == 4 && empty($form->timepublished)) {
         $form->timepublished = time();
     }
 }
 if (empty($err)) {
     if (!($id = insert_record("netpublish_articles", $form))) {