<body>
<?php
include 'config.php';
if (isset($_POST['pw']))
{
$pw = $_POST['pw'];
$_SESSION['pw'] = $pw;
}
elseif (isset($_GET['pw']))
{
$pw = $_GET['pw'];
$_SESSION['pw'] = $pw;
}
elseif (isset($_SESSION['pw']))
{
$pw = $_SESSION['pw'];
}
if ($pw == $adminpass)
{
include 'library/opendb.php';
include 'library/timeFunctions.php';
include 'library/displayFunctions.php';
$action = $_GET['action'];
$id = $_GET['id'];
if($action == 'delete')
{
$query = "DELETE FROM events WHERE id =" . $id;
mysql_query($query) or die('Error, query failed');
echo "Anlass erfolgreich gelöscht!<br><br><a href='admin.php'>Neuer Anlass hinzufügen</a>";
}
elseif (isset($_POST['add']) || isset($_POST['edit']))
{
$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
$rawTime = $_POST['time'];
if($rawTime > 23 )
{
$rawTime = '0';
}
$time = ($rawTime + $_POST['ampm']) . ':' . $_POST['minute'] . ':00';
$showTime = $_POST['showTime'];
if ($showTime == "on")
{
$showTime = 1;
}
else
{
$showtime = 0;
}
$venue = $_POST['venue'];
$description = $_POST['description'];
if (isset($_POST['add'])) {
$query = "INSERT INTO events (date, time, showTime, venue, description) VALUES ('$date', '$time', '$showTime', '$venue', '$description')";
}
elseif (isset($_POST['edit'])) {
$query = "UPDATE events SET date = '$date', time = '$time', showTime = '$showTime', venue = '$venue', description = '$description' WHERE id ='$id'";
}
mysql_query($query) or die('Error, insert query failed');
echo "Liste erfolgreich aktualisiert!<br><br><a href='admin.php'>Neuer Anlass hinzufügen</a>";
}
else
{
if($action == 'edit')
{
$query = "SELECT * FROM events WHERE id='$id'";
$result = mysql_query($query);
$date = mysql_result($result,0,"date");
$time = mysql_result($result,0,"time");
$venue = mysql_result($result,0,"venue");
$description = mysql_result($result,0,"description");
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$format = function ( $i ) {
$year = substr($date, 0, 4);
$hour = realHour($time);
$minute = substr($time, 3, 2);
$ampm = realAMPM($time);
$showTime = mysql_result($result,0,"showTime");
}
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Datum</td>
<td>
<select name="month" id="month">
<option value="01" <?php if ($month == "01") {echo "selected";} ?>>Jan
<option value="02" <?php if ($month == "02") {echo "selected";} ?>>Feb
<option value="03" <?php if ($month == "03") {echo "selected";} ?>>Mar
<option value="04" <?php if ($month == "04") {echo "selected";} ?>>Apr
<option value="05" <?php if ($month == "05") {echo "selected";} ?>>Mai
<option value="06" <?php if ($month == "06") {echo "selected";} ?>>Jun
<option value="07" <?php if ($month == "07") {echo "selected";} ?>>Jul
<option value="08" <?php if ($month == "08") {echo "selected";} ?>>Aug
<option value="09" <?php if ($month == "09") {echo "selected";} ?>>Sep
<option value="10" <?php if ($month == "10") {echo "selected";} ?>>Okt
<option value="11" <?php if ($month == "11") {echo "selected";} ?>>Nov
<option value="12" <?php if ($month == "12") {echo "selected";} ?>>Dez
</select>
<select name="day" id="day">
<option value="01" <?php if ($day == "01") {echo "selected";} ?>>01
<option value="02" <?php if ($day == "02") {echo "selected";} ?>>02
<option value="03" <?php if ($day == "03") {echo "selected";} ?>>03
<option value="04" <?php if ($day == "04") {echo "selected";} ?>>04
<option value="05" <?php if ($day == "05") {echo "selected";} ?>>05
<option value="06" <?php if ($day == "06") {echo "selected";} ?>>06
<option value="07" <?php if ($day == "07") {echo "selected";} ?>>07
<option value="08" <?php if ($day == "08") {echo "selected";} ?>>08
<option value="09" <?php if ($day == "09") {echo "selected";} ?>>09
<option <?php if ($day == "10") {echo "selected";} ?>>10
<option <?php if ($day == "11") {echo "selected";} ?>>11
<option <?php if ($day == "12") {echo "selected";} ?>>12
<option <?php if ($day == "13") {echo "selected";} ?>>13
<option <?php if ($day == "14") {echo "selected";} ?>>14
<option <?php if ($day == "15") {echo "selected";} ?>>15
<option <?php if ($day == "16") {echo "selected";} ?>>16
<option <?php if ($day == "17") {echo "selected";} ?>>17
<option <?php if ($day == "18") {echo "selected";} ?>>18
<option <?php if ($day == "19") {echo "selected";} ?>>19
<option <?php if ($day == "20") {echo "selected";} ?>>20
<option <?php if ($day == "21") {echo "selected";} ?>>21
<option <?php if ($day == "22") {echo "selected";} ?>>22
<option <?php if ($day == "23") {echo "selected";} ?>>23
<option <?php if ($day == "24") {echo "selected";} ?>>24
<option <?php if ($day == "25") {echo "selected";} ?>>25
<option <?php if ($day == "26") {echo "selected";} ?>>26
<option <?php if ($day == "27") {echo "selected";} ?>>27
<option <?php if ($day == "28") {echo "selected";} ?>>28
<option <?php if ($day == "29") {echo "selected";} ?>>29
<option <?php if ($day == "30") {echo "selected";} ?>>30
<option <?php if ($day == "31") {echo "selected";} ?>>31
</select>
,
<select name="year" id="year">
<option <?php if ($year == (date('Y') - 3)) {echo "selected";} echo ">" . (date('Y') - 3); ?>
<option <?php if ($year == (date('Y') - 2)) {echo "selected";} echo ">" . (date('Y') - 2); ?>
<option <?php if ($year == (date('Y') - 1)) {echo "selected";} echo ">" . (date('Y') - 1); ?>
<option <?php if (($year == date('Y')) OR (!isset($year))) {echo "selected";} echo ">" . date('Y'); ?>
<option <?php if ($year == (date('Y') + 1)) {echo "selected";} echo ">" . (date('Y') + 1); ?>
<option <?php if ($year == (date('Y') + 2)) {echo "selected";} echo ">" . (date('Y') + 2); ?>
<option <?php if ($year == (date('Y') + 3)) {echo "selected";} echo ">" . (date('Y') + 3); ?>
<option <?php if ($year == (date('Y') + 4)) {echo "selected";} echo ">" . (date('Y') + 4); ?>
</select>
</td>
</tr>
<tr>
<td width="100">Zeit</td>
<td>
<input name="time" type="text" id="time" size="2" maxlength="2" <?php if (isset($hour)) {echo "value=" . $hour;} else {echo "value='18'";} ?>> :
<input name="minute" type="text" id="minute" size="2" maxlength="2" <?php if (isset($minute)) {echo "value=" . $minute;} else {echo "value='00'";} ?>>
<select name="ampm" id="ampm" style="visibility:hidden;">
<option value="12" <?php if ($ampm == "PM") {echo "selected";} ?>>PM
<option value="0" <?php if ($ampm == "AM") {echo "selected";} ?>>AM
</select>
(Zeit anzeigen? <input name="showTime" type="checkbox" id="showTime" <?php if ($showTime) {echo "checked";} elseif (!isset($showTime)) {echo "checked";} ?>>)
</td>
</tr>
<tr>
<td width="100">Anlass</td>
<td>
<textarea name="venue" id="venue" rows="5" cols="80"><?php if (isset($venue)) {echo $venue;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Ort</td>
<td>
<textarea name="description" id="description" rows="5" cols="80"><?php if (isset($description)) {echo $description;} ?></textarea>
</td>
</tr>
<tr>
<td width="100"> </td>
<td>
<?php
if ($action == 'edit')
{
echo "<input name='edit' type='submit' id='edit' value='Anlass aktualisieren'>";
}
else
{
echo "<input name='add' type='submit' id='add' value='Anlass hinzufügen'>";
}
?>
</td>
</tr>
</table>
</form>
<?php
}
?>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
Bevorstehende Termine
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date, time";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] >= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
?>
</table>
<BR>
<BR>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
Vergangene Termine
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date DESC, time DESC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] <= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
include 'library/closedb.php';
}
else
{
echo "Wrong password";
}
?>
</table>
<br />