Infused Solutions » phpGene » Genealogy Functions

<?php
  
function get_name($indiv) {
    
$query "SELECT givenname as gname, surname as sname, aka ,sex, notekey
              FROM gen_indiv
              WHERE gen_indiv.indkey = \"$indiv\""
;
    
$result mysql_query($query);
    
$row mysql_fetch_array($result);
    
$facts = array("indkey"=>$indiv
                   
"gname"=>$row["gname"], 
                   
"sname"=>$row["sname"], 
                   
"aka"=>$row["aka"], 
                   
"sex"=>$row["sex"], 
                   
"notekey"=>$row["notekey"]);
    return 
$facts;
  }
    
  function 
get_sources($factkey) {
    
$sources = array();
    
$query =  "SELECT * FROM gen_citation WHERE factkey=\"$factkey\"";
    
$result mysql_query($query);
    while (
$row mysql_fetch_array($result)) {
      
$srckey $row["srckey"];
      
$srccitation $row["source"];
      
$query2 =  "SELECT * FROM gen_source WHERE srckey=\"$srckey\"";
      
$result2 mysql_query($query2);
      
$row2 mysql_fetch_array($result2);
      
$msrc $row2["text"];
      
$source $msrc."<br>".$srccitation;
      
array_push($sources,$source);
    }
    return 
$sources;
  }
    
  function 
get_events($indfamkey) {
    
$facts = array();
    
$query =  "SELECT type, date, place, factkey 
               FROM gen_facts 
               WHERE (indfamkey = \"$indfamkey\" 
               AND type!=\"Birth\") 
               AND (indfamkey = \"$indfamkey\" 
               AND type!=\"Death\")"
;
    
$result mysql_query($query);
    
$count mysql_num_rows($result);
    for (
$i 0$i $count$i++) {
      
$row mysql_fetch_array($result);
      
$type $row["type"];
      
$date ucwords(strtolower($row["date"]));
      
$place $row["place"];
      
$factkey $row["factkey"];
      
$facts[$i] = array("type"=>$type,"date"=>$date,"place"=>$place,"factkey"=>$factkey);
    }
    return 
$facts;
  }
    
  function 
get_vitals($indfamkey) {
    
$facts = array();
    
$query =  "SELECT type, date, place, factkey FROM gen_facts WHERE indfamkey = \"$indfamkey\"";
    
$result mysql_query($query);
    while (
$row mysql_fetch_array($result)) {
      if (
$row["type"] == "Birth") {
        if (!
$birthset) {
          
$facts["birth"] = ucwords(strtolower($row["date"]));
          
$facts["birthplace"] = $row["place"];
          
$facts["birthfactkey"] = $row["factkey"];
          
$birthset 1;
        }
      }
      else if (
$row["type"] == "Death") {
        if (!
$deathset) {
          
$facts["death"] = ucwords(strtolower($row["date"]));
          
$facts["deathplace"] = $row["place"];
          
$facts["deathfactkey"] = $row["factkey"];
          
$deathset 1;
        }
      }
    }
    return 
$facts;
  }
    
  function 
get_marriage($indfamkey) {
    
$facts = array();
    
$query =  "SELECT date, place, factkey 
               FROM gen_facts 
               WHERE indfamkey = \"$indfamkey\" 
               AND type = \"Marriage\" 
               LIMIT 1"
;
    
$result mysql_query($query);
    
$row mysql_fetch_array($result);
    
$facts["marriage"] = ucwords(strtolower($row["date"]));
    
$facts["marriageplace"] = $row["place"];
    
$facts["marriagefactkey"] = $row["factkey"];
    return 
$facts;
  }
    
  function 
get_parents($indiv) {
    
$query "SELECT spouse1, spouse2    
              FROM gen_family, gen_relation
              WHERE gen_relation.indkey = \"$indiv\" 
              AND gen_family.famkey = gen_relation.famkey"
;
    
$result mysql_query($query);
    
$row mysql_fetch_array($result);
    
$parents = array("father"=>$row["spouse1"], "mother"=>$row["spouse2"]);
    return 
$parents;
  }
    
  function 
get_wives($indiv) {
    
$wives = array();
    
$query "SELECT famkey, spouse2 as wife, endstatus, notekey FROM gen_family WHERE spouse1 = \"$indiv\"";
    
$result mysql_query($query);
    while (
$row mysql_fetch_array($result)) {
      
$wife = array("famkey"=>$row["famkey"],
                    
"indkey"=>$row["wife"],
                    
"endstatus"=>$row["endstatus"],
                    
"notekey"=>$row["notekey"]);
      
array_push($wives$wife);
    }
    return 
$wives;
  }
    
  function 
get_husbands($indiv) {
    
$husbands = array();
    
$query "SELECT famkey, spouse1 as husband, endstatus, notekey 
              FROM gen_family WHERE spouse2 = \"$indiv\""
;
    
$result mysql_query($query);
    while (
$row mysql_fetch_array($result)) {
      
$husband = array("famkey"=>$row["famkey"],
                       
"indkey"=>$row["husband"],
                       
"endstatus"=>$row["endstatus"],
                       
"notekey"=>$row["notekey"]);
      
array_push($husbands$husband);
    }
    return 
$husbands;
  }
    
  function 
get_children($famkey) {
    
$children = array();
    
$query "SELECT indkey FROM gen_relation WHERE famkey = \"$famkey\"";
    
$result mysql_query($query);
    
$count mysql_num_rows($result);
    for (
$i 0$i $count$i++) {
      
$row mysql_fetch_array($result);
      
$children[$i] = $row["indkey"];
    }
    return 
$children;
  }
    
  function 
get_notes($notekey) {
    
$query "SELECT text FROM gen_notes WHERE notekey = \"$notekey\"";
    
$result mysql_query($query);
    
$row mysql_fetch_array($result);
    
$notes $row["text"];
    return 
$notes;
  }
    
  function 
get_images($indkey) {
    
$query "SELECT filename,title,caption,pbase_link 
              FROM gen_images 
              WHERE indfamkey = \"$indkey\" 
              ORDER BY sort_order"
;
    
$result mysql_query($query);
    
$count mysql_num_rows($result);
    if (
$count 1) { 
      return 
$count;
    }
    else { 
      
$images = array();
      for (
$i 0$i $count$i++) {
        
$row mysql_fetch_array($result);
        
$filename $row["filename"];
        
$title $row["title"];
        
$caption $row["caption"];
        
$pbase_link $row["pbase_link"];
        
$images[$i] = array("filename"=>$filename,
                            
"title"=>$title,
                            
"caption"=>$caption,
                            
"pbase_link"=>$pbase_link);
      }
      return 
$images;
    }
  }
?>

© 1999-2003 Keith Morrison, Infused Solutions