<?php include("../header_test.php") ?>
<?php include("../menu_test.php") ?>
		<div id="content_main">
			<div id="sectionhead">
                OCEAN PICTURE OF THE DAY (OPOD)
			</div>
<?php include("../action/menu.php") ?>
		    <div id="right_col">
              <div id="content">
			  <table bgcolor="white" border="0" cellpadding="10" cellspacing="0" width="780">
                <tr>
                  <td align="center" valign="middle">
					<?php       
                    $hostname='mysql27.secureserver.net';
					$username='oceanweb';
					$password='password';
					$dbname='oceanweb';
                    $incoming=$_REQUEST['incoming'];
					$img_date = date("Y").'-'.date("m").'-'.date("d");
					$today = Date("Y-m-d");
					$tomorrow = date( "Y-m-d", strtotime ("+1 day" ) ) ;
					$yesterday = date( "Y-m-d", strtotime ("-1 day" ) ) ;
					$image_folder = "http://www.theoceanproject.org/opod/upload";
					if(isset($_REQUEST['date'])) {
						$img_date = $_REQUEST['date'];
						if ($img_date <= "2010-07-31") {
							$image_folder = "http://metothesea.org/upload";
						}
						if(substr($_REQUEST['date'],-2,1)=="-") {
							$t_day = (int)substr($_REQUEST['date'],-1) + 1;
							$y_day = (int)substr($_REQUEST['date'],-1) - 1;
						} else {
							$t_day = (int)substr($_REQUEST['date'],-2) + 1;
							$y_day = (int)substr($_REQUEST['date'],-2) - 1;
						}
						
						if ($t_day < 10) {
							$tomorrow = substr($_REQUEST['date'],0,7).'-0'.$t_day;
						} else {
							$tomorrow = substr($_REQUEST['date'],0,7).'-'.$t_day;												
						}
						if ($y_day < 10) {
							$yesterday = substr($_REQUEST['date'],0,7).'-0'.$y_day;
						} else {
							$yesterday = substr($_REQUEST['date'],0,7).'-'.$y_day;
						}
					}
					if ($tomorrow=="2009-09-31") {
						$tomorrow="2009-10-01";
					} else if ($tomorrow=="2009-10-32") {
						$tomorrow="2009-11-01";
					} else if ($tomorrow=="2009-11-31") {
						$tomorrow="2009-12-01";
					} else if ($tomorrow=="2009-12-32") {
						$tomorrow="2010-01-01";
					} else if ($tomorrow=="2010-01-32") {
						$tomorrow="2010-02-01";
					} else if ($tomorrow=="2010-02-29") {
						$tomorrow="2010-03-01";
					} else if ($tomorrow=="2010-03-32") {
						$tomorrow="2010-04-01";
					} else if ($tomorrow=="2010-04-31") {
						$tomorrow="2010-05-01";
					} else if ($tomorrow=="2010-05-32") {
						$tomorrow="2010-06-01";
					} else if ($tomorrow=="2010-06-31") {
						$tomorrow="2010-07-01";
					} else if ($tomorrow=="2010-07-32") {
						$tomorrow="2010-08-01";
					} else if ($tomorrow=="2010-08-32") {
						$tomorrow="2010-09-01";
					}
					
					if ($yesterday=="2009-10-00") {
						$yesterday="2009-09-30";
					} else if ($yesterday=="2009-11-00") {
						$yesterday="2009-10-31";
					} else if ($yesterday=="2009-12-00") {
						$yesterday="2009-11-30";
					} else if ($yesterday=="2010-01-00") {
						$yesterday="2009-12-31";
					} else if ($yesterday=="2010-02-00") {
						$yesterday="2010-01-31";
					} else if ($yesterday=="2010-03-00") {
						$yesterday="2010-02-28";
					} else if ($yesterday=="2010-04-00") {
						$yesterday="2010-03-31";
					} else if ($yesterday=="2010-05-00") {
						$yesterday="2010-04-30";
					} else if ($yesterday=="2010-06-00") {
						$yesterday="2010-05-31";
					} else if ($yesterday=="2010-07-00") {
						$yesterday="2010-06-30";
					} else if ($yesterday=="2010-08-00") {
						$yesterday="2010-07-31";
					} else if ($yesterday=="2010-09-00") {
						$yesterday="2010-08-31";
					}                    
                    
                    //connect to database
                    mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
                    
                    //select - use this database 
                    mysql_select_db($dbname);
			        
					$query = "SELECT first, last, name, caption, location FROM user, pic, submits WHERE user.id = submits.user_id AND pic.id = submits.picture_id AND submits.use_date = '".$img_date."' AND submits.status = 1 LIMIT 1";
                    
                    //echo 'Running Query: '.$query;						
                    $result = mysql_query($query);
                    if($result) {
                        if($row = mysql_fetch_array($result)){
							echo "<center><a href=\"$image_folder/".$row['name']."\" target=\"_blank\" border=\"0\"><img height=\"260\" src=\"$image_folder/".$row['name']."\" alt=\"$image_name\" /></a></center>"; 
                            echo '<center><p style="font-family:Verdana;font-size:12px;width:600;color:#2B76AD">';
                            echo $row['caption'];
                            echo '</p>';
							if(isset($_REQUEST['date'])) {
								echo 'Archive for: '.$_REQUEST['date']; 
                        	} else {
								print(Date("l, F d, Y")); 
                        	}
	                        echo '</p><p style="font-family:Verdana;font-size:12px;width:600">';
                            echo '<a href="index.php?date='.$yesterday.'"><--prev</a>    '.$row['location'].' image courtesy of '.$row['first'].' '.$row['last'].'    ';
							if ($tomorrow <= $today) {
								echo '<a href="index.php?date='.$tomorrow.'">next--></a>';
							}
                            echo '</p></center>';
                        } else {
	                        echo '<a href="index.php?date='.$yesterday.'"><--prev</a>    Sorry, We Have No Picture For '.$img_date.'    <a href="index.php?date='.$tomorrow.'">next--></a>';
						}
                    }
                    ?>
                  </td>
                </tr>
                <tr>
                    <td><p style="font-size:12px" align="center"><a href="upload_form.php">Submit an Ocean Picture Of the Day</a></p>
    				</td>
                </tr>
                <tr>
                    <td><p style="font-size:12px" align="center">
                    		<a href="http://antwrp.gsfc.nasa.gov/apod/astropix.html" target="_blank">Astronomy Picture of the Day</a>
                    		| <a href="http://epod.usra.edu/" target="_blank">Earth Science Picture of the Day</a></p><p> </p><p> </p><p style="font-size:12px" align="center"><a href="MonitorLogin.php" style="font-size: 12px">Moderator Login</a></p>
              
          </td></tr>
</table>
          <div id="totd" style="position:relative;top:-156px;left:584px;width:184px">
              <img src="action-day.gif" width="184px">
              <img src="../images/spacer.gif" height="200" width="5" align="left">
              <span>
                  <?php
                    $today = getdate();
                    $query="";
					$opdate = $today;
                    $i = $today['mday'];
                    $j = $today['mon'];

					if(isset($_REQUEST['date'])) {
                    	$opdate = $_REQUEST['date'];
					} else {
						if ($j < 10) {
							if ($i < 10) {
								$opdate = $today['year'].'-0'.$j.'-0'.$i;
							} else {
								$opdate = $today['year'].'-0'.$j.'-'.$i;
							}
						} else {
							if ($i < 10) {
								$opdate = $today['year'].'-'.$j.'-0'.$i;
							} else {
								$opdate = $today['year'].'-'.$j.'-'.$i;
							}
						}
					}
                                                       
                    //Connect To Database
                    $hostname='mysql27.secureserver.net';
                    $username='oceanweb';
                    $password='password';
                    $dbname='oceanweb';
                    mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
                    mysql_select_db($dbname);
					$query = 'SELECT tip FROM tips WHERE last_use = \''.$opdate.'\' LIMIT 1';
                    $result = mysql_query($query);
                    if($result) {
                        while($row = mysql_fetch_array($result)) {
                            echo $row['tip'];
                        }
                    }
                    echo "\n";
                  ?>
              </span>
        	</div>
          </div>
        </div>
        <div id="footer" style="left:464px;top:712px">
        <table>
            <tr>
                <td style="background:transparent">
<?php include("../footer_div.php") ?>
</div>
</body>
</html>