<?php

/*
   ###############################################
   TEST/DEMO FUNCTION:  Get_Obj_Data()

   AUTHOR   : Jay Tanner - 2025
   LANGUAGE : PHP v8.2.12
   LICENSE  : Public Domain

   This function returns data on any target object
   in the JPL database.
   ###############################################
*/

// ---------------------------------
// Define demo function name string.

   
$FunctionNameStr 'Get_Obj_Data';


/* -------------------------------------------------------------------
   Below are some suggested target object queries to try.
   NOT case-sensitive.

   The target object ID can refer to a special query (like 'news'),
   rather than an actual solar system object.

   For small bodies, like asteroids, it is good practice append a
   semicolon (;) to the end of the ID number or name string to
   avoid confusion with another object of the same name.

   The semicolon triggers a search of the small bodies database which
   holds all the data on asteroids and comets.

   EXAMPLE: Juno   =  Matches multiple objects - but no asteroids.
            Juno*  =  Same as Juno
            Juno;  =  Matches ONLY the asteroid 3 Juno (A804 RA).
            3;     =  Same as Juno;

   -------------------------------------------------------------------
   OBJECT ID   RETURNS
   ---------   -------------------------------------------------------
   ?           Basic information on using the NASA/JPL Horizons API.
   ?!          Technical data behind the NASA/JPL Horizons API.
   *           General listing of object and spacecraft ID#s
   -*          Listing of spacecraft and ID#s
   news        Latest NASA/JPL new and news backlog.

   499         Physical data for Mars.
   301         Physical data for The Moon (Luna).
   10          Physical data for The Sun.
   999         Physical data for Pluto.
   301;        Physical data for asteroid 301 Bavaria (A890 WA).
   Ceres;      Physical data for asteroid 1 Ceres (A801 AA).
   Juno;       Physical data for asteroid 3 Juno (A804 RA).
   4;          Physical data for asteroid 4 Vesta (A807 FA)

   Pioneer 6   Data on the Pioneer 6 mission.
   Voyaqer 1   Data on the Voyager 1 mission.
   Spitzer     Data on the Spitzer space telescope
   JWST        Data on the James Webb space telescope.
   Hubble      Data on the Hubble space telescope.
   -------------------------------------------------------------------
*/


// --------------------------------------------
// Set value of demo Target Object ID argument.

   
$TargObjID '699'// 699 = The planet Saturn


// --------------------------------------------------------------------
// Call function to send the object query to the NASA/JPL Horizons API.

   
$ObjectDataText Get_Obj_Data ($TargObjID);



// ----------------------------------------------------
// Generate client HTML page to display returned result.

   
print <<< HTML_PAGE_OUTPUT

<!DOCTYPE HTML>

<!-- Top yellow source code view link. --->
<br>
<table width="420" align="bottom" cellspacing="1" cellpadding="3">
<tr>
<td colspan="1" style="font-size:10pt; color:black; background:white;
                       text-align:left;">
<b>
<a href='View-Source-Code.php' target='_blank'
   style='font-family:Verdana; color:black; background:yellow;
          text-decoration:none; border:1px solid black; padding:4px;'>
&nbsp;View Source Code&nbsp;</a>
</b>
</td>
</tr>
</table>

<b><pre style='font-size:11pt;'>
TEST/DEMO FUNCTION:

ObjectDataText = 
$FunctionNameStr (TargObjID)

This function returns the basic data on any catalogued solar system body.

It can also be used as a general JPL Horizons data query for spacecraft and
space vehicles, rovers, NASA satellites, space telescopes as well as past
space missions such as Pioneer, Voyagers 1 and 2, etc.

##############################################################################

ARGUMENT(S):

TargObjID = 
$TargObjID

##############################################################################
Returned Result:

$ObjectDataText
</pre></b>

<!-- For extra scroll space at bottom of page --->
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

HTML_PAGE_OUTPUT;





/*
   ###########################################################################
   This function returns the basic data on any catalogued solar system objects
   including planets, asteroids, comets, satellites, spacecraft and missions
   data.

   The (TargObjID) argument can be a unique name, NASA Body ID #, record #,
   or an SPK ID# or DES=xxxxxxx for a comet or a special info query or direc-
   tive.

   It can also be used as a general JPL Horizons data query for spacecraft
   and space vehicles, rovers, NASA satellites, space telescopes as well as
   past space missions such as Pioneer, Voyagers 1 and 2, etc.

   Generic.  No special error checking is done, but the Horizons API does do
   some error checking and reports them at runtime.

   NO DEPENDENCIES
   ---------------------------------------------------------------------------
*/

   
function Get_Obj_Data ($TargObjID)
{
// ---------------------------------------------------------------------------
// Construct query URL for the NASA/JPL Horizons API.

   
$Command URLEncode(trim($TargObjID));

   
$From_Horizons_API =
   
"https://ssd.jpl.nasa.gov/api/horizons.api?format=text" .
   
"&COMMAND='$Command'" .
   
"&MAKE_EPHEM='NO'"    .
   
"&OBJ_DATA='YES'"     ;

// ---------------------------------------------------------------------------
// Send query to Horizons API to obtain the basic physical data for the given
// target object ID as a single long text string with embedded control codes.

   
$w File_Get_Contents($From_Horizons_API);

/* ----------------------------------------------
   Encode certain special characters so that they
   will display properly within a web page.
*/
   
return HTMLEntities($w);

// End of  Get_Obj_Data(...)



?>