<?
    
if($_REQUEST['submit']=='Update Person') {
        
        
import_request_variables("p");

        
$update_values='';
        
        
$update_values .= "age = ".( $age != '' "'$age', " "NULL, ");
        
$update_values .= "birth = ".( $birth != '' "'$birth', " "NULL, ");
        
$update_values .= "death = ".( $death != '' "'$death', " "NULL, ");
        
$update_values .= "father = ".( $father != '' "'$father', " "NULL, ");
        
$update_values .= "mother = ".( $mother != '' "'$mother', " "NULL, ");
        
$update_values .= "husband = ".( $husband != '' "'$husband', " "NULL, ");
        
$update_values .= "tribe = ".( $tribe != '' "'$tribe', " "NULL, ");
        
$update_values .= "prophet = ".($prophet == '' $prophet=='f' "'f', " "'t', ");
        
$update_values .= "translation = ".( $translation != '' "'".trim($translation)."', " "NULL, ");
                                
        
$update_sql="UPDATE tl_people SET name = '$name', $update_values sex = '$sex'  WHERE id = $people_id";
        
// echo $update_sql;
        
mysql_query($update_sql) or die(mysql_error());
        
header("Location: people.php?people_id=$people_id");

        
    }
    
    elseif(
$_REQUEST['submit']=='Add Person') {
        
import_request_variables("p");
        
$insert_values='';
        
$insert_fields='';

        
$name=trim($name);

        if(
$translation!='') {
            
$insert_fields.="translation, ";
            
$insert_values.="'".trim($translation)."', ";
        }

        if(
$age!='') {
            
$insert_fields.="age, ";
            
$insert_values.="'$age', ";
        }
        
        if(
$birth!='') {
            
$insert_fields.="birth, ";
            
$insert_values.="'$birth', ";
        }
        
        if(
$death!='') {
            
$insert_fields.="death, ";
            
$insert_values.="'$death', ";
        }
                
        if(
$father!='') {
            
$insert_fields.="father, ";
            
$insert_values.="$father, ";
        }

        if(
$mother!='') {
            
$insert_fields.="mother, ";
            
$insert_values.="$mother,";
        }

        if(
$husband!='') {
            
$insert_fields.="husband, ";
            
$insert_values.="$husband, ";
        }

        if(
$tribe!='') {
            
$insert_fields.="tribe, ";
            
$insert_values.="'$tribe', ";
        }
        
        if(
$prophet!='') {
            
$insert_fields.="prophet, ";
            
$insert_values.="'$prophet', ";
        }
        
        
$insert_sql="INSERT INTO tl_people (name, $insert_fields sex) VALUES ('$name', $insert_values '$sex')";
        
mysql_query($insert_sql) or die(mysql_error());

        
header ("Location: people.php?people_id=".mysql_insert_id());

    }

    elseif(
$_REQUEST['submit']=='Add New Reference') {
        
import_request_variables("p");

        if(!
$verse)
            
$verse='null';
        
        if(!
$chapter_end && !$verse_end)
            
$chapter_end='null';
        elseif(!
$chapter_end && $verse_end)
            
$chapter_end=$chapter;
    
        if(!
$verse_end)
            
$verse_end='null';
            
        if(!
$jst)
            
$jst='f';
        
        
$insert_sql="INSERT INTO tl_references (ref_type, ref_id, book, chapter, chapter_end, verse, verse_end, jst) VALUES ('person', $ref_id, $book, $chapter, $chapter_end, $verse, $verse_end, '$jst')";
        
// echo $insert_sql;
        
mysql_query($insert_sql) or die(mysql_error());
        
header ("Location: people.php?people_id=".$ref_id."&book=".$book);
    }
?>