<?php
/* daCode _ http://www.dacode.org
 * $Id: submit.php3,v 1.14 2001/07/12 09:48:15 penso Exp $
 *
 */

	$topdir = '..';
	require $topdir."/dacode.php3";

	$db = LoadClass('Db');
	$html = LoadClass('Html');
	$user = LoadClass('User');
	$utils = LoadClass('Utils');

	if (empty($table[submit]) || !isset($image)) {
		echo $html->header("Proposer une webcam");
	}

	// echo $user->makerand();

	if ($user->checked != 1) {
		echo lecho("Must be logged...")."<br>\n";
		echo $html->footer();
		exit;
	}

if (empty($table[submit])) {
  ?>

 <span class="newstext">
	<center>

	<table border="0">
	<tr><td class="newstext">

	<form method="post" enctype="multipart/form-data">

	<textarea name="table[comment]" wrap="virtual" rows="5" cols="50">
Mettez un commentaire de 255 caractères maximum...
	</textarea>
	</td></tr>
	<tr><td class="newstext">
	<input type="file" size="50" name="image"><br>
	</td></tr>
	<tr><td class="newstext">
	<center>
	<input type="submit" name="table[submit]" value="Envoyer!">
	</center>
	</form>
	</td></tr></table>
	</span>

<?php

	echo $html->footer();

} else {

	if (!isset($image)) {
		echo lecho("You must propose a file...");
  		echo $html->footer();
	} else {

		if (!file_exists($image) || !$fd = fopen($image, "r")) {
			echo lecho("No filename. Contact webmaster<br>\n");
			exit;
		}
		$contents = fread($fd,filesize($image));
		fclose( $fd );
		$contents = addslashes($contents);
		$image_name = addslashes($image_name);
		$image_size = addslashes($image_size);
		$image_type = addslashes($image_type);
		$table[comment] = addslashes($table[comment]);
	
		$q = "INSERT INTO ".$config->tables[webcam].
			" (user_id,image,comment,content_type,size,name) VALUES ('".
			addslashes($user->user_id)."','".
			addslashes($contents)."','".
			addslashes($table[comment])."','".
			addslashes($image_type)."','".
			addslashes($image_size)."','".
			addslashes($image_name)."')";

		$ret = $db->query($q);
		if (!$ret) {
			echo "<!-- SQL Failed: ".$db->error()."-->\n";
			echo "<!-- SQL was: $q -->\n";
			exit;
		}

		header("Location: ".$config->basehref);
	}
}

?>
