<?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");
		}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.0 to 1.2</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 `torrent_config` ADD `upload_dead` ENUM( 'true', 'false' ) NOT NULL DEFAULT 'true' ;","Adding Allow dead torrent upload To configs table");
sql_run("CREATE TABLE `torrent_paypal` (`siteurl` varchar(255) NOT NULL default '', `paypal_email` varchar(60) NOT NULL default '', `sitecost` varchar(60) NOT NULL default '', `reseaved_donations` varchar(60) NOT NULL default '', `donatepage` longtext NOT NULL, `donation_block` enum('true','false') NOT NULL default 'true', `nodonate` enum('EU','UK','US') NOT NULL default 'US') TYPE=MyISAM;","Creating Pay-pal table");
sql_run("INSERT INTO `torrent_paypal` VALUES('http://www.yoursite.net','you@youraddy.com','0','0','0','','');","Adding Default Pay-pal settings");
sql_run("CREATE TABLE `torrent_rules` (`id` int(11) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '', `text` text NOT NULL, `public` enum('yes','no') NOT NULL default 'yes', `level` enum('user','premium','moderator','admin') NOT NULL default 'user',  PRIMARY KEY  (`id`)) ENGINE=MyISAM;","Adding Rules Block");
sql_run("INSERT INTO `torrent_paypal` VALUES('http://www.yoursite.net','you@youraddy.com','0','0','0','','');","Adding Default Pay-pal settings");
sql_run("INSERT INTO `torrent_rules` VALUES (14, 'how do you get files', 'You must be a member Of this site to do any thing......', 'yes', 'user');","z");
sql_run("INSERT INTO `torrent_rules` VALUES (9, 'Avatar Guidelines - <font color=#CC0000>Please try to follow these guidelines</font>', '<ul>     The allowed formats are .gif, .jpg and .png.      Be considerate. Resize your images to a width of 150 px and a size of no more than 150 KB. (Browsers will rescale them anyway: smaller images will be expanded and will not look good; larger images will just waste bandwidth and CPU cycles.) For now this is just a guideline but it will be automatically enforced in the near future.      Do not use potentially offensive material involving porn, religious material, animal / human cruelty or ideologically charged images. Mods have wide discretion on what is acceptable. If in doubt PM one. 		 </ul>', 'no', 'user');","Adding test rules");
sql_run("INSERT INTO `torrent_rules` VALUES (10, 'Moderating Rules - <font color=#CC0000>Use your better judgement!</font>', '<ul>     The most important rule: Use your better judgment!     Don''t be afraid to say <strong>NO</strong>! (a.k.a. &quot;Helshad''s rule&quot;.)      Don''t defy another mod in public, instead send a PM or through IM.     Be tolerant! Give the user(s) a chance to reform.     Don''t act prematurely, let the users make their mistakes and THEN correct them.     Try correcting any &quot;off topics&quot; rather then closing a thread.     Move topics rather than locking them.     Be tolerant when moderating the Chit-chat section (give them some slack).     If you lock a topic, give a brief explanation as to why you''re locking it.     Before you disable a user account, send him/her a PM and if they reply, put them on a 2 week trial.     Don''t disable a user account until he or she has been a member for at least 4 weeks.     <strong>Always</strong> state a reason (in the user comment box) as to hy the user is being banned / warned. </ul>', 'no', 'premium');","Adding test rules");
sql_run("UPDATE torrent_config SET version = '1.2.1';","Finally, updating version number!");

$db->sql_query("COMMIT;");

echo "<h3>Upgrade complete!</h3>";
?>