remove old readme
[atutor.git] / docs / 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$
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                 $sql = "SELECT course_id, title FROM ".TABLE_PREFIX."courses ORDER BY title";
66                 $result = mysql_query($sql, $db);
67                 $savant->assign('result', $result);             
68
69 require(AT_INCLUDE_PATH.'header.inc.php'); 
70
71 $savant->assign('system_courses', $system_courses);
72 $savant->display('admin/courses/forum_add.tmpl.php');
73 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>