<?php
//session
session_start();
include ("connect.php");
$username = $_SESSION['staff'];

$eventDate = $_POST["eventDate"];
$eventTime = $_POST["eventTime"];
$eventLocation = $_POST["eventLocation"];
$eventTitle = $_POST["eventTitle"];
$eventDescription = $_POST["eventDescription"];

if($_POST["Submit"] == "Submit")
	{
	if(($eventDate == "")||($eventTime == "")||($eventLocation == "")||($eventTitle == "")||($eventDescription == ""))
	{
	echo "<script>alert('Please fill in all the information for Submit')</script>";
	echo "<script language='javascript'>window.location='event.php'</script>";
	}
	
else{
	$result = mysql_query("UPDATE companyevent SET eventDate = '$eventDate', eventTime = '$eventTime', eventLocation = '$eventLocation', eventDescription = '$eventDescription' WHERE eventTitle = '$eventTitle'");
	
	
	$tmp_file_name = $_FILES['file']['tmp_name']; 
	$file_name = $_FILES['file']['name']; 
	$file_dir = './event/'.$_POST['title'].'/';  
	if(is_dir($file_dir)) 
	{ 
	move_uploaded_file($tmp_file_name,$file_dir.$file_name); 
	$img_url = $file_dir.$file_name; 
	if($img_url!="./event//"){
	$result = mysql_query("UPDATE companyevent SET eventImage = '$img_url' WHERE eventTitle = '$eventTitle'");
	
	}
	}
	$db = mysql_close();
	echo "<script language='javascript'>alert('Insert success.')</script>";
	echo "<script language='javascript'>window.location='event.php'</script>";
	}
	}
?>

<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="calendar-setup.js"></script>
<script type="text/javascript" src="calendar-en.js"></script>
<style type="text/css"> @import url("calendar-win2k-cold-1.css"); </style>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>

<center>
<h2>Daily Bookstore Management - Manage Event</h2>
</center>

<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset style="margin:0 5 0 0">
<legend><img src="Picture/event.gif" width="30" height="30">Manage Event</legend>
<table>
<tr>
<td valign="top">
<a href="event.php"><img src="Picture/list.gif" width="30" height="30" alt="event list"><a href="event.php">Event List</a><br/>
<br/>
<a href="addEvent.php"><img src="Picture/add.gif" width="30" height="30" alt="add event"><a href="addEvent.php">Add Event</a><br/>
<br/>
</td>
</tr>
</table>
</fieldset>
</td>

<td width="75%">
<!--1st table-->
<table border="0" width="90%" align="center">

<tr>

<td>
<form name='addevent' method="POST" enctype="multipart/form-data">
<fieldset> 
<legend><img src="Picture/add.gif" width="30" height="30">Edit Event</legend>
	
<table width="100%">

<tr>
<br/>
<td valign="top">Event Image</td>
<td valign="top">
<input type="file" name="file" OnChange='showPreview(this)'/></td>

<?php
include("connect.php");
$eventTitle=$_GET['eventTitle'];
$result = mysql_query("SELECT * FROM companyevent WHERE eventTitle = '$eventTitle'");


$row = mysql_fetch_array($result);
echo "<td width='200' rowspan='5'><img id='imgAvatar' img src='$row[eventImage]'></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Event Title</td>";
echo "<td><input type='hidden' name='eventTitle' value='$row[eventTitle]'>$row[eventTitle]";
echo "<font color='red'>&nbsp;&nbsp;&nbsp;Title cannot be edit.</font>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Event Date</td>";
echo "<td><input type='text' id='cal-field-1' name='eventDate' value='$row[eventDate]'/>
			<button type='submit' id='cal-button-1'>Date</button>
			<script type='text/javascript'>
			Calendar.setup({
			inputField : 'cal-field-1',
			button : 'cal-button-1',
			align : 'Tr'
			});
			</script></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Event Time</td>";
echo "<td><input type='text' size='15' maxlength='15' name='eventTime' value='$row[eventTime]'></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Event Description</td>";
echo "<td><textarea name='eventDescription' rows='10' cols='80' maxlength='100' style='font-family:times new roman'>$row[eventDescription]</textarea></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Event Location</td>";
echo "<td><input type='text' size='30' maxlength='30' name='eventLocation' value='$row[eventLocation]'></td></tr>";

echo "<tr>";
echo "<td colspan='2' align='center'><input type='Submit' name='Submit' value='Submit'><input type='Reset' name='Reset'></td></tr>";
?>
</table>
</fieldset>
</form>
</td>
</tr>
</table>

</td>
</tr>
</table>
<center>
<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved.
<br/>
Website:<a href="../bookstore" target="_blank">www.dailybook.com.my
</div>
</center>

</body>
</html>