<?php
session_start();

include "../functions.php";
checkAdmin(session_id());

$submit = $_POST["submit"];

require("fileupload-class.php");
$path = "files/";
$upload_file_name = "userfile";
$acceptable_file_types = "image/gif|image/jpeg|image/pjpeg";
$default_extension = "";
$mode = 2;

if (isset($submit))
{
	$mediaName = $_POST["mediaName"];
	//$categoryID = $_POST["categoryID"];
	$mediaDescrip = $_POST["mediaDescrip"];
	$categoryID = 0;
	
	//upload file now
	$my_uploader = new uploader('en');
	$my_uploader->max_filesize(100000);
	$my_uploader->max_image_size(800, 800);
	if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) 
	{
		$my_uploader->save_file($path, $mode);
	}
	
	if ($my_uploader->error) 
	{
		$err .= $my_uploader->error;
		echo $err;
	}
	else
	{
		$mediaURL = $path . $my_uploader->file['name'];
	}
	
	if (! $err)
	{
		$query = "insert into media_media(categoryID, mediaName, mediaDescrip, mediaURL, lastdate) values($categoryID, '$mediaName', '$mediaDescrip', '$mediaURL', now())";
		//echo $query;
		mysql_query($query) or die (mysql_error());
	
		header("location: press.php");
	}
}
else
{
include "header.php";
?>


<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" enctype="multipart/form-data">
<center>
<table width="80%" border="0" cellpadding=5 cellspacing=1>
  <tr>
    <td align="right">Name:</td>
    <td align="left"><input type="text" name="mediaName" size=30></td>
  </tr>

  <tr>
    <td align="right" valign="top">Description:</td>
    <td align="left"><textarea name="mediaDescrip" rows=5 cols=30 wrap="virtual"></textarea></td>
  </tr>

  <tr>
    <td align="right">File:</td>
    <td align="left"><input type="file" name="<?php echo $upload_file_name; ?>" size="30"></td>
  </tr>

  <tr>
    <td colspan="2" align="center"><input type="hidden" name="submit" value=1><input type="submit" value=" Add ">&nbsp;<input type="reset" value="Cancel"></td>
  </tr>
</table>

</center>

</form>
<?php
}
include "footer.php";
?>