<?php
require_once 'localtime2.php';
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
##  Whilst this source code is freely available to view, it is strictly for educational use only. 
##  All the code is written by myself, and most of the equations are derived from 'Astronomical Algorithms' by Jean Meeus. 
##  The code is therefore copyrighted and no part may be reproduced without permission.
##  David Campbell
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <link rel="stylesheet" type="text/css" href="printstyle.css" media="print" />  
  <link rel="stylesheet" type="text/css" href="astro.css" media="screen" />
<title>12 Dimensional String</title>
</head>
<body>

<div class="wholepage">

<div id="header">
         <div class="superheader">&nbsp;</div>
         <div class="mainheader"><h1>12 Dimensional String</h1><p><script src="header.js"></script></p></div>
         <div class="subheader">&nbsp;</div>
</div>

<div id="sidecontainer">
         <h2>Navigation</h2>
         <SCRIPT src="menu.js">
</SCRIPT>
        
</div>
<div id="content">
         <h1>Sunset and Sunrise times </h1>
        
           <p>
    
<?php


$nowday
=date('j');
$nowyear=date('Y');
$nowmonth=date('n');
if(isset(
$_COOKIE['latitude'])){
    
$lat $_COOKIE['latitude']; 
}else{
    
$lat = ('51.479184');
}
if(isset(
$_COOKIE['longitude'])){
    
$long $_COOKIE['longitude']; 
}else{
    
$long = ('0');
}    

if ( isset(
$_GET['day']) ) { $_SESSION['sunday'] = $_GET['day'];}
$day $_SESSION['sunday']; 
if (
$day == "")
{
$day $nowday; }
if ( isset(
$_GET['month']) ) { $_SESSION['sunmonth'] = $_GET['month'];}
$month $_SESSION['sunmonth']; 
if (
$month == "")
{
$month $nowmonth; }
if ( isset(
$_GET['year']) ) { $_SESSION['sunyear'] = $_GET['year'];}
$year $_SESSION['sunyear']; 
if (
$year == "")
{
$year $nowyear; }
if (
$month 2){
$M2 $month;
$Y $year;
}else{
$M2 = ($month +12);
$Y = ($year 1);
}
$A floor($Y/100);
$B $A floor($A/4);
$JDE = (floor(365.25 * ($Y 4716))) + (floor(30.6001*($M2+1))) + $day $B 1524.5;
$T = ($JDE 2451545.0)/36525;
$y $year + (($month 0.5)/12);
$ty $y 2000;
$deltaT 62.92 + (0.32217 $ty) + (0.005589 $ty $ty);
$L0pre 280.46646 + ($T *(36000.76983 + (0.0003032 $T)));
if (
$L0pre 0){
$L0 $L0pre + ((- (floor($L0pre/360)))*360);
}else{
if (
$L0pre 360){
$L0 $L0pre - ((floor($L0pre/360))*360);
}else{
$L0 $L0pre;
}}
$Mpre357.52911 + ($T *(35999.05029 + (0.0001537 $T)));
if (
$Mpre 0){
$M $Mpre + ((- (floor($Mpre/360)))*360);
}else{
if (
$Mpre 360){
$M $Mpre - ((floor($Mpre/360))*360);
}else{
$M $Mpre;
}}
$e0.016708634 - ($T *(0.000042037 + (0.0000001267 $T)));
$C = + ((1.914602 - ($T *(0.004817 + (0.000014 $T))))* (sin(deg2rad($M))))
    + ((
0.019993 - ($T 0.000101 ))* (sin(deg2rad(2*$M))))
    + 
0.000289 * (sin(deg2rad(3*$M)));
$Slon $L0 $C;
$v $M $C;
$R = (1.000001018 * (- ($e*$e)))/(+ ($e * (cos(deg2rad($v)))));
$omega 125.04452 - (1934.136261*$T) + (0.0020708 *$T $T) + (($T*$T*$T)/450000);
$L 280.4665 + (36000.7698 $T);
$Ldash 218.3165 + (481267.8813 $T);
$deltaepsilon = (((9.20/3600) * (cos(deg2rad($omega)))) + ((0.57/3600) * (cos(deg2rad(2*$L)))) + ((0.10/3600) * (cos(deg2rad(2*$Ldash)))) - ((0.09/3600) * (cos(deg2rad(2*$omega)))));
$epsilon0 23.4392911111 - (0.013004166667 *$T) - ((1.63889/10000000) *$T $T) + ($T*$T*$T * (5.03611/10000000));
$epsilon $epsilon0 $deltaepsilon;
$Sra2 rad2deg(atan2(((cos(deg2rad($epsilon)))*(sin(deg2rad($Slon)))),(cos(deg2rad($Slon)))));
$Sdec2 rad2deg(asin((sin(deg2rad($epsilon)))*(sin(deg2rad($Slon)))));
$h0= -0.83333;
$H0rad2deg(acos((sin(deg2rad($h0))) - ((sin(deg2rad($lat)))*(sin(deg2rad($Sdec2))))/((cos(deg2rad($lat))) * (cos(deg2rad($Sdec2))))));
$theta0pre=100.46061837 + (36000.770053608 $T) + (0.000387933 $T $T) - (($T*$T*$T)/38710000);
if (
$theta0pre 0){
$theta0 $theta0pre + ((- (floor($theta0pre/360)))*360);
}else{
if (
$theta0pre 360){
$theta0 $theta0pre - ((floor($theta0pre/360))*360);
}else{
$theta0 $theta0pre;
}}
$m0pre = ($Sra2 + ($long) - $theta0pre)/360;
if (
$m0pre 0){
$m0 $m0pre + ((- (floor($m0pre/1)))*1);
}else{
if (
$m0pre 1){
$m0 $m0pre - ((floor($m0pre/1))*1);
}else{
$m0 $m0pre;
}}
$m1 =  $m0 - ($H0/360);
$m2 =  $m0 + ($H0/360);
$theta0m1 $theta0 + (360.985647 $m1);
$theta0m2 $theta0 + (360.985647 $m2);
$n1 $m1 + ($deltaT 86400);
$n2 $m2 + ($deltaT 86400);

$JDE1 = (floor(365.25 * ($Y 4716))) + (floor(30.6001*($M2+1))) + ($day 1) + $B 1524.5;
$T1 = ($JDE1 2451545.0)/36525;
$L0pre1 280.46646 + ($T1 *(36000.76983 + (0.0003032 $T1)));
if (
$L0pre1 0){
$L01 $L0pre1 + ((- (floor($L0pre1/360)))*360);
}else{
if (
$L0pre1 360){
$L01 $L0pre1 - ((floor($L0pre1/360))*360);
}else{
$L01 $L0pre1;
}}
$Mpre1357.52911 + ($T1 *(35999.05029 + (0.0001537 $T1)));
if (
$Mpre1 0){
$M1 $Mpre1 + ((- (floor($Mpre1/360)))*360);
}else{
if (
$Mpre1 360){
$M1 $Mpre1 - ((floor($Mpre1/360))*360);
}else{
$M1 $Mpre1;
}}
$e10.016708634 - ($T1 *(0.000042037 + (0.0000001267 $T1)));
$C1 = + ((1.914602 - ($T1 *(0.004817 + (0.000014 $T1))))* (sin(deg2rad($M1))))
    + ((
0.019993 - ($T1 0.000101 ))* (sin(deg2rad(2*$M1))))
    + 
0.000289 * (sin(deg2rad(3*$M1)));
$Slon1 $L01 $C1;
$v1 $M1 $C1;
$R1 = (1.000001018 * (- ($e1*$e1)))/(+ ($e1 * (cos(deg2rad($v1)))));
$omega1 125.04452 - (1934.136261*$T1) + (0.0020708 *$T1 $T1) + (($T1*$T1*$T1)/450000);
$L1 280.4665 + (36000.7698 $T1);
$Ldash1 218.3165 + (481267.8813 $T1);
$deltaepsilon1 = (((9.20/3600) * (cos(deg2rad($omega1)))) + ((0.57/3600) * (cos(deg2rad(2*$L1)))) + ((0.10/3600) * (cos(deg2rad(2*$Ldash1)))) - ((0.09/3600) * (cos(deg2rad(2*$omega1)))));
$epsilon01 23.4392911111 - (0.013004166667 *$T1) - ((1.63889/10000000) *$T1 $T1) + ($T1*$T1*$T1 * (5.03611/10000000));
$epsilon1 $epsilon01 $deltaepsilon1;
$Sra1 rad2deg(atan2(((cos(deg2rad($epsilon1)))*(sin(deg2rad($Slon1)))),(cos(deg2rad($Slon1)))));
$Sdec1 rad2deg(asin((sin(deg2rad($epsilon1)))*(sin(deg2rad($Slon1)))));
///////////////////////////
$JDE3 = (floor(365.25 * ($Y 4716))) + (floor(30.6001*($M2+1))) + ($day 1) + $B 1524.5;
$T3 = ($JDE3 2451545.0)/36525;
$L0pre3 280.46646 + ($T3 *(36000.76983 + (0.0003032 $T3)));
if (
$L0pre3 0){
$L03 $L0pre3 + ((- (floor($L0pre3/360)))*360);
}else{
if (
$L0pre3 360){
$L03 $L0pre3 - ((floor($L0pre3/360))*360);
}else{
$L03 $L0pre3;
}}
$Mpre3357.52911 + ($T3 *(35999.05029 + (0.0001537 $T3)));
if (
$Mpre3 0){
$M3 $Mpre3 + ((- (floor($Mpre3/360)))*360);
}else{
if (
$Mpre3 360){
$M3 $Mpre3 - ((floor($Mpre3/360))*360);
}else{
$M3 $Mpre3;
}}
$e30.016708634 - ($T3 *(0.000042037 + (0.0000001267 $T3)));
$C3 = + ((1.914602 - ($T3 *(0.004817 + (0.000014 $T3))))* (sin(deg2rad($M3))))
    + ((
0.019993 - ($T3 0.000101 ))* (sin(deg2rad(2*$M3))))
    + 
0.000289 * (sin(deg2rad(3*$M3)));
$Slon3 $L03 $C3;
$v3 $M3 $C3;
$R3 = (1.000001018 * (- ($e3*$e3)))/(+ ($e3 * (cos(deg2rad($v3)))));
$omega3 125.04452 - (1934.136261*$T3) + (0.0020708 *$T3 $T3) + (($T3*$T3*$T3)/450000);
$L3 280.4665 + (36000.7698 $T3);
$Ldash3 218.3165 + (481267.8813 $T3);
$deltaepsilon3 = (((9.20/3600) * (cos(deg2rad($omega3)))) + ((0.57/3600) * (cos(deg2rad(2*$L3)))) + ((0.10/3600) * (cos(deg2rad(2*$Ldash3)))) - ((0.09/3600) * (cos(deg2rad(2*$omega3)))));
$epsilon03 23.4392911111 - (0.013004166667 *$T3) - ((1.63889/10000000) *$T3 $T3) + ($T3*$T3*$T3 * (5.03611/10000000));
$epsilon3 $epsilon03 $deltaepsilon3;
$Sra3 rad2deg(atan2(((cos(deg2rad($epsilon3)))*(sin(deg2rad($Slon3)))),(cos(deg2rad($Slon3)))));
$Sdec3 rad2deg(asin((sin(deg2rad($epsilon3)))*(sin(deg2rad($Slon3)))));

$ara = ($Sra2 $Sra1);
$bra = ($Sra3 $Sra2);
$cra = ($bra $ara);
$adec = ($Sdec2 $Sdec1);
$bdec = ($Sdec3 $Sdec2);
$cdec = ($bdec $adec);

$Sram1 $Sra2 + (($n1/2) * ($ara $bra + ($n1 $cra)));
$Sram2 $Sra2 + (($n2/2) * ($ara $bra + ($n2 $cra)));
$Sdecm1 $Sdec2 + (($n1/2) * ($adec $bdec + ($n1 $cdec)));
$Sdecm2 $Sdec2 + (($n2/2) * ($adec $bdec + ($n2 $cdec)));-

$Hm1 $theta0m1 - ($long) - $Sram1;
$Hm2 $theta0m2 - ($long) - $Sram2;
$hm1 rad2deg(asin(((sin(deg2rad($lat)))*(sin(deg2rad($Sdecm1)))) + ((cos(deg2rad($lat)))*(cos(deg2rad($Sdecm1)))*(cos(deg2rad($Hm1))))));
$hm2 rad2deg(asin(((sin(deg2rad($lat)))*(sin(deg2rad($Sdecm2)))) + ((cos(deg2rad($lat)))*(cos(deg2rad($Sdecm2)))*(cos(deg2rad($Hm2))))));
$deltam1 = ($hm1 $h0) / ( 360 * (cos(deg2rad($Sdecm1)))*(cos(deg2rad($lat)))*(sin(deg2rad($Hm1))));
$deltam2 = ($hm2 $h0) / ( 360 * (cos(deg2rad($Sdecm2)))*(cos(deg2rad($lat)))*(sin(deg2rad($Hm2))));







$rise = (($m1 $deltam1) * 24)+$offset;
$set = (($m2 $deltam2) * 24)+$offset;
$riseh floor ($rise);
$risempre floor((($rise $riseh) *60));
if (
$risempre 10){
$risem "0$risempre";
}else{
$risem $risempre;
}
$seth floor ($set);
$setmpre floor((($set $seth) *60));
if (
$setmpre 10){
$setm "0$setmpre";
}else{
$setm $setmpre;
}

if (
$day  == 1){
$suf 'st';
}
if (
$day  == 2){
$suf 'nd';
}
if (
$day  == 3){
$suf 'rd';
}
if (
$day  == 21){
$suf 'st';
}
if (
$day == 22){
$suf 'nd';
}
if (
$day == 23){
$suf "rd";
}
if (
$day == 31){
$suf "st";
}
if (
$suf == "")
{
$suf 'th'; }


if (
$month == 1){
$mon 'January';}
if (
$month == 2){
$mon 'February';}
if (
$month == 3){
$mon 'March';}
if (
$month == 4){
$mon 'April';}
if (
$month == 5){
$mon 'May';}
if (
$month == 6){
$mon 'June';}
if (
$month == 7){
$mon 'July';}
if (
$month == 8){
$mon 'August';}
if (
$month == 9){
$mon 'September';}
if (
$month == 10){
$mon 'October';}
if (
$month == 11){
$mon 'November';}
if (
$month == 12){
$mon 'December';}

echo 
"<br><br><b>Sunset and Sunrise times for: $day$suf $mon $year<br><br><br><br>Rise time = $riseh:$risem Local time<br>";
echo 
"Set time = $seth:$setm Local time<br></b><br><br>";


echo 
"(<A HREF=\"javascript:void(0)\"
onclick=\"window.open('location.htm','location','width=500,height=280',status='no')\">Set your location </A>- currently "
;


if (
$lat 0){
$lat1 $lat;
echo 
round($lat1,2);
echo 
"S/";
}else{
echo 
round($lat,2);
echo 
"N/";
}
if (
$long 0){
$long1 $long;
echo 
round($long1,2);
echo 
"W)";
}else{
echo 
round($long,2);
echo 
"E)";
}

echo
"<br>
<form action='suntimes.php' method='get'><table style=\"border-width:thin; border-color:#333333; border-style:solid\" >
<tr><td>Day (1-31):</td><td><input type=\"text\" name=\"day\" size=\"2\" value=\"$day\"></td></tr><tr>
<td>Month (1-12):</td><td><input type=\"text\" name=\"month\" size=\"2\" value=\"$month\"></td></tr><tr>
<td>Year (4-digit):</td><td><input type=\"text\" name=\"year\" size=\"4\" value=\"$year\"></td></tr><tr>
<td>&nbsp;</td><td align=\"right\"><input type=\"submit\" value=\"Submit\"></td></tr></table></form>"
;

?> <br><br><font size="1">Equations derived from 'Astronomical Algorithms' by Jean Meeus. <a href="suntimes.phps" target="_blank">View page source</a> </font></p>

</div>

<div id="footer">
         <div class="superfooter"></div>
         <div class="mainfooter">
         <p><script src="footer.js"></script></p>
         </div>
         <div class="subfooter"></div>
</div>


</div>
</body>
</html>