<?php
/* daCode _ http://www.dacode.org
 *
 * $Id: submit.php3,v 1.8 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($table[tip])) {
		echo $html->header("Proposer une astuce");
	}

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

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

  ?>

 <span class="newstext">
	<center>
	<br>
	<table border="0">
	<tr><td class="newstext">

	<form method="post">
	<tr><td class="newstext">
	Tip's section:

<?php
		//  Section
		$out = "<select name=\"table[tip_section_id]\">\n";
		$sqlc_q = "SELECT id,tip_section FROM ".$config->tables['tips_sections'] .
			" ORDER BY tip_section";
		$ret = $db->query($sqlc_q);
		if (!$ret) {
			return $db->error();
		}

		while($sections_tmp=$db->fetch_array()) {
			if (isset($table['tip_section_id']) && 
				$table['tip_section_id'] == $sections_tmp[0]) {

				$out .= "<option value=\"$sections_tmp[0]\" selected>$sections_tmp[1]\n";
			} else {
				$out .= "<option value=\"$sections_tmp[0]\">$sections_tmp[1]\n";
			}
		}
		$db->free();
		$out .= "</select>\n";
		echo $out;
?>
	</td></tr>
	<tr><td class="newstext">
	Tip's subject: <input type="text" size="45" name="table[name]" value="">
	</td></tr>
	<tr><td>
	<textarea name="table[tip]" wrap="virtual" rows="10" cols="50">Place your tip here.</textarea>
	</td></tr>
	<tr><td class="newstext">
	<center>
	<input type="submit" name="table[submit]" value="<?php lecho ("Submit") ?>!">
	</center>
	</form>

	</td></tr></table>
	</span>

<?php

		echo $html->footer();

	} else {

		if ( empty($table[tip]) || empty($table[name]) ) {
			echo $html->header("Submit a tip");
			echo lecho("<br>You must propose a tip and a tip's name...<br><br>");
			echo $html->footer();
		} else {

			$table[name] = addslashes($table[name]);
			$table[tip] = addslashes($table[tip]);
	
			$sqlc_q = "INSERT INTO ".$config->tables[tips].
				" (user_id,name,tip,tip_section_id) VALUES ('".
				addslashes($user->user_id)."','".
				addslashes($table[name])."','".
				addslashes($table[tip])."','".
				addslashes($table[tip_section_id])."')";

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

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

?>
