91bf8226ce4dcab6c3f6e4a996eb0771ddec784d
[atutor.git] / docs / mods / _standard / faq / edit_topic.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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$
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
16
17 authenticate(AT_PRIV_FAQ);
18
19
20 if (isset($_POST['cancel'])) {
21         $msg->addFeedback('CANCELLED');
22         header('Location: index_instructor.php');
23         exit;
24
25
26 if (isset($_GET['id'])) {
27         $id = intval($_GET['id']);
28 } else {
29         $id = intval($_POST['id']);
30 }
31
32 if (isset($_POST['submit'])) {
33         if (trim($_POST['name']) == '') {
34                 $msg->addError('NAME_EMPTY');
35         }
36
37         if (!$msg->containsErrors()) {
38                 $_POST['name'] = $addslashes($_POST['name']);
39                 //This will truncate the content of the length to 240 as defined in the db.
40                 $_POST['name'] = validate_length($_POST['name'], 250);
41
42                 $sql    = "UPDATE ".TABLE_PREFIX."faq_topics SET name='$_POST[name]' WHERE topic_id=$id AND course_id=$_SESSION[course_id]";
43                 $result = mysql_query($sql,$db);
44
45                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
46                 header('Location: index_instructor.php');
47                 exit;
48         }
49 }
50 $onload = 'document.form.name.focus();';
51
52 require(AT_INCLUDE_PATH.'header.inc.php');
53
54 if ($id == 0) {
55         $msg->printErrors('ITEM_NOT_FOUND');
56         require (AT_INCLUDE_PATH.'footer.inc.php');
57         exit;
58 }
59
60 $sql    = "SELECT name FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] AND topic_id=$id ORDER BY name";
61 $result = mysql_query($sql, $db);
62 if (!$row = mysql_fetch_assoc($result)) {
63         $msg->printErrorS('ITEM_NOT_FOUND');
64         require(AT_INCLUDE_PATH.'footer.inc.php');
65         exit;
66 } else if (!isset($_POST['name'])) {
67         $_POST['name'] = $row['name'];
68 }
69 $savant->assign('id', $id);
70 $savant->display('instructor/faq/edit_topic.tmpl.php');
71 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>