<?php

include "config.php";

if ($link!="") {

$link=explode("/", $link);

// profiles/ -

if (ereg("^profiles$", $link[0]) AND ereg("^[a-zA-Z0-9\-]*$", $link[1])) {
$f="profile";
$user=$link[1];
}

// galleries/ -

if (ereg("^galleries$", $link[0]) AND ereg("^[a-z0-9\-]*$", $link[1])) {
$f="gallery";
$g=$link[1];
}

// signup/

if (ereg("^signup$", $link[0]) AND $link[1]=="") {
$f="signup";
}

// search/

if (ereg("^search$", $link[0]) AND $link[1]=="") {
$f="search";
}

// settings/

if (ereg("^settings$", $link[0]) AND $link[1]=="") {
$f="settings";
}

// sections/

if (ereg("^[a-z0-9\-]*$", $link[0]) AND $link[1]=="") {
$s=$link[0];
}

// section/article/

if (ereg("^[a-z0-9\-]*$", $link[0]) AND ereg("^[a-z0-9\-]*$", $link[1])) {
$s=$link[0];
$a=$link[1];
}

// section/page/

if (ereg("^[a-z0-9\-]*$", $link[0]) AND ereg("^[0-9]*$", $link[1])) {
$s=$link[0];
$page=$link[1];
$a="";
}

}

// loading variables...
$sql=mysql_query("SELECT * FROM kcms_variables");
while($item=mysql_fetch_array($sql)) {
${$item["variable"]}=stripslashes(${$item["variable"]}=$item["value"]);
${$item["variable"]}=str_replace("&", "&amp;", ${$item["variable"]}=$item["value"]);
}

include ("languages/".$lang.".php");

if ($s!="") {
$section=mysql_query("SELECT id, name FROM kcms_sections WHERE quick='".addslashes($s)."'");
$section=mysql_fetch_array($section);
$where="section='".$section["id"]."' AND published!='0' AND published<='".time()."'";
$count=mysql_query("SELECT COUNT(*) AS id FROM kcms_articles WHERE $where");
$count=mysql_fetch_array($count);
} else {
$where="hp='1' AND published!='0' AND published<='".time()."'";
}

if ($count["id"]==1 OR $a!="") {
if ($count["id"]==1) { $where2="section='".$section["id"]."'"; }
if ($a!="") { $where2="quick='".addslashes($a)."'"; }
$article=mysql_query("SELECT id, quick, title, type, discussion, perex, text, published, author, pereximg, views FROM kcms_articles WHERE $where2");
$article=mysql_fetch_array($article);
$article_id=$article["id"];
if ($_COOKIE["viewed_".$article_id]!=1) {
$views=$article["views"]+1;
$sql=mysql_query("UPDATE kcms_articles SET views='".addslashes($views)."' WHERE id='".$article["id"]."'", $dbserver);
setcookie("viewed_".$article["id"], "1");
} else {
$views=$article["views"];
}
}

if ($submit!="" AND $nick!="" AND $text!="" AND $web=="") {
setcookie("posted_comment", $text);
}

if ($submit_login!="") {
if ($login!="" AND $password!="") {
$check=mysql_query("SELECT id FROM kcms_users WHERE login='".addslashes($_POST["login"])."' AND password='".SHA1(addslashes($_POST["password"]))."'");
$check=mysql_fetch_array($check);
if ($check["id"]!="") {
setcookie("user_id", $check["id"]);
$sql=mysql_query("UPDATE kcms_users SET lastvisit='".time()."' WHERE login='".addslashes($_POST["login"])."'", $dbserver);
header("Location: /");
}
}
}

if ($_COOKIE["user_id"]!="") {
$userinfo=mysql_query("SELECT login, rights FROM kcms_users WHERE id='".$_COOKIE["user_id"]."'");
$userinfo=mysql_fetch_array($userinfo);
if ($userinfo["rights"]=="") { $rights=0; } else { $rights=$userinfo["rights"]; }
}

?>
<!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="<?php echo ($lang); ?>" lang="<?php echo ($lang); ?>">
<head>
<meta name="Author" content="K:CMS system v<?php echo ($version); ?>, (c) <?php echo(date("Y")); ?> Štěpán Mátl (http://khamos.wz.cz)" />
<meta name="Copyright" content="<?php echo ($meta_copyright); ?>" />
<meta name="Keywords" content="<?php if ($article["id"]=="") { echo ($meta_keywords); } else { $keywords=str_replace(" ", ", ", $article["title"]); $keywords=str_replace("-, ", "", $keywords); $keywords=str_replace("!", "", $keywords); $keywords=str_replace("?", "", $keywords); $keywords=str_replace(":", "", $keywords);  $keywords=str_replace("\"", "", stripslashes($keywords)); echo (strtolower($keywords)); } ?>" />
<meta name="Robots" content="index, follow" />
<meta name="Description" content="<?php if ($article["id"]=="") { echo ($meta_desc); } else { echo (htmlspecialchars(stripslashes($article["title"]))." - "); if ($article["perex"]!="") { echo (htmlspecialchars(stripslashes(strip_tags($article["perex"])))); } else { mb_internal_encoding("utf-8"); $desc=mb_strcut(strip_tags($article["text"]), 0, 240); $desc=trim($desc, "."); $desc=trim($desc, "?"); $desc=trim($desc, "!"); $desc.="..."; } echo (htmlspecialchars(stripslashes($desc))); } ?>" />
<meta http-equiv="Content-language" content="<?php echo ($lang); ?>" />
<meta http-equiv="Cache-control" content="public" />
<meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
<link rel="Stylesheet" href="/styles/<?php echo ($theme); ?>.css" type="text/css" />
<link rel="Shortcut icon" href="/components/images/favicon.ico" type="image/x-icon" />
<link rel="Icon" href="/components/images/favicon.ico" type="image/x-icon" />
<title><?php if ($f=="") { if ($section["name"]=="") { echo "$lang_homepage"; } else { echo ($section["name"]); } if ($a!="") { echo (" - ".stripslashes($article["title"])); } } if ($f=="signup") { echo "$lang_index_signup"; } if ($f=="profile") { echo "$lang_index_profile $user"; } if ($f=="settings") { echo "$lang_index_personal_settings"; } if ($f=="search") { echo "$lang_index_searching_of \"".$_POST["search"]."\""; } ?> - <?php echo ($sitename); ?></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"><?php echo ($sitename); ?></div>
<h1><?php if ($f=="") { if ($section["name"]=="") { echo "$lang_homepage"; } else { echo ($section["name"]); } if ($a!="") { echo (" - ".stripslashes($article["title"])); } } if ($f=="signup") { echo "$lang_index_signup"; } if ($f=="profile") { echo "$lang_index_profile $user"; } if ($f=="settings") { echo "$lang_index_personal_settings"; } if ($f=="search") { echo "$lang_index_searching_of \"".$_POST["search"]."\""; } ?></h1>

<div class="main">

<div class="left-column">

<div class="menu-title"><?php echo($lang_sections); ?></div>

<ul>
<li><a href="/"><?php echo ($lang_homepage); ?></a></li>
<?php
if ($sort_sections_by_name==1) { $sort_sections="name"; } else { $sort_sections="id"; }
$print=mysql_query("SELECT quick, name, highlight FROM kcms_sections ORDER by $sort_sections");
while (list($quick, $name, $highlight) = mysql_fetch_row($print)) {
echo "<li><a href=\"/$quick/\">";
if ($highlight==1) { echo "<strong>"; }
echo "$name";
if ($highlight==1) { echo "</strong>"; }
echo "</a></li>\n";
}
?>
</ul>

<?php
$count=mysql_query("SELECT COUNT(*) AS id FROM kcms_images_sections WHERE public='1' ORDER by name");
$count=MySQL_Fetch_Array($count);
if ($count["id"]>0):
?>

<div class="menu-title"><?php echo($lang_index_gallery); ?></div>

<ul>
<?php
$print=mysql_query("SELECT quick, name FROM kcms_images_sections WHERE public='1' ORDER by name");
while (list($quick, $name) = mysql_fetch_row($print)) {
echo "<li><a href=\"/galleries/$quick/\">$name</a></li>\n";
}
?>
</ul>

<?php endif; ?>

<?php echo(stripslashes($left_column)."\n\n"); ?></div>

<div class="center-column">

<?php
// alerts
if ($submit_login!="") {
if ($login=="" OR $password=="") {
echo "<div class=\"popup-error\">$lang_alert_empty_inputs</div>";
}
if ($check["id"]=="") {
echo "<div class=\"popup-error\">$lang_alert_bad_username_or_password</div>";
}
}
?>

<?php

if ($f=="") {
if ($article["id"]=="") {
if ($page=="") {
$page=1;
$skip=0;
}
else {
$skip=$page*$articles_number-$articles_number;
}

$pages=MySQL_Query("SELECT COUNT(*) AS id FROM kcms_articles WHERE $where");
$pages=MySQL_Fetch_Array($pages);
$pages=ceil($pages["id"]/$articles_number);

$print=mysql_query("SELECT id, quick, title, discussion, section, type, perex, text, author, published, pereximg, views FROM kcms_articles WHERE $where ORDER by published DESC, type DESC LIMIT $skip,$articles_number");
while (list($id, $quick, $title, $discussion, $section, $type, $perex, $text, $author, $published, $pereximg, $views) = mysql_fetch_row($print)) {

include "components/print_articles.php";

}

if ($s!="") {

echo "<div class=\"paging\">";

if ($pages>1 AND $page>1) {
$i=$page-1;
echo "<input type=\"button\" onclick=\"parent.location='/$s/$i/'\" value=\"&lt;\" /> ";
}
$i=0;
echo "$lang_form_showing_page_number <select onchange=\"parent.location='/$s/' + options[this.selectedIndex].value; + '/'\">\n";

while ($i<$pages) {
$i++;
echo "<option value=\"$i\"";
if ($page==$i) { echo " selected=\"selected\""; }
echo ">$i</option>\n";
}
echo "</select>\n";

if ($pages>1 AND $page<$pages) {
$i=$page+1;
echo " <input type=\"button\" onclick=\"parent.location='/$s/$i/'\" value=\"&gt;\" />";
}

echo "</div>";

}

} else {

if ($article["perex"]!="") {
echo "<p><em>";
if ($article["pereximg"]!="") { echo "<img src=\"".$article["pereximg"]."\" alt=\"".$article["title"]."\" class=\"perex-img\" />"; }
echo (stripslashes($article["perex"]));
if ($article["pereximg"]!="") { echo "<span class=\"cb2\"><!-- --></span>"; }
echo "</em></p>\n\n";

}

echo "<p class=\"article-info\">";

if (date("d.m.Y", $article["published"])==date("d.m.Y", time())) { echo ($lang_index_today." ".date("(G:i)", $article["published"])); } elseif (date("d.m.Y", $article["published"])==date("d.m.Y", time()-86400)) { echo ($lang_index_yesterday." ".date("(G:i)", $article["published"])); } elseif ($article["published"]==0) { echo ($lang_form_not_published_yet); } else { echo (date("d.m.Y (G:i)", $article["published"])); }

$author=mysql_query("SELECT login FROM kcms_users WHERE id='".$article["author"]."'");
$author=mysql_fetch_array($author);

$count_comments=mysql_query("SELECT COUNT(*) AS id FROM kcms_comments WHERE article='".$article["id"]."' ORDER by id DESC");
$count_comments=mysql_fetch_array($count_comments);

echo ", <a href=\"/profiles/".$author["login"]."/\">".$author["login"]."</a>, <a href=\"/$s/\">".$section["name"]."</a>, $lang_index_commented ".$count_comments["id"]."×, ".strtolower($lang_index_viewed)." ".$views."×</p>\n\n";

echo (stripslashes($article["text"]));

echo "\n\n<p class=\"discussion\">";
if ($article["discussion"]==0) { echo "$lang_index_discussion_is_not_allowed_for_this_article</p>\n\n";  } else {
echo "$lang_index_discussion_for_the_article ".stripslashes($article["title"]).":</p>\n\n";
if ($submit!="") {
if ($nick!="" AND $text!="" AND $web=="") {
if ($_COOKIE["posted_comment"]!=$text) {
if ($_COOKIE["user_id"]!="") { $registered_user=1; $nick=$_COOKIE["user_id"]; } else { $registered_user=0; }
$nick=strip_tags($nick);
$nick=addslashes($nick);
$text=strip_tags($text);
$text=str_replace("\r\n", "<br />", $text);
$text=addslashes($text);
$sql=mysql_query("INSERT INTO kcms_comments values ('', '".$article["id"]."', '".time()."', '$nick', '$text', '0', '$registered_user')", $dbserver);
echo "<div class=\"popup-success\">$lang_alert_success</div>";

}

} else {

echo "<div class=\"popup-error\">$lang_alert_empty_inputs</div>";

}

}

$i=0;
$print=mysql_query("SELECT id, article, added, author, text, user FROM kcms_comments WHERE article='".$article["id"]."' ORDER by added");
while (list($id, $article, $added, $author, $text, $user) = mysql_fetch_row($print)) {

$i++;

if ($user==1) {

$author=mysql_query("SELECT login FROM kcms_users WHERE id='$author'");
$author=mysql_fetch_array($author);

}

echo "<div class=\"comment-line\"><div class=\"cl-left\"><span>$i.</span> ";
if ($user==1) { echo "<a href=\"/profiles/".$author["login"]."/\">".$author["login"]."</a>"; } else { echo (stripslashes($author)); }

echo "</div><div class=\"cl-right\">".date("j.n.Y [G:i]", $added)."</div>\n\n<div class=\"cb2\"><!-- --></div>\n\n</div>\n\n<p class=\"comment-text\">".stripslashes($text)."</p>\n\n";

}

if ($i==0) { echo "<p><em>$lang_index_this_article_wasnt_commented_yet</em></p>\n\n"; }

echo "<p class=\"discussion\">$lang_index_add_comment:</p>\n\n";

if ($login_for_comments==1) {

echo "<p>$lang_index_you_must_be_logged_in</p>\n\n";

} else {

echo "<form action=\"/$s/$a/\" method=\"post\">

<div><strong>Nick:</strong><br /><input type=\"text\" name=\"nick\" value=\"";
if ($userinfo["login"]=="") { echo ($_POST["nick"]); } else { echo ($userinfo["login"]); }
echo "\" style=\"width: 150px;\"";
if ($submit!="" AND $_POST["nick"]=="") { echo " class=\"input-error\""; }
echo " /><br /><strong>$lang_form_text:</strong><br /><textarea name=\"text\" cols=\"\" rows=\"\" style=\"height: 50px; width: 400px;\"";
if ($submit!="" AND $_POST["text"]=="") { echo " class=\"input-error\""; }
echo ">".$_POST["text"]."</textarea><br /><input type=\"text\" name=\"web\" value=\"\" style=\"display: none;\" /><input type=\"submit\" name=\"submit\" value=\"$lang_button_save\" /></div>

</form>\n\n";

}

}

}

}

if ($f=="signup"):

if ($submit!="") {

$check=mysql_query("SELECT id FROM kcms_users WHERE login='".$_POST["login"]."'");
$check=mysql_fetch_array($check);

if ($check["id"]=="") {

if ($_POST["login"]!="" AND preg_match("/^[0-9a-zA-Z]{3,128}$/", $_POST["login"]) AND $_POST["password"]!="") {

$sql=mysql_query("INSERT INTO kcms_users values ('', '".addslashes($_POST["login"])."', '".SHA1(addslashes($_POST["password"]))."', '0', '', '', '', '', '', '', '".time()."', '')", $dbserver);

echo "<div class=\"popup-success\">$lang_alert_success</div>";

} else {

echo "<div class=\"popup-error\">$lang_alert_empty_inputs";

if (preg_match("/^[0-9a-zA-Z]{3,128}$/", $_POST["login"])==0) { echo ("<br />".$lang_alert_bad_format); }

echo "</div>";

}

} else {

echo "<div class=\"popup-error\">$lang_alert_existing_user</div>";

}

}

?>

<form action="/signup/" method="post">

<div><strong><?php echo "$lang_form_choose_username"; ?>:</strong><br /><input type="text" name="login" style="width: 200px;" value="<?php echo ($_POST["login"]); ?>"<?php if ($submit!="" AND $_POST["login"]=="") { echo " class=\"input-error\""; } ?> /> <?php echo "$lang_form_reg_allowed_characters"; ?><br />
<strong><?php echo "$lang_form_choose_password"; ?>:</strong><br /><input type="password" name="password" style="width: 200px;" value="<?php echo ($_POST["password"]); ?>"<?php if ($submit!="" AND $_POST["password"]=="") { echo " class=\"input-error\""; } ?> /> <input type="submit" name="submit" value="<?php echo "$lang_button_signup"; ?>" /></div>

</form>

<?php
endif;
if ($f=="profile"):
$userinfo=mysql_query("SELECT id, login, rights, age, jabber, skype, about, mail, realname, regdate, lastvisit FROM kcms_users WHERE login='$user'");
$userinfo=mysql_fetch_array($userinfo);
function safe_address($data) {
$data=str_replace("@", " (@) ", $data);
$data=str_replace(".", " (.) ", $data);
return ($data);
}
?>

<?php if ($userinfo["id"]==""): ?>

<h2><?php echo ($lang_index_this_user_does_not_exist); ?></h2>

<?php else: ?>

<h2><?php echo ($lang_index_registration_data); ?></h2>

<p><strong>ID:</strong> <?php echo ("#".$userinfo["id"]); ?></p>

<p><strong><?php echo ($lang_form_user); ?>:</strong> <?php echo ($user); ?></p>

<p><strong><?php echo ($lang_form_registration_date); ?>:</strong> <?php echo (date("j. n. Y", $userinfo["regdate"])); ?></p>

<h2><?php echo ($lang_index_user_info); ?></h2>

<p><strong><?php echo ($lang_form_last_visit); ?>:</strong> <?php echo (date("j. n. Y, H:i", $userinfo["lastvisit"])); ?></p>

<?php if ($userinfo["realname"]!="") { echo "<p><strong>$lang_form_real_name:</strong> ".$userinfo["realname"]."</p>"; } ?>

<?php if ($userinfo["age"]!="") { echo "<p><strong>$lang_form_age:</strong> ".$userinfo["age"]."</p>"; } ?>

<p><strong><?php echo ($lang_form_rights); ?>:</strong> <?php if ($userinfo["rights"]==0) { echo ($lang_form_member); } if ($userinfo["rights"]==1) { echo ($lang_form_admin1); } if ($userinfo["rights"]==2) { echo ($lang_form_admin2); } if ($userinfo["rights"]==3) { echo ($lang_form_admin3); } ?></p>

<?php if ($userinfo["about"]!="") { echo "<p><strong>$lang_form_about_me:</strong> ".stripslashes($userinfo["about"])."</p>"; } ?>

<h2><?php echo ($lang_index_contact); ?></h2>

<?php if ($userinfo["mail"]!="") { echo "<p><strong>$lang_form_mail:</strong> ".safe_address($userinfo["mail"])."</p>"; } ?>

<?php if ($userinfo["jabber"]!="") { echo "<p><strong>$lang_form_jabber:</strong> ".safe_address($userinfo["jabber"])."</p>"; } ?>

<?php if ($userinfo["skype"]!="") { echo "<p><strong>$lang_form_skype:</strong> ".$userinfo["skype"]."</p>"; } ?>

<?php
endif;
endif;

if ($f=="settings"):

if ($submit_personal_settings!="") {

if ($_POST["username"]!="" AND preg_match("/^[0-9a-zA-Z]{3,128}$/", $_POST["username"])) {

$about=str_replace("\r\n", "<br />", $_POST["about"]);
$about=str_replace("&", "&amp;", $_POST["about"]);

$sql=mysql_query("UPDATE kcms_users SET
realname='".addslashes($_POST["realname"])."',
age='".addslashes($_POST["age"])."',
about='".addslashes($about)."',
mail='".addslashes($_POST["mail"])."',
jabber='".addslashes($_POST["jabber"])."',
skype='".addslashes($_POST["skype"])."'
WHERE id='".$_COOKIE["user_id"]."'", $dbserver);

if ($_POST["password"]!="") {
$sql=mysql_query("UPDATE kcms_users SET password='".addslashes(SHA1($_POST["password"]))."' WHERE id='".$_COOKIE["user_id"]."'", $dbserver);
}

echo "<div class=\"popup-success\">$lang_alert_success</div>";

} else {

echo "<div class=\"popup-error\">$lang_alert_empty_inputs";

if (preg_match("/^[0-9a-zA-Z]{3,128}$/", $_POST["username"])==0) { echo ("<br />".$lang_alert_bad_format); }

echo "</div>";

}

$old_username=mysql_query("SELECT login FROM kcms_users WHERE id='".$_COOKIE["user_id"]."'");
$old_username=mysql_fetch_array($old_username);

if ($old_username["login"]!=$_POST["username"]) {

$check=mysql_query("SELECT id FROM kcms_users WHERE login='".addslashes($_POST["username"])."'");
$check=mysql_fetch_array($check);

if ($check["id"]=="") {

$sql=mysql_query("UPDATE kcms_users SET login='".addslashes($_POST["username"])."' WHERE id='".$_COOKIE["user_id"]."'", $dbserver);

} else {

echo "<div class=\"popup-error\">$lang_alert_existing_user</div>";

}

}

}

$userinfo=mysql_query("SELECT login, age, jabber, skype, about, mail, realname FROM kcms_users WHERE id='".$_COOKIE["user_id"]."'");
$userinfo=mysql_fetch_array($userinfo);

$about=str_replace("<br />", "\r\n", $userinfo["about"]);

?>

<form action="/settings/" method="post">

<div><strong><?php echo "$lang_form_user"; ?>:</strong><br /><input type="text" name="username" style="width: 200px;" value="<?php echo ($userinfo["login"]); ?>"<?php if ($submit_personal_settings!="" AND $_POST["username"]=="") { echo " class=\"input-error\""; } ?> /> <?php echo "$lang_form_reg_allowed_characters"; ?></div>

<div><strong><?php echo "$lang_form_password"; ?>:</strong><br /><input type="password" name="password" style="width: 200px;" /> <?php echo "$lang_form_fill_only_if_you_want_to_change_it"; ?></div>

<div><strong><?php echo "$lang_form_real_name"; ?>:</strong><br /><input type="text" name="realname" style="width: 200px;" value="<?php echo ($userinfo["realname"]); ?>" /><br /><strong><?php echo "$lang_form_age"; ?>:</strong><br /><input type="text" name="age" style="width: 50px;" value="<?php echo ($userinfo["age"]); ?>" /><br /><strong><?php echo ($lang_form_about_me); ?>:</strong><br /><textarea name="about" cols="" rows="" style="height: 50px; width: 400px;"><?php echo (stripslashes($about)); ?></textarea></div>

<div><strong><?php echo "$lang_form_mail"; ?>:</strong><br /><input type="text" name="mail" style="width: 200px;" value="<?php echo ($userinfo["mail"]); ?>" /> <?php echo ($lang_form_this_item_will_be_spam_protected); ?><br /><strong><?php echo "$lang_form_jabber"; ?>:</strong><br /><input type="text" name="jabber" style="width: 200px;" value="<?php echo ($userinfo["jabber"]); ?>" /> <?php echo ($lang_form_this_item_will_be_spam_protected); ?><br /><strong><?php echo "$lang_form_skype"; ?>:</strong><br /><input type="text" name="skype" style="width: 200px;" value="<?php echo ($userinfo["skype"]); ?>" /></div>

<div><input type="submit" name="submit_personal_settings" value="<?php echo "$lang_button_save"; ?>" /></div>

</form>

<?php

endif;

if ($f=="search"):
$i=0;
$print=mysql_query("SELECT id, quick, title, discussion, section, type, perex, text, author, published, pereximg, views, MATCH (title, perex, text) AGAINST ('".addslashes($_POST["search"])."' IN BOOLEAN MODE) AS score1, ((2*(MATCH (title) AGAINST ('".addslashes($_POST["search"])."'))) + (MATCH (perex) AGAINST ('".addslashes($_POST["search"])."')) + (MATCH (text) AGAINST ('".addslashes($_POST["search"])."'))) AS score2 FROM kcms_articles WHERE published!='0' AND published<='".time()."' HAVING score1 > 0 ORDER BY score1 DESC, score2 DESC, published DESC, type DESC");
while (list($id, $quick, $title, $discussion, $section, $type, $perex, $text, $author, $published, $pereximg, $views) = mysql_fetch_row($print)) {

$i++;
include "components/print_articles.php";

}

if ($i==0) { echo "<h2>$lang_index_no_results.</h2>"; }
endif;
if ($f=="gallery"):

$gallery=mysql_query("SELECT id, name FROM kcms_images_sections WHERE quick='".addslashes($g)."' AND public='1'");
$gallery=mysql_fetch_array($gallery);

?>

<table>
<tr>
<th colspan="6" class="table-title"><?php echo($gallery["name"]); ?></th>
</tr>
<tr>
<th><?php echo($lang_form_thumbnail); ?></th>
<th><?php echo($lang_form_informations); ?></th>
<th><?php echo($lang_form_thumbnail); ?></th>
<th><?php echo($lang_form_informations); ?></th>
</tr>
<?php

$i=0;
$i2=0;
$count=mysql_query("SELECT COUNT(*) AS id FROM kcms_images WHERE section='".$gallery["id"]."'");
$count=mysql_fetch_array($count);
$print=mysql_query("SELECT id, file, added FROM kcms_images WHERE section='".$gallery["id"]."' ORDER by added DESC");
while (list($id, $file, $added) = mysql_fetch_row($print)) {
if ($i==0) { echo "<tr>\n"; }
$i++;
$i2++;
$filename=explode(".", $file);
if ($filename[1]=="jpg") {
$img_data=imagecreatefromjpeg("./gallery/$file");
}
if ($filename[1]=="png") {
$img_data=imagecreatefrompng("./gallery/$file");
}
if ($filename[1]=="gif") {
$img_data=imagecreatefromgif("./gallery/$file");
}
echo "<td><a href=\"/gallery/$file\"><img src=\"/gallery/thumbs/".$filename[0].".jpg\" alt=\"$file\" /></a></td>
<td>$file<span class=\"filedesc\">".date("d.m.Y G:i", $added)."<br />".imagesx($img_data)."×".imagesy($img_data)." px<br />".round(filesize("./gallery/$file")/1024)." kB</span></td>";
if ($i==2) { $i=0; echo "\n</tr>\n"; }
if ($i==1 AND $i2==$count["id"]) { echo "\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n"; }
}

?>
</table>

<?php
endif;
?>

</div>

<div class="right-column">

<div class="menu-title"><?php echo($lang_index_account); if ($_COOKIE["user_id"]!="") { echo (" (".$userinfo["login"].")"); } ?></div>

<?php
if ($_COOKIE["user_id"]==""):
?>

<form action="/" method="post">

<div class="a-right"><strong><?php echo "$lang_form_user"; ?>:</strong> <input type="text" name="login" style="width: 100px;"<?php if ($submit_login!="" AND $_POST["login"]=="") { echo " class=\"input-error\""; } ?> /><br /><strong><?php echo "$lang_form_password"; ?>:</strong> <input type="password" name="password" style="width: 100px;"<?php if ($submit_login!="" AND $_POST["password"]=="") { echo " class=\"input-error\""; } ?> /><br /><a href="/signup/"><?php echo "$lang_index_dont_have_an_account"; ?></a> <input type="submit" name="submit_login" value="<?php echo "$lang_button_login"; ?>" /></div>

</form>

<?php
else:
?>

<ul>
<?php if ($rights>0): ?><li><a href="/admin.php"><?php echo ($lang_administration); ?></a></li><?php endif; ?>
<li><a href="/profiles/<?php echo ($userinfo["login"]); ?>/"><?php echo ($lang_button_my_profile); ?></a></li>
<li><a href="/settings/"><?php echo ($lang_index_personal_settings); ?></a></li>
</ul>

<?php
endif;
?>

<div class="menu-title"><?php echo($lang_index_search); ?></div>

<form action="/search/" method="post">

<div class="a-center"><input type="text" name="search" style="width: 100px;" /> <input type="submit" value="<?php echo "$lang_index_search"; ?>" /></div>

</form>

<div class="menu-title"><?php echo($lang_index_news); ?></div>

<ul>
<?php
$i=0;
$print=mysql_query("SELECT quick, title, section FROM kcms_articles WHERE type='1' AND published!='0' AND published<='".time()."' ORDER by published DESC LIMIT 0,5");
while (list($quick, $title, $section) = mysql_fetch_row($print)) {

$i++;

$article_section=mysql_query("SELECT quick, name FROM kcms_sections WHERE id='$section'");
$article_section=mysql_fetch_array($article_section);

echo "<li><a href=\"/".$article_section["quick"]."/$quick/\">".stripslashes($title)."</a></li>";

}
if ($i==0) { echo "<li><!-- --></li>"; }
?>
</ul>

<div class="menu-title"><?php echo($lang_index_promo); ?></div>

<ul>
<?php
$i=0;
$print=mysql_query("SELECT quick, title, section FROM kcms_articles WHERE type='3' AND published!='0' AND published<='".time()."' ORDER by published DESC LIMIT 0,5");
while (list($quick, $title, $section) = mysql_fetch_row($print)) {

$i++;

$article_section=mysql_query("SELECT quick, name FROM kcms_sections WHERE id='$section'");
$article_section=mysql_fetch_array($article_section);

echo "<li><a href=\"/".$article_section["quick"]."/$quick/\"><strong>".stripslashes($title)."</strong></a></li>\n";

}
if ($i==0) { echo "<li><!-- --></li>"; }
?>
</ul>

<?php echo(stripslashes($right_column)."\n\n"); ?>

</div>

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

</div>

<p class="footer">

<?php echo($meta_copyright."<br />K:CMS system v$version, (c) ".date("Y")." <a href=\"http://khamos.wz.cz/k-cms/\">Štěpán Mátl</a>."); ?>

</p>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3791442-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>