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