[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/glossary/ -> view.php (source)

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


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7