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