"Example_Session", "auth" => "Example_Auth", "perm" => "Example_Perm")); $perm->check("user"); print ""; include("/var/web/vn/vn.css"); break; default: page_open(array("sess" => "Example_Session")); include("/var/web/vn/vn.css"); break; }; function pg_query ($sql,$sql2="") { global $conn,$rows,$result_set,$result_set2; $conn = pg_pConnect("host=localhost user=vernier dbname=eduml"); if (!$conn) { echo "error connecting to database" ; }; $result_set = pg_Exec ($conn, $sql); $rows = pg_NumRows($result_set); if ($sql2) { $result_set2 = pg_Exec ($conn, $sql2); $rows2 = pg_NumRows($result_set2); } if ((!$result_set) || ($rows < 1)) { echo "

ERROR - no rows returned

"; echo "

ERREUR - aucun livre ne correspond

"; exit; } } function pg_display ($col1,$col2="",$col3="",$col4="",$col5="",$col6="",$col7="") { global $conn,$result_set; $rows=pg_NumRows($result_set); print ""; for ($j=0; $j < $rows; $j++) { print ""; if ($col2 != "") { echo "";} if ($col3 != "") { echo "";} if ($col4 != "") { echo "";} if ($col5 != "") { echo "";} if ($col6 != "") { echo "";} if ($col7 != "") { echo "";} print ""; } print "
$col1$col2$col3$col4$col5$col6$col7
"; echo pg_result($result_set, $j, "$col1"); print "".pg_result($result_set, $j, "$col2")."".pg_result($result_set, $j, "$col3")."".pg_result($result_set, $j, "$col4")."".pg_result($result_set, $j, "$col5")."".pg_result($result_set, $j, "$col6")."".pg_result($result_set, $j, "$col7")."
"; } function pg_showfield ($field,$fieldname,$j,$extra="") { global $result_set; $field_content = pg_result($result_set, $j, "$field"); if ($field_content) { echo "$fieldname$field_content"; if ($extra) {echo " $extra" ;}; echo ""; }; } if ($module=='acquisition'){ print "

acquisition

"; $i=0; $fieldz = array ("barcode","copies","realkey","title","author","synonyms","publisher","responsibility", "call_number","date","value","new_copies","reading_level", "title_loan_code","illustrator","translator","series", "series_number","subject","uniform_title","added_title", "collation","frequency","last_updated","last_updated_by","status"); $conn = pg_pConnect("host=localhost user=vernier dbname=eduml"); $result_set = pg_Exec ($conn,"select max(realkey) as m from titles"); $max_realkey = pg_result($result_set, 0, m); $result_set = pg_Exec ($conn,"select max(barcode) as max from barcodes"); $max_barcode = pg_result($result_set, 0, max); echo "current max barcode: $max_barcode
current max realkey: $max_realkey

"; if (!$conn) { echo "error connecting to database" ;}; if (!$all) {$all = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";}; if (! eregi('r',$all)) {$cat='barcodes.barcode'; $result_set = pg_Exec ($conn, "select * from titles,barcodes where barcodes.realkey = titles.realkey and $cat::text='$all'"); }else {$cat='titles.realkey'; $all = eregi_replace("r"," ",$all); echo "

$cat $all

"; $result_set = pg_Exec ($conn, "select * from titles where $cat::text=$all::text"); } if (! pg_NumRows($result_set)) { echo "not using any template"; } else { echo "using $cat $all as template";}; while ($fieldz[$i]) { if ($i%2) {$r2="";} else {$r2="";}; if (! pg_NumRows($result_set)) { $template = ""; } else { $template = pg_result($result_set, 0, $fieldz[$i]); }; if ($i==25) {$template .= " unprinted"; }; if ($i==24) {$template .= $username; }; if ($i==23) {$template = date("j M Y"); }; print "$r2
$fieldz[$i] \n"; $i++; } print "

"; } if ($module=='newstuff'){ $fieldstitle="realkey,title,author,synonyms,publisher,responsibility, call_number,date,value, new_copies,reading_level,title_loan_code,illustrator, translator,series,series_number,subject,uniform_title, added_title,collation,frequency,last_updated,last_updated_by, status"; $valuestitle="'$realkey','$title','$author','$synonyms','$publisher', '$responsibility','$call_number','$date','$value', '$new_copies','$reading_level','$title_loan_code','$illustrator', '$translator','$series','$series_number','$subject','$uniform_title', '$added_title','$collation','$frequency','$last_updated','$last_updated_by', '$status'"; $conn = pg_pConnect("host=localhost user=vernier dbname=eduml"); if (!$conn) { echo "error connecting to database" ;}; if ($mode=='add') { echo 'add mode'; $result_set = pg_Exec($conn,"insert into titles ($fieldstitle) values ($valuestitle)"); $m1 = pg_ErrorMessage($conn); $result_set = pg_Exec($conn,"insert into barcodes (realkey,copies,barcode) values ($realkey,$copies,$barcode)"); $m2 = pg_ErrorMessage($conn); } elseif ($mode=='delete_barcode') { echo "delete_barcode $barcode"; $result_set = pg_Exec($conn,"delete from barcodes where barcode=$barcode and realkey=$realkey"); $m1 = pg_ErrorMessage($conn); $m2 = pg_NumRows($result_set); } elseif ($mode=='lost_title') { echo "lost_title $realkey $call_number $title"; $result_set = pg_Exec($conn,"update titles set status='perdu en 1999' where realkey=$realkey and call_number='$call_number' and title='$title'"); $m1 = pg_ErrorMessage($conn); $m2 = pg_NumRows($result_set); } elseif ($mode=='modify') { echo "modify title $realkey $call_number $title"; print "

Modifies realkey $realkey

"; $result_set = pg_Exec($conn,"update titles set title='$title', author='$author',synonyms='$synonyms',publisher='$publisher', responsibility='$responsibility',call_number='$call_number', date='$date',value='$value',new_copies='$new_copies', reading_level='$reading_level',title_loan_code='$title_loan_code', illustrator='$illustrator',translator='$translator', series='$series',series_number='$series_number',subject='$subject', uniform_title='$uniform_title',added_title='$added_title', collation='$collation',frequency='$frequency', last_updated='$last_updated',last_updated_by='$last_updated_by', status='$status' where realkey=$realkey"); $m1 = pg_ErrorMessage($conn); $m2 = pg_NumRows($result_set); } if (! $m1 && ! $m2) {echo "

Success!

";} else {echo "

$m1

$m2

";}; echo "
"; } if (eregi("research",$module)) { $all = strtoupper($all); $title = strtoupper ($title); $author = strtoupper ($author); $subject = strtoupper ($subject); if (!$all AND !$title AND !$author AND !$subject) {echo "nothing";exit; }; echo "Research

Recherche: $all $title $author $subject

"; if ($all) {$cond = "(subject ~* '$all' OR author ~* '$all' OR title ~* '$all' OR synonyms ~* '$all' OR series ~* '$all' OR publisher ~* '$all' OR call_number ~* '$all' OR translator ~* '$all' OR responsibility ~* '$all' OR illustrator ~* '$all')";}; if ($title) {$cond1 = "title ~* '$title'";}; if ($author) {$cond2 = "(author ~* '$author' OR illustrator ~* '$author' OR translator ~* '$author')";}; if ($subject) {$cond3 = "subject ~* '$subject'";}; if ($cond1 AND $cond) {$cond = "$cond AND $cond1";}; if ($cond1 AND !$cond) {$cond = "$cond1";}; if ($cond2 AND $cond) {$cond = "$cond AND $cond2";}; if ($cond2 AND !$cond) {$cond = "$cond2";}; if ($cond3 AND $cond) {$cond = "$cond AND $cond3";}; if ($cond3 AND !$cond) {$cond = "$cond3";}; if (ereg("^([0-9]+[rR])$",$all)) {$all = eregi_replace('r','',$all); $cond ="realkey = $all" ;} elseif (ereg("^([0-9]+)$",$all)) {$cond =" realkey in (select realkey from barcodes where barcode=$all) " ;}; if (ereg("\~",$all)) {$cond ="text_soundex(title) = text_soundex('$all')" ;}; if (ereg("\~",$title)) {$cond ="text_soundex(title) = text_soundex('$title')" ;}; if (ereg("\~",$author)) {$cond ="text_soundex(author) = text_soundex('$author')" ;}; if (ereg("\~",$subject)) {$cond ="text_soundex(subject) = text_soundex('$subject')" ;}; pg_query("select * from titles where $cond order by call_number"); print "

$rows items

"; print "
\n"; print "\n"; print "\n"; if ($rows <= 20) {$size=$rows;} else {$size=20;}; if ($rows == 1) { $value = pg_result($result_set, $j, "realkey"); echo "\n"; echo pg_result($result_set, $j, "call_number"); echo pg_result($result_set, $j, "title"); echo ""; }else{ print ""; print ""; }; print "
"; mail("vernier@vc.bc.ca","jel-query $all $title $author $subject","$cond \n$rows items found"); } if ($module=="details") { #details about selected titles in research echo "

Details

"; $items = count($book);$books = $book[0]; for ($i=1; $i <$items; $i++) {$books .= " ,$book[$i]";}; $sql = "select * from titles where realkey in ($books) order by call_number"; pg_query("$sql"); print ""; for ($j=0; $j < $items; $j++) { $realkey = pg_result($result_set, $j, "realkey"); $sql2 = "select * from barcodes where realkey = $realkey"; $result_set2 = pg_Exec($conn,$sql2); $item = "
$items items
"; for ($i=0; $i < pg_NumRows($result_set2); $i++) { $barcode = pg_result($result_set2, $i, "barcode"); $sql3 = "select * from circulation where barcode = $barcode"; $result_set3 = pg_Exec($conn,$sql3); if (!pg_NumRows($result_set3)) { $available = "disponible"; } else {$available = 'due: '.pg_result($result_set3,0,'date_due') .' by '.pg_result($result_set3,0,'borrower');} $item .= ""; } $realstatus = pg_result($result_set, $j, "status"); if ($realstatus) {$item .= "";}; $item .= ""; $item .= ""; $item .= ""; $item .= "
". pg_result($result_set, $j, "call_number")." ". pg_result($result_set, $j, "date")."
copie " . pg_result($result_set2, $i, "copies") . ": $barcode $available $realstatus
$realstatus
".pg_result($result_set, $j, "reading_level")."
".pg_result($result_set, $j, "title_loan_code")."
".pg_result($result_set, $j, "collation")."
"; print "$item"; echo "
Titre..... : " . pg_result($result_set, $j, "title") . ""; pg_showfield("synonyms" , "Autre Titre:",$j); pg_showfield("author", "Auteur.....:",$j); pg_showfield("subject", "Subject....:",$j); pg_showfield("illustrator","Dessinateur:",$j); pg_showfield("translator" ,"Traducteur.:",$j); pg_showfield("responsibility" , "Responsable:",$j); pg_showfield("uniform_title","Uniform....:",$j); pg_showfield("added_title","Added Title:",$j); pg_showfield("series" , "Serie......:",$j, pg_result($result_set,$j,"series_number")); pg_showfield("frequency" , "Frequence..:",$j); pg_showfield("publisher" , "Publisher..:",$j, " ".pg_result($result_set,$j,"value"). " - ".pg_result($result_set,$j,"new_copies")); pg_showfield("realkey" , "RealKey....:",$j, " updated on ".pg_result($result_set,$j,"last_updated"). " by ".pg_result($result_set,$j,"last_updated_by")); print "
"; if (eregi("Lynx",$HTTP_USER_AGENT)) {print "
";}; } #
SQL: $sql
"; print "
"; } if ($module=="inventory") { #remember to grant select to inventory in eduml echo "

Inventaire

"; passthru('psql -c "select * from inventory order by call_number;" -H -d eduml',$asdf); } if ($module=="help") { echo "

Help

"; echo " (c)opyleft GPL 1999 : This program was designed by Denise Dunstheimer and written by Bruno Vernier for Ecole Saint Sacrement

Basic Instructions:

The keyword field is used by some modules in these ways:
  1. research : see advanced searching below for more, NOTE: pure numbers search barcodes and realkeys
  2. overdues : just enter the grade
  3. circulation: enter how many barcodes you want to process at a time per borrower
  4. search: if you put a number, it will search for that barcode
  5. search: if you put a number followed by an r, it searches that realkey

Advanced Searching:

use regular expressions
  • ~ is a wild card for 'sounds approximately like'
  • . is a wild card for any single character (letter)
  • .* is a wild card for anything
  • | means OR
  • the following is for very advanced searches ... if you dare :-)

      ";
      system("man regex");
    }
    
    if ($module=="returns") {
       echo "Returns

    Returns

  • returned barcode:
  • "; } if ($module=="circ_return") { echo "Circulation

    Circulation Returns

    "; $conn = pg_Connect("host=localhost user=vernier dbname=eduml"); if (!$barcode) {echo "missing barcode";exit; } $result_set=pg_Exec($conn,"select * from barcodes where barcode = $barcode"); if (pg_NumRows($result_set)) {$realkey = pg_result($result_set,0,'realkey');} else { echo "There is no barcode $barcode in this library!"; exit;} $result_set=pg_Exec($conn,"select * from titles where realkey=$realkey"); if (pg_NumRows($result_set)) { $title = pg_result($result_set,0,'title'); $call_number = pg_result($result_set,0,'call_number'); } else { echo "There is no realkey $realkey in this library!"; exit;} $result_set = pg_Exec($conn,"select * from circulation where barcode = $barcode"); if (pg_NumRows($result_set)) { pg_display("borrower","barcode","date_begin","date_due"); $borrower = pg_result($result_set,0,'borrower'); $date_due = pg_result($result_set,0,'date_due'); $date_begin = pg_result($result_set,0,'date_begin'); $result_set2 =pg_Exec($conn,"insert into history (barcode,borrower,date_due,date_begin,date_returned) values ($barcode,'$borrower','$date_due','$date_begin','now')"); $result_set2 =pg_Exec($conn,"delete from circulation where borrower = '$borrower' and barcode = $barcode"); if (! $error=pg_ErrorMessage($conn)) { echo "succesfully returned item $barcode:\n $call_number $title" ; } else {echo $error;}; } else { echo "Problem: $call_number : $title"; echo "(barcode $barcode) was not signed out and yet you are trying to return it ...";}; $result_set = pg_Exec($conn,"select * from circulation"); echo "
    ".pg_NumRows($result_set)." items still on loan"; # echo "
    #
    #
    "; echo "More Returns

    More Returns

  • returned barcode:
  • "; } if ($module=="circulation") { echo "Circulation

    Circulation

    "; $date_due=`cat /var/web/vn/.overdue`; #$date_due=`date --date "14 days"`; print "

    date due:
    borrower:

    "; if (! ereg("^([0-9]+)$",$all)) {$all=10;}; for ($i=0;$i<$all;$i++) { print "
  • barcode:"; } print"
  • "; } if ($module=="circ_proc") {$i=0; echo "Circulation

    Circulation Processing

    "; `echo $date_due >/var/web/vn/.overdue`; $conn = pg_Connect("host=localhost user=vernier dbname=eduml"); if (!$borrower) {echo "missing borrower or barcode";exit; } $result_set = pg_Exec($conn,"select * from people where login = '$borrower' OR local_id = '$borrower'"); if (!pg_NumRows($result_set)==1) {echo "No such borrower: $borrower"; exit ;} else { $given = pg_result($result_set,0,"given"); $family = pg_result($result_set,0,"family"); $grade = pg_result($result_set,0,"grade"); print "

    $given $family $grade

    "; }; while ($barcode[$i]) { # START OF BARCODE LOOP $result_set=pg_Exec($conn,"select * from barcodes where barcode = '$barcode[$i]'"); if (pg_NumRows($result_set)) {$realkey = pg_result($result_set,0,'realkey');} else { echo "
    Barcode $barcode[$i] NOT in this library!"; break;} $result_set=pg_Exec($conn,"select * from titles where realkey=$realkey"); if (pg_NumRows($result_set)) { $title = pg_result($result_set,0,'title'); $call_number = pg_result($result_set,0,'call_number'); } else { echo "
    Realkey $realkey NOT in this library!"; break;} $result_set = pg_Exec($conn,"select * from circulation where barcode = $barcode[$i]"); if (pg_NumRows($result_set)) { echo "
    Processing Renewal for $borrower with Barcode $barcode[$i] "; pg_display("borrower","barcode","date_begin","date_due"); $borrower_old = pg_result($result_set,0,'borrower');#to allow others to renew $date_due_old = pg_result($result_set,0,'date_due'); $date_begin_old = pg_result($result_set,0,'date_begin'); $result_set2 =pg_Exec($conn,"insert into history (barcode,borrower,date_due,date_begin,date_returned) values ($barcode[$i],'$borrower_old','$date_due_old','$date_begin_old','now')"); $result_set2 =pg_Exec($conn,"delete from circulation where borrower = '$borrower' and barcode = $barcode[$i]"); if (! $error=pg_ErrorMessage($conn)) { echo "

    renewing item $barcode[$i]:\n

    " ; } else {echo $error;}; } if (! $error=pg_ErrorMessage($conn)) { echo "
    Barcode $barcode[$i] loaned

    $call_number $title

    " ; $date_begin=`date`; #$date_due=`date --date "15 days"`; $result_set = pg_Exec($conn,"insert into circulation (barcode,borrower,date_begin,date_due) values ($barcode[$i],'$borrower','$date_begin','$date_due')"); }else {echo $error;} $i++; } $result_set = pg_Exec($conn," select date_due,title,call_number,local_id,barcodes.barcode as barcode from circulation,people,barcodes,titles where (borrower='$borrower' OR local_id='$borrower') and (borrower=login OR borrower=local_id) and barcodes.barcode = circulation.barcode and barcodes.realkey = titles.realkey order by date_due,call_number"); if ($rows = pg_NumRows($result_set)) { echo "

    $given now has $rows titles out:

    "; echo pg_display(date_due,barcode,call_number,title); } echo "
    "; echo "
    "; } if ($module=="acquisition") { echo "Acquisitions

    New Books

    "; } if ($module=="reservation") { echo "Reservations

    Reservations

    "; } if ($module=="overdues") { if ($all) {$cond=" and grade='$all' " ;} else {$cond ="";}; echo "Overdues

    Overdues $all

    "; $conn = pg_Connect("host=localhost user=vernier dbname=eduml"); $result_set = pg_Exec($conn," select grade,family||', '||given as name,login,date_due,title,call_number,barcodes.barcode as barcode from circulation,people,barcodes,titles where date_due::abstime <= datetime('now'::abstime) $cond and (borrower=login OR borrower=local_id) and barcodes.barcode = circulation.barcode and barcodes.realkey = titles.realkey order by grade,family"); if ( $result_set) { echo "There are " . pg_NumRows($result_set) . " overdues"; echo "
    ".pg_display(grade,name,date_due,barcode,call_number,title). "
    "; } } if ($module=="labels") { echo "Labels

    Labels

    "; } if ($module=="problems") { echo "Barcodes

    Barcodes

    "; print "
    "; # print "
  • Realkey: #
  • Barcode: #
  • # #
    "; require("table.inc"); $t = new Table; $db = new DB_Sql; print "Titles that do not have barcodes:"; $result_set=$db -> query ("SELECT realkey,call_number,title FROM titles WHERE status is null and NOT EXISTS (SELECT realkey FROM barcodes WHERE realkey = titles.realkey) order by call_number"); print " ".$db -> nf() . " items"; pg_display("realkey","call_number","title"); $t -> show_result($db,""); print "Barcodes associated to unknown titles:"; $result_set=$db -> query ("select realkey,copies,barcode FROM barcodes WHERE NOT EXISTS (SELECT realkey FROM titles WHERE realkey = barcodes.realkey) order by realkey"); print " " . $db -> nf() . " items"; pg_display("realkey","copies","barcode"); print "
    "; } if ($module=="newbarcode") { echo "New Barcode

    New Barcode $barcode for $realkey

    "; $conn = pg_Connect("host=localhost user=vernier dbname=eduml"); $result_set = pg_Exec($conn,"select * from barcodes where barcode = $barcode;"); if (pg_NumRows($result_set)) {echo "

    ERROR: barcode $barcode already associated to realkey: ". pg_result($result_set,0,"realkey");exit;}; $result_set = pg_Exec($conn,"select * from titles where realkey = $realkey;"); if (!pg_NumRows($result_set)) {echo "

    ERROR: realkey $realkey DOES NOT EXIST in titles database";exit;}; $result_set = pg_Exec($conn,"select * from barcodes where realkey = $realkey;"); $copies = pg_NumRows($result_set); $copies++; echo "

    realkey $realkey now has $copies copie(s)"; $result_set = pg_Exec($conn,"insert into barcodes (realkey, copies, barcode) values ($realkey, $copies, $barcode);"); echo pg_ErrorMessage($conn); } if ($module=="statistics") { echo "Statistics

    Statistics

    "; require("table.inc"); $t = new Table; $db = new DB_Sql; print "Number of Titles on Loan per Borrower:"; $db -> query ("select distinct borrower,count(*) from circulation group by borrower order by borrower"); $t -> show_result($db,""); echo "
    "; } if ($module=="borrowers") { echo "Borrowers

    Borrowers

    "; } if ($module=="stopwords") { echo "Stopwords

    Stopwords

    "; } if ($module=="") { echo ""; echo "Research

    Search

    "; print "
    Any Keyword "; #
    Titre...... #
    Auteur..... #
    Subject.... #
    # print "
    print "
    "; } #quarantine #passthru('psql -c "select * from missing_barcodes order by call_number;" -H -d eduml',$asdf); page_close(); ?>