<?php
     
    switch ($action):
    case "g_default":
    drawMainTop();
     
    print("searching");
     
    drawMainBottom();
    break;
     
    case "g_sitesearch":
    drawMainTop();
     
    $query_term = $_REQUEST['query_keyword'];
     
    // include the class
    include("nusoap.php");
     
    // create a instance of the SOAP client object
     
    // remember that this script is the client,
    // accessing the web service provided by Google
     
    $soapclient = new soapclient("http://api.google.com/search/beta2");
     
    // uncomment the next line to see debug messages
    // $soapclient->debug_flag = 1;
    $sitename = $_SERVER['SERVER_NAME'];
    // set up an array containing input parameters to be
    // passed to the remote procedure
    $params = array(
    'key' => 'PUTYOURGOOGLEKEYHERE', // Google license key
    'q' => $query_term . " site:" . $sitename, // search term
    'start' => 0, // start from result
    'maxResults' => 10, // show a total of n results
    'filter' => false, // remove similar results
    'restrict' => '', // restrict by topic
    'safeSearch' => false, // remove adult links
    'lr' => '', // restrict by language
    'ie' => '', // input encoding
    'oe' => '' // output encoding
    );
     
     
     
    // invoke the method on the server
    $result = $soapclient->call("doGoogleSearch", $params, "urn:GoogleSearch", "urn:GoogleSearch");
     
    if (array_key_exists('faultstring', $result))
    {
        if ($result['faultstring'] )
        {
            print("An error occurred contacting the Google Web APIs");
        }
    }
    else
    {
        $query = $result['searchQuery'];
        $rescount = $result['estimatedTotalResultsCount'];
        $time = $result['searchTime'];
        print("Search for " . $query . " returned " . $rescount . " results in " . $time . " seconds.<br />");
         
        if (is_array($result['resultElements']) )
        {
            $idx = 1;
            foreach($result['resultElements'] as $r )
            {
                print("<div class=\"searchresult\">");
                print("<div class=\"searchtitle\">" . $idx . ". <a href=\"" . $r['URL'] . "\">" . $r['title'] . "</a></div>");
                print($r['URL'] . "<br /><br />");
                print($r['snippet'] . "<br /><br />");
                print("</div>");
                $idx++;
            }
        }
    }
    drawMainBottom();
    break;
     
     
    endswitch;
     
?>
