<?php

include ("../inc/inc_connect.php");

print "<html><head><title>Upgrager</title></head><body><font face=\"arial\" size=2>";

if ($action == "forum")
{
    $query = "DELETE FROM $grouptable";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    print "Sub-Forum information deleted!<br><br>";
}

if ($action == "posts")
{
    $query = "DELETE FROM $forumtable";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    print "Post information deleted!<br><br>";
}

if ($action != "go")
{
    print "<font face=\"arial\" size=4>
    <font color=\"red\"><b><br><br>IMPORTANT: THIS UPGRADER WILL DELETE ANY POSTS OR SUB-FORUMS ALREADY SETUP</b><font face=\"arial\" size=2><br><br>
    <font color=\"black\">
    <br>For this upgrade to work, GrimForum 5 must be fully installed, and <b>in the same database at GrimForum 4.1</b>.<br>
    It will update your forum lists with no options (like allow voting) set.<br>
    It will update forum posts.<br><br>

    <b><a href=\"upgrade_forums.php?action=go\">Click here to start</a></b><br><br><br><font size=1>
    Please note that this upgrader is untested. If it all goes wrong, click <a href=\"upgrade_forums.php?action=posts\">here</a> to delete all the posts, and <a href=\"upgrade_forums.php?action=forum\">here</a> to delete all the sub-forum information.</body></html>";

    exit;
}

//cross your fingers...

//wipe forum lists

$query = "DELETE FROM $grouptable";
mysql_query( $query, $link ) or die ( "1Error! : ".mysql_error() );

//upgrade forum lists

$result=mysql_query("SELECT * FROM tblforumgroups");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $query = "INSERT INTO $grouptable ( intId, intGroupId, intGroupOrder, strName, strDateCreated, ynGroupMaster, strGrimforumName, strComments, strPassword) values( '$a_row->intId', '$a_row->intGroupId', '$a_row->intGroupOrder', '$a_row->strName', '$a_row->strDateCreated', '$a_row->ynGroupMaster', '$a_row->strGrimforumName', '$a_row->strComments', '$a_row->strPassword')";
    mysql_query( $query, $link ) or die ( "2Error! : ".mysql_error() );
}

//wipe posts

$query = "DELETE FROM $forumtable";
mysql_query( $query, $link ) or die ( "3Error! : ".mysql_error() );

$result=mysql_query("SELECT * FROM tblforum");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $fff = addslashes($a_row->strTopicName);
    $ff = addslashes($a_row->mempost);

    // Thanks to GF5 community member 'Juulke' for adding the 'f' rows above!

    $query = "INSERT INTO $forumtable ( intId, strName, strTopicName, memPost, strForumComment, ynTopicRow, strDate, intTopicId, intPostId, strTime, strAvatar, memSig, strEmail, intPosts, strHomepage, strIp, ynShowEmail, strIcqNumber, strMsnName, strYahooId, strLocation, intLastPost, intReplies, intViews, strSmilieUrl, strLastPostName, strLastPostTime, strLastPostDate, strEpochTime, ynLocked, strLockedBy, ynPriority, intForumId, intForumGroup) values( '$a_row->intId', '$a_row->strName', '$fff', '$ff', '$a_row->strForumComment', '$a_row->ynTopicRow', '$a_row->strDate', '$a_row->intTopicId', '$a_row->intPostId', '$a_row->strTime', '$a_row->strAvatar', '$a_row->memSig', '$a_row->strEmail', '$a_row->intPosts', '$a_row->strHomepage', '$a_row->strIp', '$a_row->ynShowEmail', '$a_row->strIcqNumber', '$a_row->strMsnName', '$a_row->strYahooId', '$a_row->strLocation', '$a_row->intLastPost', '$a_row->intReplies', '$a_row->intViews', '$a_row->strSmilieUrl', '$a_row->strLastPostName', '$a_row->strLastPostTime', '$a_row->strLastPostDate', '$a_row->strEpochTime', '$a_row->ynLocked', '$a_row->strLockedBy', '$a_row->ynPriority', '$a_row->intForumId', '$a_row->intForumGroup')";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}


print "<b><br><br>UPGRADE COMPLETE!</body></html>";

?>


