Title: Merge Forums Tool v2.0

Author: John Briggs

Updated by: Robert Chapin (miqrogroove)

Description:
This modification will provide a tool to move threads from one forum to another forum in the admininistration panel.

Copyright:  2006 John Briggs. All rights reserved.

Compatability: XMB 1.9.11 Only

Install Note: Before adding this modification to your forum you should back up all files related to this mod.

License Note: This modification is released under the GPL License. A copy is provided with this software.

Author Note:
Please visit http://www.xmbgarage.com/ for support.

=======================================================================================================================================
=======
Step 1:
=======

=====================================
Edit File: include/admin.inc.php
=====================================

==========
Find Code:
==========

    &raquo;&nbsp;<a href="tools.php?action=whosonlinedump"><?php echo $lang['cpwodump']?></a><br />
    </td>
    <td class="tablerow" align="left" valign="top" width="20%" bgcolor="<?php echo $THEME['altbg2']?>">

===============
Add Code Below:
===============

    &raquo;&nbsp;<a href="tools.php?action=mergeforums"><?php echo $lang['mergeforumstxt']?></a><br />

=======================================================================================================================================
=======
Step 2:
=======

=====================================
Edit File: header.php
=====================================

=========
Find Code :
=========

/* Set Up HTML Templates and Themes */

==============
Add Code Above:
==============

// Assert Merge Forum Tool Translation
if (!isset($lang['tool_mergeforums'])) {
    require_once(ROOT.'include/translation.inc.php');
    $phrases = array();
    $phrases['mergeforumstxt'] = "Merge Forums";
    $phrases['mergeforums_note'] = "Note: Here you can merge threads from one forum to another by applying the old fid to merge threads to the new fid.";
    $phrases['mergeforums_newfid'] = "Move Them Into This Forum:";
    $phrases['mergeforums_oldfid'] = "Move All Threads Out of This Forum:";
    $phrases['mergeforum_newfid_none'] = "You did not select a destination forum.";
    $phrases['mergeforum_oldfid_none'] = "You did not select an old forum to move threads out of.";
    $phrases['tool_mergeforums'] = "Forums merged successfully.";
    setManyLangValues($phrases, $langfile);
    loadLang($langfile);
}

=======================================================================================================================================
=======
Step 3:
=======

====================
Edit File: tools.php
====================

==========
Find Code:
==========

    case 'checktables':

===============
Add Code Above:
===============

    case 'mergeforums':
        if (noSubmit('mergesubmit')) {
            $fromselect = forumList('fromfid', FALSE, FALSE);
            $toselect   = forumList('tofid',   FALSE, FALSE);
            ?>
            <form method="POST" action="tools.php?action=mergeforums">
            <tr class="category">
            <td colspan="2"><strong><font color="<?php echo $cattext?>"><?php echo $lang['mergeforumstxt']?></font></strong></td>
            </td>
            <tr class="tablerow">
            <td bgcolor="<?php echo $altbg2?>" colspan="2"><?php echo $lang['mergeforums_note']?></td>
            </tr>
            <tr class="tablerow">
            <td bgcolor="<?php echo $altbg1?>" width="22%"><?php echo $lang['mergeforums_oldfid']?></td>
            <td bgcolor="<?php echo $altbg2?>"><?php echo $fromselect; ?></td>
            </tr>
            <tr class="tablerow">
            <td bgcolor="<?php echo $altbg1?>" width="22%"><?php echo $lang['mergeforums_newfid']?></td>
            <td bgcolor="<?php echo $altbg2?>"><?php echo $toselect; ?></td>
            </tr>
            <tr class="ctrtablerow" bgcolor="<?php echo $altbg2?>">
            <td colspan="2"><input class="submit" type="submit" name="mergesubmit" value="<?php echo $lang['textsubmitchanges']?>" />
            </form>
            <?php
        }

        if (onSubmit('mergesubmit')) {
            $new_fid = formInt('tofid');
            $old_fid = formInt('fromfid');

            $newForum = getForum($new_fid);
            $oldForum = getForum($old_fid);

            if ($newForum === FALSE Or $new_fid == $old_fid) {
                error($lang['mergeforum_newfid_none'], false, '</table></table><br />');
            }

            if ($oldForum === FALSE) {
                error($lang['mergeforum_oldfid_none'], false, '</table></table><br />');
            }

            $newfidvar = "fid=$new_fid";
            $oldfidvar = "fid=$old_fid";
            $db->query("UPDATE ".X_PREFIX."threads SET $newfidvar WHERE $oldfidvar");
            $db->query("UPDATE ".X_PREFIX."posts SET $newfidvar WHERE $oldfidvar");

            //Update all summary columns.
            if ($oldForum['type'] == 'sub') {
                updateforumcount($oldForum['fup']);
            }
            if ($newForum['type'] == 'sub') {
                $doupdate = TRUE;
                if ($oldForum['type'] == 'sub') {
                    $doupdate = ($newForum['fup'] != $oldForum['fup']);
                }
                if ($doupdate) {
                    updateforumcount($newForum['fup']);
                }
            }
            updateforumcount($new_fid);
            updateforumcount($old_fid);

            nav($lang['tools']);
            echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['tool_completed'].' - '.$lang['tool_mergeforums'].'</td></tr></table></table>';
        }
        break;

=======================================================================================================================================
