%Title%, %Authors%\n"); * echo $recentpubs * ?> * * Or, if you only want to display certain results (This example displays all, but is easily adapted): * * %Title%, %Authors%\n"); * for($i = 0; $i < $recentpubs->size; $i++) * echo $recentpubs->getFormattedRow($i); * ?> */ class Result { var $rows; var $error; var $parse; var $sql; // Pre-configured for AI-Lab var $host = "localhost"; var $user = "onue5"; var $pass = ""; var $db = "aidb"; var $IR = 0; function __toString() { return $this->toString(); } function toString() { $str = ""; if(count($this->error)==0) { for($c = 0;$c < count($this->rows); $c++) { $str .= $this->getFormattedRow($c); } } else { for($c = 0;$c < count($this->error); $c++) { $str .= $this->error[$c]; } } return $str; } function getFormattedRow($row) { $str = $this->parse; foreach($this->rows[$row] as $key => $value) { $str = str_replace("%$key%",$value,$str); } return $str; } function query() { $this->rows = array(); $this->size = 0; $this->error = array(); if(!$IR) $this->openDatabase($this->host,$this->user,$this->pass,$this->db); $result = mysqli_query($this->IR,$this->sql); if(!$result) { $this->error[] = mysqli_error($this->IR); } else while($row = mysqli_fetch_assoc($result)) { $this->rows[] = $row; } if($result) mysqli_free_result($result); } function Result($sql,$parse) { $this->sql = $sql; $this->parse = $parse; $this->query(); } function openDatabase($host,$user,$pass,$db) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; $this->IR = mysqli_connect($this->host, $this->user, $this->pass, $this->db) or die(mysqli_error($IR)); } function isValid() { if(count($error)==0) return true; else return false; } function getSize() { return count($this->rows); } } // This is a freakin' useful function to cleverly display links to authors of a publication. function print_publications($result) { echo "
\n"; for($c = 0;$c < $result->getSize(); $c++) { echo $result->getFormattedRow($c); echo "
\n"; print_authors($result->rows[$c]); echo "
\n"; } echo "
\n"; } function array_empty($array) { foreach($array as $key => $value) { if($value === false or !is_string($value) or strlen($value)<2) unset($array[$key]); } return $array; } function print_authors($pub) { // Turn "and"s into commas $pub['Authors'] = str_replace(" and",",",$pub['Authors']); $pub['Authors_Ext'] = str_replace(" and",",",$pub['Authors_Ext']); // Get array of author list(s) $authors = explode(",",$pub['Authors']); $ext = explode(",",$pub['Authors_Ext']); // <-- I regret introducing this field // Remove intersection foreach($ext as $keyx => $authorx) { $lastname = strrpos($authorx," "); if(!$lastname) $lastname = strrpos($authorx,"."); $lastname = substr($authorx,$lastname+1,strlen($authorx)); foreach($authors as $key => $author) { $authorx = trim($authorx); $author = trim($author); if($authorx == $author or strstr($author,$lastname)) { $authors[$key] = $ext[$keyx]; unset($ext[$keyx]); } } } $authors = array_merge($authors,$ext); $authors = array_empty($authors); // Decorate authors who appear in the database $result = new Result("select people.Firstname,people.Lastname,people.PID from people"); foreach($authors as $key => $author) { if(strlen($author) < 2 or !$author) unset($authors[$key]); $author = trim($author); $author = explode(" ",$author); $best_match = Array(); foreach($result->rows as $entry) { if($entry['Lastname'] == $author[sizeof($author)-1] or $entry['Firstname'] == $author[0]) { if(empty($best_match)) $best_match = $entry; if($entry['Lastname'] == $author[sizeof($author)-1] and $entry['Firstname'] == $author[0]) $best_match = $entry; } } if(!empty($best_match) && $author[0][0] == $best_match['Firstname'][0]) { $author = "{$best_match['Firstname']} {$best_match['Lastname']}"; if(is_array($author)) $author = implode(" ",$author); $authors[$key] = $author; } } echo implode(", ",$authors); } /* function print_authors($pub) { $result = new Result("select relppub.PID,relppub.PubID,people.Firstname,people.Lastname,people.PID from relppub,people where people.PID = relppub.PID and PubID = {$pub['PubID']} order by people.Lastname"," %Firstname% %Lastname%, "); $str = substr($result->toString(),0,strlen($result->toString())-2); echo $str; if($pub['Authors_Ext']) echo " -- {$pub['Authors_Ext']}"; echo "
-
\n"; $str = $pub['Authors']; $str = str_replace(" and",",",$str); echo $str; if($pub['Authors_Ext']) echo " -- {$pub['Authors_Ext']}"; }*/ // Old, deprecated by relational author lists /* function print_authors($authors) { $authors = split(",|and ",$authors); for($author_c =0; $author_c < count($authors); $author_c++) { $tmp = split(" ",trim($authors[$author_c])); $first = $tmp[0]; if(count($tmp)>1) $last = $tmp[count($tmp)-1]; else $last = ""; $s_first = $first; if(strpos($first,".")>0) $s_first = $first[0]; $id_result = new Result("select PID from people where (Firstname = '$first' and Lastname = '$last') or (Firstname like '$s_first%' and Lastname = '$last')","%PID%"); $start = ""; $end = ""; if($id_result->rows[0]) { $start = "\trows[0]['PID']}\">"; $end = ""; } echo "$start{$tmp[0]} $last$end"; if($author_c1 ) echo " and\n"; } }*/ // For searching, call this function on $_POST or $_GET (or, for that matter, on $_REQUEST) for security. function slash($array) { for($c = 0; $c < count($array); $c++) { $array[$c] = mysql_real_escape_string($array[$c]); } return $array; } // Don't display email directly, instead, call safe_email($email). // Changes dna@cs.utexas.edu => dna [at] cs utexas edu // People will love you function safe_email($email) { $email = str_replace("@"," [at] ",$email); $email = str_replace("."," ",$email); return $email; } // Below here are a few example helper functions. // BEGIN_AUTO_DOC_FUNCTIONS function getPublicationsByName($lastname,$firstname,$format) { $result = new Result("Select * from people,pubs,relppub where pubs.PubID = relppub.PubID and relppub.PID = people.PID and people.Firstname = \"$firstname\" and people.Lastname = \"$lastname\" and people.Archived = 0",$format); echo $result; } function getPublicationsByEmail($email,$format) { $result = new Result("Select * from people,pubs,relppub where pubs.PubID = relppub.PubID and relppub.PID = people.PID and people.Email = \"$email\" and people.Archived = 0",$format); echo $result; } function getPublicationsByYear($year,$compare,$format) { $result = new Result("Select * from pubs where pubs.Year $compare $year and pubs.Archive = 0",$format); echo $result; } function getPublicationsByLab($lab,$format) { $result = new Result("Select * from labs,relpublab,pubs where pubs.PubID = relpublab.pubID and relpublab.labID = labs.LabID and labs.name = \"$lab\" and labs.archive = 0 and pubs.Archive = 0",$format); echo $result; } function getPublicationsByLabID($labid,$format) { $result = new Result("Select * from labs,relpublab,pubs where pubs.PubID = relpublab.pubID and relpublab.labID = $labid and labs.LabID = $labid and labs.archive = 0 and pubs.Archive = 0",$format); echo $result; } function getPublicationsByArea($area,$format) { $result = new Result("Select * from areas,relpubarea,pubs where pubs.PubID = relpubarea.pubID and relpubarea.AreaID = areas.AreaID and areas.AreaName = \"$area\" and pubs.Archive = 0 order by PubTimestamp",$format); echo $result; } function getPublicationsByAreaID($areaid,$format) { $result = new Result("Select * from areas,relpubarea,pubs where pubs.PubID = relpubarea.pubID and relpubarea.AreaID = $areaid and areas.AreaID = $areaid and pubs.Archive = 0 order by PubTimestamp",$format); echo $result; } function getPeopleByLab($lab,$format) { $result = new Result("Select * from people,relplab,labs where people.PID = relplab.PID and relplab.LabID = labs.LabID and labs.name = \"$lab\" abd people.Archived = 0 and labs.archive = 0",$format); echo $result; } function getPeopleByLabID($labid,$format) { $result = new Result("Select * from people,relplab,labs where people.PID = relplab.PID and relplab.LabID = labs.LabID and labs.LabID = $labid and people.Archived = 0 and labs.archive = 0",$format); echo $result; } function getPeopleByProjectID($projid,$format) { $result = new Result("Select * from people,relpproj,projects where people.PID = relpproj.PID and relpproj.ProjID = projects.ProjID and projects.ProjID = $projid and people.Archived = 0 and projects.Archive = 0",$format); echo $result; } function getPeopleByTitle($title,$format) { $result = new Result("Select * from people where people.title = \"$title\" and people.Archived = 0",$format); echo $result; } function getProjectsByLab($lab,$format) { $result = new Result("Select * from labs,relprojlab,projects where labs.LabID = relprojlab.LabID and relprojlab.ProjID = projects.ProjID and labs.name = \"$lab\" and projects.Archive = 0 and labs.archive = 0",$format); echo $result; } function getProjectsByArea($area,$format) { $result = new Result("Select * from areas,relprojarea,projects where areas.AreaID = relprojarea.AreaID and relprojarea.ProjID = projects.ProjID and areas.AreaName = \"$area\" and projects.Archive = 0",$format); echo $result; } function getProjectsByAreaID($areaid,$format) { $result = new Result("Select * from areas,relprojarea,projects where areas.AreaID = relprojarea.AreaID and relprojarea.ProjID = projects.ProjID and areas.AreaID = $areaid and projects.Archive = 0",$format); echo $result; } ?>