<?php

/* 
 *	W-AGORA 4.0
 *	-----------
 *	$Id: upgrade_site_402.php,v 1.3 2004/10/05 17:11:47 mdruilhe Exp $
 *	Usage:		Upgrade a site to v4.0.2 (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 messages
	echo "<li> copy $tmpl_dir/admin/site_msgs.$ext $bn_dir/$bn_msgs <br>";
	copy ("$tmpl_dir/admin/site_msgs.$ext", "$bn_dir/$bn_msgs");


# 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
# ------------------------------------------------
	// default configuration file for new forums
	echo "<li> copy $tmpl_dir/default/agora/conf.$ext $bn_dir_default/conf.$ext <br>";
	copy ("$tmpl_dir/default/agora/conf.$ext", "$bn_dir_default/conf.$ext");

	// Add mail template
	echo "<li> copy $tmpl_dir/default/agora/mail_template.$ext $bn_dir_default/mail_template.$ext <br>";
	copy ("$tmpl_dir/default/agora/mail_template.$ext", "$bn_dir_default/mail_template.$ext");

	// update messages
	if (file_exists ("$bn_dir_default/msgs.$ext")  ) {
		updateMsgFile ("$bn_dir_default/msgs.$ext");
	} else {
		echo "<li> copy $tmpl_dir/default/agora/msgs.$ext $bn_dir_default/msgs.$ext <br>";
		copy ("$tmpl_dir/default/agora/msgs.$ext", "$bn_dir_default/msgs.$ext");
	}

	// update template
	if (file_exists ("$bn_dir_default/template.$ext") ) {
		updateTemplate ("$bn_dir_default/template.$ext");
	} else {
		echo "<li> copy $tmpl_dir/default/agora/template.$ext $bn_dir_default/template.$ext <br>";
		copy ("$tmpl_dir/default/agora/template.$ext", "$bn_dir_default/template.$ext");
	}

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

	reset ($forums);
	while (list ($name, $table) = each($forums) ) {
		print "<li><I>updating forum</I>: <B>$name</B> <br>";
		print "<ul>";

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

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

		// update template
		if (!empty($bn_template) && file_exists ("$bn_dir/$bn_template") ) {
			updateTemplate ("$bn_dir/$bn_template");
		}

		// update Notes directory
		if (!empty($bn_dir_notes)  ) {
			updateNotes ("$bn_dir_notes");
		}
		print "</ul>";
	}

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

	print "</ul>";

?>