tagging as ATutor 1.5.4-release
[atutor.git] / editor / edit_forum.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton        */
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
15 define('AT_INCLUDE_PATH', '../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17
18 authenticate(AT_PRIV_FORUMS);
19
20 require (AT_INCLUDE_PATH.'lib/forums.inc.php');
21
22 if (isset($_POST['cancel'])) {
23         $msg->addFeedback('CANCELLED');
24         header('Location: '.AT_BASE_HREF.'tools/forums/index.php');
25         exit;
26 } else if (isset($_POST['edit_forum'])) {
27         $_POST['fid'] = intval($_POST['fid']);
28
29         if ($_POST['title'] == '') {
30                 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
31         }
32
33         if (!$msg->containsErrors()) {
34                 if (!is_shared_forum($_POST['fid'])) {
35                         edit_forum($_POST);
36                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
37                 } else {
38                         $msg->addError('FORUM_NO_EDIT_SHARE');
39                 }
40                 
41                 header('Location: '.AT_BASE_HREF.'tools/forums/index.php');
42                 exit;
43         }
44 }
45
46 $onload = 'document.form.title.focus();';
47 require(AT_INCLUDE_PATH.'header.inc.php');
48
49 $fid = intval($_REQUEST['fid']);
50
51 if (!isset($_POST['submit'])) {
52         $row = get_forum($fid, $_SESSION['course_id']);
53         if (!is_array($row)) {
54                 $msg->addError('FORUM_NOT_FOUND');
55                 $msg->printALL();
56                 require(AT_INCLUDE_PATH.'footer.inc.php');
57                 exit;
58         }
59 } else {
60         $row['description'] = $_POST['body'];
61         $row['mins_to_edit'] = $_POST['edit'];
62 }
63
64 $msg->printErrors();
65
66 ?>
67 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
68 <input type="hidden" name="edit_forum" value="true">
69 <input type="hidden" name="fid" value="<?php echo $fid; ?>">
70
71 <div class="input-form">
72         <div class="row">
73                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="title"><?php echo _AT('title'); ?></label><br />
74                 <input type="text" name="title" size="50" id="title" value="<?php echo htmlspecialchars(stripslashes($row['title'])); ?>" />
75         </div>
76
77         <div class="row">
78                 <label for="body"><?php echo _AT('description'); ?></label><br />
79                 <textarea name="body" cols="45" rows="2" id="body" wrap="wrap"><?php echo $row['description']; ?></textarea>
80         </div>
81
82         <div class="row">
83                 <label for="edit"><?php echo _AT('allow_editing'); ?></label><br />
84                 <input type="text" name="edit" size="3" id="edit" value="<?php echo intval($row['mins_to_edit']); ?>" /> <?php echo _AT('in_minutes'); ?>
85         </div>
86
87         <div class="row buttons">
88                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" /> 
89                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
90         </div>
91 </div>
92 </form>
93
94 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>