ATutor 2.0
[atutor.git] / mods / _standard / forums / admin / forum_add.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id: forum_add.php 7208 2008-01-09 16:07:24Z greg $
13
14 define('AT_INCLUDE_PATH', '../../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate(AT_ADMIN_PRIV_FORUMS);
17
18 if (isset($_POST['cancel'])) {
19         $msg->addFeedback('CANCELLED');
20         header('Location: '.AT_BASE_HREF.'mods/_standard/forums/admin/forums.php');
21         exit;
22 } else if (isset($_POST['add_forum'])) {
23         $missing_fields = array();
24
25         if (empty($_POST['title'])) {
26                 $missing_fields[] = _AT('title');
27         } 
28
29         if (empty($_POST['courses'])) {
30                 $missing_fields[] = _AT('courses');
31         } 
32
33         if ($missing_fields) {
34                 $missing_fields = implode(', ', $missing_fields);
35                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
36         }
37
38         $_POST['edit'] = intval($_POST['edit']);
39
40         if (!($msg->containsErrors())) {
41                 //add forum
42                 $sql    = "INSERT INTO ".TABLE_PREFIX."forums (title, description, mins_to_edit) VALUES ('" . $_POST['title'] . "','" . $_POST['description'] ."', $_POST[edit])";
43                 $result = mysql_query($sql, $db);
44                 $forum_id = mysql_insert_id($db);
45                 write_to_log(AT_ADMIN_LOG_INSERT, 'forums', mysql_affected_rows($db), $sql);
46
47                 //for each course, add an entry to the forums_courses table
48                 foreach ($_POST['courses'] as $course) {
49                         $sql    = "INSERT INTO ".TABLE_PREFIX."forums_courses VALUES (" . $forum_id . "," . $course . ")";
50                         $result = mysql_query($sql, $db);
51                         write_to_log(AT_ADMIN_LOG_INSERT, 'forums_courses', mysql_affected_rows($db), $sql);
52                 }
53
54                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
55                 if($course =="0"){
56                         $msg->addFeedback('FORUM_POSTING');
57                 }
58                 header('Location: '.AT_BASE_HREF.'mods/_standard/forums/admin/forums.php');
59                 exit;
60         }
61 }
62
63 $onload = 'document.form.title.focus();';
64
65 require(AT_INCLUDE_PATH.'header.inc.php'); 
66
67 ?>
68 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
69 <input type="hidden" name="add_forum" value="true">
70
71 <div class="input-form">
72         <div class="row">
73                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
74                 <input type="text" name="title" size="40" id="title" value="<?php echo $_POST['title']; ?>" />
75         </div>
76
77         <div class="row">
78                 <label for="body"><?php echo _AT('description'); ?></label><br />
79                 <textarea name="description" cols="45" rows="2" id="body" wrap="wrap"><?php echo $_POST['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">
88                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="courses"><?php echo _AT('courses'); ?></label><br />
89                 <?php if ($system_courses): ?>
90                         <select name="courses[]" id="courses" multiple="multiple" size="5"><?php
91                 
92                                 $sql = "SELECT course_id, title FROM ".TABLE_PREFIX."courses ORDER BY title";
93                                 $result = mysql_query($sql, $db);
94                                 while ($row = mysql_fetch_assoc($result)) {
95                                         echo '<option value="'.$row['course_id'].'">'.$row['title'].'</option>';                
96                                 }
97                                 ?>
98                         </select>
99                 <?php else: ?>
100                         <span id="courses"><?php echo _AT('no_courses_found'); ?></span>
101                 <?php endif; ?>
102         </div>
103
104         <div class="row buttons">
105                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" /> 
106                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
107         </div>
108 </div>
109 </form>
110
111 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>