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();';
91 require(AT_INCLUDE_PATH.'header.inc.php');
95 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
96 <input type="hidden" name="num_terms" value="<?php echo $num_terms; ?>" />
98 for ($i=0;$i<$num_terms;$i++) {
99 if ($glossary[$word[$i]] != '') {
100 echo '<input type="hidden" name="ignore['.$i.']" value="1" />';
104 for ($j=0;$j<$i;$j++) {
105 if ($word[$j] == $word[$i]) {
106 echo '<input type="hidden" name="ignore['.$i.']" value="1" />';
111 if ($word[$i] == '') {
112 $word[$i] = ContentManager::cleanOutput($_POST['word'][$i]);
115 <div class="input-form">
116 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('add_glossary'); ?></legend>
118 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title<?php echo $i; ?>"><?php echo _AT('glossary_term'); ?></label><br />
119 <input type="text" name="word[<?php echo $i; ?>]" size="30" value="<?php echo trim($word[$i]); ?>" id="title<?php echo $i; ?>" /><?php
120 if ($_GET['pcid'] != '') {
121 echo '<input type="checkbox" name="ignore['.$i.']" value="1" id="ig'.$i.'" /><label for="ig'.$i.'">Ignore this term</label>.';
127 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="body<?php echo $i; ?>"><?php echo _AT('glossary_definition'); ?></label><br />
128 <textarea name="definition[<?php echo $i; ?>]" class="formfield" cols="55" rows="7" id="body<?php echo $i; ?>" style="width:90%;"><?php echo ContentManager::cleanOutput($_POST['definition'][$i]); ?></textarea>
132 <?php echo _AT('glossary_related'); ?><br />
134 $sql = "SELECT * FROM ".TABLE_PREFIX."glossary WHERE course_id=$_SESSION[course_id] ORDER BY word";
135 $result = mysql_query($sql, $db);
136 if ($row_g = mysql_fetch_assoc($result)) {
137 echo '<select name="related_term['.$i.']">';
138 echo '<option value="0"></option>';
140 echo '<option value="'.$row_g['word_id'].'">'.$row_g['word'].'</option>';
141 } while ($row_g = mysql_fetch_assoc($result));
144 echo _AT('none_available');
150 <div class="row buttons">
151 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
152 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
158 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>