function run_batch($lines, $date) { $rowcount = 0; $b = array(); while (count($lines)) { //$columns = explode(",",trim(array_shift($lines))); $columns = str_getcsv(array_shift($lines), ",", "\""); /* * Column 0 is for Serial Number * */ if ($columns[0] == 'S No') { continue; } $rowcount++; if (strlen(trim($columns[0])) == 0) { //add title to an array $b[$rowcount] = "Line Number " . $rowcount . " Barcode/Serial No not entered."; continue; } /* * Column 1 is for Title */ if (strlen(trim($columns[1])) == 0) { $b[$rowcount] = "Barcode " . $columns[0] . " Title not entered."; continue; } else { $columns[1] = str_replace("'", "\\'", $columns[1]); } /* * Column 2 is for Author */ $columns[2] = str_replace("'", "\\'", $columns[2]); /* * Column 3 is for Circulation Status */ if (strlen(trim($columns[3])) == 0) { $columns[3] = "in"; } if (strcmp($columns[3], 'Missing') == 0) { $columns[3] = "lst"; } if (strcmp($columns[3], 'Active') == 0) { $columns[3] = "in"; } if (strcmp($columns[3], 'Inactive') == 0) { $columns[3] = "ina"; } if (strcmp($columns[3], 'Damaged') == 0) { $columns[3] = "mnd"; } /* * Column 4 is for Reading Level */ if (strlen(trim($columns[4])) == 0 || strcmp($columns[4], 'X') == 0) { $columns[4] = 9; } /* * Column 5 is for Basket Number */ if (strlen(trim($columns[5])) == 0 || strcmp($columns[5], 'XY') == 0) { $columns[5] = "Unassigned"; } /* * Column 6 is for Comments */ if (strlen(trim($columns[6])) == 0) { $columns[6] = ' '; } /* Column 7 is for publication*/ $import = new ImportQuery(); $bibid = $import->alreadyInDB($columns[1], $columns[2], $columns[7]); if ($bibid == 0) { $lastinsertid = $import->insertBiblio($columns); if ($lastinsertid == 0) { //add title to an array $b[$rowcount] = "Record " . $rowcount . " Unknown error."; continue; } $result = $import->insertBiblioCopy($columns, $lastinsertid); if ($result != null) { $b[$rowcount] = $result; } } else { $result = $import->insertBiblioCopy($columns, $bibid); if ($result != null) { $b[$rowcount] = $result; } } } return $b; }
function run_batch($lines, $date) { $rowcount = 0; $b = array(); while (count($lines)) { $columns = str_getcsv(array_shift($lines), ",", "\""); /* Column 0 is for the serial number */ if ($columns[0] == 'S No') { continue; } $rowcount++; if (strlen(trim($columns[0])) == 0) { //add title to an array $b[$rowcount] = "Record " . $rowcount . " Barcode/Serial No not entered."; continue; } /*column 1 is for the title*/ if (strlen(trim($columns[1])) == 0) { $b[$rowcount] = "Record " . $rowcount . " Title not entered."; continue; } else { $columns[1] = str_replace("'", "\\'", $columns[1]); } /*column 2 is for the author*/ $columns[2] = str_replace("'", "\\'", $columns[2]); $import = new ImportQuery(); $dmQ = new DmQuery(); $collectionDesc = $dmQ->getAssoc("collection_dm", "description"); $materials = $dmQ->getAssoc("material_type_dm", "description"); $statuses = $dmQ->getAssoc("biblio_status_dm", "description"); /*column 3 is for the circulation status(in- active,ina- inactive,lst-damaged)*/ $status_found = false; foreach ($statuses as $code => $status) { if (strcmp($columns[3], $status) == 0) { $columns[3] = $code; $status_found = true; } } if (strlen(trim($columns[3])) == 0 || status_found == false) { $columns[3] = "in"; } /*column 4 is for Category , column 5 is for Type*/ foreach ($collectionDesc as $code => $collection) { if (strcmp($columns[4] . " " . $columns[5], $collection) == 0) { $columns[4] = $code; } } if (strlen(trim($columns[4])) == 0) { $columns[4] = '1'; } /*column 6 is for Medium(book,video/dvd,magazine)*/ foreach ($materials as $code => $collection) { if (strcmp($columns[6], $collection) == 0) { $columns[6] = $code; } } if (strlen(trim($columns[6])) == 0) { $columns[6] = '2'; } /*column 7 is for comments*/ if (strlen(trim($columns[7])) == 0) { $columns[7] = ' '; } /*column 8 is for location id*/ if (strlen(trim($columns[8]) == 0) || !is_numeric($columns[8])) { $columns[8] = null; } $bibid = $import->alreadyInDB($columns[1]); if ($bibid == 0) { $lastinsertid = $import->insertBiblio($columns); if ($lastinsertid == 0) { //add title to an array $b[$rowcount] = "Record " . $rowcount . " Unknown error."; continue; } $import->insertBiblioCopy($columns, $lastinsertid); } else { $import->insertBiblioCopy($columns, $bibid); } } return $b; }