3 require_once('../../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
7 $cmid = required_param('cmid', PARAM_INT
); // Course Module ID
8 $id = optional_param('id', 0, PARAM_INT
); // EntryID
10 if (!$cm = get_coursemodule_from_id('glossary', $cmid)) {
11 throw new \
moodle_exception('invalidcoursemodule');
14 if (!$course = $DB->get_record('course', array('id'=>$cm->course
))) {
15 throw new \
moodle_exception('coursemisconf');
18 require_login($course, false, $cm);
20 $context = context_module
::instance($cm->id
);
22 if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance
))) {
23 throw new \
moodle_exception('invalidid', 'glossary');
26 $url = new moodle_url('/mod/glossary/edit.php', array('cmid'=>$cm->id
));
28 $url->param('id', $id);
32 if ($id) { // if entry is specified
34 throw new \
moodle_exception('guestnoedit', 'glossary', "$CFG->wwwroot/mod/glossary/view.php?id=$cmid");
37 if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id, 'glossaryid'=>$glossary->id
))) {
38 throw new \
moodle_exception('invalidentry');
41 // Check if the user can update the entry (trigger exception if he can't).
42 mod_glossary_can_update_entry($entry, $glossary, $context, $cm, false);
43 // Prepare extra data.
44 $entry = mod_glossary_prepare_entry_for_edition($entry);
47 require_capability('mod/glossary:write', $context);
48 // note: guest user does not have any write capability
49 $entry = new stdClass();
53 list($definitionoptions, $attachmentoptions) = glossary_get_editor_and_attachment_options($course, $context, $entry);
55 $entry = file_prepare_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry', $entry->id
);
56 $entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary', 'attachment', $entry->id
);
58 $entry->cmid
= $cm->id
;
60 // create form and set initial data
61 $mform = new mod_glossary_entry_form(null, array('current'=>$entry, 'cm'=>$cm, 'glossary'=>$glossary,
62 'definitionoptions'=>$definitionoptions, 'attachmentoptions'=>$attachmentoptions));
64 if ($mform->is_cancelled()){
66 redirect("view.php?id=$cm->id&mode=entry&hook=$id");
68 redirect("view.php?id=$cm->id");
71 } else if ($data = $mform->get_data()) {
72 $entry = glossary_edit_entry($data, $course, $cm, $glossary, $context);
73 if (core_tag_tag
::is_enabled('mod_glossary', 'glossary_entries') && isset($data->tags
)) {
74 core_tag_tag
::set_item_tags('mod_glossary', 'glossary_entries', $data->id
, $context, $data->tags
);
76 redirect("view.php?id=$cm->id&mode=entry&hook=$entry->id");
80 $PAGE->navbar
->add(get_string('edit'));
83 $PAGE->set_title($glossary->name
);
84 $PAGE->set_heading($course->fullname
);
85 $PAGE->set_secondary_active_tab('modulepage');
86 $PAGE->activityheader
->set_attrs([
87 'hidecompletion' => true,
90 echo $OUTPUT->header();
92 echo $OUTPUT->heading(get_string('addsingleentry', 'mod_glossary'));
94 echo $OUTPUT->heading(get_string('editentry', 'mod_glossary'));
97 $data = new StdClass();
98 $data->tags
= core_tag_tag
::get_item_tags_array('mod_glossary', 'glossary_entries', $id);
99 $mform->set_data($data);
103 echo $OUTPUT->footer();