<?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.6.1";

//---[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);

if (substr($data, 0, 10)!="<?php\r\ndef" AND substr($data, 0, 8)!="<?php ?".">") {

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.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $_GET["lang"]; ?>">
<head>
<meta name="Author" content="Powered by K:CMS v<?php echo($version); ?>, (c) 2008-2009 Štěpán Mátl, kcms.stepanmatl.cz" />
<meta name="Robots" content="noindex, nofollow" />
<meta http-equiv="Content-language" content="<?php echo $_GET["lang"]; ?>" />
<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:CMS <?php echo($version); ?></div>

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

<div id="content">

<div id="left-column">

<h2><?php echo LANG_LANGUAGE_FILE; ?></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_KCMS." ".$version; ?>...</h2>

<?php echo LANG_LEAD_IN_TEXT; ?>

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

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"]=""; }

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

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

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

@$dbserver=mysql_connect($_POST["db_server"], $_POST["db_login"], $_POST["db_password"]);

if (!$dbserver) {  echo "<div class=\"popup-error\">".LANG_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\">".LANG_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\">".LANG_THIS_DATABASE_NOT_EXISTS."</div>"; } else { $ok=1; }
}

if ($ok==1) {

mysql_query("SET CHARACTER SET utf8");
 
$sql1=mysql_query("CREATE TABLE kcms_articles (
  id int(11) NOT NULL auto_increment,
  quick varchar(160) NOT NULL,
  title varchar(128) NOT NULL,
  type int(1) NOT NULL,
  hp int(1) NOT NULL,
  complete int(1) NOT NULL,
  confirmed int(1) NOT NULL,
  discussion int(1) NOT NULL,
  section int(3) NOT NULL,
  perex text,
  text text,
  added int(11) NOT NULL,
  published int(11) NOT NULL,
  author int(11) NOT NULL,
  publisher int(11) NOT NULL,
  edited int(11) NOT NULL,
  pereximg varchar(128) NOT NULL,
  views int(11) NOT NULL,
  top int(1) NOT NULL,
  show_article_info int(1) NOT NULL,
  keywords text,
  poll int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql2=mysql_query("CREATE TABLE kcms_bans (
  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);
 
$sql3=mysql_query("CREATE TABLE kcms_columns (
  id int(11) NOT NULL auto_increment,
  col varchar(5) NOT NULL,
  name varchar(128) NOT NULL,
  content text NOT NULL,
  hidden int(1) NOT NULL,
  position int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql4=mysql_query("CREATE TABLE kcms_comments (
  id int(11) NOT NULL auto_increment,
  article int(11) NOT NULL,
  added int(11) default NULL,
  author varchar(128) NOT NULL,
  text text NOT NULL,
  confirmed int(1) NOT NULL,
  user int(1) NOT NULL,
  ip varchar(32) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql5=mysql_query("CREATE TABLE kcms_files (
  id int(11) NOT NULL auto_increment,
  file varchar(128) NOT NULL,
  added int(11) NOT NULL,
  uploader int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql6=mysql_query("CREATE TABLE kcms_images (
  id int(11) NOT NULL auto_increment,
  section int(11) NOT NULL,
  file varchar(128) NOT NULL,
  added int(11) NOT NULL,
  title varchar(128),
  uploader int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql7=mysql_query("CREATE TABLE kcms_images_sections (
  id int(11) NOT NULL auto_increment,
  quick varchar(160) NOT NULL,
  name varchar(128) NOT NULL,
  public int(1) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql8=mysql_query("CREATE TABLE kcms_polls (
  id int(11) NOT NULL auto_increment,
  name varchar(128) NOT NULL,
  visible int(1) NOT NULL,
  type int(1) NOT NULL,
  author int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);
 
$sql9=mysql_query("CREATE TABLE kcms_polls_data (
  id int(11) NOT NULL auto_increment,
  poll int(11) NOT NULL,
  answer varchar(128) NOT NULL,
  votes int(11) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql10=mysql_query("CREATE TABLE kcms_sections (
  id int(11) NOT NULL auto_increment,
  quick varchar(160) NOT NULL,
  name varchar(128) NOT NULL,
  highlight int(1) NOT NULL,
  outlink text NOT NULL,
  ntbl int(1) NOT NULL,
  position int(3) NOT NULL,
  hidden int(1) NOT NULL,
  level int(3) NOT NULL,
  higher int(3) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

$sql11=mysql_query("CREATE TABLE kcms_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 text NOT NULL,
  icq varchar(9) NOT NULL,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci", $dbserver);

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

$sql=mysql_query("INSERT INTO kcms_users values ('', 'admin', '".SHA1("admin")."', '5', '', '', '', '', '', '', '".time()."', '', '', '', '', '', '', '')", $dbserver);

$sql=mysql_query("INSERT INTO kcms_variables values ('lang', '".$_GET["lang"]."')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('sitename', 'Website')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('login_for_comments', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_text', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('sort_sections_by_name', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('articles_number', '10')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('comments_number', '10')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('meta_copyright', 'Copyright')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('meta_keywords', '')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('meta_desc', '')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('version', '$version')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('url_type', '".$_POST["url_type"]."')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('use_emoticons', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_random_image', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('sort_images_by_name', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('sort_comments_from_newest', '0')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_add_content', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_archive', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_bans', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_comments', '2')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_unverified_articles', '2')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_edit_content', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_files', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_images', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_mail_messages', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_meta_tags', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_my_content', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_options', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_overview', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_polls', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_unpublished_articles', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_rights', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_sections', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('rights_users', '3')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_article_date', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_article_section', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_article_comments_number', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_article_views_number', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('show_article_author', '1')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('table_users', 'kcms_users')", $dbserver);
$sql=mysql_query("INSERT INTO kcms_variables values ('template', 'kcms_default')", $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 AND $sql10 AND $sql12) {
echo "<div class=\"popup-success\">".LANG_INSTALLATION_WAS_SUCCESSFULLY_COMPLETED."</div>";
} else {
echo "<div class=\"popup-error\">".LANG_AN_ERROR_OCCURED_WHILE_INSTALLING."</div>";
}

}

}
} else { echo "<div class=\"popup-error\">".LANG_YOU_HAVE_NOT_FILLED_SOME_ITEMS."</div>"; }
}

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

$sqlite_db=sqlite_open("components/sqlite/sqlite.db");

if (!$sqlite_db) {
echo "<div class=\"popup-error\">".LANG_AN_ERROR_OCCURED_WHILE_INSTALLING."</div>";
} else {
  
$sql1=sqlite_query($sqlite_db, "CREATE TABLE kcms_articles (
  id INTEGER PRIMARY KEY NOT NULL,
  quick varchar(160) NOT NULL,
  title varchar(128) NOT NULL,
  type INTEGER NOT NULL,
  hp INTEGER NOT NULL DEFAULT '0',
  complete INTEGER NOT NULL DEFAULT '0',
  confirmed INTEGER NOT NULL DEFAULT '0',
  discussion INTEGER NOT NULL DEFAULT '0',
  section INTEGER NOT NULL,
  perex text,
  text text,
  added INTEGER NOT NULL,
  published INTEGER NOT NULL DEFAULT '0',
  author INTEGER NOT NULL,
  publisher INTEGER NOT NULL DEFAULT '0',
  edited INTEGER NOT NULL DEFAULT '0',
  pereximg varchar(128) NOT NULL,
  views INTEGER NOT NULL DEFAULT '0',
  top int(1) NOT NULL DEFAULT '0',
  show_article_info int(1) NOT NULL DEFAULT '0',
  keywords text,
  poll int(1) NOT NULL DEFAULT '0')");
  
$sql2=sqlite_query($sqlite_db, "CREATE TABLE kcms_banns (
  id INTEGER PRIMARY KEY NOT NULL,
  ip varchar(128) NOT NULL)");
  
$sql3=sqlite_query($sqlite_db, "CREATE TABLE kcms_columns (
  id INTEGER PRIMARY KEY NOT NULL,
  col varchar(5) NOT NULL,
  name varchar(128) NOT NULL,
  content text NOT NULL,
  hidden int(1) NOT NULL DEFAULT '0',
  position INTEGER NOT NULL)");

$sql4=sqlite_query($sqlite_db, "CREATE TABLE kcms_comments (
  id INTEGER PRIMARY KEY NOT NULL,
  article INTEGER NOT NULL,
  added INTEGER default NULL,
  author varchar(128) NOT NULL,
  text text NOT NULL,
  confirmed int(1) NOT NULL DEFAULT '0',
  user int(1) NOT NULL DEFAULT '0',
  ip varchar(32) NOT NULL)");

$sql5=sqlite_query($sqlite_db, "CREATE TABLE kcms_files (
  id INTEGER PRIMARY KEY NOT NULL,
  file varchar(128) NOT NULL,
  added INTEGER NOT NULL,
  uploader INTEGER NOT NULL)");

$sql6=sqlite_query($sqlite_db, "CREATE TABLE kcms_images (
  id INTEGER PRIMARY KEY NOT NULL,
  section INTEGER NOT NULL,
  file varchar(128) NOT NULL,
  added INTEGER NOT NULL,
  title varchar(128),
  uploader INTEGER NOT NULL)");

$sql7=sqlite_query($sqlite_db, "CREATE TABLE kcms_images_sections (
  id INTEGER PRIMARY KEY NOT NULL,
  quick varchar(160) NOT NULL,
  name varchar(128) NOT NULL,
  public int(1) NOT NULL DEFAULT '0')");

$sql8=sqlite_query($sqlite_db, "CREATE TABLE kcms_polls (
  id INTEGER PRIMARY KEY NOT NULL,
  name varchar(128) NOT NULL,
  visible int(1) NOT NULL DEFAULT '0',
  type int(1) NOT NULL,
  author INTEGER NOT NULL)");

$sql9=sqlite_query($sqlite_db, "CREATE TABLE kcms_polls_data (
  id INTEGER PRIMARY KEY NOT NULL,
  poll INTEGER NOT NULL,
  answer varchar(128) NOT NULL,
  votes INTEGER NOT NULL DEFAULT '0')");

$sql10=sqlite_query($sqlite_db, "CREATE TABLE kcms_sections (
  id INTEGER PRIMARY KEY NOT NULL,
  quick varchar(160) NOT NULL,
  name varchar(128) NOT NULL,
  highlight int(1) NOT NULL DEFAULT '0',
  outlink text,
  ntbl int(1) NOT NULL DEFAULT '0',
  position int(3) NOT NULL DEFAULT '0',
  hidden int(1) NOT NULL DEFAULT '0',
  level int(3) NOT NULL DEFAULT '0',
  higher int(3) NOT NULL DEFAULT '0')");

$sql11=sqlite_query($sqlite_db, "CREATE TABLE kcms_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 text,
  msn varchar(9))");

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

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

$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('lang', '".$_GET["lang"]."')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('sitename', 'Website')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('login_for_comments', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_text', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('sort_sections_by_name', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('articles_number', '10')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('comments_number', '10')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('meta_copyright', 'Copyright')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('meta_keywords', '')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('meta_desc', '')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('version', '$version')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('url_type', '".$_POST["url_type"]."')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('use_emoticons', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_random_image', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('sort_images_by_name', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('sort_comments_from_newest', '0')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_add_content', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_archive', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_bans', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_comments', '2')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_unverified_articles', '2')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_edit_content', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_files', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_images', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_mail_messages', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_meta_tags', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_my_content', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_options', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_overview', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_polls', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_unpublished_articles', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_rights', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_sections', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('rights_users', '3')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_article_date', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_article_section', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_article_comments_number', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_article_views_number', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('show_article_author', '1')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('table_users', 'kcms_users')");
$sql=sqlite_query($sqlite_db, "INSERT INTO kcms_variables (variable, value) values ('template', 'kcms_default')");

$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 AND $sql10 AND $sql11 AND $sql12) {
echo "<div class=\"popup-success\">".LANG_INSTALLATION_WAS_SUCCESSFULLY_COMPLETED."</div>";
} else {
echo "<div class=\"popup-error\">".LANG_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>

<div 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>

</div>

</div>

<div>

<p><strong><?php echo LANG_URL_ADDRESSES_TYPE; ?>:</strong><br />
<input type="radio" name="url_type" value="static"<?php if ($_POST["url_type"]!="dynamic") { echo " checked=\"checked\""; } ?> /> <?php echo LANG_STATIC_URL_RECOMMENDED_REQUIRE_MOD_REWRITE_SUPPORT; ?><br />
<input type="radio" name="url_type" value="dynamic"<?php if ($_POST["url_type"]=="dynamic") { echo " checked=\"checked\""; } ?> /> <?php echo LANG_DYNAMIC_URL; ?></p>

</div>

<div>

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

</div>

</form>

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

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\">".UPDATE_WAS_SUCCESSFULLY_COMPLETED."</div>";
} else {
echo "<div class=\"popup-error\">".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>