Moved scripts in "docs" one level up into root folder. In addition, removed "docs...
[atutor.git] / 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: glossary.inc.php 10197 2010-09-16 16:18:25Z greg $
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
43                 foreach ($words as $k => $v) {
44                         $original_v = $v;
45                         $v = $strtolower(urlencode($v));        //array_change_key_case change everything to lowercase, including encoding. 
46
47                         if (isset($glossary_key_lower[$v]) && $glossary_key_lower[$v] != '') {
48
49                                 $v_formatted = urldecode(array_search($glossary_key_lower[$v], $glossary));
50
51                                 $def = htmlentities(AT_print($glossary_key_lower[$v], 'glossary.definition'), ENT_QUOTES, 'UTF-8');
52
53                                 $count++;
54                                 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="'.addslashes($v_formatted).': '.$def.'">';
55                                 if ($strlen($original_v) > 26 ) {
56                                         $v_formatted = $substr($v_formatted, 0, 26-4).'...';
57                                 }
58                                 echo AT_print($v_formatted, 'glossary.word').'</a>';
59                                 echo '<br />';
60                         }
61                 }
62
63                 if ($count == 0) {
64                         /* there are defn's, but they're not defined in the glossary */
65                         echo '<strong>'._AT('no_terms_found').'</strong>';
66                 }
67         } else {
68                 /* there are no glossary terms on this page */
69                 echo '<strong>'._AT('no_terms_found').'</strong>';
70         }
71 } else {
72         /* there are no glossary terms in the system for this course or error */
73         echo '<strong>'._AT('na').'</strong>';
74 }
75
76 $savant->assign('dropdown_contents', ob_get_contents());
77 ob_end_clean();
78
79 $savant->assign('title', _AT('glossary'));
80 $savant->display('include/box.tmpl.php');
81 ?>