The tag for ATutor 2.0.3 release.
[atutor.git] / mods / _standard / forums / edit_forum.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
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.'../mods/_standard/forums/lib/forums.inc.php');
21
22 if (isset($_POST['cancel'])) {
23         $msg->addFeedback('CANCELLED');
24         header('Location: '.AT_BASE_HREF.'mods/_standard/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         } else {
32                 $_POST['title'] = validate_length($_POST['title'], 60);
33         }
34
35         if (!$msg->containsErrors()) {
36                 if (!is_shared_forum($_POST['fid'])) {
37                         edit_forum($_POST);
38                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
39                 } else {
40                         $msg->addError('FORUM_NO_EDIT_SHARE');
41                 }
42                 
43                 header('Location: '.AT_BASE_HREF.'mods/_standard/forums/index.php');
44                 exit;
45         }
46 }
47
48 $onload = 'document.form.title.focus();';
49 require(AT_INCLUDE_PATH.'header.inc.php');
50
51 $fid = intval($_REQUEST['fid']);
52
53 if (!isset($_POST['submit'])) {
54         $row = get_forum($fid, $_SESSION['course_id']);
55         if (!is_array($row)) {
56                 $msg->addError('FORUM_NOT_FOUND');
57                 $msg->printALL();
58                 require(AT_INCLUDE_PATH.'footer.inc.php');
59                 exit;
60         }
61 } else {
62         $row['description'] = $_POST['body'];
63         $row['mins_to_edit'] = $_POST['edit'];
64 }
65
66 $msg->printErrors();
67
68 ?>
69 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
70 <input type="hidden" name="edit_forum" value="true">
71 <input type="hidden" name="fid" value="<?php echo $fid; ?>">
72
73 <div class="input-form">
74         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_forum'); ?></legend>
75         <div class="row">
76                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
77                 <input type="text" name="title" size="50" id="title" value="<?php echo htmlspecialchars(stripslashes($row['title'])); ?>" />
78         </div>
79
80         <div class="row">
81                 <label for="body"><?php echo _AT('description'); ?></label><br />
82                 <textarea name="body" cols="45" rows="2" id="body" wrap="wrap"><?php echo AT_print($row['description'], 'input.text'); ?></textarea>
83         </div>
84
85         <div class="row">
86                 <label for="edit"><?php echo _AT('allow_editing'); ?></label><br />
87                 <input type="text" name="edit" size="3" id="edit" value="<?php echo intval($row['mins_to_edit']); ?>" /> <?php echo _AT('in_minutes'); ?>
88         </div>
89
90         <div class="row buttons">
91                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" /> 
92                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
93         </div>
94         </fieldset>
95 </div>
96 </form>
97
98 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>