<?php

/* 
 *	W-AGORA 4.0
 *	-----------
 *	$Id: upgrade_site_403.php,v 1.5 2004/10/05 17:11:47 mdruilhe Exp $
 *	Usage:		Upgrade a site to v4.0.3 (must be called from upgrade.php)
 *	Author:		Marc Druilhe <mdruilhe@w-agora.com>
 */

	if (!defined('_GLOBALS')) {
		die('Hacking attempt');
	}

# Site configuration
# ------------------

	if (!is_file ("$cfg_dir/site_${site}.$ext") ) {
		print "Cannot open file: $cfg_dir/site_${site}.$ext, make sure that site $site really exists";
		exit;
	}

	include "$cfg_dir/site_${site}.$ext";

	print "<ul>";

# Update tables in database
# --------------------------
	include "$inc_dir/$bn_access.$ext";
	$db_class = "${bn_access}_access";
	$db = new $db_class;
	$db->openDB($dbhost, $dbport, $dbuser, $dbpassword, $dbname, $site);

	updateSite($site);

# Update default configuration files for this site
# ------------------------------------------------
	// change password template
	echo "<li> copy $tmpl_dir/default/agora/change_password_form.$ext $bn_dir_default/change_password_form.$ext <br>";
	@copy ("$tmpl_dir/default/agora/change_password_form.$ext", "$bn_dir_default/change_password_form.$ext");

	// forgot password template
	echo "<li> copy $tmpl_dir/default/agora/forgot_password_form.$ext $bn_dir_default/forgot_password_form.$ext <br>";
	@copy ("$tmpl_dir/default/agora/forgot_password_form.$ext", "$bn_dir_default/forgot_password_form.$ext");

	// Show Profile template
	echo "<li> copy $tmpl_dir/default/agora/show_profile.$ext $bn_dir_default/show_profile.$ext <br>";
	@copy ("$tmpl_dir/default/agora/show_profile.$ext", "$bn_dir_default/show_profile.$ext");

	// update messages
	updateMsgFile ("$bn_dir_default/msgs.$ext");

	// gets all configured forums
	if (is_array($forums) ) {
		unset($forums);
	}
	$forums = Array();
	$db->query ("select bn_db, bn_name from $site where category!=1");
	while ($db->next_record() ) {
		$bn_db = $db->f("bn_db");
		$forums[$bn_db] = $db->f("bn_name");
	}

	reset ($forums);
	while (list ($table, $name) = each($forums) ) {

		include "$cfg_dir/${name}.$ext";

		print "<li><I>updating forum</I>: <B>$name</B> <br>";
		print "<ul>";

		// update messages
		if (!empty($bn_msgs) && file_exists ("$bn_dir/$bn_msgs")  ) {
			updateMsgFile ("$bn_dir/$bn_msgs");
		}

		print "<li><I>updating stats for table</I>: <B>$table</B> <br>";
		updateUserForumStats($site, $table);
		print "</ul>";
	}

	updateSiteStats($site);

	$db->closeDB();
	unset ($db);

	print "</ul>";

?>