remove old readme
[atutor.git] / docs / 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                 $_POST['gid'] = intval($_POST['gid']);\r
54 \r
55                 $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
56                 \r
57                 $result = mysql_query($sql, $db);\r
58 \r
59                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
60                 Header('Location: index.php');\r
61                 exit;\r
62         }\r
63 }\r
64 \r
65 $onload = 'document.form.title.focus();';\r
66 \r
67 require(AT_INCLUDE_PATH.'header.inc.php');\r
68 \r
69 if ($_POST['submit']) {\r
70         $gid = intval($_POST['gid']);\r
71 } else {\r
72         $gid = intval($_GET['gid']);\r
73 }\r
74 \r
75 if ($gid == 0) {\r
76         $msg->printErrors('ITEM_NOT_FOUND');\r
77         require (AT_INCLUDE_PATH.'footer.inc.php');\r
78         exit;\r
79 }\r
80 \r
81 $msg->printErrors();\r
82 \r
83 $result = mysql_query("SELECT * FROM ".TABLE_PREFIX."glossary WHERE word_id=$gid", $db);\r
84 \r
85 if (!( $row = @mysql_fetch_array($result)) ) {\r
86         $msg->printErrors('ITEM_NOT_FOUND');\r
87         require (AT_INCLUDE_PATH.'footer.inc.php');\r
88         exit;\r
89 }\r
90 \r
91 if ($_POST['submit']) {\r
92         $row['word']            = $_POST['word'];\r
93         $row['definition']  = $_POST['definition'];\r
94 }\r
95 \r
96 ?>\r
97 \r
98 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
99 <input type="hidden" name="gid" value="<?php echo $gid; ?>" />\r
100 \r
101 <div class="input-form">\r
102         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_glossary'); ?></legend>\r
103         <div class="row">\r
104                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('glossary_term');  ?></label><br/ >\r
105                 <input type="text" name="word" size="40" id="title" value="<?php echo htmlentities_utf8($stripslashes($row['word'])); ?>" />\r
106         </div>\r
107 \r
108         <div class="row">\r
109                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="body"><?php echo _AT('glossary_definition'); ?></label><br />\r
110                 <textarea name="definition" cols="55" rows="7" id="body"><?php echo htmlentities_utf8($row['definition']); ?></textarea>\r
111         </div>\r
112 \r
113         <div class="row">\r
114                 <?php echo _AT('glossary_related');  ?><br />\r
115         <?php\r
116                 $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] AND word_id<>$gid ORDER BY word";\r
117 \r
118                 $result = mysql_query($sql, $db);\r
119                 if ($row_g = mysql_fetch_array($result)) {\r
120                         echo '<select name="related_term">';\r
121                         echo '<option value="0"></option>';\r
122                         do {\r
123                                 if ($row_g['word_id'] == $row['word_id']) {\r
124                                         continue;\r
125                                 }\r
126                 \r
127                                 echo '<option value="'.$row_g['word_id'].'"';\r
128                         \r
129                                 if ($row_g['word_id'] == $row['related_word_id']) {\r
130                                         echo ' selected="selected" ';\r
131                                 }\r
132                         \r
133                                 echo '>'.htmlentities_utf8($row_g['word']).'</option>';\r
134                         } while ($row_g = mysql_fetch_array($result));\r
135                         \r
136                         echo '</select>';\r
137                 \r
138                 } else {\r
139                         echo  _AT('no_glossary_items');\r
140                 }\r
141         ?>\r
142         </div>\r
143         <div class="row buttons">\r
144                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />\r
145                 <input type="submit" name="cancel" value="<?php echo _AT('cancel');  ?>" />\r
146         </div>\r
147         </fieldset>\r
148 </div>\r
149 </form>\r
150 \r
151 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>\r