- Not Categorized is now the default view for category tab.
[moodle.git] / mod / glossary / lib.php
CommitLineData
07842023 1<?PHP // $Id$
2
3/// Library of functions and constants for module glossary
4/// (replace glossary with the name of your module and delete this line)
5
e179048e 6require_once("$CFG->dirroot/files/mimetypes.php");
07842023 7
fb443f1a 8$tCFG->TabTableBGColor = $THEME->cellcontent2;
9$tCFG->TabTableWidth = "70%";
10$tCFG->ActiveTabColor = $THEME->cellcontent2;
11$tCFG->InactiveTabColor = $THEME->cellheading2;
12$tCFG->TabsPerRow = 5;
13$tCFG->TabSeparation = 4;
14
07842023 15function glossary_add_instance($glossary) {
16/// Given an object containing all the necessary data,
17/// (defined by the form in mod.html) this function
18/// will create a new instance and return the id number
19/// of the new instance.
20
21 $glossary->timecreated = time();
22 $glossary->timemodified = $glossary->timecreated;
23
24 # May have to add extra stuff in here #
25
26 return insert_record("glossary", $glossary);
27}
28
29
30function glossary_update_instance($glossary) {
31/// Given an object containing all the necessary data,
32/// (defined by the form in mod.html) this function
33/// will update an existing instance with new data.
34
35 $glossary->timemodified = time();
36 $glossary->id = $glossary->instance;
37
38 # May have to add extra stuff in here #
39
40 return update_record("glossary", $glossary);
41}
42
43
44function glossary_delete_instance($id) {
45/// Given an ID of an instance of this module,
46/// this function will permanently delete the instance
47/// and any data that depends on it.
48
49 if (! $glossary = get_record("glossary", "id", "$id")) {
50 return false;
51 }
52
53 $result = true;
54
55 # Delete any dependent records here #
56
57 if (! delete_records("glossary", "id", "$glossary->id")) {
58 $result = false;
59 }
60 delete_records("glossary_entries", "glossaryid", "$glossary->id");
61
62 return $result;
63}
64
65function glossary_user_outline($course, $user, $mod, $glossary) {
66/// Return a small object with summary information about what a
67/// user has done with a given particular instance of this module
68/// Used for user activity reports.
69/// $return->time = the time they did it
70/// $return->info = a short text description
71
72 return $return;
73}
74
75function glossary_user_complete($course, $user, $mod, $glossary) {
76/// Print a detailed representation of what a user has done with
77/// a given particular instance of this module, for user activity reports.
78
79 return true;
80}
81
82function glossary_print_recent_activity($course, $isteacher, $timestart) {
83/// Given a course and a time, this module should find recent activity
84/// that has occurred in glossary activities and print it out.
85/// Return true if there was output, or false is there was none.
86
87 global $CFG, $THEME;
88
89 if (!$logs = get_records_select("log", "time > '$timestart' AND ".
90 "course = '$course->id' AND ".
91 "module = 'glossary' AND ".
92 "action = 'add %' ", "time ASC")) {
93 return false;
94 }
95
07842023 96 foreach ($logs as $log) {
97 //Create a temp valid module structure (course,id)
98 $tempmod->course = $log->course;
99 $tempmod->id = $log->info;
100 //Obtain the visible property from the instance
101 $modvisible = instance_is_visible($log->module,$tempmod);
07842023 102
103 //Only if the mod is visible
104 if ($modvisible) {
105 $entries[$log->info] = glossary_log_info($log);
106 $entries[$log->info]->time = $log->time;
107 $entries[$log->info]->url = $log->url;
108 }
07842023 109 }
110
07842023 111 $content = false;
112 if ($entries) {
113 $strftimerecent = get_string("strftimerecent");
114 $content = true;
115 print_headline(get_string("newentries", "glossary").":");
116 foreach ($entries as $entry) {
117 $date = userdate($entry->timemodified, $strftimerecent);
118 echo "<p><font size=1>$date - $entry->firstname $entry->lastname<br>";
119 echo "\"<a href=\"$CFG->wwwroot/mod/glossary/$entry->url\">";
120 echo "$entry->concept";
121 echo "</a>\"</font></p>";
122 }
123 }
124
125 return $content;
126}
127
128function glossary_cron () {
129/// Function to be run periodically according to the moodle cron
130/// This function searches for things that need to be done, such
131/// as sending out mail, toggling flags etc ...
132
133 global $CFG;
134
135 return true;
136}
137
138function glossary_grades($glossaryid) {
139/// Must return an array of grades for a given instance of this module,
140/// indexed by user. It also returns a maximum allowed grade.
141
142 $return->grades = NULL;
143 $return->maxgrade = NULL;
144
145 return $return;
146}
147
148
149//////////////////////////////////////////////////////////////////////////////////////
150/// Any other glossary functions go here. Each of them must have a name that
151/// starts with glossary_
152
153function glossary_log_info($log) {
154 global $CFG;
155 return get_record_sql("SELECT g.*, u.firstname, u.lastname
156 FROM {$CFG->prefix}glossary_entries g,
157 {$CFG->prefix}user u
158 WHERE g.glossaryid = '$log->info'
159 AND u.id = '$log->userid'");
160}
161
162function glossary_get_entries($glossaryid, $entrylist) {
163 global $CFG;
164
165 return get_records_sql("SELECT id,userid,concept,definition,format
166 FROM {$CFG->prefix}glossary_entries
167 WHERE glossaryid = '$glossaryid'
168 AND id IN ($entrylist)");
169}
170
fb443f1a 171function glossary_print_entry($course, $cm, $glossary, $entry,$currentview="",$cat="") {
914cb260 172 global $THEME, $USER, $CFG;
e179048e 173
174 $PermissionGranted = 0;
175 $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
176 $functionname = "glossary_print_entry_by_format";
177
178 if ( $glossary->displayformat > 0 ) {
179 if ( file_exists($formatfile) ) {
180 include_once($formatfile);
181 if (function_exists($functionname) ) {
182 $PermissionGranted = 1;
183 }
184 }
07842023 185 } else {
e179048e 186 $PermissionGranted = 1;
07842023 187 }
06d94a52 188
e179048e 189 if ( $glossary->displayformat > 0 and $PermissionGranted ) {
fb443f1a 190 glossary_print_entry_by_format($course, $cm, $glossary, $entry,$currentview,$cat);
07842023 191 } else {
fb443f1a 192 glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat);
07842023 193 }
07842023 194
07842023 195}
196
fb443f1a 197function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview="",$cat="") {
07842023 198 global $THEME, $USER;
199
200 $colour = $THEME->cellheading2;
201
202 echo "\n<TR>";
e179048e 203 echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
204 if ($entry->attachment) {
205 $entry->course = $course->id;
206 echo "<table border=0 align=right><tr><td>";
207 echo glossary_print_attachments($entry,"html");
208 echo "</td></tr></table>";
209 }
210 echo "<b>$entry->concept</b>: ";
07842023 211 echo format_text($entry->definition, $entry->format);
fb443f1a 212 glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
07842023 213 echo "</td>";
214 echo "</TR>";
215}
216
fb443f1a 217function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") {
07842023 218 global $THEME, $USER;
219
ad58adac 220 $ImportedEntry = ($entry->sourceglossaryid == $glossary->id);
221 $IsTeacher = isteacher($course->id);
222 $IsMainGlossary = $glossary->mainglossary;
223
224 if ($IsTeacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
07842023 225 echo "<p align=right>";
ad58adac 226 // only teachers can export entries so check it out
227 if ($IsTeacher and !$IsMainGlossary and !$ImportedEntry) {
07842023 228 $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
ad58adac 229 if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
230
231 echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
07842023 232
233 }
234 }
ad58adac 235
236 if ( $entry->sourceglossaryid ) {
237 $icon = "minus.gif"; // graphical metaphor (minus) for deleting an imported entry
238 } else {
239 $icon = "../../pix/t/delete.gif";
240 }
241
242 // Exported entries can be updated/deleted only by teachers in the main glossary
243 if ( !$ImportedEntry and ($IsTeacher or !$IsMainGlossary) ) {
244 echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("delete") . "\"src=\"";
245 echo $icon;
246 echo "\" height=11 width=11 border=0></a> ";
247
248 echo "<a href=\"edit.php?id=$cm->id&e=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
249 } elseif ( $ImportedEntry ) {
250 echo "<font size=-1>" . get_string("exportedentry","glossary") . "</font>";
251 }
252 }
07842023 253}
254
255function glossary_search_entries($searchterms, $glossary, $includedefinition) {
256/// Returns a list of entries found using an array of search terms
257/// eg word +word -word
258///
259
260 global $CFG;
261
262 if (!isteacher($glossary->course)) {
263 $glossarymodule = get_record("modules", "name", "glossary");
6a22879b 264 $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
07842023 265 $onlyvisibletable = ", {$CFG->prefix}course_modules cm";
266 } else {
267
268 $onlyvisible = "";
269 $onlyvisibletable = "";
270 }
271
272 /// Some differences in syntax for PostgreSQL
273 if ($CFG->dbtype == "postgres7") {
274 $LIKE = "ILIKE"; // case-insensitive
275 $NOTLIKE = "NOT ILIKE"; // case-insensitive
276 $REGEXP = "~*";
277 $NOTREGEXP = "!~*";
278 } else {
279 $LIKE = "LIKE";
280 $NOTLIKE = "NOT LIKE";
281 $REGEXP = "REGEXP";
282 $NOTREGEXP = "NOT REGEXP";
283 }
284
285 $conceptsearch = "";
286 $definitionsearch = "";
287
288
289 foreach ($searchterms as $searchterm) {
290 if (strlen($searchterm) < 2) {
291 continue;
292 }
293 if ($conceptsearch) {
294 $conceptsearch.= " OR ";
295 }
296 if ($definitionsearch) {
297 $definitionsearch.= " OR ";
298 }
299
300 if (substr($searchterm,0,1) == "+") {
301 $searchterm = substr($searchterm,1);
302 $conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
303 $definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
304 } else if (substr($searchterm,0,1) == "-") {
305 $searchterm = substr($searchterm,1);
306 $conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
307 $definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
308 } else {
309 $conceptsearch .= " e.concept $LIKE '%$searchterm%' ";
310 $definitionsearch .= " e.definition $LIKE '%$searchterm%' ";
311 }
312 }
313
314 if ( !$includedefinition ) {
315 $definitionsearch = "0";
316 }
317
318 $selectsql = "{$CFG->prefix}glossary_entries e,
319 {$CFG->prefix}glossary g $onlyvisibletable
320 WHERE ($conceptsearch OR $definitionsearch)
ad58adac 321 AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
07842023 322 AND g.id = $glossary->id";
323
324 $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
325
326 return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format FROM
327 $selectsql ORDER BY e.concept ASC $limit");
328}
329
330function glossary_get_participants($glossaryid) {
331//Returns the users with data in one glossary
332//(users with records in glossary_entries, students)
333
334 global $CFG;
335
336 //Get students
337 $students = get_records_sql("SELECT DISTINCT u.*
338 FROM {$CFG->prefix}user u,
339 {$CFG->prefix}glossary_entries g
340 WHERE g.glossaryid = '$glossaryid' and
341 u.id = g.userid");
342
343 //Return students array (it contains an array of unique users)
344 return ($students);
345}
346
e179048e 347
348function glossary_file_area_name($entry) {
349// Creates a directory file name, suitable for make_upload_directory()
350 global $CFG;
351
352 return "$entry->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id";
353}
354
355function glossary_file_area($entry) {
356 return make_upload_directory( glossary_file_area_name($entry) );
357}
358
359function glossary_delete_old_attachments($entry, $exception="") {
360// Deletes all the user files in the attachments area for a entry
361// EXCEPT for any file named $exception
362
363 if ($basedir = glossary_file_area($entry)) {
364 if ($files = get_directory_list($basedir)) {
365 foreach ($files as $file) {
366 if ($file != $exception) {
367 unlink("$basedir/$file");
368// notify("Existing file '$file' has been deleted!");
369 }
370 }
371 }
372 if (!$exception) { // Delete directory as well, if empty
373 rmdir("$basedir");
374 }
375 }
376}
377
378function glossary_copy_attachments($entry, $newentry) {
379/// Given a entry object that is being copied to glossaryid,
380/// this function checks that entry
381/// for attachments, and if any are found, these are
382/// copied to the new glossary directory.
383
384 global $CFG;
385
386 $return = true;
387
388 if ($entries = get_records_select("glossary_entries", "id = '$entry->id' AND attachment <> ''")) {
389 foreach ($entries as $curentry) {
390 $oldentry->id = $entry->id;
391 $oldentry->course = $entry->course;
392 $oldentry->glossaryid = $curentry->glossaryid;
393 $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
394 if (is_dir($oldentrydir)) {
395
396 $newentrydir = glossary_file_area($newentry);
397 if (! copy("$oldentrydir/$newentry->attachment", "$newentrydir/$newentry->attachment")) {
398 $return = false;
399 }
400 }
401 }
402 }
403 return $return;
404}
405
406function glossary_move_attachments($entry, $glossaryid) {
407/// Given a entry object that is being moved to glossaryid,
408/// this function checks that entry
409/// for attachments, and if any are found, these are
410/// moved to the new glossary directory.
411
412 global $CFG;
413
414 $return = true;
415
416 if ($entries = get_records_select("glossary_entries", "glossaryid = '$entry->id' AND attachment <> ''")) {
417 foreach ($entries as $entry) {
418 $oldentry->course = $entry->course;
419 $oldentry->glossaryid = $entry->glossaryid;
420 $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
421 if (is_dir($oldentrydir)) {
422 $newentry = $oldentry;
423 $newentry->glossaryid = $glossaryid;
424 $newentrydir = "$CFG->dataroot/".glossary_file_area_name($newentry);
425 if (! @rename($oldentrydir, $newentrydir)) {
426 $return = false;
427 }
428 }
429 }
430 }
431 return $return;
432}
433
434function glossary_add_attachment($entry, $newfile) {
435// $entry is a full entry record, including course and glossary
436// $newfile is a full upload array from $_FILES
437// If successful, this function returns the name of the file
438
439 global $CFG;
440
441 if (empty($newfile['name'])) {
442 return "";
443 }
444
445 $newfile_name = clean_filename($newfile['name']);
446
447 if (valid_uploaded_file($newfile)) {
448 if (! $newfile_name) {
449 notify("This file had a wierd filename and couldn't be uploaded");
450
451 } else if (! $dir = glossary_file_area($entry)) {
452 notify("Attachment could not be stored");
453 $newfile_name = "";
454
455 } else {
456 if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
457 chmod("$dir/$newfile_name", $CFG->directorypermissions);
458 glossary_delete_old_attachments($entry, $newfile_name);
459 } else {
460 notify("An error happened while saving the file on the server");
461 $newfile_name = "";
462 }
463 }
464 } else {
465 $newfile_name = "";
466 }
467
468 return $newfile_name;
469}
470
471function glossary_print_attachments($entry, $return=NULL) {
472// if return=html, then return a html string.
473// if return=text, then return a text-only string.
474// otherwise, print HTML for non-images, and return image HTML
475
476 global $CFG;
477
478 $filearea = glossary_file_area_name($entry);
479
480 $imagereturn = "";
481 $output = "";
482
483 if ($basedir = glossary_file_area($entry)) {
484 if ($files = get_directory_list($basedir)) {
485 $strattachment = get_string("attachment", "glossary");
486 $strpopupwindow = get_string("popupwindow");
487 foreach ($files as $file) {
488 $icon = mimeinfo("icon", $file);
489 if ($CFG->slasharguments) {
490 $ffurl = "file.php/$filearea/$file";
491 } else {
492 $ffurl = "file.php?file=/$filearea/$file";
493 }
494 $image = "<img border=0 src=\"$CFG->wwwroot/files/pix/$icon\" height=16 width=16 alt=\"$strpopupwindow\">";
495
496 if ($return == "html") {
497 $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$image</a> ";
498 $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a><br />";
499 } else if ($return == "text") {
500 $output .= "$strattachment $file:\n$CFG->wwwroot/$ffurl\n";
501
502 } else {
503 if ($icon == "image.gif") { // Image attachments don't get printed as links
504 $imagereturn .= "<br /><img src=\"$CFG->wwwroot/$ffurl\">";
505 } else {
506 link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment);
507 echo "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a>";
508 echo "<br />";
509 }
510 }
511 }
512 }
513 }
514
515 if ($return) {
516 return $output;
517 }
518
519 return $imagereturn;
520}
521
ad58adac 522function glossary_print_tabbed_table_start($data, $CurrentTab, $tTHEME = NULL) {
06d94a52 523
524if ( !$tTHEME ) {
525 global $THEME;
526 $tTHEME = $THEME;
527}
528
529$TableColor = $tTHEME->TabTableBGColor;
530$TableWidth = $tTHEME->TabTableWidth;
531$CurrentTabColor = $tTHEME->ActiveTabColor;
532$TabColor = $tTHEME->InactiveTabColor;
533$TabsPerRow = $tTHEME->TabsPerRow;
534$TabSeparation = $tTHEME->TabSeparation;
535
536$Tabs = count($data);
537$TabWidth = (int) (100 / $TabsPerRow);
538
539$CurrentRow = ( $CurrentTab - ( $CurrentTab % $TabsPerRow) ) / $TabsPerRow;
540
541$NumRows = (int) ( $Tabs / $TabsPerRow ) + 1;
542
543?>
544 <center>
ad58adac 545 <table border="0" cellpadding="0" cellspacing="0" width="<?php p($TableWidth) ?>">
06d94a52 546 <tr>
547 <td width="100%">
548
549 <table border="0" cellpadding="0" cellspacing="0" width="100%">
550
ad58adac 551<?php
06d94a52 552$TabProccessed = 0;
553for ($row = 0; $row < $NumRows; $row++) {
554 echo "<tr>\n";
555 if ( $row != $CurrentRow ) {
556 for ($col = 0; $col < $TabsPerRow; $col++) {
557 if ( $TabProccessed < $Tabs ) {
ad58adac 558 if ( $col == 0 ) {
559 echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
560 }
06d94a52 561 if ($TabProccessed == $CurrentTab) {
562 $CurrentColor = $CurrentTabColor;
563 } else {
564 $CurrentColor = $TabColor;
565 }
914cb260 566
567 echo "<td width=\"$TabWidth%\" bgcolor=\"$CurrentColor\" align=\"center\"><b>";
568 if ($TabProccessed != $CurrentTab) {
569 echo "<a href=\"" . $data[$TabProccessed]->link . "\">";
570 }
571 echo $data[$TabProccessed]->caption;
572 if ($TabProccessed != $CurrentTab) {
573 echo "</a>";
574 }
575 echo "</b></td>";
576
577 if ( $col < $TabsPerRow ) {
578 echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
579 }
06d94a52 580 } else {
581 $CurrentColor = "";
582 }
583 $TabProccessed++;
584 }
585 } else {
586 $FirstTabInCurrentRow = $TabProccessed;
587 $TabProccessed += $TabsPerRow;
588 }
589 echo "</tr><tr><td colspan=" . (2* $TabsPerRow) . " ></td></tr>\n";
590}
591 echo "<tr>\n";
592 $TabProccessed = $FirstTabInCurrentRow;
593 for ($col = 0; $col < $TabsPerRow; $col++) {
594 if ( $TabProccessed < $Tabs ) {
ad58adac 595 if ( $col == 0 ) {
596 echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
597 }
06d94a52 598 if ($TabProccessed == $CurrentTab) {
599 $CurrentColor = $CurrentTabColor;
600 } else {
601 $CurrentColor = $TabColor;
602 }
914cb260 603 echo "<td width=\"$TabWidth%\" bgcolor=\"$CurrentColor\" align=\"center\"><b>";
604 if ($TabProccessed != $CurrentTab) {
605 echo "<a href=\"" . $data[$TabProccessed]->link . "\">";
606 }
607 echo $data[$TabProccessed]->caption;
608 if ($TabProccessed != $CurrentTab) {
609 echo "</a>";
610 }
611 echo "</b></td>";
612
613 if ($col < $TabsPerRow) {
614 echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
615 }
06d94a52 616 } else {
617 if ($NumRows > 1) {
618 $CurrentColor = $TabColor;
619 } else {
620 $CurrentColor = "";
621 }
622 echo "<td colspan = " . (2 * ($TabsPerRow - $col)) . " bgcolor=\"$CurrentColor\" align=\"center\">";
623 echo "</td>";
624
625 $col = $TabsPerRow;
626 }
627 $TabProccessed++;
628 }
629 echo "</tr>\n";
630 ?>
631
632 </table>
633 </td>
634 </tr>
635 <tr>
ad58adac 636 <td width="100%" bgcolor="<?php p($TableColor) ?>"><hr></td>
06d94a52 637 </tr>
638 <tr>
ad58adac 639 <td width="100%" bgcolor="<?php p($TableColor) ?>">
06d94a52 640 <center>
ad58adac 641<?php
06d94a52 642}
643
ad58adac 644function glossary_print_tabbed_table_end() {
06d94a52 645 echo "</center><p></td></tr></table></center>";
646}
647
fb443f1a 648function glossary_print_alphabet_menu($cm, $glossary, $l) {
649global $CFG, $THEME;
650 $strselectletter = get_string("selectletter", "glossary");
651 $strspecial = get_string("special", "glossary");
652 $strallentries = get_string("allentries", "glossary");
653
914cb260 654 if ($glossary->showalphabet) {
655 $output .= get_string("explainalphabet","glossary");
656 }
657 if ($glossary->showspecial) {
658 $output .= get_string("explainspecial","glossary");
659 }
660 if ($glossary->showall) {
661 $output .= get_string("explainall","glossary");
662 }
663
664 echo "<CENTER>$output<p>";
fb443f1a 665
666 if ( $glossary->showspecial ) {
667 if ( $l == "SPECIAL" ) {
914cb260 668 echo "<b>$strspecial</b> | ";
fb443f1a 669 } else {
914cb260 670 echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial</a> | ";
fb443f1a 671 }
672 }
673
674 if ( $glossary->showalphabet ) {
675 $alphabet = explode("|", get_string("alphabet","glossary"));
676 $letters_by_line = 14;
677 for ($i = 0; $i < count($alphabet); $i++) {
678 if ( $l == $alphabet[$i] ) {
679 echo "<b>$alphabet[$i]</b>";
680 } else {
681 echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]</a>";
682 }
683 if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
684 echo " | ";
685 } else {
686 echo "<br>";
687 }
688 }
689 }
690
691 if ( $glossary->showall ) {
692 if ( $l == "ALL" ) {
693 echo "<b>$strallentries</b></p>";
694 } else {
695 echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries</a></p>";
696 }
697 }
698}
914cb260 699function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
fb443f1a 700global $CFG, $THEME;
701 echo "<table border=0 width=100%>";
702 echo "<tr>";
703
704 echo "<td align=center width=20%>";
705 if ( isteacher($course->id) ) {
706 $options['id'] = $cm->id;
707 $options['cat'] = $cat;
708 echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
709 }
710 echo "</td>";
711
712 echo "<td align=center width=60%>";
713 echo "<b>";
3122e8f3 714
715 $menu["-1"] = get_string("allcategories","glossary");
716 $menu["0"] = get_string("nocategorized","glossary");
717
718 $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
719 if ( $categories ) {
720 foreach ($categories as $currentcategory) {
721 $url = $currentcategory->id;
722 if ( $category ) {
723 if ($currentcategory->id == $category->id) {
724 $selected = $url;
725 }
726 }
727 $menu[$url] = $currentcategory->name;
728 }
729 }
730 if ( !$selected ) {
731 $selected = "0";
732 }
733
fb443f1a 734 if ( $category ) {
735 echo $category->name;
736 } else {
914cb260 737 if ( $cat < 0 ) {
3122e8f3 738 echo get_string("allcategories","glossary");
914cb260 739 $selected = "-1";
740 } elseif ( $cat == 0 ) {
3122e8f3 741 echo get_string("entrieswithoutcategory","glossary");
914cb260 742 $selected = "0";
743 }
fb443f1a 744 }
745 echo "</b></td>";
746 echo "<td align=center width=20%>";
fb443f1a 747
914cb260 748 echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&currentview=categories&cat=", $menu, "catmenu", $selected, "",
fb443f1a 749 "", "", false);
750
751 echo "</td>";
752 echo "</tr>";
753
754 echo "<tr><td colspan=3><hr></td></tr>";
755 echo "</table>";
756}
ad58adac 757
758function glossary_sort_entries ( $entry0, $entry1 ) {
759 if ( strtolower(ltrim($entry0->concept)) < strtolower(ltrim($entry1->concept)) ) {
760 return -1;
761 } elseif ( strtolower(ltrim($entry0->concept)) > strtolower(ltrim($entry1->concept)) ) {
762 return 1;
763 } else {
764 return 0;
765 }
766}
767
e179048e 768?>