<?php
/*
*-------------------------------phpMyBitTorrent--------------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*----------         Developed By Emad Hossam (aka emadness)          ----------*
*-------------               http://www.fulldls.com               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   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, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*/

if (!file_exists("include/config.php")) die("You must run this file from your phpMyBitTorrent ROOT directory, where index.php is!!");

function result($status) {
        if ($status == "ok") echo "<font color=\"#00FF00\">Done</font>";
        else echo "<font color=\"#FF0000\">Error!</font>";
}

function sql_run($sql, $descr, $failtext = "") {
        global $db;
        if ($db->sql_query($sql)){
		echo "<p>".$descr."...";
		result("ok");
		}elseif ($err["code"] =1060 ){
                //result("error");
                $err = Array();
                $err = $db->sql_error();
		echo "<p>".$descr."... ".$err["message"]."";
		result("ok");
		
		}else{
		echo "<p>".$descr."..."; 
                result("error");
                $err = Array();
                $err = $db->sql_error();
                echo("<br>");
                echo(_btsqlerror2.$err["code"]);
                echo("<br>");
                echo(_btsqlerror3.$err["message"]);

                $db->sql_query("ROLLBACK;"); //works only if in a transactional environment
                if (!empty($failtext)) echo "<br>".$failtext;
                die();
        }
		
        echo "</p>";
}

include("include/config.php");
include("language/english.php");
ob_implicit_flush(1);

echo "<h1>Upgrade from 1.2-modded to 2.0</h1>";

echo "<p>Detecting if in a transactional environment...";
if ($db->sql_query("START TRANSACTION;")) result("ok");
else {
        result("error");
        echo "<br>If anything goes wrong you'll have to manually upgrade your database";
}
echo "</p>";
sql_run("ALTER TABLE `".$db_prefix."_config`  ADD `force_passkey` enum('true','false') NOT NULL default 'false';","");
sql_run("ALTER TABLE `".$db_prefix."_config`  ADD `search_cloud_block` enum('true','false') NOT NULL default 'true';","");
sql_run("ALTER TABLE `".$db_prefix."_config`  ADD `pivate_mode` enum('true','false') NOT NULL default 'false';","");
sql_run("ALTER TABLE `".$db_prefix."_private_messages`  ADD `sender_del` enum('true','false') NOT NULL default 'false';","");
sql_run("ALTER TABLE `".$db_prefix."_private_messages`  ADD `force_passkey` enum('true','false') NOT NULL default 'false';","");
sql_run("CREATE TABLE `#prefix#_time_offset` (
  `id` smallint(4) NOT NULL auto_increment,
  `name` varchar(50) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;","");
sql_run("ALTER TABLE `".$db_prefix."_torrents`  ADD `imdb` varchar(225) NOT NULL default '';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `clean_username` varchar(25) character set utf8 collate utf8_bin NOT NULL default '';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `tzoffset` smallint(4) NOT NULL default '0';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `can_shout` enum('true','false') character set utf8 collate utf8_bin NOT NULL default 'true';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `Show_online` enum('true','false') character set utf8 collate utf8_bin NOT NULL default 'true';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `donated` int(5) unsigned NOT NULL default '0';","");
sql_run("ALTER TABLE `".$db_prefix."_users`  ADD `dondate` datetime NOT NULL default '0000-00-00 00:00:00';","");
sql_run("UPDATE ".$db_prefix."_config SET version = '2.0.2';","Finally, updating version number!");
$db->sql_query("COMMIT;");

echo "<h3>Upgrade complete! You have Just Upgraded To the New Modded version of phpMyBitTorrent 2.0.2</h3>";
?>
