<script language="javascript" type="text/javascript" src="tinymce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
 tinyMCE.init({
 mode : "textareas",
 language: "pl",
 convert_fonts_to_spans : true,
 });
</script>

<?php if (!session_id()) { session_start(); }

echo '<h2>Panel</h2>';

if (!isset($_SESSION['userID'])) {
echo '<p><strong>Nie jesteś zalogowany!</strong></p>';
}

elseif(empty($_GET['c'])) {
echo'<p><a href="index.php?t=cp&amp;c=addnews">Dodaj news</a></p>';
echo '<p><a href="index.php?t=cp&amp;c=addrep">Dodaj do repertuaru</a></p>';
}

elseif ($_GET['c'] == "addnews") {
echo '<h3>Dodaj news</h3>';

 if (isset($_POST['title']) && isset($_POST['text'])) {
 mysql_connect($dbconfig['address'], $dbconfig['user'], $dbconfig['password']);
 mysql_select_db ($dbconfig['db']);
 $title = mysql_real_escape_string($_POST['title']);
 $text = mysql_real_escape_string($_POST['text']);
 $date = date("Y-m-d");
 $author = $_SESSION['name'];
 
 $query="INSERT INTO `teatr_news` (`content`, `title`, `date`, `author`) VALUES ('$text', '$title', '$date', '$author')";
 $result = mysql_query($query);
 if ($result) {echo "<p>Dodano!</p>";}
 } 

?>

<form action="" method="post">
<label for="title">Tytuł:</label>
<input name="title" id="text"></input>
<label for="text">Treść:</label>
<textarea name="text" id="text"></textarea>
<input type="submit" name="submit" value="Wyślij!"></input>
</form>
<?php }

elseif ($_GET['c'] == "addrep") { 
echo '<h3>Dodaj do repertuaru</h3>'; 

 if (isset($_POST['title']) && isset($_POST['author']) && isset($_POST['description']) && isset($_POST['text'])) {
 mysql_connect($dbconfig['address'], $dbconfig['user'], $dbconfig['password']);
 mysql_select_db ($dbconfig['db']);
 
 $title = mysql_real_escape_string($_POST['title']);
 $author = mysql_real_escape_string($_POST['author']);
 $desc = mysql_real_escape_string($_POST['description']);
 $text = mysql_real_escape_string($_POST['text']);
 
 $query="INSERT INTO `teatr_repertuar` (`author`, `title`, `description`, `content`) VALUES ('$author', '$title', '$desc', '$text')";
 $result = mysql_query($query);
 if ($result) {echo "<p>Dodano!</p>";}
 }

?>
<form action="" method="post">
<label for="title">Tytuł:</label>
<input name="title" id="title"></input>
<label for="author">Autor:</label>
<input name="author" id="author"></input>
<label for="desc">Opis:</label>
<textarea name="description" id="desc"></textarea>
<label for="text">Treść:</label>
<textarea name="text" id="text" class="addToRep"></textarea>
<input type="submit" name="submit" value="Wyślij!"></input>
</form>
<?php }

?>