tagging as ATutor 1.5.4-release
[atutor.git] / tools / glossary / index.php
1 <?php\r
2 /****************************************************************************/\r
3 /* ATutor                                                                                                                                       */\r
4 /****************************************************************************/\r
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton        */\r
6 /* Adaptive Technology Resource Centre / University of Toronto                          */\r
7 /* http://atutor.ca                                                                                                                     */\r
8 /*                                                                                                                                                      */\r
9 /* This program is free software. You can redistribute it and/or                        */\r
10 /* modify it under the terms of the GNU General Public License                          */\r
11 /* as published by the Free Software Foundation.                                                        */\r
12 /****************************************************************************/\r
13 \r
14 define('AT_INCLUDE_PATH', '../../include/');\r
15 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
16 \r
17 authenticate(AT_PRIV_GLOSSARY);\r
18 \r
19 require (AT_INCLUDE_PATH.'lib/links.inc.php');\r
20 \r
21 if (isset($_POST['edit'], $_POST['word_id'])) {\r
22         header('Location: edit.php?gid='.$_POST['word_id']);\r
23         exit;\r
24 } else if (isset($_POST['delete'], $_POST['word_id'])) {\r
25         header('Location: delete.php?gid='.$_POST['word_id']);\r
26         exit;\r
27 } else if (!empty($_POST)) {\r
28         $msg->addError('NO_ITEM_SELECTED');\r
29 }\r
30 \r
31 require(AT_INCLUDE_PATH.'header.inc.php');\r
32 \r
33 //get terms\r
34 $sql    = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";                  \r
35 $result= mysql_query($sql, $db);\r
36 \r
37 $gloss_results = array();\r
38 while ($row = mysql_fetch_assoc($result)) {\r
39         $gloss_results[] = $row;\r
40 }\r
41 $num_results = count($gloss_results);\r
42 $results_per_page = 25;\r
43 $num_pages = ceil($num_results / $results_per_page);\r
44 $page = intval($_GET['p']);\r
45 if (!$page) {\r
46         $page = 1;\r
47 }\r
48         \r
49 $count = (($page-1) * $results_per_page) + 1;\r
50 $gloss_results = array_slice($gloss_results, ($page-1)*$results_per_page, $results_per_page);\r
51         \r
52 if($num_pages > 1) {\r
53         echo _AT('page').': ';\r
54         for ($i=1; $i<=$num_pages; $i++) {\r
55                 if ($i == $page) {\r
56                         echo '<strong>'.$i.'</strong>';\r
57                 } else {\r
58                         echo ' | <a href="'.$_SERVER['PHP_SELF'].'?p='.$i.'#list">'.$i.'</a>';\r
59                 }\r
60         }\r
61 }\r
62 ?>\r
63 \r
64 <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
65 \r
66 <table class="data" summary="" rules="cols" style="width: 90%;">\r
67 <thead>\r
68 <tr>\r
69         <th scope="col">&nbsp;</th>\r
70         <th scope="col"><?php echo _AT('glossary_term'); ?></th>\r
71         <th scope="col"><?php echo _AT('glossary_definition'); ?></th>\r
72         <th scope="col"><?php echo _AT('glossary_related'); ?></th>\r
73 </tr>\r
74 </thead>\r
75 <tfoot>\r
76 <tr>\r
77         <td colspan="4"><input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>\r
78 </tr>\r
79 </tfoot>\r
80 <tbody>\r
81 <?php\r
82 if(!empty($gloss_results)) {\r
83         foreach ($gloss_results as $row) {      \r
84                 //get related term name\r
85                 $related_word = '';\r
86                 if ($row['related_word_id']) {\r
87                         $sql    = "SELECT word FROM ".TABLE_PREFIX."glossary WHERE word_id=".$row['related_word_id']." AND course_id=".$_SESSION['course_id'];\r
88                         $result = mysql_query($sql, $db);\r
89                         if ($row_related = mysql_fetch_array($result)) {\r
90                                 $related_word = $row_related['word'];                   \r
91                         }\r
92                 }\r
93 \r
94                 $def_trunc = substr($row['definition'], 0, 70);\r
95                 if (strlen($def_trunc) < strlen($row['definition'])) {\r
96                         $def_trunc .= ' &#8230;';\r
97                 }\r
98         ?>\r
99                         <tr onmousedown="document.form['m<?php echo $row['word_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['word_id']; ?>">\r
100                                 <td valign="top" width="10"><input type="radio" name="word_id" value="<?php echo $row['word_id']; ?>" id="m<?php echo $row['word_id']; ?>" /></td>\r
101                                 <td valign="top"><label for="m<?php echo $row['word_id']; ?>"><?php echo AT_print($row['word'], 'glossary.word'); ?></label></td>\r
102                                 <td style="whitespace:nowrap;"><?php echo AT_print($def_trunc,          'glossary.definition'); ?></td>\r
103                                 <td valign="top"><?php echo AT_print($related_word,     'glossary.word'); ?></td>\r
104                         </tr>\r
105 <?php \r
106         }                               \r
107 } else {\r
108 ?>\r
109         <tr>\r
110                 <td colspan="5"><?php echo _AT('none_found'); ?></td>\r
111         </tr>\r
112 <?php\r
113 }                                       \r
114 ?>\r
115 \r
116 </tbody>\r
117 </table>\r
118 </form>\r
119 \r
120 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>