60c3b0ac229bd211a7bacb63dfc4f63cf0cd91a4
[atutor.git] / docs / mods / _standard / forums / forum / subscribe_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: index.php 2526 2004-11-25 18:54:16Z greg$
14
15 define('AT_INCLUDE_PATH', '../../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 include(AT_INCLUDE_PATH.'../mods/_standard/forums/lib/forums.inc.php');
18
19 $fid = intval($_REQUEST['fid']);
20
21 // check if they have access
22 if (!valid_forum_user($fid) || !$_SESSION['enroll']) {
23         $msg->addError('FORUM_NOT_FOUND');
24         header('Location: list.php');
25         exit;
26 }
27
28 $sql = "SELECT title FROM ".TABLE_PREFIX."forums WHERE forum_id=$fid";
29 $result = mysql_query($sql, $db);
30 if ($row = mysql_fetch_assoc($result)) {
31         $forum_title = $row['title'];
32 } else {
33         $msg->addError('FORUM_NOT_FOUND');
34         header('Location: list.php');
35         exit;
36 }
37
38 if (isset($_GET['us'])) {
39         $sql = "DELETE from ".TABLE_PREFIX."forums_subscriptions WHERE forum_id = $fid AND member_id = $_SESSION[member_id]";
40         $result = mysql_query($sql, $db);
41         $msg->addFeedback(array(FORUM_UNSUBSCRIBED, $forum_title));
42
43 } else {
44         $sql = "INSERT into ".TABLE_PREFIX."forums_subscriptions VALUES($fid, '$_SESSION[member_id]')";
45         mysql_query($sql, $db);
46
47         $msg->addFeedback(array(FORUM_SUBSCRIBED,$forum_title));
48 }
49
50 header('Location: list.php');
51 exit;
52 ?>