File translation terminated
[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}
252
c76e673a 253function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="",$cat="") {
07842023 254 global $THEME, $USER;
255
256 $colour = $THEME->cellheading2;
257
258 echo "\n<TR>";
c76e673a 259 echo "<TD WIDTH=100% valign=\"top\" BGCOLOR=\"#FFFFFF\">";
260 if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
261 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>";
262 }
e179048e 263 if ($entry->attachment) {
264 $entry->course = $course->id;
265 echo "<table border=0 align=right><tr><td>";
266 echo glossary_print_attachments($entry,"html");
267 echo "</td></tr></table>";
268 }
269 echo "<b>$entry->concept</b>: ";
07842023 270 echo format_text($entry->definition, $entry->format);
c76e673a 271 glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
07842023 272 echo "</td>";
273 echo "</TR>";
274}
275
c76e673a 276function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab="",$cat="") {
767a31c3 277 global $THEME, $USER;
278 if ($entry) {
c76e673a 279 if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
280 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>";
281 }
767a31c3 282 if ($entry->attachment) {
283 $entry->course = $course->id;
284 echo "<table border=0 align=right><tr><td>";
285 echo glossary_print_attachments($entry, "html");
286 echo "</td></tr></table>";
287 }
288 echo " $entry->concept ";
289 echo format_text($entry->definition, $entry->format);
290
c76e673a 291 glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
767a31c3 292 }
293}
c76e673a 294function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat="") {
07842023 295 global $THEME, $USER;
296
7dd88447 297 $importedentry = ($entry->sourceglossaryid == $glossary->id);
d88824c4 298 $isteacher = isteacher($course->id);
7dd88447 299 $ismainglossary = $glossary->mainglossary;
891ae55e 300
c76e673a 301 echo "<p align=\"right\"><font size=1>";
891ae55e 302
c76e673a 303 if (!$entry->approved) {
304 echo get_string("entryishidden","glossary");
305 }
dc36351d 306 $count = count_records("glossary_comments","entryid",$entry->id);
c1e97fe5 307 if ($count) {
c76e673a 308 echo " <a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
c1e97fe5 309 if ($count == 1) {
310 print_string("comment", "glossary");
311 } else {
312 print_string("comments", "glossary");
313 }
c76e673a 314 echo "</a>";
dc36351d 315 }
c76e673a 316 echo "</font>";
c197e607 317 if ( $glossary->allowcomments and !isguest()) {
c76e673a 318 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 319 }
dc36351d 320
ed0201dd 321 if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
322 // only teachers can export entries so check it out
ed0201dd 323 if ($isteacher and !$ismainglossary and !$importedentry) {
324 $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
325 if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
326
c76e673a 327 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 328
ed0201dd 329 }
330 }
331
ad58adac 332 if ( $entry->sourceglossaryid ) {
333 $icon = "minus.gif"; // graphical metaphor (minus) for deleting an imported entry
334 } else {
335 $icon = "../../pix/t/delete.gif";
336 }
337
ed0201dd 338 // Exported entries can be updated/deleted only by teachers in the main glossary
7dd88447 339 if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
c76e673a 340 echo " <a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("delete") . "\"src=\"";
ad58adac 341 echo $icon;
342 echo "\" height=11 width=11 border=0></a> ";
343
c76e673a 344 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 345 } elseif ( $importedentry ) {
c76e673a 346 echo " <font size=-1>" . get_string("exportedentry","glossary") . "</font>";
ad58adac 347 }
ed0201dd 348 }
07842023 349}
350
351function glossary_search_entries($searchterms, $glossary, $includedefinition) {
352/// Returns a list of entries found using an array of search terms
353/// eg word +word -word
354///
355
356 global $CFG;
357
358 if (!isteacher($glossary->course)) {
359 $glossarymodule = get_record("modules", "name", "glossary");
6a22879b 360 $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
07842023 361 $onlyvisibletable = ", {$CFG->prefix}course_modules cm";
362 } else {
363
364 $onlyvisible = "";
365 $onlyvisibletable = "";
366 }
367
368 /// Some differences in syntax for PostgreSQL
369 if ($CFG->dbtype == "postgres7") {
370 $LIKE = "ILIKE"; // case-insensitive
371 $NOTLIKE = "NOT ILIKE"; // case-insensitive
372 $REGEXP = "~*";
373 $NOTREGEXP = "!~*";
374 } else {
375 $LIKE = "LIKE";
376 $NOTLIKE = "NOT LIKE";
377 $REGEXP = "REGEXP";
378 $NOTREGEXP = "NOT REGEXP";
379 }
380
381 $conceptsearch = "";
382 $definitionsearch = "";
383
384
385 foreach ($searchterms as $searchterm) {
07842023 386 if ($conceptsearch) {
387 $conceptsearch.= " OR ";
388 }
389 if ($definitionsearch) {
390 $definitionsearch.= " OR ";
391 }
392
393 if (substr($searchterm,0,1) == "+") {
394 $searchterm = substr($searchterm,1);
395 $conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
396 $definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
397 } else if (substr($searchterm,0,1) == "-") {
398 $searchterm = substr($searchterm,1);
399 $conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
400 $definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
401 } else {
402 $conceptsearch .= " e.concept $LIKE '%$searchterm%' ";
403 $definitionsearch .= " e.definition $LIKE '%$searchterm%' ";
404 }
405 }
406
ed0201dd 407 if ( !$includedefinition ) {
408 $definitionsearch = "0";
409 }
07842023 410
411 $selectsql = "{$CFG->prefix}glossary_entries e,
412 {$CFG->prefix}glossary g $onlyvisibletable
413 WHERE ($conceptsearch OR $definitionsearch)
ad58adac 414 AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
c76e673a 415 AND g.id = $glossary->id AND e.approved != 0";
07842023 416
4d4c38f3 417 return get_records_sql("SELECT e.*
418 FROM $selectsql ORDER BY e.concept ASC");
07842023 419}
420
e179048e 421function glossary_file_area_name($entry) {
422// Creates a directory file name, suitable for make_upload_directory()
423 global $CFG;
424
425 return "$entry->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id";
426}
427
428function glossary_file_area($entry) {
429 return make_upload_directory( glossary_file_area_name($entry) );
430}
431
432function glossary_delete_old_attachments($entry, $exception="") {
433// Deletes all the user files in the attachments area for a entry
434// EXCEPT for any file named $exception
435
436 if ($basedir = glossary_file_area($entry)) {
437 if ($files = get_directory_list($basedir)) {
438 foreach ($files as $file) {
439 if ($file != $exception) {
440 unlink("$basedir/$file");
441// notify("Existing file '$file' has been deleted!");
442 }
443 }
444 }
445 if (!$exception) { // Delete directory as well, if empty
446 rmdir("$basedir");
447 }
448 }
449}
450
451function glossary_copy_attachments($entry, $newentry) {
452/// Given a entry object that is being copied to glossaryid,
453/// this function checks that entry
454/// for attachments, and if any are found, these are
455/// copied to the new glossary directory.
456
457 global $CFG;
458
459 $return = true;
460
461 if ($entries = get_records_select("glossary_entries", "id = '$entry->id' AND attachment <> ''")) {
462 foreach ($entries as $curentry) {
463 $oldentry->id = $entry->id;
464 $oldentry->course = $entry->course;
465 $oldentry->glossaryid = $curentry->glossaryid;
466 $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
467 if (is_dir($oldentrydir)) {
468
469 $newentrydir = glossary_file_area($newentry);
470 if (! copy("$oldentrydir/$newentry->attachment", "$newentrydir/$newentry->attachment")) {
471 $return = false;
472 }
473 }
474 }
475 }
476 return $return;
477}
478
479function glossary_move_attachments($entry, $glossaryid) {
480/// Given a entry object that is being moved to glossaryid,
481/// this function checks that entry
482/// for attachments, and if any are found, these are
483/// moved to the new glossary directory.
484
485 global $CFG;
486
487 $return = true;
488
489 if ($entries = get_records_select("glossary_entries", "glossaryid = '$entry->id' AND attachment <> ''")) {
490 foreach ($entries as $entry) {
491 $oldentry->course = $entry->course;
492 $oldentry->glossaryid = $entry->glossaryid;
493 $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
494 if (is_dir($oldentrydir)) {
495 $newentry = $oldentry;
496 $newentry->glossaryid = $glossaryid;
497 $newentrydir = "$CFG->dataroot/".glossary_file_area_name($newentry);
498 if (! @rename($oldentrydir, $newentrydir)) {
499 $return = false;
500 }
501 }
502 }
503 }
504 return $return;
505}
506
507function glossary_add_attachment($entry, $newfile) {
508// $entry is a full entry record, including course and glossary
509// $newfile is a full upload array from $_FILES
510// If successful, this function returns the name of the file
511
512 global $CFG;
513
514 if (empty($newfile['name'])) {
515 return "";
516 }
517
518 $newfile_name = clean_filename($newfile['name']);
519
520 if (valid_uploaded_file($newfile)) {
521 if (! $newfile_name) {
522 notify("This file had a wierd filename and couldn't be uploaded");
523
524 } else if (! $dir = glossary_file_area($entry)) {
525 notify("Attachment could not be stored");
526 $newfile_name = "";
527
528 } else {
529 if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
530 chmod("$dir/$newfile_name", $CFG->directorypermissions);
531 glossary_delete_old_attachments($entry, $newfile_name);
532 } else {
533 notify("An error happened while saving the file on the server");
534 $newfile_name = "";
535 }
536 }
537 } else {
538 $newfile_name = "";
539 }
540
541 return $newfile_name;
542}
543
de53b9ac 544function glossary_print_attachments($entry, $return=NULL, $align="left") {
e179048e 545// if return=html, then return a html string.
546// if return=text, then return a text-only string.
547// otherwise, print HTML for non-images, and return image HTML
b764feaa 548// if attachment is an image, $align set its aligment.
e179048e 549 global $CFG;
b764feaa 550
551 $newentry = $entry;
552 if ( $newentry->sourceglossaryid ) {
553 $newentry->glossaryid = $newentry->sourceglossaryid;
554 }
e179048e 555
b764feaa 556 $filearea = glossary_file_area_name($newentry);
e179048e 557
558 $imagereturn = "";
559 $output = "";
560
b764feaa 561 if ($basedir = glossary_file_area($newentry)) {
e179048e 562 if ($files = get_directory_list($basedir)) {
563 $strattachment = get_string("attachment", "glossary");
564 $strpopupwindow = get_string("popupwindow");
565 foreach ($files as $file) {
566 $icon = mimeinfo("icon", $file);
567 if ($CFG->slasharguments) {
568 $ffurl = "file.php/$filearea/$file";
569 } else {
570 $ffurl = "file.php?file=/$filearea/$file";
571 }
572 $image = "<img border=0 src=\"$CFG->wwwroot/files/pix/$icon\" height=16 width=16 alt=\"$strpopupwindow\">";
573
574 if ($return == "html") {
575 $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$image</a> ";
576 $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a><br />";
577 } else if ($return == "text") {
578 $output .= "$strattachment $file:\n$CFG->wwwroot/$ffurl\n";
579
580 } else {
581 if ($icon == "image.gif") { // Image attachments don't get printed as links
de53b9ac 582 $imagereturn .= "<br /><img src=\"$CFG->wwwroot/$ffurl\" align=$align>";
e179048e 583 } else {
584 link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment);
585 echo "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a>";
586 echo "<br />";
587 }
588 }
589 }
590 }
591 }
592
593 if ($return) {
594 return $output;
595 }
596
597 return $imagereturn;
598}
599
7dd88447 600function glossary_print_tabbed_table_start($data, $currenttab, $tTHEME = NULL) {
06d94a52 601
602if ( !$tTHEME ) {
603 global $THEME;
604 $tTHEME = $THEME;
605}
606
7dd88447 607$tablecolor = $tTHEME->TabTableBGColor;
608$currenttabcolor = $tTHEME->ActiveTabColor;
609$tabcolor = $tTHEME->InactiveTabColor;
610$inactivefontcolor = $tTHEME->InactiveFontColor;
06d94a52 611
7dd88447 612$tablewidth = $tTHEME->TabTableWidth;
613$tabsperrow = $tTHEME->TabsPerRow;
614$tabseparation = $tTHEME->TabSeparation;
06d94a52 615
7dd88447 616$tabs = count($data);
617$tabwidth = (int) (100 / $tabsperrow);
06d94a52 618
7dd88447 619$currentrow = ( $currenttab - ( $currenttab % $tabsperrow) ) / $tabsperrow;
620
621$numrows = (int) ( $tabs / $tabsperrow ) + 1;
06d94a52 622
623?>
624 <center>
7dd88447 625 <table border="0" cellpadding="0" cellspacing="0" width="<?php p($tablewidth) ?>">
06d94a52 626 <tr>
627 <td width="100%">
628
629 <table border="0" cellpadding="0" cellspacing="0" width="100%">
630
ad58adac 631<?php
7dd88447 632$tabproccessed = 0;
633for ($row = 0; $row < $numrows; $row++) {
06d94a52 634 echo "<tr>\n";
7dd88447 635 if ( $row != $currentrow ) {
636 for ($col = 0; $col < $tabsperrow; $col++) {
637 if ( $tabproccessed < $tabs ) {
ad58adac 638 if ( $col == 0 ) {
7dd88447 639 echo "<td width=\"$tabseparation\" align=\"center\">&nbsp;</td>";
ad58adac 640 }
7dd88447 641 if ($tabproccessed == $currenttab) {
642 $currentcolor = $currenttabcolor;
e94c179a 643 $currentstyle = 'generaltabselected';
06d94a52 644 } else {
7dd88447 645 $currentcolor = $tabcolor;
e94c179a 646 $currentstyle = 'generaltab';
06d94a52 647 }
e94c179a 648 echo "<td class=\"$currentstyle\" width=\"$tabwidth%\" bgcolor=\"$currentcolor\" align=\"center\"><b>";
7dd88447 649 if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
650 echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
914cb260 651 }
7dd88447 652
ed0201dd 653 if ( !$data[$tabproccessed]->link ) {
654 echo "<font color=\"$inactivefontcolor\">";
655 }
7dd88447 656 echo $data[$tabproccessed]->caption;
ed0201dd 657 if ( !$data[$tabproccessed]->link ) {
658 echo "</font>";
659 }
7dd88447 660
661 if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
914cb260 662 echo "</a>";
663 }
664 echo "</b></td>";
665
7dd88447 666 if ( $col < $tabsperrow ) {
667 echo "<td width=\"$tabseparation\" align=\"center\">&nbsp;</td>";
914cb260 668 }
06d94a52 669 } else {
7dd88447 670 $currentcolor = "";
06d94a52 671 }
7dd88447 672 $tabproccessed++;
06d94a52 673 }
674 } else {
7dd88447 675 $firsttabincurrentrow = $tabproccessed;
676 $tabproccessed += $tabsperrow;
06d94a52 677 }
7dd88447 678 echo "</tr><tr><td colspan=" . (2* $tabsperrow) . " ></td></tr>\n";
06d94a52 679}
680 echo "<tr>\n";
7dd88447 681 $tabproccessed = $firsttabincurrentrow;
682 for ($col = 0; $col < $tabsperrow; $col++) {
683 if ( $tabproccessed < $tabs ) {
ad58adac 684 if ( $col == 0 ) {
7dd88447 685 echo "<td width=\"$tabseparation\" align=\"center\">&nbsp;</td>";
ad58adac 686 }
7dd88447 687 if ($tabproccessed == $currenttab) {
688 $currentcolor = $currenttabcolor;
e8ff59d6 689 $currentstyle = 'generaltabselected';
06d94a52 690 } else {
7dd88447 691 $currentcolor = $tabcolor;
e8ff59d6 692 $currentstyle = 'generaltab';
06d94a52 693 }
e8ff59d6 694 echo "<td class=\"$currentstyle\" width=\"$tabwidth%\" bgcolor=\"$currentcolor\" align=\"center\"><b>";
7dd88447 695 if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
696 echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
914cb260 697 }
7dd88447 698
ed0201dd 699 if ( !$data[$tabproccessed]->link ) {
700 echo "<font color=\"$inactivefontcolor\">";
701 }
7dd88447 702 echo $data[$tabproccessed]->caption;
ed0201dd 703 if ( !$data[$tabproccessed]->link ) {
704 echo "</font>";
705 }
7dd88447 706
707 if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
914cb260 708 echo "</a>";
709 }
710 echo "</b></td>";
711
7dd88447 712 if ($col < $tabsperrow) {
713 echo "<td width=\"$tabseparation\" align=\"center\">&nbsp;</td>";
914cb260 714 }
06d94a52 715 } else {
7dd88447 716 if ($numrows > 1) {
717 $currentcolor = $tabcolor;
06d94a52 718 } else {
7dd88447 719 $currentcolor = "";
06d94a52 720 }
7dd88447 721 echo "<td colspan = " . (2 * ($tabsperrow - $col)) . " bgcolor=\"$currentcolor\" align=\"center\">";
06d94a52 722 echo "</td>";
723
7dd88447 724 $col = $tabsperrow;
06d94a52 725 }
7dd88447 726 $tabproccessed++;
06d94a52 727 }
728 echo "</tr>\n";
729 ?>
730
731 </table>
732 </td>
733 </tr>
734 <tr>
7dd88447 735 <td width="100%" bgcolor="<?php p($tablecolor) ?>"><hr></td>
06d94a52 736 </tr>
737 <tr>
7dd88447 738 <td width="100%" bgcolor="<?php p($tablecolor) ?>">
06d94a52 739 <center>
ad58adac 740<?php
06d94a52 741}
742
ad58adac 743function glossary_print_tabbed_table_end() {
06d94a52 744 echo "</center><p></td></tr></table></center>";
745}
746
c76e673a 747function glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder = "",$tab=GLOSSARY_STANDARD_VIEW) {
c76e673a 748 if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
c197e607 749 echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
677038ee 750 }
c76e673a 751 glossary_print_special_links($cm, $glossary,$l, $tab);
752
753 glossary_print_alphabet_links($cm, $glossary,$l, $tab);
754
755 glossary_print_all_links($cm, $glossary,$l, $tab);
756
757 glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
758}
759
760function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
c197e607 761 if ( $tab != GLOSSARY_DATE_VIEW ) {
762 if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
763 echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
764 }
c76e673a 765
c197e607 766 glossary_print_special_links($cm, $glossary,$l, $tab);
c76e673a 767
c197e607 768 glossary_print_alphabet_links($cm, $glossary,$l, $tab);
769
770 glossary_print_all_links($cm, $glossary,$l, $tab);
771 } else {
772 glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
773 }
c76e673a 774}
775
776function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
777global $CFG, $THEME;
c197e607 778 echo '<table border=0 width=100%>';
779 echo '<tr>';
c76e673a 780
c197e607 781 echo '<td align=center width=20%>';
c76e673a 782 if ( isteacher($course->id) ) {
783 $options['id'] = $cm->id;
784 $options['cat'] = $cat;
785 echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
786 }
c197e607 787 echo '</td>';
c76e673a 788
c197e607 789 echo '<td align=center width=60%>';
790 echo '<b>';
c76e673a 791
792 $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
793 $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
677038ee 794
c76e673a 795 $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
c197e607 796 $selected = '';
c76e673a 797 if ( $categories ) {
798 foreach ($categories as $currentcategory) {
799 $url = $currentcategory->id;
800 if ( $category ) {
801 if ($currentcategory->id == $category->id) {
802 $selected = $url;
803 }
804 }
805 $menu[$url] = $currentcategory->name;
806 }
807 }
808 if ( !$selected ) {
809 $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
810 }
811
812 if ( $category ) {
813 echo $category->name;
814 } else {
815 if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
816
817 echo get_string("entrieswithoutcategory","glossary");
818 $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
819
820 } elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
821
822 echo get_string("allcategories","glossary");
823 $selected = GLOSSARY_SHOW_ALL_CATEGORIES;
824
825 }
826 }
c197e607 827 echo '</b></td>';
828 echo '<td align=center width=20%>';
c76e673a 829
830 echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&tab=" . GLOSSARY_CATEGORY_VIEW . "&cat=", $menu, "catmenu", $selected, "",
831 "", "", false);
677038ee 832
c197e607 833 echo '</td>';
834 echo '</tr>';
c76e673a 835
c197e607 836 echo '</table>';
c76e673a 837}
838
839function glossary_print_all_links($cm, $glossary, $l, $tab) {
840global $CFG;
841 if ( $glossary->showall and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
842 $strallentries = get_string("allentries", "glossary");
c197e607 843 if ( $l == 'ALL' ) {
c76e673a 844 echo "<b>$strallentries</b>";
845 } else {
846 $strexplainall = strip_tags(get_string("explainall","glossary"));
847 echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL&tab=$tab\">$strallentries</a>";
848 }
849 }
850}
851
852function glossary_print_special_links($cm, $glossary, $l, $tab) {
853global $CFG;
854 if ( $glossary->showspecial and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
855 $strspecial = get_string("special", "glossary");
c197e607 856 if ( $l == 'SPECIAL' ) {
677038ee 857 echo "<b>$strspecial</b> | ";
858 } else {
859 $strexplainspecial = strip_tags(get_string("explainspecial","glossary"));
c76e673a 860 echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL&tab=$tab\">$strspecial</a> | ";
677038ee 861 }
914cb260 862 }
c76e673a 863}
677038ee 864
c76e673a 865function glossary_print_alphabet_links($cm, $glossary,$l, $tab) {
866global $CFG;
867 if ( $glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
677038ee 868 $alphabet = explode("|", get_string("alphabet","glossary"));
869 $letters_by_line = 14;
870 for ($i = 0; $i < count($alphabet); $i++) {
871 if ( $l == $alphabet[$i] and $l) {
872 echo "<b>$alphabet[$i]</b>";
873 } else {
c76e673a 874 echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]&tab=$tab\">$alphabet[$i]</a>";
677038ee 875 }
876 if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
c197e607 877 echo ' | ';
677038ee 878 } else {
c197e607 879 echo '<br>';
677038ee 880 }
767a31c3 881 }
677038ee 882 }
c76e673a 883}
884
885function glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab) {
886global $CFG;
887 $strsort = get_string("sortchronogically", "glossary");
888 $strsortbycreation = get_string("sortbycreation", "glossary");
889 $strsortbylastupdate = get_string("sortbylastupdate", "glossary");
677038ee 890
c197e607 891 $neworder = '';
677038ee 892 if ( $sortorder ) {
c197e607 893 if ( $sortorder == 'asc' ) {
894 $neworder = '&sortorder=desc';
677038ee 895 $ordertitle = get_string("descending","glossary");
896 } else {
c197e607 897 $neworder = '&sortorder=asc';
677038ee 898 $ordertitle = get_string("ascending","glossary");
899 }
900 $icon = " <img src=\"$sortorder.gif\" border=0 width=16 height=16>";
901 } else {
c197e607 902 if ( $sortkey != 'CREATION' and $sortkey != 'UPDATE' ) {
677038ee 903 $icon = "";
904 $ordertitle = get_string("ascending","glossary");
905 } else {
906 $ordertitle = get_string("descending","glossary");
c197e607 907 $neworder = '&sortorder=desc';
908 $icon = ' <img src="asc.gif" border=0 width=16 height=16>';
677038ee 909 }
910 }
c197e607 911 $cicon = '';
912 $cneworder = '';
913 $cbtag = '';
914 $cendbtag = '';
677038ee 915
c197e607 916 $uicon = '';
917 $uneworder = '';
918 $ubtag = '';
919 $uendbtag = '';
677038ee 920
c197e607 921 if ( $sortkey == 'CREATION' ) {
677038ee 922 $cicon = $icon;
923 $cneworder = $neworder;
924 $cordertitle = $ordertitle;
925 $uordertitle = get_string("ascending","glossary");
c197e607 926 $cbtag = '<b>';
927 $cendbtag = '</b>';
928 } elseif ($sortkey == 'UPDATE') {
677038ee 929 $uicon = $icon;
930 $uneworder = $neworder;
931 $cordertitle = get_string("ascending","glossary");
932 $uordertitle = $ordertitle;
c197e607 933 $ubtag = '<b>';
934 $uendbtag = '</b>';
677038ee 935 } else {
936 $cordertitle = get_string("ascending","glossary");
937 $uordertitle = get_string("ascending","glossary");
938 }
c76e673a 939 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 | ".
940 "$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 941}
ad58adac 942
943function glossary_sort_entries ( $entry0, $entry1 ) {
944 if ( strtolower(ltrim($entry0->concept)) < strtolower(ltrim($entry1->concept)) ) {
945 return -1;
946 } elseif ( strtolower(ltrim($entry0->concept)) > strtolower(ltrim($entry1->concept)) ) {
947 return 1;
948 } else {
949 return 0;
950 }
951}
952
ed0201dd 953function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
954 global $THEME, $CFG, $USER;
955
956// if ($entry->timemarked < $entry->modified) {
957 $colour = $THEME->cellheading2;
958// } else {
959// $colour = $THEME->cellheading;
960// }
961
962 $user = get_record("user", "id", $comment->userid);
963 $strby = get_string("writtenby","glossary");
964
965 echo "<table class=\"generalbox\" BORDER=1 CELLSPACING=0 valign=top cellpadding=0 width=70% border=0><tr><td>";
966
967 echo "\n<TABLE width=\"100%\" BORDER=0 CELLSPACING=0 valign=top cellpadding=5><tr>";
968
969 echo "\n<TD BGCOLOR=\"$THEME->cellheading\" WIDTH=25% VALIGN=TOP align=right >";
970 print_user_picture($user->id, $course->id, $user->picture);
971 echo "<br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
972 echo "<br><FONT SIZE=1>(".get_string("lastedited").": ".userdate($comment->timemodified).")</FONT></small><br>";
973 echo "</TD>";
c197e607 974
ed0201dd 975 echo "<TD NOWRAP valign=top WIDTH=75% BGCOLOR=\"$THEME->cellcontent\">";
976 if ($comment) {
c197e607 977 echo format_text($comment->comment, $comment->format);
ed0201dd 978 } else {
c197e607 979 echo "<center>";
ed0201dd 980 print_string("nocomment", "glossary");
c197e607 981 echo "</center>";
ed0201dd 982 }
983
984 echo "<p align=right>";
c197e607 985 if ( (time() - $comment->timemodified < $CFG->maxeditingtime and $USER->id == $comment->userid) or isteacher($course->id) ) {
ed0201dd 986 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 987 }
988 if ( $USER->id == $comment->userid or isteacher($course->id) ) {
ed0201dd 989 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 990 }
ed0201dd 991 echo "</td>";
c197e607 992
ed0201dd 993 echo "</tr></TABLE>\n";
994
995 echo "</td></tr></table>";
996}
997
cca6f7f1 998 function glossary_print_dynaentry($courseid, $entries) {
999 global $THEME, $USER;
1000
1001 $colour = $THEME->cellheading2;
1002
1003 echo "\n<center><table width=95% border=0><tr>";
1004 echo "<td width=100%\">";
1005 if ( $entries ) {
1006 foreach ( $entries as $entry ) {
1007
1008 if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) {
1009 error("Glossary ID was incorrect or no longer exists");
1010 }
1011 if (! $course = get_record("course", "id", $glossary->course)) {
1012 error("Glossary is misconfigured - don't know what course it's from");
1013 }
1014 if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) {
1015 error("Glossary is misconfigured - don't know what course module it is ");
1016 }
1017
1018 glossary_print_entry($course, $cm, $glossary, $entry);
1019 }
1020 }
1021 echo "</td>";
1022 echo "</tr></table></center>";
1023 }
e179048e 1024?>