automating custom notices and messages using sql
TRANSCRIPT
David Noe Orange County Library [email protected]
Automating Custom Patron 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
PROBLEMS:•Delivered notices are clunky Browser email Mobile
PROBLEMS:•Delivered notices are clunky•Customizing delivered notices?
– iReport (which is being replaced by something else?)– Java– Notice Data Libraries
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
EXAMPLE CUSTOM NOTICE WE SENT BEFORE SQL ACCESS:
SOLUTION:
Create our own email notices leveraging in-house expertise.
LANGUAGE
•Perl•Python•VB•PHP
PHP
LANGUAGE
•Perl•Python•VB•PHP•Whatever you got
BASIC DATA FLOW
RESOURCES
PHP
MySQL
WELCOME MESSAGE
<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)
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)
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)
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)
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;
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;
FINE ALERT
FURTURE PLANS
•Courtesy notices•More personalized welcome notices • Requests filled (held items delivery)• Internal statistics
Fin.