automating custom notices and messages using sql

22
David Noe Orange County Library System [email protected] Automating Custom Patron Notices and Messages Using SQL

Upload: david-noe

Post on 06-Apr-2017

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automating Custom Notices and Messages Using SQL

David Noe Orange County Library [email protected]

Automating Custom Patron Notices and Messages Using SQL

Page 2: Automating Custom Notices and Messages Using SQL

•Metropolitan public library•Main downtown library and 14 branches • Serving > 1,000,000 Orange County Residents•> 1.7 million items•~ 0.5 million checkouts a month•~10% of that are requests delivered•~350 employees• Annual budget totals approximately $35.3 million•Migrated to Sierra in late 2012

Page 3: Automating Custom Notices and Messages Using SQL

PROBLEMS:•Delivered notices are clunky Browser email Mobile

Page 4: Automating Custom Notices and Messages Using SQL

PROBLEMS:•Delivered notices are clunky•Customizing delivered notices?

– iReport (which is being replaced by something else?)– Java– Notice Data Libraries

Page 5: Automating Custom Notices and Messages Using SQL

PROBLEMS:•Delivered notices are clunky•Customizing delivered notices?

– iReport (which is being replaced by something else?)– Java– Notice Data Libraries

• Limited notices delivered– Holds expiration alert– Welcome messages– Due date alerts– Fine alerts

Page 6: Automating Custom Notices and Messages Using SQL

EXAMPLE CUSTOM NOTICE WE SENT BEFORE SQL ACCESS:

Page 7: Automating Custom Notices and Messages Using SQL

SOLUTION:

Create our own email notices leveraging in-house expertise.

Page 8: Automating Custom Notices and Messages Using SQL

LANGUAGE

•Perl•Python•VB•PHP

Page 9: Automating Custom Notices and Messages Using SQL

PHP

Page 10: Automating Custom Notices and Messages Using SQL

LANGUAGE

•Perl•Python•VB•PHP•Whatever you got

Page 11: Automating Custom Notices and Messages Using SQL

BASIC DATA FLOW

Page 12: Automating Custom Notices and Messages Using SQL

RESOURCES

PHP

MySQL

Page 13: Automating Custom Notices and Messages Using SQL

WELCOME MESSAGE

Page 14: Automating Custom Notices and Messages Using SQL

<PHP? $dbp = pg_connect("host=192.168.xxx.xxx port=1032 dbname=iii user=xxx password=xxx"); $dbm = mysql_pconnect('192.168.xxx.xxx','xxxx','xxxx'); $items = array(); $html = file_get_contents('/home/xxx/scripts/Templates/welcome_email.html'); $htmls = ''; $nl = "\r\n"; $q = " SELECT svn.patron_record_id as prid, svv.field_content as em, svn.last_name as ln, svn.first_name as fn FROM sierra_view.patron_record svp

LEFT JOIN sierra_view.record_metadata svm ON svp.id=svm.id

LEFT JOIN sierra_view.varfield svv ON svp.record_id = svv.record_id

LEFT JOIN sierra_view.patron_record_fullname svn ON svp.record_id = svn.patron_record_id

WHERE date(svm.creation_date_gmt) = current_date -15 AND svm.record_type_code='p' AND svp.mblock_code = '-' AND svp.ptype_code < '2' AND svv.varfield_type_code = 'z'; ";

$r = pg_query($dbp,$q); ...

WELCOME MESSAGE (only touching on core concepts)

Page 15: Automating Custom Notices and Messages Using SQL

if ($r) {

while ($row = pg_fetch_assoc($r)) {

$pid = $row['prid'];$ln = ucwords(strtolower($row['ln']));$fn = ucwords(strtolower($row['fn']));$em = trim($row['em']);

if (@!$items[$em]) {$items[$em][0][0] = $ln;$items[$em][0][1] = $fn;$items[$em][0][2] = $pid;

} else {array_push($items[$em],array($ln,$fn,$pid));

}}

} ...

WELCOME MESSAGE (seriously, do not attempt to read all of this)

Page 16: Automating Custom Notices and Messages Using SQL

foreach ($items as $h => $a) {

echo "\r\n<$h> \"".$items[$h][0][0]." ".$items[$h][0][1]." ".$items[$h][0][2]."\" \r\n";

$pname = $items[$h][0][1]." ".$items[$h][0][0];$prid = $items[$h][0][2];$em = trim($h);

$to = $h;

$subject = 'The Coolest Card In Town';$headers = "From: <[email protected]> \"Orange County Library System\"\r\n";$headers .= "MIME-Version: 1.0\r\n";$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; ...

WELCOME MESSAGE (not my code, so it takes me half an hour)

Page 17: Automating Custom Notices and Messages Using SQL

if ($dbm) {$s = "insert into statistics.welcomenotices(pid,em,ts) values ('".$prid."','".$em."',now());";$r = mysql_query($s,$dbm);echo "logging data \r\n";

} else {echo "no connection to mysql \r\n";

}

if (preg_match('/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/',$em) == 1) {

$htmls = str_replace('<!-- PATRON -->',$pname,$html);

mail($to,$subject,$htmls,$headers);

usleep(1500000);

}

}

?>

WELCOME MESSAGE (I may try to post some of our code later)

Page 18: Automating Custom Notices and Messages Using SQL

DUE DATE ALERTSELECT svc.patron_record_id as pid, svp.first_name as fn, svp.last_name as ln, svv.field_content as email, svb.best_title as title

FROM sierra_view.checkout svc LEFT JOIN sierra_view.patron_record_fullname svp ON svc.patron_record_id = svp.patron_record_id

LEFT JOIN sierra_view.varfield svv ON svp.patron_record_id = svv.record_id

LEFT JOIN sierra_view.item_record_property svi ON svi.item_record_id = svc.item_record_id

LEFT JOIN sierra_view.bib_record_item_record_link svl ON svl.item_record_id = svi.item_record_id

LEFT JOIN sierra_view.bib_record_property svb ON svl.bib_record_id=svb.bib_record_id

WHERE date(svc.due_gmt) = current_date AND svv.varfield_type_code = 'z'

ORDER BY svp.patron_record_id;

Page 19: Automating Custom Notices and Messages Using SQL

HOLDS EXPIRATION ALERTSELECT svh.patron_record_id as pid, date_trunc('day',svh.expires_gmt) as exp, svp.last_name as ln, svp.first_name as fn, sv1.field_content as email, sv2.field_content as title

FROM sierra_view.hold svh LEFT JOIN sierra_view.patron_record_fullname svp ON (svh.patron_record_id = svp.patron_record_id) JOIN sierra_view.varfield sv1 ON (svh.patron_record_id = sv1.record_id AND sv1.varfield_type_code = 'z') LEFT JOIN sierra_view.bib_record_item_record_link bil ON (svh.record_id = bil.item_record_id) LEFT JOIN sierra_view.varfield sv2 ON ((svh.record_id = sv2.record_id OR bil.bib_record_id = sv2.record_id) AND sv2.varfield_type_code = 't')

WHERE DATE(svh.expires_gmt) > DATE (now() + interval '7days') AND DATE(svh.expires_gmt) < DATE (now() + interval '14days')

ORDER BY svh.patron_record_id asc, exp asc;

Page 20: Automating Custom Notices and Messages Using SQL

FINE ALERT

Page 21: Automating Custom Notices and Messages Using SQL

FURTURE PLANS

•Courtesy notices•More personalized welcome notices • Requests filled (held items delivery)• Internal statistics

Page 22: Automating Custom Notices and Messages Using SQL

Fin.