Location: PHPKode > projects > WB News > install/upgrades/upgrade_2.0.0b-1.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2008                          #||
||#     Created: 27th Feb 2008                           #||
||#     Filename: upgrade_2.0.0b-1.php                   #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *  @version $Id: upgrade_2.0.0b-1.php,v 1.1.2.4 2008/06/21 07:23:48 pmcilwaine Exp $
 */

if ( $_SERVER["SCRIPT_FILENAME"] == __FILE__ )
{
	echo "You cannot upgrade this way. Please <a href=\"../upgrade.php\">upgrade using this</a>.";
	exit;
}

require_once( "../global.php" );

if ( !isset($_SESSION["page"]) )
{
	$_SESSION["page"] = "config_update";

	$_SESSION["status"] = array(
		"config_update" => FALSE
		);
}

$myform = "upgrade";

$navigation = array(
	"config_update" => "Configuration Update",
	"complete" => "Complete"
	);

if ( $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["form"]) && $_POST["form"] == $myform )
{

	switch ( Submit() )
	{
	case "Next":
	case "Finish":

		$err_msg = array();

		switch ( $_SESSION["page"] )
		{
		case "config_update":

			/** update data **/
			$cond = array();
			$cond[] = "\"group_bit\" & " . $permissions["canconfig"];
			$cond = join( " AND ", $cond );
			$records = $DB->ListBy( TBL_UGROUPS, $cond, array( "usergroupid", "group_bit" ) );

			foreach ( $records as $record )
			{
				$group_bit = $record["group_bit"] + $permissions["master"];
				$usergroupid = $record["usergroupid"];
				$DB->query( "UPDATE " . TBL_UGROUPS . " SET \"group_bit\"='$group_bit' WHERE \"usergroupid\"='$usergroupid'" );
			}

			$sqls = array();
			$sqls[] = "UPDATE " . TBL_MENU . " SET label = 'Add &Category', icon = 'img/page_add.png', auth = 'addcategory' WHERE url = 'edit-category.php';";
			$sqls[] = "DELETE FROM " . TBL_MENU . " WHERE url = 'category-permission.php';";

			$new_id = $DB->NewID( SEQ_PREFIX . "seq_menu" );
			$sqls[] = "INSERT INTO " . TBL_MENU . " (id, created_ts, parent, auth, label, url, icon) VALUES ( '$new_id', NOW(), 20, 'canconfig', 'Add &Emoticon','edit-emoticon.php', 'img/page_add.png');";

			$sqls[] = "UPDATE " . TBL_MENU . " SET icon = 'img/page_add.png', label = 'Add &News Item' WHERE url = 'edit-news.php';";
			$sqls[] = "UPDATE " . TBL_MENU . " SET url = 'news-comments.php', label = '&Comments' WHERE url = 'comments.php';";
			$sqls[] = "UPDATE " . TBL_MENU . " SET url = 'news-sendmsg.php', label = '&Send to Friend' WHERE url = 'sendfriend.php';";

			$sqls[] = "UPDATE " . TBL_MENU . " SET label = 'Add &Theme', icon = 'img/page_add.png' WHERE url = 'edit-theme.php';";

			$sqls[] = "UPDATE " . TBL_MENU . " SET label = 'Add &User', icon = 'img/page_add.png' WHERE url = 'edit-user.php';";
			$sqls[] = "DELETE FROM " . TBL_MENU . " WHERE label IN ('Database Backup','File Backup')";

			$new_id = $DB->NewID( SEQ_PREFIX . "seq_themes" );
			$sqls[] = "INSERT INTO " . TBL_THEMES . " VALUES ($new_id, 'Beta Theme', 'beta')";
			
			foreach ( $sqls as $sql )
			{
				$DB->query( $sql );
			}

			/**
			*  Upgrade config.php to newest version
			*/
			$configUpdate = file("../config.php");
			$configUpdate[24] = "\$config[\"version\"] = '" . $version . "';           //version\n";
			$configUpdate = implode("", $configUpdate);

			$fp = fopen("../config.php", "w");
			$bytes = fwrite($fp, $configUpdate);
			fclose($fp);

			break;
		}
		
		if ( count($err_msg) > 0 )
		{
			$_SESSION["formdata"] = $_POST;
			$_SESSION["err_msg"] = $err_msg;
			redirect( make_url() );
			exit;
		}

		switch ( $_SESSION["page"] )
		{
		case "config_update":
			$_SESSION["status"]["config_update"] = TRUE;
			$_SESSION["page"] = "complete";
			redirect( make_url() );
			break;
		}
		exit;
	case "Back":
		switch ( $_SESSION["page"] )
		{
		case "config_update":
			redirect( make_url() );
			break;
		}
		exit;
	}

}

$tmpl->SetOutput( TRUE );
$tmpl->AddParam( "action", make_url_html() );
$tmpl->AddParam( "navigation", $navigation );
$tmpl->AddParam( "page", $_SESSION["page"] );
$formdata =& $tmpl->AddParam( "formdata", array() );

$formdata["hidden"] = array(
	"form" => $myform
	);

switch ( $_SESSION["page"] )
{
case "config_update":
	$tmpl->SetFilename( "templates/config-update-nonform.ihtml" );
	$tmpl->AddParam( "buttons", "Next" );
	break;
case "complete":
	$tmpl->SetFilename( "templates/complete.ihtml" );
	$tmpl->AddParam( "admin_url", htmlspecialchars( "../admin/" ) );
	
	break;
}

if ( isset($_SESSION["err_msg"]) )
{
	if ( isset($_SESSION["err_msg"]) )
	{
		$tmpl->AddParam( "msg", $_SESSION["err_msg"] );
	}

	if ( isset($_SESSION["formdata"]) )
	{
		foreach ( $_SESSION["formdata"] as $var => $val )
		{
			$formdata[$var] = htmlspecialchars( $val );
		}
	}

	unset( $_SESSION["err_msg"], $_SESSION["formdata"] );
}

$tmpl->GetHTML();

?>
Return current item: WB News