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);
20 if (isset($_POST['cancel'])) {
21 $msg->addFeedback('CANCELLED');
22 header('Location: index_instructor.php');
26 if (isset($_GET['id'])) {
27 $id = intval($_GET['id']);
29 $id = intval($_POST['id']);
32 if (isset($_POST['submit'])) {
33 $_POST['question'] = trim($_POST['question']);
34 $_POST['answer'] = trim($_POST['answer']);
36 $missing_fields = array();
38 if (!$_POST['question']) {
39 $missing_fields[] = _AT('question');
42 if (!$_POST['answer']) {
43 $missing_fields[] = _AT('answer');
46 if ($missing_fields) {
47 $missing_fields = implode(', ', $missing_fields);
48 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
51 if (!$msg->containsErrors()) {
52 $_POST['question'] = $addslashes($_POST['question']);
53 $_POST['answer'] = $addslashes($_POST['answer']);
54 $_POST['topic_id'] = intval($_POST['topic_id']);
56 $sql = "UPDATE ".TABLE_PREFIX."faq_entries SET question='$_POST[question]', answer='$_POST[answer]', topic_id=$_POST[topic_id] WHERE entry_id=$id";
57 $result = mysql_query($sql,$db);
59 $msg->addFeedback('QUESTION_UPDATED');
60 header('Location: index_instructor.php');
64 $onload = 'document.form.topic.focus();';
66 require(AT_INCLUDE_PATH.'header.inc.php');
69 $msg->printErrors('ITEM_NOT_FOUND');
70 require (AT_INCLUDE_PATH.'footer.inc.php');
74 $sql = "SELECT * FROM ".TABLE_PREFIX."faq_entries WHERE entry_id=$id";
75 $result = mysql_query($sql,$db);
76 if (!($row = mysql_fetch_assoc($result))) {
77 $msg->printErrors('ITEM_NOT_FOUND');
78 require (AT_INCLUDE_PATH.'footer.inc.php');
83 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
84 $result = mysql_query($sql, $db);
85 $num_topics = mysql_num_rows($result);
87 $msg->printErrorS('NO_FAQ_TOPICS');
88 require(AT_INCLUDE_PATH.'footer.inc.php');
94 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
95 <input type="hidden" name="id" value="<?php echo $row['entry_id']; ?>" />
97 <div class="input-form">
100 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
101 $result = mysql_query($sql, $db);
104 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="topic"><?php echo _AT('topic'); ?></label><br />
105 <select name="topic_id" id="topic">
106 <?php while ($topic_row = mysql_fetch_assoc($result)): ?>
107 <option value="<?php echo $topic_row['topic_id']; ?>"<?php if ($topic_row['topic_id'] == $row['topic_id']) { echo ' selected="selected"'; } ?>><?php echo htmlspecialchars($topic_row['name']); ?></option>
113 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?>:</label><br />
114 <input type="text" name="question" size="50" id="question" value="<?php if (isset ($_POST['question'])) { echo $stripslashes($_POST['question']); } else { echo $row['question']; } ?>" />
118 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="answer"><?php echo _AT('answer'); ?></label><br />
119 <textarea name="answer" cols="45" rows="3" id="answer" style="width:90%;"><?php if (isset ($_POST['answer'])) { echo $stripslashes($_POST['answer']); } else { echo $row['answer']; } ?></textarea>
122 <div class="row buttons">
123 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
124 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
129 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>