remove old readme
[atutor.git] / docs / mods / _core / glossary / tools / add.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2010                                                  */
6 /* Inclusive Design Institute                                               */
7 /* http://atutor.ca                                                                                                                     */
8 /*                                                                                                                                                      */
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 /****************************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18 authenticate(AT_PRIV_GLOSSARY);
19
20 if ($_POST['cancel']) { 
21         $msg->addFeedback('CANCELLED');
22         header('Location: index.php');
23         exit;
24 }
25
26 if (isset($_POST['submit'])) {
27         $num_terms = intval($_POST['num_terms']);
28         $missing_fields = array();
29
30         for ($i=0; $i<$num_terms; $i++) {
31
32                 if ($_POST['ignore'][$i] == '') {
33                         $_POST['word'][$i] = trim($_POST['word'][$i]);
34                         $_POST['definition'][$i] = trim($_POST['definition'][$i]);
35
36                         if ($_POST['word'][$i] == '') {
37                                 $missing_fields[] = _AT('glossary_term');
38                         } else{
39                                 //60 is defined by the sql
40                                 $_POST['word'][$i] = validate_length($_POST['word'][$i], 60);
41                         }
42                         
43
44                         if ($_POST['definition'][$i] == '') {
45                                 $missing_fields[] = _AT('glossary_definition');
46                         }
47
48                         if ($terms_sql != '') {
49                                 $terms_sql .= ', ';
50                         }
51
52                         $_POST['related_term'][$i] = intval($_POST['related_term'][$i]);
53
54                         /* for each item check if it exists: */
55
56                         if ($glossary[urlencode($_POST['word'][$i])] != '' ) {
57                                 $errors = array('TERM_EXISTS', $_POST['word'][$i]);
58                                 $msg->addError($errors);
59                         } else {
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]);
63
64                                 $terms_sql .= "(NULL, $_SESSION[course_id], '{$_POST[word][$i]}', '{$_POST[definition][$i]}', {$_POST[related_term][$i]})";
65                         }
66                 }
67         }
68
69         if ($missing_fields) {
70                 $missing_fields = implode(', ', $missing_fields);
71                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
72         }
73
74         if (!$msg->containsErrors()) {
75                 $sql = "INSERT INTO ".TABLE_PREFIX."glossary VALUES $terms_sql";
76                 $result = mysql_query($sql, $db);
77
78                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
79                 header('Location: index.php');
80                 exit;
81         }
82         $_GET['pcid'] = $_POST['pcid'];
83 }
84
85 $onload = 'document.form.title0.focus();';
86
87 unset($word);
88
89 $num_terms = 1;
90 $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";
91 $result_glossary = mysql_query($sql, $db);
92
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'); 
98
99
100 ?>