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