<?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 --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2008 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;
        echo "<p>".$descr."...";
        if ($db->sql_query($sql)) result("ok");
        else {
                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 2.0.2 to 2.0.3</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("CREATE TABLE `".$db_prefix."_bonus_points` (
  `active` enum('true','false') NOT NULL default 'false',
  `upload` decimal(10,2) NOT NULL default '0.00',
  `comment` decimal(10,2) NOT NULL default '0.00',
  `offer` decimal(10,2) NOT NULL default '0.00',
  `fill_request` decimal(10,2) NOT NULL default '0.00',
  `seeding` decimal(10,2) NOT NULL default '0.00',
  `by_torrent` int(10) NOT NULL default '1'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
","Makeing Bonus Points Table");
sql_run("INSERT INTO `".$db_prefix."_bonus_points` (`active`, `upload`, `comment`, `offer`, `fill_request`, `seeding`, `by_torrent`) VALUES ('true', 50.00, 10.00, 20.00, 30.00, 0.25, 1);","Adding Default Bonus points settings");
sql_run("CREATE TABLE `".$db_prefix."_client_ban` (
  `id` int(10) NOT NULL auto_increment,
  `client` varchar(60) NOT NULL,
  `reason` varchar(255) NOT NULL,
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `client` (`client`)
) ENGINE=MyISAM;","Makeing Client Bans Table");
sql_run("CREATE TABLE `".$db_prefix."_img_bucket` (
  `allow` enum('true','false') NOT NULL default 'false',
  `level` enum('user','premium','moderator','admin') NOT NULL default 'user',
  `max_folder_size` varchar(60) NOT NULL default '0',
  `max_file_size` varchar(60) NOT NULL default '0'
) ENGINE=MyISAM;","Makeing New Image Bucket Table");
sql_run("CREATE TABLE `".$db_prefix."_log` (
  `event` int(60) unsigned NOT NULL auto_increment,
  `datetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `action` varchar(255) NOT NULL default '',
  `results` varchar(255) NOT NULL default '',
  `ip` int(10) unsigned NOT NULL default '0',
  `host` varchar(255) NOT NULL default '',
  `userid` int(60) NOT NULL default '0',
  PRIMARY KEY  (`event`),
  KEY `datetime` (`datetime`)
) ENGINE=MyISAM;
","Makeing New Log Table");
sql_run("ALTER TABLE `".$db_prefix."_shouts` ADD id_to` int(10) NOT NULL default '0',;","Adding id_to Shout");
sql_run("UPDATE ".$db_prefix."_config SET version = '2.0.3';","Finally, updating version number!");
$db->sql_query("COMMIT;");

echo "<h3>Upgrade complete! Thank You For Useing PHPMYBITTORRENT!</h3>";
?>
