HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file search_forms.php

Documentation is available at search_forms.php

  1. <?php
  2. /**
  3.  * Search forms.
  4.  * This file contains the function used to display various parts of the search
  5.  * forms.
  6.  * @package HRDIODB
  7.  */
  8.  
  9. /**
  10.  * This file is part of HRDIODB.
  11.  *
  12.  * HRDIODB is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * HRDIODB is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with HRDIODB; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. /** UARS day class */
  28. require_once("uars_day_class.php");
  29. /** Common class */
  30. require_once("common_class.php");
  31.  
  32. /**
  33.  * Checks if the operator is selected.
  34.  * This utility function checks to see if the current operator is selected.
  35.  * @param mixed Operator value
  36.  * @param integer Operator index
  37.  * @param array The clean $_GET array
  38.  * @return string The string "SELECTED" or ""
  39.  */
  40. function is_selected_operator($value$index$got){
  41.   if(isset($got["operator".$index]&& ($got["operator".$index== $value)){
  42.     return "SELECTED";
  43.   }
  44.   return "";
  45. }
  46.  
  47.   
  48. /**
  49.  * Displays the page selector.
  50.  * This function figures out which page we're on and displays the search
  51.  * results page selector.
  52.  * @param integer The page we're on
  53.  * @param integer The number of results per page
  54.  * @param integer The number of search results
  55.  */
  56. function display_page_selector ($page$page_size$num_records{
  57.   //Compose get argument
  58.   $query "";
  59.  
  60.   foreach ($_GET as $k => $v{
  61.     if($k != 'page'){
  62.       $new_get[$k$v;
  63.     }
  64.   }
  65.  
  66.   foreach ($new_get as $k => $v{
  67.     ifis_array($v)){
  68.       foreach($v as $val){
  69.        $query .= "&".$k."[]=$val";
  70.       }
  71.     }
  72.     else{
  73.      $query .= "&$k=$v";
  74.     }
  75.   }
  76.     
  77.   // Ensure the displayed range matches the number of search results
  78.   $page_end $page_size $page;
  79.  
  80.   if ($num_records $page_end{
  81.     $page_end $num_records;
  82.   }
  83.   
  84.   if ($num_records{
  85.     print "Showing records "($page_size ($page 11" - "$page_end ."<br/>";
  86.   }
  87.  
  88.   if (ceil($num_records $page_size1{
  89.     print "Page: ";
  90.     for ($p 1$p <= ceil($num_records $page_size)$p++{
  91.       if($page == $p){
  92.         print " <b>$p</b>";
  93.       else {
  94.         print " <a href=\"search.php?page=$p$query\">$p</a>";
  95.       }
  96.       
  97.       if ($p (ceil($num_records/$page_size))) {
  98.         print ", ";
  99.       }
  100.     }
  101.   }
  102. }
  103.  
  104. /**
  105.  * Displays search results.
  106.  * This function is responsible for displaying the search results.
  107.  * @param search_class $search Search class instance containing search results
  108.  * @param hrdi_db $hdb HRDI database instance
  109.  * @param integer $page The search results page we're on
  110.  * @param integer $page_size The number of results per page
  111.  */
  112. function display_search_results($search$hdb$page$page_size){
  113.   global $session;
  114.  
  115.   $displayed_fields array('UARS''Year-DOY''Day''Date''Direction''Beta''Operational Mode: Azimuths','Comments');
  116.  
  117.   // Results table
  118.   print "<table class=\"hrdi\"><tr class=\"c_label\"><td>Found "
  119.       . sizeof($search->results)
  120.       . " matching records ";
  121.  
  122.   // Download button
  123.   if ($session->get_var("days"&& $session->get_var("types")) {
  124.     print "<input type=\"button\" onClick=\"javascript:location.href='download.php'\" value=\"Download Files\">";
  125.   }
  126.   
  127.   print "</td></tr><tr><td>";
  128.  
  129.   display_page_selector($page$page_sizesizeof($search->results));
  130.  
  131.   print "</td></tr></table>";
  132.  
  133.   // Search results table header
  134.   print  "<table class=\"hrdi\"><tr class=\"c_label\">";
  135.  
  136.   foreach ($displayed_fields as $field{
  137.     print "<td>$field</td>";
  138.   }
  139.       
  140.   // Initialize pids table
  141.   $pids array();
  142.   $j 0;
  143.  
  144.   //Display the search results
  145.   $counter 0
  146.   foreach($search->results as $result{
  147.     if($counter >= ($page_size*($page -1))){
  148.       print "<tr class=\"data\">";
  149.       $day new uars_day($hdb$result);
  150.       print "<td><a href=\"day.php?uars_day={$day->data['UARS_Day']}\">{$day->data['UARS_Day']}</a> </td>
  151.              <td>{$day->data['Year']}-{$day->data['Day_Of_Year']}</td>
  152.              <td>{$day->data['Day_Of_Week']}</td>
  153.              <td>{$day->data['Date']}</td>
  154.              <td>{$day->display_data['Flight_Direction']}</td>
  155.              <td>{$day->data['Beta_Angle']}</td>
  156.              <td nowrap>";
  157.         
  158.       // Create the pids table
  159.       foreach ($day->modes as $mode{
  160.         if (strlen(trim($mode['Description']))) {
  161.           if (array_key_exists($mode['Description']$pids)) {
  162.             // We already have the description
  163.             $def $pids[$mode['Description']]['Def'];
  164.           else {
  165.             // New description
  166.             $pids[$mode['Description']]['Pid'$mode['Process_ID'];
  167.             $pids[$mode['Description']]['Def'$def $j;
  168.             $j++;
  169.           }
  170.         
  171.           print common::deflink($mode['Process_ID']$def);
  172.         else {
  173.           print $mode['Process_ID'];
  174.         }
  175.  
  176.         // Display the modes
  177.         print ": "
  178.             . $mode['Azimuth1']
  179.             . ", "
  180.             . $mode['Azimuth2']
  181.             . ", "
  182.             . $mode['Azimuth3']
  183.             . ", "
  184.             . $mode['Azimuth4']
  185.             . "<br/>\n";
  186.       }
  187.  
  188.       print "</td><td>{$day->data['Comments']}</td></tr>";
  189.     }
  190.  
  191.     $counter++;
  192.     // Exit the display loop if a full page has been displayed
  193.     if($counter == ($page_size*$page)) break;
  194.   }
  195.  
  196.   print "</table>";
  197.  
  198.   // Create the additional JavaScript array indexes for the popup display
  199.   print "<script type=\"text/javascript\">";
  200.  
  201.   foreach ($pids as $desc => $keys{
  202.     print "defs['{$keys['Def']}'] = '$desc';\n";
  203.   }
  204.  
  205.   print "</script>";
  206. }
  207.  
  208. /**
  209.  * Prints file filter form.
  210.  * This function takes an array of file types and the sanitized get variable
  211.  * and prints the html form for filtering searches by file types.
  212.  * @param array $types File types and their ids
  213.  * @param array $got The sanitized get variable
  214.  */
  215. function file_filter_form($types$got){
  216.   print "<table class=\"hrdi\"><tr class=\"c_label\"><td>Filter search results by available file types</td></tr>";
  217.  
  218.   foreach ($types as $type{
  219.     if(isset($got['filetypes']&& in_array($type['ID']$got['filetypes'])) {
  220.       print "<tr><td><input type=\"checkbox\" name=\"filetypes[]\"
  221.              value=\"{$type['ID']}\" checked>{$type['Description']}</td></tr>";
  222.     else {
  223.       print "<tr><td><input type=\"checkbox\" name=\"filetypes[]\"
  224.              value=\"{$type['ID']}\">{$type['Description']}</td></tr>";
  225.     }
  226.   }
  227.  
  228.   print "</table>";
  229. }
  230.  
  231. /**
  232.  * Takes a {@link hrdi_db} class instance and prints the HTML forms for
  233.  * the free form searches.
  234.  * @param hrdi_db $hdb The hrdi_db instance
  235.  * @param array $got The sanitized $_GET array
  236.  */
  237. function free_search_forms($hdb$got$search_results=FALSE){
  238.   //Compose get argument
  239.   $query "";
  240.  
  241.   foreach($got as $k => $v{
  242.     if ($k != 'num_forms'{
  243.       $new_get[$k$v;
  244.     }
  245.   }
  246.  
  247.   foreach($new_get as $k=>$v){
  248.     $query .= "&$k=$v";
  249.   }
  250.     
  251.   print "<!-- Javascript to retain data when adding search forms -->
  252.          <script type=\"text/JavaScript\">
  253.          function submit_form (i) {
  254.            document.search.num_forms.value = (document.search.num_forms.value-0) + i;
  255.            document.search.submitted.value = \"no\";
  256.            document.search.submit();
  257.          }
  258.         </SCRIPT>
  259.         <table class=\"hrdi\">
  260.         <tr class=\"c_label\"><td>Free Form Search Instructions</td></tr>
  261.         <tr><td>
  262.         Select sets consisting of fields, operators and values.  Use the
  263.         controls to add and remove set entry forms.  Search results displayed
  264.         will be the intersection of the sets.
  265.         </td></tr></table>
  266.  
  267.         <!-- Table to align search form and file filter form -->
  268.         <form name=\"search\" method=\"get\">
  269.         ";
  270.  
  271.     print "
  272.         <table><tr valign=\"top\"><td>
  273.         <table class=\"hrdi\">
  274.         <tr class=\"c_label\">
  275.         <td>Field</td><td>Operator</td><td>Value</td>
  276.         <input type=\"hidden\" name=\"submitted\" value=\"yes\">
  277.         <input type=\"hidden\" name=\"free_form\" value=\"yes\">
  278.         <input type=\"hidden\" name=\"num_forms\" value=\"{$got['num_forms']}\">
  279.         <input type=\"hidden\" name=\"table\" value=\"HRDI_Days\">
  280.         </tr>";
  281.  
  282.   require_once('field_names.php');
  283.   for($i =1$i <=$got['num_forms']$i++){
  284.     // Field display
  285.     print "<tr><td><select name=\"field$i\"><option value=\"\">-- Select a Field --</option>";
  286.  
  287.     foreach($field_names as $value=>$name){
  288.       $selected "";
  289.       if (isset($got["field$i"]&& ($got["field$i"== $value)) {
  290.         $selected "SELECTED";
  291.       }
  292.       print "<option value=\"".$value."\" $selected>".$name."</option>\n";
  293.     }
  294.  
  295.     print "</select></td><td>";
  296.  
  297.     print "<select name=\"operator$i\">
  298.            <option value=\"\" ".is_selected_operator("",$i,$got).">-- Select an Operator --</option>
  299.            <option value=\"=\" ".is_selected_operator("=",$i,$got).">is</option>
  300.            <option value=\"!=\" ".is_selected_operator("!=",$i,$got).">is not</option>
  301.            <option value=\"&gt\" ".is_selected_operator(">",$i,$got).">is greater than</option>
  302.            <option value=\"&gt=\" ".is_selected_operator(">=",$i,$got).">is greater than or equal to</option>
  303.            <option value=\"&lt\" ".is_selected_operator("<",$i,$got).">is less than</option>
  304.            <option value=\"&lt=\" ".is_selected_operator("<=",$i,$got).">is less than or equal to</option>
  305.            </select></td><td>";
  306.  
  307.     // Value display, show the previous value data
  308.     print "<input name=\"value$i\" value=\""
  309.         . common::get_value("value$i"$got)
  310.         . "\"></td></tr>";
  311.  
  312.     if ($i != $got['num_forms']{
  313.       print "<tr><td colspan=\"3\"><center>AND</center></td></tr>";
  314.     }
  315.   }
  316.     
  317.   print "<tr><td><a href=\"javascript: submit_form(1);\">Add another search form</a></td>
  318.          <td><a href=\"javascript: submit_form(-1);\">Remove the last search form</a></td>
  319.          <td><input type=\"submit\"></td></tr>";
  320.  
  321.   
  322.   if($search_results){
  323.       print "<tr><td colspan=3><center><b><br/>Found "
  324.           . sizeof($search_results->results)
  325.           . " records. Scroll down for results.<br/></b></center></td></tr>";
  326.   }
  327.   elseif(!isset($_SESSION['error']&& isset($got['submitted'])){
  328.     print "<tr><td colspan=\"3\"><center><div id=\"error\">No matching entries found</div></center></td></tr>";
  329.   }
  330.  
  331.   if(isset($_SESSION['error'])){
  332.     print "<tr><td colspan=\"3\"><center><div id=\"error\">".$_SESSION['error']."</div></center></td></tr>";
  333.     unset($_SESSION['error']);
  334.   }
  335.  
  336.   
  337.   print "</tr></table> 
  338.          </td><td>";
  339.     
  340.   $sql "SELECT *
  341.           FROM HRDI_FileTypes
  342.           ORDER BY ID";
  343.  
  344.   $types $hdb->get_list($sql);
  345.  
  346.   file_filter_form($types$got);
  347.  
  348.   print "</td></tr>";
  349.   print "</table></form>";
  350. }
  351.  
  352. /**
  353.  * Prints predefined search forms.
  354.  * Controls the layout of search forms. Calls all predefined search forms.
  355.  * @param hrdi_db $hdb The hrdi_db instance
  356.  * @param array $got The clean $_GET array
  357.  */
  358. function predefined_search_forms($hdb$got$search_results=FALSE){
  359.   $searches[0]="Operational Mode, Date, Latitude Search";
  360. //  $searches[1]="Operational Mode Search";
  361.  
  362.   for($i=0$i<count($searches);$i++){
  363.     print "<a href=\"search.php?predefined_search=$i\">$searches[$i]</a>";
  364.     if($i+count($searches)){
  365.      print " | ";
  366.     }
  367.   }
  368.   // Gather information needed by search forms
  369.   $pids $hdb->get_table("HRDI_Pids");
  370.  
  371.   $sql "SELECT *
  372.           FROM HRDI_FileTypes
  373.           ORDER BY ID";
  374.  
  375.   $types $hdb->get_list($sql);
  376.  
  377.   $search_num 0;
  378.   $search_num @$got['predefined_search'];
  379.   
  380.   // Place all search form printing functions here
  381.   switch ($search_num{
  382.     case 0:
  383.       pid_day_coverage_form($got$pids$types$search_results);
  384.       break;
  385.     case 1:
  386.       pid_form($got,$types);
  387.       break;
  388.    }
  389. }
  390.  
  391. /**
  392.  * Displays pid search form.
  393.  * This function displays the pid day coverage form. It has been put here for
  394.  * users following the tutorial on writing new search functions.
  395.  * @param array $got The clean $_GET array
  396.  */
  397. function pid_form($got,$types){
  398. ?>
  399.   <!-- Tables class are used for a consistent look -->
  400.   <table class="hrdi">
  401.     <tr class="c_label">
  402.      <td>
  403.      Instructions
  404.      </td>
  405.     </tr>
  406.     <tr>
  407.       <td>
  408.       Enter an Operational Mode (pid) and press search.
  409.       </td>
  410.     </tr>
  411.   </table>
  412.  
  413.   <!-- Using the "get" method allows users to bookmark searches, but also invites tinkering.
  414.        Please use the $got variable to access submitted data for safety.  -->
  415.   <form name="search" method="get">
  416.     <table class="hrdi">
  417.       <tr class="c_label">
  418.         <td>
  419.          Operational Mode Search
  420.         </td>
  421.       </tr>
  422.       <tr>
  423.         <td>
  424.         <!-- This tells search.php to run a search and which search to run -->
  425.         <input type="hidden" name="submitted" value="pid">
  426.         <!-- This tells search_form.php to return to this view after it is submitted -->
  427.         <input type="hidden" name="predefined_search" value="1">
  428.         <!-- This is the data we are submitting. The previous value (if any) is repopulated.-->
  429.         <input type="text" name="pid" value="<?php print common::get_value('pid'$got)?>">
  430.         <input type="submit" name="" value="Search">
  431. <?php
  432.  
  433.   display_search_results$search$hdb$page$page_size );
  434.   
  435. ?>
  436.         </td>
  437.       </tr>
  438.     </table>
  439.     <?php file_filter_form($types$got)?>
  440.   </form>
  441.       <?php
  442. }
  443.  
  444. /**
  445.  * Displays day coverage form.
  446.  * This function displays the pid day coverage form.
  447.  * @param array $got The clean $_GET array
  448.  * @param array $pids Array of pids
  449.  * @param array $types File types
  450.  */
  451. function pid_day_coverage_form($got$pids$types$search_results=FALSE{
  452.   $day_types array("none"=>"No date filter",
  453.                      "UARS_Day"=>"UARS Day",
  454.                      "year_day"=>"Year - Day of Year",
  455.                      "calendar_day"=>"Calendar date")
  456.   
  457.   $coverage_x array("Latitude min (deg.)","Latitude max (deg.)")
  458.   $coverage_y[array("Warm Side","Cold Side");
  459.   $coverage_y[array("Day""Night");
  460.   $coverage_y[array("Asc""Desc");
  461. ?>               
  462.       <!-- Table to align search form and file filter form -->
  463.   <table class="hrdi">
  464.   <tr class="c_label"><td>Instructions</td></tr>
  465.   <tr><td>
  466.   This search has three main components: Operational Mode, Date and Latitude. Each component
  467.   is optional and will not affect the search if left untouched. If an operational mode is
  468.   selected, the search results will be limited to record with that operational mode.  Only
  469.   one or "Any" operational mode may be selected at a time. If a date range is entered, the
  470.   search results will be required to fall within that range. Dates may be
  471.   entered in three formats: 
  472.   <br/>1) Uars day (ex. 71) 
  473.   <br/>2) Year - Day of Year (ex. 1992-255)
  474.   <br/>3) Calendar date (ex. January 17, 1992 or 1/17/1992).
  475.   <br/>Night and day latitude ranges can be specified independently in degrees (ex. 40.7).
  476.   <br/>To search with any combination of available criteria, use the <a href="search.php?free_form">free form search page</a>.
  477.   </td></tr></table>
  478.   <form name="search" method="get">
  479.   <table><tr valign="top"><td>
  480.   <input type="hidden" name="submitted" value="pid_day_coverage">
  481.   <!-- This tells search_form.php to return to this view after it is submitted -->
  482.   <input type="hidden" name="predefined_search" value="0">
  483.   <table class="hrdi">
  484.   <tr class="c_label"><td colspan=3>Search</td></tr>
  485.   <tr><td>Operational mode is
  486.   <select size=5 name="pid">";
  487.   <?php
  488.     if(!isset($got['pid']or $got['pid'== "any"{
  489.       print "<option value=\"any\" selected >Any</option>";
  490.     else {
  491.       print "<option value=\"any\">Any</option>";
  492.     }
  493.  
  494.     
  495.     $sets[]='Daytime';
  496.     $sets[]='Stratosphere';
  497.     $sets[]='Mesosphere';
  498.     $sets[]='Daytime mesosphere';
  499.     $sets[]='Nighttime mesosphere';
  500.     foreach($sets as $set{
  501.       print "<option value=\"{$set}\" ";
  502.       if ($set == @$got['pid']{
  503.         print "selected";
  504.       
  505.       print " >{$set}</option>";
  506.     }
  507.  
  508.     foreach($pids as $pid{
  509.       print "<option value=\"{$pid['Pid']}\" ";
  510.       if ($pid['Pid'== @$got['pid']{
  511.         print "selected";
  512.       
  513.       print " >{$pid['Pid']}: {$pid['Description']}</option>";
  514.     }
  515.   ?>    
  516.   </select>
  517.   </td></tr><tr>
  518.   <td nowrap> and 
  519.   <select size=4 name="date_type">
  520.   <?php
  521.     if (!isset($got['date_type'])){
  522.       $got['date_type'"none";
  523.     }
  524.     common::print_select_options($day_types$got['date_type']);
  525.   ?>
  526.   </select>
  527.   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);}?>">
  528.   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);}?>">
  529.   </td></tr><tr><td colspan="2"><center>and (leave blank for all latitudes)</center>
  530.   <table class="hrdi">
  531.   <tr><td>Day Latitude (degrees) is between:</td>
  532.   <td><input type="text" size="6" name="lat_day_min" value="<?php print common::get_value('lat_day_min'$got)?>">
  533.   and <input type="text" size="6" name="lat_day_max" value="<?php print common::get_value('lat_day_max'$got)?>"></td></tr>
  534.   <tr><td>Night Latitude (degrees) is between:</td>
  535.   <td><input type="text" size="6" name="lat_night_min" value=<?php print common::get_value('lat_night_min'$got)?>> and
  536.   <input type="text" size="6" name="lat_night_max" value=<?php print common::get_value('lat_night_max'$got)?>></td></tr>
  537.   </table>
  538.   </td></tr><tr>
  539.   <td colspan="2" align="right">
  540.   <input type="submit" name="pid_by_date" value="Search">
  541.   </td></tr>
  542.   <?php
  543.   if($search_results){
  544.       print "<tr><td colspan=3><center><b><br/>Found "
  545.           . sizeof($search_results->results)
  546.           . " records. Scroll down for results.<br/></b></center></td></tr>";
  547.   }
  548.   elseif(!isset($_SESSION['error']&& isset($got['submitted'])){
  549.     print "<tr><td colspan=\"3\"><center><div id=\"error\">No matching entries found</div></center></td></tr>";
  550.   }
  551.  
  552.   if(isset($_SESSION['error'])){
  553.     print "<tr><td colspan=\"3\"><center><div id=\"error\">".$_SESSION['error']."</div></center></td></tr>";
  554.     unset($_SESSION['error']);
  555.   }
  556. ?>
  557.   </table>
  558.   </td><td>
  559. <?php
  560.   // Display the file type selector
  561.   file_filter_form($types$got);
  562.  
  563.   print "</td></tr></table></form>";
  564.  
  565.   }
  566. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:52 -0500 by phpDocumentor 1.3.0RC6