<?php
/*

This program is a 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 3.0 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 General Public License for more details.

You can receive a copy of GNU General Public License at the World Wide Web 
address <http://www.gnu.org/licenses/gpl.html>.

--------------------------------------------------------
 Product Name        QueryCatcher
 Product URL        http://www.jasonclark.info/files.php
 Product Description    A PHP/MySQL search term recorder module - collect queries logged into system, presents terms as browseable links
 
 Latest Version        1.0
 Release Date         2008/06/16

 Author's Name        Jason Clark 
 Author's Email        jaclark@montana.edu
 Author's URL        http://jasonclark.info
 License            GNU's Public License (GPL)
--------------------------------------------------------

The code from this application is also available in the Code4Lib Journal (http://journal.code4lib.org).
The article that explains the "QueryCatcher" application is titled: "Making Patron Data Work Harder: User Search Terms as Access Points?"
It can be retrieved at http://journal.code4lib.org/articles/78.

*/


//purpose: This code searches the ETD database for the user specified search terms and logs the search terms to a database table. Then the results are displayed in groups of 15 to the user.
//note: you will need to create your own database, user login, and password to have data to query - see the querycatcher.sql file in package for an example

//pass db name, login data and connection directions
mysql_pconnect("YOUR-DB-HOST","YOUR-DB-USER","YOUR-DB-PASSWORD") or die ("Error: Unable to connect to the database.");    
mysql_select_db("YOUR-DB-NAME");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Search List View: QueryCatcher</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen, projection">
<!--
@import url("styles.css");
?>
-->
</style>
</head>
<body>
<p class="toggle"><a class="expand" href="./searchcloud.php" title="View searches arranged in a weighted cloud list">View searches as a SearchCloud</a> | <a class="expand" href="./form.php" title="Return to main search form">Return to Search Form</a></p>
    <ul id="block">
    <?php
    
//get searches that start with the current variable, place hit number and count number
    
$query "SELECT DISTINCT(query_data), COUNT(query_id) AS query_count, query_results, query_time FROM log GROUP BY query_data ORDER BY query_time DESC LIMIT 0,50";
    
$result mysql_query($query);
    
    
//use while loop to iterate through query results, print out data for display
    
while ($row mysql_fetch_object($result)) {
    
$search rtrim(stripslashes($row->query_data));
    
$searchResults $row->query_results;
    
$searchCount $row->query_count;
        if (
$search != "") {
            echo 
'<li><h2><a href="./results.php?keyword='.urlencode($search).'">'.$search.'</a></h2>'."\n";
            echo 
'<p>Results: <strong>'.$searchResults.'</strong> hits <br/>Term searched/browsed: <strong>'.$searchCount.'</strong> time(s)</p>'."\n";
            echo 
'</li>'."\n";
        }
    }
    
?>
    </ul>
</body>
</html>