2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_FAQ);
19 if (isset($_POST['cancel'])) {
20 $msg->addFeedback('CANCELLED');
21 header('Location: index_instructor.php');
23 } else if (isset($_POST['submit'])) {
24 $_POST['question'] = trim($_POST['question']);
25 $_POST['answer'] = trim($_POST['answer']);
27 $missing_fields = array();
29 if (!$_POST['question']) {
30 $missing_fields[] = _AT('question');
33 if (!$_POST['answer']) {
34 $missing_fields[] = _AT('answer');
37 if ($missing_fields) {
38 $missing_fields = implode(', ', $missing_fields);
39 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
43 if (!$msg->containsErrors()) {
44 $_POST['question'] = $addslashes($_POST['question']);
45 $_POST['answer'] = $addslashes($_POST['answer']);
46 $_POST['topic_id'] = intval($_POST['topic_id']);
48 // check that this topic_id belongs to this course:
49 $sql = "SELECT topic_id FROM ".TABLE_PREFIX."faq_topics WHERE topic_id=$_POST[topic_id] AND course_id=$_SESSION[course_id]";
50 $result = mysql_query($sql, $db);
51 if ($row = mysql_fetch_assoc($result)) {
52 $sql = "INSERT INTO ".TABLE_PREFIX."faq_entries VALUES (NULL, $_POST[topic_id], NOW(), 1, '$_POST[question]', '$_POST[answer]')";
53 $result = mysql_query($sql,$db);
56 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
57 header('Location: index_instructor.php');
62 $onload = 'document.form.topic.focus();';
64 require(AT_INCLUDE_PATH.'header.inc.php');
66 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
67 $result = mysql_query($sql, $db);
68 $num_topics = mysql_num_rows($result);
70 $msg->printErrors('NO_FAQ_TOPICS');
71 require(AT_INCLUDE_PATH.'footer.inc.php');
76 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
78 <div class="input-form">
81 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="topic"><?php echo _AT('topic'); ?></label><br />
82 <select name="topic_id" id="topic">
83 <?php while ($row = mysql_fetch_assoc($result)): ?>
84 <option value="<?php echo $row['topic_id']; ?>"<?php if (isset($_POST['topic_id']) && ($row['topic_id'] == $_POST['topic_id'])) { echo ' selected="selected"'; } ?>><?php echo htmlspecialchars($row['name']); ?></option>
89 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label><br />
90 <input type="text" name="question" size="50" id="question" value="<?php if (isset($_POST['question'])) echo $stripslashes($_POST['question']); ?>" />
94 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="answer"><?php echo _AT('answer'); ?></label><br />
95 <textarea name="answer" cols="45" rows="3" id="answer" style="width:90%;"><?php if (isset ($_POST['answer'])) echo $stripslashes($_POST['answer']); ?></textarea>
99 <div class="row buttons">
100 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
101 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
106 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>