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 /****************************************************************/
13 // $Id: add_question.php 10142 2010-08-17 19:17:26Z hwong $
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']);
47 //These will truncate the content of the length to 240 as defined in the db.
48 $_POST['question'] = validate_length($_POST['question'], 250);
49 $_POST['answer'] = validate_length($_POST['answer'], 250);
51 // check that this topic_id belongs to this course:
52 $sql = "SELECT topic_id FROM ".TABLE_PREFIX."faq_topics WHERE topic_id=$_POST[topic_id] AND course_id=$_SESSION[course_id]";
53 $result = mysql_query($sql, $db);
54 if ($row = mysql_fetch_assoc($result)) {
55 $sql = "INSERT INTO ".TABLE_PREFIX."faq_entries VALUES (NULL, $_POST[topic_id], NOW(), 1, '$_POST[question]', '$_POST[answer]')";
56 $result = mysql_query($sql,$db);
59 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
60 header('Location: index_instructor.php');
65 $onload = 'document.form.topic.focus();';
67 require(AT_INCLUDE_PATH.'header.inc.php');
69 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
70 $result = mysql_query($sql, $db);
71 $num_topics = mysql_num_rows($result);
73 $msg->printErrors('NO_FAQ_TOPICS');
74 require(AT_INCLUDE_PATH.'footer.inc.php');
79 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
81 <div class="input-form">
82 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('add_question'); ?></legend>
85 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="topic"><?php echo _AT('topic'); ?></label><br />
86 <select name="topic_id" id="topic">
87 <?php while ($row = mysql_fetch_assoc($result)): ?>
88 <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>
93 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label><br />
94 <input type="text" name="question" size="50" id="question" value="<?php if (isset($_POST['question'])) echo htmlentities_utf8($stripslashes($_POST['question'])); ?>" />
98 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="answer"><?php echo _AT('answer'); ?></label><br />
99 <textarea name="answer" cols="45" rows="3" id="answer" style="width:90%;"><?php if (isset ($_POST['answer'])) echo htmlentities_utf8($stripslashes($_POST['answer'])); ?></textarea>
103 <div class="row buttons">
104 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
105 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
111 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>