<?php
// set a variable to determine which design templates to use
$templates="1";
//set page specific variables
$title="Fishing Photo Contest | PrairieOutdoors.com";
$keywords='"Alberta fishing pictures, Saskatchewan fishing pictures, Manitoba fishing pictures, fishing story pictures, fishing photos, fishing pictures, fishing photo contest"';
$description='"Fishing photo contest from Alberta, Saskatchewan and Manitoba Canada"';
//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

if (isset($_POST['submit'])){
 
	if ( ($_FILES['uploadfile']['type']=="image/jpeg") OR ($_FILES['uploadfile']['type']=="image/pjpeg") OR ($_FILES['uploadfile']['type']=="image/gif")){
		$setimagewidth=800;
		$setthumbwidth=150;
		if ( ($_FILES['uploadfile']['type']=="image/jpeg") OR ($_FILES['uploadfile']['type']=="image/pjpeg")){
			include 'upload-jpeg.php';
		}else{
			include 'upload-gif.php';
		}

	$caption=$_POST['caption'];
	$des=$_POST['des'];
	$species=$_POST['species'];
	$otherspecies=$_POST['otherspecies'];
	if ($otherspecies<>""){
	 	$species=$otherspecies;
	}
	$month=date("F");
	$subby=$_POST['subby'];
	$subname=$_POST['subname'];
	include "../mysql_connect_po.php";
    $query = "INSERT INTO photocontest SET caption='$caption', subby='$subby',subname='$subname',description='$des',image='$image', month='$month',thumb='$thumb',type='fish', species='$species', frm='s3', subdate=CURDATE()";
    $result=@mysql_query($query);
    if ($result) {
		echo('<center><font face="Arial" size="2"> Thanks for your item.</font></center>');
		mail('gsonntag@prairieoutdoors.com',$caption,$des,"From: fishingphotocontest@s3outdoors.com");
	}
	
//get image id of newest entry
$query = "SELECT * FROM photocontest ORDER BY id";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){ 
     $imageid=$row['id'];
}
//add a rating of 3 to newest entry

    $query = "INSERT INTO photocontestrating SET imageid='$imageid', r='3', month='$month', subdate=CURDATE()";
    $result=@mysql_query($query);
  
	// add details to campfire db table

	$location=$_POST['location'];
	$query = "INSERT INTO campfire SET date=CURDATE(), text='$des', location='$location', alttext='$caption', image='$image', timage='$thumb', category='fishing', species='$species', frm='s3', submitted_date=CURDATE()";
        $result=@mysql_query($query);
        if ($result) {
		  mail('gjs@s3outdoors.com',$caption,$des,"From: campfire@s3outdoors.com");
        } 
	echo '<center></br></br></br></br><font size="4">Thanks for your entry to the Fishing Photo contest.</br></br>
	<a href="'.$_SERVER['PHP_SELF'].'">See all entries.</a></font></center>';
	}else{
	 	echo '<p align="center""><font color="red" size="3">Invalid File Type.  Please upload a gif or jpeg file.</font></p>';
	}

}else{
if (isset($_POST['sendrating'])){
	$rating=$_POST['rating'];
	$imageid=$_POST['imageid'];
	$month=date("F");
	include "../mysql_connect_po.php";
    $query = "INSERT INTO photocontestrating SET imageid='$imageid', r='$rating', month='$month', subdate=CURDATE()";
    $result=@mysql_query($query);
    if ($result) {
		echo '</br></br></br></br><center><font size="4"><b>Thanks, the rating was saved.</b></font></center>';
	}else{
		echo 'rating entry to db failed: '.mysql_error();
	}
}
if ($_GET['form']=='yes'){
	?>
	<h1>Fishing Photo Contest</h1>
 
	<font size="+2">Fill out the form below and then click submit to enter the photo contest.</font></br>
	<p>UPLOAD JPG OR JPEG FILES ONLY PLEASE</p>
	<form action="<?=$_SERVER['PHP_SELF']?>" method="post" ENCTYPE="multipart/form-data">
	<table border="0">
	<tr>
	<td>File (max size = 2MB, JPG or JPEG):</td><td> <input type="file" id="uploadfile" name="uploadfile" size="50"></td></tr>
	<tr><td>Caption:</td><td><input type="text" name="caption" size="40"></td></tr>
	<tr><td>Species:</td><td><select name="species">
		<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>Sturgeon</option>
		</select>
		</td></tr>
	<tr><td>Other Species:</td><td><input type="text" name="otherspecies" size="40"></td></tr>
	<tr><td>Description:</td><td><textarea name="des" cols=40 rows=5></textarea></td></tr>
	<tr><td>Location:</td><td><input name="location" size="35"></td></tr>
	<tr><td>Your Email (required for contest entry):</td><td> <input type="text" name="subby" size="40"></td></tr>
	<tr><td>Your Name (required for contest entry):</td><td> <input type="text" name="subname" size="40"></td></tr>
	<input type="hidden" name="type" value="fish">
	<tr><td></td><td><input name="submit" type="submit" value="Submit"></td></tr>
	</form>
	<tr><td>Click the submit button only once.</td></tr>
	</table>
	<?php
}else{
 	?>
		<a name="label">  </a> 
      <div align="center">
      <h1>Fishing Photo Contest</h1>
 
      Welcome to the monthly fishing photo contest on S3Outdoors.com.   Here you will be able to send in your own trophy pictures for others to vote on.  Each month, the highest rated fishing photo will be awarded "Fishing Photo of the Month".  You can view our archive of past monthly contests and winners.

      <font size=-1 face="Tahoma">Select the month to view contest pictures:</br>
      <?php
    $query="SELECT * FROM photocontest GROUP BY month ORDER BY subdate";
	include "../mysql_connect_po.php";
	$result=mysql_query($query);
	while ($row = mysql_fetch_array($result)){ 
	 	$month=$row['month'];
    	echo '<a href="'.$_SERVER['PHP_SELF'].'?showmonthsub='.$month.'">'.$month.'</a> ';
    }
	?> 
        </div>
<p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?form=yes"><font size=+1>Join the Contest.  Send us your pictures.</font></a>
 | See also the <a href="hunting-photo-contest.php">Hunting Photo Contest</a>
<hr width="100%">
<?php

// put banner ad code here

?>

<table BORDER="1" WIDTH="100%" >
<tr>
<td><font size=2 face="Tahoma">Fishing Photo Contest Entries</font>
<?php
if (isset($_GET['showmonthsub'])){
	$showmonth=$_GET['showmonthsub'];
}else{
   $showmonth=date("F");
}
echo '</td><td><font size=2>Month: '.$showmonth.'</td></tr>';

$count=0;
include "../mysql_connect_po.php";

$query2 = "SELECT imageid, avg(r) as avg FROM photocontestrating GROUP BY imageid ORDER BY avg DESC";
$result2=mysql_query($query2);
while ( $row = mysql_fetch_array($result2)){
	$avg=round($row['avg'],2);
	$imageid=$row['imageid'];

	$query="SELECT * from photocontest WHERE id='$imageid' AND month='$showmonth' AND type='fish'";
	$result=mysql_query($query);
	while ($row = mysql_fetch_array($result)){
	    	$subdate=$row['subdate'];
	    	$image=$row['image'];
	    	$thumb=$row['thumb'];
	    	$caption=$row['caption'];
	    	$frm=$row['frm'];
	    	$count++;
		if ($count==1){echo '<tr>';}
		echo '<td>';
		echo '<font face="tahoma" size="2">'.$caption.'</br>';
    	if ($frm=="s3"){    		
			 	echo '<a href="http://www.s3outdoors.com/'.$image.'" target="_blank"><img src="http://www.s3outdoors.com/'.$thumb.'" alt="'.$caption.'" border="0"></a>';
			}else{
    		echo '<a href="http://www.prairieoutdoors.com/'.$image.'" target="_blank"><img src="http://www.prairieoutdoors.com/'.$thumb.'" alt="'.$caption.'" border="0"></a>';
    		}
			echo '</br>Current Rating: '.$avg.'
			</center>';
		?>
		<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
		Rating (1=low, 5=high): 
		<select name="rating">
		<option>1</option>
		<option>2</option>
		<option>3</option>
		<option>4</option>
		<option>5</option>
		</select>
		</br>	<input type="hidden" name="imageid" value="<?php echo $imageid; ?>">
		</br><input type="submit" name="sendrating" value="Send Rating">
		</form>
		<?php
	}
	echo '</td>';
	if ($count==4){echo '</tr>';}
}
if (!($count==4)){echo '</tr>';}
?>
</table>

<p align="center"><font size=-1 face="Tahoma">Send us your <a href="<?php echo $_SERVER[PHP_SELF]; ?>?form=yes"><font size=+1>fishing pictures</font></a>.</font>
<hr width="100%">
        <font face="Tahoma">
<br><b><font size=-1><a href="#top">Back to Top of Page</a></font></b>
        </font>
<?php
}
}
//set right and bottom layout, includes bottom links and page closing body and html tags 
include $layoutrightandbottom;
?>