remove old readme
[atutor.git] / mods / _standard / forums / forum / delete_thread.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
14 define('AT_INCLUDE_PATH', '../../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 include(AT_INCLUDE_PATH.'../mods/_standard/forums/lib/forums.inc.php');
17
18 authenticate(AT_PRIV_FORUMS);
19
20 $pid  = intval($_REQUEST['pid']);
21 $ppid = intval($_REQUEST['ppid']);
22 $fid  = intval($_REQUEST['fid']);
23
24 if (!valid_forum_user($fid)) {
25         $msg->addError('FORUM_NOT_FOUND');
26         header('Location: list.php');
27         exit;
28 }
29
30 if (isset($_POST['submit_no'])) {
31         
32         $msg->addFeedback('CANCELLED'); 
33         if ($_POST['nest']) {
34                 header('Location: view.php?fid='.$_POST['fid'].SEP.'pid='. ($_POST['ppid'] ? $_POST['ppid'] : $_POST['pid']));
35                 exit;
36         } else {
37                 header('Location: index.php?fid='.$_POST['fid']);
38                 exit;
39         }
40
41         exit;
42
43 } else if (isset($_POST['submit_yes'])) {
44         // check if they have access
45         if (!valid_forum_user($fid)) {
46                 $msg->addError('FORUM_NOT_FOUND');
47                 header('Location: list.php');
48                 exit;
49         }
50
51         if ($ppid == 0) {   /* If deleting an entire post */
52                 /* First get number of comments from specific post */
53                 $sql    = "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$pid AND forum_id=$fid";
54                 $result = mysql_query($sql, $db);
55                 if (!($row = mysql_fetch_assoc($result))) {
56                         $msg->addError('FORUM_NOT_FOUND');
57                         header('Location: list.php');
58                         exit;
59
60                 } // else:
61
62                 /* Decrement count for number of posts and topics*/
63                 $sql    = "UPDATE ".TABLE_PREFIX."forums SET num_posts=num_posts-1-".$row['num_comments'].", num_topics=num_topics-1, last_post=last_post WHERE forum_id=$fid";
64                 $result = mysql_query($sql, $db);
65
66                 $sql    = "DELETE FROM ".TABLE_PREFIX."forums_threads WHERE (parent_id=$pid OR post_id=$pid) AND forum_id=$fid";
67                 $result = mysql_query($sql, $db);
68
69                 $sql    = "DELETE FROM ".TABLE_PREFIX."forums_accessed WHERE post_id=$pid";
70                 $result = mysql_query($sql, $db);
71
72         } else {   /* Just deleting a single thread */
73                 $sql    = "DELETE FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$pid AND forum_id=$fid";
74                 $result = mysql_query($sql, $db);
75                 if (mysql_affected_rows($db) == 0) {
76                         $msg->addError('FORUM_NOT_FOUND');
77                         header('Location: list.php');
78                         exit;
79                 }
80
81             /* Decrement count of comments in forums_threads table*/
82                 $sql    = "UPDATE ".TABLE_PREFIX."forums_threads SET num_comments=num_comments-1, last_comment=last_comment, date=date WHERE post_id=$ppid";
83                 $result = mysql_query($sql, $db);
84
85                 /* Decrement count of posts in forums table */
86                 $sql    = "UPDATE ".TABLE_PREFIX."forums SET num_posts=num_posts-1, last_post=last_post WHERE forum_id=$fid";
87                 $result = mysql_query($sql, $db);
88
89         }
90
91         if ($ppid) {
92                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
93                 header('Location: view.php?fid='.$fid.SEP.'pid='.$ppid);
94                 exit;
95         } else {
96                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
97                 header('Location: index.php?fid='.$fid);
98                 exit;
99         }
100 }
101
102 $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['title']    = get_forum_name($fid);
103 $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['parent']   = 'forum/list.php';
104 $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['children'] = array('mods/_standard/forums/forum/new_thread.php?fid='.$fid);
105
106 $_pages['mods/_standard/forums/forum/new_thread.php?fid='.$fid]['title_var'] = 'new_thread';
107 $_pages['mods/_standard/forums/forum/new_thread.php?fid='.$fid]['parent']    = 'mods/_standard/forums/forum/index.php?fid='.$fid;
108
109 $_pages['mods/_standard/forums/forum/view.php']['title']  = $post_row['subject'];
110 $_pages['mods/_standard/forums/forum/view.php']['parent'] = 'forum/index.php?fid='.$fid;
111
112 $_pages['mods/_standard/forums/forum/delete_thread.php']['title_var'] = 'delete_post';
113 $_pages['mods/_standard/forums/forum/delete_thread.php']['parent']    = 'mods/_standard/forums/forum/index.php?fid='.$fid;
114 $_pages['mods/_standard/forums/forum/delete_thread.php']['children']  = array();
115
116 require(AT_INCLUDE_PATH.'header.inc.php');
117
118
119 $sql = "SELECT * from ".TABLE_PREFIX."forums_threads WHERE post_id = '$pid'";
120 $result = mysql_query($sql, $db);
121 $row = mysql_fetch_assoc($result);
122 $title = AT_print($row['subject'], 'forums_threads.subject');
123
124
125 $hidden_vars['fid']  = $_GET['fid'];
126 $hidden_vars['pid']  = $_GET['pid'];
127 $hidden_vars['ppid'] = $_GET['ppid'];
128 $hidden_vars['nest'] = $_GET['nest'];
129
130 $msg->addConfirm(array('DELETE', $title),$hidden_vars);
131 if (($ppid=='') || ($ppid =='0')) {
132         $ppid = '0';
133 }
134
135 $msg->printConfirm();
136
137 require(AT_INCLUDE_PATH.'footer.inc.php');
138 ?>