|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 require_once("../../config.php"); 00005 require_once("lib.php"); 00006 require_once($CFG->libdir . '/completionlib.php'); 00007 require_once("$CFG->libdir/rsslib.php"); 00008 00009 $id = optional_param('id', 0, PARAM_INT); // Course Module ID 00010 $g = optional_param('g', 0, PARAM_INT); // Glossary ID 00011 00012 $tab = optional_param('tab', GLOSSARY_NO_VIEW, PARAM_ALPHA); // browsing entries by categories? 00013 $displayformat = optional_param('displayformat',-1, PARAM_INT); // override of the glossary display format 00014 00015 $mode = optional_param('mode', '', PARAM_ALPHA); // term entry cat date letter search author approval 00016 $hook = optional_param('hook', '', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode 00017 $fullsearch = optional_param('fullsearch', 0,PARAM_INT); // full search (concept and definition) when searching? 00018 $sortkey = optional_param('sortkey', '', PARAM_ALPHA);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME... 00019 $sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA); // it defines the order of the sorting (ASC or DESC) 00020 $offset = optional_param('offset', 0,PARAM_INT); // entries to bypass (for paging purposes) 00021 $page = optional_param('page', 0,PARAM_INT); // Page to show (for paging purposes) 00022 $show = optional_param('show', '', PARAM_ALPHA); // [ concept | alias ] => mode=term hook=$show 00023 00024 if (!empty($id)) { 00025 if (! $cm = get_coursemodule_from_id('glossary', $id)) { 00026 print_error('invalidcoursemodule'); 00027 } 00028 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 00029 print_error('coursemisconf'); 00030 } 00031 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { 00032 print_error('invalidid', 'glossary'); 00033 } 00034 00035 } else if (!empty($g)) { 00036 if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) { 00037 print_error('invalidid', 'glossary'); 00038 } 00039 if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) { 00040 print_error('invalidcourseid'); 00041 } 00042 if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) { 00043 print_error('invalidcoursemodule'); 00044 } 00045 $id = $cm->id; 00046 } else { 00047 print_error('invalidid', 'glossary'); 00048 } 00049 00050 require_course_login($course->id, true, $cm); 00051 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00052 00053 // Prepare format_string/text options 00054 $fmtoptions = array( 00055 'context' => $context); 00056 00057 require_once($CFG->dirroot . '/comment/lib.php'); 00058 comment::init(); 00059 00061 $textlib = textlib_get_instance(); 00062 00064 if ($tab == GLOSSARY_ADDENTRY_VIEW ) { 00065 redirect("edit.php?cmid=$cm->id&mode=$mode"); 00066 } 00067 00069 if ( !$entriesbypage = $glossary->entbypage ) { 00070 $entriesbypage = $CFG->glossary_entbypage; 00071 } 00072 00074 if ($page != 0 && $offset == 0) { 00075 $offset = $page * $entriesbypage; 00076 } 00077 00080 if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { 00082 switch ($dp->defaultmode) { 00083 case 'cat': 00084 $defaulttab = GLOSSARY_CATEGORY_VIEW; 00085 break; 00086 case 'date': 00087 $defaulttab = GLOSSARY_DATE_VIEW; 00088 break; 00089 case 'author': 00090 $defaulttab = GLOSSARY_AUTHOR_VIEW; 00091 break; 00092 default: 00093 $defaulttab = GLOSSARY_STANDARD_VIEW; 00094 } 00096 $printpivot = $dp->showgroup; 00097 if ( $mode == '' and $hook == '' and $show == '') { 00098 $mode = $dp->defaultmode; 00099 $hook = $dp->defaulthook; 00100 $sortkey = $dp->sortkey; 00101 $sortorder = $dp->sortorder; 00102 } 00103 } else { 00104 $defaulttab = GLOSSARY_STANDARD_VIEW; 00105 $printpivot = 1; 00106 if ( $mode == '' and $hook == '' and $show == '') { 00107 $mode = 'letter'; 00108 $hook = 'ALL'; 00109 } 00110 } 00111 00112 if ( $displayformat == -1 ) { 00113 $displayformat = $glossary->displayformat; 00114 } 00115 00116 if ( $show ) { 00117 $mode = 'term'; 00118 $hook = $show; 00119 $show = ''; 00120 } 00122 if ($course->id != SITEID) { 00123 require_login($course->id); 00124 } 00125 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { 00126 echo $OUTPUT->header(); 00127 notice(get_string("activityiscurrentlyhidden")); 00128 } 00129 add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id); 00130 00131 // Mark as viewed 00132 $completion = new completion_info($course); 00133 $completion->set_module_viewed($cm); 00134 00136 if ( $sortorder = strtolower($sortorder) ) { 00137 if ($sortorder != 'asc' and $sortorder != 'desc') { 00138 $sortorder = ''; 00139 } 00140 } 00141 if ( $sortkey = strtoupper($sortkey) ) { 00142 if ($sortkey != 'CREATION' and 00143 $sortkey != 'UPDATE' and 00144 $sortkey != 'FIRSTNAME' and 00145 $sortkey != 'LASTNAME' 00146 ) { 00147 $sortkey = ''; 00148 } 00149 } 00150 00151 switch ( $mode = strtolower($mode) ) { 00152 case 'search': 00153 $tab = GLOSSARY_STANDARD_VIEW; 00154 00155 //Clean a bit the search string 00156 $hook = trim(strip_tags($hook)); 00157 00158 break; 00159 00160 case 'entry': 00161 $tab = GLOSSARY_STANDARD_VIEW; 00162 if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) { 00163 $displayformat = $dp->popupformatname; 00164 } 00165 break; 00166 00167 case 'cat': 00168 $tab = GLOSSARY_CATEGORY_VIEW; 00169 if ( $hook > 0 ) { 00170 $category = $DB->get_record("glossary_categories", array("id"=>$hook)); 00171 } 00172 break; 00173 00174 case 'approval': 00175 $tab = GLOSSARY_APPROVAL_VIEW; 00176 if ( !$hook and !$sortkey and !$sortorder) { 00177 $hook = 'ALL'; 00178 } 00179 break; 00180 00181 case 'term': 00182 $tab = GLOSSARY_STANDARD_VIEW; 00183 break; 00184 00185 case 'date': 00186 $tab = GLOSSARY_DATE_VIEW; 00187 if ( !$sortkey ) { 00188 $sortkey = 'UPDATE'; 00189 } 00190 if ( !$sortorder ) { 00191 $sortorder = 'desc'; 00192 } 00193 break; 00194 00195 case 'author': 00196 $tab = GLOSSARY_AUTHOR_VIEW; 00197 if ( !$hook ) { 00198 $hook = 'ALL'; 00199 } 00200 if ( !$sortkey ) { 00201 $sortkey = 'FIRSTNAME'; 00202 } 00203 if ( !$sortorder ) { 00204 $sortorder = 'asc'; 00205 } 00206 break; 00207 00208 case 'letter': 00209 default: 00210 $tab = GLOSSARY_STANDARD_VIEW; 00211 if ( !$hook ) { 00212 $hook = 'ALL'; 00213 } 00214 break; 00215 } 00216 00217 switch ( $tab ) { 00218 case GLOSSARY_IMPORT_VIEW: 00219 case GLOSSARY_EXPORT_VIEW: 00220 case GLOSSARY_APPROVAL_VIEW: 00221 $showcommonelements = 0; 00222 break; 00223 00224 default: 00225 $showcommonelements = 1; 00226 break; 00227 } 00228 00230 $strglossaries = get_string("modulenameplural", "glossary"); 00231 $strglossary = get_string("modulename", "glossary"); 00232 $strallcategories = get_string("allcategories", "glossary"); 00233 $straddentry = get_string("addentry", "glossary"); 00234 $strnoentries = get_string("noentries", "glossary"); 00235 $strsearchindefinition = get_string("searchindefinition", "glossary"); 00236 $strsearch = get_string("search"); 00237 $strwaitingapproval = get_string('waitingapproval', 'glossary'); 00238 00240 $PAGE->set_title(format_string($glossary->name)); 00241 $PAGE->set_heading($course->fullname); 00242 $url = new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id)); 00243 if (isset($mode)) { 00244 $url->param('mode', $mode); 00245 } 00246 $PAGE->set_url($url); 00247 00248 if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) 00249 && $glossary->rsstype && $glossary->rssarticles) { 00250 00251 $rsstitle = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . ': %fullname%'; 00252 rss_add_http_header($context, 'mod_glossary', $glossary, $rsstitle); 00253 } 00254 00255 if ($tab == GLOSSARY_APPROVAL_VIEW) { 00256 require_capability('mod/glossary:approve', $context); 00257 $PAGE->navbar->add($strwaitingapproval); 00258 echo $OUTPUT->header(); 00259 echo $OUTPUT->heading($strwaitingapproval); 00260 } else { 00261 echo $OUTPUT->header(); 00262 } 00263 00265 if ($showcommonelements) { 00267 $availableoptions = ''; 00268 00270 /*if (has_capability('mod/glossary:import', $context)) { 00271 $availableoptions = '<span class="helplink">' . 00272 '<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' . 00273 ' title="' . s(get_string('importentries', 'glossary')) . '">' . 00274 get_string('importentries', 'glossary') . '</a>' . 00275 '</span>'; 00276 } 00278 if (has_capability('mod/glossary:export', $context)) { 00279 if ($availableoptions) { 00280 $availableoptions .= ' / '; 00281 } 00282 $availableoptions .='<span class="helplink">' . 00283 '<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id . 00284 '&mode='.$mode . '&hook=' . urlencode($hook) . '"' . 00285 ' title="' . s(get_string('exportentries', 'glossary')) . '">' . 00286 get_string('exportentries', 'glossary') . '</a>' . 00287 '</span>'; 00288 }*/ 00289 00291 if (has_capability('mod/glossary:approve', $context)) { 00293 if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id, 'approved'=>0))) { 00294 if ($availableoptions) { 00295 $availableoptions .= '<br />'; 00296 } 00297 $availableoptions .='<span class="helplink">' . 00298 '<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id . 00299 '&mode=approval' . '"' . 00300 ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' . 00301 get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' . 00302 '</span>'; 00303 } 00304 } 00305 00307 // print_box_start('glossarycontrol clearfix'); 00308 echo '<div class="glossarycontrol" style="text-align: right">'; 00309 echo $availableoptions; 00310 00312 if ( $showcommonelements and $mode != 'search') { 00313 if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) { 00314 // print_box_start('printicon'); 00315 echo '<span class="wrap printicon">'; 00316 echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\"><img class=\"icon\" src=\"".$OUTPUT->pix_url('print', 'glossary')."\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>"; 00317 echo '</span>'; 00318 // print_box_end(); 00319 } 00320 } 00322 // print_box_end(); /// glossarycontrol 00323 echo '</div>'; 00324 00325 // print_box(' ', 'clearer'); 00326 } 00327 00329 if ($glossary->intro && $showcommonelements) { 00330 echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro'); 00331 } 00332 00334 if ($showcommonelements ) { 00335 echo '<form method="post" action="view.php">'; 00336 00337 echo '<table class="boxaligncenter" width="70%" border="0">'; 00338 echo '<tr><td align="center" class="glossarysearchbox">'; 00339 00340 echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> '; 00341 if ($mode == 'search') { 00342 echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> '; 00343 } else { 00344 echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> '; 00345 } 00346 if ($fullsearch || $mode != 'search') { 00347 $fullsearchchecked = 'checked="checked"'; 00348 } else { 00349 $fullsearchchecked = ''; 00350 } 00351 echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />'; 00352 echo '<input type="hidden" name="mode" value="search" />'; 00353 echo '<input type="hidden" name="id" value="'.$cm->id.'" />'; 00354 echo '<label for="fullsearch">'.$strsearchindefinition.'</label>'; 00355 echo '</td></tr></table>'; 00356 00357 echo '</form>'; 00358 00359 echo '<br />'; 00360 } 00361 00363 if (has_capability('mod/glossary:write', $context) && $showcommonelements ) { 00364 echo '<div class="singlebutton glossaryaddentry">'; 00365 echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">"; 00366 echo '<div>'; 00367 echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />"; 00368 echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />'; 00369 echo '</div>'; 00370 echo '</form>'; 00371 echo "</div>\n"; 00372 } 00373 00374 echo '<br />'; 00375 00376 require("tabs.php"); 00377 00378 require("sql.php"); 00379 00381 $entriesshown = 0; 00382 $currentpivot = ''; 00383 $paging = NULL; 00384 00385 if ($allentries) { 00386 00387 //Decide if we must show the ALL link in the pagebar 00388 $specialtext = ''; 00389 if ($glossary->showall) { 00390 $specialtext = get_string("allentries","glossary"); 00391 } 00392 00393 //Build paging bar 00394 $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,' ', $specialtext, -1); 00395 00396 echo '<div class="paging">'; 00397 echo $paging; 00398 echo '</div>'; 00399 00400 //load ratings 00401 require_once($CFG->dirroot.'/rating/lib.php'); 00402 if ($glossary->assessed != RATING_AGGREGATE_NONE) { 00403 $ratingoptions = new stdClass; 00404 $ratingoptions->context = $context; 00405 $ratingoptions->component = 'mod_glossary'; 00406 $ratingoptions->ratingarea = 'entry'; 00407 $ratingoptions->items = $allentries; 00408 $ratingoptions->aggregate = $glossary->assessed;//the aggregation method 00409 $ratingoptions->scaleid = $glossary->scale; 00410 $ratingoptions->userid = $USER->id; 00411 $ratingoptions->returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id; 00412 $ratingoptions->assesstimestart = $glossary->assesstimestart; 00413 $ratingoptions->assesstimefinish = $glossary->assesstimefinish; 00414 00415 $rm = new rating_manager(); 00416 $allentries = $rm->get_ratings($ratingoptions); 00417 } 00418 00419 foreach ($allentries as $entry) { 00420 00421 // Setting the pivot for the current entry 00422 $pivot = $entry->glossarypivot; 00423 $upperpivot = $textlib->strtoupper($pivot); 00424 $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions)); 00425 // Reduce pivot to 1cc if necessary 00426 if ( !$fullpivot ) { 00427 $upperpivot = $textlib->substr($upperpivot, 0, 1); 00428 $pivottoshow = $textlib->substr($pivottoshow, 0, 1); 00429 } 00430 00431 // if there's a group break 00432 if ( $currentpivot != $upperpivot ) { 00433 00434 // print the group break if apply 00435 if ( $printpivot ) { 00436 $currentpivot = $upperpivot; 00437 00438 echo '<div>'; 00439 echo '<table cellspacing="0" class="glossarycategoryheader">'; 00440 00441 echo '<tr>'; 00442 if ( isset($entry->userispivot) ) { 00443 // printing the user icon if defined (only when browsing authors) 00444 echo '<th align="left">'; 00445 00446 $user = $DB->get_record("user", array("id"=>$entry->userid)); 00447 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id)); 00448 $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); 00449 } else { 00450 echo '<th >'; 00451 } 00452 00453 echo $OUTPUT->heading($pivottoshow); 00454 echo "</th></tr></table></div>\n"; 00455 00456 } 00457 } 00458 00460 if ($mode == 'search') { 00461 //We have to strip any word starting by + and take out words starting by - 00462 //to make highlight works properly 00463 $searchterms = explode(' ', $hook); // Search for words independently 00464 foreach ($searchterms as $key => $searchterm) { 00465 if (preg_match('/^\-/',$searchterm)) { 00466 unset($searchterms[$key]); 00467 } else { 00468 $searchterms[$key] = preg_replace('/^\+/','',$searchterm); 00469 } 00470 //Avoid highlight of <2 len strings. It's a well known hilight limitation. 00471 if (strlen($searchterm) < 2) { 00472 unset($searchterms[$key]); 00473 } 00474 } 00475 $strippedsearch = implode(' ', $searchterms); // Rebuild the string 00476 $entry->highlight = $strippedsearch; 00477 } 00478 00480 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat); 00481 $entriesshown++; 00482 } 00483 } 00484 if ( !$entriesshown ) { 00485 echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide"); 00486 } 00487 00488 if (!empty($formsent)) { 00489 // close the form properly if used 00490 echo "</div>"; 00491 echo "</form>"; 00492 } 00493 00494 if ( $paging ) { 00495 echo '<hr />'; 00496 echo '<div class="paging">'; 00497 echo $paging; 00498 echo '</div>'; 00499 } 00500 echo '<br />'; 00501 glossary_print_tabbed_table_end(); 00502 00504 echo $OUTPUT->footer();