PHP + DOM + Joel = SMS from OPAC

      Comments Off on PHP + DOM + Joel = SMS from OPAC

Mentioned the other day that I was working on adding a “send this call number to your cell phone” capability to our Voyager OPAC (mitigating the “find a scrap of paper” problem). I was heading down the JavaScript path (based on a email exchange I had with Kevin Gilbertson of Wake Forest) when I got a tip that Joel Shields, Library Portal Specialist at the Washington Research Library Consortium (WRLC), had developed similar functionality for their Aladin system (also a Voyager catalog).

Emailed Joel and got a quick reply: while his code was not yet in production, he’d be more than happy to share it with me. That was really nice of him but to my mind even nicer was the fact that he coded his solution in PHP—meaning I could sidestep all the browser-specific issues that accompany (plague?) javascript development.

Following Joel’s well-documented instructions, I had the feature up and running within the hour. I made a few modifications to the logic for parsing out the call number then added the new capability to our OPAC with a “Send Call Number to  Phone (beta) label.


It’s “beta” because I’m still tweaking the figure out the call number logic and toying with the idea of reworking the script to better deal with what I think is an edge case:  multiple copies of an item shelved under different call numbers in multiple libraries. The current script grabs the call number from the bibliographic record (stepping through the 090, 099, 050 and 086 MARC tags to figure out the correct call number).   If all copies share a common call number (which appears to be the typical case) it’s not a big deal that I’m not capturing location (after all, you’ll have to know which building you want to go to before you’ll ever be able to get there).

But if a copy of an item has a call number that’s different from the one stored in the bib record, the software will display the “wrong” number. For now, I’m forced to treat this as a documentation problem; that is, I have a note on the popup window suggesting that you should make sure the call number displayed is the one you’re actually interested in sending to your phone.

How does it work…

Several hidden field values are added to the template that builds the Voyager OPAC display. The relevant values are imbedded in <div> tags to simplify identifying them in subsequent processing.  Here’s an excerpt from display1.cfg that shows how the hidden values are labeled and embedded:

[sourcecode language=’html’]
&nbsp;
HTML:245||a:

{a}

HTML:245||c:

{c}

HTML:090||ab:

{a}{b}

HTML:050||ab:

{a}{b}

HTML:099||a:

{a}

HTML:086||a:

{a}

[/sourcecode]

A link (the cell phone icon), launches a PHP script on another machine, passing along the BibID for the item that’s displayed.  Again from display1.cfg, here’s how the link to the PHP code is handled:

[sourcecode language=”html”]
Send Call Number to phone (beta):
HTML:001:
[/sourcecode]

Once launched, the PHP script (scrape.php) does a second “behind-the-scenes” query of the OPAC using the BBID value, then as the OPAC returns an HTML page, it is parsed and dumped into a DOM object. Using the SimpleHTMLDOM module (basically a wrapper around the DOM functions in PHP5 and a port of jQuery functionality) it’s pretty easy to pick out and deal with relevant data elements within the <div> tags (e.g., “scrapeauthor” and “scrapetitle” and so on).

After four days I think I can say it’s stable…and I notice it’s been used just over 300 times.  That’s not bad for a new “find it yourself” feature that’s had no promotion whatsoever.