<html>
	<head>
		<title>Playwire Video API Test - Video Upload</title>
	</head>
<body>
<?php
	require_once('../common.php');
	if (empty($api_token)) {
		showAPITokenForm();
	} else {
		require_once('../class.playwire.php');

		$playwire = new Playwire($api_token);

		$is_post = $_POST['is_post'];
		if ($is_post) {
			echo "<pre>";
			// This is a POST, call the API
			$video = new Video();
			$video->name = $_POST['name'];
			$video->source_url = $_POST['source_url'];
			$video->description = $_POST['description'];
			$video->category_id = $_POST['category_id'];
			$video->width = $_POST['width'];
			$video->height = $_POST['height'];
			$video->tag_list = $_POST['tag_list'];
			$video->show_video_watermark = checkboxValue($_POST['show_video_watermark']);
			$video->use_age_gate = checkboxValue($_POST['use_age_gate']);
			$video->auto_start = checkboxValue($_POST['auto_start']);
			try {
				$new_video = $playwire->uploadVideo($video);
				echo "Successfully uploaded video, new id is " . $new_video->id;
			} catch (PlaywireException $exception) {
				echo "Had an exception: " . $exception->getMessage();
			}
			echo "</pre>";
		}
		else {
			echo "<pre>";
			$defaults = $playwire->getVideoDefaults();
			$categories = $playwire->getVideoCategories();
			echo "</pre>";
?>
<h2>Upload New Video</h2>
<form method="post" action="upload.php">
<input type="hidden" name="is_post" value="1"/>
<div>
	<label for="name">Name:</label>
	<input type="text" name="name" size="80"/>
</div>
<div>
	<label for="source_url">Video Source URL:</label>
	<input type="text" name="source_url" size="80"/>
</div>
<div>
	<label for="description">Description:</label><br/>
	<textarea name="description"></textarea>
</div>
<div>
	<label for="category_id">Category:</label><br/>
	<select name="category_id">
		<option value=""></option>
		<?php
			foreach($categories as $category) {
				echo '<option value="' . $category->id . '">' . $category->name . '</option>'; 
			}
		?>
	</select>
</div>
<div>
	<label for="width">Width:</label>
	<input type="text" name="width" size="5" value="<?php echo $defaults->width; ?>"/>
	<label for="height">Height:</label>
	<input type="text" name="height" size="5" value="<?php echo $defaults->height; ?>"/>
</div>
<div>
	<label for="tags">Tags:</label>
	<input type="text" name="tag_list" size="80" />
</div>
<div>
	<h4>Video Settings</h4>
	<div>
	<input type="checkbox" name="show_video_watermark" value="on" <?php if ($defaults->show_video_watermark) echo 'checked="checked"'; ?>/>
		<label for="show_video_watermark">Show Video Watermark</label>
	</div>
	<div>
		<input type="checkbox" name="use_age_gate" value="on" <?php if ($defaults->use_age_gate) echo 'checked="checked"'; ?>/>
		<label for="use_age_gate">Use Age Gate</label>
	</div>
	<div>
		<input type="checkbox" name="auto_start" value="on" <?php if ($defaults->auto_start) echo 'checked="checked"'; ?>/>
		<label for="auto_start">Auto Play</label>
	</div>
</div>
<div>
	<input type="submit"/>
</div>
<?php 
		}
	}
?>
</body>
</html>
