Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  
   3  require_once('../../config.php');
   4  require_once ('lib.php');
   5  require_once ('edit_form.php');
   6  
   7  $cmid = required_param('cmid', PARAM_INT);            // Course Module ID
   8  $id   = optional_param('id', 0, PARAM_INT);           // EntryID
   9  
  10  if (!$cm = get_coursemodule_from_id('glossary', $cmid)) {
  11      print_error('invalidcoursemodule');
  12  }
  13  
  14  if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
  15      print_error('coursemisconf');
  16  }
  17  
  18  require_login($course, false, $cm);
  19  
  20  $context = context_module::instance($cm->id);
  21  
  22  if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
  23      print_error('invalidid', 'glossary');
  24  }
  25  
  26  $url = new moodle_url('/mod/glossary/edit.php', array('cmid'=>$cm->id));
  27  if (!empty($id)) {
  28      $url->param('id', $id);
  29  }
  30  $PAGE->set_url($url);
  31  
  32  if ($id) { // if entry is specified
  33      if (isguestuser()) {
  34          print_error('guestnoedit', 'glossary', "$CFG->wwwroot/mod/glossary/view.php?id=$cmid");
  35      }
  36  
  37      if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id, 'glossaryid'=>$glossary->id))) {
  38          print_error('invalidentry');
  39      }
  40  
  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);
  45  
  46  } else { // new entry
  47      require_capability('mod/glossary:write', $context);
  48      // note: guest user does not have any write capability
  49      $entry = new stdClass();
  50      $entry->id = null;
  51  }
  52  
  53  list($definitionoptions, $attachmentoptions) = glossary_get_editor_and_attachment_options($course, $context, $entry);
  54  
  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);
  57  
  58  $entry->cmid = $cm->id;
  59  
  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));
  63  
  64  if ($mform->is_cancelled()){
  65      if ($id){
  66          redirect("view.php?id=$cm->id&mode=entry&hook=$id");
  67      } else {
  68          redirect("view.php?id=$cm->id");
  69      }
  70  
  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);
  75      }
  76      redirect("view.php?id=$cm->id&mode=entry&hook=$entry->id");
  77  }
  78  
  79  if (!empty($id)) {
  80      $PAGE->navbar->add(get_string('edit'));
  81  }
  82  
  83  $PAGE->set_title($glossary->name);
  84  $PAGE->set_heading($course->fullname);
  85  echo $OUTPUT->header();
  86  echo $OUTPUT->heading(format_string($glossary->name), 2);
  87  if ($glossary->intro) {
  88      echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro');
  89  }
  90  
  91  $data = new StdClass();
  92  $data->tags = core_tag_tag::get_item_tags_array('mod_glossary', 'glossary_entries', $id);
  93  $mform->set_data($data);
  94  
  95  $mform->display();
  96  
  97  echo $OUTPUT->footer();
  98