<?php
require 'rb-include.php';
rb_header();

if ($submitted == 1) {
	if (substr($page, 0, 7) == 'http://') {
		pg_exec($db, "insert into pages (url, owner) values ('$page', '$uid')");
		echo '<p>The following page will be crawled shortly, due to your request.  When the Rainbow Builder has extracted all of the songs from the page, you will be notified by email.  Then you can correct any mistakes in its findings, and create a final RDF file.</p><ul><li><tt>', $page, "</tt></li></ul>\n";
	} else {
		echo '<p>Sorry, but the page you entered is not a valid URL.  Please go back and try again.</p>', "\n";
	}
} else if ($submitted == 2) {
	$correct = '';
	$incorrect = '';
	$correct_num = 0;
	$incorrect_num = 0;
	for ($i = 1; $i <= 30; $i++) {
		$a = 'audiofile' . $i;
		$a = $$a;
		if (substr($a, 0, 7) == 'http://') {
			$correct_num++;
			$correct .= '<li><tt>' . $a . '</tt></li>' . "\n";
			pg_exec($db, "insert into available (url, use, owner) values ('$a', 1, $uid)");
		} else if ($a != '') {
			$incorrect_num++;
			$incorrect .= '<li><tt>' . $a . '</tt></li>' . "\n";			
		}
	}
	
	if ($correct_num == 0) {
		echo '<p>You did not enter any correct URLs.  Please go back and try again.</p>', "\n";
	} else {
		echo '<p>Thank you for your submission.  The songs you entered will be scanned shortly, and you will receive an email when this is completed.  Then you can come back and create the final RDF file.</p><p>The following files will be scanned:</p>', "\n";
		echo '<ul>', "\n", $correct, '</ul>', "\n";
	}
	
	if ($incorrect_num != 0) {
		echo '<p>The following URLs are invalid and will not be scanned:</p>', "\n";
		echo '<ul>', "\n", $incorrect, '</ul>', "\n";
	}
} else {
?>

<p>Welcome to Rainbow Builder.  This process will allow your music to be featured on Gnomoradio under a Creative Commons license.  If you have not done so already, please publish all of the files that you wish to have on Gnomoradio on a web server in mp3 or ogg format.</p>

<p>This system is still in testing, so it is not fully automated yet.  This will allow us to fix any mistakes that happen with the data.</p>

<p>If all of your mp3s/oggs are linked from a single page, please type that page into the box below and click continue.</p>

<form method="post">
<input type="hidden" name="submitted" value="1"/>
<table>
<tr><td><b>URL of page:</b></td><td><input size="40" name="page" value="http://"/></td></tr>
<tr><td></td><td><input type="submit" value="Continue"/></td></tr>
</table>
</form>

<p>If your audio files are not linked from a single page, do not worry!  Simply enter the address of each mp3 or ogg file in the boxes below, and click "Crawl" at the bottom of the page.  Fill up as many boxes as you need.  Our server will then collect information about each of them.</p>

<p>If you have multiple mirrors of the same file, or multiple formats of the same song, feel free to enter them below.  The crawler will be sure to look at all the information associated with each file to determine its exact place.</p>

<form method="post">
<input type="hidden" name="submitted" value="2"/>
<table>
<?php
for ($i = 1; $i <= 30; $i++) {
	echo '<tr><td><input name="audiofile', $i, '" size="40"/></td></tr>', "\n";
}
?>
<tr><td><input type="submit" value="Crawl"/></td></tr>
</table>
</form>

<?php
}

rb_footer();
?>
