Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       1  <?php
       2  
       3  /// This page prints a particular instance of glossary
       4  require_once("../../config.php");
       5  require_once ("lib.php");
       6  require_once($CFG->libdir . '/completionlib.php');
       7  require_once("$CFG->libdir/rsslib.php");
       8  
       9  $id = optional_param('id', 0, PARAM_INT);           // Course Module ID
      10  $g  = optional_param('g', 0, PARAM_INT);            // Glossary ID
      11  
      12  $tab  = optional_param('tab', GLOSSARY_NO_VIEW, PARAM_ALPHA);    // browsing entries by categories?
      13  $displayformat = optional_param('displayformat',-1, PARAM_INT);  // override of the glossary display format
      14  
      15  $mode       = optional_param('mode', '', PARAM_ALPHA);           // term entry cat date letter search author approval
      16  $hook       = optional_param('hook', '', PARAM_CLEAN);           // the term, entry, cat, etc... to look for based on mode
      17  $fullsearch = optional_param('fullsearch', 0,PARAM_INT);         // full search (concept and definition) when searching?
      18  $sortkey    = optional_param('sortkey', '', PARAM_ALPHA);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
      19  $sortorder  = optional_param('sortorder', 'ASC', PARAM_ALPHA);   // it defines the order of the sorting (ASC or DESC)
      20  $offset     = optional_param('offset', 0,PARAM_INT);             // entries to bypass (for paging purposes)
      21  $page       = optional_param('page', 0,PARAM_INT);               // Page to show (for paging purposes)
      22  $show       = optional_param('show', '', PARAM_ALPHA);           // [ concept | alias ] => mode=term hook=$show
      23  
      24  if (!empty($id)) {
      25      if (! $cm = get_coursemodule_from_id('glossary', $id)) {
      26          print_error('invalidcoursemodule');
      27      }
      28      if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
      29          print_error('coursemisconf');
      30      }
      31      if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
      32          print_error('invalidid', 'glossary');
      33      }
      34  
      35  } else if (!empty($g)) {
      36      if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
      37          print_error('invalidid', 'glossary');
      38      }
      39      if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) {
      40          print_error('invalidcourseid');
      41      }
      42      if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) {
      43          print_error('invalidcoursemodule');
      44      }
      45      $id = $cm->id;
      46  } else {
      47      print_error('invalidid', 'glossary');
      48  }
      49  
      50  require_course_login($course->id, true, $cm);
      51  $context = context_module::instance($cm->id);
      52  require_capability('mod/glossary:view', $context);
      53  
      54  // Prepare format_string/text options
      55  $fmtoptions = array(
      56      'context' => $context);
      57  
      58  require_once($CFG->dirroot . '/comment/lib.php');
      59  comment::init();
      60  
      61  /// redirecting if adding a new entry
      62  if ($tab == GLOSSARY_ADDENTRY_VIEW ) {
      63      redirect("edit.php?cmid=$cm->id&amp;mode=$mode");
      64  }
      65  
      66  /// setting the defaut number of entries per page if not set
      67  if ( !$entriesbypage = $glossary->entbypage ) {
      68      $entriesbypage = $CFG->glossary_entbypage;
      69  }
      70  
      71  /// If we have received a page, recalculate offset
      72  if ($page != 0 && $offset == 0) {
      73      $offset = $page * $entriesbypage;
      74  }
      75  
      76  /// setting the default values for the display mode of the current glossary
      77  /// only if the glossary is viewed by the first time
      78  if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
      79  /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
      80      switch ($dp->defaultmode) {
      81          case 'cat':
      82              $defaulttab = GLOSSARY_CATEGORY_VIEW;
      83              break;
      84          case 'date':
      85              $defaulttab = GLOSSARY_DATE_VIEW;
      86              break;
      87          case 'author':
      88              $defaulttab = GLOSSARY_AUTHOR_VIEW;
      89              break;
      90          default:
      91              $defaulttab = GLOSSARY_STANDARD_VIEW;
      92      }
      93  /// Fetch the rest of variables
      94      $printpivot = $dp->showgroup;
      95      if ( $mode == '' and $hook == '' and $show == '') {
      96          $mode      = $dp->defaultmode;
      97          $hook      = $dp->defaulthook;
      98          $sortkey   = $dp->sortkey;
      99          $sortorder = $dp->sortorder;
     100      }
     101  } else {
     102      $defaulttab = GLOSSARY_STANDARD_VIEW;
     103      $printpivot = 1;
     104      if ( $mode == '' and $hook == '' and $show == '') {
     105          $mode = 'letter';
     106          $hook = 'ALL';
     107      }
     108  }
     109  
     110  if ( $displayformat == -1 ) {
     111       $displayformat = $glossary->displayformat;
     112  }
     113  
     114  if ( $show ) {
     115      $mode = 'term';
     116      $hook = $show;
     117      $show = '';
     118  }
     119  
     120  /// stablishing flag variables
     121  if ( $sortorder = strtolower($sortorder) ) {
     122      if ($sortorder != 'asc' and $sortorder != 'desc') {
     123          $sortorder = '';
     124      }
     125  }
     126  if ( $sortkey = strtoupper($sortkey) ) {
     127      if ($sortkey != 'CREATION' and
     128          $sortkey != 'UPDATE' and
     129          $sortkey != 'FIRSTNAME' and
     130          $sortkey != 'LASTNAME'
     131          ) {
     132          $sortkey = '';
     133      }
     134  }
     135  
     136  switch ( $mode = strtolower($mode) ) {
     137  case 'search': /// looking for terms containing certain word(s)
     138      $tab = GLOSSARY_STANDARD_VIEW;
     139  
     140      //Clean a bit the search string
     141      $hook = trim(strip_tags($hook));
     142  
     143  break;
     144  
     145  case 'entry':  /// Looking for a certain entry id
     146      $tab = GLOSSARY_STANDARD_VIEW;
     147      if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) {
     148          $displayformat = $dp->popupformatname;
     149      }
     150  break;
     151  
     152  case 'cat':    /// Looking for a certain cat
     153      $tab = GLOSSARY_CATEGORY_VIEW;
     154      if ( $hook > 0 ) {
     155          $category = $DB->get_record("glossary_categories", array("id"=>$hook));
     156      }
     157  break;
     158  
     159  case 'approval':    /// Looking for entries waiting for approval
     160      $tab = GLOSSARY_APPROVAL_VIEW;
     161      // Override the display format with the approvaldisplayformat
     162      if ($glossary->approvaldisplayformat !== 'default' && ($df = $DB->get_record("glossary_formats",
     163              array("name" => $glossary->approvaldisplayformat)))) {
     164          $displayformat = $df->popupformatname;
     165      }
     166      if ( !$hook and !$sortkey and !$sortorder) {
     167          $hook = 'ALL';
     168      }
     169  break;
     170  
     171  case 'term':   /// Looking for entries that include certain term in its concept, definition or aliases
     172      $tab = GLOSSARY_STANDARD_VIEW;
     173  break;
     174  
     175  case 'date':
     176      $tab = GLOSSARY_DATE_VIEW;
     177      if ( !$sortkey ) {
     178          $sortkey = 'UPDATE';
     179      }
     180      if ( !$sortorder ) {
     181          $sortorder = 'desc';
     182      }
     183  break;
     184  
     185  case 'author':  /// Looking for entries, browsed by author
     186      $tab = GLOSSARY_AUTHOR_VIEW;
     187      if ( !$hook ) {
     188          $hook = 'ALL';
     189      }
     190      if ( !$sortkey ) {
     191          $sortkey = 'FIRSTNAME';
     192      }
     193      if ( !$sortorder ) {
     194          $sortorder = 'asc';
     195      }
     196  break;
     197  
     198  case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
     199  default:
     200      $tab = GLOSSARY_STANDARD_VIEW;
     201      if ( !$hook ) {
     202          $hook = 'ALL';
     203      }
     204  break;
     205  }
     206  
     207  switch ( $tab ) {
     208  case GLOSSARY_IMPORT_VIEW:
     209  case GLOSSARY_EXPORT_VIEW:
     210  case GLOSSARY_APPROVAL_VIEW:
     211      $showcommonelements = 0;
     212  break;
     213  
     214  default:
     215      $showcommonelements = 1;
     216  break;
     217  }
     218  
     219  // Trigger module viewed event.
     220  $event = \mod_glossary\event\course_module_viewed::create(array(
     221      'objectid' => $glossary->id,
     222      'context' => $context,
     223      'other' => array('mode' => $mode)
     224  ));
     225  $event->add_record_snapshot('course', $course);
     226  $event->add_record_snapshot('course_modules', $cm);
     227  $event->add_record_snapshot('glossary', $glossary);
     228  $event->trigger();
     229  
     230  // Mark as viewed
     231  $completion = new completion_info($course);
     232  $completion->set_module_viewed($cm);
     233  
     234  /// Printing the heading
     235  $strglossaries = get_string("modulenameplural", "glossary");
     236  $strglossary = get_string("modulename", "glossary");
     237  $strallcategories = get_string("allcategories", "glossary");
     238  $straddentry = get_string("addentry", "glossary");
     239  $strnoentries = get_string("noentries", "glossary");
     240  $strsearchindefinition = get_string("searchindefinition", "glossary");
     241  $strsearch = get_string("search");
     242  $strwaitingapproval = get_string('waitingapproval', 'glossary');
     243  
     244  /// If we are in approval mode, prit special header
     245  $PAGE->set_title($glossary->name);
     246  $PAGE->set_heading($course->fullname);
     247  $url = new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id));
     248  if (isset($mode)) {
     249      $url->param('mode', $mode);
     250  }
     251  $PAGE->set_url($url);
     252  
     253  if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds)
     254      && $glossary->rsstype && $glossary->rssarticles) {
     255  
     256      $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': '. format_string($glossary->name);
     257      rss_add_http_header($context, 'mod_glossary', $glossary, $rsstitle);
     258  }
     259  
     260  if ($tab == GLOSSARY_APPROVAL_VIEW) {
     261      require_capability('mod/glossary:approve', $context);
     262      $PAGE->navbar->add($strwaitingapproval);
     263      echo $OUTPUT->header();
     264      echo $OUTPUT->heading($strwaitingapproval);
     265  } else { /// Print standard header
     266      echo $OUTPUT->header();
     267  }
     268  echo $OUTPUT->heading(format_string($glossary->name), 2);
     269  
     270  /// All this depends if whe have $showcommonelements
     271  if ($showcommonelements) {
     272  /// To calculate available options
     273      $availableoptions = '';
     274  
     275  /// Decide about to print the import link
     276      /*if (has_capability('mod/glossary:import', $context)) {
     277          $availableoptions = '<span class="helplink">' .
     278                              '<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' .
     279                              '  title="' . s(get_string('importentries', 'glossary')) . '">' .
     280                              get_string('importentries', 'glossary') . '</a>' .
     281                              '</span>';
     282      }
     283  /// Decide about to print the export link
     284      if (has_capability('mod/glossary:export', $context)) {
     285          if ($availableoptions) {
     286              $availableoptions .= '&nbsp;/&nbsp;';
     287          }
     288          $availableoptions .='<span class="helplink">' .
     289                              '<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
     290                              '&amp;mode='.$mode . '&amp;hook=' . urlencode($hook) . '"' .
     291                              '  title="' . s(get_string('exportentries', 'glossary')) . '">' .
     292                              get_string('exportentries', 'glossary') . '</a>' .
     293                              '</span>';
     294      }*/
     295  
     296  /// Decide about to print the approval link
     297      if (has_capability('mod/glossary:approve', $context)) {
     298      /// Check we have pending entries
     299          if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id, 'approved'=>0))) {
     300              if ($availableoptions) {
     301                  $availableoptions .= '<br />';
     302              }
     303              $availableoptions .='<span class="helplink">' .
     304                                  '<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id .
     305                                  '&amp;mode=approval' . '"' .
     306                                  '  title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
     307                                  get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
     308                                  '</span>';
     309          }
     310      }
     311  
     312  /// Start to print glossary controls
     313  //        print_box_start('glossarycontrol clearfix');
     314      echo '<div class="glossarycontrol" style="text-align: right">';
     315      echo $availableoptions;
     316  
     317  /// The print icon
     318      if ( $showcommonelements and $mode != 'search') {
     319          if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) {
     320              echo " <a class='printicon' title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;offset=$offset\">" . get_string("printerfriendly","glossary")."</a>";
     321          }
     322      }
     323  /// End glossary controls
     324  //        print_box_end(); /// glossarycontrol
     325      echo '</div>';
     326  
     327  //        print_box('&nbsp;', 'clearer');
     328  }
     329  
     330  /// Info box
     331  if ($glossary->intro && $showcommonelements) {
     332      echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro');
     333  }
     334  
     335  /// Search box
     336  if ($showcommonelements ) {
     337      echo '<form method="post" action="view.php">';
     338  
     339      echo '<table class="boxaligncenter" width="70%" border="0">';
     340      echo '<tr><td align="center" class="glossarysearchbox">';
     341  
     342      echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> ';
     343      if ($mode == 'search') {
     344          echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> ';
     345      } else {
     346          echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> ';
     347      }
     348      if ($fullsearch || $mode != 'search') {
     349          $fullsearchchecked = 'checked="checked"';
     350      } else {
     351          $fullsearchchecked = '';
     352      }
     353      echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />';
     354      echo '<input type="hidden" name="mode" value="search" />';
     355      echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
     356      echo '<label for="fullsearch">'.$strsearchindefinition.'</label>';
     357      echo '</td></tr></table>';
     358  
     359      echo '</form>';
     360  
     361      echo '<br />';
     362  }
     363  
     364  /// Show the add entry button if allowed
     365  if (has_capability('mod/glossary:write', $context) && $showcommonelements ) {
     366      echo '<div class="singlebutton glossaryaddentry">';
     367      echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">";
     368      echo '<div>';
     369      echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />";
     370      echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />';
     371      echo '</div>';
     372      echo '</form>';
     373      echo "</div>\n";
     374  }
     375  
     376  echo '<br />';
     377  
     378  require ("tabs.php");
     379  
     380  require ("sql.php");
     381  
     382  /// printing the entries
     383  $entriesshown = 0;
     384  $currentpivot = '';
     385  $paging = NULL;
     386  
     387  if ($allentries) {
     388  
     389      //Decide if we must show the ALL link in the pagebar
     390      $specialtext = '';
     391      if ($glossary->showall) {
     392          $specialtext = get_string("allentries","glossary");
     393      }
     394  
     395      //Build paging bar
     396      $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;fullsearch=$fullsearch&amp;",9999,10,'&nbsp;&nbsp;', $specialtext, -1);
     397  
     398      echo '<div class="paging">';
     399      echo $paging;
     400      echo '</div>';
     401  
     402      //load ratings
     403      require_once($CFG->dirroot.'/rating/lib.php');
     404      if ($glossary->assessed != RATING_AGGREGATE_NONE) {
     405          $ratingoptions = new stdClass;
     406          $ratingoptions->context = $context;
     407          $ratingoptions->component = 'mod_glossary';
     408          $ratingoptions->ratingarea = 'entry';
     409          $ratingoptions->items = $allentries;
     410          $ratingoptions->aggregate = $glossary->assessed;//the aggregation method
     411          $ratingoptions->scaleid = $glossary->scale;
     412          $ratingoptions->userid = $USER->id;
     413          $ratingoptions->returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id;
     414          $ratingoptions->assesstimestart = $glossary->assesstimestart;
     415          $ratingoptions->assesstimefinish = $glossary->assesstimefinish;
     416  
     417          $rm = new rating_manager();
     418          $allentries = $rm->get_ratings($ratingoptions);
     419      }
     420  
     421      foreach ($allentries as $entry) {
     422  
     423          // Setting the pivot for the current entry
     424          $pivot = $entry->glossarypivot;
     425          $upperpivot = core_text::strtoupper($pivot);
     426          $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
     427          // Reduce pivot to 1cc if necessary
     428          if ( !$fullpivot ) {
     429              $upperpivot = core_text::substr($upperpivot, 0, 1);
     430              $pivottoshow = core_text::substr($pivottoshow, 0, 1);
     431          }
     432  
     433          // if there's a group break
     434          if ( $currentpivot != $upperpivot ) {
     435  
     436              // print the group break if apply
     437              if ( $printpivot )  {
     438                  $currentpivot = $upperpivot;
     439  
     440                  echo '<div>';
     441                  echo '<table cellspacing="0" class="glossarycategoryheader">';
     442  
     443                  echo '<tr>';
     444                  if ( isset($entry->userispivot) ) {
     445                  // printing the user icon if defined (only when browsing authors)
     446                      echo '<th align="left">';
     447  
     448                      $user = $DB->get_record("user", array("id"=>$entry->userid));
     449                      echo $OUTPUT->user_picture($user, array('courseid'=>$course->id));
     450                      $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', context_course::instance($course->id)));
     451                  } else {
     452                      echo '<th >';
     453                  }
     454  
     455                  echo $OUTPUT->heading($pivottoshow, 3);
     456                  echo "</th></tr></table></div>\n";
     457  
     458              }
     459          }
     460  
     461          /// highlight the term if necessary
     462          if ($mode == 'search') {
     463              //We have to strip any word starting by + and take out words starting by -
     464              //to make highlight works properly
     465              $searchterms = explode(' ', $hook);    // Search for words independently
     466              foreach ($searchterms as $key => $searchterm) {
     467                  if (preg_match('/^\-/',$searchterm)) {
     468                      unset($searchterms[$key]);
     469                  } else {
     470                      $searchterms[$key] = preg_replace('/^\+/','',$searchterm);
     471                  }
     472                  //Avoid highlight of <2 len strings. It's a well known hilight limitation.
     473                  if (strlen($searchterm) < 2) {
     474                      unset($searchterms[$key]);
     475                  }
     476              }
     477              $strippedsearch = implode(' ', $searchterms);    // Rebuild the string
     478              $entry->highlight = $strippedsearch;
     479          }
     480  
     481          /// and finally print the entry.
     482          glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat);
     483          $entriesshown++;
     484      }
     485  }
     486  if ( !$entriesshown ) {
     487      echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide");
     488  }
     489  
     490  if (!empty($formsent)) {
     491      // close the form properly if used
     492      echo "</div>";
     493      echo "</form>";
     494  }
     495  
     496  if ( $paging ) {
     497      echo '<hr />';
     498      echo '<div class="paging">';
     499      echo $paging;
     500      echo '</div>';
     501  }
     502  echo '<br />';
     503  glossary_print_tabbed_table_end();
     504  
     505  /// Finish the page
     506  echo $OUTPUT->footer();
    

    Search This Site: