2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 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']);
55 //These will truncate the content of the length to 240 as defined in the db.
56 $_POST['question'] = validate_length($_POST['question'], 250);
57 $_POST['answer'] = validate_length($_POST['answer'], 250);
59 $sql = "UPDATE ".TABLE_PREFIX."faq_entries SET question='$_POST[question]', answer='$_POST[answer]', topic_id=$_POST[topic_id] WHERE entry_id=$id";
60 $result = mysql_query($sql,$db);
62 $msg->addFeedback('QUESTION_UPDATED');
63 header('Location: index_instructor.php');
67 $onload = 'document.form.topic.focus();';
69 require(AT_INCLUDE_PATH.'header.inc.php');
72 $msg->printErrors('ITEM_NOT_FOUND');
73 require (AT_INCLUDE_PATH.'footer.inc.php');
77 $sql = "SELECT * FROM ".TABLE_PREFIX."faq_entries WHERE entry_id=$id";
78 $result = mysql_query($sql,$db);
79 if (!($row = mysql_fetch_assoc($result))) {
80 $msg->printErrors('ITEM_NOT_FOUND');
81 require (AT_INCLUDE_PATH.'footer.inc.php');
86 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
87 $result = mysql_query($sql, $db);
88 $num_topics = mysql_num_rows($result);
90 $msg->printErrorS('NO_FAQ_TOPICS');
91 require(AT_INCLUDE_PATH.'footer.inc.php');
97 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
98 <input type="hidden" name="id" value="<?php echo $row['entry_id']; ?>" />
100 <div class="input-form">
101 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create_new_file'); ?></legend>
104 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
105 $result = mysql_query($sql, $db);
108 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="topic"><?php echo _AT('topic'); ?></label><br />
109 <select name="topic_id" id="topic">
110 <?php while ($topic_row = mysql_fetch_assoc($result)): ?>
111 <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>
117 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?>:</label><br />
118 <input type="text" name="question" size="50" id="question" value="<?php if (isset ($_POST['question'])) { echo $stripslashes($_POST['question']); } else { echo $row['question']; } ?>" />
122 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="answer"><?php echo _AT('answer'); ?></label><br />
123 <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>
126 <div class="row buttons">
127 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
128 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
133 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>