Location: PHPKode > scripts > Weight Loss Recipe Book > weight-loss-recipe-book/wlrb-submit.php
<?php 
	include('wlrb_files/functions/functions_general.php');
	include('wlrb_files/config.php');
	//$custom_vars = getCustomVars();
	include('wlrb_files/GOTCHA/gotcha.php');
	
	session_start();
	
	$CAPTCHA_SESSION_KEY = 'CAPTCHA';
	$CAPTCHA_IMAGE_URI = 'wlrb_files/GOTCHA/captcha_image.php';
	
	
	
	if ($_POST['action'] == 'add_recipe') {
		$text = isset($_SESSION[$CAPTCHA_SESSION_KEY])? $_SESSION[$CAPTCHA_SESSION_KEY] : NULL;
		if (!$p =trim($_POST['code'])) {
			$result_div .= getResultDiv('Please enter a code for the image below');
		} else if((strtolower($p)) != ($c = strtolower($text))){
			$result_div .= getResultDiv('The code entered for the image below was not correct');
		} else {
			$recipe_name = full_input_clean($_POST['recipe_name']);
			if ($recipe_name != '') {
				$heading_addon = ' for ' . $recipe_name;
			}
			$i = 1;
			while ($i <= 15) {
				$ingredent = full_input_clean($_POST['ingredient_' . $i]);
				if ($ingredent != '') {
					$ingredient_text .= '<li>' . $ingredent . "</li>";
				}
				$i++;
			}
			if ($ingredient_text != '') {
				$ingredient_text = '<h4>Ingredients' . $heading_addon . '</h4><ol>' . $ingredient_text . '</ol>';
			}
			$instructions = full_input_clean($_POST['instructions']);
			
			$instructions = nl2br($instructions);
			if ($instructions != '') {
				$instruction_text = '<h4>Instructions' . $heading_addon . '</h4>' . $instructions;
			}
			$recipe_text = '<h2>' . $recipe_name . '</h2>' . $ingredient_text . $instruction_text;
			$recipe_text = str_replace('"',"'",$recipe_text);
			$double_check_text = '
			<form method="post" action="wlrb-submit.php"><p><strong>Please check your recipe below to make sure it looks right. If it does not, please adjust the values below and click the button below:</strong></p>
				<p class="align-center"><input type="submit" value="The recipe looks good, please submit it!" /></p><hr />' . $recipe_text . '<hr />
				<input type="hidden" name="action" value="recipe_approved" />
				<input type="hidden" name="wlrb_recipes_content" value="' . $recipe_text . '" />
				<input type="hidden" name="wlrb_recipes_title" value="' . $recipe_name . '" />
				<input type="hidden" name="wlrb_recipes_submitter" value="' . full_input_clean($_POST['wlrb_recipes_submitter']) . '" />
				<input type="hidden" name="wlrb_categories_id" value="' . $_POST['wlrb_categories_id'] . '" />
			</form>
			';
			$result_div .= getResultDiv($double_check_text,'success');
		}
	}
	
	if ($_POST['action'] == 'recipe_approved') {
		$insert = mysql_query('
			INSERT INTO wlrb_recipes
			SET wlrb_recipes_title = "' . $_POST['wlrb_recipes_title'] . '",
				wlrb_recipes_content = "' . $_POST['wlrb_recipes_content'] . '",
				wlrb_recipes_submitter = "' . $_POST['wlrb_recipes_submitter'] . '",
				wlrb_categories_id = "' . $_POST['wlrb_categories_id'] . '"');
		$result_div .= getResultDiv('Your recipe has been submitted for approval.','success');
		
	}
	
	// Get category list
	$result = mysql_query('
		SELECT *
		FROM wlrb_categories
		ORDER BY wlrb_categories_title ASC');
	while ($row = mysql_fetch_array($result)) {
		$category_list .= '<option value="' . $row['wlrb_categories_id'] . '">' . $row['wlrb_categories_title'] . '</option>';
	}
	$category_list = '<select name="wlrb_categories_id">' . $category_list . '<option value="0">Miscellaneous</option></select>';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="wlrb_files/styles/default.css">
</head>
<body>
<div class="align-center">
	<a href="wlrb-recipe-categories.php"><img src="wlrb_files/images/browse_categories.gif" alt="Browse Categories" /></a> <a href="wlrb-submit.php"><img src="wlrb_files/images/submit_recipe.gif" alt="Submit Recipe" /></a></div>
<div class="main">
<?php echo $result_div; ?>
<h1>Weight List Recipe Book Submit</h1>
<p>To add a recipe to the recipe book, just fill in the information below.</p>
<form action="wlrb-submit.php" method="post">
	<input type="hidden" name="action" value="add_recipe" />
<div class="highlighted-border">
	<table>
		<tr>
			<td>Recipe Name: </td>
			<td><input type="text" name="recipe_name" value="<?php echo $_POST['recipe_name']; ?>" maxlength="125" size="70" /></td>
		</tr>
		<tr>
			<td>Category: </td>
			<td><?php echo $category_list; ?></td>
		<tr>
		<tr>
			<td>Your Name: </td>
			<td><input type="text" name="wlrb_recipes_submitter" value="<?php echo $_POST['wlrb_recipes_submitter']; ?>" maxlength="125" size="40" /></td>
		<tr>
			<td>Ingredient 1: </td>
			<td><input type="text" name="ingredient_1" value="<?php echo $_POST['ingredient_1']; ?>" maxlength="125" size="60" /></td>
		</tr>
		<tr>
			<td>Ingredient 2: </td>
			<td><input type="text" name="ingredient_2" value="<?php echo $_POST['ingredient_2']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 3: </td>
			<td><input type="text" name="ingredient_3" value="<?php echo $_POST['ingredient_3']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 4: </td>
			<td><input type="text" name="ingredient_4" value="<?php echo $_POST['ingredient_4']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 5: </td>
			<td><input type="text" name="ingredient_5" value="<?php echo $_POST['ingredient_5']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 6: </td>
			<td><input type="text" name="ingredient_6" value="<?php echo $_POST['ingredient_6']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 7: </td>
			<td><input type="text" name="ingredient_7" value="<?php echo $_POST['ingredient_7']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 8: </td>
			<td><input type="text" name="ingredient_8" value="<?php echo $_POST['ingredient_8']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 9: </td>
			<td><input type="text" name="ingredient_9" value="<?php echo $_POST['ingredient_9']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 10: </td>
			<td><input type="text" name="ingredient_10" value="<?php echo $_POST['ingredient_10']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 11: </td>
			<td><input type="text" name="ingredient_11" value="<?php echo $_POST['ingredient_11']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 12: </td>
			<td><input type="text" name="ingredient_12" value="<?php echo $_POST['ingredient_12']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 13: </td>
			<td><input type="text" name="ingredient_13" value="<?php echo $_POST['ingredient_13']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 14: </td>
			<td><input type="text" name="ingredient_14" value="<?php echo $_POST['ingredient_14']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Ingredient 15: </td>
			<td><input type="text" name="ingredient_15" value="<?php echo $_POST['ingredient_15']; ?>" maxlength="125" size="60"  /></td>
		</tr>
		<tr>
			<td>Instructions: </td>
			<td><i>Note that new lines are preserved, but HTML will be stripped out.</i></td>
		</tr>
		<tr>
			<td></td>
			<td><textarea name="instructions" cols="60" rows="10"><?php echo $_POST['instructions']; ?></textarea></td>
		</tr>
		<tr>
			<td>Code from Image: </td>
			<td><input type="text" size="10" name="code" id="code" /></td>
		</tr>
		<tr>
			<td></td>
			<td><a href="#" onclick="var d = document.getElementById('gotcha-captcha');if(d){d.src +='?'+ Math.round(Math.random()*100000);} return false;" id="reload" title="load a new image"><img src="<?php echo $CAPTCHA_IMAGE_URI; ?>" id="gotcha-captcha" alt="captcha image" ></a><br>(Click image if you can't read code)</td>
		</tr>
	</table>
	
			<input type="submit" value="Submit Recipe" />
</div>
</form>

</div>	
<p class="align-center">Powered by <a href="http://www.my-health-and-fitness.org">My-Health-and-Fitness.org</a></p>
</body>
</html>
Return current item: Weight Loss Recipe Book