'.__('You are not authorized to view this section').''); } if (!extension_loaded('yaz')) { die('
YAZ extension library is not loaded/installed yet. ' .'YAZ library is needed to use z3950 enabled service. ' .'Please refer to official YAZ PHP Manual' .' on how to setup/install YAZ extension library in PHP.
'); } if (isset($_GET['z3950_source'])) { $zserver[] = trim(urldecode($_GET['z3950_source'])); } else { $zserver[] = 'z3950.loc.gov:7090/voyager'; } /* RECORD OPERATION */ if (isset($_POST['saveZ']) AND isset($_SESSION['z3950result'])) { require MDLBS.'bibliography/biblio_utils.inc.php'; $gmd_cache = array(); $publ_cache = array(); $place_cache = array(); $lang_cache = array(); $author_cache = array(); $subject_cache = array(); $input_date = date('Y-m-d H:i:s'); // create dbop object $sql_op = new simbio_dbop($dbs); $r = 0; foreach ($_POST['zrecord'] as $rec_idx) { // get the record from session $biblio = $_SESSION['z3950result'][$rec_idx]; // escape all string value foreach ($biblio as $field => $content) { if (is_string($content)) { $biblio[$field] = $dbs->escape_string($content); } } // gmd $biblio['gmd_id'] = utility::getID($dbs, 'mst_gmd', 'gmd_id', 'gmd_name', $biblio['gmd'], $gmd_cache); unset($biblio['gmd']); // publisher $biblio['publisher_id'] = utility::getID($dbs, 'mst_publisher', 'publisher_id', 'publisher_name', $biblio['publisher'], $publ_cache); unset($biblio['publisher']); // publish place $biblio['publish_place_id'] = utility::getID($dbs, 'mst_place', 'place_id', 'place_name', $biblio['publish_place'], $place_cache); unset($biblio['publish_place']); // language $biblio['language_id'] = utility::getID($dbs, 'mst_language', 'language_id', 'language_name', $biblio['language'], $lang_cache); unset($biblio['language']); // author primary $author_main = $biblio['author_main']; unset($biblio['author_main']); // authors additional $authors_add = $biblio['authors_add']; unset($biblio['authors_add']); // authors corporate body $authors_corp = $biblio['authors_corp']; unset($biblio['authors_corp']); // authors conference $authors_conf = $biblio['authors_conf']; unset($biblio['authors_conf']); // subject $subjects = $biblio['subjects']; unset($biblio['subjects']); // unset copies unset($biblio['copies']); $biblio['input_date'] = $input_date; $biblio['last_update'] = $input_date; // title $biblio['title'] = trim(substr_replace($biblio['title'], '', strpos($biblio['title'], '/'))); // fot debugging purpose // var_dump($biblio); // die(); // insert biblio data $sql_op->insert('biblio', $biblio); $biblio_id = $sql_op->insert_id; if ($biblio_id < 1) { continue; } // insert author if ($author_main) { // author $author_id = utility::getID($dbs, 'mst_author', 'author_id', 'author_name', $author_main, $author_cache); @$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)"); } // insert additional personal name authors if ($authors_add) { $author_id = 0; $author_type = 'p'; foreach ($authors_add as $add_author) { $author_id = getAuthorID($add_author, $author_type, $author_cache); @$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)"); } } // insert corporate body authors if ($authors_corp) { $author_id = 0; $author_type = 'o'; foreach ($authors_corp as $author_corp) { $author_id = getAuthorID($author_corp, $author_type, $author_cache); @$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)"); } } // insert conference/meeting authors if ($authors_conf) { $author_id = 0; $author_type = 'c'; foreach ($authors_conf as $author_conf) { $author_id = getAuthorID($author_conf, $author_type, $author_cache); @$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)"); } } // insert subject/topical terms if ($subjects) { foreach ($subjects as $subject) { $subject_type = 't'; $subject_id = getSubjectID($subject, $subject_type, $subject_cache); @$dbs->query("INSERT IGNORE INTO biblio_topic (biblio_id, topic_id, level) VALUES ($biblio_id, $subject_id, 1)"); } } if ($biblio_id) { $r++; } } // destroy result Z3950 session unset($_SESSION['z3950result']); utility::jsAlert($r.' records inserted to database.'); echo ''; exit(); } /* RECORD OPERATION END */ /* SEARCH OPERATION */ if (isset($_GET['keywords']) AND $can_read) { require LIB.'marcxmlsenayan.inc.php'; $_SESSION['z3950result'] = array(); $keywords = trim($_GET['keywords']); $num_hosts = count($zserver); $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 ''."\n"; echo ''."\n"; for ($h = 0; $h < $num_hosts; $h++) { $error = yaz_error($id[$h]); if (!empty($error)) { $errors[] = $error; } else { // number of results $hits = yaz_hits($id[$h]); } for ($rnum = 1; $rnum <= $sysconf['z3950_max_result']; $rnum++) { $rec = yaz_record($id[$h], $rnum, 'xml; charset=marc-8,utf-8'); if (empty($rec)) continue; echo $rec; } } echo ''; $xml_result_string = ob_get_clean(); // below is for debugging purpose // echo htmlentities($xml_result_string); if ($hits > 0) { echo '
Found '.$hits.' records from Z3950 Server, '.$sysconf['z3950_max_result'].' listed.
'; // parse XML $xmlrec = marcXMLsenayan($xml_result_string); // save it to session vars for retrieving later $_SESSION['z3950result'] = $xmlrec; // create list and form echo '
'; echo ''; echo ''; echo ''; echo ''; // loop records $row = 1; foreach ($xmlrec as $rec_idx => $rec) { $row_class = ($row%2 == 0)?'alterCell':'alterCell2'; echo ''; echo ''; echo ''; echo ''; echo ''; $row++; } echo '
'.$rec['title'].'
'.$rec['author_main'].'
'.$rec['isbn_issn'].'
'; echo '
'; } else if ($errors) { echo '
'; } else { echo '
No Results Found!
'; } } else { echo '
No Keywords Supplied!
'; } exit(); } /* SEARCH OPERATION END */ /* search form */ ?>