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);
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');
95 $sql = "SELECT name, topic_id FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] ORDER BY name";
96 $result = mysql_query($sql, $db);
97 $faq_topics = array();
98 while ($topic_row = mysql_fetch_assoc($result)){
99 $faq_topics[] = $topic_row;
104 $savant->assign('row', $row);
105 $savant->assign('result', $result);
106 $savant->assign('faq_topics', $faq_topics);
107 $savant->display('instructor/faq/edit_question.tmpl.php');
108 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>