SVN tag for release should only contain scripts in "docs" folder without "mods",...
[atutor.git] / mods / _core / glossary / tools / edit.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 if ($_POST['cancel']) {\r
20         $msg->addFeedback('CANCELLED');\r
21         Header('Location: index.php');\r
22         exit;\r
23 }\r
24 \r
25 if ($_POST['submit']) {\r
26         $missing_fields = array();\r
27 \r
28         $_POST['word'] = trim($_POST['word']);\r
29         $_POST['definition'] = trim($_POST['definition']);\r
30 \r
31         if ($_POST['word'] == '') {\r
32                 $missing_fields[] = _AT('glossary_term');\r
33         } else{\r
34                 //60 is defined by the sql\r
35                 $_POST['word'] = validate_length($_POST['word'], 60);\r
36         }\r
37 \r
38         if ($_POST['definition'] == '') {\r
39                 $missing_fields[] = _AT('glossary_definition');\r
40         }\r
41 \r
42         if ($missing_fields) {\r
43                 $missing_fields = implode(', ', $missing_fields);\r
44                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
45         }\r
46 \r
47         $_POST['related_term'] = intval($_POST['related_term']);\r
48 \r
49 \r
50         if (!$msg->containsErrors()) {\r
51                 $_POST['word']  = $addslashes($_POST['word']);\r
52                 $_POST['definition']  = $addslashes($_POST['definition']);\r
53 \r
54                 $sql = "UPDATE ".TABLE_PREFIX."glossary SET word='$_POST[word]', definition='$_POST[definition]', related_word_id=$_POST[related_term] WHERE word_id=$_POST[gid] AND course_id=$_SESSION[course_id]";\r
55                 \r
56                 $result = mysql_query($sql, $db);\r
57 \r
58                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
59                 Header('Location: index.php');\r
60                 exit;\r
61         }\r
62 }\r
63 \r
64 $onload = 'document.form.title.focus();';\r
65 \r
66 require(AT_INCLUDE_PATH.'header.inc.php');\r
67 \r
68 if ($_POST['submit']) {\r
69         $gid = intval($_POST['gid']);\r
70 } else {\r
71         $gid = intval($_GET['gid']);\r
72 }\r
73 \r
74 if ($gid == 0) {\r
75         $msg->printErrors('ITEM_NOT_FOUND');\r
76         require (AT_INCLUDE_PATH.'footer.inc.php');\r
77         exit;\r
78 }\r
79 \r
80 $msg->printErrors();\r
81 \r
82 $result = mysql_query("SELECT * FROM ".TABLE_PREFIX."glossary WHERE word_id=$gid", $db);\r
83 \r
84 if (!( $row = @mysql_fetch_array($result)) ) {\r
85         $msg->printErrors('ITEM_NOT_FOUND');\r
86         require (AT_INCLUDE_PATH.'footer.inc.php');\r
87         exit;\r
88 }\r
89 \r
90 if ($_POST['submit']) {\r
91         $row['word']            = $_POST['word'];\r
92         $row['definition']  = $_POST['definition'];\r
93 }\r
94 \r
95 ?>\r
96 \r
97 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
98 <input type="hidden" name="gid" value="<?php echo $gid; ?>" />\r
99 \r
100 <div class="input-form">\r
101         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_glossary'); ?></legend>\r
102         <div class="row">\r
103                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('glossary_term');  ?></label><br/ >\r
104                 <input type="text" name="word" size="40" id="title" value="<?php echo htmlentities_utf8($stripslashes($row['word'])); ?>" />\r
105         </div>\r
106 \r
107         <div class="row">\r
108                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="body"><?php echo _AT('glossary_definition'); ?></label><br />\r
109                 <textarea name="definition" cols="55" rows="7" id="body"><?php echo htmlentities_utf8($row['definition']); ?></textarea>\r
110         </div>\r
111 \r
112         <div class="row">\r
113                 <?php echo _AT('glossary_related');  ?><br />\r
114         <?php\r
115                 $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] AND word_id<>$gid ORDER BY word";\r
116 \r
117                 $result = mysql_query($sql, $db);\r
118                 if ($row_g = mysql_fetch_array($result)) {\r
119                         echo '<select name="related_term">';\r
120                         echo '<option value="0"></option>';\r
121                         do {\r
122                                 if ($row_g['word_id'] == $row['word_id']) {\r
123                                         continue;\r
124                                 }\r
125                 \r
126                                 echo '<option value="'.$row_g['word_id'].'"';\r
127                         \r
128                                 if ($row_g['word_id'] == $row['related_word_id']) {\r
129                                         echo ' selected="selected" ';\r
130                                 }\r
131                         \r
132                                 echo '>'.htmlentities_utf8($row_g['word']).'</option>';\r
133                         } while ($row_g = mysql_fetch_array($result));\r
134                         \r
135                         echo '</select>';\r
136                 \r
137                 } else {\r
138                         echo  _AT('no_glossary_items');\r
139                 }\r
140         ?>\r
141         </div>\r
142         <div class="row buttons">\r
143                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />\r
144                 <input type="submit" name="cancel" value="<?php echo _AT('cancel');  ?>" />\r
145         </div>\r
146         </fieldset>\r
147 </div>\r
148 </form>\r
149 \r
150 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>