Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  
   3  global $CFG;
   4  
   5  require_once("../../config.php");
   6  require_once ("lib.php");
   7  
   8  $id            = required_param('id', PARAM_INT);                     // Course Module ID
   9  $sortorder     = optional_param('sortorder', 'asc', PARAM_ALPHA);     // Sorting order
  10  $offset        = optional_param('offset', 0, PARAM_INT);              // number of entries to bypass
  11  $pagelimit     = optional_param('pagelimit', 0, PARAM_INT);           // Number of entries per page, 0 if unlimited.
  12  $displayformat = optional_param('displayformat',-1, PARAM_INT);
  13  
  14  $mode    = required_param('mode', PARAM_ALPHA);             // mode to show the entries
  15  $hook    = optional_param('hook','ALL', PARAM_CLEAN);       // what to show
  16  $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
  17  
  18  $url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
  19  if ($sortorder !== 'asc') {
  20      $url->param('sortorder', $sortorder);
  21  }
  22  if ($offset !== 0) {
  23      $url->param('offset', $offset);
  24  }
  25  if ($displayformat !== -1) {
  26      $url->param('displayformat', $displayformat);
  27  }
  28  if ($sortkey !== 'UPDATE') {
  29      $url->param('sortkey', $sortkey);
  30  }
  31  if ($mode !== 'letter') {
  32      $url->param('mode', $mode);
  33  }
  34  if ($hook !== 'ALL') {
  35      $url->param('hook', $hook);
  36  }
  37  $PAGE->set_url($url);
  38  
  39  if (! $cm = get_coursemodule_from_id('glossary', $id)) {
  40      throw new \moodle_exception('invalidcoursemodule');
  41  }
  42  
  43  if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  44      throw new \moodle_exception('coursemisconf');
  45  }
  46  
  47  if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
  48      throw new \moodle_exception('invalidid', 'glossary');
  49  }
  50  
  51  if ($pagelimit < 0) {
  52      $pagelimit = 0;
  53  }
  54  
  55  require_course_login($course, true, $cm);
  56  $context = context_module::instance($cm->id);
  57  
  58  // Prepare format_string/text options
  59  $fmtoptions = array(
  60      'context' => $context);
  61  
  62  $PAGE->set_pagelayout('print');
  63  $PAGE->set_title(get_string("modulenameplural", "glossary"));
  64  $PAGE->set_heading($course->fullname);
  65  echo $OUTPUT->header();
  66  
  67  if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
  68      notice(get_string('printviewnotallowed', 'glossary'));
  69  }
  70  
  71  /// setting the default values for the display mode of the current glossary
  72  /// only if the glossary is viewed by the first time
  73  if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
  74      $printpivot = $dp->showgroup;
  75      if ( $mode == '' and $hook == '' and $show == '') {
  76          $mode      = $dp->defaultmode;
  77          $hook      = $dp->defaulthook;
  78          $sortkey   = $dp->sortkey;
  79          $sortorder = $dp->sortorder;
  80      }
  81  } else {
  82      $printpivot = 1;
  83      if ( $mode == '' and $hook == '' and $show == '') {
  84          $mode = 'letter';
  85          $hook = 'ALL';
  86      }
  87  }
  88  
  89  if ( $displayformat == -1 ) {
  90       $displayformat = $glossary->displayformat;
  91  }
  92  
  93  /// stablishing flag variables
  94  if ( $sortorder = strtolower($sortorder) ) {
  95      if ($sortorder != 'asc' and $sortorder != 'desc') {
  96          $sortorder = '';
  97      }
  98  }
  99  if ( $sortkey = strtoupper($sortkey) ) {
 100      if ($sortkey != 'CREATION' and
 101          $sortkey != 'UPDATE' and
 102          $sortkey != 'FIRSTNAME' and
 103          $sortkey != 'LASTNAME'
 104          ) {
 105          $sortkey = '';
 106      }
 107  }
 108  
 109  switch ( $mode = strtolower($mode) ) {
 110  case 'entry':  /// Looking for a certain entry id
 111      $tab = GLOSSARY_STANDARD_VIEW;
 112  break;
 113  
 114  case 'cat':    /// Looking for a certain cat
 115      $tab = GLOSSARY_CATEGORY_VIEW;
 116      if ( $hook > 0 ) {
 117          $category = $DB->get_record("glossary_categories", array("id"=>$hook));
 118      }
 119  break;
 120  
 121  case 'approval':    /// Looking for entries waiting for approval
 122      $tab = GLOSSARY_APPROVAL_VIEW;
 123      if ( !$hook and !$sortkey and !$sortorder) {
 124          $hook = 'ALL';
 125      }
 126  break;
 127  
 128  case 'term':   /// Looking for entries that include certain term in its concept, definition or aliases
 129      $tab = GLOSSARY_STANDARD_VIEW;
 130  break;
 131  
 132  case 'date':
 133      $tab = GLOSSARY_DATE_VIEW;
 134      if ( !$sortkey ) {
 135          $sortkey = 'UPDATE';
 136      }
 137      if ( !$sortorder ) {
 138          $sortorder = 'desc';
 139      }
 140  break;
 141  
 142  case 'author':  /// Looking for entries, browsed by author
 143      $tab = GLOSSARY_AUTHOR_VIEW;
 144      if ( !$hook ) {
 145          $hook = 'ALL';
 146      }
 147      if ( !$sortkey ) {
 148          $sortkey = 'FIRSTNAME';
 149      }
 150      if ( !$sortorder ) {
 151          $sortorder = 'asc';
 152      }
 153  break;
 154  
 155  case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
 156  default:
 157      $tab = GLOSSARY_STANDARD_VIEW;
 158      if ( !$hook ) {
 159          $hook = 'ALL';
 160      }
 161  break;
 162  }
 163  
 164  include_once ("sql.php");
 165  
 166  $entriesshown = 0;
 167  $currentpivot = '';
 168  
 169  $site = $DB->get_record("course", array("id"=>1));
 170  
 171  // Print dialog link.
 172  $printtext = get_string('print', 'glossary');
 173  $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'glossary_no_print printicon');
 174  $printiconlink = html_writer::link('#', $printtext, $printlinkatt);
 175  echo  html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon'));
 176  
 177  echo html_writer::tag('div', userdate(time()), array('class' => 'displaydate'));
 178  
 179  $sitename = get_string("site") . ': <span class="strong">' . format_string($site->fullname) . '</span>';
 180  echo html_writer::tag('div', $sitename, array('class' => 'sitename'));
 181  
 182  $coursename = get_string("course") . ': <span class="strong">' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</span>';
 183  echo html_writer::tag('div', $coursename, array('class' => 'coursename'));
 184  
 185  $modname = get_string("modulename","glossary") . ': <span class="strong">' . format_string($glossary->name, true) . '</span>';
 186  echo html_writer::tag('div', $modname, array('class' => 'modname'));
 187  
 188  if ( $allentries ) {
 189      foreach ($allentries as $entry) {
 190  
 191          // Setting the pivot for the current entry.
 192          if ($printpivot) {
 193  
 194              $pivot = $entry->{$pivotkey};
 195              $upperpivot = core_text::strtoupper($pivot);
 196              $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
 197  
 198              // Reduce pivot to 1cc if necessary.
 199              if (!$fullpivot) {
 200                  $upperpivot = core_text::substr($upperpivot, 0, 1);
 201                  $pivottoshow = core_text::substr($pivottoshow, 0, 1);
 202              }
 203  
 204              // If there's a group break.
 205              if ($currentpivot != $upperpivot) {
 206                  $currentpivot = $upperpivot;
 207  
 208                  if ($userispivot) {
 209                      // Printing the user icon if defined (only when browsing authors).
 210                      $user = mod_glossary_entry_query_builder::get_user_from_record($entry);
 211                      $pivottoshow = fullname($user);
 212                  }
 213                  echo html_writer::tag('div', clean_text($pivottoshow), array('class' => 'mdl-align strong'));
 214              }
 215          }
 216  
 217          glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, true);
 218      }
 219      // The all entries value may be a recordset or an array.
 220      if ($allentries instanceof moodle_recordset) {
 221          $allentries->close();
 222      }
 223  }
 224  
 225  echo $OUTPUT->footer();