<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
if( defined("PHPBB_INSTALLED") )
{
    message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic');
}

require_once("mainfile.php");

function Configure() {
    global $admin;
    include ("config.php");
    include ("header.php");
    OpenTable();
    echo "<center><font class=\"title\"><b>Forum Startup</b></font></center>";
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<center><font class=\"option\"><b>Forum Config</b></font></center>"
	."<form action=\"modules.php?name=Forums&file=install\" method=\"post\">"
	."<table border=\"0\"><tr><td>"
	."<b>Site URL:</b></td><td><input type=\"text\" name=\"xnukeurl\" value=\"$nukeurl\" size=\"40\" maxlength=\"100\">"
	."</td></tr><tr><td>"
	."<b>Forum Admin: </b></td><td> <SELECT NAME=\"xadmin_user\">";
        $result = sql_query("select uid, uname from $user_prefix"._users." order by uname", $dbi);
	while(list($uid, $uname) = mysql_fetch_row($result)) {
	    echo "<OPTION VALUE=\"$uid\">$uname</OPTION>";
	}
	echo "</select>\n"
	."</td></tr></table><br><br>"
	."<input type=\"hidden\" name=\"op\" value=\"ForumSave\">"
	."<center><input type=\"submit\" value=\"Save Changes\"></center>"
	."</form>";
    CloseTable();
    include ("footer.php");
}

function ForumSave($xnukeurl, $xadmin_user) {
    global $xnukeurl, $xadmin_user, $user_prefix, $dbi;
    $query="update ".$user_prefix."_users set user_level='2' where uid='$xadmin_user'";
    if(!sql_query($query, $dbi)) {
        echo "Error Updating Admin user level<br>";
    }
    $xnukeurl = ereg_replace("http://", "", "$xnukeurl");
        echo "Please set the Sitename in the forum admin/Configuration<br>";
    $query="update ".$user_prefix."_config set config_value='$xnukeurl' where config_name='cookie_domain'";
    if(!sql_query($query, $dbi)) {
        echo "Error Updating Cookie Domain<br>";
    }
    $query="update ".$user_prefix."_config set config_value='$xnukeurl' where config_name='server_name'";
    if(!sql_query($query, $dbi)) {
        echo "Error Updating Servername<br>";
    }
    $xnukeurl = ereg_replace("www", "", "$xnukeurl");
    $query="update ".$user_prefix."_config set config_value='Thanks, Webmaster@$xnukeurl' where config_name='board_email_sig'";
    if(!sql_query($query, $dbi)) {
        echo "Error Updating Webmaster Signature<br>";
    }
    $query="update ".$user_prefix."_config set config_value='webmaster@$xnukeurl' where config_name='board_email'";
    if(!sql_query($query, $dbi)) {
        echo "Error Updating webmaster Email<br>";
    }
    $file = fopen("modules/Forums/config.php", "w");
    $content = "<?php\n\n";
    $content .= "\n";
    $content .= "\n";
    $content .= "@include(\"../../config.php\");\n";
    $content .= "\n";
    $content .= "define('PHPBB_INSTALLED', true);\n";
    $content .= "\n";
    $content .= "?>";
    fwrite($file, $content);
    fclose($file);	    
    $file="modules/Forums/install.php";
    if (file_exists($file)) {
        unlink("$file");
	echo "Install complete";
    } else {
	echo "Install complete, but could not delete install.php."
	    ."Please delete this file manually.";
    }    
    echo "<META HTTP-EQUIV=\"refresh\" content=\"3;URL=modules.php?name=Forums&file=index\">";
}

switch($op) {

    case "ForumSave":
    ForumSave($xnukeurl, $xadmin_user);
    break;

    default:
    Configure();
    break;

}
?>
