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