<html>
<head>
<title>FutureBB 1.1 to 1.2 Update Patch</title>
<style>
body, table {
 font-size: 12px;
 font-family: Arial;
}
</style>
</head>
<body>
<?php
$do = @$_POST['do'];

if ($do == "") {
?>
<center><font size="+1">FutureBB 1.1 to 1.2 Update Patch</font></center><br />
Before running this file, make sure you have overwritten all of your old 1.1 files with the new 1.2 files. You will need to provide your MySQL username, password, server, and database from your old 1.1 installation - since the old configuration file has been overwritten.<br /><br />
<form method="POST" action="?">
 <input type="hidden" name="do" value="update">
 <table>
  <tr>
   <td align="right"><b>MySQL Username:</b></td>
   <td><input type="text" name="mysqli_user" value="root" size="15"></td>
  </tr>
  <tr>
   <td align="right"><b>MySQL Password:</b></td>
   <td><input type="password" name="mysqli_pass" size="15"></td>
  </tr>
  <tr>
   <td align="right"><b>MySQL Database:</b></td>
   <td><input type="text" name="mysqli_data" value="futurebb" size="15"></td>
  </tr>
  <tr>
   <td align="right"><b>MySQL Server:</b></td>
   <td><input type="text" name="mysqli_serv" value="localhost" size="15"></td>
  </tr>
  <tr>
   <td align="center" colspan="2"><input type="submit" value="UPDATE"></td>
  </tr>
 </table>
</form>
<?php
}
else if ($do == "update") {
 $mysqli_user = addslashes(@$_POST['mysqli_user']);
 $mysqli_pass = addslashes(@$_POST['mysqli_pass']);
 $mysqli_data = addslashes(@$_POST['mysqli_data']);
 $mysqli_serv = addslashes(@$_POST['mysqli_serv']);
 if ($mysqli_user && $mysqli_data && $mysqli_serv) {
  $mysqli_php_file_information = "<?" . "php
\$mysqli_user = \"{$mysqli_user}\";
\$mysqli_pass = \"{$mysqli_pass}\";
\$mysqli_data = \"{$mysqli_data}\";
\$mysqli_serv = \"{$mysqli_serv}\";

// DO NOT EDIT BELOW THIS LINE
\$mysqli_conn=mysqli_connect(\$mysqli_serv, \$mysqli_user, \$mysqli_pass);
mysqli_select_db(\$mysqli_conn,\$mysqli_data);
?" . ">";

  $error = 0;
  $fp = @fopen("includes/mysql.php", "w");
  if ($fp) {
   $wr = @fwrite($fp, $mysqli_php_file_information);
   if (!$wr) {
    $error = 1;
    echo "Unable to write to includes/mysql.php file.";
   }
  }
  else {
   $error = 1;
   echo "Failed to open includes/mysql.php file.";
  }
  @fclose($fp);

  if (!$error) {
   include("includes/mysql.php");
   $q1 = mysqli_query($connection,"ALTER TABLE `users` ADD subtitle varchar(255) AFTER title");
   $q2 = mysqli_query($connection,"UPDATE `users` SET subtitle=title");
   $q3 = mysqli_query($connection,"ALTER TABLE `cats` ADD catOrder int(100) AFTER name");
   $c = 1;
   $q = mysqli_query($connection,"SELECT * FROM `cats`");
   while ($row = mysqli_fetch_array($q)) {
    mysqli_query($connection,"UPDATE `cats` SET catOrder='$c' WHERE id='{$row['id']}'");
    $c++;
   }
   $q4 = mysqli_query($connection,"ALTER TABLE `forums` ADD forumOrder int(100) AFTER locked");
   $c = 1;
   $q = mysqli_query($connection,"SELECT * FROM `forums`");
   while ($row = mysqli_fetch_array($q)) {
    mysqli_query($connection,"UPDATE `forums` SET forumOrder='$c' WHERE id='{$row['id']}'");
    $c++;
   }
   $q5 = mysqli_query($connection,"create table `guests` (
 id int(100) auto_increment,
 user varchar(100),
 date int(10),
 primary key(id)
);");
   $q6 = mysqli_query($connection,"create table `smileys` (
 id int(100) auto_increment,
 src varchar(255),
 keyVal varchar(5),
 primary key(id)
);");
   $q7 = mysqli_query($connection,"insert into `smileys` values ('','smiley01.gif',':)');");
   $q8 = mysqli_query($connection,"insert into `smileys` values ('','smiley02.gif',';)');");
   $q9 = mysqli_query($connection,"insert into `smileys` values ('','smiley03.gif',':p');");
   $q10 = mysqli_query($connection,"insert into `smileys` values ('','smiley04.gif',':(');");
   $q11 = mysqli_query($connection,"insert into `smileys` values ('','smiley05.gif',':d');");
   $q12 = mysqli_query($connection,"insert into `smileys` values ('','smiley06.gif',':o');");
   $q13 = mysqli_query($connection,"ALTER TABLE `threads` ADD sticky int(1) AFTER inForum");
   $q14 = mysqli_query($connection,"UPDATE `threads` SET sticky='0'");
   echo "Your FutureBB 1.1 installation has now been upgraded to FutureBB 1.2!<br />";
   echo "You should delete this file now.";
  }
 }
 else {
  echo "You need to specify a username, database, and host name.";
 }
 echo "<br /><br />\n<a href=\"update.php\">[ Back ]</a>\n";
}
?>
</body>
</html>