<?php
$version="1.3.0";
$prev_version="1.2.0";
if ($mod=="update" OR $mod=="uninstall") { require "config.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:CMS v<?php echo($version); ?>, &copy; 2008 Stepan Matl, matl-soft.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="./styles/admin.css" type="text/css" />
<title>K:CMS <?php echo($version); ?> - Instalace (Installation) / Aktualizace (Update)</title>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
function openWindow(link) {
  otevrit=window.open(link);
  return (typeof(otevrit)=='object')?true:false;
}
/* ]]> */
</script>

<div class="header">K:CMS <?php echo($version); ?></div>
<h1>Instalace (Installation) / Aktualizace (Update)</h1>

<div class="main">

<div class="left-column">

<div class="menu-title">Módy (Modes)</div>

<ul>
<li><a href="./install.php">Úvod (Lead-in)</a></li>
<li><a href="./install.php?mod=install">Instalovat (Install)</a></li>
<li><a href="./install.php?mod=update">Aktualizovat (Update)</a></li>
<li><a href="./install.php?mod=uninstall">Odinstalovat (Uninstall)</a></li>
</ul>

</div>

<div class="right-column">

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

<h2>Vítejte v K:CMS <?php echo($version); ?>...</h2>

<p>Toto je automatická instalace. Prosím, vyberte příslušný mód. Tlačítko <em>Instalovat</em> vytvoří zcela novou instalaci systému K:CMS. Budete potřebovat údaje pro připojení k databázovému serveru - <strong>adresu serveru</strong>, <strong>přihlašovací jméno</strong>, <strong>heslo</strong> a <strong>jméno databáze</strong>. Pokud neznáte jméno existující databáze, můžete vytvořit novou.</p>

<p>Tlačítko <em>Aktualizovat</em> provede aktualizaci stávající verze K:CMS na novější.</p>

<h3>Nakonec nezapomeňte SMAZAT tento soubor ze serveru!</h3>

<h2>Welcome to K:CMS <?php echo($version); ?>...</h2>

<p>This is automatic installation. Please, select corresponding mode. The <em>Install</em> will create a new installation of K:CMS. For this action, you need connection data for connection to database server - <strong>server address</strong>, <strong>login name</strong>, <strong>password</strong> and <strong>database name</strong>. If you don't know the name of existing database, you can create new one.</p>

<p>The <em>Update</em> button will update the current version of K:CMS to newer.</p>

<h3>Finally, don't forget to DELETE this file from the server!</h3>

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

// instalujeme...
if ($submit!="") {
if ($_POST["db_server"]!="" AND $_POST["db_login"]!="" AND $_POST["db_password"]!="" AND $_POST["db_new"]==1 OR $_POST["db_new"]==0 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 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,
  PRIMARY KEY (id),
  FULLTEXT KEY title (title),
  FULLTEXT KEY text (text),
  FULLTEXT KEY perex (perex)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci");

$sql2=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,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci");

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

$sql3=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,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci");

$sql4=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");

$sql5=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,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci");

$sql6=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,
  PRIMARY KEY (id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci");

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

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

$sql10=mysql_query("INSERT INTO kcms_variables values ('lang', '".$_POST["selected_language"]."')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('sitename', 'Website')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('login_for_comments', '0')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('show_text', '0')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('sort_sections_by_name', '0')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('articles_number', '10')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('left_column', '')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('right_column', '')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('meta_copyright', 'Copyright')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('meta_keywords', '')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('meta_desc', '')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('version', '$version')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('theme', 'kcms_default')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('show_news_box', '1')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('show_promo_box', '1')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('news_box_items', '5')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('promo_box_items', '5')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('show_infolane', '1')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('show_sitename', '1')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('header_wallpaper', '')", $dbserver);
$sql10=mysql_query("INSERT INTO kcms_variables values ('header_wallpaper_height', '')", $dbserver);

$sql11=mysql_query("INSERT INTO kcms_sections values ('', 'test', 'Test', '0', '')", $dbserver);

$sql12=mysql_query("INSERT INTO kcms_articles values ('', 'test', 'Test', '1', '1', '1', '1', '1', '1', '', '<p>Test article / testovací článek.</p>', '".time()."', '".time()."', '1', '1', '', '', '')", $dbserver);

$config=fopen("config.php", "w+");
$data="<?php
\$dbserver=mysql_connect(\"".$_POST["db_server"]."\", \"".$_POST["db_login"]."\", \"".$_POST["db_password"]."\");
\$dbname=\"".$_POST["db_name"]."\";
mysql_select_db(\"\$dbname\", \$dbserver);
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 $sql10 AND $sql11 AND $sql12 AND $sql13) {
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>Instalace (Installation)</h2>

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

<div><strong>Databázový server (Database server):</strong><br />
<input type="text" name="db_server" style="width: 200px;" value="<?php echo($_POST["db_server"]); ?>"<?php if ($submit!="" AND $_POST["db_server"]=="") { echo " class=\"input-error\""; } ?> /><br />
<strong>Přihlašovací jméno (Login name):</strong><br />
<input type="text" name="db_login" style="width: 200px;" value="<?php echo($_POST["db_login"]); ?>"<?php if ($submit!="" AND $_POST["db_login"]=="") { echo " class=\"input-error\""; } ?> /><br />
<strong>Heslo (Password):</strong><br />
<input type="text" name="db_password" style="width: 200px;" value="<?php echo($_POST["db_password"]); ?>"<?php if ($submit!="" AND $_POST["db_password"]=="") { echo " class=\"input-error\""; } ?> /><br />
<strong>Jméno databáze (Database name):</strong><br />
<input type="text" name="db_name" style="width: 200px;" value="<?php echo($_POST["db_name"]); ?>"<?php if ($submit!="" AND $_POST["db_name"]=="" AND $_POST["db_new"]==0) { echo " class=\"input-error\""; } ?> /><br />
<input type="radio" name="db_new" value="0"<?php if ($_POST["db_new"]!=1) { echo " checked=\"checked\""; } ?> /> Použít existující databázi (Use existing database)<br />
<input type="radio" name="db_new" value="1"<?php if ($_POST["db_new"]==1) { echo " checked=\"checked\""; } ?> /> Vytvořit novou databázi (Create new database)</div>

<div><strong>Jazyk systému (System language):</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]==$lang) { echo " selected=\"selected\""; }
echo ">$lang_name</option>\n";
}
}
?>
</select>
</div>

<div><input type="submit" name="submit" value="Instalovat (Install)" /></div>

</form>

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

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

$sql1=mysql_query("UPDATE kcms_variables SET value='$version' WHERE variable='version'", $dbserver);

$sql2=mysql_query("INSERT INTO kcms_variables values ('show_news_box', '1')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('show_promo_box', '1')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('news_box_items', '5')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('promo_box_items', '5')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('show_infolane', '1')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('show_sitename', '1')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('header_wallpaper', '')", $dbserver);
$sql2=mysql_query("INSERT INTO kcms_variables values ('header_wallpaper_height', '')", $dbserver);

$sql3=mysql_query("ALTER TABLE kcms_sections ADD outlink TEXT NOT NULL;", $dbserver);

if ($sql1 AND $sql2 AND $sql3) {
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=mysql_query("SELECT value FROM kcms_variables WHERE variable='version'");
$old_version=mysql_fetch_array($old_version);
?>

<h2>Aktualizace (Update) K:CMS <?php echo($prev_version); ?> &rarr; <?php echo($version); ?></h2>

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

<div><strong>Ověření verzí (Check versions):</strong><br />
Aktuálně nainstalovaná verze (currently installed version): <strong><?php echo($old_version["value"]); ?></strong><br />
Požadovaná verze (requested version): <strong><?php echo($prev_version); ?></strong></div>

<div class="a-center"><strong><?php if ($old_version["value"]==$prev_version) { echo "Můžete aktualizovat. (You can update.)"; } else { echo "Aktualizace této verze není možná! (You can't update this version!)"; } ?></strong></div>

<?php if ($old_version["value"]==$prev_version): ?><div><input type="submit" name="submit" value="Aktualizovat (Update)" /></div><?php endif; ?>

</form>

<?php
endif;
if ($mod=="uninstall"):

// mažeme...
if ($submit!="") {

if ($opt==1) {
$sql=mysql_query("DROP DATABASE $dbname;", $dbserver);
if ($sql) {
echo "<div class=\"popup-success\">KCMS byl úspěšně smazán!<br />KCMS was successfully deleted!</div>";
} else {
echo "<div class=\"popup-error\">Při odinstalaci došlo k chybě!<br />An error occured while unistalling!</div>";
}
}

if ($opt==2) {
$sql=mysql_query("DROP TABLE kcms_articles, kcms_comments, kcms_files, kcms_images, kcms_images_sections, kcms_sections, kcms_users, kcms_variables;", $dbserver);
if ($sql) {
echo "<div class=\"popup-success\">KCMS byl úspěšně smazán!<br />KCMS was successfully deleted!</div>";
} else {
echo "<div class=\"popup-error\">Při odinstalaci došlo k chybě!<br />An error occured while unistalling!</div>";
}
}

}
?>

<h2>Odinstalace (Uninstallation)</h2>

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

<div><strong>Možnosti (Options):</strong><br />
<input type="radio" name="opt" value="1" checked="checked" /> Smazat celou databázi (Completely delete database)<br />
<input type="radio" name="opt" value="2" /> Smazat pouze tabulky, zachovat databázi (Delete tables only, keep database)</div>

<div><input type="submit" name="submit" value="Odinstalovat (Uninstall)" /></div>

</form>

<?php
endif;
?>

</div>

<div class="cb"><!-- --></div>

</div>

<p class="footer">

<?php echo "Powered by <a href=\"http://www.matl-soft.cz/k-cms/\">K:CMS</a> v$version, &copy; 2008 Stepan Matl.\n\n"; ?></p>

</body>
</html>