<?php

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

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

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

$sql=mysql_query("INSERT INTO kcms_articles values ('',
'".addslashes($article_link)."',
'".addslashes($article_title)."',
'".addslashes($article_type)."',
'".addslashes($hp)."',
'".addslashes($complete)."',
'".addslashes($_POST["confirmed"])."',
'".addslashes($discussion)."',
'".addslashes($section)."',
'".addslashes($perex)."',
'".addslashes($text)."',
'".time()."',
'',
'".$_COOKIE["user_id"]."',
'',
'',
'".addslashes($pereximg)."',
'')", $dbserver);

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

$preview=1;

}

} else {

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

}

}

?>

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

<?php

if ($preview==1):

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

if ($_POST["article_type"]==1) { $properties=$lang_form_news; }
if ($_POST["article_type"]==2) { $properties=$lang_form_standard_article; }
if ($_POST["article_type"]==3) { $properties=$lang_form_promo_article; }
if ($_POST["hp"]==1) { $properties.=", ".$lang_form_show_on_homepage; }
if ($_POST["complete"]==1) { $properties.=", ".$lang_form_article_is_complete; }
if ($_POST["confirmed"]==1) { $properties.=", ".$lang_form_article_is_confirmed; }
if ($_POST["discussion"]==1) { $properties.=", ".$lang_form_allow_discussion; }

?>

<p><strong><?php echo($lang_form_article_title); ?>:</strong> <a href="/<?php echo ($section["quick"]); ?>/<?php echo ($article_link); ?>/" onclick="return !openWindow(this.href);"><?php echo (stripslashes($article_title)); ?></a>
<br />
<strong><?php echo($lang_form_generated_link); ?>:</strong> <?php echo ($article_link); ?>
<br />
<strong><?php echo($lang_form_section); ?>:</strong> <?php echo ($section["name"]); ?>
<br />
<strong><?php echo($lang_form_properties); ?>:</strong> <?php echo "$properties"; ?></p>

<?php else: ?>

<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=add_article" 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 (htmlspecialchars(stripslashes($_POST["article_title"]))); ?>" style="width: 300px;"<?php if ($submit!="" AND $_POST["article_title"]=="") { echo " class=\"input-error\""; } ?> />
<br />
<strong><?php echo($lang_form_generated_link); ?>:</strong>
<br />
<input type="text" name="article_link" id="article_link"  value="<?php echo ($_POST["article_link"]); ?>" 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 ($_POST["section"]==$id) { echo " selected=\"selected\""; }
echo ">$name</option>\n";
}
?>
</select></td>
</tr>
</table>
</div>

<div>
<strong><?php echo($lang_form_properties); ?>:</strong><?php if ($submit!="" AND $_POST["article_type"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br />
<table>
<tr>
<td><input type="radio" name="article_type" value="1"<?php if ($_POST["article_type"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_news); ?></td>
<td><input type="checkbox" name="hp" value="1"<?php if ($_POST["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 ($_POST["article_type"]==2) { echo " checked=\"checked\""; } ?> /> <?php echo($lang_form_standard_article); ?></td>
<td><input type="checkbox" name="complete" value="1"<?php if ($_POST["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 ($_POST["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 ($_POST["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 ($_POST["discussion"]==1 AND $submit!="" OR $_POST["discussion"]=="" AND $submit=="") { 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 { echo "/gallery/"; } ?>" style="width: 300px;" /><br /><strong><?php echo($lang_form_perex); ?>:</strong><br /><textarea name="perex" cols="" rows="" style="width: 700px; height: 100px;"><?php echo (stripslashes($_POST["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 (stripslashes($_POST["text"])); ?></textarea></div>

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

</form>

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