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 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  
   3  require_once('../../config.php');
   4  require_once ('lib.php');
   5  
   6  $id       = required_param('id', PARAM_INT);          // Entry ID
   7  $confirm  = optional_param('confirm', 0, PARAM_BOOL); // export confirmation
   8  $prevmode = required_param('prevmode', PARAM_ALPHA);
   9  $hook     = optional_param('hook', '', PARAM_CLEAN);
  10  
  11  $url = new moodle_url('/mod/glossary/exportentry.php', array('id'=>$id,'prevmode'=>$prevmode));
  12  if ($confirm !== 0) {
  13      $url->param('confirm', $confirm);
  14  }
  15  if ($hook !== 'ALL') {
  16      $url->param('hook', $hook);
  17  }
  18  $PAGE->set_url($url);
  19  
  20  if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id))) {
  21      print_error('invalidentry');
  22  }
  23  
  24  if ($entry->sourceglossaryid) {
  25      //already exported
  26      if (!$cm = get_coursemodule_from_id('glossary', $entry->sourceglossaryid)) {
  27          print_error('invalidcoursemodule');
  28      }
  29      redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
  30  }
  31  
  32  if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
  33      print_error('invalidcoursemodule');
  34  }
  35  
  36  if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
  37      print_error('invalidid', 'glossary');
  38  }
  39  
  40  if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
  41      print_error('coursemisconf');
  42  }
  43  
  44  require_course_login($course->id, true, $cm);
  45  $context = context_module::instance($cm->id);
  46  require_capability('mod/glossary:export', $context);
  47  
  48  $returnurl = "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=".urlencode($hook);
  49  
  50  if (!$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1))) {
  51      //main glossary not present
  52      redirect($returnurl);
  53  }
  54  
  55  if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) {
  56      print_error('invalidcoursemodule');
  57  }
  58  
  59  $context     = context_module::instance($cm->id);
  60  $maincontext = context_module::instance($maincm->id);
  61  
  62  if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
  63      print_error('coursemisconf');
  64  }
  65  
  66  
  67  $strglossaries     = get_string('modulenameplural', 'glossary');
  68  $entryalreadyexist = get_string('entryalreadyexist','glossary');
  69  $entryexported     = get_string('entryexported','glossary');
  70  
  71  if (!$mainglossary->allowduplicatedentries) {
  72      if ($DB->record_exists_select('glossary_entries',
  73              'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
  74                  'glossaryid' => $mainglossary->id,
  75                  'concept'    => core_text::strtolower($entry->concept)))) {
  76          $PAGE->set_title($glossary->name);
  77          $PAGE->set_heading($course->fullname);
  78          echo $OUTPUT->header();
  79          echo $OUTPUT->notification(get_string('errconceptalreadyexists', 'glossary'));
  80          echo $OUTPUT->continue_button($returnurl);
  81          echo $OUTPUT->box_end();
  82          echo $OUTPUT->footer();
  83          die;
  84      }
  85  }
  86  
  87  if (!data_submitted() or !$confirm or !confirm_sesskey()) {
  88      $PAGE->set_title($glossary->name);
  89      $PAGE->set_heading($course->fullname);
  90      echo $OUTPUT->header();
  91      echo '<div class="boxaligncenter">';
  92      $areyousure = '<h2>'.format_string($entry->concept).'</h2><p align="center">'.get_string('areyousureexport','glossary').'<br /><b>'.format_string($mainglossary->name).'</b>?';
  93      $linkyes    = 'exportentry.php';
  94      $linkno     = 'view.php';
  95      $optionsyes = array('id'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
  96      $optionsno  = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
  97  
  98      echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
  99      echo '</div>';
 100      echo $OUTPUT->footer();
 101      die;
 102  
 103  } else {
 104      $entry->glossaryid       = $mainglossary->id;
 105      $entry->sourceglossaryid = $glossary->id;
 106  
 107      $DB->update_record('glossary_entries', $entry);
 108  
 109      // move attachments too
 110      $fs = get_file_storage();
 111  
 112      if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) {
 113          foreach ($oldfiles as $oldfile) {
 114              $file_record = new stdClass();
 115              $file_record->contextid = $maincontext->id;
 116              $fs->create_file_from_storedfile($file_record, $oldfile);
 117          }
 118          $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
 119          $entry->attachment = '1';
 120      } else {
 121          $entry->attachment = '0';
 122      }
 123      $DB->update_record('glossary_entries', $entry);
 124  
 125      redirect ($returnurl);
 126  }
 127