tagging as ATutor 1.5.4-release
[atutor.git] / faq / edit_topic.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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
40                 $sql    = "UPDATE ".TABLE_PREFIX."faq_topics SET name='$_POST[name]' WHERE topic_id=$id AND course_id=$_SESSION[course_id]";
41                 $result = mysql_query($sql,$db);
42
43                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
44                 header('Location: index_instructor.php');
45                 exit;
46         }
47 }
48 $onload = 'document.form.name.focus();';
49
50 require(AT_INCLUDE_PATH.'header.inc.php');
51
52 if ($id == 0) {
53         $msg->printErrors('ITEM_NOT_FOUND');
54         require (AT_INCLUDE_PATH.'footer.inc.php');
55         exit;
56 }
57
58 $sql    = "SELECT name FROM ".TABLE_PREFIX."faq_topics WHERE course_id=$_SESSION[course_id] AND topic_id=$id ORDER BY name";
59 $result = mysql_query($sql, $db);
60 if (!$row = mysql_fetch_assoc($result)) {
61         $msg->printErrorS('ITEM_NOT_FOUND');
62         require(AT_INCLUDE_PATH.'footer.inc.php');
63         exit;
64 } else if (!$_POST['name']) {
65         $_POST['name'] = $row['name'];
66 }
67
68 ?>
69
70 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
71 <input type="hidden" name="id" value="<?php echo $id; ?>" />
72
73 <div class="input-form">
74         <div class="row">
75                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="name"><?php  echo _AT('name'); ?></label><br />
76                 <input type="text" name="name" size="50" id="name" value="<?php if (isset($_POST['name'])) echo $stripslashes($_POST['name']);  ?>" />
77         </div>
78
79         <div class="row buttons">
80                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
81                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
82         </div>
83
84 </div>
85 </form>
86 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>