'.__('You are not authorized to view this section').'');
}
// check if PEAR is installed
ob_start();
include 'System.php';
include 'File/MARC.php';
ob_end_clean();
if (!(class_exists('System') && class_exists('File_MARC'))) {
die('
');
}
// max chars in line for file operations
$max_chars = 1024*100;
if ($sysconf['index']['type'] == 'index') {
require MDLBS.'system/biblio_indexer.inc.php';
// create biblio_indexer class instance
$indexer = new biblio_indexer($dbs);
}
if (isset($_POST['doImport'])) {
// check for form validity
if (!$_FILES['importFile']['name']) {
utility::jsAlert(__('Please select the file to import!'));
exit();
} else {
require MDLBS.'bibliography/biblio_utils.inc.php';
require SIMBIO.'simbio_DB/simbio_dbop.inc.php';
$start_time = time();
// set PHP time limit
set_time_limit(0);
// set ob implicit flush
ob_implicit_flush();
// create upload object
$upload = new simbio_file_upload();
// get system temporary directory location
$temp_dir = sys_get_temp_dir();
$uploaded_file = $temp_dir.DS.$_FILES['importFile']['name'];
// set max size
$max_size = $sysconf['max_upload']*1024;
$upload->setAllowableFormat(array('.mrc', '.xml', '.txt'));
$upload->setMaxSize($max_size);
$upload->setUploadDir($temp_dir);
$upload_status = $upload->doUpload('importFile');
if ($upload_status != UPLOAD_SUCCESS) {
utility::jsAlert(__('Upload failed! File type not allowed or the size is more than').($sysconf['max_upload']/1024).' MB');
exit();
}
$updated_row = 0;
$marc_string = file_get_contents($uploaded_file);
$marc_data = new File_MARC($marc_string, File_MARC::SOURCE_STRING);
// create dbop object
$sql_op = new simbio_dbop($dbs);
$gmd_cache = array();
$publ_cache = array();
$place_cache = array();
$lang_cache = array();
$sor_cache = array();
$author_cache = array();
$subject_cache = array();
$updated_row = '';
while ($record = $marc_data->next()) {
$data = array();
$input_date = date('Y-m-d H:i:s');
$data['input_date'] = $input_date;
$data['last_update'] = $input_date;
$title_fld = $record->getField('245');
// Main title
$title_main = $title_fld->getSubfields('a');
// echo $title_main[0]->getData();
$data['title'] = $dbs->escape_string(trim($title_main[0]->getData()));
// Sub title
$subtitle = $title_fld->getSubfields('b');
if (isset($subtitle[0])) {
// echo 'Subtitle: '.$subtitle[0]->getData();
$data['title'] .= $dbs->escape_string(trim($subtitle[0]->getData()));
}
// Statement of Responsibility
$sor = $title_fld->getSubfields('c');
if (isset($sor[0])) {
// $data['title'] .= $sor[0]->getData();
$data['sor'] = $dbs->escape_string(trim($sor[0]->getData()));
// echo "\n"; echo 'Statement of responsibility: '.$sor[0]->getData();
// $data['sor_id'] = utility::getID($dbs, 'mst_sor', 'sor_id', 'sor', $sor[0]->getData(), $sor_cache);
}
// Edition
$ed_fld = $record->getField('250');
if ($ed_fld) {
$ed = $ed_fld->getSubfields('a');
$ed2 = $ed_fld->getSubfields('b');
if (isset($ed[0])) {
// echo "\n"; echo 'Edition: '.$ed[0]->getData();
$data['edition'] = $dbs->escape_string(trim($ed[0]->getData()));
}
if (isset($ed2[0])) {
// echo "\n"; echo 'Edition: '.$ed[0]->getData();
$data['edition'] .= $dbs->escape_string(trim($ed2[0]->getData()));
}
}
// GMD
$gmd = $title_fld->getSubFields('h');
if (isset($gmd[0])) {
// echo "\n"; echo 'GMD: '.$gmd[0]->getData();
$data['gmd_id'] = utility::getID($dbs, 'mst_gmd', 'gmd_id', 'gmd_name', $gmd[0]->getData(), $gmd_cache);
}
// Identifier - ISBN
$id_fld = $record->getField('020');
if ($id_fld) {
$isbn_issn = $id_fld->getSubfields('a');
if (isset($isbn_issn[0])) {
// echo "\n"; echo 'ISBN/ISSN: '.$isbn_issn[0]->getData();
$data['isbn_issn'] = $isbn_issn[0]->getData();
}
}
// Identifier - ISSN
$id_fld = $record->getField('022');
if ($id_fld) {
echo "\n";
$isbn_issn = $id_fld->getSubfields('a');
if (isset($isbn_issn[0])) {
// echo 'ISBN/ISSN: '.$isbn_issn[0]->getData();
$data['isbn_issn'] = $isbn_issn[0]->getData();
}
}
// Classification DDC
$cls_fld = $record->getField('082');
if ($cls_fld) {
echo "\n";
$classification = $cls_fld->getSubfields('a');
if (isset($classification[0])) {
// echo 'Classification: '.$classification[0]->getData();
$data['classification'] = $classification[0]->getData();
}
}
// Publication
$pbl_fld = $record->getField('260');
if ($pbl_fld) {
$place = $pbl_fld->getSubfields('a');
$publisher = $pbl_fld->getSubfields('b');
$publish_year = $pbl_fld->getSubfields('c');
if (isset($place[0])) {
// echo "\n"; echo 'Publish place: '.$place[0]->getData();
$data['publish_place_id'] = utility::getID($dbs, 'mst_place', 'place_id', 'place_name', $place[0]->getData(), $place_cache);
}
if (isset($publisher[0])) {
// echo 'Publisher: '.$publisher[0]->getData();
$data['publisher_id'] = utility::getID($dbs, 'mst_publisher', 'publisher_id', 'publisher_name', $publisher[0]->getData(), $publ_cache);
}
if (isset($publish_year[0])) {
// echo 'Publish year: '.$publish_year[0]->getData();
$data['publish_year'] = $publish_year[0]->getData();
}
}
// Collation
$clt_fld = $record->getField('300');
if ($clt_fld) {
$data['collation'] = '';
$pages = $clt_fld->getSubfields('a');
$ilus = $clt_fld->getSubfields('b');
$dimension = $clt_fld->getSubfields('c');
if (isset($pages[0])) {
// echo 'Pages: '.$pages[0]->getData();
$data['collation'] .= $pages[0]->getData();
}
if (isset($ilus[0])) {
// echo 'Ilus.: '.$ilus[0]->getData();
$data['collation'] .= $ilus[0]->getData();
}
if (isset($dimension[0])) {
// echo 'Dimension: '.$dimension[0]->getData();
$data['collation'] .= $dimension[0]->getData();
}
}
// Series title
$series_fld = $record->getField('440');
if ($series_fld) {
$series = $series_fld->getSubfields('a');
if (isset($series[0])) {
// echo "\n"; echo 'Series: '.$series[0]->getData();
$data['series_title'] = $dbs->escape_string(trim($series[0]->getData()));
}
}
// Notes
$notes_flds = $record->getFields('^5', true);
if ($notes_flds) {
$data['notes'] = '';
// echo "\n"; echo 'Notes: ';
foreach ($notes_flds as $note_fld) {
if ($note_fld) {
$notes = $note_fld->getSubfields('a');
if (isset($notes[0])) {
$data['notes'] .= $dbs->escape_string(trim($notes[0]->getData()));
}
}
}
}
// insert biblio data
$sql_op->insert('biblio', $data);
echo ''.$sql_op->error.'
';
$biblio_id = $sql_op->insert_id;
if ($biblio_id < 1) {
continue;
}
$updated_row++;
// Subject
$subject_flds = $record->getFields('650|651|648|655|656|657', true);
if ($subject_flds) {
// echo 'Subject: ';
foreach ($subject_flds as $subj_fld) {
if ($subj_fld) {
$subject = $subj_fld->getSubfields('a');
if (isset($subject[0])) {
// echo $subject[0]->getData();
$subject_type = 't';
$subject_id = getSubjectID($dbs->escape_string(trim($subject[0]->getData())), $subject_type, $subject_cache);
@$dbs->query("INSERT IGNORE INTO biblio_topic (biblio_id, topic_id, level) VALUES ($biblio_id, $subject_id, 1)");
}
}
}
}
// Main entry
$me_fld = $record->getField('100');
if ($me_fld) {
$mes = $me_fld->getSubfields('a');
if (isset($me[0])) {
// echo 'Main entry: '.$me[0]->getData();
$author_id = utility::getID($dbs, 'mst_author', 'author_id', 'author_name', $dbs->escape_string(trim($me[0]->getData())), $author_cache);
@$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)");
}
}
// Author additional
$author_flds = $record->getFields('700|710|711', true);
if ($author_flds) {
// echo 'Author: ';
foreach ($author_flds as $tag => $auth_fld) {
if ($tag == '710') {
$author_type = 'o';
} else if ($tag == '711') {
$author_type = 'c';
} else {
$author_type = 'p';
}
if ($auth_fld) {
$author = $auth_fld->getSubfields('a');
if (isset($author[0])) {
// echo $author[0]->getData();
$author_id = getAuthorID($dbs->escape_string(trim($author[0]->getData())), $author_type, $author_cache);
@$dbs->query("INSERT IGNORE INTO biblio_author (biblio_id, author_id, level) VALUES ($biblio_id, $author_id, 1)");
}
}
}
}
// create biblio index
if ($sysconf['index']['type'] == 'index') {
$indexer->makeIndex($biblio_id);
}
}
$end_time = time();
$import_time_sec = $end_time-$start_time;
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', 'Importing '.$updated_row.' MARC records from file : '.$_FILES['importFile']['name']);
echo '';
exit();
}
}
?>
submit_button_attr = 'name="doImport" value="'.__('Import Now').'" class="btn btn-default"';
// form table attributes
$form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
$form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
$form->table_content_attr = 'class="alterCell2"';
/* Form Element(s) */
// csv files
$str_input = simbio_form_element::textField('file', 'importFile');
$str_input .= ' Maximum '.$sysconf['max_upload'].' KB';
$form->addAnything(__('File To Import'), $str_input);
// text import
// $form->addTextField('textarea', 'MARCtext', __('MARC record text'), '', 'style="width: 100%; height: 500px;"');
// number of records to import
$form->addTextField('text', 'recordNum', __('Number of records to import (0 for all records)'), '0', 'style="width: 10%;"');
// output the form
echo $form->printOut();