Source for file search_forms.php
Documentation is available at search_forms.php
* This file contains the function used to display various parts of the search
* This file is part of HRDIODB.
* HRDIODB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* HRDIODB 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with HRDIODB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require_once("uars_day_class.php");
require_once("common_class.php");
* Checks if the operator is selected.
* This utility function checks to see if the current operator is selected.
* @param mixed Operator value
* @param integer Operator index
* @param array The clean $_GET array
* @return string The string "SELECTED" or ""
if(isset ($got["operator". $index]) && ($got["operator". $index] == $value)){
* Displays the page selector.
* This function figures out which page we're on and displays the search
* @param integer The page we're on
* @param integer The number of results per page
* @param integer The number of search results
foreach ($_GET as $k => $v) {
foreach ($new_get as $k => $v) {
$query .= "&". $k. "[]=$val";
// Ensure the displayed range matches the number of search results
$page_end = $page_size * $page;
if ($num_records < $page_end) {
$page_end = $num_records;
print "Showing records ". ($page_size * ($page - 1) + 1) . " - ". $page_end . "<br/>";
if (ceil($num_records / $page_size) > 1) {
for ($p = 1; $p <= ceil($num_records / $page_size); $p++ ) {
print " <a href=\"search.php?page=$p$query\">$p</a>";
if ($p < (ceil($num_records/ $page_size))) {
* Displays search results.
* This function is responsible for displaying the search results.
* @param search_class $search Search class instance containing search results
* @param hrdi_db $hdb HRDI database instance
* @param integer $page The search results page we're on
* @param integer $page_size The number of results per page
$displayed_fields = array('UARS', 'Year-DOY', 'Day', 'Date', 'Direction', 'Beta', 'Operational Mode: Azimuths','Comments');
print "<table class=\"hrdi\"><tr class=\"c_label\"><td>Found "
if ($session->get_var("days") && $session->get_var("types")) {
print "<input type=\"button\" onClick=\"javascript:location.href='download.php'\" value=\"Download Files\">";
print "</td></tr><tr><td>";
print "</td></tr></table>";
// Search results table header
print "<table class=\"hrdi\"><tr class=\"c_label\">";
foreach ($displayed_fields as $field) {
//Display the search results
foreach($search->results as $result) {
if($counter >= ($page_size* ($page - 1))){
print "<tr class=\"data\">";
print "<td><a href=\"day.php?uars_day={$day->data['UARS_Day']}\">{ $day->data['UARS_Day']}</ a> </ td>
<td>{$day->data['Year']}-{ $day->data['Day_Of_Year']}</ td>
<td>{$day->data['Day_Of_Week']}</ td>
<td>{$day->data['Date']}</ td>
<td>{$day->display_data['Flight_Direction']}</ td>
<td>{$day->data['Beta_Angle']}</ td>
foreach ($day->modes as $mode) {
// We already have the description
$def = $pids[$mode['Description']]['Def'];
$pids[$mode['Description']]['Pid'] = $mode['Process_ID'];
$pids[$mode['Description']]['Def'] = $def = $j;
print $mode['Process_ID'];
print "</td><td>{$day->data['Comments']}</ td></ tr> ";
// Exit the display loop if a full page has been displayed
if($counter == ($page_size* $page)) break;
// Create the additional JavaScript array indexes for the popup display
print "<script type=\"text/javascript\">";
foreach ($pids as $desc => $keys) {
print "defs['{$keys['Def']}'] = '$desc';\n";
* Prints file filter form.
* This function takes an array of file types and the sanitized get variable
* and prints the html form for filtering searches by file types.
* @param array $types File types and their ids
* @param array $got The sanitized get variable
print "<table class=\"hrdi\"><tr class=\"c_label\"><td>Filter search results by available file types</td></tr>";
foreach ($types as $type) {
if(isset ($got['filetypes']) && in_array($type['ID'], $got['filetypes'])) {
print "<tr><td><input type=\"checkbox\" name=\"filetypes[]\"
value=\"{$type['ID']}\" checked>{$type['Description']}</td></tr>";
print "<tr><td><input type=\"checkbox\" name=\"filetypes[]\"
value=\"{$type['ID']}\">{$type['Description']}</td></tr>";
* Takes a {@link hrdi_db} class instance and prints the HTML forms for
* the free form searches.
* @param hrdi_db $hdb The hrdi_db instance
* @param array $got The sanitized $_GET array
foreach($got as $k => $v) {
foreach($new_get as $k=> $v){
print "<!-- Javascript to retain data when adding search forms -->
<script type=\"text/JavaScript\">
function submit_form (i) {
document.search.num_forms.value = (document.search.num_forms.value-0) + i;
document.search.submitted.value = \"no\";
document.search.submit();
<tr class=\"c_label\"><td>Free Form Search Instructions</td></tr>
Select sets consisting of fields, operators and values. Use the
controls to add and remove set entry forms. Search results displayed
will be the intersection of the sets.
<!-- Table to align search form and file filter form -->
<form name=\"search\" method=\"get\">
<table><tr valign=\"top\"><td>
<td>Field</td><td>Operator</td><td>Value</td>
<input type=\"hidden\" name=\"submitted\" value=\"yes\">
<input type=\"hidden\" name=\"free_form\" value=\"yes\">
<input type=\"hidden\" name=\"num_forms\" value=\"{$got['num_forms']}\">
<input type=\"hidden\" name=\"table\" value=\"HRDI_Days\">
require_once('field_names.php');
for($i = 1; $i <= $got['num_forms']; $i++ ){
print "<tr><td><select name=\"field$i\"><option value=\"\">-- Select a Field --</option>";
foreach($field_names as $value=> $name){
if (isset ($got["field$i"]) && ($got["field$i"] == $value)) {
print "<option value=\"". $value. "\" $selected>". $name. "</option>\n";
print "</select></td><td>";
print "<select name=\"operator$i\">
// Value display, show the previous value data
print "<input name=\"value$i\" value=\""
if ($i != $got['num_forms']) {
print "<tr><td colspan=\"3\"><center>AND</center></td></tr>";
print "<tr><td><a href=\"javascript: submit_form(1);\">Add another search form</a></td>
<td><a href=\"javascript: submit_form(-1);\">Remove the last search form</a></td>
<td><input type=\"submit\"></td></tr>";
print "<tr><td colspan=3><center><b><br/>Found "
. sizeof($search_results->results)
. " records. Scroll down for results.<br/></b></center></td></tr>";
elseif(!isset ($_SESSION['error']) && isset ($got['submitted'])){
print "<tr><td colspan=\"3\"><center><div id=\"error\">No matching entries found</div></center></td></tr>";
if(isset ($_SESSION['error'])){
print "<tr><td colspan=\"3\"><center><div id=\"error\">". $_SESSION['error']. "</div></center></td></tr>";
unset ($_SESSION['error']);
$types = $hdb->get_list($sql);
* Prints predefined search forms.
* Controls the layout of search forms. Calls all predefined search forms.
* @param hrdi_db $hdb The hrdi_db instance
* @param array $got The clean $_GET array
$searches[0]= "Operational Mode, Date, Latitude Search";
// $searches[1]="Operational Mode Search";
for($i= 0; $i< count($searches);$i++ ){
print "<a href=\"search.php?predefined_search=$i\">$searches[$i]</a>";
if($i+ 1 < count($searches)){
// Gather information needed by search forms
$pids = $hdb->get_table("HRDI_Pids");
$types = $hdb->get_list($sql);
$search_num = @$got['predefined_search'];
// Place all search form printing functions here
* Displays pid search form.
* This function displays the pid day coverage form. It has been put here for
* users following the tutorial on writing new search functions.
* @param array $got The clean $_GET array
<!-- Tables class are used for a consistent look -->
Enter an Operational Mode (pid) and press search.
<!-- Using the "get" method allows users to bookmark searches, but also invites tinkering.
Please use the $got variable to access submitted data for safety. -->
<form name="search" method="get">
<!-- This tells search.php to run a search and which search to run -->
<input type="hidden" name="submitted" value="pid">
<!-- This tells search_form.php to return to this view after it is submitted -->
<input type="hidden" name="predefined_search" value="1">
<!-- This is the data we are submitting. The previous value (if any) is repopulated.-->
<input type="text" name="pid" value=" <?php print common::get_value('pid', $got)?>">
<input type="submit" name="" value="Search">
* Displays day coverage form.
* This function displays the pid day coverage form.
* @param array $got The clean $_GET array
* @param array $pids Array of pids
* @param array $types File types
$day_types = array("none"=> "No date filter",
"year_day"=> "Year - Day of Year",
"calendar_day"=> "Calendar date");
$coverage_x = array("Latitude min (deg.)","Latitude max (deg.)");
$coverage_y[] = array("Warm Side","Cold Side");
$coverage_y[] = array("Day", "Night");
$coverage_y[] = array("Asc", "Desc");
<!-- Table to align search form and file filter form -->
<tr class="c_label"><td>Instructions</td></tr>
This search has three main components: Operational Mode, Date and Latitude. Each component
is optional and will not affect the search if left untouched. If an operational mode is
selected, the search results will be limited to record with that operational mode. Only
one or "Any" operational mode may be selected at a time. If a date range is entered, the
search results will be required to fall within that range. Dates may be
entered in three formats:
<br/>1) Uars day (ex. 71)
<br/>2) Year - Day of Year (ex. 1992-255)
<br/>3) Calendar date (ex. January 17, 1992 or 1/17/1992).
<br/>Night and day latitude ranges can be specified independently in degrees (ex. 40.7).
<br/>To search with any combination of available criteria, use the <a href="search.php?free_form">free form search page</a>.
<form name="search" method="get">
<table><tr valign="top"><td>
<input type="hidden" name="submitted" value="pid_day_coverage">
<!-- This tells search_form.php to return to this view after it is submitted -->
<input type="hidden" name="predefined_search" value="0">
<tr class="c_label"><td colspan=3>Search</td></tr>
<tr><td>Operational mode is
<select size=5 name="pid">";
if(!isset ($got['pid']) or $got['pid'] == "any") {
print "<option value=\"any\" selected >Any</option>";
print "<option value=\"any\">Any</option>";
$sets[]= 'Daytime mesosphere';
$sets[]= 'Nighttime mesosphere';
print "<option value=\"{$set}\" ";
if ($set == @$got['pid']) {
print " >{$set}</option>";
print "<option value=\"{$pid['Pid']}\" ";
if ($pid['Pid'] == @$got['pid']) {
print " >{$pid['Pid']}: {$pid['Description']}</option>";
<select size=4 name="date_type">
if (!isset ($got['date_type'])){
$got['date_type'] = "none";
is between <input size="8" type="text" name="date_value_low" value=" <?php if($got['date_type']!= 'none'){print common::get_value('date_value_low', $got);}?>">
and <input type="text" size="8" name="date_value_high" value=" <?php if($got['date_type']!= 'none'){print common::get_value('date_value_high', $got);}?>">
</td></tr><tr><td colspan="2"><center>and (leave blank for all latitudes)</center>
<tr><td>Day Latitude (degrees) is between:</td>
<td><input type="text" size="6" name="lat_day_min" value=" <?php print common::get_value('lat_day_min', $got)?>">
and <input type="text" size="6" name="lat_day_max" value=" <?php print common::get_value('lat_day_max', $got)?>"></td></tr>
<tr><td>Night Latitude (degrees) is between:</td>
<td><input type="text" size="6" name="lat_night_min" value= <?php print common::get_value('lat_night_min', $got)?>> and
<input type="text" size="6" name="lat_night_max" value= <?php print common::get_value('lat_night_max', $got)?>></td></tr>
<td colspan="2" align="right">
<input type="submit" name="pid_by_date" value="Search">
print "<tr><td colspan=3><center><b><br/>Found "
. sizeof($search_results->results)
. " records. Scroll down for results.<br/></b></center></td></tr>";
elseif(!isset ($_SESSION['error']) && isset ($got['submitted'])){
print "<tr><td colspan=\"3\"><center><div id=\"error\">No matching entries found</div></center></td></tr>";
if(isset ($_SESSION['error'])){
print "<tr><td colspan=\"3\"><center><div id=\"error\">". $_SESSION['error']. "</div></center></td></tr>";
unset ($_SESSION['error']);
// Display the file type selector
print "</td></tr></table></form>";
|