made a copy
[atutor.git] / include / html / dropdowns / glossary.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id: glossary.inc.php 5252 2005-08-09 16:39:26Z heidi $
14
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 global $contentManager;
17 global $_base_path;
18 global $savant;
19 global $glossary;
20 global $strlen, $substr, $strtolower;
21
22 ob_start(); 
23 $result = false;
24 if (isset($_GET['cid'])) {
25         $result = $contentManager->getContentPage($_GET['cid']);
26 }
27 if ($result && ($row = mysql_fetch_array($result))) {
28         $matches = find_terms($row['text']);
29         $matches = $matches[0];
30         $words = str_replace(array('[?]', '[/?]'), '', $matches);
31         $words = str_replace("\n", ' ', $words);
32
33         //case-insensitive, unique array of words
34         for($i=0;$i<count($words);$i++) {
35                 $words[$i] = $strtolower($words[$i]);
36         }
37         $words = array_unique($words);
38
39         if (count($words) > 0) {
40                 $count = 0;
41
42                 $glossary_key_lower = array_change_key_case($glossary);
43
44                 foreach ($words as $k => $v) {
45                         $original_v = $v;
46                         $v = $strtolower(urlencode($v));        //array_change_key_case change everything to lowercase, including encoding. 
47
48                         if (isset($glossary_key_lower[$v]) && $glossary_key_lower[$v] != '') {
49
50                                 $v_formatted = urldecode(array_search($glossary_key_lower[$v], $glossary));
51
52                                 $def = htmlentities(AT_print($glossary_key_lower[$v], 'glossary.definition'), ENT_QUOTES, 'UTF-8');
53
54                                 $count++;
55                                 echo '<a class="tooltip" href="'.$_base_path.'glossary/index.php?g_cid='.$_SESSION['s_cid'].htmlentities(SEP).'w='.urlencode($original_v).'#term" title="'.addslashes($v_formatted).': '.$def.'">';
56                                 if ($strlen($original_v) > 26 ) {
57                                         $v_formatted = $substr($v_formatted, 0, 26-4).'...';
58                                 }
59                                 echo AT_print($v_formatted, 'glossary.word').'</a>';
60                                 echo '<br />';
61                         }
62                 }
63
64                 if ($count == 0) {
65                         /* there are defn's, but they're not defined in the glossary */
66                         echo '<em>'._AT('no_terms_found').'</em>';
67                 }
68         } else {
69                 /* there are no glossary terms on this page */
70                 echo '<em>'._AT('no_terms_found').'</em>';
71         }
72 } else {
73         /* there are no glossary terms in the system for this course or error */
74         echo '<em>'._AT('na').'</em>';
75 }
76
77 $savant->assign('dropdown_contents', ob_get_contents());
78 ob_end_clean();
79
80 $savant->assign('title', _AT('glossary'));
81 $savant->display('include/box.tmpl.php');
82 ?>