Source for file search.php
Documentation is available at search.php
* This file contains the logic that composes and routes search requests.
* It makes use of search_forms.php for display elements and search_class.php for search execution.
* 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
/** Configuration file */
require_once("conf.php");
/** Debugging functions */
require_once("debugging.php");
require_once("search_class.php");
require_once("search_forms.php");
require_once("session_class.php");
/** HRDI database class */
require_once("hrdi_db_class.php");
require_once("user_class.php");
* Composes an indexed array of associative arrays for free form searching from the $_GET
* formatted input. See search_class::free_form for the required conditions format.
* @param mixed $got The sanitized get variable
* @param int $num_forms The number of arrays to be built
for($i = 1; $i <= $num_forms; $i++ ){
if(isset ($got["value$i"]) && $got["value$i"] != "" && $got["field$i"] != "" && $got["operator$i"] != ""){
$conditions[] = array("Table"=> $got["table"],
"Field"=> $got["field$i"],
"Operator"=> $got["operator$i"],
"Value"=> $got["value$i"]);
* Check string for sql injection attacks. Every value that originates in GET and is put into a sql statement
* must be passed through this function for security.
* @param string $string A string to be sanitized.
* Validates $_GET values.
* This function validates and cleans the values passed in the $_GET array.
* It ensures that malicious actions cannot be performed.
* @return array Clean values
foreach($_GET as $k=> $v){
foreach($v as $key=> $val){
// Determine which page of a multi-page result set is shown
if(isset ($_GET['page']) && !is_numeric($_GET['page'])){
// Default to page 1 if a page is not set in the get variable, else set $page to the get value.
if(isset ($_GET['page'])){
$clean['page']= $_GET['page'];
// Determine how many free form search input forms are/were displayed
if(isset ($_GET['num_forms']) && !is_numeric($_GET['num_forms'])){
error("Bad num_forms value");
if(isset ($_GET['num_forms']) && ($_GET['num_forms'] > 1)){
$clean['num_forms'] = $_GET['num_forms'];
if($clean['num_forms'] > 100){
error("Please limit yourself to 100 search forms");
$clean['num_forms'] = 100;
if(isset ($_GET['free_form']) || isset ($_GET['free_form'])){
$clean['free_form'] = "yes";
// Prepare the conditions from the get value
// Determine which cookie the search conditions may be stored/read from
$cookie_name = 'hrdiodb_search';
if(isset ($got['free_form'])){
$cookie_name = 'hrdiodb_free_form_search';
// If a search was performed, store it in a cookie
if(isset ($got['submitted']) && $got['submitted']!= "no"){
unset ($got_copy['submitted']);
// Make sure the search doesn't time out
// Create class instances
$user = new user($hdb, $session);
if (isset ($got['free_form'])) {
$page_title = "Free Form Search";
$page_title = "Pre-defined Search";
// Include the page header
require_once("header.php");
// Create the search instance and perform the search
if(isset ($got['submitted']) && $got['submitted']!= "no"){
// Process free form search entries
if(isset ($got['free_form'])){
$status = $search->free_form($conditions);
error("Free form search failed");
// Process a predefined search entry
if($got['submitted']== "pid_day_coverage"){
// The got variable is not passed itself because searches may be (in other interfaces) called in other manners.
$status = $search->pid_day_coverage($got['pid'], @$got['date_type'],$got['date_value_low'],$got['date_value_high'], $got['lat_day_min'], $got['lat_day_max'], $got['lat_night_min'], $got['lat_night_max']);
if($got['submitted']== "pid"){
$conditions[0]["Table"]= "HRDI_Modes";
$conditions[0]["Field"]= "Process_ID";
$conditions[0]["Operator"]= "=";
$conditions[0]["Value"]= @$got['pid'];
$status = $search->free_form($conditions);
// Apply file type filter to search results
if(isset ($status) && isset ($got['filetypes'])){
$search->filetype_filter($got['filetypes']);
// Store search results for download logic to access
if (isset ($got['filetypes'])) {
$session->set_var("types", $got['filetypes']);
$session->set_var("days", $search->results);
$session->unset_var("types");
$session->unset_var("days");
// Re-prepare the conditions from the get value to account for changes made by search class methods
elseif(isset ($_COOKIE[$cookie_name]) && (!isset ($got['submitted']) || $got['submitted'] != 'no')){
if (isset ($got['free_form'])) {
if(isset ($search) && $status){
if(isset ($search) && $status){
if(isset ($got['submitted']) && $got['submitted']!= "no" && !$cookie_loaded){
// Display the search results
// Include the page footer
require_once("footer.php");
|