Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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);
        }
    }
}