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 /****************************************************************/
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');
77 $savant->assign('result', $result);
78 $savant->display('instructor/faq/add_question.tmpl.php');
79 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>