Removed unnecessary code (maxlogs)
[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;
677038ee 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");
721
722 $output = "";
723 if ($glossary->showalphabet) {
724 $output .= get_string("explainalphabet","glossary").'<br />';
725 }
726
727 echo "<center>$output<p>";
728
729 if ( $glossary->showspecial ) {
730 if ( $l == "SPECIAL" ) {
731 echo "<b>$strspecial</b> | ";
732 } else {
733 $strexplainspecial = strip_tags(get_string("explainspecial","glossary"));
734 echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial</a> | ";
735 }
914cb260 736 }
677038ee 737
738 if ( $glossary->showalphabet ) {
739 $alphabet = explode("|", get_string("alphabet","glossary"));
740 $letters_by_line = 14;
741 for ($i = 0; $i < count($alphabet); $i++) {
742 if ( $l == $alphabet[$i] and $l) {
743 echo "<b>$alphabet[$i]</b>";
744 } else {
745 echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]</a>";
746 }
747 if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
748 echo " | ";
749 } else {
750 echo "<br>";
751 }
767a31c3 752 }
677038ee 753 }
754
755 if ( $glossary->showall ) {
756 if ( $l == "ALL" ) {
757 echo "<b>$strallentries</b>";
758 } else {
759 $strexplainall = strip_tags(get_string("explainall","glossary"));
760 echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries</a>";
761 }
762 }
763 $neworder = "";
764 if ( $sortorder ) {
765 if ( $sortorder == "asc" ) {
766 $neworder = "&sortorder=desc";
767 $ordertitle = get_string("descending","glossary");
768 } else {
769 $neworder = "&sortorder=asc";
770 $ordertitle = get_string("ascending","glossary");
771 }
772 $icon = " <img src=\"$sortorder.gif\" border=0 width=16 height=16>";
773 } else {
774 if ( $sortkey != "CREATION" and $sortkey != "UPDATE" ) {
775 $icon = "";
776 $ordertitle = get_string("ascending","glossary");
777 } else {
778 $ordertitle = get_string("descending","glossary");
779 $neworder = "&sortorder=desc";
780 $icon = " <img src=\"asc.gif\" border=0 width=16 height=16>";
781 }
782 }
783 $cicon = "";
784 $cneworder = "";
785 $cbtag = "";
786 $cendbtag = "";
787
788 $uicon = "";
789 $uneworder = "";
790 $ubtag = "";
791 $uendbtag = "";
792
793 if ( $sortkey == "CREATION" ) {
794 $cicon = $icon;
795 $cneworder = $neworder;
796 $cordertitle = $ordertitle;
797 $uordertitle = get_string("ascending","glossary");
798 $cbtag = "<b>";
799 $cendbtag = "</b>";
800 } elseif ($sortkey == "UPDATE") {
801 $uicon = $icon;
802 $uneworder = $neworder;
803 $cordertitle = get_string("ascending","glossary");
804 $uordertitle = $ordertitle;
805 $ubtag = "<b>";
806 $uendbtag = "</b>";
807 } else {
808 $cordertitle = get_string("ascending","glossary");
809 $uordertitle = get_string("ascending","glossary");
810 }
811 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 | ".
812 "$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder\">$strsortbycreation$cicon</a>$cendbtag</p>";
fb443f1a 813}
677038ee 814
914cb260 815function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
fb443f1a 816global $CFG, $THEME;
817 echo "<table border=0 width=100%>";
818 echo "<tr>";
819
820 echo "<td align=center width=20%>";
821 if ( isteacher($course->id) ) {
822 $options['id'] = $cm->id;
823 $options['cat'] = $cat;
824 echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
825 }
826 echo "</td>";
827
828 echo "<td align=center width=60%>";
829 echo "<b>";
3122e8f3 830
7dd88447 831 $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
832 $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
3122e8f3 833
834 $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
835 if ( $categories ) {
836 foreach ($categories as $currentcategory) {
837 $url = $currentcategory->id;
838 if ( $category ) {
839 if ($currentcategory->id == $category->id) {
840 $selected = $url;
841 }
842 }
843 $menu[$url] = $currentcategory->name;
844 }
845 }
846 if ( !$selected ) {
7dd88447 847 $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
3122e8f3 848 }
849
fb443f1a 850 if ( $category ) {
851 echo $category->name;
852 } else {
7dd88447 853 if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
854
3122e8f3 855 echo get_string("entrieswithoutcategory","glossary");
7dd88447 856 $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
857
858 } elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
859
860 echo get_string("allcategories","glossary");
861 $selected = GLOSSARY_SHOW_ALL_CATEGORIES;
862
914cb260 863 }
fb443f1a 864 }
865 echo "</b></td>";
866 echo "<td align=center width=20%>";
fb443f1a 867
914cb260 868 echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&currentview=categories&cat=", $menu, "catmenu", $selected, "",
fb443f1a 869 "", "", false);
870
871 echo "</td>";
872 echo "</tr>";
873
874 echo "<tr><td colspan=3><hr></td></tr>";
875 echo "</table>";
876}
ad58adac 877
878function glossary_sort_entries ( $entry0, $entry1 ) {
879 if ( strtolower(ltrim($entry0->concept)) < strtolower(ltrim($entry1->concept)) ) {
880 return -1;
881 } elseif ( strtolower(ltrim($entry0->concept)) > strtolower(ltrim($entry1->concept)) ) {
882 return 1;
883 } else {
884 return 0;
885 }
886}
887
ed0201dd 888function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
889 global $THEME, $CFG, $USER;
890
891// if ($entry->timemarked < $entry->modified) {
892 $colour = $THEME->cellheading2;
893// } else {
894// $colour = $THEME->cellheading;
895// }
896
897 $user = get_record("user", "id", $comment->userid);
898 $strby = get_string("writtenby","glossary");
899
900 echo "<table class=\"generalbox\" BORDER=1 CELLSPACING=0 valign=top cellpadding=0 width=70% border=0><tr><td>";
901
902 echo "\n<TABLE width=\"100%\" BORDER=0 CELLSPACING=0 valign=top cellpadding=5><tr>";
903
904 echo "\n<TD BGCOLOR=\"$THEME->cellheading\" WIDTH=25% VALIGN=TOP align=right >";
905 print_user_picture($user->id, $course->id, $user->picture);
906 echo "<br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
907 echo "<br><FONT SIZE=1>(".get_string("lastedited").": ".userdate($comment->timemodified).")</FONT></small><br>";
908 echo "</TD>";
909
910 echo "<TD NOWRAP valign=top WIDTH=75% BGCOLOR=\"$THEME->cellcontent\">";
911 if ($comment) {
912 echo format_text($comment->comment, $comment->format);
913 } else {
914 echo "<center>";
915 print_string("nocomment", "glossary");
916 echo "</center>";
917 }
918
919 echo "<p align=right>";
920 if ( (time() - $comment->timemodified < $CFG->maxeditingtime and $USER->id == $comment->userid) or isteacher($course->id) ) {
921 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> ";
922 }
923 if ( $USER->id == $comment->userid or isteacher($course->id) ) {
924 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>";
925 }
926 echo "</td>";
927
928 echo "</tr></TABLE>\n";
929
930 echo "</td></tr></table>";
931}
932
cca6f7f1 933 function glossary_print_dynaentry($courseid, $entries) {
934 global $THEME, $USER;
935
936 $colour = $THEME->cellheading2;
937
938 echo "\n<center><table width=95% border=0><tr>";
939 echo "<td width=100%\">";
940 if ( $entries ) {
941 foreach ( $entries as $entry ) {
942
943 if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) {
944 error("Glossary ID was incorrect or no longer exists");
945 }
946 if (! $course = get_record("course", "id", $glossary->course)) {
947 error("Glossary is misconfigured - don't know what course it's from");
948 }
949 if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) {
950 error("Glossary is misconfigured - don't know what course module it is ");
951 }
952
953 glossary_print_entry($course, $cm, $glossary, $entry);
954 }
955 }
956 echo "</td>";
957 echo "</tr></table></center>";
958 }
e179048e 959?>