Esempio n. 1
0
function antall_treff($q)
{
    global $config;
    $bib = $_GET['bib'];
    $debug = 0;
    if ($config['libraries'][$bib]['sru']) {
        // SRU
        $qu = urlencode($q);
        $query = '(dc.author=' . $qu . '+or+dc.title=' . $qu . ')+and+dc.title=lydopptak';
        $sruurl = $config['libraries'][$bib]['sru'] . '?version=1.1&operation=searchRetrieve&query=' . $query;
        if ($xml = file_get_contents($sruurl)) {
            preg_match("/numberOfRecords>(.*?)</", $xml, $matches);
            return $matches[1];
        } else {
            echo 'error';
        }
    } else {
        //Z39.50
        $ccl = "(fo={$q} or in={$q} or ti={$q}) and ti=lydopptak";
        $host = $config['libraries'][$bib]['z3950'];
        $zconfig = get_zconfig();
        $type = 'xml';
        $syntax = 'NORMARC';
        $id = yaz_connect($host);
        yaz_element($id, "F");
        yaz_syntax($id, $syntax);
        yaz_range($id, 1, 1);
        yaz_ccl_conf($id, $zconfig);
        $cclresult = array();
        if (!yaz_ccl_parse($id, $ccl, $cclresult)) {
            echo $debug ? 'Error: ' . $cclresult["errorstring"] : 'error';
        } else {
            $rpn = $cclresult["rpn"];
            yaz_search($id, "rpn", utf8_decode($rpn));
        }
        yaz_wait();
        $error = yaz_error($id);
        if (!empty($error)) {
            echo $debug ? "Error yazCclArray: {$error}" : 'error';
        } else {
            return yaz_hits($id);
        }
    }
}
}
if (!empty($lookupVal5)) {
    $qry = '@and ' . $qry . ' @attr 1=' . $srchBy5 . ' ' . $lookupVal5;
}
//echo 'Query specification is: ' . htmlspecialchars($qry) . '<br />';
//showMeComplex('host array',$postVars[hosts]);
for ($i = 0; $i < $postVars[numHosts]; $i++) {
    //			$ptr = ($useHost == -1)?$i:$useHost;
    $ptr = $i;
    //showMeComplex("using host #$ptr",$postVars[hosts][$ptr][name]);
    //showMeComplex("using host #$ptr",$postVars[hosts][$ptr]);
    //showMeComplex("using host #$ptr",$postVars[hosts]);
    $aHost = $postVars[hosts][$ptr][host];
    $aUser = $postVars[hosts][$ptr][user];
    $aPw = $postVars[hosts][$ptr][pw];
    $connOK = yaz_connect($aHost, array("user" => $aUser, "password" => $aPw));
    if (!$connOK) {
        echo 'yaz setup not successful! <br />';
        trigger_error($lookLoc->getText("lookup_yaz_setup_failed") . $postVars[hosts][$ptr][name] . "<br />", E_USER_ERROR);
    } else {
        //echo 'yaz setup successful! <br />';
        $id[$ptr] = $connOK;
        $db = $postVars[hosts][$ptr][db];
        //echo "specifying db: $db<br />";
        yaz_database($id[$ptr], $db);
        yaz_syntax($id[$ptr], $syntax);
        yaz_element($id[$ptr], "F");
        //echo "sending: $qry <br />";
        if (!yaz_search($id[$ptr], $srchType, $qry)) {
            trigger_error($lookLoc->getText("lookup_badQuery") . "<br />", E_USER_NOTICE);
        }
Esempio n. 3
0
 $query = '';
 if ($keywords) {
     // parsing keywords and map query to RPN
     switch ($_GET['field']) {
         case 'ti':
             $query = '@or @and @attr 1=4 ' . $keywords . ' @and @attr 1=5 ' . $keywords;
             break;
         case 'au':
             $query = '@attr 1=1 @and ' . $keywords;
             break;
         default:
             $query = '@or @attr 1=7 ' . $keywords . ' @attr 1=8 ' . $keywords;
             break;
     }
     for ($h = 0; $h < $num_hosts; $h++) {
         $id[] = yaz_connect($zserver[$h]);
         yaz_syntax($id[$h], 'usmarc');
         yaz_range($id[$h], 1, $sysconf['z3950_max_result']);
         yaz_search($id[$h], 'rpn', $query);
     }
     yaz_wait();
     // preparing to buffer MARC XML result
     $errors = array();
     $hits = 0;
     ob_start();
     echo '<?xml version="1.0" standalone="yes"?>' . "\n";
     echo '<collection xmlns="http://www.loc.gov/MARC21/slim">' . "\n";
     for ($h = 0; $h < $num_hosts; $h++) {
         $error = yaz_error($id[$h]);
         if (!empty($error)) {
             $errors[] = $error;
Esempio n. 4
0
            GILS test
                <input type="checkbox" name="host[]" value="www.bibhit.dk">
                Bibhit
                <input type="checkbox" checked="1" name="host[]" value="blpcz.bl.uk:21021/BLPC-ALL">
                British Library
<br>
RPN Query:
<input type="text" size="30" name="term">
<input type="submit" name="action" value="Search">
        ';        
    }
    else
    {
        echo 'You searced for ' . htmlspecialchars($term) . '<br>';
        for ($i = 0; $i < $num_hosts; $i++) {
            $id[] = yaz_connect($host[$i]);
            yaz_syntax($id[$i],"sutrs");
            yaz_search($id[$i],"rpn",$term);
        }
        yaz_wait();
        for ($i = 0;  $i <$num_hosts; $i++)
        {
            echo '<hr>' . $host[$i] . ":";
            $error = yaz_error($id[$i]);
            if (!empty($error)) {
                echo "Error: $error";
            } else {
                $hits = yaz_hits($id[$i]);
                echo "Result Count $hits";
            }
            echo '<dl>';
        if ($val1 == "" and $val2 == "") {
            affiche_jsscript($msg['z3950_echec_no_champ'], "z3950_failed", $bib_id);
        } else {
            affiche_jsscript($msg['z3950_echec_no_valid_attr'], "z3950_failed", $bib_id);
        }
    } else {
        //////////////////////////////////////////////////////////////////////////////////
        // the query is ok we prepare the Z 3950 process for this biblio and
        // save the $id to be able later to retrieve the records from the servers
        //////////////////////////////////////////////////////////////////////////////////
        //$stato[$bib_id] = 1;
        $auth = $auth_user . $auth_pass;
        if ($auth != "") {
            $id = yaz_connect("{$url}:{$port}/{$base}", array("user" => $auth_user, "password" => $auth_pass, "piggyback" => false)) or affiche_jsscript($msg['z3950_echec_cnx'], "z3950_failed", $bib_id);
        } else {
            $id = yaz_connect("{$url}:{$port}/{$base}", array("piggyback" => false)) or affiche_jsscript($msg['z3950_echec_cnx'], "z3950_failed", $bib_id);
        }
        $map[$bib_id] = $id;
        yaz_element($id, "F");
        $etrange_limite = $limite_notices;
        yaz_range($id, 1, $etrange_limite);
        yaz_syntax($id, strtolower($format));
        echo $term;
        yaz_search($id, "rpn", $term);
    }
}
///////////////////////////////////////////////////////////////////////////
// Fase 2: all the possible connections are ready now start the researches
//////////////////////////////////////////////////////////////////////////
//Correction mystérieuse : visiblement la fonction yaz_search impacte la variable global $limite... modifié en $limite_notices
affiche_jsscript($msg['z3950_zmsg_wait'], "", $mioframe);
 /**
  * 
  * 
  * @param string $ps_source
  * @param array $pa_options
  * @return bool
  */
 public function nextRow()
 {
     if (!$this->opa_row_ids || !is_array($this->opa_row_ids) || !sizeof($this->opa_row_ids)) {
         return false;
     }
     if (isset($this->opa_row_ids[$this->opn_current_row]) && ($vn_worldcat_id = $this->opa_row_ids[$this->opn_current_row])) {
         $o_client = new Client(WorldCatDataReader::$s_worldcat_detail_url);
         // Create a request
         try {
             if ($this->opb_z3950_available && $this->ops_z3950_user) {
                 $r_conn = yaz_connect(WorldCatDataReader::$s_worldcat_z3950_host, array('user' => $this->ops_z3950_user, 'password' => $this->ops_z3950_password));
                 yaz_syntax($r_conn, "usmarc");
                 yaz_range($r_conn, 1, 10);
                 yaz_search($r_conn, "rpn", '@attr 1=12 @attr 4=2 "' . str_replace('"', '', $vn_worldcat_id) . '"');
                 yaz_wait();
                 $vs_data = simplexml_load_string(yaz_record($r_conn, 1, "xml; charset=marc-8,utf-8"));
             } elseif ($this->ops_api_key) {
                 $o_request = $o_client->get("{$vn_worldcat_id}?wskey=" . $this->ops_api_key);
                 $o_response = $o_request->send();
                 $vs_data = $o_response->xml();
             } else {
                 throw new Exception("Neither Z39.50 nor WorldCat web API is configured");
             }
             if (!$vs_data) {
                 throw new Exception("No data returned");
             }
             $o_row = $this->opo_handle_xml = dom_import_simplexml($vs_data);
             $this->opa_row_buf[$this->opn_current_row] = $o_row;
         } catch (Exception $e) {
             return false;
         }
         $this->opa_row_buf = array();
         $this->_extractXMLValues($o_row);
         $o_row_clone = $o_row->cloneNode(TRUE);
         $this->opo_handle_xml = new DOMDocument();
         $this->opo_handle_xml->appendChild($this->opo_handle_xml->importNode($o_row_clone, TRUE));
         $this->opo_handle_xpath = new DOMXPath($this->opo_handle_xml);
         if ($this->ops_xml_namespace_prefix && $this->ops_xml_namespace) {
             $this->opo_handle_xpath->registerNamespace($this->ops_xml_namespace_prefix, $this->ops_xml_namespace);
         }
         $this->opn_current_row++;
         if ($this->opn_current_row > $this->numRows()) {
             return false;
         }
         return true;
     }
     return false;
 }
Esempio n. 7
0
* Returns a MarcXML record when queried with an bibliographic identifier. 
*/
// Z39.50 address, eg. host:port/dbname
$host = '';
if (isset($_REQUEST['bib_id'])) {
    // Simple sanitizing of input
    $bib_id = preg_replace("/[^a-zA-Z0-9 ]+/", "", $_REQUEST['bib_id']);
    header('Content-Type: text/xml');
    header('Content-Disposition: inline; filename="' . $bib_id . '.xml";');
    $bib_id = '@attr 1=12 ' . $bib_id;
    // The backend server can be unreliable, so we'll try connecting multiple
    // times if we get an erroneous response.
    $xml_string;
    $maxTries = 5;
    for ($try = 1; $try <= $maxTries; $try++) {
        $id = yaz_connect($host);
        yaz_syntax($id, "usmarc");
        yaz_range($id, 1, 1);
        $host_options = array("timeout" => "10");
        yaz_search($id, "rpn", $bib_id);
        yaz_wait($host_options);
        $error = yaz_error($id);
        if (empty($error)) {
            // Successful Z39.50 Connection
            $rec = yaz_record($id, 1, 'xml');
            if (!empty($rec)) {
                // Successul record retrieval
                http_response_code(200);
                $doc = new DOMDocument();
                $doc->loadXML($rec);
                $doc->formatOutput = true;
function do_search_and_show_hits()
{
    output_header("Search Results");
    echo "<br>";
    if (empty($_GET['start'])) {
        $start = 1;
    } else {
        $start = $_GET['start'];
    }
    if (!empty($_GET['fq'])) {
        $fullquery = unserialize(base64_decode($_GET['fq']));
    } else {
        $fullquery = query_format();
    }
    global $external_catalog_locator;
    $id = yaz_connect($external_catalog_locator);
    yaz_syntax($id, "usmarc");
    yaz_element($id, "F");
    yaz_search($id, "rpn", trim($fullquery));
    $extra_options = array("timeout" => 60);
    yaz_wait($extra_options);
    $errorMsg = yaz_error($id);
    if (!empty($errorMsg)) {
        echo "<center>";
        echo _("The following error has occurred:");
        echo "<br><br>";
        echo "<b><i>{$errorMsg}</i></b>";
        echo "<p>";
        $url = "editproject.php?action=createnew";
        echo sprintf(_("Please try again. If the problem recurs, please create your project manually by following this <a href='%s'>link</a>."), $url);
        echo "</center>";
        exit;
    }
    echo "<center>";
    if (yaz_hits($id) == 0) {
        echo "<b>";
        echo _("There were no results returned.");
        echo "</b>";
        echo "<br>";
        echo _("Please search again or click 'No Matches' to create the project manually.");
        echo "<br>";
    } else {
        echo "<b>";
        echo sprintf(_("%d results returned. Note that some non-book results may not be displayed."), yaz_hits($id));
        echo "<br>";
        echo _("Please pick a result from below:");
        echo "</b>";
    }
    echo "</center>";
    echo "<br><form method='post' action='editproject.php'>";
    echo "<input type='hidden' name='action' value='create_from_marc_record'>";
    echo "<table border='0 width='100%' cellpadding='0' cellspacing='0'>";
    // -----------------------------------------------------
    $hits_per_page = 20;
    // Perhaps later this can be a PM preference or an option on the form.
    $i = 1;
    while ($start <= yaz_hits($id) && $i <= $hits_per_page) {
        $rec = yaz_record($id, $start, "array");
        //if it's not a book don't display it.  we might want to uncomment in the future if there are too many records being returned - if (substr(yaz_record($id, $start, "raw"), 6, 1) != "a") { $start++; continue; }
        $marc_record = new MARCRecord();
        $marc_record->load_yaz_array($rec);
        if ($i % 2 == 1) {
            echo "<tr>";
        }
        echo "<td width='5%' align='center' valign='top'>";
        echo "<input type='radio' name='rec' value='" . base64_encode(serialize($rec)) . "'>";
        echo "</td>";
        echo "<td width='45%' align='left' valign='top'>";
        echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'>";
        foreach (array(array('label' => _("Title"), 'value' => $marc_record->title), array('label' => _("Author"), 'value' => $marc_record->author), array('label' => _("Publisher"), 'value' => $marc_record->publisher), array('label' => _("Language"), 'value' => $marc_record->language), array('label' => _("LCCN"), 'value' => $marc_record->lccn), array('label' => _("ISBN"), 'value' => $marc_record->isbn)) as $couple) {
            $label = $couple['label'];
            $value = $couple['value'];
            echo "<tr>";
            echo "<td width='20%' align='left' valign='top'><b>{$label}</b>:</td>";
            echo "<td align='left' valign='top'>{$value}</td>";
            echo "</tr>\n";
        }
        echo "</table><p></td>";
        if ($i % 2 != 1) {
            echo "</tr>\n";
        }
        $i++;
        $start++;
    }
    if ($i % 2 != 1) {
        echo "</tr>\n";
    }
    // -----------------------------------------------------
    $encoded_fullquery = base64_encode(serialize($fullquery));
    echo "<tr>";
    echo "<td colspan='2' width='50%' align='left' valign='top'>";
    if (isset($_GET['start']) && $_GET['start'] - $hits_per_page > 0) {
        $url = "external_catalog_search.php?action=do_search_and_show_hits&start=" . ($_GET['start'] - $hits_per_page) . "&fq={$encoded_fullquery}";
        echo "<a href='{$url}'>Previous</a>";
    } else {
        echo "&nbsp;";
    }
    echo "</td>";
    echo "<td colspan='2' width='50%' align='right' valign='top'>";
    if ($start + $hits_per_page <= yaz_hits($id)) {
        $url = "external_catalog_search.php?action=do_search_and_show_hits&start={$start}&fq={$encoded_fullquery}";
        echo "<a href='{$url}'>Next</a>";
    } else {
        echo "&nbsp;";
    }
    echo "</td>";
    echo "</tr>\n";
    // -----------------------------------------------------
    echo "</table><br><center>";
    if (yaz_hits($id) != 0) {
        echo "<input type='submit' value='", attr_safe(_("Create the Project")), "'>&nbsp;";
    }
    $label = attr_safe(_('Search Again'));
    $url = "external_catalog_search.php?action=show_query_form";
    echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>";
    echo "&nbsp;";
    $label = attr_safe(_('No Matches'));
    $url = "editproject.php?action=createnew";
    echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>";
    echo "&nbsp;";
    $label = attr_safe(_('Quit'));
    $url = "projectmgr.php";
    echo "<input type='button' value='{$label}' onclick='javascript:location.href=\"{$url}\";'>";
    echo "</form>";
    echo "</center>";
    yaz_close($id);
}
Esempio n. 9
0
<?php

$z = yaz_connect("localhost:9999");
yaz_range($z, 1, 2);
yaz_search($z, "rpn", "computer");
yaz_wait();
$error = yaz_error($z);
if (!empty($error)) {
    echo "Error: {$error}\n";
} else {
    $hits = yaz_hits($z);
    echo "Result count {$hits}\n";
    for ($p = 1; $p <= 2; $p++) {
        $rec = yaz_record($z, $p, "string");
        if (empty($rec)) {
            break;
        }
        echo "----- {$p} -----\n{$rec}";
    }
}
 function doZConnect()
 {
     $zid = yaz_connect($this->z_host, $this->z_options);
     if (!$zid) {
         $this->addError("error", sprintf(_("Verbindung zu %s kann nicht aufgebaut werden!"), $this->z_host));
         return false;
     }
     return $zid;
 }
Esempio n. 11
0
 * Aufruf aus Webbrowser:
 * swb?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * swb?ppn=PPN
 *   PPN ist die eine ID-Nummer des SWB
 * swb?isbn=ISBN&format=json
 * swb?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im SWB-Katalog
 * und gibt maximal 10 Ergebnisse als MARCXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(SWB_URL);
yaz_syntax($id, SWB_SYNTAX);
//utf-8 Kodierung
yaz_range($id, 1, 10);
yaz_element($id, SWB_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=12 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';
Esempio n. 12
0
function yazCclArray($ccl, $syntax = 'marc21', $host = 'default')
{
    global $config;
    if ($host == 'default') {
        $host = $config['libraries'][$_GET['bib']]['z3950'];
    }
    $zconfig = get_zconfig();
    $hits = 0;
    $type = 'xml';
    $id = yaz_connect($host);
    yaz_element($id, "F");
    yaz_syntax($id, $syntax);
    yaz_range($id, 1, 1);
    yaz_ccl_conf($id, $zconfig);
    $cclresult = array();
    if (!yaz_ccl_parse($id, $ccl, $cclresult)) {
        echo 'Error: ' . $cclresult["errorstring"];
    } else {
        // NB! Ser ikke ut som Z39.50 fra Bibliofil støtter "sort"
        // Se nederst her: http://www.bibsyst.no/produkter/bibliofil/z3950.php
        // PHP/YAZ-funksjonen yaz-sort ville kunne dratt nytte av dette:
        // http://no.php.net/manual/en/function.yaz-sort.php
        // Sort Flags
        // a Sort ascending
        // d Sort descending
        // i Case insensitive sorting
        // s Case sensitive sorting
        // Bib1-attributter man kunne sortert på:
        // http://www.bibsyst.no/produkter/bibliofil/z/carl.xml
        // yaz_sort($id, "1=31 di");
        $rpn = $cclresult["rpn"];
        yaz_search($id, "rpn", utf8_decode($rpn));
    }
    yaz_wait();
    $error = yaz_error($id);
    if (!empty($error)) {
        echo "Error yazCclArray: {$error}";
    } else {
        $hits = yaz_hits($id);
    }
    $data = array();
    for ($p = 1; $p <= $hits; $p++) {
        $rec = yaz_record($id, $p, $type);
        if (empty($rec)) {
            continue;
        }
        $data[] = $rec;
        if ($p == $config['maks_poster']) {
            break;
        }
    }
    $ret = array("hits" => $hits, "result" => $data);
    return $ret;
}
Esempio n. 13
0
         $trunc_right = "@attr 6=1";
     } else {
         $trunc_right = "";
     }
     $fullquery = $fieldmap[$field] . $trunc_right . ' "' . $oterm . '"';
 }
 if ($fullquery != "" && $expr_isbn != "") {
     $fullquery = "@or " . $expr_isbn . " " . $fullquery;
 } else {
     if ($expr_isbn != "") {
         $fullquery = $expr_isbn;
     }
 }
 //    $options=array("proxy"=>"localhots");
 $options = array();
 for ($reintentar = 0; $reintentar <= $intentos; $reintentar++) {
     for ($i = 0; $i < $num_hosts; $i++) {
         $id = yaz_connect($host[$i], $options);
         $ids[$i] = $id;
         if ($id <= 0) {
             continue;
         }
         if (!yaz_search($id, "rpn", $fullquery)) {
             echo $msgstr["expr_err"] . '<br>';
             $reintentar = 999;
             break;
         }
         if ($number > 1) {
             yaz_element($id, $element);
         } else {
             yaz_element($id, "F");
Esempio n. 14
0
function yazCclArray($ccl)
{
    global $config;
    $system = $config['lib']['system'];
    // Create an array to hold settings for the different systems
    $zopts = array();
    $zopts['aleph'] = array('syntax' => '', 'yaz_con_opts' => array('piggyback' => true));
    $zopts['bibliofil'] = array('syntax' => 'normarc', 'yaz_con_opts' => array('piggyback' => true));
    $zopts['bibsys'] = array('syntax' => '', 'yaz_con_opts' => array('piggyback' => false));
    $zopts['koha'] = array('syntax' => '', 'yaz_con_opts' => array('piggyback' => true));
    $zopts['mikromarc'] = array('syntax' => 'normarc', 'yaz_con_opts' => array('piggyback' => true));
    /*
    The Glitre project has not been able to find sample servers fot these
    systems, even after asking the vendors if any exist:
    
    $zopts['reindex'] = array(
      'syntax' => '', 
      'yaz_con_opts' => array(
    	'piggyback' => false,
      ),
    );
    $zopts['tidemann'] = array(
      'syntax' => '', 
      'yaz_con_opts' => array(
    	'piggyback' => false,
      ),	
    );
    */
    $hits = 0;
    $type = 'xml';
    $id = yaz_connect($config['lib']['z3950'], $zopts[$system]['yaz_con_opts']);
    yaz_element($id, "F");
    yaz_syntax($id, $zopts[$system]['syntax']);
    yaz_range($id, 1, 1);
    yaz_ccl_conf($id, get_zconfig());
    $cclresult = array();
    if (!yaz_ccl_parse($id, $ccl, $cclresult)) {
        echo 'Error yaz_ccl_parse: ' . $cclresult["errorstring"];
    } else {
        // Norwegian Z39.50 have no or limited support for yaz_sort
        // See http://wiki.biblab.no/index.php/Z39.50%2C_SRU_og_sortering for details
        // yaz_sort($id, "1=31 di");
        $rpn = $cclresult["rpn"];
        yaz_search($id, "rpn", utf8_decode($rpn));
    }
    yaz_wait();
    $error = yaz_error($id);
    if (!empty($error)) {
        $yaz_errno = yaz_errno($id);
        // echo "<p>Error yaz_wait: $error ($yaz_errno)</p>";
        $error = array('error' => true, 'stage' => 'yaz_wait', 'desc' => $error, 'num' => $yaz_errno);
        return $error;
    } else {
        $hits = yaz_hits($id);
    }
    $data = array();
    for ($p = 1; $p <= $hits; $p++) {
        $rec = yaz_record($id, $p, $type);
        if (empty($rec)) {
            continue;
        }
        $data[] = $rec;
        // If a max number of records is set for this library, respect it - otherwise use the default.
        $records_max = $config['lib']['records_max'] ? $config['lib']['records_max'] : $config['records_max'];
        if ($p == $records_max) {
            break;
        }
    }
    $ret = array("hits" => $hits, "result" => $data);
    return $ret;
}
Esempio n. 15
0
 function getEnrichment($notice_id, $source_id, $type = "", $enrich_params = array())
 {
     global $charset;
     $enrichment = array();
     $this->noticeToEnrich = $notice_id;
     // récupération du code sudoc (PPN) de la notice stocké dans le champ perso de type "resolve" avec pour label "SUDOC"
     $mes_pp = new parametres_perso("notices");
     $mes_pp->get_values($notice_id);
     $values = $mes_pp->values;
     foreach ($values as $field_id => $vals) {
         if ($mes_pp->t_fields[$field_id]['TYPE'] == "resolve") {
             $field_options = _parser_text_no_function_("<?xml version='1.0' encoding='" . $charset . "'?>\n" . $mes_pp->t_fields[$field_id]['OPTIONS'], "OPTIONS");
             foreach ($field_options['RESOLVE'] as $resolve) {
                 if (strtoupper($resolve['LABEL']) == "SUDOC") {
                     $infos = explode('|', $vals[0]);
                     $ppn = $infos[0];
                 }
             }
         }
     }
     if ($ppn == "") {
         return $this->build_error();
     }
     $url = "carmin.sudoc.abes.fr";
     $port = "210";
     $base = "abes-z39-public";
     $format = "unimarc";
     $term = "@attr 1=12 @attr 2=3 \"{$ppn}\" ";
     $id = yaz_connect("{$url}:{$port}/{$base}", array("piggyback" => false));
     yaz_range($id, 1, 1);
     yaz_syntax($id, strtolower($format));
     yaz_search($id, "rpn", $term);
     $options = array("timeout" => 45);
     //Override le timeout du serveur mysql, pour être sûr que le socket dure assez longtemps pour aller jusqu'aux ajouts des résultats dans la base.
     $sql = "set wait_timeout = 120";
     mysql_query($sql);
     yaz_wait($options);
     $error = yaz_error($id);
     $error_info = yaz_addinfo($id);
     if (!empty($error)) {
         yaz_close($id);
         return $this->build_error();
     } else {
         $hits = yaz_hits($id);
         $hits += 0;
         if ($hits) {
             $rec = yaz_record($id, 1, "raw");
             $record = new iso2709_record($rec);
             if (!$record->valid()) {
                 yaz_close($id);
                 return $this->build_error();
             }
             $lines = "";
             $document->document_type = $record->inner_guide[dt];
             $document->bibliographic_level = $record->inner_guide[bl];
             $document->hierarchic_level = $record->inner_guide[hl];
             if ($document->hierarchic_level == "") {
                 if ($document->bibliographic_level == "s") {
                     $document->hierarchic_level = "1";
                 }
                 if ($document->bibliographic_level == "m") {
                     $document->hierarchic_level = "0";
                 }
             }
             $indicateur = array();
             $cle_list = array();
             for ($i = 0; $i < count($record->inner_directory); $i++) {
                 $cle = $record->inner_directory[$i]['label'];
                 $indicateur[$cle][] = substr($record->inner_data[$i]['content'], 0, 2);
                 $field_array = $record->get_subfield_array_array($cle);
                 $line = "";
                 if (!$cle_list[$cle]) {
                     foreach ($field_array as $field) {
                         $line .= $cle . "  ";
                         foreach ($field as $ss_field) {
                             $line .= "\$" . $ss_field["label"] . $ss_field["content"];
                         }
                         $line .= "<br>";
                     }
                 }
                 $cle_list[$cle] = 1;
                 $lines .= $line;
             }
             if ($lines == "") {
                 yaz_close($id);
                 return $this->build_error();
             }
         } else {
             yaz_close($id);
             return $this->build_error();
         }
     }
     yaz_close($id);
     $enrichment['sudoc']['content'] = $lines;
     $enrichment['source_label'] = $this->msg['sudoc_enrichment_source'];
     return $enrichment;
 }
Esempio n. 16
0
 /** 
  * Fetch details about a specific item from WorldCat data service 
  *
  * @param array $pa_settings Plugin settings values
  * @param string $ps_url The URL originally returned by the data service uniquely identifying the item
  * @param array $pa_options Options include:
  *		APIKey = WorldCat API key to use. [Default is the key configured in worldcat_api_key in app.conf]
  *		user = Worldcat Z39.50 login name. [Default is the username configured in worldcat_z39.50_user in app.conf]
  *		password = WorldCAt Z39.50 password. [Default is the password configured in worldcat_z39.50_password in app.conf]
  *
  * @return array An array of data from the data server defining the item.
  */
 public function getExtendedInformation($pa_settings, $ps_url, $pa_options = null)
 {
     $va_config = $this->_getConfiguration($pa_settings, $pa_options);
     $va_tmp = explode("/", $ps_url);
     $vn_worldcat_id = array_pop($va_tmp);
     $va_data = array();
     if ($va_config['user'] && $va_config['z39IsAvailable']) {
         $r_conn = yaz_connect(WLPlugInformationServiceWorldCat::$s_worldcat_z3950_host, array('user' => $va_config['user'], 'password' => $va_config['password']));
         yaz_syntax($r_conn, "usmarc");
         yaz_range($r_conn, $vn_start + 1, $vn_start + $vn_count);
         yaz_search($r_conn, "rpn", '@attr 1=12 @attr 4=2 "' . str_replace('"', '', $vn_worldcat_id) . '"');
         yaz_wait();
         $vs_data = yaz_record($r_conn, 1, "xml; charset=marc-8,utf-8");
     } else {
         $o_client = new Client(WLPlugInformationServiceWorldCat::$s_worldcat_detail_url);
         try {
             if (!$va_config['curlIsAvailable']) {
                 throw new Exception(_t('CURL is required for WorldCat web API usage but not available on this server'));
             }
             if (!$va_config['APIKey']) {
                 if (!$va_config['z39IsAvailable']) {
                     throw new Exception(_t('Neither Z39.50 client is installed nor is WorldCat web API key configured'));
                 } else {
                     throw new Exception(_t('WorldCat web API key is not configured'));
                 }
             }
             // Create a request
             $o_request = $o_client->get("{$vn_worldcat_id}?wskey=" . $va_config['APIKey']);
             // Send the request and get the response
             $o_response = $o_request->send();
             $vs_data = (string) $o_response->getBody();
         } catch (Exception $e) {
             return array('display' => _t('WorldCat data could not be loaded: %1', $e->getMessage()));
         }
     }
     try {
         if (!$vs_data) {
             throw new Exception("No data returned");
         }
         $xml = new DOMDocument();
         $xml->loadXML($vs_data);
     } catch (Exception $e) {
         return array('display' => _t('WorldCat data could not be parsed: %1', $e->getMessage()));
     }
     switch ($pa_settings['detailStyle']) {
         case 'labels':
         default:
             $vs_template = file_get_contents(__CA_LIB_DIR__ . "/core/Plugins/InformationService/WorldCat/MARC21slim2English.xml");
             break;
         case 'codes':
             $vs_template = file_get_contents(__CA_LIB_DIR__ . "/core/Plugins/InformationService/WorldCat/MARC21slim2HTML.xml");
             break;
         case 'template':
             $vs_template = $pa_settings['detailXSLTemplate'];
             break;
     }
     try {
         $xsl = new DOMDocument();
         $xsl->loadXML($vs_template);
     } catch (Exception $e) {
         return array('display' => _t('WorldCat detail display template could not be parsed: %1', $e->getMessage()));
     }
     try {
         $proc = new XSLTProcessor();
         $proc->importStyleSheet($xsl);
         $vs_output = $proc->transformToXML($xml);
         $va_data = array('display' => $vs_output);
     } catch (Exception $e) {
         return array('display' => _t('WorldCat detail display template could not be created: %1', $e->getMessage()));
     }
     return $va_data;
 }
Esempio n. 17
0
        if ($val1 == "" and $val2 == "") {
            affiche_jsscript($msg[z3950_echec_no_champ], "#FF3333", $bib_id);
        } else {
            affiche_jsscript($msg[z3950_echec_no_valid_attr], "#FF3333", $bib_id);
        }
    } else {
        //////////////////////////////////////////////////////////////////////////////////
        // the query is ok we prepare the Z 3950 process for this biblio and
        // save the $id to be able later to retrieve the records from the servers
        //////////////////////////////////////////////////////////////////////////////////
        //$stato[$bib_id] = 1;
        $auth = $auth_user . $auth_pass;
        if ($auth != "") {
            $id = yaz_connect("{$url}:{$port}/{$base}", array("user" => $auth_user, "password" => $auth_pass, "piggyback" => false)) or affiche_jsscript("Echec : impossible de se connecter au Serveur", "#FF3333", $bib_id);
        } else {
            $id = yaz_connect("{$url}:{$port}/{$base}", array("piggyback" => false)) or affiche_jsscript($msg[z3950_echec_cnx], "#FF3333", $bib_id);
        }
        $map[$bib_id] = $id;
        yaz_element($id, "F");
        $etrange_limite = $limite_notices;
        yaz_range($id, 1, $etrange_limite);
        yaz_syntax($id, strtolower($format));
        echo $term;
        yaz_search($id, "rpn", $term);
    }
}
///////////////////////////////////////////////////////////////////////////
// Fase 2: all the possible connections are ready now start the researches
//////////////////////////////////////////////////////////////////////////
//Correction mystérieuse : visiblement la fonction yaz_search impacte la variable global $limite... modifié en $limite_notices
affiche_jsscript($msg['z3950_zmsg_wait'], "#FFCC99", $mioframe);
 public function getSearchResults($query, $start, $step, &$hits, &$pid)
 {
     $stop = $start + $step;
     if ($this->grabQueryFromCache($query)) {
         //pull from cache
         $hits = mysql_num_rows($this->results);
         for ($i = $start; $i < $stop; $i++) {
             $results[] = $this->getCachedBook($i);
         }
     } else {
         //pull from LoC
         //  			$mayDemandCache = ( ( $HTTP_GET_VARS['type'] != $HTTP_GET_VARS['sort'] ) &&
         //  								( $HTTP_GET_VARS['type'] != 'Keyword' ) &&
         //                                 ( !isset( $HTTP_GET_VARS['sort'] ) ) );
         $mayDemandCache = isset($_GET['sort']) && (!($HTTP_GET_VARS['sort'] == $HTTP_GET_VARS['type'] && !isset($_GET['desc'])) || isset($_GET['desc']));
         $willCache = (ShelveIt::$cachePolicy == 'always' || ShelveIt::$cachePolicy == 'demand' && $mayDemandCache) && !(ShelveIt::$cachePolicy == 'never');
         // connect to LoC server
         $LoC = yaz_connect('z3950.loc.gov:7090/voyager');
         //set server options
         yaz_syntax($LoC, 'marc21');
         if ($willCache) {
             // we're going to grab all results
             yaz_range($LoC, 1, $this->maxHits);
         } else {
             yaz_range($LoC, $start, $step);
         }
         // perform search
         yaz_search($LoC, 'rpn', $query);
         // wait for search to finish
         yaz_wait();
         // check for an error
         $error = yaz_error($LoC);
         if (!empty($error)) {
             ShelveIt::$messages['errors'][] = $error . " {$query}";
             $hits = 0;
         } else {
             //get results
             $hits = yaz_hits($LoC);
             if ($willCache && $hits > ShelveIt::$query_cache['maxHits']) {
                 ShelveIt::$messages['warnings'][] = "Your search has too many results to be quickly sorted. It has been limited from {$hits} to " . ShelveIt::$query_cache['maxHits'] . ". You can make your search more specific so it has a small enough number of hits, or not sort to see all of the results.";
                 $hits = ShelveIt::$query_cache['maxHits'];
             }
             if ($hits > 0) {
                 if ($willCache) {
                     for ($i = 1; $i < $start; $i++) {
                         $rec = yaz_record($LoC, $i, 'xml');
                         $this->cacheBook($query, new Brief_Book($rec));
                     }
                 } else {
                     $i = $start;
                 }
                 for (; $i < $stop; $i++) {
                     $rec = yaz_record($LoC, $i, 'xml');
                     $book = new Brief_Book($rec);
                     $results[] = $book;
                     if ($willCache) {
                         $this->cacheBook($query, $book);
                     }
                 }
                 if ($willCache) {
                     // 						// quick note: I can fork using pcntl_fork
                     // 						$pid = pcntl_fork();
                     // 						if( $pid == -1 ) {
                     // 							die( 'CRITICAL ERROR: Forking failed. The server is likely in trouble. Please come back later.' );
                     // 						} else if(  $pid == 0 ) {
                     // pick up where we left off
                     for (; $i <= $hits; $i++) {
                         $rec = yaz_record($LoC, $i, 'xml');
                         $this->cacheBook($query, new Brief_Book($rec));
                     }
                     $this->collectGarbage();
                     // 							exit( 0 );
                     // 						}
                 }
             }
         }
     }
     return $results;
 }
 function fetchYazInfos($book)
 {
     global $booklibrary_configuration;
     if (!extension_loaded('yaz')) {
         echo "<script> alert('Sorry, \\'yaz.so\\' isn\\'t loaded....'); window.history.go(-1);</script>\n";
         exit;
     }
     $param_ws = mosBooklibraryWS::getWsParamById($book->informationFrom) - 1;
     $hosts = mosBooklibraryWS::getWSArray();
     $str_conect = trim($hosts[$param_ws][3]) . ":" . trim($hosts[$param_ws][4]) . "/" . trim($hosts[$param_ws][5]);
     //$str_conect ="z3950.bibsys.no:2100";// "140.147.249.38:7090/voyager";
     //$str_conect = "troy.lib.sfu.ca:210/innopac";
     //echo $str_conect;
     $id = yaz_connect($str_conect);
     yaz_syntax($id, $hosts[$param_ws][6]);
     $query = '@attr 1=7  ' . $book->isbn;
     yaz_search($id, 'rpn', $query);
     yaz_wait();
     $error = yaz_error($id);
     if (!empty($error)) {
         echo "<script> alert('ERROR:" . addslashes($error) . "'); window.history.go(-1);</script>\n";
         exit;
     }
     $rec = yaz_record($id, 1, "array");
     $error = yaz_error($id);
     if (yaz_hits($id) == 0) {
         echo "<script> alert('On this ISBN(" . addslashes($book->isbn) . ") of the not found records'); window.history.go(-1);</script>\n";
         yaz_close($id);
         exit;
     } elseif (!empty($error)) {
         echo "<script> alert('ERROR:" . addslashes($error) . "'); window.history.go(-1);</script>\n";
         yaz_close($id);
         exit;
     }
     yaz_close($id);
     $book->comment = "";
     $book->title = "";
     $book->authors = "";
     $book->manufacturer = "";
     $book->release_Date = "";
     $book->URL = "";
     foreach ($rec as $i => $value) {
         $s = explode(")(", $rec[$i][0]);
         if (isset($s[2])) {
             switch (substr($s[0], 3, strlen($s[0]))) {
                 case '245':
                     $book->comment .= $rec[$i][1];
                     if (substr($s[2], 2, strlen($s[2]) - 3) == 'a') {
                         $book->title .= $rec[$i][1];
                     }
                     break;
                 case '100':
                     $book->authors .= $rec[$i][1];
                     break;
                 case '260':
                     $book->manufacturer .= $rec[$i][1];
                     if (substr($s[2], 2, strlen($s[2]) - 3) == 'c') {
                         $book->release_Date .= $rec[$i][1];
                     }
                     break;
                 case '856':
                     $book->URL .= $rec[$i][1];
                     break;
             }
         }
     }
     return $book;
 }
Esempio n. 20
0
 function _getLookupResult($server, $isbn)
 {
     // Now support YAZ only.
     $query = '@attr 1=7 ' . $isbn;
     $conn = yaz_connect($server['host'], array('user' => $server['user'], 'password' => $server['pw']));
     if (!$conn) {
         return array('error' => 'could not connect lookup');
     }
     yaz_database($conn, $server['db']);
     yaz_syntax($conn, "usmarc");
     yaz_element($conn, "F");
     //echo "sending: $qry <br />";
     if (!yaz_search($conn, 'rpn', $query)) {
         return array('error' => 'bad query');
     }
     $param = array('timeout' => 5);
     yaz_wait($param);
     $error = yaz_error($conn);
     if (!empty($error)) {
         return array('error' => 'lookup response error (' . yaz_errno($conn) . ') : ' . yaz_addinfo($conn));
     }
     if (yaz_hits($conn) < 1) {
         return array('error' => 'no result');
     }
     // For bulk actions, auto select first record
     require_once "../lookup2/lookupYazFunc.php";
     $data = extract_marc_fields(yaz_record($conn, 1, 'array'), true, 1, 1, $server['charset']);
     if (empty($data['callNmbr1']) && empty($data['050a']) || empty($data['100a'])) {
         // Require callNmbr1, continue search
         return array('error' => 'no result');
     }
     return $data;
 }
Esempio n. 21
0
 * Aufruf aus Webbrowser:
 * hbz?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * hbz?ppn=PPN
 *   PPN ist die eine ID-Nummer des HBZ
 * hbz?isbn=ISBN&format=json
 * hbz?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im HBZ-Katalog
 * und gibt maximal 10 Ergebnisse als MABXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(HBZ_URL);
yaz_syntax($id, HBZ_SYNTAX);
yaz_range($id, 1, 10);
yaz_element($id, HBZ_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=12 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';
        yaz_search($id, "rpn", $suchString);
Esempio n. 22
0
 * Aufruf aus Webbrowser:
 * gbv?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * gbv?ppn=PPN
 *   PPN ist die eine ID-Nummer des GBV
 * gbv?isbn=ISBN&format=json
 * gbv?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im GBV-Katalog
 * und gibt maximal 10 Ergebnisse als MARCXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(GBV_URL);
yaz_syntax($id, GBV_SYNTAX);
yaz_range($id, 1, 10);
yaz_element($id, GBV_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=12 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';
        yaz_search($id, "rpn", $suchString);
Esempio n. 23
0
 static function connect($host)
 {
     self::$connection = yaz_connect($host, array('charset' => 'UTF-8'));
     yaz_syntax(self::$connection, 'marc21');
 }
Esempio n. 24
0
 * Aufruf aus Webbrowser:
 * nebis?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * nebis?ppn=PPN
 *   PPN ist die eine ID-Nummer des NEBIS
 * nebis?isbn=ISBN&format=json
 * nebis?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im NEBIS-Katalog
 * und gibt maximal 10 Ergebnisse als MARCXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(NEBIS_URL);
yaz_syntax($id, NEBIS_SYNTAX);
yaz_range($id, 1, 10);
yaz_element($id, NEBIS_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=12 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';
        yaz_search($id, "rpn", $suchString);
Esempio n. 25
0
 function search($source_id, $query, $search_id)
 {
     global $base_path, $charset, $include_path;
     //global $url,$z3950_base,$z3950_login,$z3950_password,$z3950_max_notices,$z3950_format,$z3950_port,$z3950_convert,$z3950_profil;
     $this->error = false;
     $this->error_message = "";
     $params = $this->get_source_params($source_id);
     $this->fetch_global_properties();
     if ($params["PARAMETERS"]) {
         //Affichage du formulaire avec $params["PARAMETERS"]
         $vars = unserialize($params["PARAMETERS"]);
         foreach ($vars as $key => $val) {
             global ${$key};
             ${$key} = $val;
         }
     }
     if (!($z3950_max_notices * 1)) {
         $z3950_max_notices = 100;
     }
     //Tranformation de la recherche en requete rpn bib1
     $rpn = $this->parse_query($query);
     $zurl = $url . ($z3950_port ? ":" . $z3950_port : "") . ($z3950_base ? "/" . $z3950_base : "");
     $opts = array();
     if ($z3950_login) {
         $opts["user"] = $z3950_login;
     }
     if ($z3950_password) {
         $opts["password"] = $z3950_password;
     }
     $opts["piggyback"] = false;
     $yaz_id = yaz_connect($zurl, $opts);
     yaz_element($yaz_id, "F");
     yaz_range($yaz_id, 1, $z3950_max_notices);
     yaz_syntax($yaz_id, strtolower($z3950_format));
     yaz_search($yaz_id, "rpn", $rpn . " ");
     $opts_wait = array("timeout" => $params["TIMEOUT"]);
     yaz_wait($opts_wait);
     if (yaz_error($yaz_id)) {
         $this->error = true;
         $this->error_message = yaz_error($yaz_id);
     } else {
         $n_results = yaz_hits($yaz_id);
         if ($n_results > $z3950_max_notices) {
             $n_results = $z3950_max_notices;
         }
         $convert_order = $this->get_convert_order($z3950_convert);
         for ($k = 1; $k <= $n_results; $k++) {
             $notice = yaz_record($yaz_id, $k, "raw");
             //Conversion de la notice
             if ($z3950_convert) {
                 $export = new convert($notice, $convert_order);
                 if (!$export->error) {
                     $cnotice = $export->output_notice;
                 } else {
                     $cnotice = "";
                 }
             } else {
                 $cnotice = $notice;
             }
             if ($cnotice) {
                 //Conversion de la notice en XML
                 $xmlunimarc = new xml_unimarc();
                 $nxml = $xmlunimarc->iso2709toXML_notice($cnotice);
                 if ($xmlunimarc->is_utf8) {
                     $rcharset = "utf-8";
                 } else {
                     $rcharset = $charset;
                 }
                 $xmlunimarc->notices_xml_[0] = '<?xml version="1.0" encoding="' . $rcharset . '"?>' . $xmlunimarc->notices_xml_[0];
                 if ($xslt_exemplaire) {
                     $xmlunimarc->notices_xml_[0] = $this->apply_xsl_to_xml($xmlunimarc->notices_xml_[0], $xslt_exemplaire["content"]);
                 }
                 //					print_r($xmlunimarc->notices_xml_[0]);
                 if ($nxml >= 1) {
                     $params = _parser_text_no_function_($xmlunimarc->notices_xml_[0], "NOTICE");
                     $this->rec_record($params, $source_id, $search_id);
                 }
             }
         }
     }
 }
function smarty_function_find_isbn($params, &$smarty)
{
    function filter_array($theHaystack, $info)
    {
        if (is_array($theHaystack)) {
            for ($k = 0; $k <= count($theHaystack); $k++) {
                if (substr_count($theHaystack[$k][0], '245') > 0 && substr_count($theHaystack[$k][0], 'a') > 0) {
                    if ($info == 'title') {
                        return $theHaystack[$k][1] . " " . substr($theHaystack[$k + 1][1], 0, strlen($theHaystack[$k + 1][1]) - 1);
                    } elseif ($info == 'author') {
                        return $theHaystack[$k + 2][1];
                    }
                }
            }
        } else {
            //$array=$explode(" / ", $theHaystack);
            $parts = explode("/", $theHaystack);
            if ($info == 'title') {
                return $parts[0];
            } elseif ($info == 'author') {
                return substr($parts[1], 0, strpos($parts[1], '-'));
            }
        }
        return "";
    }
    $isbninfo = array();
    if (empty($params['var'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    if (empty($params['info'])) {
        $smarty->trigger_error("assign: missing 'info' parameter");
        return;
    } else {
        $info = $params['info'];
    }
    if (empty($params['isbn'])) {
        $smarty->trigger_error("assign: missing 'isbn' parameter");
        return;
    } else {
        $isbn = $params['isbn'];
    }
    $name = array("HeBIS", "Deutsche Nationalbibliothek", "GILS", "Libraray of Congress");
    $host = array("tolk.hebis.de:20212/hebis", "z3950.dbf.ddb.de:210/iltis", "bagel.indexdata.dk/gils", "z3950.loc.gov:7090/voyager");
    $user = array("3950", "gast", "", "");
    $passwd = array("Z3950", "gast", "", "");
    $syntax = array("usmarc", "sutrs", "usmarc", "usmarc");
    $query = "@attr 1=7 " . $isbn;
    $found = false;
    $i = 0;
    $j = 0;
    while ($found == false && $i <= 3) {
        $id[$i] = yaz_connect($host[$i], array("user" => $user[$i], "password" => $passwd[$i]));
        yaz_syntax($id[$i], $syntax[$i]);
        yaz_range($id[$i], 1, 1);
        yaz_search($id[$i], "rpn", $query);
        yaz_wait();
        $error = yaz_error($id[$i]);
        $hits = yaz_hits($id[$i]);
        if (!empty($error) | $hits == 0) {
            $i++;
            if (!empty($error)) {
                $j++;
            }
        } else {
            $found = true;
            if ($i == 1) {
                $rec = yaz_record($id[$i], 1, "string");
            } else {
                $rec = yaz_record($id[$i], 1, "array");
            }
            //var_dump($rec);
            //echo "<table>";
            //echo "<tr><td valign='top'><b>Titel: </b></td><td>".filter_array($rec, 'title')."</td></tr>";
            //echo "<tr><td valign='top'><b>Autor: </b></td><td> ".filter_array($rec, 'author')."</td></tr>";
            //echo "</table>";
            $isbninfo['title'] = filter_array($rec, 'title');
            $isbninfo['author'] = filter_array($rec, 'author');
        }
    }
    if (empty($isbninfo['title']) | $found == false) {
        $isbninfo['title'] = "Es wurden keine Einträge gefunden.";
        $isbninfo['author'] = "Es wurden keine Einträge gefunden.";
        if ($j == 4) {
            $isbninfo['title'] = "Es konnte keine Verbindung hergestellt werden.";
            $isbninfo['author'] = "Es konnte keine Verbindung hergestellt werden.";
        }
    }
    //var_dump($isbninfo);
    $smarty->assign($params['var'], $isbninfo);
}
Esempio n. 27
0
<?php

$dir = dirname(__FILE__);
require 'File/MARC.php';
// Define the usable fields for our CCL query
$ccl_fields = array("ti" => "1=4", "au" => "1=1", "isbn" => "1=7");
// Declare the array that will hold the parsed results
$ccl_results = array();
// Connect to the laurentian.ca Z39.50 server
$conn = yaz_connect('142.51.8.7:2200/UNICORN');
yaz_ccl_conf($conn, $ccl_fields);
// Define our query for a most excellent text
$ccl_query = "ti='derby' and au='scott'";
// Parse the CCL query into yaz's native format
$result = yaz_ccl_parse($conn, $ccl_query, $ccl_results);
if (!$result) {
    echo "Error: " . $ccl_results['errorstring'];
    exit;
}
// Submit the query
$rpn = $ccl_results['rpn'];
yaz_search($conn, 'rpn', $rpn);
yaz_wait();
// Any errors trying to retrieve this record?
$error = yaz_error($conn);
if ($error) {
    print "Error: {$error}\n";
    exit;
}
// Retrieve the first MARC record as raw MARC
$rec = yaz_record($conn, 1, "raw");
Esempio n. 28
0
File: bl.php Progetto: stweil/malibu
 * Aufruf aus Webbrowser:
 * bl?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * bl?ppn=PPN
 *   PPN ist die eine ID-Nummer des BL
 * bl?isbn=ISBN&format=json
 * bl?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im BL-Katalog
 * und gibt maximal 10 Ergebnisse als MARCXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(BL_URL, array("user" => BL_USER, "password" => BL_PASSWORD));
yaz_syntax($id, BL_SYNTAX);
//utf-8 Kodierung
yaz_range($id, 1, 10);
yaz_element($id, BL_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=12 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';
 function _getLookupResult($server, $isbn)
 {
     // Now support YAZ only
     $query = '@attr 1=7 ' . $isbn;
     $conn = yaz_connect($server['host'], array('user' => $server['user'], 'password' => $server['pw']));
     if (!$conn) {
         return false;
     }
     yaz_database($conn, $server['db']);
     yaz_syntax($conn, "usmarc");
     yaz_element($conn, "F");
     if (!yaz_search($conn, 'rpn', $query)) {
         return false;
     }
     yaz_wait();
     $error = yaz_error($conn);
     if (!empty($error)) {
         return false;
     }
     if (yaz_hits($conn) < 1) {
         return false;
     }
     // For bulk actions, auto select first record
     require_once "../lookup2/lookupYazFunc.php";
     $data = extract_marc_fields(yaz_record($conn, 1, 'array'), true, 1, 1);
     return $data['856u'];
 }
Esempio n. 30
0
 * Aufruf aus Webbrowser:
 * obvsg.php?isbn=ISBN
 *   ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen
 *   ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein
 * obvsg.php?ppn=PPN
 *   PPN ist die eine ID-Nummer des B3KAT
 * obvsg.php?isbn=ISBN&format=json
 * obvsg.php?ppn=PPN&format=json
 *   Ausgabe erfolgt als JSON
 *
 * Sucht übergebene ISBN bzw. PPN im OBVSG-Katalog
 * und gibt maximal 10 Ergebnisse als MABXML zurück
 * bzw. als JSON.
 */
include 'lib.php';
$id = yaz_connect(OBVSG_URL, array("user" => OBVSG_USER, "password" => OBVSG_PASSWORD));
//"mab2; charset=iso5426,utf8"
yaz_syntax($id, OBVSG_SYNTAX);
yaz_range($id, 1, 10);
yaz_element($id, OBVSG_ELEMENTSET);
if (isset($_GET['ppn'])) {
    $ppn = trim($_GET['ppn']);
    yaz_search($id, "rpn", '@attr 5=100 @attr 1=1016 "' . $ppn . '"');
}
if (isset($_GET['isbn'])) {
    $n = trim($_GET['isbn']);
    $nArray = explode(",", $n);
    if (count($nArray) > 1) {
        //mehrere ISBNs, z.B. f @or @or @attr 1=7 "9783937219363" @attr 1=7 "9780521369107" @attr 1=7 "9780521518147"
        //Anfuehrungsstriche muessen demaskiert werden, egal ob String mit ' gemacht wird
        $suchString = str_repeat("@or ", count($nArray) - 1) . '@attr 1=7 \\"' . implode('\\" @attr 1=7 \\"', $nArray) . '\\"';