} $simplehtml = new nsreas_form(null, array('itemid' => $iditem, 'contextid' => $contextid)); $toform['blockid'] = $blockid; $toform['courseid'] = $courseid; $toform['component'] = $component; $toform['id'] = $id; $toform['status'] = 1; $toform['context_id'] = $contextid; $simplehtml->set_data($toform); $url = new moodle_url('/course/view.php', array('id' => $courseid)); if ($simplehtml->is_cancelled()) { redirect($url); } else { if ($simplehtml->get_data()) { $fromform = $simplehtml->get_data(); $name = $simplehtml->get_new_filename('attachment'); $simplehtml->save_stored_file('attachment', $contextid, 'block_nsreas', 'draft', $iditem, '/', $name, true, $USER->id); $fromform->file_name = $name; $fromform->item_id = $iditem; $fromform->context_id = $contextid; if ($fromform->linkurl != null) { if (strpos($fromform->linkurl, 'http') === false) { //print_object(strpos($fromform->linkurl, 'http')); $fromform->linkurl = 'http://' . $fromform->linkurl; } } //------------------ if ($fromform->id != 0) { $fs = get_file_storage(); $oldentry = $DB->get_record('block_nsreas', array('id' => $fromform->id)); // Prepare file record object