Documentation here.'; // Function that will handle the wizard-like behaviour function dispatch() { if (empty ($_GET['step'])) $step = 0; else $step = (int) $_GET['step']; // load the header $this->header(); switch ($step) { case 0 : $this->greet(); break; case 1 : $this->iii_start(); break; case 2: $this->iii_getrecords(); break; case 3: $this->ktnxbye(); break; } // load the footer $this->footer(); } function header() { echo '
'.__('Howdy! Start here to import records from a Innovative Interfaces (III) ILS system into Scriblio.').'
'; echo ''.__('This has not been tested much. Mileage may vary.').'
'; echo ''; if(!function_exists('mb_convert_encoding')){ echo ''.__('This PHP install does not support multibyte string functions, including mb_convert_encoding. Without that function, this importer can't convert the character encoding from records in the ILS into UTF-8. Accented characters will likely not import correctly.').'
'; } echo ''.__('All done.').'
'; echo ''.__('All Scriblio records have a 'sourceid,' a unique alphanumeric string that's used to avoid creating duplicate records and, in some installations, link back to the source system for current availability information.').'
'; echo ''.__('The sourceid is made up of two parts: the prefix that you assign, and the bib number from the Innopac. Theoretically, you chould gather records from 1,296 different systems, it's a big world.').'
'; echo ''; echo ''.__('Sorry, there has been an error.').'
'; echo 'Please complete all fields
'; return; } // save these settings so we can try them again later $prefs = get_option('scrib_iiiimporter'); $prefs['scrib_iii-sourceprefix'] = strtolower(ereg_replace('[^a-z|A-Z|0-9]', '', $_POST['scrib_iii-sourceprefix'])); stripslashes($_POST['scrib_iii-sourceprefix']); $prefs['scrib_iii-sourceinnopac'] = ereg_replace('[^a-z|A-Z|0-9|-|\.]', '', $_POST['scrib_iii-sourceinnopac']); $prefs['scrib_iii-record_start'] = (int) $_POST['scrib_iii-record_start']; $prefs['scrib_iii-record_end'] = (int) $_POST['scrib_iii-record_end']; update_option('scrib_iiiimporter', $prefs); $interval = 50; if(!$prefs['scrib_iii-record_end'] || ($prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start'] < $interval)) $interval = $prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start']; if($prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start'] < 1) $interval = 1; ini_set('memory_limit', '1024M'); set_time_limit(0); ignore_user_abort(TRUE); error_reporting(E_ERROR); if(!empty($_POST['scrib_iii-debug'])){ $host = $prefs['scrib_iii-sourceinnopac']; $bibn = (int) $prefs['scrib_iii-record_start']; echo ''; echo $this->iii_get_record($host, $bibn); echo '
'; $test_pancake = $this->iii_parse_record($this->iii_get_record($host, $bibn), $bibn); print_r($test_pancake); echo ''; echo '
Reading $interval records from {$prefs['scrib_iii-sourceinnopac']}. Please be patient.
([^<]*)/', $record, $stuff);
return($stuff[1]);
}
$this->error = 'Host unreachable or no parsable data found for record number '. $bibn .'.';
return(FALSE);
}
function iii_done(){
$prefs = get_option('scrib_iiiimporter');
// click next
echo '';
if(count($prefs['scrib_iii-warnings'])){
echo 'Warnings
';
echo 'bottom · errors';
echo '- ';
echo implode($prefs['scrib_iii-warnings'], '
- ');
echo '
';
}
if(count($prefs['scrib_iii-errors'])){
echo 'Errors
';
echo 'bottom · warnings';
echo '- ';
echo implode($prefs['scrib_iii-errors'], '
- ');
echo '
';
}
echo ''.__('Processing complete.').'
';
echo ''. $prefs['scrib_iii-records_harvested'] .' '.__('records harvested.').' with '. count($prefs['scrib_iii-warnings']) .' warnings and '. count($prefs['scrib_iii-errors']) .' errors.
';
echo ''.__('Continue to the next step to publish those harvested catalog entries.').'
';
echo '';
echo '';
}
function iii_parse_row($lineray){
$marcrow = array();
unset($lineray[0]);
foreach($lineray as $element){
$count[$element{0}]++;
$elementname = $element{0}.$count[$element{0}];
$marcrow[$elementname] = trim(str_replace(' ', ' ', substr($element, 1)));
}
return($marcrow);
}
function iii_parse_record($marcrecord, $bibn){
global $scrib_import;
$atomic = array();
$marcrecord = str_replace("\n ", ' ', $marcrecord);
$details = explode("\n", $marcrecord);
array_pop($details);
array_shift($details);
$details[0] = str_replace('LEADER ', '000 ', $details[0]);
foreach($details as $line){
unset($lineray);
unset($marc);
$line = trim($line);
$lineray = substr($line, 0, 3) . '|' . substr($line, 4, 2) . '|a' . substr($line, 7);
$lineray = explode('|', ereg_replace('\.$', '', $lineray));
unset($lineray[1]);
// Authors
if(($lineray[0] == 100) || ($lineray[0] == 110)){
$marc = $this->iii_parse_row($lineray);
$temp = ereg_replace(',$', '', $marc['a1'] .' '. $marc['d1']);
$atomic['author'][] = $temp;
}else if($lineray[0] == 110){
$marc = $this->iii_parse_row($lineray);
$temp = $marc['a1'];
$atomic['author'][] = $temp;
}else if(($lineray[0] > 699) && ($lineray[0] < 721)){
$marc = $this->iii_parse_row($lineray);
$temp = ereg_replace(',$', '', $marc['a1'] .' '. $marc['d1']);
$atomic['author'][] = $temp;
//Standard Numbers
}else if($lineray[0] == 10){
$marc = $this->iii_parse_row($lineray);
$atomic['lccn'][] = ereg_replace('[^0-9]', '', $marc['a1']);
}else if($lineray[0] == 20){
$marc = $this->iii_parse_row($lineray);
$temp = trim($marc['a1']) . ' ';
$temp = ereg_replace('[^0-9|x|X]', '', strtolower(substr($temp, 0, strpos($temp, ' '))));
$atomic['isbn'][] = $temp;
}else if($lineray[0] == 22){
$marc = $this->iii_parse_row($lineray);
$temp = trim($marc['a1']) . ' ';
$temp = ereg_replace('[^0-9|x|X|\-]', '', strtolower(substr($temp, 0, strpos($temp, ' '))));
$atomic['issn'][] = $temp;
//Titles
}else if($lineray[0] == 245){
$marc = $this->iii_parse_row($lineray);
$temp = ucwords(trim(ereg_replace('/$', '', $marc['a1']) .' '. trim(ereg_replace('/$', '', $marc['b1']))));
$atomic['title'][] = $temp;
$atomic['attribution'][] = $marc['c1'];
}else if($lineray[0] == 240){
$marc = $this->iii_parse_row($lineray);
$temp = trim(ereg_replace('/$', '', $marc['a1'] .' '. $marc['b1']));
$atomic['alttitle'][] = $temp;
}else if($lineray[0] == 246){
$marc = $this->iii_parse_row($lineray);
$temp = trim(ereg_replace('/$', '', $marc['a1'] .' '. $marc['b1']));
$atomic['alttitle'][] = $temp;
}else if(($lineray[0] > 719) && ($lineray[0] < 741)){
$marc = $this->iii_parse_row($lineray);
$temp = $marc['a1'];
$atomic['alttitle'][] = $marc['a1'];
//Dates
}else if($lineray[0] == 260){
$marc = $this->iii_parse_row($lineray);
if($marc['c1']){
$temp = str_pad(substr(ereg_replace('[^0-9]', '', $marc['c1']), 0, 4), 4 , '5');
$atomic['pubyear'][] = $temp;
}
}else if($lineray[0] == 5){
$atomic['acqdate'][] = $line{7}.$line{8}.$line{9}.$line{10} .'-'. $line{11}.$line{12} .'-'. $line{13}.$line{14};
}else if($lineray[0] == 8){
$temp = intval(substr($line, 14, 4));
if($temp)
$atomic['pubyear'][] = substr($line, 14, 4);
//Subjects
}else if(($lineray[0] > 599) && ($lineray[0] < 700)){
$marc = $this->iii_parse_row($lineray);
$atomic['subject'][] = implode(' -- ', $marc);
if($atomic['subjkey']){
$atomic['subjkey'] = array_unique(array_merge($atomic['subjkey'], array_values($marc)));
}else{
$atomic['subjkey'] = array_values($marc);
}
//URLs
}else if($lineray[0] == 856){
$marc = $this->iii_parse_row($lineray);
unset($temp);
$temp['href'] = $temp['title'] = str_replace(' ', '', $marc['u1']);
$temp['title'] = trim(parse_url( $temp['href'] , PHP_URL_HOST), 'www.');
if($marc['31'])
$temp['title'] = $marc['31'];
if($marc['z1'])
$temp['title'] = $marc['z1'];
$atomic['url'][] = ''. $temp['title'] .'';
//Notes
}else if(($lineray[0] > 299) && ($lineray[0] < 400)){
$marc = $this->iii_parse_row($lineray);
$atomic['physdesc'][] = implode(' ', array_values($marc));
}else if(($lineray[0] > 399) && ($lineray[0] < 500)){
$marc = $this->iii_parse_row($lineray);
$atomic['title'][] = implode("\n", array_values($marc));
}else if(($lineray[0] > 799) && ($lineray[0] < 841)){
$marc = $this->iii_parse_row($lineray);
$atomic['series'][] = implode("\n", array_values($marc));
}else if(($lineray[0] > 499) && ($lineray[0] < 600)){
$line = substr($line, 7);
if($lineray[0] == 504)
continue;
if($lineray[0] == 505){
$atomic['contents'][] = str_replace(array('> ','> ','> '), '>', '