<?php
error_reporting(E_ALL);

//---[CZ]: složka s třídami
define("CLASSES_PATH", "components/classes/");

//---[CZ]: deklarace verzí
$version="2.0.0";
$prev_version="1.1.3";

//---[CZ]: definování proměnných
if (!isset($_GET["mod"])) { $_GET["mod"]=""; }
if (!isset($_GET["lang"])) { $_GET["lang"]="cs"; }
if (!isset($_POST["submit"])) { $_POST["submit"]=""; }

//---[CZ]: načtení potřebných tříd a souborů
if ($_GET["mod"]=="update") {
$file = "config.php";
$f = fopen($file, "r");
$data = fread($f, filesize($file));
fclose($f);

echo substr($data, 0, 5);

if (substr($data, 0, 5)!="define") {

list($host, $name, $select, $query, $type) = split(";", $data);
list($bla1, $ip, $bla2, $login, $bla, $password) = split("\"", $host);
list($bla1, $db_name) = split("\"", $name);
list($bla1, $db_type) = split("\"", $type);

if ($db_type=="mysql") {

$config=fopen("config.php", "w+");
$data="<?php
define(\"DB_TYPE\", \"mysql\");
define(\"DB_NAME\", \"$db_name\");
define(\"DB_HOST\", mysql_connect(\"$ip\", \"$login\", \"$password\"));

mysql_select_db(DB_NAME, DB_HOST);
mysql_query(\"SET CHARACTER SET utf8\");
?".">";
fwrite($config, $data);
fclose($config);

}

}

include "config.php";
include CLASSES_PATH."Db_layer.php"; $db=new Db_layer();
}

//---[CZ]: načteme jazykový soubor
if (isset($_GET["lang"])) {
include "languages/".$_GET["lang"].".php";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta name="Author" content="Powered by K:Board v<?php echo($version); ?>, (c) 2008-2009 Štěpán Mátl, kboard.stepanmatl.cz" />
<meta name="Robots" content="noindex, nofollow" />
<meta http-equiv="Content-language" content="cs" />
<meta http-equiv="Cache-control" content="public" />
<meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
<link rel="Stylesheet" href="./themes/admin.css" type="text/css" />
<title>K:Board <?php echo($version); ?> - <?php echo LANG_INSTALLATION_AND_UPDATE; ?></title>
</head>
<body>

<div id="header">K:Board <?php echo($version); ?></div>

<h1><?php echo LANG_INSTALLATION_AND_UPDATE; ?></h1>

<div id="content">

<div id="left-column">

<h2><?php echo LANG_LANGUAGE_SELECTION; ?></h2>

<ul>
<li<?php if ($_GET["lang"]=="cs" OR $_GET["lang"]=="") { echo " class=\"active-item\""; } ?>><a href="./install.php?mod=<?php echo $_GET["mod"]; ?>&amp;lang=cs">Česky</a></li>
<li<?php if ($_GET["lang"]=="en") { echo " class=\"active-item\""; } ?>><a href="./install.php?mod=<?php echo $_GET["mod"]; ?>&amp;lang=en">English</a></li>
<li<?php if ($_GET["lang"]=="sk") { echo " class=\"active-item\""; } ?>><a href="./install.php?mod=<?php echo $_GET["mod"]; ?>&amp;lang=sk">Slovensky</a></li>
</ul>

<h2><?php echo LANG_OPTIONS; ?></h2>

<ul>
<li><a href="./index.php"><?php echo LANG_GO_TO." ".$_SERVER["SERVER_NAME"]; ?></a></li>
<li<?php if ($_GET["mod"]=="") { echo " class=\"active-item\""; } ?>><a href="./install.php<?php if (isset($_GET["lang"])) { echo "?lang=".$_GET["lang"]; } ?>"><?php echo LANG_GET_STARTED; ?></a></li>
<li<?php if ($_GET["mod"]=="install") { echo " class=\"active-item\""; } ?>><a href="./install.php?mod=install<?php if (isset($_GET["lang"])) { echo "&amp;lang=".$_GET["lang"]; } ?>"><?php echo LANG_INSTALL; ?></a></li>
<li<?php if ($_GET["mod"]=="update") { echo " class=\"active-item\""; } ?>><a href="./install.php?mod=update<?php if (isset($_GET["lang"])) { echo "&amp;lang=".$_GET["lang"]; } ?>"><?php echo LANG_UPDATE; ?></a></li>
</ul>

</div>

<div id="right-column">

<?php
if ($_GET["mod"]==""):
?>

<h2><?php echo LANG_WELCOME_TO_KBOARD." ".$version; ?>...</h2>

<?php echo LANG_LEAD_IN_TEXT; ?>

<?php
endif;
if ($_GET["mod"]=="install"):

// definovani promennych
if (!isset($_POST["db_type"])) { $_POST["db_type"]=""; }
if (!isset($_POST["db_server"])) { $_POST["db_server"]=""; }
if (!isset($_POST["db_login"])) { $_POST["db_login"]=""; }
if (!isset($_POST["db_password"])) { $_POST["db_password"]=""; }
if (!isset($_POST["db_name"])) { $_POST["db_name"]=""; }
if (!isset($_POST["db_new"])) { $_POST["db_new"]=""; }
if (!isset($_POST["url_type"])) { $_POST["url_type"]=""; }
if (!isset($_POST["selected_language"])) { $_POST["selected_language"]=""; }

// instalujeme...
if ($_POST["submit"]!="") {

// výběr databáze
if ($_POST["db_type"]=="mysql") {

if ($_POST["db_server"]!="" AND $_POST["db_login"]!="" AND $_POST["db_password"]!="" AND $_POST["db_name"]!="") {

// zkusíme se připojit
@$dbserver=mysql_connect($_POST["db_server"], $_POST["db_login"], $_POST["db_password"]);
// pokud se nepovede
if (!$dbserver) {  echo "<div class=\"popup-error\">Špatné přihlašovací údaje!<br />Bad login data!</div>"; } else {

if ($_POST["db_new"]==1) {
@$create_db=mysql_query("CREATE DATABASE ".$_POST["db_name"]." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;", $dbserver);
@$select_db=mysql_select_db($_POST["db_name"], $dbserver);
if (!$create_db) {  echo "<div class=\"popup-error\">Při instalaci došlo k chybě!<br />An error occured while installing!</div>"; } else { $ok=1; }
}

if ($_POST["db_new"]==0) {
@$select_db=mysql_select_db($_POST["db_name"], $dbserver);
if (!$select_db) {  echo "<div class=\"popup-error\">Neexistující databáze!<br />Not existing database!</div>"; } else { $ok=1; }
}

if ($ok==1) {

mysql_query("SET CHARACTER SET utf8");
 
$sql1=mysql_query("CREATE TABLE kboard_banns (
  id int(11) NOT NULL auto_increment,
  ip varchar(128) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql2=mysql_query("CREATE TABLE kboard_categories (
  id int(11) NOT NULL auto_increment,
  name varchar(128) NOT NULL,
  position int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql3=mysql_query("CREATE TABLE kboard_forums (
  id int(11) NOT NULL auto_increment,
  name varchar(128) NOT NULL,
  description varchar(128) NOT NULL,
  read_ntbl int(1) NOT NULL,
  write_ntbl int(1) NOT NULL,
  category int(11) NOT NULL,
  locked int(1) NOT NULL,
  position int(11) NOT NULL,
  read_rights int(1) NOT NULL,
  write_rights int(1) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql4=mysql_query("CREATE TABLE kboard_posts (
  id int(11) NOT NULL auto_increment,
  author int(11) NOT NULL,
  response int(11) NOT NULL,
  text text NOT NULL,
  timestamp int(11) NOT NULL,
  topic int(11) NOT NULL,
  forum int(11) NOT NULL,
  ip varchar(128) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql5=mysql_query("CREATE TABLE kboard_ranks (
  id int(11) NOT NULL auto_increment,
  name varchar(128) NOT NULL,
  start int(11) NOT NULL,
  end int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql6=mysql_query("CREATE TABLE kboard_topics (
  id int(11) NOT NULL auto_increment,
  name varchar(128) NOT NULL,
  author int(11) NOT NULL,
  locked int(1) NOT NULL,
  forum int(11) NOT NULL,
  timestamp int(11) NOT NULL,
  views int(11) NOT NULL,
  lastpost_id int(11) NOT NULL,
  lastpost_timestamp int(11) NOT NULL,
  status int(1) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql7=mysql_query("CREATE TABLE kboard_users (
  id int(11) NOT NULL auto_increment,
  login varchar(128) NOT NULL,
  password varchar(128) NOT NULL,
  rights int(1) NOT NULL,
  age varchar(3) default NULL,
  jabber varchar(128) NOT NULL,
  skype varchar(128) NOT NULL,
  about text NOT NULL,
  mail varchar(128) NOT NULL,
  realname varchar(128) NOT NULL,
  regdate int(11) NOT NULL,
  lastvisit int(11) NOT NULL,
  mail_messages int(1) NOT NULL,
  msn varchar(128) NOT NULL,
  avatar text NOT NULL,
  sign text NOT NULL,
  user_check varchar(64) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql7=mysql_query("CREATE TABLE kboard_variables (
  variable varchar(64) default NULL,
  value text
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql8=mysql_query("INSERT INTO kboard_users values ('', 'admin', '".SHA1("admin")."', '3', '', '', '', '', '', '', '".time()."', '', '', '', '', '', '')", $dbserver);

$sql9=mysql_query("INSERT INTO kboard_variables values ('lang', '".$_POST["selected_language"]."')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('sitename', 'Forum')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('table_users', 'kboard_users')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('meta_copyright', 'Copyright')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('meta_desc', '')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('meta_keywords', '')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('version', '$version')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('theme', 'kboard_default')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('paging_number', '20')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('date_format', 'd.m.Y [H:i]')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('locked_forums_writing_rights', '2')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('locked_topics_writing_rights', '1')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('topic_delete_rights', '2')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('post_delete_rights', '1')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('topic_lock_and_unlock_rights', '1')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('top_links', '')", $dbserver);
$sql9=mysql_query("INSERT INTO kboard_variables values ('items_replace_rights', '1')", $dbserver);

$config=fopen("config.php", "w+");
$data="<?php
define(\"DB_TYPE\", \"mysql\");
define(\"DB_NAME\", \"".$_POST["db_name"]."\");
define(\"DB_HOST\", mysql_connect(\"".$_POST["db_server"]."\", \"".$_POST["db_login"]."\", \"".$_POST["db_password"]."\"));

mysql_select_db(DB_NAME, DB_HOST);
mysql_query(\"SET CHARACTER SET utf8\");
?".">";
fwrite($config, $data);
fclose($config);

if ($sql1 AND $sql2 AND $sql3 AND $sql4 AND $sql5 AND $sql6 AND $sql7 AND $sql8 AND $sql9) {
echo "<div class=\"popup-success\">Instalace byla úspěšně dokočena!<br />Installation was successfully completed.</div>";
} else {
echo "<div class=\"popup-error\">Při instalaci došlo k chybě!<br />An error occured while installing!</div>";
}

}

}
} else { echo "<div class=\"popup-error\">Chyba, musíte vyplnit zvýrazněná pole!<br />Error, you must fill highlighted inputs!</div>"; }
}

if ($_POST["db_type"]=="sqlite") {

// založíme / otevřene databázi
$sqlite_db=sqlite_open("components/sqlite/sqlite.db");

if (!$sqlite_db) {
echo "<div class=\"popup-error\">Při instalaci došlo k chybě!<br />An error occured while installing!</div>";
} else {
  
$sql1=sqlite_query($sqlite_db, "CREATE TABLE kboard_banns (
  id INTEGER PRIMARY KEY NOT NULL,
  ip varchar(128) NOT NULL)");

$sql2=sqlite_query($sqlite_db, "CREATE TABLE kboard_categories (
  id INTEGER PRIMARY KEY NOT NULL,
  name varchar(128) NOT NULL,
  position INTEGER NOT NULL DEFAULT '0')");

$sql3=sqlite_query($sqlite_db, "CREATE TABLE kboard_forums (
  id INTEGER PRIMARY KEY NOT NULL,
  name varchar(128) NOT NULL,
  description varchar(128) NULL,
  read_ntbl int(1) NOT NULL DEFAULT '0',
  write_ntbl int(1) NOT NULL DEFAULT '0',
  category INTEGER NOT NULL DEFAULT '0',
  locked int(1) NOT NULL DEFAULT '0',
  position INTEGER NOT NULL DEFAULT '0',
  read_rights int(1) NOT NULL DEFAULT '0',
  write_rights int(1) NOT NULL DEFAULT '0')");
  
$sql4=sqlite_query($sqlite_db, "CREATE TABLE kboard_posts (
  id INTEGER PRIMARY KEY NOT NULL,
  author INTEGER NOT NULL DEFAULT '0',
  response INTEGER NOT NULL DEFAULT '0',
  text text,
  timestamp INTEGER NOT NULL DEFAULT '0',
  topic INTEGER NOT NULL DEFAULT '0',
  forum INTEGER NOT NULL DEFAULT '0',
  ip varchar(128) NOT NULL)");
  
$sql5=sqlite_query($sqlite_db, "CREATE TABLE kboard_ranks (
  id INTEGER PRIMARY KEY NOT NULL,
  name varchar(128) NOT NULL,
  start INTEGER NOT NULL DEFAULT '0',
  end INTEGER NOT NULL DEFAULT '0')");
  
$sql6=sqlite_query($sqlite_db, "CREATE TABLE kboard_topics (
  id INTEGER PRIMARY KEY NOT NULL,
  name varchar(128) NOT NULL,
  author INTEGER NOT NULL DEFAULT '0',
  locked int(1) NULL DEFAULT '0',
  forum INTEGER NOT NULL DEFAULT '0',
  timestamp INTEGER NOT NULL DEFAULT '0',
  views INTEGER NOT NULL DEFAULT '0',
  lastpost_id INTEGER NOT NULL DEFAULT '0',
  lastpost_timestamp INTEGER NOT NULL DEFAULT '0',
  status int(1) NULL DEFAULT '0')");

$sql7=sqlite_query($sqlite_db, "CREATE TABLE kboard_users (
  id INTEGER PRIMARY KEY NOT NULL,
  login varchar(128) NOT NULL,
  password varchar(128) NOT NULL,
  rights int(1) NOT NULL DEFAULT '0',
  age varchar(3) default NULL,
  jabber varchar(128),
  skype varchar(128),
  about text,
  mail varchar(128),
  realname varchar(128),
  regdate INTEGER NOT NULL DEFAULT '0',
  lastvisit INTEGER NOT NULL DEFAULT '0',
  mail_messages int(1) NOT NULL DEFAULT '0',
  msn varchar(128),
  avatar text,
  sign text,
  user_check varchar(68))");

$sql8=sqlite_query($sqlite_db, "CREATE TABLE kboard_variables (
  variable varchar(64) default NULL,
  value text)");

$sql8=sqlite_query($sqlite_db, "INSERT INTO kboard_users (login, password, rights, regdate) values ('admin', '".SHA1("admin")."', 3, ".time().")");

$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('lang', '".$_POST["selected_language"]."')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('sitename', 'Forum')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('meta_copyright', 'Copyright')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('meta_keywords', '')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('meta_desc', '')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('version', '$version')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('theme', 'kboard_default')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('table_users', 'kboard_users')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('paging_number', '20')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('date_format', 'd.m.Y [H:i]')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('locked_forums_writing_rights', '2')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('locked_topics_writing_rights', '1')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('topic_delete_rights', '2')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('post_delete_rights', '1')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('topic_lock_and_unlock_rights', '1')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('top_links', '')");
$sql9=sqlite_query($sqlite_db, "INSERT INTO kboard_variables (variable, value) values ('items_replace_rights', '1')");

$config=fopen("config.php", "w+");
$data="<?php
define(\"DB_TYPE\", \"sqlite\");
define(\"DB_HOST\", sqlite_open(\"components/sqlite/sqlite.db\"));
?".">";
fwrite($config, $data);
fclose($config);

if ($sql1 AND $sql2 AND $sql3 AND $sql4 AND $sql5 AND $sql6 AND $sql7 AND $sql8 AND $sql9) {
echo "<div class=\"popup-success\">Instalace byla úspěšně dokočena!<br />Installation was successfully completed.</div>";
} else {
echo "<div class=\"popup-error\">Při instalaci došlo k chybě!<br />An error occured while installing!</div>";
}

}

}
}
?>

<h2><?php echo LANG_INSTALL; ?></h2>

<script type="text/javascript">
/* <![CDATA[ */
function db_options(what) {
if (what=='mysql') document.getElementById('options').style.display='block';
if (what=='sqlite') document.getElementById('options').style.display='none';
}
/* ]]> */
</script>

<form action="./install.php?mod=install" method="post">

<div>

<p><strong><?php echo LANG_DATABASE; ?>:</strong><br />
<select name="db_type" style="width: 150px;" onchange="db_options(options[this.selectedIndex].value);">
<option value="mysql"<?php if ($_POST["submit"]!="" AND $_POST["db_type"]=="mysql") { echo " selected=\"selected\""; } ?>>MySQL</option>
<option value="sqlite"<?php if ($_POST["submit"]!="" AND $_POST["db_type"]=="sqlite") { echo " selected=\"selected\""; } ?>>SQLite</option>
</select></p>

<span id="options"<?php if ($_POST["db_type"]=="sqlite") { echo " style=\"display: none;\""; } ?>>

<p><strong><?php echo LANG_DATABASE_SERVER; ?>:</strong><br />
<input type="text" name="db_server" style="width: 200px;" value="<?php echo($_POST["db_server"]); ?>"<?php if ($_POST["submit"]!="" AND $_POST["db_server"]=="") { echo " class=\"input-error\""; } ?> /></p>

<p><strong><?php echo LANG_USERNAME; ?>:</strong><br />
<input type="text" name="db_login" style="width: 200px;" value="<?php echo($_POST["db_login"]); ?>"<?php if ($_POST["submit"]!="" AND $_POST["db_login"]=="") { echo " class=\"input-error\""; } ?> /></p>

<p><strong><?php echo LANG_PASSWORD; ?>:</strong><br />
<input type="password" name="db_password" style="width: 200px;" value="<?php echo($_POST["db_password"]); ?>"<?php if ($_POST["submit"]!="" AND $_POST["db_password"]=="") { echo " class=\"input-error\""; } ?> /></p>

<p><strong><?php echo LANG_DATABASE_NAME; ?>:</strong><br />
<input type="text" name="db_name" style="width: 200px;" value="<?php echo($_POST["db_name"]); ?>"<?php if ($_POST["submit"]!="" AND $_POST["db_name"]=="") { echo " class=\"input-error\""; } ?> /></p>

<p><input type="radio" name="db_new" value="0"<?php if ($_POST["db_new"]!=1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_USE_AN_EXISTING_DATABASE; ?><br />
<input type="radio" name="db_new" value="1"<?php if ($_POST["db_new"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_CREATE_A_NEW_DATABASE; ?></p>

</span>

</div>

<div>

<p><strong><?php echo LANG_LANGUAGE_SELECTION; ?>:</strong><br />
<select name="selected_language" style="width: 100px;">
<?php
$dir=opendir("./languages/");
while ($file=readdir($dir)){
$file=explode(".", $file);
$lang_name=strtoupper($file[0]);
if ($lang_name!="") {
echo ("<option value=\"".$file[0]."\"");
if ($file[0]==$_POST["selected_language"]) { echo " selected=\"selected\""; }
echo ">$lang_name</option>\n";
}
}
?>
</select></p>

</div>

<div>

<p><input type="submit" name="submit" value="<?php echo LANG_INSTALL; ?>" /></p>

</div>

</form>

<?php
endif;
if ($_GET["mod"]=="update"):

// aktualizujeme...
if ($_POST["submit"]!="") {

$sql1=$db->query("UPDATE kboard_variables SET value='$version' WHERE variable='version'");
$sql2=$db->query("ALTER TABLE kboard_users ADD user_check varchar(68) NOT NULL");
$sql3=$db->query("UPDATE kboard_users SET avatar=''");

$p=$db->query("SELECT id, text FROM kboard_posts");
while (list($id, $text) = $db->fetch_row($p)) {
$text=str_replace("[.bold.]", "[b]", $text);
$text=str_replace("[./bold.]", "[/b]", $text);
$text=str_replace("[.italic.]", "[i]", $text);
$text=str_replace("[./italic.]", "[/i]", $text);
$ulozit=$db->query("UPDATE kboard_posts SET text='$text' WHERE id=$id");
}

if ($sql1 AND $sql2) {
echo "<div class=\"popup-success\">Aktualizace byla úspěšně dokočena!<br />Update was successfully completed.</div>";
} else {
echo "<div class=\"popup-error\">Při aktualizaci došlo k chybě!<br />An error occured while updating!</div>";
}

}

$old_version=$db->query("SELECT value FROM kboard_variables WHERE variable='version'");
$old_version=$db->fetch_array($old_version);
?>

<h2><?php echo LANG_UPDATE; ?> K:Board <?php echo $old_version["value"]; ?> &rarr; <?php echo $version; ?></h2>

<form action="./install.php?mod=update" method="post">

<div>

<p><strong><?php echo LANG_CHECKING_VERSIONS; ?>:</strong><br />
<?php echo LANG_CURRENTLY_INSTALLED_VERSION; ?>: <strong><?php echo $old_version["value"]; ?></strong><br />
<?php echo LANG_REQUIRED_VERSION; ?>: <strong><?php echo $prev_version; ?> <?php echo LANG_AND_NEWER; ?></strong></p>

</div>

<div>

<p class="align-center"><strong<?php $ko=0; if (str_replace(".", "", $old_version["value"])>=str_replace(".", "", $prev_version) AND $old_version["value"]!=$version) { echo " style=\"color: #8ecb03; font-size: 130%;\"> ".LANG_YOU_CAN_UPDATE; } else { echo " style=\"color: #e23e00; font-size: 130%;\"> ".LANG_YOU_CANT_UPDATE_FROM_THIS_VERSION; $ko=1; } ?></strong></p>

</div>

<div>

<p><input type="submit" name="submit" value="<?php echo LANG_UPDATE; ?>"<?php if ($ko==1) { echo " disabled=\"disabled\""; } ?> /></p>

</div>

</form>

<?php
endif;
?>

</div>

<div class="float-ending"><!-- --></div>

</div>

<p id="footer"><?php echo "Powered by <a href=\"http://kboard.stepanmatl.cz\">K:Board</a> v$version, &copy; 2008-2009 Štěpán Mátl."; ?></p>

</body>
</html>