Search Bibliography";
/* construct the template filename */
$qry="select substr(templates,5) as templ_file from x_search where substr(templates,1,3)='SS:'";
db_vars($con,$qry);
$templ_file.="-search.tmpl";
/* clean browse letter */
$letter=strtoupper(substr(trim($letter),0,1));
if(strlen($letter)<1){
$letter="A";
$QUERY_STRING="letter=A";
}
/* result string start */
$result="";
/* check for table containing list of journal browse letters */
$qry="select tablename as chktable from pg_tables ";
$qry.="where tablename='jour_browse_letters'";
$chktable="";
db_vars($con,$qry);
if(strlen($chktable) < 1 ){
// create browse letter table
$qry = "create table jour_browse_letters ( letter varchar )";
pg_exec($con,$qry);
$qry = "insert into jour_browse_letters select distinct ";
$qry.= "trim(substr(upper(secondarytitle),1,1)) as letter ";
$qry.= "from pubresource ";
$qry.= "where trim(substr(upper(secondarytitle),1,1)) >= 'A' and ";
$qry.= "(upper(type)='ARTICLE' or upper(type)='JOURNAL ARTICLE') ";
$qry.= "and trim(upper(secondarytitle)) not like 'THE %' ";
pg_exec($con,$qry);
// deal with all secondarytitles that do start with 'THE '
$qry = "insert into jour_browse_letters select distinct ";
$qry.= "trim(substr(upper(secondarytitle),4,1)) as letter ";
$qry.= "from pubresource ";
$qry.= "where trim(substr(upper(secondarytitle),4,1)) >= 'A' and ";
$qry.= "(upper(type)='ARTICLE' or upper(type)='JOURNAL ARTICLE') ";
$qry.= "and trim(substr(upper(secondarytitle),4,1)) not in ( ";
$qry.= "select letter from jour_browse_letters ) and ";
$qry.= "upper(secondarytitle) like 'THE %' ";
pg_exec($con,$qry);
}
$qry = "select letter as jour_letters from jour_browse_letters";
db_vars($con,$qry,1);
$lt_str= buildBrowse($journals_link, $jour_letters);
$result.="
";
/* get resources for this letter */
/* by journal - with date range and citation count */
$qry="select distinct secondarytitle as the_journal, min(x_year) as start_date, ";
$qry.="max(x_year) as end_date, count(secondarytitle) as the_count ";
$qry.="from pubresource where ";
$qry.="( ('$letter' != 'T' and ( UPPER(secondarytitle) like '$letter%' ";
$qry.="or UPPER(secondarytitle) like 'THE $letter%' )) or ";
$qry.="('$letter' = 'T' and (UPPER(secondarytitle) like 'THE T%' or ";
$qry.="(UPPER(secondarytitle) like 'T%' and ";
$qry.=" UPPER(secondarytitle) not like 'THE %')))) ";
$qry.="and (upper(type)='ARTICLE' or upper(type)='JOURNAL ARTICLE'";
$qry.=") group by secondarytitle having count(secondarytitle) > 0 ";
$qry.="order by secondarytitle asc;";
$res=pg_exec($con,$qry);
$numrows=pg_numrows($res);
// check if there are any journals for this letter
if($numrows<1){
$result.="";
$result.="There were no journals found begining with '$letter'";
$result.=" |
";
}
$order_ary = array();
for($i=0;$i<$numrows;$i++){
$tmpstr="";
$bgcol=($i%2)?"class=\"altcolour\"":"";
$row=pg_fetch_array($res,$i);
$journal_name=$row['the_journal'];
$name_key = strtoupper($journal_name);
if(!strcmp(substr($name_key,0,4),"THE ")){
$name_key=substr($name_key,4);
}
$journal_stats=$row['the_count']." citation";
if($row['the_count']>1)$journal_stats.="s";
$journal_stats.="; ".$row['start_date'];
if(strcmp($row['start_date'],$row['end_date'])){
$journal_stats.=" - ".$row['end_date'];
}
$canned_search=$canned_link."?sectitletext=".urlencode($row['the_journal']);
$canned_search.="§itletype=exact&typetext=+&dir=Ascending&page=0&dosearch=1";
$canned_search.="&subval=Refine+Search&subele=Search&order=Author&perpg=10";
$order_ary[$name_key] = array();
$order_ary[$name_key][0] = $journal_name;
$order_ary[$name_key][1] = $canned_search;
$order_ary[$name_key][2] = $journal_stats;
}
/* sort jour_ary and add to output */
ksort($order_ary);
$i=0;
for(reset($order_ary);$cur = each($order_ary);){
$bgcol=($i%2)?"class=\"altcolour\"":"";
$tmp = $cur['value'];
$result.="";
$result.=$tmp[0];
$result.=" | ";
$result.="(".$tmp[2].")";
$result.=" |
\n";
$i=$i+1;
}
/* add browse letters at bottom of page for more than 20 items */
$big_res_a="\n\n";
if($numrows > 20){
$big_res_a="";
$big_res_b="";
}
$result.="
";
/* construct heading */
$page_title="Browse Bibliography (by Journal) - $letter";
$page_heading="Bibliography";
/* set the citable url for this page */
$tmp_url = "http://".$SERVER_NAME.$PHP_SELF;
if(strlen($QUERY_STRING)>0)$tmp_url.="?".$QUERY_STRING;
$url=wrap_url($tmp_url, 80);
/* fill out and display template file */
/* open template file */
$fd=fopen($templ_file,'r');
if($fd){
/* read the entire template into memory */
$template=fread($fd,filesize($templ_file));
/* close the template file */
fclose($fd);
/* output template to client substituting
* the template variables
* $RESULT - the search result table
* $URL - citable url for this page
* $TITLE - page title
*/
$template = eregi_replace("[$]+submenu([^a-z])",$lt_str."\\1",$template);
$template = eregi_replace("[$]+newsearch([^a-z])",$search_href."\\1",$template);
$template = eregi_replace("[$]+heading([^a-z])",$page_heading."\\1",$template);
$template = eregi_replace("[$]+refine([^a-z])"," "."\\1",$template);
$template = eregi_replace("[$]+pages_bottom([^a-z])",""."\\1",$template);
$template = eregi_replace("[$]+pages([^a-z])",""."\\1",$template);
$template = eregi_replace("[$]+resultstatement_bottom([^a-z])",""."\\1",$template);
$template = eregi_replace("[$]+resultstatement([^a-z])",""."\\1",$template);
$template = eregi_replace("[$]+result([^a-z])",$result."\\1",$template);
$template = eregi_replace("[$]+url([^a-z])",$url."\\1",$template);
$template = eregi_replace("[$]+title([^a-z])",$page_title."\\1",$template);
$template = stripslashes($template);
/* send the results page to client */
echo $template;
}
else{
/* Could not open template file
*/
echo "Could not find template file $templ_file";
exit;
}
?>