All pastes #477411 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-08 17:13 UTC
rendered paste body
<?php
/*******************************
 *   PHP Web search form for   *
 *   Searchy the IRC Log Bot   *
 *     Copyright (c) 2007      *
 *        Andrew Wilcox        *
 *     All Rights Reserved     *
 *******************************/

/** header **/
$title = "Searchy";
require_once("header.inc");

/** connect to database **/
$conn = mysql_connect("66.104.104.132", "imasandwich", "imasandwich") or die(mysql_error());

/** select database **/
mysql_select_db("searchy") or die(mysql_error());

/** is the form submitted? */
if(isset($_POST['submit']))
{
    /** yes **/
    echo "<h2>Search results:</h2>\n";
    echo "<span class=\"search-text\">You searched for $_POST[type]";
    /** beginning of query **/
    $query = "SELECT * FROM searchy ";
    /** what kind of query? **/
    switch($_POST[kind])
    {
    case "exact":
        /** exact string **/
        $query .= sprintf("WHERE %s='%s' AND channel REGEXP '%s$' ",
            mysql_real_escape_string($_POST[type]), mysql_real_escape_string($_POST[terms]),
            mysql_real_escape_string($_POST[channel]));
        echo " $_POST[terms]";
        break;
    case "regexp":
        /** regular expression **/
        $query .= sprintf("WHERE %s REGEXP '%s' AND channel REGEXP '%s$' ",
            mysql_real_escape_string($_POST[type]), mysql_real_escape_string($_POST[terms]),
            mysql_real_escape_string($_POST[channel]));
        echo "s that match the regular expression $_POST[terms]";
        break;
    default:
        /** unknown -- possibly malformed request **/
        die("That option was not valid.  Please select a different kind of search, or report this error to your systems administrator.");
    }
    $datestart = strtotime($_POST[startdate]);
    $datestart = unixtojd($datestart);
    $datestart -= 2444239;
    $datestop = strtotime($_POST[stopdate]);
    if ($_POST[stopdate] = "") $datestop == $time;
    $datestop = unixtojd($datestop);
    $datestop -= 2444239;
    echo("<br>$datestart<br>");
    if($_POST[startdate] != "") echo " starting on $_POST[startdate] and ";
    if($_POST[stopdate] != "") echo "ending on $_POST[stopdate]";
    if($_POST[channel] != "") echo " in channel $_POST[channel].";
    
    else echo ".";
    /** $query .= "AND mdate >; **/
    /** order by date **/
    $query .= "ORDER BY mdate";
    /** start table **/
    echo "<table class=\"results\">\n";
    /** query it! **/
    echo("$query <br>");
    $result = mysql_query($query) or die(mysql_error());
    /** fetch the results **/


    //$query_loop = "SELECT * FROM searchy WHERE increment > $fstart AND increment < $fstop ORDER BY mdate";
    //$result = mysql_query($query_loop) or die(mysql_error());
    while($row_outer = mysql_fetch_array($result))
    {
        //new stuff! lets loop through and get context... maybe
        $fstart = $row_outer[increment] - 5;
        $fstop = $row_outer[increment] + 5;
        if($fstart < 0) $fstart = 1;

        $query_loop = "SELECT * FROM searchy WHERE increment > $fstart AND increment < $fstop ORDER BY mdate"; 
        echo ($query_loop);
        $result = mysql_query($query_loop) or die(mysql_error());                                              
        while($row = mysql_fetch_array($result))
        {
        $daycount = $row[mdate];
        $daycount = intval($daycount);
        $daycount +=2444240;
        $i = 1 / 24;
        $tz = intval($_POST[tzoffset]);
        $daycount +=($i * $tz);
        $date = jdtogregorian($daycount);
        $time = $row[mdate];
        $time += ($i * $tz);
        $i = intval($time);
        $time -= $i;
        $time *= 86400;
        $secs = $time;
        $mins = $secs / 60;
        $mins = intval($mins);
        $secs -= ($mins * 60);
        $secs = intval($secs);
        $hrs  = $mins / 60;
        $hrs  = intval($hrs);
        $mins -= ($hrs * 60);
        $htmlrow = sprintf("<tr valign=\"top\"><td><a title=\"Date of message\">[%s %02s:%02s:%02s]</a></td> <td><a title=\"Channel\">%s</a></td> <td><a title=\"Nickname\">&lt;%s&gt;</a></td> <td><a title=\"Message text\">%s</a></td></tr>\n", $date, $hrs, $mins, $secs, $row[channel], $row[nick], htmlspecialchars($row[message]));
        if ($row[mdate] > $datestart)
         echo($htmlrow);
    };
    };
    echo "</table>\n";
        //echo($query);
} else {
    echo "<script src=\"JonathanD.js\" type=\"text/javascript\" />\n";
    echo "<form action=\"./index.php\" method=\"post\" name=\"searchy\">\n";
    echo "<div class=\"form-content\">\n<p>\nSearch for ";
    echo "<select name=\"type\">\n<option value=\"nick\">nicknames</option>\n";
    echo "<option selected=\"selected\" value=\"message\">message texts</option>\n</select> ";
    echo "<select name=\"kind\">\n";
    echo "<option value=\"exact\">with the exact phrase</option>\n";
    echo "<option selected=\"selected\" value=\"regexp\">using the regular expression</option>\n</select>\n";
    echo "<input type=\"text\" name=\"terms\" />\n";
    echo "<select name=\"channel\">\n";
    $query = "SELECT DISTINCT channel FROM searchy WHERE 1 ORDER BY channel"; 
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
        $channel = preg_replace("/^#{1,2}/", "", $row[channel]);
        $htmlrow = sprintf("<option value=\"%s\">%s</option>\n", $channel, $row[channel]);
        if ($channel != "searchy" and $channel != "searchy2") {
        echo($htmlrow);
        }
    }
    echo "</select>\n</p>\n";
    echo "<input type=\"submit\" name=\"submit\" value=\"Search\" />\n</div>\n";
    echo "<div onclick=\"toggleAdvancedOptions();\" id=\"toggle\">Show advanced options</div>\n<br />\n";
    echo "<div class=\"form-content\" id=\"advanced\">\n<p>\n<b>Advanced options:</b><br>\n";
    echo "Between Date:<input type=\"text\" name=\"startdate\"/>\n";
    echo "and Date:<input type=\"text\" name=\"stopdate\"/>\n";
    echo "<select name=\"tzoffset\">\n";
    echo "<option value=\"-12\">(GMT -12:00) Eniwetok, Kwajalein</option>\n";
    echo "<option value=\"-11\">(GMT -11:00) Midway Island, Samoa</option>\n";
    echo "<option value=\"-10\">(GMT -10:00) Hawaii</option>\n";
    echo "<option value=\"-09\">(GMT -09:00) Alaska</option>\n";
    echo "<option value=\"-08\">(GMT -08:00) Pacific Standard (US & Canada), Tijuana</option>\n";
    echo "<option value=\"-07\">(GMT -07:00) Mountain Standard, Pacific Daylight (US & Canada)</option>\n";
    echo "<option value=\"-06\">(GMT -06:00) Central Standard, Mountain Daylight (US & Canada)</option>\n";
    echo "<option value=\"-05\">(GMT -05:00) Eastern Standard, Central Daylight (US & Canada)</option>\n";
    echo "<option value=\"-04\">(GMT -04:00) Atlantic Standard, Eastern Daylight (US & Canada)</option>\n";
    echo "<option value=\"-03.5\">(GMT -03:30) Newfoundland</option>\n";
    echo "<option value=\"-03\">(GMT -03:00) Brasilia, Buenos Aires</option>\n";
    echo "<option value=\"-02\">(GMT -02:00) Mid-Atlantic</option>\n";
    echo "<option value=\"-01\">(GMT -01:00) Azores, Cape Verde Islands</option>\n";
    echo "<option selected=\"selected\" value=\"0\">(GMT) Greenwich Mean Time, UTC, Dublin, London, Casablanca, Lisbon, Edinburgh</option>\n";
    echo "<option value=\"1\">(GMT +01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna, Brussels, Copenhagen, Madrid, Paris, Vilnius, Warsaw, Sarajevo</option>\n";
    echo "<option value=\"2\">(GMT +02:00) Athens, Cairo, Istanbul, Jerusalem</option>\n";
    echo "</select>\n</p>\n</div>\n";
    echo "</form>";
};

mysql_close($conn) or die(mysql_error());

require_once("./footer.inc");
?>