source: temp/test-xoops.ec-cube.net/html/modules/newbb/topicmanager.php @ 405

Revision 405, 8.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2/***************************************************************************
3                            topicmanager.php  -  description
4                             -------------------
5    begin                : Sat June 17 2000
6    copyright            : (C) 2001 The phpBB Group
7    email                : [email protected]
8
9    $Id: topicmanager.php,v 1.3 2005/09/04 20:46:10 onokazu Exp $
10
11 ***************************************************************************/
12
13/***************************************************************************
14 *
15 *   This program is free software; you can redistribute it and/or modify
16 *   it under the terms of the GNU General Public License as published by
17 *   the Free Software Foundation; either version 2 of the License, or
18 *   (at your option) any later version.
19 *
20 ***************************************************************************/
21include "header.php";
22if ( $_POST['submit'] ) {
23    foreach (array('forum', 'topic_id', 'newforum') as $getint) {
24        ${$getint} = isset($_POST[$getint]) ? intval($_POST[$getint]) : 0;
25    }
26} else {
27    foreach (array('forum', 'topic_id') as $getint) {
28        ${$getint} = isset($_GET[$getint]) ? intval($_GET[$getint]) : 0;
29    }
30}
31$accesserror = 0;
32if ( $xoopsUser ) {
33    if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
34        if ( !is_moderator($forum, $xoopsUser->uid()) ) {
35            $accesserror = 1;
36        }
37    }
38} else {
39    $accesserror = 1;
40}
41if ( $accesserror == 1 ) {
42    redirect_header("viewtopic.php?topic_id=$topic_id&amp;post_id=$post_id&amp;order=$order&amp;viewmode=$viewmode&amp;pid=$pid&amp;forum=$forum",3,_MD_YANTMOTFTYCPTF);
43    exit();
44}
45
46include XOOPS_ROOT_PATH.'/header.php';
47OpenTable();
48if ( $_POST['submit'] ) {
49    switch ($_POST['mode']) {
50    case 'del':
51        // Update the users's post count, this might be slow on big topics but it makes other parts of the
52        // forum faster so we win out in the long run.
53        $sql = "SELECT uid, post_id FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $topic_id";
54        if ( !$r = $xoopsDB->query($sql) ) {
55            exit(_MD_COULDNOTQUERY);
56        }
57        while ( $row = $xoopsDB->fetchArray($r) ) {
58            if ( $row['uid'] != 0 ) {
59                $sql = sprintf("UPDATE %s SET posts = posts - 1 WHERE uid = %u", $xoopsDB->prefix("users"), $row['uid']);
60                $xoopsDB->query($sql);
61            }
62        }
63
64        // Get the post ID's we have to remove.
65        $sql = "SELECT post_id FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $topic_id";
66        if ( !$r = $xoopsDB->query($sql) ) {
67            exit(_MD_COULDNOTQUERY);
68        }
69        while ( $row = $xoopsDB->fetchArray($r) ) {
70            $posts_to_remove[] = $row['post_id'];
71        }
72       
73        $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $xoopsDB->prefix("bb_posts"), $topic_id);
74        if ( !$result = $xoopsDB->query($sql) ) {
75            exit(_MD_COULDNOTREMOVE);
76        }
77        $sql= sprintf("DELETE FROM %s WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $topic_id);
78        if ( !$result = $xoopsDB->query($sql) ) {
79            exit(_MD_COULDNOTQUERY);
80        }
81
82        $sql = "DELETE FROM ".$xoopsDB->prefix("bb_posts_text")." WHERE ";
83        for ( $x = 0; $x < count($posts_to_remove); $x++ ) {
84            if ( $set ) {
85                $sql .= " OR ";
86            }
87            $sql .= "post_id = ".$posts_to_remove[$x];
88            $set = true;
89        }
90
91        if ( !$xoopsDB->query($sql) ) {
92            exit(_MD_COULDNOTREMOVETXT);
93        }
94        sync($forum, 'forum');
95        // RMV-NOTIFY
96        xoops_notification_deletebyitem ($xoopsModule->getVar('mid'), 'thread', $topic_id);
97        echo _MD_TTHBRFTD."<p><a href='viewforum.php?forum=$forum'>"._MD_RETURNTOTHEFORUM."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
98        break;
99    case 'move':
100        if ($newforum > 0) {
101            $sql = sprintf("UPDATE %s SET forum_id = %u WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $newforum, $topic_id);
102            if ( !$r = $xoopsDB->query($sql) ) {
103                exit(_MD_EPGBATA);
104            }
105            $sql = sprintf("UPDATE %s SET forum_id = %u WHERE topic_id = %u", $xoopsDB->prefix("bb_posts"), $newforum, $topic_id);
106            if ( !$r = $xoopsDB->query($sql) ) {
107                exit(_MD_EPGBATA);
108            }
109            sync($newforum, 'forum');
110            sync($forum, 'forum');
111        }
112        echo _MD_TTHBM."<p><a href='viewtopic.php?topic_id=$topic_id&amp;forum=$newforum'>"._MD_VTUT."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
113        break;
114    case 'lock':
115        $sql = sprintf("UPDATE %s SET topic_status = 1 WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $topic_id);
116        if ( !$r = $xoopsDB->query($sql) ) {
117            exit(_MD_EPGBATA);
118        }
119        echo _MD_TTHBL."<p><a href='viewtopic.php?topic_id=$topic_id&amp;forum=$forum'>"._MD_VIEWTHETOPIC."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
120        break;
121    case 'unlock':
122        $sql = sprintf("UPDATE %s SET topic_status = 0 WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $topic_id);
123        if ( !$r = $xoopsDB->query($sql) ) {
124            exit("Error - Could not unlock the selected topic. Please go back and try again.");
125        }
126        echo _MD_TTHBU."<p><a href='viewtopic.php?topic_id=$topic_id&amp;forum=$forum'>"._MD_VIEWTHETOPIC."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
127        break;
128    case 'sticky':
129        $sql = sprintf("UPDATE %s SET topic_sticky = 1 WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $topic_id);
130        if ( !$r = $xoopsDB->query($sql) ) {
131            exit("Error - Could not sticky the selected topic. Please go back and try again.");
132        }
133        echo _MD_TTHBS."<p><a href='viewtopic.php?topic_id=$topic_id&amp;forum=$forum'>"._MD_VIEWTHETOPIC."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
134        break;
135    case 'unsticky':
136        $sql = sprintf("UPDATE %s SET topic_sticky = 0 WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $topic_id);
137        if ( !$r = $xoopsDB->query($sql) ) {
138            exit("Error - Could not unsticky the selected topic. Please go back and try again.");
139        }
140        echo _MD_TTHBUS."<p><a href='viewtopic.php?topic_id=$topic_id&amp;forum=$forum'>"._MD_VIEWTHETOPIC."</a></p><p><a href='index.php'>"._MD_RTTFI."</a></p>";
141        break;
142    }
143} else {  // No submit
144    $mode = $_GET['mode'];
145    echo "<form action='".xoops_getenv('PHP_SELF')."' method='post'>
146    <table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'><tr><td class='bg2'>
147    <table border='0' cellpadding='1' cellspacing='1' width='100%'>
148    <tr class='bg3' align='left'>";
149    switch ( $mode ) {
150    case 'del':
151        echo '<td colspan="2">'. _MD_OYPTDBATBOTFTTY .'</td>';
152        break;
153    case 'move':
154        echo '<td colspan="2">'._MD_OYPTMBATBOTFTTY.'</td>';
155        break;
156    case 'lock':
157        echo '<td colspan="2">'._MD_OYPTLBATBOTFTTY.'</td>';
158        break;
159    case 'unlock':
160        echo '<td colspan="2">'._MD_OYPTUBATBOTFTTY.'</td>';
161        break;
162    case 'sticky':
163        echo '<td colspan="2">'._MD_OYPTSBATBOTFTTY.'</td>';
164        break;
165    case 'unsticky':
166        echo '<td colspan="2">'._MD_OYPTTBATBOTFTTY.'</td>';
167        break;
168    }
169    echo '</tr>';
170
171    if ( $mode == 'move' ) {
172        echo '<tr>
173        <td class="bg3">'._MD_MOVETOPICTO.'</td>
174        <td class="bg1"><select name="newforum" size="0">';
175        $sql = "SELECT forum_id, forum_name FROM ".$xoopsDB->prefix("bb_forums")." WHERE forum_id != $forum ORDER BY forum_id";
176        if ( $result = $xoopsDB->query($sql) ) {
177            if ( $myrow = $xoopsDB->fetchArray($result) ) {
178                do {
179                    echo "<option value='".$myrow['forum_id']."'>".$myrow['forum_name']."</option>\n";
180                } while ( $myrow = $xoopsDB->fetchArray($result) );
181            } else {
182                echo "<option value='-1'>"._MD_NOFORUMINDB."</option>\n";
183            }
184        } else {
185            echo "<option value='-1'>"._MD_DATABASEERROR."</option>\n";
186        }
187        echo '</select></td></tr>';
188    }
189    echo '<tr class="bg3">
190    <td colspan="2" align="center">';
191
192    switch ( $mode ) {
193    case 'del':
194        echo '<input type="hidden" name="mode" value="del" />
195        <input type="hidden" name="topic_id" value="'.$topic_id.'" />
196        <input type="hidden" name="forum" value="'.$forum.'" />
197        <input type="submit" name="submit" value="'._MD_DELTOPIC.'" />';
198        break;
199    case 'move':
200        echo '<input type="hidden" name="mode" value="move" />
201        <input type="hidden" name="topic_id" value="'.$topic_id.'" />
202        <input type="hidden" name="forum" value="'.$forum.'" />
203        <input type="submit" name="submit" value="'._MD_MOVETOPIC.'" />';
204        break;
205    case 'lock':
206        echo '<input type="hidden" name="mode" value="lock" />
207        <input type="hidden" name="topic_id" value="'.$topic_id.'" />
208        <input type="hidden" name="forum" value="'.$forum.'" />
209        <input type="submit" name="submit" value="'._MD_LOCKTOPIC.'" />';
210        break;
211    case 'unlock':
212        echo '<input type="hidden" name="mode" value="unlock" />
213        <input type="hidden" name="topic_id" value="'.$topic_id.'" />
214        <input type="hidden" name="forum" value="'.$forum.'" />
215        <input type="submit" name="submit" value="'._MD_UNLOCKTOPIC.'" />';
216        break;
217    case 'sticky':
218        echo "<input type='hidden' name='mode' value='sticky' />
219        <input type='hidden' name='topic_id' value='$topic_id' />
220        <input type='hidden' name='forum' value='$forum' />
221        <input type='submit' name='submit' value='"._MD_STICKYTOPIC."' />";
222        break;
223    case 'unsticky':
224        echo "<input type='hidden' name='mode' value='unsticky' />
225        <input type='hidden' name='topic_id' value='$topic_id' />
226        <input type='hidden' name='forum' value='$forum' />
227        <input type='submit' name='submit' value='". _MD_UNSTICKYTOPIC."' />";
228        break;
229    }
230    echo '</td></tr>
231    </form>
232    </table></td></tr></table>';
233}
234CloseTable();
235include XOOPS_ROOT_PATH.'/footer.php';
236?>
Note: See TracBrowser for help on using the repository browser.