2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************************/
15 define('AT_INCLUDE_PATH', '../../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_GLOSSARY);
20 if ($_POST['cancel']) {
21 $msg->addFeedback('CANCELLED');
22 header('Location: index.php');
26 if (isset($_POST['submit'])) {
27 $num_terms = intval($_POST['num_terms']);
28 $missing_fields = array();
30 for ($i=0; $i<$num_terms; $i++) {
32 if ($_POST['ignore'][$i] == '') {
33 $_POST['word'][$i] = trim($_POST['word'][$i]);
34 $_POST['definition'][$i] = trim($_POST['definition'][$i]);
36 if ($_POST['word'][$i] == '') {
37 $missing_fields[] = _AT('glossary_term');
39 //60 is defined by the sql
40 $_POST['word'][$i] = validate_length($_POST['word'][$i], 60);
44 if ($_POST['definition'][$i] == '') {
45 $missing_fields[] = _AT('glossary_definition');
48 if ($terms_sql != '') {
52 $_POST['related_term'][$i] = intval($_POST['related_term'][$i]);
54 /* for each item check if it exists: */
56 if ($glossary[urlencode($_POST['word'][$i])] != '' ) {
57 $errors = array('TERM_EXISTS', $_POST['word'][$i]);
58 $msg->addError($errors);
60 $_POST['word'][$i] = $addslashes($_POST['word'][$i]);
61 $_POST['definition'][$i] = $addslashes($_POST['definition'][$i]);
62 $_POST['related_term'][$i] = $addslashes($_POST['related_term'][$i]);
64 $terms_sql .= "(NULL, $_SESSION[course_id], '{$_POST[word][$i]}', '{$_POST[definition][$i]}', {$_POST[related_term][$i]})";
69 if ($missing_fields) {
70 $missing_fields = implode(', ', $missing_fields);
71 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
74 if (!$msg->containsErrors()) {
75 $sql = "INSERT INTO ".TABLE_PREFIX."glossary VALUES $terms_sql";
76 $result = mysql_query($sql, $db);
78 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
79 header('Location: index.php');
82 $_GET['pcid'] = $_POST['pcid'];
85 $onload = 'document.form.title0.focus();';
90 $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";
91 $result_glossary = mysql_query($sql, $db);
93 require(AT_INCLUDE_PATH.'header.inc.php');
94 $savant->assign('result_glossary', $result_glossary);
95 $savant->assign('num_terms', $num_terms);
96 $savant->display('instructor/glossary/add.tmpl.php');
97 require(AT_INCLUDE_PATH.'footer.inc.php');