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