<?php
//this is the home page for PrairieOutdoors.com

// set a variable to determine which design templates to use
$templates="2";

//set page specific variables
$title="Add your Fishing Report on PrairieOutdoors.com for Alberta, Saskatchewan and Manitoba";
$keywords='"fishing reports, fishing, fishing lodges, Fishing, guides, Lodges, Resorts, Outdoor, Prairie, Fishing Tackle, Western Canada, Alberta, Saskatchewan, Manitoba, Northern Pike, Walleye, Trout, Sturgeon, Whitefish"';
$description='"Fishing reports from Alberta and Saskatchewan and Manitoba."';

//include the top html page code
include 'top.php';

//select the design template to use in the body based on the $templates variable
$header='header'.$templates.'.htm';
$layouttopandleft='layouttopandleft'.$templates.'.htm';
$layoutrightandbottom='layoutrightandbottom'.$templates.'.htm';

//set page header
include $header;

//set top and left layout (usually includes navigation, google ads, and affiliate program
include $layouttopandleft;

//page specific content goes here, php scripts, text, images
?>

<?php
$sort=$_GET['sort'];
$submit=$_GET['submit'];
if ($sort==""){$sort="date";}
$today=date("Y").'-'.date("m").'-'.date("d");
?>
<center><h3>Fishing Reports on PrairieOutdoors.com</h3></center>
<center><a href="<?php echo $_SERVER['PHP_SELF'].'?submit=report'; ?>">Cast your fishing report</a> | <a href="http://www.prairieoutdoors.com/outdoors/favorite.php">Our Favorite Places</a></center><br>
<?php
if (isset($_POST['enter'])){
 	$province=$_POST['province'];
	$date=$_POST['date'];
	$species=$_POST['species'];
	$location=$_POST['location'];
	$rating=$_POST['rating'];
	if ($rating=="--choose a rating--"){$rating="none";}
	$comments=$_POST['comments'];
	$check=$_POST['check'];
	$code=$_POST['code'];
	include "../mysql_connect.php";
	$query="INSERT INTO fishingreports SET province='$province', date='$date', species='$species', location='$location', rating='$rating', comments='$comments'";
	$result=@mysql_query($query);
	if ($result) {
		  echo('<br><center><font size="2"> Thanks for your report.</font></center>');
		  mail('gsonntag@prairieoutdoors.com',$location,$species,"From: fishingreport@prairieoutdoors.com");
	} else {
		  echo '<p> database update failed</p>'.
            mysql_error() . '</p>';
    }
} 
if ($submit=="report"){
 
 //start randomcheck

$codelenght = 4;
while($newcode_length < $codelenght) {
$x=1;
$y=3;
$part = rand($x,$y);
if($part==1){$a=48;$b=57;}  // Numbers
if($part==2){$a=65;$b=90;}  // UpperCase
if($part==3){$a=97;$b=122;} // LowerCase
$code_part=chr(rand($a,$b));
$newcode_length = $newcode_length + 1;
$newcode = $newcode.$code_part;
}

//end randomcheck
 
?>

<h3>Enter your fishing report</h3>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
<table>
<tr>
<td>Province:</td><td>
<select name="province">
        <option>--choose the Province--</option>
        <option>AB</option>
        <option>SK</option>
        <option>MB</option>
      </select> 
</td>
</tr><tr>
<td>Species:</td><td>
<select name="species">
        <option>--choose the species--</option>
        <option>Walleye</option>
        <option>Pike</option>
        <option>Rainbow trout</option>
        <option>Brook trout</option>
        <option>Brown trout</option>
        <option>Lake Trout</option>
        <option>Perch</option>
        <option>Arctic Greyling</option>
      </select> 
</td>
</tr><tr>
<td>Date (yyyy-mm-dd):</td><td><input type="text" name="date" value="<?php echo $today; ?>"></td>
</tr><tr>
<td>Location:</td><td><input type="text" name="location"></td>
</tr>
<tr>
<td>Rating:</td><td>
<select name="rating">
        <option>--choose a rating--</option>
        <option>Slow</option>
        <option>Fair</option>
        <option>Good</option>
        <option>Excellent</option>
      </select> 
</td>
</tr><tr>
<tr>
<td>Comments:</td><td><textarea name="comments" rows="5" columns="60"></textarea></td>
</tr>
<tr><td>Enter the code in the box to the right:
<p align="right"><font size="3"><b><?php echo $newcode; ?></b></font></td>
<td><input type="text" name="code"></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Enter" name="enter">
<input type="hidden" name="check" value="<?php echo $newcode; ?>" >
</td>
</tr>
</table>
</form>

<?php 
}else{
 
 ?>
<table width="100%" border="1">
	<tr>
		<td><a href="<?php echo $_SERVER['PHP_SELF'].'?sort=province'; ?>"><font size="2">Province</a></td>
		<td><a href="<?php echo $_SERVER['PHP_SELF'].'?sort=species'; ?>"><font size="2">Species</td>
		<td><a href="<?php echo $_SERVER['PHP_SELF'].'?sort=date'; ?>"><font size="2">Date</td>
		<td><a href="<?php echo $_SERVER['PHP_SELF'].'?sort=location'; ?>"><font size="2">Location</td>
		<td><font size="2">Rating</td>
		<td><font size="2">Comments</td>
	</tr>

<?php	
if ($sort=="date"){$desc="DESC";}else{$desc="ASC";}
$query="SELECT * from fishingreports WHERE huntorfish='' ORDER BY $sort $desc";
include "../mysql_connect.php";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
	$province=$row['province'];
    $date=$row['date'];
	$species=$row['species'];
	$location=$row['location'];
	$rating=$row['rating'];
	$comments=$row['comments'];
	echo '<tr><td><font size="2">'.$province.'</td><td><font size="2">'.$species.'</td><td><font size="2">'.$date.'</td><td><font size="2">'.$location.'</td><td><font size="2">'.$rating.'</td><td><font size="2">'.$comments.'</td></tr>';
}
?>	
</table>
<br><center><a href="<?php echo $_SERVER['PHP_SELF'].'?submit=report'; ?>">Cast your fishing report</a> | <a href="http://www.prairieoutdoors.com/outdoors/favorite.php">Our Favorite Places</a></center>


<?php
}
//set right and bottom layout, includes bottom links and page closing body and html tags 
include $layoutrightandbottom;

?>
