<?php

// -----------------------------------------------------------------
// tady můžete nastavit práva (1 - 3)
// here you can set the rights (1 - 3)
if ($rights>=1):
// -----------------------------------------------------------------

if ($submit!="") {

$old_quick=mysql_query("SELECT quick FROM kcms_articles WHERE id='".addslashes($id)."'");
$old_quick=mysql_fetch_array($old_quick);

if ($old_quick["quick"]!=$article_link) {

$check=mysql_query("SELECT id FROM kcms_articles WHERE quick='".addslashes($article_link)."'");
$check=mysql_fetch_array($check);

}

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

if ($article_title!="" AND $article_link!="" AND $section!="" AND $article_type!="") {

include "formater.php";

if ($pereximg=="/gallery/") { $pereximg=""; }

if ($rights>=2) { $secure=""; } else { $secure=" AND author='".$_COOKIE["user_id"]."'"; }

$save=mysql_query("UPDATE kcms_articles SET quick='$article_link',
title='".addslashes($article_title)."',
type='".addslashes($article_type)."',
hp='".addslashes($hp)."',
complete='".addslashes($complete)."',
discussion='".addslashes($discussion)."',
section='".addslashes($section)."',
perex='".addslashes($perex)."',
text='".addslashes($text)."',
edited='".time()."',
pereximg='".addslashes($pereximg)."' WHERE id='".addslashes($id)."'$secure", $dbserver);

if ($confirmed==1 AND $rights>1) {

$save=mysql_query("UPDATE kcms_articles SET confirmed='1' WHERE id='".addslashes($id)."'", $dbserver);

}

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

}

} else {

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

}

}

$article=mysql_query("SELECT quick, title, type, hp, complete, confirmed, discussion, section, perex, text, added, published, author, publisher, edited, pereximg, views FROM kcms_articles WHERE id='".addslashes($id)."'");
$article=mysql_fetch_array($article);

$section=mysql_query("SELECT quick FROM kcms_sections WHERE id='".$article["section"]."'");
$section=mysql_fetch_array($section);

include "deformater.php";

?>

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

<script type="text/javascript">
/* <![CDATA[ */
function generateLink() {
var data = document.getElementById("article_title").value;
!window.open("./components/generate_link.php?article_title=" + data, "generate_link", "width=1,height=1,left=0,top=0");
return false;
}
document.write('<iframe frameborder="0px" name="generate_link" src="" style="display: none;"></iframe>');
/* ]]> */
</script>

<form action="./admin.php?f=edit_article&amp;id=<?php echo($id); ?>" method="post">

<div>
<table>
<tr>
<td><strong><?php echo($lang_form_article_title); ?>:</strong>
<br />
<input type="text" name="article_title" id="article_title" value="<?php echo (stripslashes($article["title"])); ?>" style="width: 300px;"<?php if ($submit!="" AND $_POST["article_title"]=="") { echo " class=\"input-error\""; } ?> /> <input type="button" value="-&gt;" onclick="return !openWindow('/<?php echo($section["quick"]); ?>/<?php echo($article["quick"]); ?>/');" />
<br />
<strong><?php echo($lang_form_generated_link); ?>:</strong>
<br />
<input type="text" name="article_link" id="article_link"  value="<?php echo ($article["quick"]); ?>" style="width: 300px;"<?php if ($submit!="" AND $_POST["article_link"]=="") { echo " class=\"input-error\""; } ?> /> <input type="button" value="<?php echo($lang_button_generate); ?>" onclick="generateLink();" /></td>
<td><strong><?php echo($lang_form_section); ?>:</strong><?php if ($submit!="" AND $_POST["section"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br />
<select name="section" style="width: 200px;">
<option value="">...</option>
<?php

$print=mysql_query("SELECT id, name FROM kcms_sections ORDER by id");
while (list($id, $name) = mysql_fetch_row($print)) {
echo "<option value=\"$id\"";

if ($article["section"]==$id) { echo " selected=\"selected\""; }

echo ">$name</option>\n";
}

?>
</select></td>
</tr>
</table>
</div>

<div><?php echo("<strong>$lang_form_create_date:</strong> ".date("d.m.Y, H:i", $article["added"])."<br /><strong>$lang_form_release_date:</strong> ");

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

if ($article["published"]==0) { echo (strtolower($lang_form_not_published_yet)); } else { echo (date("d.m.Y, H:i", $article["published"])." (".$publisher["login"].") <input type=\"button\" value=\"$lang_button_edit\" onclick=\"parent.location='./admin.php?f=publish_articles&amp;f2=publish&amp;id=".$_GET["id"]."';\" />"); }
echo "<br /><strong>$lang_form_last_editation:</strong> ";
if ($article["edited"]==0) { echo (strtolower($lang_form_not_edited_yet)); } else { echo (date("d.m.Y, H:i", $article["edited"])); } echo "<br /><strong>$lang_index_viewed:</strong> ".$article["views"]."×"; ?></div>

<div>
<strong><?php echo($lang_form_properties); ?>:</strong>
<br />
<table>
<tr>
<td><input type="radio" name="article_type" value="1"<?php if ($article["type"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_news); ?></td>
<td><input type="checkbox" name="hp" value="1"<?php if ($article["hp"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_show_on_homepage); ?></td>
</tr>
<tr>
<td><input type="radio" name="article_type" value="2"<?php if ($article["type"]==2) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_standard_article); ?></td>
<td><input type="checkbox" name="complete" value="1"<?php if ($article["complete"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_article_is_complete); ?></td>
</tr>
<tr>
<td><input type="radio" name="article_type" value="3"<?php if ($article["type"]==3) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_promo_article); ?></td>
<td><?php if ($rights>1): ?><input type="checkbox" name="confirmed" value="1"<?php if ($article["confirmed"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_article_is_confirmed); ?><?php else: echo "&nbsp;"; endif; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="discussion" value="1"<?php if ($article["discussion"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_allow_discussion); ?></td>
</tr>
</table>
</div>

<div>
<strong><?php echo($lang_form_perex_image); ?>:</strong>
<br />
<input type="text" name="pereximg" value="<?php if ($submit!="") { echo ($_POST["pereximg"]); } else { if ($article["pereximg"]=="") { echo "/gallery/"; } else { echo ($article["pereximg"]); } } ?>" style="width: 300px;" /><br /><strong><?php echo($lang_form_perex); ?>:</strong><br /><textarea name="perex" cols="" rows="" style="width: 700px; height: 100px;"><?php echo ($perex); ?></textarea>
</div>

<div><strong><?php echo($lang_form_text); ?>:</strong><br />

<script src="./components/formater.js" type="text/javascript"></script>

<?php include "formater_buttons.php"; ?>

<textarea name="text" id="text" cols="" rows="" style="width: 700px; height: 300px;"><?php echo ($text); ?></textarea></div>

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

</form>

<?php else: $access_denied=1; endif; ?>