<?php
//---[CZ]: ověříme přístup
if ($login->check_access("add_content")==1):

//---[CZ]: načteme potřebné třídy
include CLASSES_PATH."Articles.php";
include CLASSES_PATH."Images.php";
include CLASSES_PATH."Files.php";
include CLASSES_PATH."Polls.php";
include CLASSES_PATH."Sections.php";

//---[CZ]: vytvoříme instance
$articles=new Articles();
$images=new Images();
$files=new Files();
$polls=new Polls();
$sections=new Sections();

//---[CZ]: definování proměnných
if (!isset($_POST["article_title"])) { $_POST["article_title"]=""; }
if (!isset($_POST["article_link"])) { $_POST["article_link"]=""; }
if (!isset($_POST["section"])) { $_POST["section"]=""; }
if (!isset($_POST["article_type"])) { $_POST["article_type"]=""; }
if (!isset($_POST["hp"])) { $_POST["hp"]=""; }
if (!isset($_POST["complete"])) { $_POST["complete"]=""; }
if (!isset($_POST["confirmed"])) { $_POST["confirmed"]=""; }
if (!isset($_POST["top"])) { $_POST["top"]=""; }
if (!isset($_POST["show_article_info"])) { $_POST["show_article_info"]=""; }
if (!isset($_POST["discussion"])) { $_POST["discussion"]=""; }
if (!isset($_POST["perex"])) { $_POST["perex"]=""; }
if (!isset($_POST["text"])) { $_POST["text"]=""; }
if (!isset($_POST["publish_now"])) { $_POST["publish_now"]=""; }
if (!isset($_POST["keywords"])) { $_POST["keywords"]=""; }

//---[CZ]: přidávání obsahu
if ($_GET["tab"]=="" AND isset($_POST["submit"])) { $articles->add(); }
if ($_GET["tab"]=="images" AND isset($_POST["submit"])) { $images->upload(); }
if ($_GET["tab"]=="files" AND isset($_POST["submit"])) { $files->upload(); }
if ($_GET["tab"]=="articles_polls" AND isset($_POST["submit"])) { $polls->add_poll(); }
?>

<h2><?php echo LANG_ADD_CONTENT; ?></h2>

<ul id="tab-bar">
<li<?php if ($_GET["tab"]=="") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=add_content"><?php echo LANG_ARTICLES; ?></a></li>
<li<?php if ($_GET["tab"]=="images") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=add_content&amp;tab=images"><?php echo LANG_UPLOAD_AN_IMAGE; ?></a></li>
<li<?php if ($_GET["tab"]=="files") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=add_content&amp;tab=files"><?php echo LANG_UPLOAD_A_FILE; ?></a></li>
<li<?php if ($_GET["tab"]=="articles_polls") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=add_content&amp;tab=articles_polls"><?php echo LANG_ADD_ARTICLE_POLL; ?></a></li>
<li><span class="float-ending"><!-- --></span></li>
</ul>

<?php if ($_GET["tab"]==""): ?>

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

<form action="./admin.php?function=add_content&amp;tab=" method="post">

<div>

<table>
<tr>
<td style="width: 50%;"><strong><?php echo LANG_ARTICLE_TITLE; ?>:</strong>
<br /><input type="text" name="article_title" id="article_title" value="<?php echo htmlspecialchars($_POST["article_title"]); ?>" style="width: 300px;"<?php if (isset($_POST["submit"]) AND $_POST["article_title"]=="") { echo " class=\"input-error\""; } ?> />
<br /><strong><?php echo LANG_GENERATED_LINK; ?>:</strong>
<br /><input type="text" name="article_link" id="article_link"  value="<?php echo $_POST["article_link"]; ?>" style="width: 218px;"<?php if (isset($_POST["submit"]) AND $_POST["article_link"]=="") { echo " class=\"input-error\""; } ?> /> <input type="button" class="yellowbutton" value="<?php echo LANG_GENERATE; ?>" onclick="generate_link();" /></td>
<td><strong><?php echo LANG_SECTION; ?>:</strong>
<br /><select name="section" style="width: 307px;">
<option value=""><?php echo LANG_CHOOSE; ?></option>
<?php
$sections->load_sections(0, $_POST["section"]);
?>
</select><?php if (isset($_POST["submit"]) AND $_POST["section"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br /><strong><?php echo LANG_META_KEYWORDS; ?>:</strong>
<br /><input type="text" name="keywords" value="<?php echo htmlspecialchars($_POST["keywords"]); ?>" style="width: 300px;" /></td>
</tr>
</table>

</div>

<div>

<p><strong><?php echo LANG_PROPERTIES; ?>:</strong></p>

<table>
<tr>
<td><input type="radio" name="article_type" value="1"<?php if ($_POST["article_type"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_NEWS; ?><?php if (isset($_POST["submit"]) AND $_POST["article_type"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?></td>
<td><input type="checkbox" name="hp" value="1"<?php if ($_POST["hp"]==1 OR $_POST["hp"]=="") { echo " checked=\"checked\""; } ?> /> <?php echo LANG_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_STANDARD_ARTICLE; ?></td>
<td><input type="checkbox" name="complete" value="1"<?php if ($_POST["complete"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_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_IMPORTANT_ARTICLE; ?></td>
<td><input type="checkbox" name="confirmed" value="1"<?php if ($_POST["confirmed"]==1) { echo " checked=\"checked\""; } if ($login->check_access("confirm_articles")==0) { echo " disabled=\"disabled\""; } ?> /> <?php echo LANG_ARTICLE_IS_VERIFIED; ?></td>
</tr>
<tr>
<td><input type="checkbox" name="top" value="1"<?php if ($_POST["top"]==1) { echo " checked=\"checked\""; } ?> /> TOP</td>
<td><input type="checkbox" name="discussion" value="1"<?php if ($_POST["discussion"]==1 AND isset($_POST["submit"]) OR $_POST["discussion"]=="" AND !isset($_POST["submit"])) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_ALLOW_DISCUSSION; ?></td>
</tr>
<tr>
<td><input type="checkbox" name="show_article_info" value="1"<?php if ($_POST["show_article_info"]==1 AND isset($_POST["submit"]) OR $_POST["show_article_info"]=="" AND !isset($_POST["submit"])) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_SHOW_ARTICLE_INFO; ?></td>
<td><input type="checkbox" name="publish_now" value="1"<?php if ($_POST["publish_now"]==1) { echo " checked=\"checked\""; } if ($login->check_access("publish_articles")==0) { echo " disabled=\"disabled\""; } ?> /> <?php echo LANG_PUBLISH_NOW; ?></td>
</tr>
<tr>
<td><strong><?php echo LANG_POLL; ?>:</strong><br /><select name="poll" style="width: 200px;">
<option value=""><?php echo LANG_CHOOSE; ?></option>
<?php
$polls->load_polls($_POST["poll"]);
?>
</select></td>
<td></td>
</tr>
</table>

</div>

<div>

<p><strong><?php echo LANG_PEREX_IMAGE; ?>:</strong><br /><input type="text" name="pereximg" value="<?php if (isset($_POST["submit"])) { echo ($_POST["pereximg"]); } else { echo "/gallery/"; } ?>" style="width: 300px;" /></p>

<p><strong><?php echo LANG_PEREX; ?>:</strong></p>

</div>

<div class="normal"><textarea name="perex" class="widgEditor nothing"><?php echo $_POST["perex"]; ?></textarea></div>

<div>

<p><strong><?php echo LANG_TEXT; ?>:</strong></p>

</div>

<div class="normal"><textarea name="text" class="widgEditor nothing"><?php echo $_POST["text"]; ?></textarea></div>

<div>

<p style="text-align: right;"><input type="submit" name="submit" class="greenbutton" value="<?php echo LANG_ADD; ?>" /></p>

</div>

</form>

<?php endif; ?>

<?php if ($_GET["tab"]=="images"): ?>

<form action="./admin.php?function=add_content&amp;tab=image" method="post" enctype="multitab/form-data">

<div>

<table>
<tr>
<td style="width: 50%; vertical-align: top;"><strong><?php echo LANG_FILE; ?>:</strong>
<br /><input type="file" name="file" /><?php if (isset($_POST["submit_upload"]) AND $_FILES["file"]["name"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br /><strong><?php echo LANG_TITLE; ?>:</strong>
<br /><input type="text" name="title" value="<?php if (isset($_POST["submit_upload"])) echo $_POST["title"]; ?>" style="width: 200px;" />
</td>
<td style="width: 50%; vertical-align: top;"><strong><?php echo LANG_SECTION; ?>:</strong>
<br /><select name="gallery" style="width: 200px;">
<option value=""><?php echo LANG_CHOOSE; ?></option>
<?php
$images->load_galleries($_POST["gallery"]);
?>
</select><?php if (isset($_POST["submit_upload"]) AND $_POST["gallery"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br /><strong><?php echo LANG_RESOLUTION; ?>:</strong>
<br /><input type="radio" name="changeres" value="0"<?php if (!isset($_POST["submit_upload"])) { echo " checked=\"checked\""; } if (isset($_POST["submit_upload"]) AND $_POST["changeres"]==0) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_DEFAULT; ?>
<br /><input type="radio" name="changeres" id="changeres" value="1"<?php if (isset($_POST["submit_upload"]) AND $_POST["changeres"]==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_CHANGE_WIDTH_TO; ?> <input type="text" name="new_width" style="width: 30px;" onclick="getElementById('changeres').checked='checked'" value="<?php if (isset($_POST["submit_upload"]) AND $_POST["changeres"]==1) echo $_POST["new_width"]; ?>"<?php if (isset($_POST["submit_upload"]) AND $_POST["new_width"]=="" AND $_POST["changeres"]==1) { echo " class=\"input-error\""; } ?> /> px</td>
</tr>
</table>

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

</div>

</form>

<?php endif; ?>

<?php if ($_GET["tab"]=="files"): ?>

<form action="./admin.php?function=add_content&amp;tab=file" method="post" enctype="multitab/form-data">

<div>

<p><strong><?php echo LANG_FILE; ?>:</strong><br /><input type="file" name="file" /><?php if (isset($_POST["submit"]) AND $_FILES["file"]["name"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?></p>

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

</div>

</form>

<?php endif; ?>

<?php if ($_GET["tab"]=="articles_polls"): ?>

<form action="./admin.php?function=add_content&amp;tab=articles_polls" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 200px;"<?php if (isset($_POST["submit"]) AND $_POST["name"]=="") { echo " class=\"input-error\""; } ?> /></p>

<p><strong><?php echo LANG_OPTIONS; ?>:</strong><br /><input type="checkbox" name="visible" /> <?php echo LANG_SHOW; ?></p>

</div>

<div>

<p><strong><?php echo LANG_ANSWERS; ?>:</strong><br /><input type="text" name="answer1" style="width: 200px;" /><br /><input type="text" name="answer2" style="width: 200px;" /><br /><input type="text" name="answer3" style="width: 200px;" /><br /><input type="text" name="answer4" style="width: 200px;" /><br /><input type="text" name="answer5" style="width: 200px;" /></p>

</div>

<div>

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

</div>

</form>

<?php endif; ?>

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