} elseif ($_GET['highwire_selection'] == 'ti') {
         $query_string = urlencode("title =\"{$_GET['highwire_query']}\"");
     } elseif ($_GET['highwire_selection'] == 'abs') {
         $query_string = urlencode("dc.description =\"{$_GET['highwire_query']}\"");
     }
 }
 ########## search highwire ##############
 if (!empty($query_string) && empty($_GET['load']) && empty($_GET['save']) && empty($_GET['delete'])) {
     ############# caching ################
     $cache_name = cache_name();
     $cache_name .= '_download';
     $db_change = database_change(array('library'));
     cache_start($db_change);
     ########## search highwire ##############
     $request_url = "http://highwire.stanford.edu/cgi/sru?version=1.1&operation=searchRetrieve&query={$query_string}&startRecord=" . ($from - 1) . "&sendit=Search";
     $xml = proxy_dom_load_file($request_url, $proxy_name, $proxy_port, $proxy_username, $proxy_password);
     if ($xml === false) {
         die('Error! I, Librarian could not connect with an external web service. This usually indicates that you access the Web through a proxy server.
         Enter your proxy details in Tools->Settings. Alternatively, the external service may be temporarily down. Try again later.');
     }
 }
 ########## display search result summaries ##############
 if (isset($xml)) {
     print '<div style="padding:2px;font-weight:bold">Highwire search';
     if (!empty($_SESSION['session_download_highwire_searchname'])) {
         print ': ' . htmlspecialchars($_SESSION['session_download_highwire_searchname']);
     }
     print '</div>';
     libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     $doc->loadXML($xml);
function fetch_from_ol($ol_id, $isbn)
{
    global $proxy_name, $proxy_port, $proxy_username, $proxy_password, $response;
    if (!empty($ol_id)) {
        $query = 'q=' . urlencode($ol_id);
    } elseif (!empty($isbn)) {
        $query = 'isbn=' . urlencode($isbn);
    }
    $request_url = "http://openlibrary.org/search.json?" . $query;
    $ol = proxy_dom_load_file($request_url, $proxy_name, $proxy_port, $proxy_username, $proxy_password);
    if (empty($ol)) {
        die('Error! I, Librarian could not connect with an external web service. This usually indicates that you access the Web through a proxy server.
            Enter your proxy details in Tools->Settings. Alternatively, the external service may be temporarily down. Try again later.');
    }
    $ol = json_decode($ol, true);
    if ($ol['num_found'] !== 1) {
        die('Error! Unique record not found in Open Library.');
    }
    $record = $ol['docs'][0];
    $response['title'] = $record['title'];
    if (isset($record['subtitle'])) {
        $response['title'] .= ': ' . $record['subtitle'];
    }
    $response['year'] = $record['first_publish_year'] . '-01-01';
    //GET AUTHORS
    $name_array = array();
    if (count($record['author_name']) > 0) {
        foreach ($record['author_name'] as $author) {
            $author_array = explode(' ', $author);
            $last = array_pop($author_array);
            $first = join(' ', $author_array);
            $name_array[] = 'L:"' . $last . '",F:"' . $first . '"';
            $response['last_name'][] = $last;
            $response['first_name'][] = $first;
        }
    }
    if (isset($name_array)) {
        $response['authors'] = join(";", $name_array);
    }
    $response['keywords'] = '';
    if (count($record['subject']) > 0) {
        $response['keywords'] = join(' / ', $record['subject']);
    }
    $response['reference_type'] = 'book';
    if (empty($ol_id)) {
        $ol_id = $record['edition_key'][0];
        $response['uid'][] = 'OL:' . $ol_id;
    }
    if (empty($isbn)) {
        $isbn = $record['isbn'][0];
        $response['uid'][] = 'ISBN:' . $isbn;
    }
    $response['url'][] = 'http://openlibrary.org/book/' . $ol_id;
}