Moved scripts in "docs" one level up into root folder. In addition, removed "docs...
[atutor.git] / mods / _core / glossary / tools / index.php
1 <?php\r
2 /****************************************************************************/\r
3 /* ATutor                                                                                                                                       */\r
4 /****************************************************************************/\r
5 /* Copyright (c) 2002-2010                                                  */\r
6 /* Inclusive Design Institute                                               */\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 \r
20 if (isset($_POST['edit'], $_POST['word_id'])) {\r
21         header('Location: edit.php?gid='.$_POST['word_id']);\r
22         exit;\r
23 } else if (isset($_POST['delete'], $_POST['word_id'])) {\r
24         header('Location: delete.php?gid='.$_POST['word_id']);\r
25         exit;\r
26 } else if (!empty($_POST)) {\r
27         $msg->addError('NO_ITEM_SELECTED');\r
28 }\r
29 \r
30 require(AT_INCLUDE_PATH.'header.inc.php');\r
31 \r
32 //get terms\r
33 $sql    = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";                  \r
34 $result= mysql_query($sql, $db);\r
35 \r
36 $gloss_results = array();\r
37 while ($row = mysql_fetch_assoc($result)) {\r
38         $gloss_results[] = $row;\r
39 }\r
40 $num_results = count($gloss_results);\r
41 $results_per_page = 25;\r
42 $num_pages = ceil($num_results / $results_per_page);\r
43 $page = intval($_GET['p']);\r
44 if (!$page) {\r
45         $page = 1;\r
46 }\r
47         \r
48 $count = (($page-1) * $results_per_page) + 1;\r
49 $gloss_results = array_slice($gloss_results, ($page-1)*$results_per_page, $results_per_page);\r
50         \r
51 if($num_pages > 1) {\r
52         echo _AT('page').': ';\r
53         for ($i=1; $i<=$num_pages; $i++) {\r
54                 if ($i == $page) {\r
55                         echo '<strong>'.$i.'</strong>';\r
56                 } else {\r
57                         echo ' | <a href="'.$_SERVER['PHP_SELF'].'?p='.$i.'#list">'.$i.'</a>';\r
58                 }\r
59         }\r
60 }\r
61 ?>\r
62 \r
63 <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
64 \r
65 <table class="data" summary="" rules="cols" style="width: 90%;">\r
66 <thead>\r
67 <tr>\r
68         <th scope="col">&nbsp;</th>\r
69         <th scope="col"><?php echo _AT('glossary_term'); ?></th>\r
70         <th scope="col"><?php echo _AT('glossary_definition'); ?></th>\r
71         <th scope="col"><?php echo _AT('glossary_related'); ?></th>\r
72 </tr>\r
73 </thead>\r
74 <tfoot>\r
75 <tr>\r
76         <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
77 </tr>\r
78 </tfoot>\r
79 <tbody>\r
80 <?php\r
81 if(!empty($gloss_results)) {\r
82         foreach ($gloss_results as $row) {      \r
83                 //get related term name\r
84                 $related_word = '';\r
85                 if ($row['related_word_id']) {\r
86                         $sql    = "SELECT word FROM ".TABLE_PREFIX."glossary WHERE word_id=".$row['related_word_id']." AND course_id=".$_SESSION['course_id'];\r
87                         $result = mysql_query($sql, $db);\r
88                         if ($row_related = mysql_fetch_array($result)) {\r
89                                 $related_word = $row_related['word'];                   \r
90                         }\r
91                 }\r
92 \r
93                 /* replaced w/ validate_length()\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                 $def_trunc = validate_length($row['definition'], 70, VALIDATE_LENGTH_FOR_DISPLAY);\r
100         ?>\r
101                         <tr onmousedown="document.form['m<?php echo $row['word_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['word_id']; ?>">\r
102                                 <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
103                                 <td valign="top"><label for="m<?php echo $row['word_id']; ?>"><?php echo AT_print(htmlentities_utf8($row['word']),      'glossary.word'); ?></label></td>\r
104                                 <td style="whitespace:nowrap;"><?php echo AT_print(htmlentities_utf8($def_trunc), 'glossary.definition'); ?></td>\r
105                                 <td valign="top"><?php echo AT_print(htmlentities_utf8($related_word),  'glossary.word'); ?></td>\r
106                         </tr>\r
107 <?php \r
108         }                               \r
109 } else {\r
110 ?>\r
111         <tr>\r
112                 <td colspan="5"><?php echo _AT('none_found'); ?></td>\r
113         </tr>\r
114 <?php\r
115 }                                       \r
116 ?>\r
117 \r
118 </tbody>\r
119 </table>\r
120 </form>\r
121 \r
122 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>