<?php

######################################################
# File to upgrade from PHP-Nuke 6.5 to PHP-Nuke 6.6
# After you used this file, you can safely delete it.
######################################################
#            -= WARNING: PLEASE READ =-
#
# NOTE: This file uses config.php to retrieve needed
# variables values. So, to do the upgrade PLEASE copy
# this file in your server root directory and execute
# it from your browser.
######################################################

include("mainfile.php");

// Stories Table Alteration
$db->sql_query("ALTER TABLE ".$prefix."_stories ADD associated TEXT NOT NULL");
$db->sql_query("ALTER TABLE ".$prefix."_autonews ADD associated TEXT NOT NULL");



// Users Groups Table Creation
$db->sql_query("CREATE TABLE ".$prefix."_groups (id INT( 10 ) DEFAULT '0' AUTO_INCREMENT, name VARCHAR( 255 ) NOT NULL , description TEXT NOT NULL , points INT( 10 ) DEFAULT '0' NOT NULL , INDEX ( id ))");

// Users Groups Points System Table Creation
$db->sql_query("CREATE TABLE ".$prefix."_groups_points (id INT( 10 ) DEFAULT '0'AUTO_INCREMENT, points INT( 10 ) DEFAULT '0' NOT NULL , INDEX ( id ))");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('1', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('2', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('3', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('4', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('5', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('6', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('7', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('8', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('9', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('10', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('11', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('12', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('13', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('14', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('15', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('16', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('17', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('18', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('19', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('20', '0')");
$db->sql_query("INSERT INTO ".$prefix."_groups_points VALUES ('21', '0')");

// Modules Table Alteration
$db->sql_query("ALTER TABLE ".$prefix."_modules ADD mod_group INT(10) DEFAULT '0'");

// Users Table Alteration
$db->sql_query("ALTER TABLE ".$user_prefix."_users ADD points INT(10) DEFAULT '0'");


// Table fix
$db->sql_query("ALTER TABLE confirm RENAME ".$prefix."_confirm");

// Blocks Table Alteration
$db->sql_query("ALTER TABLE ".$prefix."_blocks ADD expire VARCHAR( 14 ) DEFAULT '0' NOT NULL");
$db->sql_query("ALTER TABLE ".$prefix."_blocks ADD action VARCHAR( 1 ) NOT NULL");

// Subscription Table Creation
$db->sql_query("CREATE TABLE ".$prefix."_subscriptions (id INT( 10 ) DEFAULT '0' AUTO_INCREMENT, userid INT( 10 ) DEFAULT '0', subscription_expire VARCHAR( 50 ) NOT NULL , INDEX ( id , userid ))");
$db->sql_query("ALTER TABLE ".$prefix."_blocks ADD subscription INT(1) DEFAULT '0' NOT NULL");


// IP Ban System Table Creation
$db->sql_query("CREATE TABLE ".$prefix."_banned_ip (id int(11) NOT NULL auto_increment, ip_address varchar(15) NOT NULL default '',  reason varchar(255) NOT NULL default '', date date NOT NULL default '0000-00-00', PRIMARY KEY id (id))");

// Users Table Modification
$db->sql_query("ALTER TABLE ".$user_prefix."_users ADD last_ip VARCHAR(15) DEFAULT '0' NOT NULL");
// Ephemerids and Sections field removal from authors table
$db->sql_query("ALTER TABLE ".$prefix."_authors DROP radminsection, DROP radminephem");

// Modules Table Update
$db->sql_query("ALTER TABLE nuke_modules ADD admins VARCHAR( 255 ) NOT NULL");

// Administrators Table modification
$db->sql_query("ALTER TABLE nuke_authors DROP radminarticle, DROP radmintopic, DROP radminuser, DROP radminsurvey, DROP radminlink , DROP radminfaq, DROP radmindownload, DROP radminreviews, DROP radminnewsletter, DROP radminforum, DROP radmincontent, DROP radminency");
$db->sql_query("ALTER TABLE nuke_authors CHANGE radminsuper radminsuper TINYINT( 1 ) DEFAULT '1' NOT NULL");

// Counter Table Alteration to add FireFox Support
$db->sql_query("INSERT INTO ".$prefix."_counter VALUES type='browser', var='FireFox', count='0'");

// PHP-Nuke copyright notice modification to be GPL 2(c) section compliant.
$db->sql_query("UPDATE ".$prefix."_config SET copyright='PHP-Nuke Copyright &copy; 2004 by Francisco Burzi. This is free software, and you may redistribute it under the <a href=\"http://phpnuke.org/files/gpl.txt\">GPL</a>. PHP-Nuke comes with absolutely no warranty, for details, see the <a href=\"http://phpnuke.org/files/gpl.txt\">license</a>.'");

$res = mysql_query ("rename table " . $prefix ."_groups to " . $prefix . "_mygroups");

echo "Upgrade to MyNews 7.6 is DONE!<br><br>"
    ."You should now delete this upgrade file from your server.";

?>
