remove old readme
[atutor.git] / docs / mods / _core / glossary / index.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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$
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 require (AT_INCLUDE_PATH.'header.inc.php');
18
19 $sql    = "SELECT word_id, related_word_id FROM ".TABLE_PREFIX."glossary WHERE related_word_id>0 AND course_id=$_SESSION[course_id] ORDER BY related_word_id";
20 $result = mysql_query($sql, $db);
21 while ($row = mysql_fetch_array($result)) {
22         $glossary_related[$row['related_word_id']][] = $row['word_id'];                 
23 }
24
25 $_GET['w'] = isset($_GET['w']) ? stripslashes($_GET['w']) : '';
26
27 if ($_GET['w']) {
28         $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] AND word='".addslashes(urldecode($_GET['w']))."'";          
29 } else {
30         $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";                     
31 }
32
33 $result= mysql_query($sql, $db);
34
35 if(mysql_num_rows($result) > 0){                
36
37         $gloss_results = array();
38         while ($row = mysql_fetch_assoc($result)) {
39                 $gloss_results[] = $row;
40         }
41         $num_results = count($gloss_results);
42         $results_per_page = 25;
43         $num_pages = ceil($num_results / $results_per_page);
44         $page = isset($_GET['p']) ? intval($_GET['p']) : 0;
45         if (!$page) {
46                 $page = 1;
47         }
48         
49         $count = (($page-1) * $results_per_page) + 1;
50         $gloss_results = array_slice($gloss_results, ($page-1)*$results_per_page, $results_per_page);
51
52         if($num_pages > 1):
53         ?>
54         <div class="paging">
55                 <ul>
56                 <?php for ($i=1; $i<=$num_pages; $i++): ?>
57                         <li>
58                                 <?php if ($i == $page) : ?>
59                                         <a class="current" href="<?php echo url_rewrite('mods/_core/glossary/index.php?p='.$i.'#list'); ?>"><strong><?php echo $i; ?></strong></a>
60                                 <?php else: ?>
61                                         <a href="<?php echo url_rewrite('mods/_core/glossary/index.php?p='.$i.'#list'); ?>"><?php echo $i; ?></a>
62                                 <?php endif; ?>
63                         </li>
64                 <?php endfor; ?>
65                 </ul>
66         </div>
67         <?php endif; ?>
68
69 <a name="list"></a>
70
71 <?php
72         $current_letter = '';
73         foreach ($gloss_results as $item):
74                 $item['word'] = AT_print($item['word'], 'glossary.word');
75
76                 if ($current_letter != $strtoupper($substr($item['word'], 0, 1))):
77                         if ($current_letter != '') {                            
78                                 echo '</dl>';
79                         } 
80                         $current_letter = $strtoupper($substr($item['word'], 0, 1)); ?>
81                         <h3 style="padding-bottom:5px;"><a name="<?php echo $current_letter; ?>"></a><?php echo $current_letter; ?></h3>
82                         <dl style="margin:0px;">
83                 <?php endif; ?>
84
85                         <dt>
86                         <?php if ($_GET['w']): ?>
87                                 <a name="term"></a>
88                         <?php else: ?>
89                                 <a name="<?php echo urlencode($item['word']); ?>"></a>
90                         <?php endif; ?>
91                         <strong><?php echo stripslashes($item['word']); ?>
92
93                         <?php if (($item['related_word_id'] != 0) || (isset($glossary_related) && is_array($glossary_related[urlencode($item['word_id'])]) )):
94                                 echo ' ('._AT('see').': ';
95
96                                 $output = false;
97
98                                 if ($item['related_word_id'] != 0) {
99                                         echo '<a href="'.$_SERVER['PHP_SELF'].'?w='.addslashes(urlencode($glossary_ids[$item['related_word_id']])).'#term">'.urldecode($glossary_ids[$item['related_word_id']]).'</a>';
100                                         $output = true;
101                                 }
102
103                                 if (is_array($glossary_related[urlencode($item['word_id'])]) ) {
104                                         $my_related = $glossary_related[$item['word_id']];
105
106                                         $num_related = count($my_related);
107                                         for ($i=0; $i<$num_related; $i++) {
108                                                 if ($glossary_ids[$my_related[$i]] == $glossary_ids[$item['related_word_id']]) {
109                                                         continue;
110                                                 }
111                                                 if ($output) {
112                                                         echo ', ';
113                                                 }
114
115                                                 echo '<a href="'.$_SERVER['PHP_SELF'].'?w='.urlencode($glossary_ids[$my_related[$i]]).'#term">'.urldecode($glossary_ids[$my_related[$i]]).'</a>';
116
117                                                 $output = true;
118                                         }
119                                 }
120                                 echo ')';
121                 endif; ?>
122                 </strong></dt>
123
124                 <dd><?php echo AT_print($item['definition'], 'glossary.definition'); ?><br /><br /></dd>
125
126
127         <?php endforeach; ?>
128
129         </dl>
130
131 <?php
132         if ($_GET['w']) {
133                 echo '<br /><br /><a href="mods/_core/glossary/index.php">'._AT('view_all').'</a>';
134
135                 if ($_GET['g_cid']) {
136                         $path   = $contentManager->getContentPath(intval($_GET['g_cid']));
137                         echo ' | '._AT('back_to').' <a href="'.url_rewrite('content.php?cid='.intval($_GET['g_cid'])).'">'.$path[0]['title'].'</a>';
138                 }
139         }
140         
141 } else {
142         echo '<p>'._AT('no_glossary_items').'</p>';
143 }
144
145 require(AT_INCLUDE_PATH.'footer.inc.php');
146 ?>