#!/usr/bin/env php
<?php

# Script:   Eryss.phpb
#
# by Apollia - http://apollia.com/
#
# http://eryss.com/
#
#
#-------------------------------------------------------------------------------
#
# 03:42:00 08/05/2019.  Text written in 2013 follows:
#
#
# Shows astrological positions, with house data.  By default, the data shown is
# for the present moment in Hubbard, OH (80:34W, 41:09N), but can display data
# for lots of other dates and locations. 
#
# To do that:
#
#	* Use a Bash script titled Date-Time-Location Prompt [...]
#
# Or,
#
#	* Change the $Chart_Data variable and/or $Longitude and $Latitude.
#
# Or,
#
#	* Send a command line argument to this script containing date/time/location
#     data.
#
#
# I haven't built in anything to handle non-Gregorian calendar dates, so,
# probably the wrong astrological data will be displayed for dates before
# about 1753.
#
# http://en.wikipedia.org/wiki/Calendar_%28New_Style%29_Act_1750
#
#
# By default, shows every asteroid and dwarf planet you have in your
# Swiss Ephemeris folder.
#
# Can be configured to show only the celestial objects you want, or to
# exclude ones you don't want.
#
# Can open Astrolog 5.40 for you.  Can output an HTML web page with
# astrological data and convenient links to info about the listed
# celestial objects, and can automatically display that page in your
# default web browser.
#
#
#-------------------------------------------------------------------------------
# 
# 
# Under the GNU Affero General Public License v3.0.
# 
# 
# Copyright (C) 2013-2019  Apollia
# 
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as published
#     by the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
# 
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
# 
# Contact info:     http://astroblahhh.com/contact-apollia.shtml
# 
# ---- 



#*****************************************************************************
#
# Settings you can change. 
#
#

$Eryss_Version = "0.1";

$Swiss_Ephemeris_Folder = "/root/sweph/";
	# Only necessary to change if you put your Swiss Ephemeris folder
	# somewhere other than: /root/sweph/


$Should_Display_Original_Chart_Data_Line = true;

$Should_Display_When_Calculated_Date = true;
$Should_Display_Julian_Day = true;

$Should_Display_HTML_Page_Footer = true;


$Custom_HTML_Comment = "";


$Default_Search_Engine = "Bing";
	# Possibilities:
	#	
	#	AOL
	#	Bing
	#	Dogpile
	#	Google (its links doesn't work right with the Dillo web browser, as of 7:54:31 4/7/2013)
	#	Yahoo


$Default_Calculation_Type = "Tropical";
	# Possibilties:
	#	
	#	Tropical
	#	Sidereal
	#	Heliocentric


$Default_House_Method = "Placidus";
	# Possibilities (long name or abbreviation)
	#
	#	Placidus				# P
	#	Koch					# K
	#	Porphyrius				# O
	#	Regiomontanus			# R
	#	Campanus				# C
	#	Equal					# E
	#	Vehlow equal			# V
	#	Whole sign				# W
	#	Axial rotation system	# X
	#	Azimuthal (horizontal)	# H
	#	Polich/Page				# T
	#	Alcabitus				# B
	#	Morinus					# M
	#	Krusinski-Pisa			# U


$Web_Browser_Shell_Command = "defaultbrowser";
	# Possibilities:
	#	
	#	dillo
	#		A fast but primitive web browser.  
	#		Installed in many Puppies by default.
	#		
	#		Much faster than Firefox and Chromium.
	#		
	#	firefox
	#	chromium
	#		These will work if you have them installed.  Will be slow for
	#		large files.
	#	
	#	defaultbrowser
	#		Whatever your default browser is set to be.
	#		
	#		It can be changed by editing this file:
	#		/usr/local/bin/defaultbrowser


$Should_Output_in_Zodiacal_Order = true;
$Should_Output_in_Arbitrary_Order = true;

$Should_Output_in_Zodiacal_Order_First = true;
	# Only applies to HTML file.

$Should_Output_HTML_Page = true;
$Should_Display_HTML_Page = true;

$Should_Display_Compact_HTML_Table_of_Houses=false;
	# If true, then displays only 6 table cells containing details
	# about opposing houses, instead of 12 total table cells
	# (1 for each house).
	
$Should_Display_Unicode_Astro_Glyphs_in_HTML_Page=true;
$Should_Display_Astro_Names_in_HTML_Page = true;

$Full_Path_to_Temporary_HTML_Page_for_Chart = "/tmp/Temporary_File_of_Astrological_Positions_with_Houses.html";


$Astrolog_540_Folder="/mnt/truecrypt1/Observatory/ast54unx/";
	# If you have Astrolog 5.40, you can have this script automatically open
	# Astrolog 5.40 after running.
	#
	#	http://astrolog.org/

$Should_Open_Chart_in_Astrolog_540=false;

$Chart_Data = "";

# $Chart_Data = "July 3 1981 12:50 EDT 79:59W 40:26N";

# You can customize this $Chart_Data variable with a remarkable variety of text.
#
# Or, you can leave it empty, in which case this script will just display
# astrological positions for the present moment using the longitude/latitude
# settings in $Longitude and $Latitude.
#
# If you send a command line argument to this script, this script will use that
# as the value of $Chart_Data instead of the above.
#
#
# Example line of chart data that works, featuring my (Apollia's) birth data: 
#
#	July 3 1981 12:50 EDT 79:59W 40:26N
#
# (That longitude/latitude is for Pittsburgh, PA.)
#
# Almost just like an Astrolog 5.40 command line. :-)
#
#
# Other valid lines:
#
#		July 3, 1981 12:50 PM EDT
#		
#		yesterday 5 PM
#		thursday 15:17
#		20-8-1890 9 am
#		noon 1795 7 sep.
#		
#		2 months 5 days ago
#		
#		next week 
#		next month
#		
#		now
#		today						# Today at midnight.
#		noon
#		midnight
#		midnight PST				# Midnight in Pacific Standard Time.
#		
#		yesterday					# Yesterday at midnight.
#		1 day ago					# Yesterday at same time as current time.
#		
#		tomorrow					# Tomorrow at midnight.
#		next day					# Tomorrow at same time as current time.
#		1 day						# Tomorrow at same time as current time.
#		1 days
#		
#		Monday						# Next Monday at midnight.
#		last Monday					# Last Monday at midnight.
#		previous Monday				# Last Monday at midnight.
#
#		2 days						# Two days from now, with current time.
#		second day					# Two days from now, with current time.
#	
#		2 days ago					# Two days ago, with current time.
#		2 years ago					# Two years ago, with current time.
#
#	
# Those optionally can all be ended with location data, like:  79:59W 40:26N
#
#
# A location is optional.  If you don't include one, the default location set
# in the $Longitude and $Latitude variables will be used.
#
# If you do include a location, it must be at the end, in a format like this:
#
#	80:34W 41:09N
#
# Seconds are OK too: 
#
#	80:34:09W 41:09:23N
#
# It doesn't matter what order the longitude/latitude are in.
#
# (That longitude/latitude is for Hubbard, OH.)
#
#
# The dates/times you can input are fairly flexible, since I used the DateTime class.  
#
#	http://www.php.net/manual/en/datetime.formats.php
#	http://www.php.net/manual/en/book.datetime.php
#
# Alas, various useful DateTime class features didn't come into being until
# PHP 5.3, so DateTime->add(), DateTime->sub(), the DateInterval class, and
# various other things aren't available.
#
# But fortunately, all I really needed was to be able to convert time zones
# easily, and that feature was there.
#
#
# Invalid dates/times (or with unexpected results):
#
#		yesterday at 5 PM
#		20/8/1890 9 PM
#		Monday previous
#		5 o'clock
#		seven PM
#		sunrise
#		sunset
#		a day ago		
#		day ago
#		1 day from now
#		1 day hence
#		two years ago
#	
#
# Below are the default latitude/longitude used if no $Chart_Data is provided,
# or the location in it is misformatted.  
#	
# Default:      Hubbard, OH       80:34W   41:09N

$Longitude = "80:34W";
	# Use this format: 80:34W
	# Seconds are OK too: 80:34:09W


$Latitude = "41:09N";
	# Use this format: 41:09N
	# Seconds are OK too: 41:09:23N

	
# To remember the difference between longitude and latitude, just remember
# that latitude is spelled almost the same as "altitude" - up/down.
# And north/south on a map (latitude) looks like up/down.


$Should_Display_Full_Error_Messages = true;
# If true, then, if $Chart_Data can't be interpreted, the full error messages
# PHP provides are shown.


$Should_Display_Longitude_Speed = true;

$Should_Show_Long_Sign_Names = true;
	# If you'd like to see the full sign names (like Aries), set to true.
	#
	# If you prefer only three-letter sign names (like Ari), set to false.



$Should_Round_Off_Arc_Seconds = true;
# Arc seconds are a tiny segment of an astrological chart. 
#
# http://en.wikipedia.org/wiki/Minute_of_arc
#
# Larger, related units are degrees and arc minutes. 
#
# If you want your arc seconds to be displayed as long messy floating point
# numbers instead of rounded off, set to false. 


$Should_Display_360_Degree_Absolute_Zodiacal_Position_of_Objects = true;
	# Also known as zodiacal longitude.
	# http://www.skyscript.co.uk/gl/ablong.html

$Should_Display_360_Degree_Absolute_Zodiacal_Position_of_House_Cusps = true;

$Should_Display_House_Data = true;
	
$Should_Display_Main_Celestial_Objects = true;
# Sun, Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto.
#
# Plus the mean north moon's node, true north moon's node, mean apogee and 
# osc. apogee (both sometimes referred to as "Lilith"), even though they're
# maybe not as important as the others.  
#
# I just didn't want to have to make more separate arrays for celestial objects,
# nor did I want to put them in the array with Ceres, etc., since I do find the
# nodes and Lilith a bit more interesting than the ones there.


$Should_Use_All_Available_Ephemerides_for_Asteroids_Etc = true;
	# Set to false if you'd rather pick and choose amongst the available 
	# asteroids and dwarf planets.
	#
	# Then, add the ones you want (if any) to the $specific_asteroids_etc
	# array.

$Should_Display_Ceres_Chiron_Pholus_Pallas_Juno_Vesta = true;

$Should_Display_All_Dwarf_Planets_Besides_Pluto_and_Ceres = true;
	# Set to false if you'd rather not use dwarf planets besides Pluto and
	# Ceres.
	#
	# Even with this set to false, you can add dwarf planets to the 
	# $specific_asteroid_etc array.

	

# ****************************************

$specific_asteroids_etc = array
(
# Will only be used if $Should_Use_All_Available_Ephemerides_for_Asteroids_Etc
# is false.
#
# If you don't want to use every available asteroid and/or dwarf planet -
# here, you can name just specific asteroids and dwarf planets you want.  
#
# You can put either their numbers (not in quotes) or their names (inside quotes).
#
# Comment out ones you don't want by putting // or # before their lines, or you
# can enclose multiple lines inside these:  /* */
#
#
# Asteroids
#
# "Linux",
# "Doga",
# 358,		# Apollonia
# 24626,	# Astrowizard
# 1703,		# Barry
# 22442,	# Blaha
# 10504,	# Doga
# 9965,		# GNU
# 5485,		# Kaula
# 216,		# Kleopatra
# 9885,		# Linux
# 9882,		# Stallman
# 9793,		# Torvalds
# 202373,	# Ubuntu
# 2868,		# Upupa
# 274301,	# Wikipedia


# Dwarf planets and possible dwarf planets

# 225088,	# 2007 OR10 (Snow White)
# 136199,	# Eris
# 136108,	# Haumea
# 136472,	# MakeMake
# 90482,	# Orcus
# 50000,	# Quaoar
# 90377,	# Sedna

);

# End of $specific_asteroids_etc array.
#
#****************************************



#****************************************

$excluded_asteroids_etc = array
(

# Optionally, you can exclude asteroids (and dwarf planets which require
# the asteroid offset) you don't want, using the $excluded_asteroids_etc array.
#
# You can put either their numbers (not in quotes) or their names (inside quotes).
#
# This will work even if you have...
#
# 		$Should_Use_All_Available_Ephemerides_for_Asteroids_Etc
#
# 	and/or
#
# 		$Should_Display_All_Dwarf_Planets_Besides_Pluto_and_Ceres
#
# ...set to true.


# Asteroids

# 358,		# Apollonia
# 24626,	# Astrowizard
# 1703,		# Barry
# 22442,	# Blaha
# 10504,	# Doga
# 9965,		# GNU
# 5485,		# Kaula
# 216,		# Kleopatra
# 9885,		# Linux
# 9882,		# Stallman
# 9793,		# Torvalds
# 202373,	# Ubuntu
# 2868,		# Upupa
# 274301,	# Wikipedia


# Dwarf planets

# 225088,	# 2007 OR10 (Snow White)
# 136199,	# Eris
# 136108,	# Haumea
# 136472,	# MakeMake
# 90482,	# Orcus
# 50000,	# Quaoar
# 90377,	# Sedna

);

# End of $excluded_asteroids_etc array.
#
#****************************************


// ****************************************
//

$excluded_no_offset_celestial_objects = array
(
	 
	# Optionally, here, you can exclude celestial objects
	# which don't use the asteroid offset.
	#
	# Only numbers or constants like SE_SUN work here.

	# SE_SUN, 
	# SE_MOON, 
	# SE_MERCURY, 
	# SE_VENUS, 
	# SE_MARS, 
	# SE_JUPITER, 
	# SE_SATURN, 
	# SE_URANUS, 
	# SE_NEPTUNE, 
	# SE_PLUTO, 
	# SE_MEAN_NODE, 
	# SE_TRUE_NODE,
	# SE_MEAN_APOG,
	# SE_OSCU_APOG,
	
	# SE_CERES, # Dwarf planet
	# SE_CHIRON,
	# SE_PHOLUS,
	# SE_PALLAS,
	# SE_JUNO,
	# SE_VESTA, 

);

# End of $excluded_no_offset_celestial_objects array.
#
#****************************************



#
#
# End of settings you can change.
#
#-----------------------------------------------------------------------------
#
#
# Everything else can be left alone.
#
#

$now_time=time();



require("includes/Library-of-Functions.php");


$Eryss_Header_or_Footer = "Page generated by the <a href=\"$Eryss_URL\" class=ext>Eryss</a> astrology software version $Eryss_Version,<br>using the <a href=\"$Swiss_Ephemeris_URL\" class=ext>Swiss Ephemeris</a> <a href=\"http://astroblahhh.com/software/glmp-gtk-or-ph-gtk/extensions/eryss-and-swiss-ephemeris\" class=ext>extension</a><br>for <a href=\"http://astroblahhh.com/software/glmp-gtk\" class=ext>Astroblahhh GLMP-GTK</a> or <a href=\"http://astroblahhh.com/software/ph-gtk\" class=ext>Astroblahhh PH-GTK</a>.";

$HTML_Page_Header = $Eryss_Header_or_Footer;
$HTML_Page_Footer = $Eryss_Header_or_Footer;


$Celestial_Objects_in_Arbitrary_Order = "";
$HTML_Lines_and_Zodiacal_Positions_Header = "";
$Celestial_Objects_in_Zodiacal_Order = "";

$HTML_Lines_and_Zodiacal_Positions = array();
	# Used to make the list which is sorted in zodiacal order.


if ( isset($argv[1]) )
{	
	$Chart_Data=$argv[1];
	array_shift($argv);
	array_shift($argv);
}


Make_Sure_Path_Is_Folder("Swiss_Ephemeris_Folder");

$no_offset_celestial_objects=array
(	
	#	Celestial objects which don't use the asteroid offset.
	#
	#	Even more no-asteroid-offset objects are listed in the
	# swephprg.htm manual file ("Programming interface to the Swiss Ephemeris")
	# at:
	#
	#	/root/sweph/Documentation/swephprg.htm

	
	SE_SUN, 
	SE_MOON, 
	SE_MERCURY, 
	SE_VENUS, 
	SE_MARS, 
	SE_JUPITER, 
	SE_SATURN, 
	SE_URANUS, 
	SE_NEPTUNE, 
	SE_PLUTO, 
	SE_MEAN_NODE, // North lunar node
	SE_TRUE_NODE, // North lunar node
	SE_MEAN_APOG, // Lilith
	SE_OSCU_APOG, // Lilith

);

$no_offset_asteroids_and_dwarf_planet = array
(	# Dwarf planet and asteroids which don't use the asteroid offset.

	SE_CERES, # Dwarf planet
	SE_CHIRON,
	SE_PHOLUS,
	SE_PALLAS,
	SE_JUNO,
	SE_VESTA, 
);

$dwarf_planets = array
(

# Asteroids and most dwarf planets (except Ceres and Pluto) need the
# +10,000 asteroid offset added to them: SE_AST_OFFSET
#
# That's a technical reason why these dwarf planets have to be in a
# separate array. 
#
# To exclude them, you can list them in $excluded_asteroids_etc, or set
# $Should_Display_All_Dwarf_Planets_Besides_Pluto_and_Ceres to false.


# Alphabetical order

225088,		# 2007 OR10 (nicknamed "Snow White")
136199,		# Eris
136108,		# Haumea
136472,		# MakeMake
90482,		# Orcus
50000,		# Quaoar
90377,		# Sedna

);

# End of $dwarf_planets array.
#
#****************************************


# This part processes command line arguments.

if ( isset($argv[0]) )
{

	foreach ($argv as $arg)
	{
		$True_or_False_Config_Variables = array("Should_Output_in_Zodiacal_Order", "Should_Output_in_Arbitrary_Order", "Should_Output_in_Zodiacal_Order_First", "Should_Output_HTML_Page", "Should_Display_HTML_Page", "Should_Display_Unicode_Astro_Glyphs_in_HTML_Page", "Should_Display_Astro_Names_in_HTML_Page", "Should_Open_Chart_in_Astrolog_540", "Should_Show_Long_Sign_Names", "Should_Round_Off_Arc_Seconds", "Should_Display_360_Degree_Absolute_Zodiacal_Position_of_Objects", "Should_Display_360_Degree_Absolute_Zodiacal_Position_of_House_Cusps", "Should_Display_House_Data", "Should_Display_Main_Celestial_Objects", "Should_Use_All_Available_Ephemerides_for_Asteroids_Etc", "Should_Display_Ceres_Chiron_Pholus_Pallas_Juno_Vesta", "Should_Display_All_Dwarf_Planets_Besides_Pluto_and_Ceres", "Should_Display_Compact_HTML_Table_of_Houses", "Should_Display_When_Calculated_Date", "Should_Display_Julian_Day", "Should_Display_HTML_Page_Footer", "Should_Display_Original_Chart_Data_Line", "Should_Display_Longitude_Speed");	


		foreach ($True_or_False_Config_Variables as $true_or_false_config_variable)
		{
			Check_for_Config_Variable_Name_and_If_Present_Set_It_to_True_or_False("$true_or_false_config_variable", $arg);
		}
		
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Allowed_Value("Web_Browser_Shell_Command", $arg, array("dillo", "firefox", "chromium", "defaultbrowser"));
			# Don't want it to be possible to execute arbitrary shell commands,
			# so, only allowing a range of values here.
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Allowed_Value("Default_Calculation_Type", $arg, array("tropical", "sidereal", "heliocentric") );
		
		#Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Allowed_Value("Default_House_Method", $arg, array("Placidus", "Koch", "Porphyrius", "Regiomontanus", "Campanus", "Equal", "Vehlow equal", "Whole sign", "Axial rotation system", "Azimuthal (horizontal)", "Polich/Page", "Alcabitus", "Morinus", "Krusinski-Pisa", "P", "K", "O", "R", "C", "E", "V", "W", "X", "H", "T", "B", "M", "U"));
		
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Longitude", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Latitude", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("HTML_Page_Header", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("HTML_Page_Title_Prefix", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Custom_HTML_Comment", $arg);
		
		
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Default_Label_for_JPL_Link", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Default_Label_for_Search_Engine_Link", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Default_Search_Engine", $arg);
	
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Any_Value("Default_House_Method", $arg);
		
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Array_of_Any_Values("specific_asteroids_etc", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Array_of_Any_Values("excluded_asteroids_etc", $arg);
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Array_of_Any_Values("excluded_no_offset_celestial_objects", $arg);		
		
		Check_for_Config_Variable_Name_and_If_Present_Set_It_to_Array_of_Any_Values("no_offset_celestial_objects", $arg);
		
		
		
		Check_for_Filepath_Variable_Name_and_If_Present_Set_It_to_a_Filepath("Path_to_CSS", $arg, "css");
		
		Check_for_Folder_Variable_Name_and_If_Present_Set_It_to_a_Folder("Swiss_Ephemeris_Folder", $arg);
		
		Check_for_Folder_Variable_Name_and_If_Present_Set_It_to_a_Folder("Astrolog_540_Folder", $arg);
		
	}
	echo "\n\n";
}

$Default_Calculation_Type=strtolower($Default_Calculation_Type);
$Default_Calculation_Type=ucfirst($Default_Calculation_Type);


switch ($Default_Calculation_Type)
{
	case "Tropical":		$iflag=SEFLG_SPEED;
							break;
	case "Heliocentric":	$iflag=SEFLG_SPEED|SEFLG_HELCTR;
							break;
	case "Sidereal":		$iflag=SEFLG_SPEED|SEFLG_SIDEREAL;
							break;
}


if (!$Chart_Data)
{
	$Chart_Data = "now $Latitude $Longitude";
}

list ($Chart_Date_and_Time, $Longitude_Float, $Latitude_Float, $Longitude_Deg, $Longitude_Min, $Longitude_Sec, $Longitude_W_or_E, $Latitude_Deg, $Latitude_Min, $Latitude_Sec, $Latitude_N_or_S, $Longitude, $Latitude) = Process_Line_of_Chart_Data($Chart_Data);


try 
{
	$Local_Chart_Datime = new DateTime("$Chart_Date_and_Time");
		# This one gets displayed.
}
catch (Exception $Exception)
{	# The user's $Chart_Data line failed, so, have to replace it with a working one.

	$Error_Footer = "\n\nError encountered when trying to use $" . "Chart_Data line:\n	$Chart_Data";
	
	$Chart_Data = "now $Latitude $Longitude";
	$Error_Footer .= "\nHad to use \"$Chart_Data\" instead.";

	if ($Should_Display_Full_Error_Messages)
	{	$Error_Footer .= "\n\n$Exception";
	}
	
	list ($Chart_Date_and_Time, $Longitude_Float, $Latitude_Float, $Longitude_Deg, $Longitude_Min, $Longitude_Sec, $Longitude_W_or_E, $Latitude_Deg, $Latitude_Min, $Latitude_Sec, $Latitude_N_or_S, $Longitude, $Latitude) = Process_Line_of_Chart_Data($Chart_Data);
	
	$Local_Chart_Datime = new DateTime("$Chart_Date_and_Time");
	# This one gets displayed.
}

list($year, $month, $day, $hour, $minute, $second) = sscanf($Local_Chart_Datime->format("Y F d G i s"), "%d %s %d %d %d %d");


$GMT_Chart_Datime = clone $Local_Chart_Datime;
	# This one gets sent to the Swiss Ephemeris.

$GMT_Timezone = new DateTimeZone("UTC");
$GMT_Chart_Datime->SetTimezone($GMT_Timezone);
	
list($gmt_year, $gmt_month, $gmt_day, $gmt_hour, $gmt_minute, $gmt_second) = sscanf($GMT_Chart_Datime->format("Y m d G i s"), "%d %d %d %d %d %d");
	

swe_set_ephe_path($Swiss_Ephemeris_Folder);

$time_in_24_hour_format_with_timezone = $Local_Chart_Datime->format("G:i:s T");

$time_in_24_hour_format_with_timezone_and_without_seconds = $Local_Chart_Datime->format("G:i T");

$am_or_pm = $Local_Chart_Datime->format("A");

$timezone_hours_to_add_or_subtract_to_get_gmt = $Local_Chart_Datime->format("O");

$long_timezone_identifier = $Local_Chart_Datime->format("e");

$julian_day = swe_julday($gmt_year, $gmt_month, $gmt_day, ($gmt_hour + ($gmt_minute / 60) + ($gmt_second / 3600) ), SE_GREG_CAL);

$minute = str_pad($minute, 2, "0", STR_PAD_LEFT);
$second = str_pad($second, 2, "0", STR_PAD_LEFT);
	
$gmt_minute = str_pad($gmt_minute, 2, "0", STR_PAD_LEFT);
$gmt_second = str_pad($gmt_second, 2, "0", STR_PAD_LEFT);
	

$Almost_Complete_Astrolog_540_Command_Line = "$month $day $year $time_in_24_hour_format_with_timezone $Longitude $Latitude";

$Almost_Complete_Astrolog_540_Command_Line_Without_Seconds = "$month $day $year $time_in_24_hour_format_with_timezone_and_without_seconds $Longitude $Latitude";
	# Finally, we start printing some output.


	
if ($HTML_Page_Header!=$Eryss_Header_or_Footer)
{
	echo $HTML_Page_Header;
	echo "\n";
}

if ($Custom_HTML_Comment)
{
	echo $Custom_HTML_Comment;
	echo "\n";
}

echo "$Almost_Complete_Astrolog_540_Command_Line  $am_or_pm $timezone_hours_to_add_or_subtract_to_get_gmt $long_timezone_identifier\n";


if ($Should_Display_Julian_Day)
{
	echo "Julian Day: $julian_day     ";
}

$now_date = date("r", $now_time);

if ($Should_Display_When_Calculated_Date)
{
	echo "Calculated: "; 
	echo $now_date;
	echo "\n$Default_Calculation_Type Calculations";
}

$House_Method_Long_Name = "";

if ($Should_Display_House_Data)
{
	$House_Method_Abbrev = Get_House_Method_Abbrev($Default_House_Method);
	
	if (!$House_Method_Abbrev)
	{	$House_Method_Abbrev = "P";
		# P for Placidus
	}
	
	$House_Method_Long_Name = Convert_House_Method_Abbrev_to_Long_Name($House_Method_Abbrev);
}

if ($Should_Output_HTML_Page)
{	$nav_anchs = "<div class=\"navanchs\">";
	$nav_anchs .= "<a href=\"#top\">&#x25B2;&nbsp;Top</a> - ";
	
	if ($Should_Output_in_Zodiacal_Order_First)
	{	
		if ($Should_Display_House_Data)
		{
			$nav_anchs .= "<a href=\"#houses\">Houses&nbsp;($House_Method_Long_Name)</a>"; 
		}
		if ( ($Should_Display_House_Data && $Should_Output_in_Zodiacal_Order )  || ($Should_Display_House_Data && !$Should_Output_in_Zodiacal_Order && $Should_Output_in_Arbitrary_Order) )
		{	$nav_anchs .= " - ";
		}
		if ($Should_Output_in_Zodiacal_Order)
		{	$nav_anchs .= "<a href=\"#zodiacal_order\">Zodiacal&nbsp;Order</a>";
		}
		if ($Should_Output_in_Zodiacal_Order && $Should_Output_in_Arbitrary_Order)
		{	$nav_anchs .= " - ";
		}
		if ($Should_Output_in_Arbitrary_Order)
		{	$nav_anchs .= "<a href=\"#arbitrary_order\">Arbitrary&nbsp;Order</a>";
		}
	}
	else
	{
		if ($Should_Display_House_Data)
		{ 
			$nav_anchs .= "<a href=\"#houses\">Houses ($House_Method_Long_Name)</a>"; 
		}
		if ( ($Should_Display_House_Data && $Should_Output_in_Arbitrary_Order )  || ($Should_Display_House_Data && !$Should_Output_in_Arbitrary_Order && $Should_Output_in_Zodiacal_Order) )
		{	$nav_anchs .= " - ";
		}
		if ($Should_Output_in_Arbitrary_Order)
		{	$nav_anchs .= "<a href=\"#arbitrary_order\">Arbitrary Order</a>";
		}
		
		if ($Should_Output_in_Arbitrary_Order && $Should_Output_in_Zodiacal_Order)
		{	$nav_anchs .= " - ";
		}
		if ($Should_Output_in_Zodiacal_Order)
		{	$nav_anchs .= "<a href=\"#zodiacal_order\">Zodiacal Order</a>";
		}
	}
	$nav_anchs .= " - <a href=\"#bottom\">&#x25BC;&nbsp;Bottom</a></div>";
}

if ($Should_Output_HTML_Page)
{
	$Beginning_of_Page_Body = "<a name=\"top\"></a><center>$nav_anchs";
	
	if ($HTML_Page_Header)
	{	$Beginning_of_Page_Body .= "<h2>$HTML_Page_Header</h2><p>";
	}
	$Beginning_of_Page_Body .= "<h3>$Almost_Complete_Astrolog_540_Command_Line &nbsp;&nbsp; $am_or_pm $timezone_hours_to_add_or_subtract_to_get_gmt $long_timezone_identifier</h3>";
	
	if ($Custom_HTML_Comment)
	{
		$Beginning_of_Page_Body .= "$Custom_HTML_Comment";
	}
	
	if ($Should_Display_Julian_Day)
	{	$Beginning_of_Page_Body .= "<p><big>Julian Day: $julian_day</big>";
	}
	
	if ($Should_Display_When_Calculated_Date)
	{
		$Beginning_of_Page_Body .= "<p>Calculated: $now_date<br>$Default_Calculation_Type Calculations<p>";
	}
	if ($Should_Display_Original_Chart_Data_Line)
	{
		$Beginning_of_Page_Body .= "<tt>Input chart data: $Chart_Data</tt>";
	}
	
	$Page_Title = "$Almost_Complete_Astrolog_540_Command_Line";
	
	if (isset($HTML_Page_Title_Prefix) )
	{
		$Page_Title = $HTML_Page_Title_Prefix . " - " . $Page_Title;
	}
	
	
	$Temporary_HTML_Page = new HTML_Page($Page_Title, $CSS_for_HTML_Page, $Beginning_of_Page_Body);
	
	
	if ($Web_Browser_Shell_Command == "dillo")
	{
		$html = Prepare_Dillo_Web_Browser_Tips_for_HTML_Display();
		
		$Temporary_HTML_Page->Add_More_Content("<p><br>" . $html . "<p>");	
	}
	
}


if ($Should_Display_Original_Chart_Data_Line)
{
	echo "\n\nInput chart data: ";
	echo $Chart_Data;
}

if ($House_Method_Long_Name)
{
	
	echo "\nHouse Method: $House_Method_Long_Name";
}
echo "\n\n";
	
# Next, we display the house data, if desired.

if ($Should_Display_House_Data)
{
	$house_lines_to_display = array();
	
	$Zodiacal_Longitudes_of_House_Cusps = Get_Zodiacal_Longitudes_of_House_Cusps($julian_day, $Latitude_Float, $Longitude_Float, $House_Method_Abbrev);
		
	
	$Pisces_Aries_Border_House = Find_Pisces_Aries_Border_House($Zodiacal_Longitudes_of_House_Cusps);
		

	$house_lines_to_display = Prepare_House_Lines_for_Display($Zodiacal_Longitudes_of_House_Cusps, $Should_Round_Off_Arc_Seconds);
	
	foreach ($house_lines_to_display as $house_line)
	{	echo $house_line;
	}
	
	if ($Should_Output_HTML_Page)
	{
		if ($Should_Display_Compact_HTML_Table_of_Houses)
		{
			$html_house_data = Prepare_House_Data_for_Compact_HTML_Display($Zodiacal_Longitudes_of_House_Cusps, $Should_Round_Off_Arc_Seconds, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page);
		}
		else
		{
			$html_house_data = Prepare_House_Data_for_HTML_Display($Zodiacal_Longitudes_of_House_Cusps, $Should_Round_Off_Arc_Seconds, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page);
		}
		$Temporary_HTML_Page->Add_More_Content("<p><br><a name=\"houses\"></a><h3>Houses ($House_Method_Long_Name)</h3>$nav_anchs<p><h3>$Almost_Complete_Astrolog_540_Command_Line</h3>" . $html_house_data . "<p>");	
	}
	
}
	
if ($Should_Output_HTML_Page)
{
	if ($Should_Output_in_Arbitrary_Order)
	{
		$Celestial_Objects_in_Arbitrary_Order = Make_Celestial_Object_Table_Header();
	}
}

# Then, we exclude objects the user didn't want.


$excluded_no_offset_celestial_objects= Convert_Mixed_NonAssociative_Array_of_Object_Constant_Names_and_Numbers_to_Just_Numbers($excluded_no_offset_celestial_objects);

$no_offset_celestial_objects = Convert_Mixed_NonAssociative_Array_of_Object_Constant_Names_and_Numbers_to_Just_Numbers($no_offset_celestial_objects);


$no_offset_celestial_objects = array_diff($no_offset_celestial_objects, $excluded_no_offset_celestial_objects);
	
# And we print the remaining main celestial objects, if the user wants.
	
if ($Should_Display_Main_Celestial_Objects)
{
	Print_Celestial_Object_Data($no_offset_celestial_objects);
	
	if ($Should_Output_HTML_Page)
	{
		$celestial_object_data = Prepare_Celestial_Object_Data_for_HTML_Display($no_offset_celestial_objects, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page);
	
		if ($Should_Output_in_Arbitrary_Order)
		{	$Celestial_Objects_in_Arbitrary_Order .= $celestial_object_data;
		}
	}
}


# If $Should_Use_All_Available_Ephemerides_for_Asteroids_Etc is true,
# we need to figure out all the available ephemerides. 


list ($all_available_asteroids_etc, $Ephemeris_Filenames, $Asteroid_Numbers_and_Names) = Get_All_Available_Asteroids_Etc_from_($Swiss_Ephemeris_Folder);

	if ($Should_Use_All_Available_Ephemerides_for_Asteroids_Etc)
	{
		# Now we can print.
		Print_Celestial_Object_Data($all_available_asteroids_etc, SE_AST_OFFSET);
		
		$celestial_object_data = Prepare_Celestial_Object_Data_for_HTML_Display($all_available_asteroids_etc, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page, SE_AST_OFFSET);
		
		if ($Should_Output_in_Arbitrary_Order)
		{	$Celestial_Objects_in_Arbitrary_Order .= $celestial_object_data;
		}
	}
	else
	{	# The user either wanted to pick their own asteroids,
		# or wanted no asteroids.
		
		if ( $specific_asteroids_etc)
		{	# The user picked some asteroids.
		
			$specific_asteroids_etc=Convert_Mixed_NonAssociative_Array_of_Asteroid_Names_and_Numbers_to_Just_Numbers($specific_asteroids_etc);
			
			$specific_asteroids_etc = array_diff($specific_asteroids_etc, $excluded_asteroids_etc);
				# Need to exclude ones the user listed as excluded.
							
			
			# Now we can print.
			Print_Celestial_Object_Data($specific_asteroids_etc, SE_AST_OFFSET);	
			
			$celestial_object_data = Prepare_Celestial_Object_Data_for_HTML_Display($specific_asteroids_etc, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page, SE_AST_OFFSET);
		
			if ($Should_Output_in_Arbitrary_Order)
			{	$Celestial_Objects_in_Arbitrary_Order .= $celestial_object_data;
			}
		}
	}
		
	if ($Should_Display_Ceres_Chiron_Pholus_Pallas_Juno_Vesta)
	{
		$no_offset_asteroids_and_dwarf_planet = array_diff($no_offset_asteroids_and_dwarf_planet, $excluded_no_offset_celestial_objects);
			# Again, firste xcluding any the user excluded.
		
		# Now we can print.
		Print_Celestial_Object_Data($no_offset_asteroids_and_dwarf_planet);
		
		$celestial_object_data = Prepare_Celestial_Object_Data_for_HTML_Display($no_offset_asteroids_and_dwarf_planet, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page);
		
		if ($Should_Output_in_Arbitrary_Order)
		{	$Celestial_Objects_in_Arbitrary_Order .= $celestial_object_data;
		}
	}
	

	
	if ($Should_Display_All_Dwarf_Planets_Besides_Pluto_and_Ceres)
	{
		if (!$Should_Use_All_Available_Ephemerides_for_Asteroids_Etc)
		{
			$dwarf_planets=array_diff($dwarf_planets, $specific_asteroids_etc);
				# Don't want to repeat the user if they included any dwarf planets,
				# so we exclude any the user already specifically named.
		}

		Print_Celestial_Object_Data($dwarf_planets, SE_AST_OFFSET);
		
		$celestial_object_data = Prepare_Celestial_Object_Data_for_HTML_Display($dwarf_planets, $Should_Display_Unicode_Astro_Glyphs_in_HTML_Page, $Should_Display_Astro_Names_in_HTML_Page, SE_AST_OFFSET);
	
		if ($Should_Output_in_Arbitrary_Order)
		{	$Celestial_Objects_in_Arbitrary_Order .= $celestial_object_data;
		}
		
	}
	
	
	if (isset($Error_Footer) )
	{	# This only ever gets set and printed if the $Chart_Data provided was invalid.
	
		echo $Error_Footer;
	}

if ($Should_Output_HTML_Page)
{	
	
	if ($Should_Output_in_Zodiacal_Order)
	{			
		asort($HTML_Lines_and_Zodiacal_Positions);
		
		$Celestial_Objects_in_Zodiacal_Order = array_keys($HTML_Lines_and_Zodiacal_Positions);
		
		$Celestial_Objects_in_Zodiacal_Order = implode("\n", $Celestial_Objects_in_Zodiacal_Order);
		
		if ($Should_Output_in_Zodiacal_Order)
		{
			$HTML_Lines_and_Zodiacal_Positions_Header = Make_Celestial_Object_Table_Header();
		}	
	}
	
	$Celestial_Objects_in_Arbitrary_Order = "<p><br><a name=\"arbitrary_order\"></a><h3>In Arbitrary Order</h3>$nav_anchs<h3>$Almost_Complete_Astrolog_540_Command_Line</h3><p>" . $Celestial_Objects_in_Arbitrary_Order . "</table>";
	
	$Celestial_Objects_in_Zodiacal_Order = "<p><br><a name=\"zodiacal_order\"></a><h3>In Zodiacal Order</h3>$nav_anchs<h3>$Almost_Complete_Astrolog_540_Command_Line</h3><p>" . $HTML_Lines_and_Zodiacal_Positions_Header . $Celestial_Objects_in_Zodiacal_Order . "</table>";
		
	if ($Should_Output_in_Zodiacal_Order_First)
	{		
		if ($Should_Output_in_Zodiacal_Order)
		{
			$Temporary_HTML_Page->Add_More_Content($Celestial_Objects_in_Zodiacal_Order);
		}
		
		if ($Should_Output_in_Arbitrary_Order)
		{
			$Temporary_HTML_Page->Add_More_Content($Celestial_Objects_in_Arbitrary_Order);
		}
	}
	else
	{	
		if ($Should_Output_in_Arbitrary_Order)
		{
			$Temporary_HTML_Page->Add_More_Content($Celestial_Objects_in_Arbitrary_Order);
		}
		
		if ($Should_Output_in_Zodiacal_Order)
		{
			$Temporary_HTML_Page->Add_More_Content($Celestial_Objects_in_Zodiacal_Order);
		}		
	}
	
	$Temporary_HTML_Page->Add_More_Content($nav_anchs . "<a name=\"bottom\"></a>");

	if ($Should_Display_HTML_Page_Footer)
	{	$Temporary_HTML_Page->Add_More_Content("<hr>$HTML_Page_Footer");
	}
	
	if ($Web_Browser_Shell_Command == "dillo")
	{
		$Temporary_HTML_Page -> Build_Page($dillo_html_body_stuff);
	}
	else
	{
		$Temporary_HTML_Page -> Build_Page();
	}
	$Temporary_HTML_Page -> Output_HTML_File_to_Path_($Full_Path_to_Temporary_HTML_Page_for_Chart);
}

if ($Should_Display_HTML_Page)
{
	execInBackground("$Web_Browser_Shell_Command \"$Full_Path_to_Temporary_HTML_Page_for_Chart\"");
}

if ($Should_Open_Chart_in_Astrolog_540)
{
	chdir($Astrolog_540_Folder);
	echo "\n\n";
	$astrolog_command_line = "./astrolog -qa $Almost_Complete_Astrolog_540_Command_Line -X";
	echo $astrolog_command_line;
	echo "\n\n";
	execInBackground($astrolog_command_line);
}

sleep(1);

if ($Should_Open_Chart_in_Astrolog_540 || $Should_Display_HTML_Page)
{
	echo "\n\nNote: Closing this terminal window will also close ";
	if ($Should_Open_Chart_in_Astrolog_540)
	{
		echo "the Astrolog 5.40 window";
	}
	if ($Should_Open_Chart_in_Astrolog_540 && $Should_Display_HTML_Page)
	{
		echo " and ";
	}
	if ($Should_Display_HTML_Page)
	{
		echo "the web browser that was opened (if it wasn't open already)";
	}
	echo ".";
}

die;

#
#
#
#*****************************************
# End of script.