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