Skip to content

Instantly share code, notes, and snippets.

@terrywbrady
Last active July 25, 2016 21:04
Show Gist options
  • Save terrywbrady/edb05c65672c291d17e1a25c5ffc02d0 to your computer and use it in GitHub Desktop.
Save terrywbrady/edb05c65672c291d17e1a25c5ffc02d0 to your computer and use it in GitHub Desktop.
Sierra Barcode Report
<?php
/*
User form for initiating a bulk ingest. User must have already uploaded ingestion folders to a server-accessible folder.
Author: Terry Brady, Georgetown University Libraries
License information is contained below.
Copyright (c) 2014, Georgetown University Libraries All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
See http://techdocs.iii.com/sierradna/
*/
include '../../web/header.php';
include 'Sierra.php';
$CUSTOM = custom::instance();
$SIERRA = new Sierra($CUSTOM->isUserSysAdmin());
$user = $CUSTOM->getCurrentUser();
$barcode = util::getArg("barcode","");
header('Content-type: text/html; charset=UTF-8');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
$header = new LitHeader("Barcode Report");
$header->litPageHeader();
?>
<style type="text/css">
th.wide {width: 200px;}
#restable tr:nth-child(odd) {
background-color: #EEE;
}
tr.processing td, tr.processing th {
background-color: yellow;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#addb").on("click", function(){
dialog.dialog( "open" );
});
$(document).bind('keypress', function(e){
if ( e.keyCode == 13 ) {
$("button.ui-button:first:enabled").click();
return false;
}
});
var dialog = $( "#dialog-form" ).dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
buttons: {
"Add Barcode": function() {
addBarcode($("#barcode").val());
$("#barcode").val("");
},
"Done": function() {
dialog.dialog( "close" );
}
},
});
$("#barcode").on("keyup", function(){valBarcode()})
$("#barcode").on("change", function(){valBarcode()})
dialog.dialog( "open" );
var testCodes = $("#test").val().split(",");
for(i=0; i<testCodes.length; i++) {
addBarcode(testCodes[i]);
}
});
function addBarcode(barcode) {
if (barcode == null || barcode == "") return;
if (!isValidBarcode(barcode)) return;
if (isDuplicateBarcode(barcode)) return;
var tr = $("<tr class='new'/>");
tr.attr("barcode",barcode);
var td = $("<th>" + barcode + "</th>");
tr.append(td);
tr.append($("<td class='record_num'/>"));
tr.append($("<td class='call_number'/>"));
tr.append($("<td class='location_code'/>"));
tr.append($("<td class='status_code'/>"));
tr.append($("<td class='icode2'/>"));
tr.append($("<td class='due_date'/>"));
tr.append($("<td class='volume'/>"));
tr.append($("<td class='is_suppressed'/>"));
tr.append($("<td class='status'/>"));
$("#restable").append(tr);
processCodes();
}
function processCodes() {
if ($("#restable tr.processing").length > 0) return;
var tr = $("#restable tr.new:first");
if (tr.length == 0) return;
tr.removeClass("new").addClass("processing");
var barcode = tr.attr("barcode");
$.getJSON("barcodeReportData.php?barcode="+barcode, function(data){
var resbarcode = data["barcode"];
var tr = $("#restable tr[barcode="+resbarcode+"]");
for(key in data) {
var val = data[key] == null ? "" : data[key];
tr.find("td."+key).text(val);
}
tr.removeClass("processing");
processCodes();
});
}
function isValidBarcode(barcode) {
return /^[0-9]{14,14}$/.test(barcode);
}
function isDuplicateBarcode(barcode) {
return ($("tr[barcode="+barcode+"]").length > 0)
}
function valBarcode() {
var bc = $("#barcode");
var msg = $("#message");
msg.text("");
bc.addClass("ui-state-error");
$("button.ui-button:first").attr("disabled", true);
var v = bc.val();
if (v == null || v == "") {
msg.text("Barcode cannot be empty");
} else if (!isValidBarcode(v)) {
msg.text("Enter a 14 digit barcode");
} else if (isDuplicateBarcode(v)) {
msg.text("Duplicate barcode");
} else {
msg.text("Barcode appears to be valid");
bc.removeClass("ui-state-error");
$("button.ui-button:first").attr("disabled", false);
}
}
</script>
</head>
<body>
<?php $header->litHeader(array("<a href='../../web/ils.php'>ILS Tools</a>"));?>
<input id="test" type="hidden" value="<?php echo util::getArg('test','')?>"/>
<div id="dialog-form" title="Add Barcode">
<p class="validateTips" id="message">Enter a barcode.</p>
<form>
<fieldset>
<label for="name">Barcode</label>
<input type="text" name="barcode" id="barcode" value="" class="text ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
<div id="main">
<button id="addb">Add Barcode</button>
<div>
<table id='restable'>
<tr class='header'>
<th class='role'>Barcode</th>
<th class='role'>Record Num</th>
<th class='role wide'>Call Number</th>
<th class='role'>Location Code</th>
<th class='role'>Status Code</th>
<th class='role'>icode2</th>
<th class='role'>Due Date</th>
<th class='role'>Volume</th>
<th class='role'>Is Suppressed (Bib)</th>
<th class='role wide'>Status</th>
</tr>
</table>
</div>
<?php $header->litFooter();?>
</div>
</body>
</html>
<?php
/*
User form for initiating a bulk ingest. User must have already uploaded ingestion folders to a server-accessible folder.
Author: Terry Brady, Georgetown University Libraries
License information is contained below.
Copyright (c) 2014, Georgetown University Libraries All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
See http://techdocs.iii.com/sierradna/
*/
include '../../web/header.php';
include 'Sierra.php';
$CUSTOM = custom::instance();
$SIERRA = new Sierra($CUSTOM->isUserSysAdmin());
$user = $CUSTOM->getCurrentUser();
$barcode = util::getArg("barcode","");
if ($barcode != "") {
echo json_encode(showReport($SIERRA, $barcode));
}
function showReport($SIERRA, $barcode) {
$sql = <<< HERE2
select
pe.index_entry as barcode,
iv.record_num,
iv.location_code,
iv.item_status_code,
iv.icode2,
(select to_char(due_gmt,'YYYY-MM-DD') from sierra_view.checkout where item_record_id = iv.id),
(select field_content from sierra_view.varfield_view where record_type_code = 'i' and varfield_type_code='v' and record_id=iv.id) as vol,
(select is_suppressed from sierra_view.bib_record where id = (
select bib_record_id from sierra_view.bib_record_item_record_link where item_record_id=iv.id)
) as bib_suppress,
(select content from sierra_view.subfield_view where record_id=iv.id and marc_tag = '090' and record_type_code='i' and field_type_code='c' and tag='a' limit 1) as f090a,
(select content from sierra_view.subfield_view where record_id=iv.id and marc_tag = '090' and record_type_code='i' and field_type_code='c' and tag='b' limit 1) as f090b,
(select content from sierra_view.subfield_view where record_id=iv.id and marc_tag = '099' and record_type_code='i' and field_type_code='c' limit 1) as f099,
(select content from sierra_view.subfield_view where record_id=iv.id and marc_tag is null and record_type_code='i' and field_type_code='c' limit 1) as varc
from
sierra_view.phrase_entry pe
inner join
sierra_view.item_view iv
on pe.record_id = iv.id
where
pe.index_tag || pe.index_entry = :barcode
HERE2;
$arg = array(":barcode" => 'b' . $barcode);
$resdata = array("barcode" => $barcode, "status" => " ** Barcode Not Found");
$dbh = $SIERRA->getPdoDb();
$stmt = $dbh->prepare($sql);
$result = $stmt->execute($arg);
if (!$result) {
print($sql);
print_r($dbh->errorInfo());
die("Error in SQL query: ");
}
$result = $stmt->fetchAll();
foreach ($result as $row) {
$call_number = "-";
if ($row[8] != "" && $row[9] != "") {
$call_number = $row[8] . " " . $row[9];
} else if ($row[8] != "" && $row[8] != null) {
$call_number = $row[8];
} else if ($row[10] != "" && $row[10] != null) {
$call_number = $row[10];
} else if ($row[11] != "" && $row[11] != null) {
$call_number = $row[11];
}
$resdata = array(
"barcode" => $row[0],
"record_num" => $row[1],
"location_code" => $row[2],
"status_code" => $row[3],
"icode2" => $row[4],
"due_date" => $row[5],
"volume" => $row[6],
"is_suppressed" => $row[7],
"call_number" => $call_number,
"status" => "Barcode Found",
);
}
return $resdata;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment