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  
   6  $id       = required_param('id', PARAM_INT);          // course module ID
   7  $confirm  = optional_param('confirm', 0, PARAM_INT);  // commit the operation?
   8  $entry    = optional_param('entry', 0, PARAM_INT);    // entry id
   9  $prevmode = required_param('prevmode', PARAM_ALPHA);
  10  $hook     = optional_param('hook', '', PARAM_CLEAN);
  11  
  12  $url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode));
  13  if ($confirm !== 0) {
  14      $url->param('confirm', $confirm);
  15  }
  16  if ($entry !== 0) {
  17      $url->param('entry', $entry);
  18  }
  19  if ($hook !== '') {
  20      $url->param('hook', $hook);
  21  }
  22  $PAGE->set_url($url);
  23  
  24  $strglossary   = get_string("modulename", "glossary");
  25  $strglossaries = get_string("modulenameplural", "glossary");
  26  $stredit       = get_string("edit");
  27  $entrydeleted  = get_string("entrydeleted","glossary");
  28  
  29  
  30  if (! $cm = get_coursemodule_from_id('glossary', $id)) {
  31      print_error("invalidcoursemodule");
  32  }
  33  
  34  if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  35      print_error('coursemisconf');
  36  }
  37  
  38  if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
  39      print_error('invalidentry');
  40  }
  41  
  42  // Permission checks are based on the course module instance so make sure it is correct.
  43  if ($cm->instance != $entry->glossaryid) {
  44      print_error('invalidentry');
  45  }
  46  
  47  require_login($course, false, $cm);
  48  $context = context_module::instance($cm->id);
  49  
  50  if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
  51      print_error('invalidid', 'glossary');
  52  }
  53  
  54  // Throws an exception if the user cannot delete the entry.
  55  mod_glossary_can_delete_entry($entry, $glossary, $context, false);
  56  
  57  /// If data submitted, then process and store.
  58  
  59  if ($confirm and confirm_sesskey()) { // the operation was confirmed.
  60  
  61      mod_glossary_delete_entry($entry, $glossary, $cm, $context, $course, $hook, $prevmode);
  62      redirect("view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook");
  63  
  64  } else {        // the operation has not been confirmed yet so ask the user to do so
  65      $strareyousuredelete = get_string("areyousuredelete", "glossary");
  66      $PAGE->navbar->add(get_string('delete'));
  67      $PAGE->set_title($glossary->name);
  68      $PAGE->set_heading($course->fullname);
  69      echo $OUTPUT->header();
  70      $areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>";
  71      $linkyes    = 'deleteentry.php';
  72      $linkno     = 'view.php';
  73      $optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
  74      $optionsno  = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
  75  
  76      echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
  77  
  78      echo $OUTPUT->footer();
  79  }