remove old readme
[atutor.git] / mods / _standard / forums / forum / move_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 $_REQUEST['pid']  = intval($_REQUEST['pid']);
21 $_REQUEST['ppid'] = intval($_REQUEST['ppid']);
22 $_REQUEST['fid']  = intval($_REQUEST['fid']);
23
24 if (!valid_forum_user($_REQUEST['fid'])) {
25         $msg->addError('FORUM_NOT_FOUND');
26         header('Location: list.php');
27         exit;
28 }
29
30 if (isset($_POST['cancel'])) {
31         $msg->addFeedback('CANCELLED'); 
32         header('Location: index.php?fid='.$_REQUEST['fid']);
33         exit;
34
35 } else if (isset($_POST['submit'])) {
36         // check if they have access
37         if (!valid_forum_user($_REQUEST['fid']) || !valid_forum_user($_REQUEST['new_fid'])) {
38                 $msg->addError('FORUM_NOT_FOUND');
39                 header('Location: list.php');
40                 exit;
41         }
42
43         if ($_REQUEST['fid'] == $_REQUEST['new_fid']) {
44                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
45                 header('Location: index.php?fid='.$_REQUEST['fid']);
46                 exit;
47         }
48
49         $sql    = "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$_REQUEST[pid] AND forum_id=$_REQUEST[fid]";
50         $result = mysql_query($sql, $db);
51         if (!($row = mysql_fetch_assoc($result))) {
52                 $msg->addError('FORUM_NOT_FOUND');
53                 header('Location: list.php');
54                 exit;
55         } // else:
56
57         /* Decrement count for number of posts and topics*/
58         $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=$_REQUEST[fid]";
59         $result = mysql_query($sql, $db);
60
61         $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=$_REQUEST[new_fid]";
62         $result = mysql_query($sql, $db);
63
64         $sql    = "UPDATE ".TABLE_PREFIX."forums_threads SET forum_id=$_REQUEST[new_fid], last_comment=last_comment, date=date WHERE (parent_id=$_REQUEST[pid] OR post_id=$_REQUEST[pid]) AND forum_id=$_REQUEST[fid]";
65         $result = mysql_query($sql, $db);
66
67         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
68         header('Location: index.php?fid='.$_REQUEST['fid']);
69         exit;
70 }
71
72 $_pages['mods/_standard/forums/forum/index.php?fid='.$_REQUEST['fid']]['title']    = get_forum_name($_REQUEST['fid']);
73 $_pages['mods/_standard/forums/forum/index.php?fid='.$_REQUEST['fid']]['parent']   = 'mods/_standard/forums/forum/list.php';
74 $_pages['mods/_standard/forums/forum/index.php?fid='.$_REQUEST['fid']]['children'] = array('mods/_standard/forums/forum/move_thread.php');
75
76 $_pages['mods/_standard/forums/forum/move_thread.php']['title_var'] = 'move_thread';
77 $_pages['mods/_standard/forums/forum/move_thread.php']['parent']    = 'mods/_standard/forums/forum/index.php?fid='.$_REQUEST['fid'];
78 $_pages['mods/_standard/forums/forum/move_thread.php']['children']  = array();
79
80 require(AT_INCLUDE_PATH.'header.inc.php');
81 ?>
82 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
83 <input type="hidden" name="fid" value="<?php echo $_REQUEST['fid']; ?>" />
84 <input type="hidden" name="pid" value="<?php echo $_REQUEST['pid']; ?>" />
85 <input type="hidden" name="ppid" value="<?php echo $_REQUEST['ppid']; ?>" />
86
87 <div class="input-form">
88         <div class="row">
89                 <?php echo _AT('move_thread_to');
90                 $all_forums = get_forums($_SESSION['course_id']);
91                 ?>
92                 <ul style="list-style: none">
93                 <?php foreach($all_forums['nonshared'] as $row): ?>
94                         <li>
95                                 <input type="radio" name="new_fid" value="<?php echo $row['forum_id']; ?>" id="f<?php echo $row['forum_id']; ?>" <?php if ($row['forum_id'] == $_REQUEST['fid']) { echo 'checked="checked"'; } ?> /><label for="f<?php echo $row['forum_id']; ?>"><?php echo AT_print($row['title'], 'forums.title'); ?></label>
96                         </li>
97                 <?php endforeach; ?>
98                 </ul>
99         </div>
100
101         <div class="row buttons">
102                 <input type="submit" name="submit" value="<?php echo _AT('move'); ?>" />
103                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
104         </div>
105 </div>
106 </form>
107
108 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>