Location: PHPKode > projects > Generic Genetic Studies Database > ggsd-2.19/cgi-bin/edit_record.php
<?php

#Copyright 2008 Aaron Day-Williams <hide@address.com>
#
#This file is part of Generic Genetic Studies Database (GGSD).
#
#GGSD is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#GGSD is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with GGSD.  If not, see <http://www.gnu.org/licenses/>.


header('Content-type: text/html');
session_cache_limiter('private');
session_start();
require 'sql_lib.inc';
require 'html_lib.inc';
require 'file_system_lib.inc';
$access_type_required = 'administrative';

#NAME	edit_record.php

#TYPE	PHP

#USES	sql_lib.inc(authenticate updateRecord tableQuery)
#	html_lib.inc(??)

#PURPOSE To give the user a form to edit or update any record in the database.

#USAGE	edit_record.php

#PARAMETERS
#	authorized user	auth_user	int	optional
#	table name	table_name	string	optional
#	individual id	indiv_id	int	optional
#	pedigree id	ped_id		int	optional
#	indiv table id	indiv_table_id	int	optional
#	gentoype id	gentotype_id	int	optional
#	marker id	marker_id	int	optional
#	gene id		gene_id		int	optional
#	allele id	allele_id	int	optional
#	phenotype id	phenotype_id	int	optional
#	pheno value id	pheno_value_id	int	optional
#	marker name	marker_name	string	optional
#	gene name	gene_name	string	optional
#	phenotype name	pheno_name	string	optional
#	allele code	allele_code	int	optional

#RETURNS
#	success message				if success
#	error message				if error

#DATASTRUCTURES No special datastructures

#FUNCTIONAL DESCRIPTION The script will get the args.  Then determine what type
#		       of record is to be updated.  Then determine which record of the
#		       selected type the user wants to update. Then print a table specific
#		       form to allow the user to update non-key fields of that record.  The
#		       script will then see what fields have been changed, and
#		       update those fields.

#ASSUMPTIONS  The user only wants to update fields using a web form, and not a file upload

#LIMITATIONS  The user can not store data in a file, upload the file, and update the database
#	     from the contents of the file.

#COMMENTS

#PRELIMINARY DESIGN
#	    1	Authenticate User
#	    2	Get Args
#	    3	Determine What Type of Record Updating
#	    4	Determine Which record Updating
#	    5	Print Table Specific Update Form for Record
#	    6	Determine if anything changed and update




echo "<html>\n";
echo " <head>\n";
if (isset($_POST['end_session'])){echo "  <META HTTP-EQUIV=Refresh CONTENT=\"$logout_refresh_time;URL=../right.html\">\n";}
else                             {echo "  <META HTTP-EQUIV=Refresh CONTENT=\"$normal_refresh_time; URL=$_SERVER[SCRIPT_NAME]\">\n";}
echo "  <title>Update Record</title>\n";
echo " </head>\n";
echo "<body bgcolor=\"white\">\n";
echo "<center><h3>Update Record</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo "<br>\n";



$ret_val = connect();
if ($ret_val != '1')
  {
    $date = date('Y-m-d H:i:s');
    echo "Error #1: $date<br>\n";
    echo "Error in call to connect from edit_record.php<br>\n";
    echo "$ret_val<br><br>\n";
    echo "Please email the above error using the Comments/Help/Support link \n";
    echo "in the left navigation bar.<br>\n";
    echo "</body></html>\n";
    exit;
  }


#1     Authenticate User
if (isset($_POST['end_session']))#if want to end session
  {
    #if (key_exists('files_on_server',$_SESSION))
    #  {
    #    $files_to_delete_array = $_SESSION['files_on_server'];
    #    $ret_val = deleteFiles($files_to_delete_array);
    #    if ($ret_val != '1')
    #      {
    #        $date = date('Y-m-d H:i:s');
    #        echo "Error #2: $date<br>\n";
    #        echo "Error in call to deleteFiles from edit_record.php<br>\n";
    #        echo "$ret_val<br><br>\n";
    #        echo "Please email the above error using Comments/Help/Support link \n";
#	    echo "in the left navigation bar.<br>\n";
#	    echo "</body></html>\n";
#	    session_unset();
#	    session_destroy();
#	    $ret_val = disconnect();
#	    exit;
#	  }#end error in call to deleteFiles
#      }#end if files that need to be deleted

    if (is_dir("../data/download_data/$_SESSION[user_name]"))
      {
        $ret_val = deleteExpiredFiles($_SESSION['user_name']);
        if ($ret_val != '1')
          {
            $date = date('Y-m-d H:i:s');
            echo "Error #3: $date<br>\n";
            echo "Error in call to deleteExpiredFiles from edit_record.php<br>\n";
            echo "$ret_val<br><br>\n";
            echo "Please email the above error using Comments/Help/Support link \n";
	    echo "in the left navigation bar.<br>\n";
	    echo "</body></html>\n";
	    session_unset();
	    session_destroy();
	    $ret_val = disconnect();
	    exit;
	  }#end error in call to deleteExpiredFiles
      }#end if user has own directory in download_data directory
    session_unset();
    session_destroy();
    echo "You have successfully logged out of the system.<br>\n";
    #echo "To log back in click on any of the links on the left navigation bar.<br>\n";
    $ret_val = disconnect();
    exit;
  }#end if want to end session
else#don't want to end session
  {
    if ((!session_is_registered('user_name')) and (!session_is_registered('user_passwd')))
      {
	if ((!preg_match('/\w+/',$_POST['user_name'])) and (!preg_match('/\w+/',$_POST['user_passwd'])))
	  {
	    $ret_val = printLoginPage('edit_record.php');
            if ($ret_val != '1')
              {
                $date = date('Y-m-d H:i:s');
		echo "Error #4: $date<br>\n";
		echo "Error in call to printLoginPage from edit_record.php<br>\n";
		echo "$ret_val<br><br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }#end if error in call to printLoginPage
	  }#end if haven't started a session yet
        else #have started a session
	  {
	    $auth_user = authenticate($_POST['user_name'],$_POST['user_passwd'],$_POST['rand'],$access_type_required,$_POST['database_id']);
	    if (($auth_user != '1') and ($auth_user != '0'))
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #5: $date<br>\n";
		echo "Error in call to authenticate from edit_record.php<br>\n";
		echo "$auth_user<br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }
            if ($auth_user == '0')
	      {
		echo "You are not an authorized user of this website!!<br><br>\n";
		echo "You must be an authorized user to access the data contained in this site.\n";
		echo "If you feel like you should be an authorized user, or want to see if you can\n";
		echo "become an authorized user please contact $contact_person at \n";
                echo "<a href=\"mailto:$contact_email\">$contact_email</a>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }
            if ($auth_user == '1')
	      {
		$_SESSION['user_name']   = $_POST['user_name'];
		$_SESSION['user_passwd'] = $_POST['user_passwd'];
                $_SESSION['database_id'] = $_POST['database_id'];
		$_SESSION['rand']        = $_POST['rand'];
                $_SESSION['entry_time']  = time();
		session_write_close();
	      }
	  }#end else have user name an passwd
      }#end if session variables not registered
    else #session variable are registered
      {
        if ((time() - $_SESSION['entry_time']) > $session_expiration_time)#if session has expired
          {
            if (key_exists('files_on_server',$_SESSION))
              {
                $files_to_delete_array = $_SESSION['files_on_server'];
                $ret_val = deleteFiles($files_to_delete_array);
                if ($ret_val != 1)
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #6: $date<br>\n";
                    echo "Error in call to deleteFiles from edit_record.php<br>\n";
                    echo "$ret_val<br><br>\n";
                    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
                    session_unset();
                    session_destroy();
                    $ret_val = disconnect();
                    exit;
                  }#end if error in call to deleteFiles
              }#end if files that need to be deleted

            if (is_dir("../data/download_data/$_SESSION[user_name]"))
              {
                $ret_val = deleteExpiredFiles($_SESSION['user_name']);
                if ($ret_val != 1)
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #7: $date<br>\n";
                    echo "Error in call to deleteExpiredFiles from edit_record.php<br>\n";
                    echo "$ret_val<br><br>\n";
                    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
                    session_unset();
                    session_destroy();
                    $ret_val = disconnect();
                    exit;
                  }#end if error in call to deleteExpiredFiles
              }#end if user has a data directory
            session_unset();
            session_destroy();

            echo "<b>Your Session has expired.  You must log back into the system.</b><br><br><br>\n";
            $ret_val = printLoginPage('edit_record.php');
            if ($ret_val != '1')
              {
                $date = date('Y-m-d H:i:s');
		echo "Error #8: $date<br>\n";
		echo "Error in call to printLoginPage from edit_record.php<br>\n";
		echo "$ret_val<br><br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }#end if error in call to printLoginPage
          }#end if session has expired 
        else #session hasn't expired
          {
	    if ((!session_is_registered('database_id')) and (!isset($_POST['database_id'])))
	      {
		$ret_val = printDatabaseSelectPage('edit_record.php');
		if ($ret_val != '1')
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #9: $date<br>\n";
		    echo "Error in call to printDatabaseSelectPage from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to printDatabaseSelectPage
	      }#end if the database id session variable isn't set and haven't selected
	    else #all the session variables are set
	      {
		$user_name   = $_SESSION['user_name'];
		$user_passwd = $_SESSION['user_passwd'];
		if (session_is_registered('database_id')){$database_id = $_SESSION['database_id'];}
		else #set database id session variable
		  {
		    $database_id = $_POST['database_id']; 
		    $_SESSION['database_id'] = $_POST['database_id'];
		  }#end else set database id session variable
		$rand        = $_SESSION['rand'];
		$_SESSION['entry_time'] = time();
		$auth_user = authenticate($user_name,$user_passwd,$rand,$access_type_required,$database_id);
		if (($auth_user != '1') and ($auth_user != '0'))
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #10: $date<br>\n";
		    echo "Error in call to authenticate from edit_record.php<br>\n";
		    echo "$auth_user<br>\n";
		    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }
		if ($auth_user == '0')
		  {
		    echo "You are not an authorized user of this website!!<br><br>\n";
		    echo "You must be an authorized user to access the data contained in this site.\n";
		    echo "If you feel like you should be an authorized user, or want to see if you can\n";
		    echo "become an authorized user please contact $contact_person \n";
		    echo "at <a href=\"mailto:$contact_email\">$contact_email</a>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }
	      }#end else all the session variables are set
          }#end else session hasn't expired
      }#end else registered values
  }#end else not ending session


#2     Get Args
$DEBUG = '0';
$table_name   = $_POST['table_name'];
$submit       = $_POST['submit'];
$search_terms = array();
if ($table_name == 'individual_table')
  {
    $individual_table_id = $_POST['individual_table_id'];
    $individual_id       = $_POST['individual_id'];#If from section 4, equal the individual table id; If from section 5, equal the individual id
    $pedigree_id         = $_POST['pedigree_id'];#If set from section 4, equal the pedigree table id; If from section 5, equal the pedigree id
    $pedigree_table_id   = $_POST['pedigree_table_id']; 
    $father_id           = $_POST['father_id'];
    $mother_id           = $_POST['mother_id'];
    $sex                 = $_POST['sex'];
    $position_in_family  = $_POST['position_in_family'];

    $field_list_array = array('affection_status_id');
    $status_rec_list  = tableQuery('affection_status_table',$_SESSION['database_id'],$field_list_array,'_','wildcard','all');
    if (!is_array($status_rec_list))
      {
        $date = date('Y-m-d H:i:s');
	echo "Error #11: $date<br>\n";
	echo "Error in call to tableQuery from edit_record.php<br>\n";
	echo "$status_rec_list<br><br>\n";
	echo "Please email the above error using the Comments/Help/Support link \n";
	echo "on the left navigation bar.\n";
	echo "</body></html>\n";
	$ret_val = disconnect();
	exit;
      }#end error in call to getFields
    foreach ($status_rec_list as $statu_rec)
      {
        $status_name = $status_rec['affection_status_name'];
        $field_name  = "$status_name"."_affection_status";
	$name = $field_name;
	$$name = $_POST[$name];
      }

    if ((preg_match('/\d+/',$pedigree_id)) and (preg_match('/\d+/',$individual_id)))
      {
	$search_terms[0] = $pedigree_id;
        $search_terms[1] = $individual_id;
      }
  }#end if table_name eq individual_table

if ($table_name == 'individual_group_table')
  {
    $individual_group_id          = $_POST['individual_group_id'];
    $individual_group_name        = $_POST['individual_group_name'];
    $individual_group_description = $_POST['individual_group_description'];

    if (preg_match('/\d+/',$individual_group_id))
      {
        $search_terms[0] = $individual_group_id;
      }
  }#end if table_name eq individual_group_table

if ($table_name == 'pedigree_table')
  {
    $pedigree_table_id = $_POST['pedigree_table_id'];
    $pedigree_id       = $_POST['pedigree_id'];#if set from section 4, equal the pedigree table id; If from section 5, equal the pedigree id
    $nationality       = $_POST['nationality'];
    $num_in_ped        = $_POST['number_in_pedigree'];

    $field_list_array = array('affection_status_id');
    $status_rec_list  = tableQuery('affection_status_table',$_SESSION['database_id'],$field_list_array,'_','wildcard','all');
    if (!is_array($status_rec_list))
      {
        $date = date('Y-m-d H:i:s');
	echo "Error #12: $date<br>\n";
	echo "Error in call to tableQuery from edit_record.php<br>\n";
	echo "$status_rec_list<br><br>\n";
	echo "Please email the above error using the Comments/Help/Support link \n";
	echo "on the left navigation bar.\n";
	echo "</body></html>\n";
	$ret_val = disconnect();
	exit;
      }#end error in call to getFields
    foreach ($status_rec_list as $status_rec)
      {
        $status_name = $status_rec['affection_status_name'];
        $field_name  = "number_".$status_name."_affected_in_pedigree";
	$name = $field_name;
	$$name = $_POST["$name"];
      }

    if ((preg_match('/\d+/',$pedigree_id)))
      {
	$search_terms[0] = $pedigree_id;
      }
  }#end if table_name eq pedigree_table

if ($table_name == 'pedigree_group_table')
  {
    $pedigree_group_id          = $_POST['pedigree_group_id'];
    $pedigree_group_name        = $_POST['pedigree_group_name'];
    $pedigree_group_description = $_POST['pedigree_group_description'];

    if (preg_match('/\d+/',$pedigree_group_id))
      {
        $search_terms[0] = $pedigree_group_id;
      }
  }#end if table_name eq pedigree_group_table

if ($table_name == 'affection_status_table')
  {
    $affection_status_id          = $_POST['status'];
    $affection_status_name        = $_POST['affection_status_name'];
    $affection_status_description = $_POST['affection_status_description'];

    if (preg_match('/\d+/',$affection_status_id))
      {
        $search_terms[0] = $affection_status_id;
      }
  }#end if table_name eq affection_status_table

if ($table_name == 'marker_table')
  {
    $chromosome_id = $_POST['chromosome_id'];
    $marker_id     = $_POST['marker_id'];
    $gene_id       = $_POST['gene_id'];
    $marker_name   = $_POST['marker_name'];
    $marker_type   = $_POST['marker_type'];
    $chr           = $_POST['chromosome'];
    $chr_pos       = $_POST['chromosome_position'];
    $genomic_pos   = $_POST['genomic_position'];
    $tag_snp       = $_POST['tag_snp'];
    $aa_change     = $_POST['amino_acid_change'];
    $num_alleles   = $_POST['number_of_alleles'];
    $hw_equil      = $_POST['hardy_weinburg_equilibrium'];
    if (preg_match('/\d+/',$marker_id))
      {
	$search_terms[0] = $marker_id;
      }
  }#end if table_name eq marker_table

if ($table_name == 'map_table')
  {
    $map_id             = $_POST['map_id'];
    $map_name           = $_POST['map_name'];
    $dist_measure       = $_POST['distance_measure'];
    $map_desc           = $_POST['map_description'];
    $marker_id          = $_POST['marker_id'];
    $marker_name        = $_POST['marker_name'];
    $map_marker_link_id = $_POST['map_marker_link_id'];
    $marker_num_in_map  = $_POST['marker_num_in_map'];
    $dist_prev_marker   = $_POST['distance_from_previous_marker'];
    $type_of_update     = $_POST['type_of_update'];

    if ((preg_match('/\d+/',$map_id)) and
        (preg_match('/\w+/',$type_of_update))
       )
      {
        if ($type_of_update == 'marker_info')
          {
            if (preg_match('/\d+/',$marker_id))
              {
                $search_terms[0] = $map_id;
                $search_terms[1] = $marker_id;
              }
          }#end if marker info update
        if ($type_of_update == 'map_info')
          {
            $search_terms[0] = $map_id;
          }#end if map info update
      }#end if have map id and type of update
  }#end if table_name eq map_table

if ($table_name == 'gene_table')
  {
    $chr_id      = $_POST['chromosome_id'];
    $gene_id     = $_POST['gene_id'];
    $gene_name   = $_POST['gene_name'];
    $chr         = $_POST['chromosome'];
    $gene_start  = $_POST['gene_start_position'];
    $gene_stop   = $_POST['gene_stop_position'];
    $num_exons   = $_POST['number_of_exons'];
    $num_introns = $_POST['number_of_introns'];
    $gene_desc   = $_POST['gene_description'];
    if (preg_match('/\d+/',$gene_id))
      {
	$search_terms[0] = $gene_id;
      }
  }#end if table_name eq gene_table

if ($table_name == 'genotype_table')
  {
    $genotype_id         = $_POST['genotype_id'];
    $individual_table_id = $_POST['individual_table_id'];
    $pedigree_table_id   = $_POST['pedigree_table_id'];
    $chromosome_id       = $_POST['chromosome_id'];
    $marker_id           = $_POST['marker_id'];
    $allele_1_id         = $_POST['allele_1_id'];
    $allele_2_id         = $_POST['allele_2_id'];
    $flagged             = $_POST['flagged'];
    $allele_1_code       = $_POST['allele_1_code'];
    $allele_2_code       = $_POST['allele_2_code'];
    $individual_id       = $_POST['individual_id']; #if set from section 4, is individual table id; If from section 5, is just individual id
    $pedigree_id         = $_POST['pedigree_id'];   #if set from section 4, id pedigree table id; If from section 5, is just pedigree id
    $marker_name         = $_POST['marker_name'];
    if ((preg_match('/\d+/',$pedigree_id)) and (preg_match('/\d+/',$individual_id)) and (preg_match('/\d+/',$marker_id)))
      {
	$search_terms[0] = $pedigree_id;
        $search_terms[1] = $individual_id;
	$search_terms[2] = $marker_id;
      }
  }#end if table_name eq genotype_table

if ($table_name == 'allele_table')
  {
    $allele_id     = $_POST['allele_id'];
    $marker_id     = $_POST['marker_id'];
    $chromosome_id = $_POST['chromosome_id'];
    $allele_code   = $_POST['allele_code'];
    $allele_size   = $_POST['allele_size'];
    $allele_seq    = $_POST['allele_sequence'];
    $allele_freq   = $_POST['allele_frequency'];
    $illumina_code = $_POST['allele_illumina_code'];
    $marker_name   = $_POST['marker_name'];
    if ((preg_match('/\d+/',$marker_id)) and (preg_match('/\w+/',$allele_id)))
      {
	$search_terms[0] = $marker_id;
	$search_terms[1] = $allele_id;
      }
  }#end if table_name eq allele_table

if ($table_name == 'phenotype_table')
  {
    $phenotype_id   = $_POST['phenotype_id'];
    $phenotype_name = $_POST['phenotype_name'];
    $phenotype_desc = $_POST['phenotype_description'];
    if (preg_match('/\d+/',$phenotype_id))
      {
	$search_terms[0] = $phenotype_id;
      }
  }#end if table_name eq phenotype_table

if ($table_name == 'phenotype_value_table')
  {
    $phenotype_value_id  = $_POST['phenotype_value_id'];
    $individual_table_id = $_POST['individual_table_id'];
    $phenotype_value     = $_POST['phenotype_value'];
    $individual_id       = $_POST['individual_id'];   #if set from section 4 of code, it is the individual table id
    $pedigree_id         = $_POST['pedigree_id'];     #if set from section 4 of code, it is the pedigree table id
    $phenotype_id        = $_POST['phenotype_id'];
    $type_of_phenotype   = $_POST['type_of_phenotype'];
    if ((preg_match('/\d+/',$pedigree_id)) and (preg_match('/\d+/',$individual_id)) and (preg_match('/\d+/',$phenotype_id)))
      {
	$search_terms[0] = $pedigree_id;
        $search_terms[1] = $individual_id;
	$search_terms[2] = $phenotype_id;
      }
  }#end if table_name eq phenotype_value_table

if ($table_name == 'age_group_table')
  {
    $age_group_id          = $_POST['age_group_id'];
    $age_group_min_age     = $_POST['age_group_min_age'];
    $age_group_max_age     = $_POST['age_group_max_age'];
    $age_group_nationality = $_POST['age_group_nationality'];
    if (preg_match('/\d+/',$age_group_id))
      {
	$search_term[0] = $age_group_id;
      }
  }#end if table_name eq age_group_table

if ($table_name == 'age_group_phenotype_percentile_link_table')
  {
    $age_group_phenotype_percentile_link_id           = $_POST['age_group_phenotype_percentile_link_id'];
    $age_group_id                                     = $_POST['age_group_id'];
    $phenotype_id                                     = $_POST['phenotype_id'];
    $age_group_phenotype_male_10th_percentile_value   = $_POST['age_group_phenotype_male_10th_percentile_value'];
    $age_group_phenotype_male_90th_percentile_value   = $_POST['age_group_phenotype_male_90th_percentile_value'];
    $age_group_phenotype_female_10th_percentile_value = $_POST['age_group_phenotype_female_10th_percentile_value'];
    $age_group_phenotype_female_90th_percentile_value = $_POST['age_group_phenotype_female_90th_percentile_value'];
    $age_group_min_age                                = $_POST['age_group_min_age'];
    $age_group_max_age                                = $_POST['age_group_max_age'];
    $age_group_nationality                            = $_POST['age_group_nationality'];
    $phenotype_name                                   = $_POST['phenotype_name'];
    if ((preg_match('/\d+/',$age_group_id)) and (preg_match('/\w+/',$phenotype_id)))
      {
	$search_term[0] = $age_group_id;
	$search_term[1] = $phenotype_id;
      }
  }#end if table_name == age_group_phenotype_percentile_link_table

if ($auth_user == '1')
  {
    $database_id = $_SESSION['database_id'];
    #3     Determine What Type of Record Updating
    if ((!preg_match('/\w+/',$table_name)) and
	(sizeof($search_terms) == '0'))
      {
	echo "<form action=\"edit_record.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
	echo "This form allows you to update an existing record in the pedigree, pedigree group, individual, individual group, gene, marker, map, \n";
	echo "allele, genotype, phenotype, phenotype value, age group, age group-phenotype percentile, or affection status tables.  \n";
        echo "You must know which record you want to update \n";
	echo "because this form does not support wildcard searches.  Please select the type of record you want to update \n";
	echo "below<br><br>\n";

	$jscript = printEditableTableSelectList();
	if ($jscript == '0')
	  {
            $date = date('Y-m-d H:i:s');
	    echo "Error #13: $date<br>\n";
	    echo "Error in call to printTableSelectList from edit_record.php<br>\n";
	    echo "See above error message from printTableSelectList for an explanation.<br><br>\n";
	    echo "Please email the above error using the Comments/Help/Support link \n";
	    echo "on the left navigation bar.\n";
	    echo "</form>\n";
	    echo "</body></html>\n";
	    $ret_val = disconnect();
	    exit;
	  }#end error in call to printTableSelectList
	echo "<br><br>\n";
        echo "<center>\n";
	echo "<input type=\"submit\" name=\"submit\" value=\"Select Record to Update\">\n";
	echo "<input type=\"reset\" name=\"reset\" value=\"Reset Selection\">\n";
	echo "</center>\n";
	echo "</form>\n";
        echo "<br><br>\n";

        $ret_val = printLogOutButton('edit_record.php');
        echo "\n\n";

	echo "<script>\n";
	echo "function Validate(form)\n";
        echo "$jscript\n";
	echo "</script>\n";
      }#end no table_name or search terms

    #4     Determine which record to update.
    if ((preg_match('/\w+/',$table_name)) and
	(sizeof($search_terms) == '0'))
      {
	echo "<form action=\"edit_record.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
	if ($table_name == 'pedigree_table')
	  {
	    echo "Please enter the Pedigree ID of the pedigree record you would like to update.<br><br>\n";
            echo "<table>\n";
	    echo "<tr><td>Pedigree ID:</td><td>\n";
            $jscript = printPedigreeSelectList($database_id);
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #14: $date<br>\n";
                echo "Error in call to printPedigreeSelectList from edit_record.php<br>\n";
                echo "See error message from printPedigreeSelectList above for an explanation.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to printPedigreeSelectList
            if ($jscript == 'no_defined_pedigrees')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }
            echo "</td></tr>\n";
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Pedigree Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Pedigree ID\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n\n";

            $ret_val = printLogOutButton('edit_record.php');
	    echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq pedigree_table

	if ($table_name == 'individual_table')
	  {
            if ((!preg_match('/\d+/',$pedigree_id)) and (!preg_match('/\d+/',$individual_id)))
              {
	        echo "Please select the Pedigree ID of the Individual whose record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Pedigree ID:</td><td>\n";
                $jscript = printPedigreeSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #15: $date<br>\n";
                    echo "Error in call to printPedigreeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printPedigreeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printPedigreeSelectList
                if ($jscript == 'no_defined_pedigrees')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no pedigrees in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Individual in This Pedigree to Update\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Pedigree ID\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";
	      
	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no pedigree_id and no individual id
            if ((preg_match('/\d+/',$pedigree_id)) and (!preg_match('/\d+/',$individual_id)))
              {
                $field_list_array = array('pedigree_table_id');
                $ped_rec_list     = tableQuery('pedigree_table',$database_id,$field_list_array,$pedigree_id,'equal','all');
                if (!is_array($ped_rec_list))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #16: $date<br>\n";
                    echo "Error in call to tableQuery from edit_record.php<br>\n";
                    echo "$ped_rec_list<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to tableQuery
                if (sizeof($ped_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The pedigree with pedigree table id $pedigree_id has been deleted from the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "Therefore there are no individuals in the database to update for that pedigree<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
                else
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #17: $date<br>\n";
                    echo "The user selected to update an individual with pedigree table id $pedigree_id,<br>\n";
                    echo "but when query the pedigree table with that id multiple records are returned.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in database data integrity

	        echo "Please select the Individual ID of the individual in Pedigree $ped_rec[pedigree_id] whose record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Individual ID:</td><td>\n";
                $jscript = printIndividualSelectList($database_id,$pedigree_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #18: $date<br>\n";
                    echo "Error in call to printIndividualSelectList from edit_record.php<br>\n";
                    echo "See the error message from printIndividualSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printIndividualSelectList
                if ($jscript == 'no_defined_individuals')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no individuals in database for pedigree
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"pedigree_id\" value=\"$pedigree_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Individual Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset ID\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";
	      
	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if pedigree_id and no individual id
	  }#end if table_name eq individual_table

        if ($table_name == 'pedigree_group_table')
          {
            echo "Please select the Pedigree Group Name of the pedigree group record you would like to update.<br><br>\n";
            echo "<table>\n";
            echo "<tr><td>Pedigree Group Name:</td><td>\n";
            $jscript = printPedigreeGroupSelectList($database_id);
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #19: $date<br>\n";
                echo "Error in call to printPedigreeGroupSelectList from edit_record.php<br>\n";
                echo "See the error message from printPedigreeGroupSelectList above for an explanation.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call printPedigreeGroupSelectList
            if ($jscript == 'no_defined_pedigree_groups')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end if no pedigree groups in database
            echo "</td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Pedigree Group Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Pedigree Group Name\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n\n";

            $ret_val = printLogOutButton('edit_record.php');
            echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq pedigree_group_table

        if ($table_name == 'individual_group_table')
          {
            echo "Please select the Individual Group Name of the individual group record you would like to update.<br><br>\n";
            echo "<table>\n";
            echo "<tr><td>Individual Group Name:</td><td>\n";
            $jscript = printIndividualGroupSelectList($database_id);
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #20: $date<br>\n";
                echo "Error in call to printIndividualGroupSelectList from edit_record.php<br>\n";
                echo "See the error message from printIndividualGroupSelectList above for an explanation.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call printIndividualGroupSelectList
            if ($jscript == 'no_defined_individual_groups')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end if no individual groups in database
            echo "</td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Individual Group Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Individual Group Name\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n\n";

            $ret_val = printLogOutButton('edit_record.php');
            echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq individual_group_table

        if ($table_name == 'affection_status_table')
          {
            echo "Please select the Affection Status Name of the affection status record you would like to update.<br><br>\n";
            echo "<table>\n";
            echo "<tr><td>Affection Status Name:</td><td>\n";
            $jscript = printStatusSelectList($database_id);
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #21: $date<br>\n";
                echo "Error in call to printStatusSelectList from edit_record.php<br>\n";
                echo "See the error message from printStatusSelectList above for an explanation.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call printStatusSelectList
            if ($jscript == 'no_defined_statuses')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end if no affection statuses in database
            echo "</td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Affection Status Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Affection Status Name\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n\n";

            $ret_val = printLogOutButton('edit_record.php');
            echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq affection_status_table
	   
	if ($table_name == 'gene_table')
	  {
            if (!preg_match('/^\w+$/',$chr_id))
              {
                echo "Please select the Chromosome of the Gene record you would like to update.<br><br>\n";
                echo "<table>\n";
                echo "<tr><td>Chromosome:</td><td>\n";
                $jscript = printChromosomeSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #22: $date<br>\n";
                    echo "Error in call to printChromosomeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printChromosomeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printChromosomeSelectList
                if ($jscript == 'no_defined_chromosomes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no genes in database
                echo "</td></tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Gene to Update\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Selected Chromosome\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";
              }#end if haven't select chromosome gene is on
            else #have chromosome gene is on
              {
	        echo "Please select the Gene Name of the gene record you would like to update.<br><br>\n";
                echo "<table>\n";
	        echo "<tr><td>Gene Name:</td><td>\n";
                $jscript = printGeneSelectList($database_id,$chr_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #23: $date<br>\n";
                    echo "Error in call to printGeneSelectList from edit_record.php<br>\n";
                    echo "See the error message from printGeneSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printGeneSelectList
                if ($jscript == 'no_defined_genes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no genes in database
                echo "</td></tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Gene Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Gene Name\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";
              }#end else have chromosome gene is on

            $ret_val = printLogOutButton('edit_record.php');
            echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq gene_table

	if ($table_name == 'marker_table')
	  {
            if (!preg_match('/\w+/',$chromosome_id))
              {
                echo "Please select the Chromosome of the Marker whose marker record you would like to update.<br><br>\n";
                echo "<table>\n";
	        echo "<tr><td>Chromosome of Marker:</td><td>\n";
                $jscript = printChromosomeSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #24: $date<br>\n";
                    echo "Error in call to printChromosomeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printChromosomeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printChromosomeSelectList
                if ($jscript == 'no_defined_chromosomes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no chromosomes in database
                echo "</td></tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Marker\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Chromosome\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no chromosome
            if (preg_match('/\w+/',$chromosome_id))
              {
	        echo "Please select the Marker Name of the marker record you would like to update.<br><br>\n";
                echo "<table>\n";
	        echo "<tr><td>Marker Name:</td><td>\n";
                $jscript = printMarkerSelectList($database_id,$chromosome_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #25: $date<br>\n";
                    echo "Error in call to printMarkerSelectList from edit_record.php<br>\n";
                    echo "See the error message from printMarkerSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printMarkerSelectList
                if ($jscript == 'no_defined_markers')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no markers in database
                echo "</td></tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"chromosome_id\" value=\"$chromosome_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Marker Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Marker Name\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if have chromosome
	  }#end if (table_name == 'marker_table')

        if ($table_name == 'map_table')
          {
            if ((!preg_match('/\d+/',$map_id)) and
                (!preg_match('/\w+/',$type_of_update))
               )
              {
                echo "Please select the Map Name of the map record you would like to update & the type of update you want to perform.<br><br>\n";
                echo "<table>\n";
	        echo "<tr><td>Map Name:</td><td>\n";
                $jscript = printMapSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #26: $date<br>\n";
                    echo "Error in call to printMapSelectList from edit_record.php<br>\n";
                    echo "See the error message from printMapSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printMapSelectList
                if ($jscript == 'no_defined_maps')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "</td></tr>\n";
                    echo "</table>\n";
                    echo "<br>\n";
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no maps in database
                echo "</td></tr>\n";
                echo "<tr>\n";
                echo "<td>&nbsp;</td>\n";
                echo "<td><input type=\"radio\" name=\"type_of_update\" value=\"marker_info\"></td>\n";
                echo "<td>Specific Marker Information (i.e. Distance From Previous Marker)</td>\n";
                echo "</tr>\n";
                echo "<tr>\n";
                echo "<td>&nbsp;</td>\n";
                echo "<td><input type=\"radio\" name=\"type_of_update\" value=\"map_info\" checked></td>\n";
                echo "<td>General Map Information (i.e. How Distance Measured)</td>\n";
                echo "</tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Map Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Map Name\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n";

                $ret_val = printLogOutButton('edit_record.php');
	        echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if don't have map id or type_of_update
            if ((preg_match('/\d+/',$map_id)) and
                ($type_of_update == 'marker_info')
               )
              {
                $field_list_array = array('map_id');
                $marker_id_array = distinctTableQuery('marker_id','map_marker_link_table',$database_id,$field_list_array,$map_id,'equal','all','marker_num_in_map');
                if (!is_array($marker_id_array))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #27: $date<br>\n";
                    echo "Error in call to distinctTableQuery from edit_record.php<br>\n";
                    echo "$marker_id_array<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to distinctTableQuery
                if (sizeof($marker_id_array) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Currently there are no markers associated with the map you selected to update marker information for.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }

                echo "Please select the Marker Name of the marker in the map whose info you would like to update.<br><br>\n";
                echo "<table>\n";
	        echo "<tr><td>Marker Name:</td><td>\n";
                echo "<select name=\"marker_id\">\n";
                echo "<option>Select A Marker\n";
                foreach ($marker_id_array as $marker_id)
                  {
                    $field_list_array = array('marker_id');
                    $marker_name_array = distinctTableQuery('marker_name','marker_table',$database_id,$field_list_array,$marker_id,'equal','all');
                    if (!is_array($marker_name_array))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #28: $date<br>\n";
                        echo "Error in call to distinctTableQuery from edit_record.php<br>\n";
                        echo "$marker_id_array<br><br>\n";
                        echo "Please email the above error message using the Comments/Help/Support link on the \n";
                        echo "left navigation bar.<br>\n";
                        echo "</form>\n";
                        echo "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end error in call to distinctTableQuery
                    foreach ($marker_name_array as $marker_name){echo "<option value=\"$marker_id\">$marker_name\n";}
                  }#end foreach marker in the map
                echo "</select>\n";
                echo "</td></tr>\n";
                echo "</table>\n";
                echo "<br><br>\n";

	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"map_id\" value=\"$map_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Map-Marker Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Marker Name\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n";

                $ret_val = printLogOutButton('edit_record.php');
	        echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "{\n";
                echo "  if (form.marker_id.selectedIndex==0){\n";
                echo "    alert(\"You must select which Marker to Update\");\n";
                echo "    form.marker_id.focus();\n";
                echo "    return(false);}\n";
                echo "  else {return(true);}\n";
                echo "}\n";
	        echo "</script>\n";
              }#end if want to update a marker's info in the map
          }#end if (table_name == 'map_table')

	if ($table_name == 'allele_table')
	  {
            if ((!preg_match('/\w+/',$chromosome_id)) and
                (!preg_match('/\d+/',$marker_id)) and 
                (!preg_match('/\d+/',$allele_id))
               )
              {
                echo "Please select the Chromosome of the Marker whose allele record you would like to update.<br><br>\n";
                echo "<table align=\"center\">\n";
                echo "<tr><td>Chromosome of Marker:</td><td>\n";
                $jscript = printChromosomeSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #29: $date<br>\n";
                    echo "Error in call to printChromosomeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printChromosomeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printChromosomeSelectList
                if ($jscript == 'no_defined_chromosomes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no chromosomes in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Marker on This Chromosome\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Chromosome\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no chromosome, marker, or allele
            if ((preg_match('/\w+/',$chromosome_id)) and
                (!preg_match('/\d+/',$marker_id)) and 
                (!preg_match('/\d+/',$allele_id))
               )
              {
	        echo "Please select the Marker Name for the marker on Chromosome $chromosome_id whose allele record you would like to update.<br><br>\n";
	        echo "<table align=\"center\">\n";
	        echo "<tr><td>Marker Name:</td><td>\n";
                $jscript = printMarkerSelectList($database_id,$chromosome_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #30: $date<br>\n";
                    echo "Error in call to printMarkerSelectList from edit_record.php<br>\n";
                    echo "See the error message from printMarkerSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printMarkerSelectList
                if ($jscript == 'no_defined_markers')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no markers in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"chromosome_id\" value=\"$chromosome_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Allele To Update for This Marker\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Marker Name\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if chromosome, no marker_id and no allele_id
            if ((preg_match('/\w+/',$chromosome_id)) and
                (preg_match('/\d+/',$marker_id)) and 
                (!preg_match('/\d+/',$allele_id))
               )
              {
                $field_list_array = array('marker_id');
                $marker_name_array = distinctTableQuery('marker_name','marker_table',$database_id,$field_list_array,$marker_id,'equal','all');
                if (!is_array($marker_name_array))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #31: $date<br>\n";
                    echo "Error in call to distinctTableQuery from edit_record.php<br>\n";
                    echo "$marker_name_array<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to distinctTableQuery
                if (sizeof($marker_name_array) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The marker, whose allele record you want to edit, is no longer in the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no longer a marker 
                elseif (sizeof($marker_name_array) == '1'){$marker_name = $marker_name_array[0];}
                else #error in data integrity
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #32: $date<br>\n";
                    echo "Error in call to edit_record.php<br>\n";
                    echo "User wanted to update an allele for Marker ID $marker_id in Database ID $database_id, \n";
                    echo "but when query the Marker Table with that information multiple records are returned.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in data integrity

	        echo "Please select the Allele Code for Marker Name $marker_name on Chromosome $chromosome_id \n";
                echo "for the allele record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Allele Code:</td><td>\n";
                $jscript = printAlleleSelectList($database_id,$marker_id,'0');
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #33: $date<br>\n";
                    echo "Error in call to printAlleleSelectList from edit_record.php<br>\n";
                    echo "See the error message from printAlleleSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printAlleleSelectList
                if ($jscript == 'no_defined_alleles')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "</td></tr>\n";
                    echo "</table>\n";
                    echo "<br>\n";
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no alleles in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"chromosome_id\" value=\"$chromosome_id\">\n";
	        echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Allele Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Allele Code\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if chromosome_id, marker_id and no allele_id
	  }#end if table_name eq allele_table

	if ($table_name == 'genotype_table')
	  {
            if ((!preg_match('/\d+/',$pedigree_id)) and 
                (!preg_match('/\w+/',$chromosome_id)) and
                (!preg_match('/\d+/',$individual_id)) and 
                (!preg_match('/\d+/',$marker_id))
               )
              {
	        echo "Please select the Pedigree ID of the Individual, and Chromosome of the Marker \n";
                echo "for the genotype record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Pedigree ID of Individual:</td><td>\n";
                $jscript_1 = printPedigreeSelectList($database_id);
                if ($jscript_1 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #34: $date<br>\n";
                    echo "Error in call to printPedigreeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printPedigreeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printPedigreeSelectList
                if ($jscript_1 == 'no_defined_pedigrees')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no pedigrees in database
                echo "</td></tr>\n";
                echo "<tr><td>Chromosome of Marker:</td><td>\n";
                $jscript_2 = printChromosomeSelectList($database_id);
                if ($jscript_2 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #35: $date<br>\n";
                    echo "Error in call to printChromosomeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printChromosomeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printChromosomeSelectList
                if ($jscript_1 == 'no_defined_chromosomes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no chromosomes in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Individual and Marker of Genotype\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

                $jscript_1 = preg_replace('/ else {return true;}
}$/','',$jscript_1);
                $jscript_2 = preg_replace('/^{
/','',$jscript_2);
                $jscript_2 = preg_replace('/ else {return true;}
}$/','',$jscript_2);
                $jscript = "$jscript_1\n$jscript_2\nreturn true;\n}";

	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no pedigree_id,chromosome_id,individual_id,and marker_id
            if ((preg_match('/\d+/',$pedigree_id)) and 
                (preg_match('/\w+/',$chromosome_id)) and
                (!preg_match('/\d+/',$individual_id)) and 
                (!preg_match('/\d+/',$marker_id))
               )
              {
                $field_list_array = array('pedigree_table_id');
                $ped_rec_list     = tableQuery('pedigree_table',$database_id,$field_list_array,$pedigree_id,'equal','all');
                if (!is_array($ped_rec_list))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #36: $date<br>\n";
                    echo "Error in call to tableQuery from edit_record.php<br>\n";
                    echo "$ped_rec_list<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to tableQuery
                if (sizeof($ped_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The pedigree with pedigree table id $pedigree_id has been deleted from the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "Therefore there are no individuals in the database to update for that pedigree<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
                else
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #37: $date<br>\n";
                    echo "The user selected to update an individual with pedigree table id $pedigree_id,<br>\n";
                    echo "but when query the pedigree table with that id multiple records are returned.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in database data integrity

	        echo "Please select the Individual ID of the individual in Pedigree $ped_rec[pedigree_id], and the Marker Name \n";
                echo "of the marker on Chromosome $chromosome_id for the genotype record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Individual ID:</td><td>\n";
                $jscript_1 = printIndividualSelectList($database_id,$pedigree_id);
                if ($jscript_1 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #38: $date<br>\n";
                    echo "Error in call to printIndividualSelectList from edit_record.php<br>\n";
                    echo "See the error message from printIndividualSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printIndividualSelectList
                if ($jscript_1 == 'no_defined_individuals')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no individuals in database for pedigree
                echo "</td></tr>\n";
	        echo "<tr><td>Marker Name:</td><td>\n";
                $jscript_2 = printMarkerSelectList($database_id,$chromosome_id);
                if ($jscript_2 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #39: $date<br>\n";
                    echo "Error in call to printMarkerSelectList from edit_record.php<br>\n";
                    echo "See the error message from printMarkerSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call printMarkerSelectList
                if ($jscript_2 == 'no_defined_markers')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no markers in database
                echo "</td></tr>\n";
	        echo "</table>\n";
                echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
                echo "<input type=\"hidden\" name=\"pedigree_id\" value=\"$pedigree_id\">\n";
                echo "<input type=\"hidden\" name=\"chromosome_id\" value=\"$chromosome_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Genotype Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n\n";

                $ret_val = printLogOutButton('edit_record.php');
                echo "\n\n";

                $jscript_1 = preg_replace('/ else {return true;}
}$/','',$jscript_1);
                $jscript_2 = preg_replace('/^{
/','',$jscript_2);
                $jscript_2 = preg_replace('/ else {return true;}
}$/','',$jscript_2);
                $jscript = "$jscript_1\n$jscript_2\nreturn true;\n}";
	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if pedigree_id and chromosome and no individual_id,marker_id
	  }#end if table_name eq genotype_table

	if ($table_name == 'phenotype_table')
	  {
	    echo "Please select the Phenotype Name of the phenotype record you would like to update.<br><br>\n";
            echo "<table>\n";
	    echo "<tr><td>Phenotype Name:</td><td>\n";
            $jscript = printPhenotypeSelectList($database_id,'0','all');
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #40: $date<br>\n";
                echo "Error in call to printPhenotypeSelectList from edit_record.php<br>\n";
                echo "See the error message from printPhenotypeSelectList above for an explanation.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to printPhenotypeSelectList
            if ($jscript == 'no_defined_phenotypes')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end if no phenotypes in database
            echo "</td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Phenotype Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Phenotype Name\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	    echo "\n\n";

	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name eq phenotype_table

	if ($table_name == 'phenotype_value_table')
	  {
            if ((!preg_match('/\d+/',$pedigree_id)) and (!preg_match('/\d+/',$individual_id)) and (!preg_match('/\d+/',$phenotype_id)))
              {
	        echo "Please select the Pedigree ID of the individual whose phenotype value record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Pedigree ID:</td><td>\n";
                $jscript = printPedigreeSelectList($database_id);
                if ($jscript == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #41: $date<br>\n";
                    echo "Error in call to printPedigreeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printPedigreeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printPedigreeSelectList
                if ($jscript == 'no_defined_pedigrees')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no pedigrees in database
                echo "</td></tr>\n";
	        echo "</table>\n";
	        echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Select Individual and Phenotype\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n";

                $ret_val = printLogOutButton('edit_record.php');
	        echo "\n\n";
	      
	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no pedigree_id,individual_id, and phenotype_id
            if ((preg_match('/\d+/',$pedigree_id)) and (!preg_match('/\d+/',$individual_id)) and (!preg_match('/\d+/',$phenotype_id)))
              {
                $field_list_array = array('pedigree_table_id');
                $ped_rec_list     = tableQuery('pedigree_table',$database_id,$field_list_array,$pedigree_id,'equal','all');
                if (!is_array($ped_rec_list))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #42: $date<br>\n";
                    echo "Error in call to tableQuery from edit_record.php<br>\n";
                    echo "$ped_rec_list<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to tableQuery
                if (sizeof($ped_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The pedigree with pedigree table id $pedigree_id has been deleted from the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "Therefore there are no individuals in the database to update for that pedigree<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
                else
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #43: $date<br>\n";
                    echo "The user selected to update an individual with pedigree table id $pedigree_id,<br>\n";
                    echo "but when query the pedigree table with that id multiple records are returned.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in database data integrity

	        echo "Please select the Individual ID in Pedigree $ped_rec[pedigree_id] and the Phenotype Name \n";
                echo "of the phenotype value record you would like to update.<br><br>\n";
	        echo "<table>\n";
	        echo "<tr><td>Individual ID:</td><td>\n";
                $jscript_1 = printIndividualSelectList($database_id,$pedigree_id);
                if ($jscript_1 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #44: $date<br>\n";
                    echo "Error in call to printIndividualSelectList from edit_record.php<br>\n";
                    echo "See the error message from printIndividualSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printIndividualSelectList
                if ($jscript_1 == 'no_defined_individuals')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no individuals in database for pedigree
                echo "</td></tr>\n";
	        echo "<tr><td>Phenotype Name:</td><td>\n";
                $jscript_2 = printPhenotypeSelectList($database_id,'0','all');
                if ($jscript_2 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #45: $date<br>\n";
                    echo "Error in call to printPhenotypeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printPhenotypeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printPhenotypeSelectList
                if ($jscript_2 == 'no_defined_phenotypes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no phenotypes in database
                echo "</td></tr>\n";
	        echo "</table>\n";
	        echo "<br><br>\n";
	        echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	        echo "<input type=\"hidden\" name=\"pedigree_id\" value=\"$pedigree_id\">\n";
	        echo "<center>\n";
	        echo "<input type=\"submit\" name=\"submit\" value=\"Get Phenotype Value Record\">\n";
	        echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
	        echo "</center>\n";
	        echo "</form>\n\n";
	      
                $jscript_1 = preg_replace('/ else {return true;}
}$/','',$jscript_1);
                $jscript_2 = preg_replace('/^{
/','',$jscript_2);
                $jscript_2 = preg_replace('/ else {return true;}
}$/','',$jscript_2);
                $jscript = "$jscript_1\n$jscript_2\nreturn true;\n}";
	        echo "<script>\n";
	        echo "function Validate(form)\n";
                echo "$jscript\n";
	        echo "</script>\n";
              }#end if no pedigree_id,individual_id, and phenotype_id 
	  }#end if table_name eq phenotype_value_table

	if ($table_name == 'age_group_table')
	  {
	    echo "Please select the Minimum Age, Maximum Age, and Nationality of the Age Group record you would like to edit:<br><br>\n";
            $jscript = printAgeGroupRadioButtonList($database_id);
            if ($jscript == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #46: $date<br>\n";
                echo "Error in call to printAgeGroupRadioButtonList from edit_record.php<br>\n";
                echo "See the error message from printAgeGroupRadioButtonList above for an explanation.<br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to printAgeGroupRadioButtonList
            if ($jscript == 'no_defined_age_groups')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }
	    echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Age Group Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	    echo "\n\n";

            echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name == age_group_table

	if ($table_name == 'age_group_phenotype_percentile_link_table')
	  {
	    echo "Please select the Minimum Age, Maximum Age, Nationality, and Phenotype Name of the Age Group-Phenotype Percentile Link Record you want to edit:<br><br>\n";
            $jscript_1 = printAgeGroupRadioButtonList($database_id);
            if ($jscript_1 == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #47: $date<br>\n";
                echo "Error in call to printAgeGroupRadioButtonList from edit_record.php<br>\n";
                echo "See the error message from printAgeGroupRadioButtonList above for an explanation.<br>\n";
                echo "Please email the above error message using the Comments/Help/Support link on the \n";
                echo "left navigation bar.<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to printAgeGroupRadioButtonList
            if ($jscript_1 == 'no_defined_age_groups')
              {
                $date = date('Y-m-d H:i:s');
                echo "This message was generated at $date<br>\n";
                echo "</form>\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }
	    echo "<br><br>\n";
            echo "<table>\n";
            echo "<tr><td>Phenotype Name:</td><td>\n";
            $jscript_2 = printPhenotypeSelectList($database_id,'0','all');
                if ($jscript_2 == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #48: $date<br>\n";
                    echo "Error in call to printPhenotypeSelectList from edit_record.php<br>\n";
                    echo "See the error message from printPhenotypeSelectList above for an explanation.<br><br>\n";
                    echo "Please email the above error message using the Comments/Help/Support link on the \n";
                    echo "left navigation bar.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end error in call to printPhenotypeSelectList
                if ($jscript_2 == 'no_defined_phenotypes')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "This message was generated at $date<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }#end if no phenotypes in database
            echo "</td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Get Age Group-Phenotype Percentile Link Record\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	    echo "\n\n";

            $jscript_1 = preg_replace('/ else {return true;}
}$/','',$jscript_1);
            $jscript_2 = preg_replace('/^{
/','',$jscript_2);
            $jscript_2 = preg_replace('/ else {return true;}
}$/','',$jscript_2);
            $jscript = "$jscript_1\n$jscript_2\n return true;\n}";
	    echo "<script>\n";
	    echo "function Validate(form)\n";
            echo "$jscript\n";
	    echo "</script>\n";
	  }#end if table_name == age_group_phenotype_percentile_link_table
      }#end if have table_name but not search terms

    #5 Print Table Specific Form
    if ((preg_match('/\w+/',$table_name)) and
	(sizeof($search_terms) > '0') and
	($submit != 'Update Record'))
      {
	echo "<form action=\"edit_record.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
	echo "Update the values you would like to update and then click the Update button:<br><br>\n";
	if ($table_name == 'pedigree_table')
	  {
	    $field_list_array = array('pedigree_table_id');
	    $ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list_array,$search_terms[0],'equal','all');
	    if (!is_array($ped_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #49: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$ped_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to tableQuery
	    if (sizeof($ped_rec_list) == '0')
	      {
		echo "There is no pedigree record in the database associated with Pedigree Table ID $pedigree_id.  \n";
		echo "Please check that you entered the Pedigree ID and Nationality correctly or use the Pedigree Search \n";
		echo "tool to find the pedigree you are looking to update.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no pedigrees
	    $ped_rec = $ped_rec_list[0];

            $affection_status_fields = array();
	    $field_list_array = array('affection_status_id');
            $affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,'_','wildcard','all');
            if (!is_array($affection_status_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #50: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$affection_status_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in call to tableQuery
            if (sizeof($affection_status_rec_list) > '0')
              {
                foreach ($affection_status_rec_list as $affection_status_rec)
                  {
                    $affection_status_name = $affection_status_rec['affection_status_name'];
                    $field_list_array = array('affection_status_id','pedigree_table_id');
                    $term_array       = array($affection_status_rec['affection_status_id'],$ped_rec['pedigree_table_id']);
                    $mode_array       = array('equal','equal');
                    $ped_affect_link_rec_list = compoundTableQuery('pedigree_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
                    if (!is_array($ped_affect_link_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #51: $date<br><br>\n";
                        echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
                        echo "$ped_affect_link_rec_list<br><br>\n";
                        echo "Please email the above error message using the Comments/Help/Support link \n";
		        echo "on the left navigation bar\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in call to compoundTableQuery
                    if (sizeof($ped_affect_link_rec_list) == '0')
                      {
                        $ret_val = insertPedigreeAffectionStatusLink($database_id,$affection_status_rec['affection_status_id'],$ped_rec['pedigree_table_id']);
                        if ($ret_val != '1')
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #52: $date<br>\n";
                            echo "Error in call to insertPedigreeAffectionStatusLink from edit_record.php<br>\n";
                            echo "$ret_val<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to insertPedigreeAffectionStatusLink
                        $affection_status_fields[$affection_status_name] = '0';
                      }
                    elseif (sizeof($ped_affect_link_rec_list) == '1')
                      {
                        $ped_affect_link_rec = $ped_affect_link_rec_list[0];
                        $affection_status_fields[$affection_status_name] = $ped_affect_link_rec['number_affected_in_pedigree'];
                      }
                    else
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #53: $date<br>\n";
                        echo "When query the pedigree affection status link table with affection status id $affection_status_rec[affection_status_id] \n";
                        echo "and pedigree table id $ped_rec[pedigree_table_id] multiple records are returned.<br><br>\n";
                        echo "Please email the above error message using the Comments/Help/Support link \n";
		        echo "on the left navigation bar\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in data integrity
                  }#end foreach affection status
              }#end if defined affection statuses
            

	    echo "<table>\n";
	    echo "<tr><td>Pedigree ID:</td><td>$ped_rec[pedigree_id]</td><td><input type=\"hidden\" name=\"pedigree_id\" value=\"$ped_rec[pedigree_id]\"></td></tr>\n";
	    echo "<tr><td>Nationality:</td><td><input type=\"text\" name=\"nationality\" size=\"15\" maxlength=\"20\" value=\"$ped_rec[nationality]\"></td></tr>\n";
	    echo "<tr><td>Number of Individuals:</td><td><input type=\"text\" name=\"number_in_pedigree\" size=\"15\" maxlength=\"3\" value=\"$ped_rec[number_in_pedigree]\"></td></tr>\n";
	    foreach ($affection_status_fields as $affection_name=>$num_affected_in_ped)
	      {
                $field_name = "number_".$affection_name."_affected_in_pedigree";
                $print_name = "Number ".$affection_name." Affected In Pedigree";
		echo "<tr><td>$print_name:</td><td><input type=\"text\" name=\"$field_name\" size=\"15\" maxlength=\"3\" value=\"$num_affected_in_ped\"></td></tr>\n";
	      }
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
            echo "<input type=\"hidden\" name=\"pedigree_table_id\" value=\"$ped_rec[pedigree_table_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_nationality\" value=\"$ped_rec[nationality]\">\n";
	    echo "<input type=\"hidden\" name=\"old_number_in_pedigree\" value=\"$ped_rec[number_in_pedigree]\">\n";
	    foreach ($affection_status_fields as $affection_name=>$num_affected_in_ped)
	      {
		$name = "old_number_".$affection_name."_affected_in_pedigree";
		echo "<input type=\"hidden\" name=\"$name\" value=\"$num_affected_in_ped\">\n";
	      }
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq pedigree_table

	if ($table_name == 'individual_table')
	  {
	    $field_array = array('pedigree_table_id');
	    $value_array = array($search_terms[0]);
	    $exists_pedigree = existsValue('pedigree_table',$field_array,$value_array,$database_id);
	    if (!preg_match('/^\d+$/',$exists_pedigree))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #54: $date<br>\n";
		echo "Error in call to existsValue from edit_record.php<br>\n";
		echo "$exists_pedigree<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end error in call to exists pedigree
	    if ($exists_pedigree == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no pedigree in the database with Pedigree Table ID $search_terms[0].  Therefore there is no individual in the \n";
		echo "database with Individual Table ID $search_terms[1] and Pedigree Table ID $search_terms[0].  This record must have been deleted \n";
                echo "from the database before you submited your request to update it.  This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if pedigree doesn't exists

	    $field_list_array = array('pedigree_table_id','individual_table_id');
	    $term_array       = array($search_terms[0],$search_terms[1]);
	    $mode_array       = array('equal','equal');
	    $indiv_rec_list = compoundTableQuery('individual_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
	    if (!is_array($indiv_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #55: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$indiv_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to compoundTableQuery
	    if (sizeof($indiv_rec_list) == '0')
	      {
		echo "There is no individual record in the database associated with Pedigree ID $search_terms[0] and Individual ID $search_terms[1].\n";
		echo "Please check that you entered the Pedigree ID and Individual ID correctly or use the Individual Search \n";
		echo "tool to find the individual you are looking to update.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no individuals
	    $indiv_rec = $indiv_rec_list[0];

	    $affection_status_fields = array();
            $field_list_array = array('affection_status_id');
            $affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,'_','wildcard','all');
            if (!is_array($affection_status_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #56: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$affection_status_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in call to tableQuery
            if (sizeof($affection_status_rec_list) > '0')
              {
                foreach ($affection_status_rec_list as $affection_status_rec)
                  {
                    $affection_status_name = $affection_status_rec['affection_status_name'];
                    $field_list_array = array('affection_status_id','individual_table_id');
                    $term_array       = array($affection_status_rec['affection_status_id'],$indiv_rec['individual_table_id']);
                    $mode_array       = array('equal','equal');
                    $indiv_affect_link_rec_list = compoundTableQuery('individual_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
                    if (!is_array($indiv_affect_link_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #57: $date<br><br>\n";
                        echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
                        echo "$indiv_affect_link_rec_list<br><br>\n";
                        echo "Please email the above error message using the Comments/Help/Support link \n";
		        echo "on the left navigation bar\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in call to compoundTableQuery
                    if (sizeof($indiv_affect_link_rec_list) == '0')
                      {
                        $ret_val = insertIndividualAffectionStatusLink($database_id,$affection_status_rec['affection_status_id'],$indiv_rec['individual_table_id']);
                        if ($ret_val != '1')
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #58: $date<br>\n";
                            echo "Error in call to insertIndividualAffectionStatusLink from edit_record.php<br>\n";
                            echo "$ret_val<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }
                        $affection_status_fields[$affection_status_name] = '0';
                      }
                    elseif (sizeof($indiv_affect_link_rec_list) == '1')
                      {
                        $indiv_affect_link_rec = $indiv_affect_link_rec_list[0];
                        $affection_status_fields[$affection_status_name] = $indiv_affect_link_rec['individual_affection_status'];
                      }
                    else
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #59: $date<br>\n";
                        echo "When query the individual affection status link table with affection status id $affection_status_rec[affection_status_id] \n";
                        echo "and individual table id $indiv_rec[individual_table_id] multiple records are returned.<br><br>\n";
                        echo "Please email the above error message using the Comments/Help/Support link \n";
		        echo "on the left navigation bar\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in data integrity
                  }#end foreach affection status
              }#end if defined affection statuses

	    echo "<table>\n";
	    echo "<tr><td>Pedigree ID:</td><td>$indiv_rec[pedigree_id]</td><td><input type=\"hidden\" name=\"pedigree_id\" value=\"$indiv_rec[pedigree_id]\"></td></tr>\n";
	    echo "<tr><td>Individual ID:</td><td>$indiv_rec[individual_id]</td><td><input type=\"hidden\" name=\"individual_id\" value=\"$indiv_rec[individual_id]\"></td></tr>\n";
	    echo "<tr><td>Father ID:</td><td><input type=\"text\" name=\"father_id\" size=\"15\" maxlength=\"11\" value=\"$indiv_rec[father_id]\"></td></tr>\n";
	    echo "<tr><td>Mother ID:</td><td><input type=\"text\" name=\"mother_id\" size=\"15\" maxlength=\"11\" value=\"$indiv_rec[mother_id]\"></td></tr>\n";
	    echo "<tr><td>Sex:</td><td><input type=\"text\" name=\"sex\" size=\"15\" maxlength=\"1\" value=\"$indiv_rec[sex]\"></td></tr>\n";
	    if (is_null($indiv_rec['position_in_family']))
	      {
		echo "<tr><td>Position in Family:</td><td><input type=\"text\" name=\"position_in_family\" size=\"15\" maxlength=\"25\" value=\"\"></td></tr>\n";
	      }
	    else
	      {
		echo "<tr><td>Position in Family:</td><td><input type=\"text\" name=\"position_in_family\" size=\"15\" maxlength=\"25\" value=\"$indiv_rec[position_in_family]\"></td></tr>\n";
	      }
	    foreach ($affection_status_fields as $affection_name=>$indiv_affection_status)
	      {
                $field_name = "$affection_name"."_affection_status";
                $print_name = "$affection_name Affection Status";
		echo "<tr><td>$print_name:</td><td><input type=\"text\" name=\"$field_name\" size=\"15\" maxlength=\"1\" value=\"$indiv_affection_status\"></td></tr>\n";
	      }
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"individual_table_id\" value=\"$indiv_rec[individual_table_id]\">\n";
            echo "<input type=\"hidden\" name=\"pedigree_table_id\" value=\"$indiv_rec[pedigree_table_id]\">\n";
            echo "<input type=\"hidden\" name=\"old_father_id\" value=\"$indiv_rec[father_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_mother_id\" value=\"$indiv_rec[mother_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_sex\" value=\"$indiv_rec[sex]\">\n";
	    if (is_null($indiv_rec['position_in_family'])) {echo "<input type=\"hidden\" name=\"old_position_in_family\" value=\"\">\n";}
	    else                                           {echo "<input type=\"hidden\" name=\"old_position_in_family\" value=\"$indiv_rec[position_in_family]\">\n";}
	    foreach ($affection_status_fields as $affection_name=>$indiv_affection_status)
	      {
		$name = "old_".$affection_name."_affection_status";
		echo "<input type=\"hidden\" name=\"$name\" value=\"$indiv_affection_status\">\n";
	      }
            echo "<br><br>\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq individual_table

	if ($table_name == 'pedigree_group_table')
          {
            $field_list = array('pedigree_group_id');
            $term       = $search_terms[0];
            $ped_group_rec_list = tableQuery('pedigree_group_table',$database_id,$field_list,$term,'equal','all');
            if (!is_array($ped_group_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #60: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$ped_group_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in call to tableQuery
	    if (sizeof($ped_group_rec_list) == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "There is no pedigree group record in the database associated with Pedigree Group ID $term.  \n";
		echo "The pedigree group record associated with that pedigree group id appears to have been deleted before you \n";
                echo "submited your request to update the record.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no groups
	    elseif (sizeof($ped_group_rec_list) == '1') {$ped_group_rec = $ped_group_rec_list[0];}
            else
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #61: $date<br>\n";
                echo "The user wanted to update pedigree group id $term, but when queried the pedigree group table with that id multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in data integrity
             
	    $stripslashes_ped_group_desc = stripslashes($ped_group_rec['pedigree_group_description']);
            echo "<table>\n";
            echo "<tr><td>Pedigree Group Name:</td><td>$ped_group_rec[pedigree_group_name]</td><td><input type=\"hidden\" name=\"pedigree_group_name\" value=\"$ped_group_rec[pedigree_group_name]\"></td></tr>\n";
            echo "<tr><td>Pedigree Group Description:</td><td><textarea name=\"pedigree_group_description\" rows=\"10\" cols=\"50\" wrap=\"virtual\">$stripslashes_ped_group_desc</textarea></td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
            echo "<input type=\"hidden\" name=\"pedigree_group_id\" value=\"$ped_group_rec[pedigree_group_id]\">\n";
            echo "<input type=\"hidden\" name=\"old_pedigree_group_description\" value=\"$stripslashes_ped_group_desc\">\n";
            echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq pedigree_group_table

        if ($table_name == 'individual_group_table')
          {
            $field_list = array('individual_group_id');
            $term       = $search_terms[0];
            $indiv_group_rec_list = tableQuery('individual_group_table',$database_id,$field_list,$term,'equal','all');
            if (!is_array($indiv_group_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #62: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$indiv_group_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in call to tableQuery
	    if (sizeof($indiv_group_rec_list) == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "There is no individual group record in the database associated with Individual Group ID $term.  \n";
		echo "The individual group record associated with that individual group id appears to have been deleted before you \n";
                echo "submited your request to update the record.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no groups
	    elseif (sizeof($indiv_group_rec_list) == '1') {$indiv_group_rec = $indiv_group_rec_list[0];}
            else
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #63: $date<br>\n";
                echo "The user wanted to update individual group id $term, but when queried the individual group table with that id multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in data integrity
             
	    $stripslashes_indiv_group_desc = stripslashes($indiv_group_rec['individual_group_description']);
            echo "<table>\n";
            echo "<tr><td>Individual Group Name:</td><td>$indiv_group_rec[individual_group_name]</td><td><input type=\"hidden\" name=\"individual_group_name\" value=\"$indiv_group_rec[individual_group_name]\"></td></tr>\n";
            echo "<tr><td>Individual Group Description:</td><td><textarea name=\"individual_group_description\" rows=\"10\" cols=\"50\" wrap=\"virtual\">$stripslashes_indiv_group_desc</textarea></td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
            echo "<input type=\"hidden\" name=\"individual_group_id\" value=\"$indiv_group_rec[individual_group_id]\">\n";
            echo "<input type=\"hidden\" name=\"old_individual_group_description\" value=\"$stripslashes_indiv_group_desc\">\n";
            echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" vale=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq individual_group_table

        if ($table_name == 'affection_status_table')
          {
            $field_list = array('affection_status_id');
            $term       = $search_terms[0];
            $affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list,$term,'equal','all');
            if (!is_array($affection_status_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #64: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$affection_status_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in call to tableQuery
	    if (sizeof($affection_status_rec_list) == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "There is no affection status record in the database associated with Affection Status ID $term.  \n";
		echo "The affection status record associated with that id appears to have been deleted before you \n";
                echo "submited your request to update the record.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no affection statuses
	    elseif (sizeof($affection_status_rec_list) == '1') {$affection_status_rec = $affection_status_rec_list[0];}
            else
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #65: $date<br>\n";
                echo "The user wanted to update affection status id $term, but when queried the affection status table with that id multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end error in data integrity
             
	    $stripslashes_affection_status_desc = stripslashes($affection_status_rec['affection_status_description']);
            echo "<table>\n";
            echo "<tr><td>Affection Status Name:</td><td>$affection_status_rec[affection_status_name]</td><td><input type=\"hidden\" name=\"affection_status_name\" value=\"$affection_status_rec[affection_status_name]\"></td></tr>\n";
            echo "<tr><td>Affection Status Description:</td><td><textarea name=\"affection_status_description\" rows=\"10\" cols=\"50\" wrap=\"virtual\">$stripslashes_affection_status_desc</textarea></td></tr>\n";
            echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
            echo "<input type=\"hidden\" name=\"status\" value=\"$affection_status_id\">\n";
            echo "<input type=\"hidden\" name=\"old_affection_status__description\" value=\"$stripslashes_affection_status_desc\">\n";
            echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq affection_status_table

	if ($table_name == 'gene_table')
	  {
	    $field_list_array = array('gene_id');
	    $term = $search_terms[0];
	    $gene_rec_list = tableQuery('gene_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($gene_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #66: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$gene_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to tableQuery
	    if (sizeof($gene_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no gene record in the database associated with Gene ID $term.  \n";
		echo "The gene record associated with that gene id appears to have been deleted before you \n";
                echo "submited your request to update the record.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no genes
	    $gene_rec = $gene_rec_list[0];
            $stripslashes_gene_desc = stripslashes($gene_rec['gene_description']);
	    echo "<table>\n";
	    echo "<tr><td>Gene Name:</td><td>$gene_rec[gene_name]</td><td><input type=\"hidden\" name=\"gene_name\" value=\"$gene_rec[gene_name]\"></td></tr>\n";
	    echo "<tr><td>Chromosome:</td><td><input type=\"text\" name=\"chromosome\" size=\"15\" maxlength=\"2\" value=\"$gene_rec[chromosome]\"></td></tr>\n";
	    echo "<tr><td>Gene Start Position:</td><td><input type=\"text\" name=\"gene_start_position\" size=\"15\" maxlength=\"11\" value=\"$gene_rec[gene_start_position]\"></td></tr>\n";
	    echo "<tr><td>Gene Stop Position:</td><td><input type=\"text\" name=\"gene_stop_position\" size=\"15\" maxlength=\"11\" value=\"$gene_rec[gene_stop_position]\"></td></tr>\n";
	    echo "<tr><td>Number of Exons:</td><td><input type=\"text\" name=\"number_of_exons\" size=\"15\" maxlength=\"3\" value=\"$gene_rec[number_of_exons]\"></td></tr>\n";
	    echo "<tr><td>Number of Introns:</td><td><input type=\"text\" name=\"number_of_introns\" size=\"15\" maxlength=\"3\" value=\"$gene_rec[number_of_introns]\"></td></tr>\n"; 
	    echo "<tr><td>Gene Description:</td><td><textarea name=\"gene_description\" rows=\"10\" cols=\"50\" wrap=\"virtual\">$stripslashes_gene_desc</textarea></td></tr>\n";
	    echo "</table>\n";
            echo "<br><br>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"gene_id\" value=\"$gene_rec[gene_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_chromosome\" value=\"$gene_rec[chromosome]\">\n";
	    echo "<input type=\"hidden\" name=\"old_gene_start_position\" value=\"$gene_rec[gene_start_position]\">\n";
	    echo "<input type=\"hidden\" name=\"old_gene_stop_position\" value=\"$gene_rec[gene_stop_position]\">\n";
	    echo "<input type=\"hidden\" name=\"old_number_of_exons\" value=\"$gene_rec[number_of_exons]\">\n";
	    echo "<input type=\"hidden\" name=\"old_number_of_introns\" value=\"$gene_rec[number_of_introns]\">\n";
	    echo "<input type=\"hidden\" name=\"old_gene_description\" value=\"$stripslashes_gene_desc\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq gene_table

	if ($table_name == 'marker_table')
	  {
	    $field_list_array = array('marker_id');
	    $term = $search_terms[0];
	    $marker_rec_list = tableQuery('marker_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($marker_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #67: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$marker_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to tableQuery
	    if (sizeof($marker_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no marker record in the database associated with Marker ID $term.  \n";
		echo "It appears that the marker record was deleted before you submited your request to update the record\n";
                echo "This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no markers
	    $marker_rec = $marker_rec_list[0];

	    echo "<table>\n";
	    echo "<tr><td>Marker Name:</td><td>$marker_rec[marker_name]</td><td><input type=\"hidden\" name=\"marker_name\" value=\"$marker_rec[marker_name]\"></td></tr>\n";
	    echo "<tr><td>Marker Type:</td><td><input type=\"text\" name=\"marker_type\" size=\"15\" maxlength=\"20\" value=\"$marker_rec[marker_type]\"></td></tr>\n";
	    echo "<tr><td>Chromosome:</td><td><input type=\"text\" name=\"chromosome\" size=\"15\" maxlength=\"2\" value=\"$marker_rec[chromosome]\"></td></tr>\n";
	    echo "<tr><td>Chromosome Position:</td><td><input type=\"text\" name=\"chromosome_position\" size=\"15\" maxlength=\"11\" value=\"$marker_rec[chromosome_position]\"></td></tr>\n";
	    echo "<tr><td>Genomic Position:</td><td><input type=\"text\" name=\"genomic_positon\" size=\"15\" maxlength=\"11\" value=\"$marker_rec[genomic_position]\"></td></tr>\n";
	    echo "<tr><td>Tag SNP:</td><td><input type=\"text\" name=\"tag_snp\" size=\"15\" maxlength=\"1\" value=\"$marker_rec[tag_snp]\"></td><td>(Enter 1 for Yes, and 0 for No)</td></tr>\n";
	    echo "<tr><td>Amino Acid Change:</td><td><input type=\"text\" name=\"amino_acid_change\" size=\"15\" maxlength=\"10\" value=\"$marker_rec[amino_acid_change]\"></td><td>(Either synonomous or nonsynonomous)</td></tr>\n"; 
	    echo "<tr><td>Number of Alleles:</td><td><input type=\"text\" name=\"number_of_alleles\" size=\"15\" maxlength=\"3\" value=\"$marker_rec[number_of_alleles]\"></td></tr>\n";
	    echo "<tr><td>Hardy-Weinburg Equilibrium:</td><td><input type=\"text\" name=\"hardy_weinburg_equilibrium\" size=\"15\" maxlength=\"1\" value=\"$marker_rec[hardy_weinburg_equilibrium]\"></td><td>(Either 1 for Yes, or 0 for No)</td></tr>\n";
	    echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_rec[marker_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_chromosome\" value=\"$marker_rec[chromosome]\">\n";
	    echo "<input type=\"hidden\" name=\"old_chromosome_position\" value=\"$marker_rec[chromosome_position]\">\n";
	    echo "<input type=\"hidden\" name=\"old_genomic_position\" value=\"$marker_rec[genomic_position]\">\n";
	    echo "<input type=\"hidden\" name=\"old_tag_snp\" value=\"$marker_rec[tag_snp]\">\n";
	    echo "<input type=\"hidden\" name=\"old_amino_acid_change\" value=\"$marker_rec[amino_acid_change]\">\n";
	    echo "<input type=\"hidden\" name=\"old_number_of_alleles\" value=\"$marker_rec[number_of_alleles]\">\n";
	    echo "<input type=\"hidden\" name=\"old_hardy_weinburg_equilibrium\" value=\"$marker_rec[hardy_weinburg_equilibrium]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq marker_table

        if ($table_name == 'map_table')
          {
            if ($type_of_update == 'map_info')
              {
                $field_list_array = array('map_id');
                $term             = $search_terms[0];
                $map_rec_list = tableQuery('map_table',$database_id,$field_list_array,$term,'equal','all');
                if (!is_array($map_rec_list))
	          {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #68: $date<br>\n";
		    echo "Error in call to tableQuery from edit_record.php<br>\n";
		    echo "$map_rec_list<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
	          }#end if error in call to tableQuery
                if (sizeof($map_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The Map you selected to update is no longer in the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($map_rec_list) == '1'){$map_rec = $map_rec_list[0];}
                else #error in data integrity
                  {
                    $date = date('Y-m-d H:i:s');
	            echo "Error #69: $date<br>\n";
                    echo "!!!Error in Database Data Integrity!!!!<br>\n";
                    echo "Stop using the data in the database until Database Administrator tells you all data is okay.<br>\n";
	            echo "Error in execution of edit_record.php<br>\n";
	            echo "The user wanted to update map information for map_id $map_id with database_id $database_id, \n";
                    echo "but when query the map table with that information multiple records are returned.<br><br>\n";
                    echo "Please email the above error using the Comments/Help/Support link \n";
	            echo "on the left navigation bar.\n";
	            echo "</body></html>\n";
	            $ret_val = disconnect();
	            exit;
                  }#end error in data integrity

                echo "<table>\n";
                echo "<tr><td>Map Name:</td><td>$map_rec[map_name]</td></tr>\n";
                echo "<tr><td>Number of Markers in Map:</td><td>$map_rec[num_markers_in_map]</td></tr>\n";
                echo "<tr><td>Distance Measurement:</td><td><select name=\"distance_measure\">\n";
                if ($map_rec['distance_measure'] == 'base_pairs'){echo "<option value=\"base_pairs\" selected>Base Pairs\n";}
                else                                             {echo "<option value=\"base_pairs\" >Base Pairs\n";}

                if ($map_rec['distance_measure'] == 'haldane_centiMorgans')
                  {echo "<option value=\"haldane_centiMorgans\" selected>Haldance centiMorgans\n";}
                else
                  {echo "<option value=\"haldane_centiMorgans\">Haldance centiMorgans\n";}

                if ($map_rec['distance_measure'] == 'kosambi_centiMorgans')
                  {echo "<option value=\"kosambi_centiMorgans\" selected>Kosambi centiMorgans\n";}
                else
                  {echo "<option value=\"kosambi_centiMorgans\">Kosambi centiMorgans\n";}

                if ($map_rec['distance_measure'] == 'recombination_fraction')
                  {echo "<option value=\"recombination_fraction\" selected>Recombination Fraction\n";}
                else
                  {echo "<option value=\"recombination_fraction\">Recombination Fraction\n";}
                echo "</select>\n";
                echo "</td></tr>\n";
                if (is_null($map_rec['map_description']))
                  {
                    echo "<tr>\n";
                    echo "<td>Map Description:</td>\n";
                    echo "<td><textarea name=\"map_description\" cols=\"50\" rows=\"10\" wrap=\"virtual\"></textarea></td>\n";
                    echo "</tr>\n";
                  }#end if map description is null
                else #not null
                  {
                    echo "<tr>\n";
                    echo "<td>Map Description:</td>\n";
                    echo "<td><textarea name=\"map_description\" cols=\"50\" rows=\"10\" wrap=\"virtual\">$map_rec[map_description]</textarea></td>\n";
                    echo "</tr>\n";
                  }#end else not null
                echo "</table>\n";
                echo "<br><br>\n";

                echo "<input type=\"hidden\" name=\"table_name\" value=\"map_table\">\n";
                echo "<input type=\"hidden\" name=\"type_of_update\" value=\"map_info\">\n";
                echo "<input type=\"hidden\" name=\"map_id\" value=\"$map_id\">\n";
                echo "<input type=\"hidden\" name=\"map_name\" value=\"$map_rec[map_name]\">\n";
                echo "<input type=\"hidden\" name=\"old_distance_measure\" value=\"$map_rec[distance_measure]\">\n";
                if (is_null($map_rec['map_description'])){echo "<input type=\"hidden\" name=\"old_map_description\" value=\"\">\n";}
                else {echo "<input type=\"hidden\" name=\"old_map_description\" value=\"$map_rec[map_description]\">\n";}

                echo "<center>\n";
                echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n";

                $ret_val = printLogOutButton('edit_record.php');
              }#end if type of update == 'map_info'
            if ($type_of_update == 'marker_info')
              {
                $field_list_array = array('map_id');
                $term             = $search_terms[0];
                $map_rec_list = tableQuery('map_table',$database_id,$field_list_array,$term,'equal','all');
                if (!is_array($map_rec_list))
	          {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #70: $date<br>\n";
		    echo "Error in call to tableQuery from edit_record.php<br>\n";
		    echo "$map_rec_list<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
	          }#end if error in call to tableQuery
                if (sizeof($map_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The Map you selected to update is no longer in the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($map_rec_list) == '1'){$map_rec = $map_rec_list[0];}
                else #error in data integrity
                  {
                    $date = date('Y-m-d H:i:s');
	            echo "Error #71: $date<br>\n";
                    echo "!!!Error in Database Data Integrity!!!!<br>\n";
                    echo "Stop using the data in the database until Database Administrator tells you all data is okay.<br>\n";
	            echo "Error in execution of edit_record.php<br>\n";
	            echo "The user wanted to update map information for map_id $map_id with database_id $database_id, \n";
                    echo "but when query the map table with that information multiple records are returned.<br><br>\n";
                    echo "Please email the above error using the Comments/Help/Support link \n";
	            echo "on the left navigation bar.\n";
	            echo "</body></html>\n";
	            $ret_val = disconnect();
	            exit;
                  }#end error in data integrity
                $map_name = $map_rec['map_name'];

                $field_list_array = array('marker_id');
                $term             = $search_terms[1];
                $marker_rec_list = tableQuery('marker_table',$database_id,$field_list_array,$term,'equal','all');
                if (!is_array($marker_rec_list))
	          {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #72: $date<br>\n";
		    echo "Error in call to tableQuery from edit_record.php<br>\n";
		    echo "$map_rec_list<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
	          }#end if error in call to tableQuery
                if (sizeof($marker_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The Marker you selected to update is no longer in the database.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($marker_rec_list) == '1'){$marker_rec = $marker_rec_list[0];}
                else #error in data integrity
                  {
                    $date = date('Y-m-d H:i:s');
	            echo "Error #73: $date<br>\n";
                    echo "!!!Error in Database Data Integrity!!!!<br>\n";
                    echo "Stop using the data in the database until Database Administrator tells you all data is okay.<br>\n";
	            echo "Error in execution of edit_record.php<br>\n";
	            echo "The user wanted to update marker information for marker_id $marker_id in map_id $map_id with database_id $database_id, \n";
                    echo "but when query the marker table with that marker id information multiple records are returned.<br><br>\n";
                    echo "Please email the above error using the Comments/Help/Support link \n";
	            echo "on the left navigation bar.\n";
	            echo "</body></html>\n";
	            $ret_val = disconnect();
	            exit;
                  }#end error in data integrity
                $marker_name = $marker_rec['marker_name'];

                $field_list_array = array('map_id','marker_id');
                $mode_array       = array('equal','equal');
                $map_marker_link_rec_list = tableQuery('map_marker_link_table',$database_id,$field_list_array,$search_terms,$mode_array,'all');
                if (!is_array($map_marker_link_rec_list))
                  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #74: $date<br>\n";
		    echo "Error in call to tableQuery from edit_record.php<br>\n";
		    echo "$map_marker_link_rec_list<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
	          }#end if error in call to tableQuery
                if (sizeof($map_marker_rec_list) == '0')
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "The Marker you selected to update is no longer in the Map you selected to update.<br>\n";
                    echo "This message was generated at $date.<br>\n";
                    echo "</form>\n";
                    echo "</body></html>\n";
                    $ret_val = disconnect();
                    exit;
                  }
                elseif (sizeof($map_marker_link_rec_list) == '1'){$map_marker_link_rec = $map_marker_link_rec_list[0];}
                else #error in data integrity
                  {
                    $date = date('Y-m-d H:i:s');
	            echo "Error #75: $date<br>\n";
                    echo "!!!Error in Database Data Integrity!!!!<br>\n";
                    echo "Stop using the data in the database until Database Administrator tells you all data is okay.<br>\n";
	            echo "Error in execution of edit_record.php<br>\n";
	            echo "The user wanted to update map information for marker_id $marker_id in map_id $map_id with database_id $database_id, \n";
                    echo "but when query the map marker link table with that information multiple records are returned.<br><br>\n";
                    echo "Please email the above error using the Comments/Help/Support link \n";
	            echo "on the left navigation bar.\n";
	            echo "</body></html>\n";
	            $ret_val = disconnect();
	            exit;
                  }#end error in data integrity

                echo "<table>\n";
                echo "<tr><td>Map Name:</td><td>$map_name</td></tr>\n";
                echo "<tr><td>Marker Name:</td><td>$marker_name</td></tr>\n";
                echo "<tr><td>Chromosome:</td><td>$map_marker_link_rec[chromosome]</td></tr>\n";
                echo "<tr>\n";
                echo "<td>Marker Number in Map:</td>\n";
                echo "<td><input type=\"text\" name=\"marker_num_in_map\" size=\"15\" maxlength=\"11\" value=\"$map_marker_link_rec[marker_number_in_map]\"></td>\n";
                echo "</tr>\n";
                echo "<tr>\n";
                echo "<td>Distance from Previous Marker in Map:</td>\n";
                echo "<td><input type=\"text\" name=\"distance_from_previous_marker\" size=\"15\" maxlength=\"255\" value=\"$map_marker_link_rec[distance_from_previous_marker]\"></td>\n";
                echo "</tr>\n";
                echo "</table>\n";
                echo "<br><br>\n\n";

                echo "<input type=\"hidden\" name=\"table_name\" value=\"map_table\">\n";
                echo "<input type=\"hidden\" name=\"type_of_update\" value=\"marker_info\">\n";
                echo "<input type=\"hidden\" name=\"map_id\" value=\"$map_id\">\n";
                echo "<input type=\"hidden\" name=\"map_name\" value=\"$map_name\">\n";
                echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id\">\n";
                echo "<input type=\"hidden\" name=\"marker_name\" value=\"$marker_name\">\n";
                echo "<input type=\"hidden\" name=\"map_marker_link_id\" value=\"$map_marker_link_rec[map_marker_link_id]\">\n";
                echo "<input type=\"hidden\" name=\"old_marker_num_in_map\" value=\"$map_marker_link_rec[marker_number_in_map]\">\n";
                echo "<input type=\"hidden\" name=\"old_distance_from_previous_marker\" value=\"$map_marker_link_rec[distance_from_previous_marker]\">\n";

                echo "<center>\n";
                echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
                echo "</form>\n";
                echo "</center>\n";
                echo "<br><br>\n";

                $ret_val = printLogOutButton('edit_record.php');
              }#end if type_of_update == 'marker_info'
          }#end if table name eq map_table

	if ($table_name == 'allele_table')
	  {
	    $field_list_array = array('marker_id');
	    $term = $search_terms[0];
	    $marker_rec_list = tableQuery('marker_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($marker_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #76: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$marker_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to tableQuery
	    if (sizeof($marker_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no marker record in the database associated with Marker ID $search_terms[0] \n";
		echo "Therfore there is no Allele ID $search_terms[1] for this marker.  It appears that \n";
                echo "the marker record for Marker ID $search_terms[0] was deleted before you submitted your request to update an allele for it.  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no markers
	    $marker_rec = $marker_rec_list[0];
	    
	    $field_list_array = array('marker_id','allele_id');
	    $term_array       = array($search_terms[0],$search_terms[1]);
	    $mode_array       = array('equal','equal');
	    $allele_rec_list  = compoundTableQuery('allele_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
	    if (!is_array($allele_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #77: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$allele_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to compoundTableQuery
	    if (sizeof($allele_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no allele record in the database associated with Marker ID $search_term[0] and Allele ID $search_term[1].  \n";
		echo "It appears that the allele record was deleted before you submited your request to update the record.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no alleles
	    $allele_rec = $allele_rec_list[0];

	    echo "<table>\n";
	    echo "<tr><td>Marker Name:</td><td>$marker_rec[marker_name]</td></tr>\n";
	    echo "<tr><td>Allele Code:</td><td>$allele_rec[allele_code]</td></tr>\n";
	    echo "<tr><td>Allele Size:</td><td><input type=\"text\" name=\"allele_size\" size=\"15\" maxlength=\"11\" value=\"$allele_rec[allele_size]\"></td></tr>\n";
	    echo "<tr><td>Allele Sequence:</td><td><input type=\"text\" name=\"allele_sequence\" size=\"15\" maxlength=\"52\" value=\"$allele_rec[allele_sequence]\"></td></tr>\n";
	    echo "<tr><td>Allele Frequency:</td><td><input type=\"text\" name=\"allele_frequency\" size=\"15\" maxlength=\"6\" value=\"$allele_rec[allele_frequency]\"></td></tr>\n";
	    echo "<tr><td>Illumina Code:</td><td><input type=\"text\" name=\"allele_illumina_code\" size=\"15\" maxlength=\"3\" value=\"$allele_rec[allele_illumina_code]\"></td></tr>\n";
	    echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"allele_id\" value=\"$allele_rec[allele_id]\">\n";
	    echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_rec[marker_id]\">\n";
	    echo "<input type=\"hidden\" name=\"allele_code\" value=\"$allele_rec[allele_code]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_size\" value=\"$allele_rec[allele_size]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_sequence\" value=\"$allele_rec[allele_sequence]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_frequency\" value=\"$allele_rec[allele_frequency]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_illumina_code\" value=\"$allele_rec[allele_illumina_code]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "<br><br>\n";
            echo "<input type=\"submit\" name=\"submit\" value=\" Log  Out \">\n";
	    echo "</center>\n";
	    echo "</form>\n";
	  }#end if table_name eq allele_table

	if ($table_name == 'genotype_table')
	  {
            $field_array = array('pedigree_table_id');
	    $value_array = array($search_terms[0]);
	    $exists_pedigree = existsValue('pedigree_table',$field_array,$value_array,$database_id);
	    if (!preg_match('/^\d+$/',$exists_pedigree))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #78: $date<br>\n";
		echo "Error in call to existsValue from edit_record.php<br>\n";
		echo "$exists_pedigree<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end error in call to exists pedigree
	    if ($exists_pedigree == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no pedigree in the database with Pedigree Table ID $search_terms[0].  Therefore there is no individual in the \n";
		echo "database with Individual Table ID $search_terms[1] and Pedigree Table ID $search_terms[0].  \n";
		echo "It appears that the pedigree and all of its individuals were deleted before you submited your request to update an individuals\n";
		echo "genotype.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if pedigree doesn't exists

	    $field_list_array = array('pedigree_table_id','individual_table_id');
	    $term_array       = array($search_terms[0],$search_terms[1]);
	    $mode_array       = array('equal','equal');
	    $indiv_rec_list = compoundTableQuery('individual_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
	    if (!is_array($indiv_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #79: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "indiv_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to compoundTableQuery
	    if (sizeof($indiv_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no individual record in the database associated with Pedigree Table ID $search_terms[0] and Individual Table ID $search_terms[1].  \n";
		echo "It appears that the pedigree and all of its individuals were deleted before you submited your request to update an individuals\n";
		echo "genotype.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no individuals
	    $indiv_rec = $indiv_rec_list[0];
	    $individual_table_id = $indiv_rec['individual_table_id'];

	    $field_list_array = array('marker_id');
	    $term             = $search_terms[2];
	    $marker_rec_list  = tableQuery('marker_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($marker_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #80: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$marker_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to distinctTableQuery
	    if (sizeof($marker_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no marker record in the database associated with Marker ID $term.  \n";
		echo "It appears that the marker and all of its genotypes were deleted from the database \n";
                echo "before you requested to update one of its genotypes.  This message was generated at $date\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no markers
	    $marker_rec = $marker_rec_list[0];

	    $field_list_array = array('individual_table_id','marker_id');
	    $term_array       = array($individual_table_id,$marker_rec['marker_id']);
	    $mode_array       = array('equal','equal');
	    $genotype_rec_list = compoundTableQuery('genotype_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
	    if (!is_array($genotype_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #81: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$indiv_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to compoundTableQuery
	    if (sizeof($genotype_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no genotype record in the database associated with Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id] \n";
		echo "for Marker Name $marker_rec[marker_name].  \n";
		echo "Either this genotype never existed, or it was deleted before you submited your request to update it.  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no genotypes
	    elseif (sizeof($genotype_rec_list) == 1){$genotype_rec = $genotype_rec_list[0];}
            else #error in data integrity
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #82: $date<br>\n";
                echo "Error in call to edit_record.php<br>\n";
                echo "User wanted to Update a Genotype Record for Individual Table ID $individual_table_id and Marker ID $marker_rec[marker_id] ";
                echo "in Database ID $database_id, but when queried the genotype table with this information multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in data integrity

	    $allele_1_id = $genotype_rec['allele_1_id'];
	    $allele_2_id = $genotype_rec['allele_2_id'];
	    $field_list_array = array('allele_id');
	    $allele_1_code_array = distinctTableQuery('allele_code','allele_table',$database_id,$field_list_array,$allele_1_id,'equal','all');
	    if (!is_array($allele_1_code_array))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #83: $date<br>\n";
		echo "Error in call to distinctTableQuery from edit_record.php<br>\n";
		echo "$allele_1_code_array<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to distinctTableQuery
	    $allele_2_code_array = distinctTableQuery('allele_code','allele_table',$database_id,$field_list_array,$allele_2_id,'equal','all');
	    if (!is_array($allele_2_code_array))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #84: $date<br>\n";
		echo "Error in call to distinctTableQuery from edit_record.php<br>\n";
		echo "allele_2_code_array<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to distinctTableQuery

	    echo "<table>\n";
	    echo "<tr>\n";
            echo "<td>Pedigree ID:</td>\n";
            echo "<td>$indiv_rec[pedigree_id]</td><td><input type=\"hidden\" name=\"pedigree_id\" value=\"$indiv_rec[pedigree_id]\"></td>\n";
            echo "</tr>\n";
	    echo "<tr>\n";
            echo "<td>Individual ID:</td>\n";
            echo "<td>$indiv_rec[individual_id]</td><td><input type=\"hidden\" name=\"individual_id\" value=\"$indiv_rec[individual_id]\"></td>\n";
            echo "</tr>\n";
	    echo "<tr>\n";
            echo "<td>Marker Name:</td><td>$marker_rec[marker_name]</td>\n";
            echo "<td><input type=\"hidden\" name=\"marker_name\" value=\"$marker_rec[marker_name]\"></td>\n";
            echo "</tr>\n";
	    echo "<tr>\n";
            echo "<td>Allele 1 Code:</td>\n";
            echo "<td><input type=\"text\" name=\"allele_1_code\" size=\"15\" maxlength=\"2\" value=\"$allele_1_code_array[0]\"></td>\n";
            echo "</tr>\n";
	    echo "<tr>\n";
            echo "<td>Allele 2 Code:</td>\n";
            echo "<td><input type=\"text\" name=\"allele_2_code\" size=\"15\" maxlength=\"2\" value=\"$allele_2_code_array[0]\"></td>\n";
            echo "</tr>\n";
	    echo "<tr>\n";
            echo "<td>Flagged:</td>\n";
            echo "<td><input type=\"text\" name=\"flagged\" size=\"15\" maxlength=\"1\" value=\"$genotype_rec[flagged]\"></td>\n";
            echo "<td>(Either 1 for Yes, or 0 for No)</td>\n";
            echo "</tr>\n";
	    echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"gentoype_id\" value=\"$genotype_rec[gentoype_id]\">\n";
	    echo "<input type=\"hidden\" name=\"individual_table_id\" value=\"$genotype_rec[individual_table_id]\">\n";
            echo "<input type=\"hidden\" name=\"pedigree_table_id\" value=\"$indiv_rec[pedigree_table_id]\">\n";
	    echo "<input type=\"hidden\" name=\"marker_id\" value=\"$genotype_rec[marker_id]\">\n";
	    echo "<input type=\"hidden\" name=\"allele_1_id\" value=\"$genotype_rec[allele_1_id]\">\n";
	    echo "<input type=\"hidden\" name=\"allele_2_id\" value=\"$genotype_rec[allele_2_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_1_code\" value=\"$allele_1_code_array[0]\">\n";
	    echo "<input type=\"hidden\" name=\"old_allele_2_code\" value=\"$allele_2_code_array[0]\">\n";
	    echo "<input type=\"hidden\" name=\"old_flagged\" value=\"$genotype_rec[flagged]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq genotype_table

	if ($table_name == 'phenotype_table')
	  {
	    $field_list_array = array('phenotype_id');
	    $term             = $search_terms[0];
	    $phenotype_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($phenotype_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #85: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$ped_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to tableQuery
	    if (sizeof($phenotype_rec_list) == '0')
	      {
                $date = ('Y-m-d H:i:s');
		echo "There is no phenotype record in the database associated with Phenotype ID $term.  \n";
		echo "It appears that the phenotype record was deleted before you submited your request to update the record.  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no phenotypes
	    $phenotype_rec = $phenotype_rec_list[0];
            $stripslashes_pheno_desc = $phenotype_rec['phenotype_description'];

	    echo "<table>\n";
	    echo "<tr><td>Phenotype Name:</td><td>$phenotype_rec[phenotype_name]</td><td><input type=\"hidden\" name=\"phenotype_name\" value=\"$phenotype_rec[phenotype_name]\"></td></tr>\n";
	    echo "<tr><td>Phenotype Description:</td><td><textarea name=\"phenotype_description\" rows=\"10\" cols=\"50\" wrap=\"virtual\">$stripslashes_pheno_desc</textarea></td></tr>\n";
	    echo "</table>\n";
            echo "<br><br>\n";
            echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"phenotype_id\" value=\"$phenotype_rec[phenotype_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_phenotype_description\" value=\"$stripslashes_pheno_desc\")>\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq phenotype_table

	if ($table_name == 'phenotype_value_table')
	  {
	    $field_array = array('pedigree_table_id');
	    $value_array = array($search_terms[0]);
	    $exists_pedigree = existsValue('pedigree_table',$field_array,$value_array,$database_id);
	    if (!preg_match('/^\d+$/',$exists_pedigree))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #86: $date<br>\n";
		echo "Error in call to existsValue from edit_record.php<br>\n";
		echo "$exists_pedigree<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end error in call to exists pedigree
	    if ($exists_pedigree == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no pedigree in the database with Pedigree Table ID $search_terms[0].  Therefore there is no individual in the \n";
		echo "database with Individual Table ID $search_terms[1] and Pedigree Table ID $search_terms[0]. It appears that this individual \n";
                echo "was deleted from the database before you submitted your request to update their phenotype value information.  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if pedigree doesn't exists

	    $field_list_array = array('pedigree_table_id','individual_table_id');
	    $term_array       = array($search_terms[0],$search_terms[1]);
	    $mode_array       = array('equal','equal');
	    $indiv_rec_list = compoundTableQuery('individual_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
	    if (!is_array($indiv_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #87: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$indiv_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to compoundTableQuery
	    if (sizeof($indiv_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no individual record in the database associated with Pedigree Table ID $search_terms[0] and Individual Table ID $search_terms[1].  \n";
		echo "It appears that this individual was deleted from the database before you submitted your request to update their phenotype value.  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no individuals
	    $indiv_rec = $indiv_rec_list[0];
	    $individual_table_id = $indiv_rec['individual_table_id'];

	    $field_list_array   = array('phenotype_id');
	    $term               = $search_terms[2];
	    $phenotype_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($phenotype_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #88: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$phenotype_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to distinctTableQuery
	    if (sizeof($phenotype_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no phenotype record in the database associated with Phenotype ID $term .  \n";
		echo "It appears that the phenotype record was deleted before you submitted your request to update the value \n";
                echo "information for Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id].  \n";
                echo "This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no phenotypes
	    $phenotype_rec = $phenotype_rec_list[0];
            $phenotype_id  = $phenotype_rec['phenotype_id'];
            $type_of_phenotype = $phenotype_rec['type_of_phenotype'];

	    $field_list_array = array('individual_table_id','phenotype_id');
	    $term_array       = array($individual_table_id,$phenotype_id);
	    $mode_array       = array('equal','equal');
	    if ($type_of_phenotype == 'qualitative')
              {$pheno_value_rec_list = compoundTableQuery('qualitative_phenotype_value_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');}
            if ($type_of_phenotype == 'quanitative')
              {$pheno_value_rec_list = compoundTableQuery('quantitative_phenotype_value_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');}
	    if (!is_array($pheno_value_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #89: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$indiv_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
              }#end if error in call to compoundTableQuery
	    if (sizeof($pheno_value_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no phenotype value record in the database associated with Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id] \n";
		echo "for Phenotype Name $phenotype_rec[phenotype_name].  \n";
		echo "It appears that it never existed, or was deleted before you submitted your request to update it.  This message was generated at $date.<br><br>\n";
                echo "You can use the Inset Phenotype Value tool on \n";
                echo "left navigation bar to insert a value for this phenotype for this individual.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no phenotype_records
	    $pheno_value_rec = $pheno_value_rec_list[0];

	    echo "<table>\n";
	    echo "<tr><td>Pedigree ID:</td><td>$indiv_rec[pedigree_id]</td><td><input type=\"hidden\" name=\"pedigree_id\" value=\"$indiv_rec[pedigree_id]\"></td></tr>\n";
	    echo "<tr><td>Individual ID:</td><td>$indiv_rec[individual_id]</td><td><input type=\"hidden\" name=\"individual_id\" value=\"$indiv_rec[individual_id]\"></td></tr>\n";
	    echo "<tr><td>Phenotype Name:</td><td>$phenotype_rec[phenotype_name]</td><td><input type=\"hidden\" name=\"phenotype_name\" value=\"$phenotype_rec[phenotype_name]\"></td></tr>\n";
	    if ($type_of_phenotype == 'qualitative')
              {echo "<tr><td>Phenotype Value:</td><td><input type=\"text\" name=\"phenotype_value\" size=\"15\" maxlength=\"52\" value=\"$pheno_value_rec[phenotype_value]\"></td</tr>\n";}
            if ($type_of_phenotype == 'quantitative')
              {echo "<tr><td>Phenotype Value:</td><td><input type=\"text\" name=\"phenotype_value\" size=\"15\" maxlength=\"255\" value=\"$pheno_value_rec[phenotype_value]\"></td</tr>\n";}
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
            echo "<input type=\"hidden\" name=\"type_of_phenotype\" value=\"$type_of_phenotype\">\n";
	    if ($type_of_phenotype == 'qualitative')
              {echo "<input type=\"hidden\" name=\"phenotype_value_id\" value=\"$pheno_value_rec[qualitative_phenotype_value_id]\">\n";}
            if ($type_of_phenotype == 'quantitative')
              {echo "<input type=\"hidden\" name=\"phenotype_value_id\" value=\"$pheno_value_rec[quantitative_phenotype_value_id]\">\n";}
	    echo "<input type=\"hidden\" name=\"phenotype_id\" value=\"$phenotype_id\">\n";
	    echo "<input type=\"hidden\" name=\"individual_table_id\" value=\"$individual_table_id\">\n";
	    echo "<input type=\"hidden\" name=\"old_phenotype_value\" value=\"$pheno_value_rec[phenotype_value]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq phenotype_value_table

	if ($table_name == 'age_group_table')
	  {
	    $field_list_array   = array('age_group_id');
	    $term               = $search_terms[0];
	    $age_group_rec_list = tableQuery($table_name,$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($age_group_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #90: $date<br>\n";
		echo "Error in call to tableQuery from edit_records.php<br>\n";
		echo "$age_group_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }
	    if (sizeof($age_group_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no Age Group record in the database associated with Age Group ID $search_terms[0].  It appears as if \n";
                echo "this age group record was deleted before you submitted your request to update it.  This message was generated at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no age_group record
	    $age_group_rec = $age_group_rec_list[0];

	    echo "<table>\n";
	    echo "<tr><td>Age Group Minimum Age:</td><td><input type=\"text\" name=\"age_group_min_age\" size=\"15\" maxlength=\"3\" value=\"$age_group_rec[age_group_min_age]\"></td></tr>\n";
	    echo "<tr><td>Age Group Maximum Age:</td><td><input type=\"text\" name=\"age_group_max_age\" size=\"15\" maxlength=\"3\" value=\"$age_group_rec[age_group_max_age]\"></td></tr>\n";
	    echo "<tr><td>Age Group Nationality:</td><td><input type=\"text\" name=\"age_group_nationality\" size=\"15\" maxlength=\"25\" value=\"$age_group_rec[age_group_nationality]\"></td></tr>\n";
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"age_group_id\" value=\"$age_group_rec[age_group_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_min_age\" value=\"$age_group_rec[age_group_min_age]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_max_age\" value=\"$age_group_rec[age_group_max_age]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_nationality\" value=\"$age_group_rec[age_group_nationality]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq age_group_table

	if ($table_name == 'age_group_phenotype_percentile_link_table')
	  {
	    $field_list_array   = array('age_group_id');
	    $term               = $search_terms[0];
	    $age_group_rec_list = tableQuery('age_group_table',$database_id,$field_list_array,$term,'equal','all');
	    if (!is_array($age_group_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #91: $date<br>\n";
		echo "Error in call to tableQuery from edit_records.php<br>\n";
		echo "$age_group_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }
	    if (sizeof($age_group_rec_list) == '0')
	      {
                $date = date('Y-m-d H:i:s');
		echo "There is no Age Group Record in the database with Age Group ID $search_terms[0].  Therefore there is no link record \n";
                echo "with Phenotype ID $search_terms[1].  It appears that the Age Group record associated with ID $search_terms[0] was deleted before \n";
                echo "you submitted your request to update the link record with phenotype $search_terms[1].  This message was genearted at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no age_group record
	    $age_group_rec = $age_group_rec_list[0];
	    $age_group_id  = $age_group_rec['age_group_id'];

	    $field_list_array   = array('phenotype_id');
	    $term               = $search_term[1];
	    $mode               = 'equal';
	    $phenotype_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$term,$mode,'all');
	    if (!is_array($phenotype_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #92: $date<br>\n";
		echo "Error in call to tableQuery from edit_record.php<br>\n";
		echo "$phenotype_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end error in call to distinctTableQuery
	    if (sizeof($phenotype_rec_list) == '0')
	      {
		echo "There is no Phenotype record in the database associated with Phenotype ID $search_terms[1].  \n";
		echo "Therefore there is no link record with Age Group ID $search_terms[0].  It appears that the Phenotype \n";
                echo "record associated with ID $search_terms[1] was deleted before \n";
                echo "you submitted your request to update the link record with age group id $search_terms[0].  This message was genearted at $date.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no phenotype record
	    $phenotype_rec = $phenotype_rec_list[0];
            $phenotype_id  = $phenotype_rec['phenotype_id'];

	    $field_list_array = array('age_group_id','phenotype_id');
	    $term_array       = array($age_group_id,$phenotype_id);
	    $mode_array       = array('equal','equal');
	    $join             = 'and';
	    $age_group_phenotype_percentile_link_rec_list = compoundTableQuery($table_name,$database_id,$field_list_array,$term_array,$mode_array,$join,'all');
	    if (!is_array($age_group_phenotype_percentile_link_rec_list))
	      {
                $date = date('Y-m-d H:i:s');
		echo "Error #93: $date<br>\n";
		echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		echo "$age_group_phenotype_percentile_link_rec_list<br><br>\n";
		echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end error in call to distinctTableQuery
	    if (sizeof($age_group_phenotype_percentile_link_rec_list) == '0')
	      {
		echo "There is no Age Group-Phenotype Percentile Link record in the database associated with Minimum Age $age_group_rec[age_group_min_age] \n";
		echo "Maximum Age $age_group_rec[age_group_max_age], Nationality $age_group_rec[age_group_nationality], and Phenotype Name $phenotype_rec[phenotype_name]. \n";
		echo "It appears as if this record never existed, or was deleted before you submitted your request to update it.  \n";
                echo "This message was generatated at $date.<br<br>\n";
                echo "You can use the Define Phenotype Percentiles tool on the left navigation bar if you would like to insert a link between this Age Group \n";
                echo "and this Phenotype.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if no phenotype record
	    $age_group_phenotype_percentile_link_rec = $age_group_phenotype_percentile_link_rec_list[0];

	    echo "<table>\n";
	    echo "<tr><td>Age Group Minimum Age:</td><td>$age_group_rec[age_group_min_age]</td></tr>\n";
	    echo "<tr><td>Age Group Maximum Age:</td><td>$age_group_rec[age_group_max_age]</td></tr>\n";
	    echo "<tr><td>Age Group Nationality:</td><td>$age_group_rec[age_group_nationality]</td></tr>\n";
	    echo "<tr><td>Phenotype Name:</td><td>$phenotype_rec[phenotype_name]</td></tr>\n";
	    echo "<tr><td>Male 10th Percentile Value:</td><td><input type=\"text\" name=\"age_group_phenotype_male_10th_percentile_value\" size=\"15\" maxlength=\"11\" value\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_male_10th_percentile_value]\"></td></tr>\n";
	    echo "<tr><td>Male 90th Percentile Value:</td><td><input type=\"text\" name=\"age_group_phenotype_male_90th_percentile_value\" size=\"15\" maxlength=\"11\" value\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_male_90th_percentile_value]\"></td></tr>\n";
	    echo "<tr><td>Female 10th Percentile Value:</td><td><input type=\"text\" name=\"age_group_phenotype_female_10th_percentile_value\" size=\"15\" maxlength=\"11\" value\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_female_10th_percentile_value]\"></td></tr>\n";
	    echo "<tr><td>Female 90th Percentile Value:</td><td><input type=\"text\" name=\"age_group_phenotype_female_90th_percentile_value\" size=\"15\" maxlength=\"11\" value\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_female_90th_percentile_value]\"></td></tr>\n";
	    echo "</table>\n";
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<input type=\"hidden\" name=\"age_group_min_age\" value=\"$age_group_rec[age_group_min_age]\">\n";
	    echo "<input type=\"hidden\" name=\"age_group_max_age\" value=\"$age_group_rec[age_group_max_age]\">\n";
	    echo "<input type=\"hidden\" name=\"age_group_nationality\" value=\"$age_group_rec[age_group_nationality]\">\n";
	    echo "<input type=\"hidden\" name=\"phenotype_name\" value=\"$phenotype_rec[phenotype_name]\">\n";
	    echo "<input type=\"hidden\" name=\"age_group_id\" value=\"$age_group_id\">\n";
	    echo "<input type=\"hidden\" name=\"phenotype_id\" value=\"$phenotype_id\">\n";
            echo "<input type=\"hidden\" name=\"age_group_phenotype_percentile_link_id\" value=\"$age_groupe_phenotype_percentile_link_rec[age_group_phenotype_percentile_link_id]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_phenotype_male_10th_percentile_value\" value=\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_male_10th_percentile_value]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_phenotype_male_90th_percentile_value\" value=\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_male_90th_percentile_value]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_phenotype_female_10th_percentile_value\" value=\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_female_10th_percentile_value]\">\n";
	    echo "<input type=\"hidden\" name=\"old_age_group_phenotype_female_90th_percentile_value\" value=\"$age_group_phenotype_percentile_link_rec[age_group_phenotype_female_90th_percentile_value]\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Update Record\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('edit_record.php');
	  }#end if table_name eq age_group_phenotype_percentile_link_table

      }#end if have table_name and search_terms

    #6     Determine if anything Changed and Update
    if ((preg_match('/\w+/',$table_name)) and
	($submit == 'Update Record'))
      {
        $rand = rand();
        $tmp_log_file = "log_file_"."$rand".".txt";
        $log_file_handle = fopen("../data/$tmp_log_file","w");
        if (!$log_file_handle)
          {
            $date = date('Y-m-d H:i:s');
            echo "Error #94: $date<br>\n";
            echo "Error in call to fopen from edit_record.php<br>\n";
            echo "Unable to open log file to keep track of when, what, and by whom data is altered in the database<br><br>\n";
	    echo "Please email the above error using the Comments/Help/Support link \n";
	    echo "on the left navigation bar.\n";
	    echo "</body></html>\n";
	    $ret_val = disconnect();
	    exit;
	  }#end error in call to fopen
        $log_file_statement = "";

	if ($table_name == 'pedigree_table')
	  {
            $updated_values     = array();
	    $update_field_array = array();
	    $update_value_array = array();

            $field_list_array = array('pedigree_table_id');
            $ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list_array,$pedigree_table_id,'equal','all');
            if (!is_array($ped_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #95: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$ped_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
	        echo "on the left navigation bar.\n";
	        echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
	        $ret_val = disconnect();
	        exit;
              }#end error in call to tableQuery
	    if (sizeof($ped_rec_list) == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "There is no pedigree record in the database for Pedigree Table ID $pedigree_table_id.  \n";
                echo "It appears that the record was deleted from the \n";
                echo "database before you submitted your request to update the record.  This message was generated at $date.\n";
                echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
                $ret_val = disconnect();
                exit;
              }#end if no pedigree
            elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
            else
              { 
                $date = date('Y-m-d H:i:s');
                echo "Error #96: $date<br>\n";
                echo "User selected to update Pedigree Table ID $pedigree_table_id.  But when query the pedigree table with that ID, \n";
                echo "multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
	        echo "on the left navigation bar.\n";
	        echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
	        $ret_val = disconnect();
	        exit;
              }#end error in data integritiy 
	      
	    if ($_POST['old_nationality'] != $nationality)
	      {
		$update_field_array[] = 'nationality';
		$update_value_array[] = $nationality;
	      }#end if new nationality

	    if ($_POST['old_number_in_pedigree'] != $num_in_ped)
	      {
		$update_field_array[] = 'number_in_pedigree';
		$update_value_array[] = $num_in_ped;
              }#end if new number_in_ped

	    $field_list_array = array('affection_status_id');
            $affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,'_','wildcard','all');
            if (!is_array($affection_status_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #97:$date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$affection_status_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
		$ret_val = disconnect();
		exit;
              }
            if (sizeof($affection_status_rec_list) > '0')
              {
	        foreach ($affection_status_rec_list as $affection_status_rec)
	          {
		    $old_name   = "old_number_".$affection_status_rec['affection_status_name']."_affected_in_pedigree";
                    $field_name = "number_".$affection_status_rec['affection_status_name']."_affected_in_pedigree";
		    if ($_POST[$old_name] != $_POST[$field_name])
		      {
                        $field_list_array = array('affection_status_id','pedigree_table_id');
                        $term_array       = array($affection_status_rec['affection_status_id'],$pedigree_table_id);
                        $mode_array       = array('equal','equal');
                        $ped_affect_link_rec_list = compoundTableQuery('pedigree_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
                        if (!is_array($ped_affect_link_rec_list))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #98: $date<br>\n";
                            echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
                            echo "$ped_affect_link_rec_list<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar.\n";
		            echo "</body></html>\n";
                            fclose($log_file_handle);
                            chmod("../data/$tmp_log_file",0777);
                            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                            exec($command,$output_array,$return_code);
                            $command = "rm ../data/$tmp_log_file";
                            exec($command,$output_array,$return_code);
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
			if (sizeof($ped_affect_link_rec_list) == '0')
                          {
                            $ret_val = insertPedigreeAffectionStatusLink($database_id,$affection_status_rec['affection_status_id'],$pedigree_table_id,$_POST[$field_name]);
                            if ($ret_val != '1')
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #99: $date<br>\n";
                                echo "Error in call to insertPedigreeAffectionStatus from edit_record.php<br>\n";
                                echo "$ret_val<br><br>\n";
                                echo "Please email the above error message using the Comments/Help/Support link \n";
		                echo "on the left navigation bar.\n";
		                echo "</body></html>\n";
                                fclose($log_file_handle);
                                chmod("../data/$tmp_log_file",0777);
                                $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                                exec($command,$output_array,$return_code);
                                $command = "rm ../data/$tmp_log_file";
                                exec($command,$output_array,$return_code);
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to insertPedigreeAffectionStatusLink
                            $date = date('Y-m-d H:i:s');
                            $log_file_statement = "$date:\t$_SESSION[user_name] Inserted a Pedigree Affection Status Link for ";
                            $log_file_statement.= "Affection Status ID $affection_status_rec[affection_status_id] and ";
                            $log_file_statement.= "Pedigree Table ID $pedigree_table_id in Database ID $database_id.\n";
                            fwrite($log_file_handle,$log_file_statement);
			  }#end if no link record
			elseif (sizeof($ped_affect_link_rec_list) == '1')
                          {
                            $ped_affect_link_rec = $ped_affect_link_rec_list[0];
                            $ped_affect_link_id  = $ped_affect_link_rec['pedigree_affection_status_link_id'];
                            $update_field = array('number_affected_in_pedigree');
                            $update_value = array($_POST[$field_name]);
                            $ret_val      = updateRecord('pedigree_affection_status_link_table',$ped_affect_link_id,$update_field,$update_value);
                            if ($ret_val != '1')
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #100: $date<br>\n";
                                echo "Error in call to updateRecord from edit_record.php<br>\n";
                                echo "$ret_val<br><br>\n";
                                echo "Please email the above error message using the Comments/Help/Support link \n";
		                echo "on the left navigation bar.\n";
		                echo "</body></html>\n";
                                fclose($log_file_handle);
                                chmod("../data/$tmp_log_file",0777);
                                $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                                exec($command,$output_array,$return_code);
                                $command = "rm ../data/$tmp_log_file";
                                exec($command,$output_array,$return_code);
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to updateRecord
                            $date = date('Y-m-d H:i:s');
                            $log_file_statement = "$date:\t$_SESSION[user_name] Updated Pedigree Affection Status Link ID $ped_affect_link_id for ";
                            $log_file_statement.= "Affection Status ID $affection_status_rec[affection_status_id] and ";
                            $log_file_statement.= "Pedigree Table ID $pedigree_table_id  in Database ID $database_id, ";
                            $log_file_statement.= "set $field_name to $_POST[$field_name].\n";
                            fwrite($log_file_handle,$log_file_statement);
			    $updated_values[$field_name] = $_POST[$field_name];
                          }#end if have link record
                        else
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #101: $date<br>\n";
                            echo "User wanted to update Pedigree Affection Status Link associated with \n";
                            echo "Affection Status ID $affection_status_rec[affection_status_id] \n";
                            echo "and Pedigree Table ID $pedigree_table_id.  But when query the Pedigree Affection Status Link Table with those IDs, \n";
                            echo "multiple records are returned<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar.\n";
		            echo "</body></html>\n";
                            fclose($log_file_handle);
                            chmod("../data/$tmp_log_file",0777);
                            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                            exec($command,$output_array,$return_code);
                            $command = "rm ../data/$tmp_log_file";
                            exec($command,$output_array,$return_code);
		            $ret_val = disconnect();
		            exit;
                          }#end else error in data integrity
		      }#end if updated value
	          }#end foreach affection status
              }#end if defined affection statuses

	    if (sizeof($update_field_array) > '0')
	      {
                $ret_val = updateRecord('pedigree_table',$pedigree_table_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #102: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                    exec($command,$output_array,$return_code);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                $date = date('Y-m-d H:i:s');
                $log_file_statement = "$date:\t$_SESSION[user_name] Updated Pedigree Table ID $pedigree_table_id in Database ID $database_id, ";
		for ($i=0;$i <sizeof($update_field_array);$i++)
		  {
                    $log_file_statement.= "set $updated_field_array[$i] to $update_value_array[$i],";
                    $updated_values[$updated_field_array[$i]] = $update_value_array[$i];
		  }#end for each updated field
                $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                $log_file_statement.= ".\n";
                fwrite($log_file_handle,$log_file_statement);
	      }#end if fields to update
            fclose($log_file_handle);
            chmod("../data/$tmp_log_file",0777);
            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
            exec($command,$output_array,$return_code);
            $command = "rm ../data/$tmp_log_file";
            exec($command,$output_array,$return_code);

	    if (sizeof($updated_values) > '0')
              {
                echo "Successfully updated Pedigree $ped_rec[pedigree_id] with the following information:<br>\n";
	        foreach ($updated_values as $field_name=>$field_value)
                  {
                    echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
                    echo "$field_name now has the value $field_value<br>\n";
                  }#end foreach updated_value
	      }#end if updated values
	    if (sizeof($updated_values) == '0')
	      {
		echo "Pedigree ID $ped_rec[pedigree_id] with Nationality $_POST[old_nationality] was not updated because \n";
                echo "there were no changes to the values for any of \n";
		echo "the fields in the table.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
	      }#end if(sizeof(update_field_array) == '0')

            echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

            $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #103: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

            $user_rec_list = getAllUsers();
            if (!is_array($user_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #104: $date<br>\n";
                echo "Error in call to getAllUsers from edit_record.php<br>\n";
                echo "$user_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getAllUsers
	    foreach ($user_rec_list as $user_rec)
              {
                if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
              }#end foreach user

            $subject = "Updated Pedigree Information in your Genetic Studies Database";
            $message = "Updated Pedigree $ped_rec[pedigree_id] in database $database_rec[database_name].  The following is the updated information for the pedigree:\n";
            foreach ($updated_values as $field_name=>$field_value)
              {
                $message.= "$field_name now has the value $field_value\n";
              }#end foreach updated_value
            $header  = "From: $root_email";


            $field_list = array('user_database_link_id');
            $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
            if (!is_array($user_database_link_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo"Error #105: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$user_database_link_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to tableQuery
	    if (sizeof($user_database_link_rec_list) > '0')
              {
                foreach ($user_database_link_rec_list as $user_database_link_rec)
                  {
                    $user_id = $user_database_link_rec['user_id'];
                    $field_list = array('user_id');
                    $user_rec_list = getUser($user_id);
                    if (!is_array($user_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #106: $date<br>\n";
                        echo "Error in call to getUser from edit_record.php<br>\n";
                        echo "$user_rec_list<br><br>\n";
                        echo "Please email the above error using the Comments/Help/Support link on the \n";
                        echo "left navigation bar.\n";
                        echo "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end error in call to getUser
		    if (sizeof($user_rec_list) == '0') {continue;}
                    elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                    else
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #107: $date<br>\n";
                        echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                        echo "with that id multiple records were returned.<br><br>\n";
                        echo "Please email the above error using the Comments/Help/Support link on the \n";
                        echo "left navigation bar.\n";
                        echo "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end error in data integrity
		    $user_email_address = $user_rec['user_email'];

                    $ret_val = mail($user_email_address,$subject,$message,$header);
                    #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                    #else           {echo "Sent an update email to user $user_name<br>\n";}
                  }#end foreach user associated with database
	      }#end if have users associated with database
	    echo "Finished sending update emails to all the users<br>\n";
	  }#end if table_name eq 'pedigree_table'

	if ($table_name == 'individual_table')
	  {
            $updated_values     = array();
	    $update_field_array = array();
	    $update_value_array = array();

            $field_list_array = array('individual_table_id');
            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$individual_table_id,'equal','all');
            if (!is_array($indiv_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #108: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$indiv_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
	        echo "on the left navigation bar.\n";
	        echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
	        $ret_val = disconnect();
	        exit;
              }#end error in call to tableQuery
	    if (sizeof($indiv_rec_list) == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "There is no individual record in the database for Individual Table ID $individual_table_id.  \n";
                echo "It appears that the record was deleted from the \n";
                echo "database before you submitted your request to update the record.  This message was generated at $date.\n";
                echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
                $ret_val = disconnect();
                exit;
              }#end if no pedigree
            elseif (sizeof($indiv_rec_list) == '1') {$indiv_rec = $indiv_rec_list[0];}
            else
              { 
                $date = date('Y-m-d H:i:s');
                echo "Error #109: $date<br>\n";
                echo "User selected to update Individual Table ID $individual_table_id.  But when query the individual table with that ID, \n";
                echo "multiple records were returned.<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
	        echo "on the left navigation bar.\n";
	        echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
	        $ret_val = disconnect();
	        exit;
              }#end error in data integritiy
	      
	    if ($_POST['old_father_id'] != $father_id) 
	      {
		$update_field_array[] = 'father_id';
		$update_value_array[] = $father_id;
	      }#end if new father_id

	    if ($_POST['old_mother_id'] != $mother_id)
	      {
		$update_field_array[] = 'mother_id';
		$update_value_array[] = $mother_id;
	      }#end if new mother_id

	    if ($_POST['old_sex'] != $sex)
	      {
		$update_field_array[] = 'sex';
		$update_value_array[] = $sex;
              }#end if new sex
	      
	    if ($_POST['old_position_in_family'] != $position_in_family)
	      {
		$update_field_array[] = 'position_in_family';
		$update_value_array[] = $position_in_family;
              }#end if new position_in_family

	    $field_list_array = array('affection_status_id');
            $affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,'_','wildcard','all');
            if (!is_array($affection_status_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #110:$date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$affection_status_rec_list<br><br>\n";
                echo "Please email the above error message using the Comments/Help/Support link \n";
		echo "on the left navigation bar.\n";
		echo "</body></html>\n";
                fclose($log_file_handle);
                chmod("../data/$tmp_log_file",0777);
                $command = "rm ../data/$tmp_log_file";
                exec($command,$output_array,$return_code);
		$ret_val = disconnect();
		exit;
              }
            if (sizeof($affection_status_rec_list) > '0')
              {
	        foreach ($affection_status_rec_list as $affection_status_rec)
	          {
		    $old_name   = "old_".$affection_status_rec['affection_status_name']."_affection_status";
                    $field_name = "$affection_status_rec[affection_status_name]"."_affection_status";
		    if ($_POST[$old_name] != $_POST[$field_name])
		      {
                        $field_list_array = array('affection_status_id','individual_table_id');
                        $term_array       = array($affection_status_rec['affection_status_id'],$individual_table_id);
                        $mode_array       = array('equal','equal');
                        $indiv_affect_link_rec_list = compoundTableQuery('individual_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
                        if (!is_array($indiv_affect_link_rec_list))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #111: $date<br>\n";
                            echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
                            echo "$indiv_affect_link_rec_list<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar.\n";
		            echo "</body></html>\n";
                            fclose($log_file_handle);
                            chmod("../data/$tmp_log_file",0777);
                            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                            exec($command,$output_array,$return_code);
                            $command = "rm ../data/$tmp_log_file";
                            exec($command,$output_array,$return_code);
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
			if (sizeof($indiv_affect_link_rec_list) == '0')
                          {
                            $ret_val = insertIndividualAffectionStatusLink($database_id,$affection_status_rec['affection_status_id'],$individual_table_id,$_POST[$field_name]);
                            if ($ret_val != '1')
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #112: $date<br>\n";
                                echo "Error in call to insertPedigreeAffectionStatus from edit_record.php<br>\n";
                                echo "$ret_val<br><br>\n";
                                echo "Please email the above error message using the Comments/Help/Support link \n";
		                echo "on the left navigation bar.\n";
		                echo "</body></html>\n";
                                fclose($log_file_handle);
                                chmod("../data/$tmp_log_file",0777);
                                $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                                exec($command,$output_array,$return_code);
                                $command = "rm ../data/$tmp_log_file";
                                exec($command,$output_array,$return_code);
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to insertPedigreeAffectionStatusLink
                            $date = date('Y-m-d H:i:s');
                            $log_file_statement = "$date:\t$_SESSION[user_name] Inserted an Individual Affection Status Link for ";
                            $log_file_statement.= "Affection Status ID $affection_status_rec[affection_status_id] and ";
                            $log_file_statement.= "Individual Table ID $individual_table_id in Database ID $database_id.\n";
                            fwrite($log_file_handle,$log_file_statement);
			  }#end if no link record
			elseif (sizeof($indiv_affect_link_rec_list) == '1')
                          {
                            $indiv_affect_link_rec = $indiv_affect_link_rec_list[0];
                            $indiv_affect_link_id  = $indiv_affect_link_rec['individual_affection_status_link_id'];
                            $update_field = array('individual_affection_status');
                            $update_value = array($_POST[$field_name]);
                            $ret_val      = updateRecord('individual_affection_status_link_table',$indiv_affect_link_id,$update_field,$update_value);
                            if ($ret_val != '1')
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #113: $date<br>\n";
                                echo "Error in call to updateRecord from edit_record.php<br>\n";
                                echo "$ret_val<br><br>\n";
                                echo "Please email the above error message using the Comments/Help/Support link \n";
		                echo "on the left navigation bar.\n";
		                echo "</body></html>\n";
                                fclose($log_file_handle);
                                chmod("../data/$tmp_log_file",0777);
                                $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                                exec($command,$output_array,$return_code);
                                $command = "rm ../data/$tmp_log_file";
                                exec($command,$output_array,$return_code);
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to updateRecord
                            $date = date('Y-m-d H:i:s');
                            $log_file_statement = "$date:\t$_SESSION[user_name] Updated Individual Affection Status Link ID $indiv_affect_link_id for ";
                            $log_file_statement.= "Affection Status ID $affection_status_rec[affection_status_id] and ";
                            $log_file_statement.= "Individual Table ID $individual_table_id in Database ID $database_id, set ";
                            $log_file_statement.= "$field_name to $_POST[$field_name].\n";
                            fwrite($log_file_handle,$log_file_statement);
			    $updated_values[$field_name] = $_POST[$field_name];
                          }#end if have link record
                        else
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #114: $date<br>\n";
                            echo "User wanted to update Individual Affection Status Link associated with Affection Status ID $affection_status_rec[affection_status_id] \n";
                            echo "and Individual Table ID $individual_table_id.  But when query the Individual Affection Status Link Table with those IDs, \n";
                            echo "multiple records are returned<br><br>\n";
                            echo "Please email the above error message using the Comments/Help/Support link \n";
		            echo "on the left navigation bar.\n";
		            echo "</body></html>\n";
                            fclose($log_file_handle);
                            chmod("../data/$tmp_log_file",0777);
                            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                            exec($command,$output_array,$return_code);
                            $command = "rm ../data/$tmp_log_file";
                            exec($command,$output_array,$return_code);
		            $ret_val = disconnect();
		            exit;
                          }#end else error in data integrity
		      }#end if updated value
	          }#end foreach affection status
              }#end if defined affection statuses

	    if (sizeof($update_field_array) > '0')
	      {
		$ret_val = updateRecord('individual_table',$individual_table_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #115: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br><br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                    exec($command,$output_array,$return_code);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                $date = date('Y-m-d H:i:s');
                $log_file_statement = "$date:\t$_SESSION[user_name] Updated Individual Table ID $individual_table_id in Database ID $database_id ";
		for ($i=0;$i <sizeof($update_field_array);$i++)
		  {
                    $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i], ";
		    $updated_values[$update_field_array[$i]] = $update_value_array[$i];
		  }#end for each updated field
                $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                $log_file_statement.= ".\n";
                fwrite($log_file_handle,$log_file_statement);
	      }#end if fields to update
            fclose($log_file_handle);
            chmod("../data/$tmp_log_file",0777);
            $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
            exec($command,$output_array,$return_code);
            $command = "rm ../data/$tmp_log_file";
            exec($command,$output_array,$return_code);

	    if (sizeof($updated_value) > '0')
              {
                echo "Successfully updated Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id] with the following information:<br>\n";
	        foreach ($updated_values as $field_name=>$field_value)
                  {
                    echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
                    echo "$field_name now has the value $field_value<br>\n";
                  }#end foreach updated_value
	      }#end if updated values
	    if (sizeof($updated_values) == '0')
	      {
		echo "Individual ID $indiv_rec[individual_id] in Pedigree ID $indiv_rec[pedigree_id] was not updated because there were no changes to the values for any of \n";
		echo "the fields in the table.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
	      }#end if(sizeof(update_field_array) == '0')

            echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

            $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #116: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

            $user_rec_list = getAllUsers();
            if (!is_array($user_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #117: $date<br>\n";
                echo "Error in call to getAllUsers from edit_record.php<br>\n";
                echo "$user_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getAllUsers
 	    foreach ($user_rec_list as $user_rec)
              {
                if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
              }#end foreach user

            $subject = "Updated Individual Information in your Genetic Studies Database";
            $message = "Updated information for Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id] in database $database_rec[database_name].  ";
            $message.= "The new information is:\n";
            foreach ($updated_values as $field_name=>$field_value)
              {
                $message.= "$field_name now has the value $field_value<br>\n";
              }#end foreach updated_value
            $header  = "From: $root_email";


            $field_list = array('user_database_link_id');
            $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
            if (!is_array($user_database_link_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo"Error #118: $date<br>\n";
                echo "Error in call to tableQuery from edit_record.php<br>\n";
                echo "$user_database_link_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to tableQuery
	    if (sizeof($user_database_link_rec_list) > '0')
              {
                foreach ($user_database_link_rec_list as $user_database_link_rec)
                  {
                    $user_id = $user_database_link_rec['user_id'];
                    $field_list = array('user_id');
                    $user_rec_list = getUser($user_id);
                    if (!is_array($user_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #119: $date<br>\n";
                        echo "Error in call to getUser from edit_record.php<br>\n";
                        echo "$user_rec_list<br><br>\n";
                        echo "Please email the above error using the Comments/Help/Support link on the \n";
                        echo "left navigation bar.\n";
                        echo "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end error in call to getUser
		    if (sizeof($user_rec_list) == '0') {continue;}
                    elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                    else
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #120: $date<br>\n";
                        echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                        echo "with that id multiple records were returned.<br><br>\n";
                        echo "Please email the above error using the Comments/Help/Support link on the \n";
                        echo "left navigation bar.\n";
                        echo "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end error in data integrity
		    $user_email_address = $user_rec['user_email'];

                    $ret_val = mail($user_email_address,$subject,$message,$header);
                    #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                    #else           {echo "Sent an update email to user $user_name<br>\n";}
                  }#end foreach user associated with database
	      }#end if have users associated with database
	    echo "Finished sending update emails to all the users<br>\n";
	  }#end if table_name eq 'individual_table'

	if ($table_name == 'pedigree_group_table')
          {
            $update_field_array = array();
            $update_value_array = array();

            if ($_POST['old_pedigree_group_description'] != $pedigree_group_description)
              {
                $update_field_array[] = 'pedigree_group_description';
                $update_value_array[] = $pedigree_group_description;
              }

            if (sizeof($update_field_array) > '0')
	      {
		$ret_val = updateRecord('pedigree_group_table',$pedigree_group_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #121: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Pedigree Group ID $pedigree_group_id in Database ID $database_id ";
		 echo "Pedigree Group Name $pedigree_group_name was successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "Pedigree Group Name $pedigree_group_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
             if (!is_array($database_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #122: $date<br>\n";
                 echo "Error in call to getDatabase from edit_record.php<br>\n";
                 echo "$database_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getDatabase
             $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #123: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Pedigree Group Information in your Genetic Studies Database";
             $message = "The Pedigree Group $pedigree_group_name was updated in database $database_rec[database_name].  The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #124: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #125: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #126: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'pedigree_group_table'

        if ($table_name == 'individual_group_table')
          {
            $update_field_array = array();
            $update_value_array = array();

            if ($_POST['old_individual_group_description'] != $individual_group_description)
              {
                $update_field_array[] = 'individual_group_description';
                $update_value_array[] = $individual_group_description;
              }

            if (sizeof($update_field_array) > '0')
	      {
		$ret_val = updateRecord('individual_group_table',$individual_group_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #127: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Individual Group ID $individual_group_id in Database ID $database_id ";
		 echo "Individual Group Name $individual_group_name was successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statment.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "Individual Group Name $individual_group_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #128: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #129: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Individual Group Information in your Genetic Studies Database";
             $message = "The Individual Group $individual_group_name was updated in database $database_rec[database_name].  The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #130: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #131: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #132: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'individual_group_table'

        if ($table_name == 'affection_status_table')
          {
            $update_field_array = array();
            $update_value_array = array();

            if ($_POST['old_affection_status_description'] != $affection_status_description)
              {
                $update_field_array[] = 'affection_status_description';
                $update_value_array[] = $affection_status_description;
              }

            if (sizeof($update_field_array) > '0')
	      {
		$ret_val = updateRecord('affection_status_table',$affection_status_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #133: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Affection Status ID $affection_status_id in Database ID $database_id ";
		 echo "Affection Status $affection_status_name was successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "Affection Status $affection_status_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #134: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #135: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Affection Status Information in your Genetic Studies Database";
             $message = "The Affection Status $affection_status_name was updated in database $database_rec[database_name].  ";
             $message.= "The new information for this affection status is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #136: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #137: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #138: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'affection_status_table'

	if ($table_name == 'gene_table')
	  {
	    $update_field_array = array();
	    $update_value_array = array();
	      
	    if ($_POST['old_chromosome'] != $chr)
	      {
		echo "old_chromosome = $_POST[old_chromosome], and chr = $chr<br>\n";
		$update_field_array[] = 'chromosome';
		$update_value_array[] = $chr;
	      }#end if new chromosome

	    if ($_POST['old_gene_start_position'] != $gene_start)
	      {
		$update_field_array[] = 'gene_start_position';
		$update_value_array[] = $gene_start;
              }#end if new gene start

	    if ($_POST['old_gene_stop_position'] != $gene_stop)
	      {
		echo "old_gene_stop_position = $_POST[old_gene_stop_position], and gene_stop = $gene_stop<br>\n";
		$update_field_array[] = 'gene_stop_position';
		$update_value_array[] = $gene_stop;
              }#end if new gene stop
	      
	    if ($_POST['old_number_of_exons'] != $num_exons)
	      {
		$update_field_array[] = 'number_of_exons';
		$update_value_array[] = $num_exons;
              }#end if new num exons
	      
	    if ($_POST['old_number_of_introns'] != $num_introns)
	      {
		$update_field_array[] = 'number_of_introns';
		$update_value_array[] = $num_introns;
              }#end if new number introns

	    if ($_POST['old_gene_description'] != $gene_desc)
	      {
		$update_field_array[] = 'gene_description';
		$update_value_array[] = $gene_desc;
              }#end if new gene desc

	    if (sizeof($update_field_array) > '0')
	      {
		$ret_val = updateRecord('gene_table',$gene_id,$update_field_array,$update_value_array);
		if ($ret_val != '1')
		  {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #139: $date<br>\n";
		    echo "Error in call to updateRecord from edit_record.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error message using the Comments/Help/Support link \n";
		    echo "on the left navigation bar.\n";
		    echo "</body></html>\n";
                    fclose($log_file_handle);
                    chmod("../data/$tmp_log_file",0777);
                    $command = "rm ../data/$tmp_log_file";
                    exec($command,$output_array,$return_code);
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Gene ID $gene_id in Database ID $database_id ";
		 echo "Gene Name $gene_name was successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "Gene Name $gene_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #140: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #141: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Gene Information in your Genetic Studies Database";
             $message = "The Gene $gene_name was updated in database $database_rec[database_name].  The new information for this gene is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #142: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #143: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #144: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'gene_table'

	 if ($table_name == 'marker_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();
	      
	     if ($_POST['old_marker_type'] != $marker_type)
	       {
		 $update_field_array[] = 'marker_type';
		 $update_value_array[] = $marker_type;
	       }#end if new father_id

	     if ($_POST['old_chromosome'] != $chr)
	       {
		 $update_field_array[] = 'chromosome';
		 $update_value_array[] = $chr;
	       }#end if new chromosome

	     if ($_POST['old_chromosome_position'] != $chr_pos)
	       {
		 $update_field_array[] = 'chromosome_position';
		 $update_value_array[] = $chr_pos;
	       }#end if new sex
	      
	     if ($_POST['gene_position'] != $gene_pos)
	       {
		 $update_field_array[] = 'gene_position';
		 $update_value_array[] = $gene_pos;
	       }#end if new gene pos
	      
	     if ($_POST['old_tag_snp'] != $tag_snp)
	       {
		 $update_field_array[] = 'tag_snp';
		 $update_value_array[] = $tag_snp;
               }#end if new tag_snp

	     if ($_POST['old_amino_acid_change'] != $aa_change)
	       {
		 $update_field_array[] = 'amino_acid_change';
		 $update_value_array[] = $aa_change;
	       }#end if new aa change

	     if ($_POST['old_number_of_alleles'] != $num_alleles)
	       {
		 $update_field_array[] = 'number_of_alleles';
		 $update_value_array[] = $num_alleles;
	       }#end if new num alleles

	     if ($_POST['old_hardy_weinburg_equilibrium'] != $hw_equil)
	       {
		 $update_field_array[] = 'hardy_weinburg_equilibrium';
		 $update_value_array[] = $hw_equil;
	       }#end if new hardy-weinburg

	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord('marker_table',$marker_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #145: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Marker ID $marker_id in Database ID $database_id ";
		 echo "Marker Name $marker_name was successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "Marker Name $marker_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
             if (!is_array($database_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #146: $date<br>\n";
                 echo "Error in call to getDatabase from edit_record.php<br>\n";
                 echo "$database_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getDatabase
             $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #147: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Marker Information in your Genetic Studies Database";
             $message = "The Marker $marker_name was updated in database $database_rec[database_name].  The new information for this marker is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #148: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #149: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #150: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'marker_table'

         if ($table_name == 'map_table')
           {
             $update_field_array = array();
	     $update_value_array = array();
             if ($type_of_update == 'map_info')
               {
                 if ($_POST['old_distance_measure'] != $dist_measure)
                   {
                     $update_field_array[] = 'distance_measure';
                     $update_value_array[] = $dist_measure;
                   }#end if distance measure changed
                 if ($_POST['old_map_description'] != $map_description)
                   {
                     $update_field_array[] = 'map_description';
                     $update_value_array[] = $map_description;
                   }#end if description changed

                 if (sizeof($update_field_array) > '0')
	           {
		     $ret_val = updateRecord('map_table',$map_id,$update_field_array,$update_value_array);
		     if ($ret_val != '1')
		       {
                         $date = date('Y-m-d H:i:s');
		         echo "Error #151: $date<br>\n";
		         echo "Error in call to updateRecord from edit_record.php<br>\n";
		         echo "$ret_val<br><br>\n";
		         echo "Please email the above error message using the Comments/Help/Support link \n";
		         echo "on the left navigation bar.\n";
		         echo "</body></html>\n";
                         fclose($log_file_handle);
                         chmod("../data/$tmp_log_file",0777);
                         $command = "rm ../data/$tmp_log_file";
                         exec($command,$output_array,$return_code);
		         $ret_val = disconnect();
		         exit;
		       }#end if error in call to updateRecord
                     $date = date('Y-m-d H:i:s');
                     $log_file_statement = "$date:\t$_SESSION[user_name] Updated Map ID $map_id in Database ID $database_id ";
		     echo "Map Name $map_name was successfully updated.  The fields updated were:<br>\n";
		     for ($i=0;$i <sizeof($update_field_array);$i++)
		       {
                         $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		         echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		       }#end for each updated field
                     $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                     $log_file_statement.= ".\n";
                     fwrite($log_file_handle,$log_file_statement);
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                     exec($command,$output_array,$return_code);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
	           }#end if fields to update
	         if (sizeof($update_field_array) == '0')
	           {
		     echo "Map Name $map_name was not updated because there were no changes to the values for any of \n";
		     echo "the fields in the table.\n";
                     echo "</body></html>\n";
                     fwrite($log_file_handle,$log_file_statement);
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                     exec($command,$output_array,$return_code);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
                     $ret_val = disconnect();
                     exit;
	           }#end if(sizeof(update_field_array) == '0')

                 $subject = "Updated Map Information in your Genetic Studies Database";
                 $message = "The Map $map_name was updated in database $database_rec[database_name].  The new information for this map is:\n";
                 for ($i=0;$i <sizeof($update_field_array);$i++)
	           {
		     $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	           }#end for each updated field
                 $header  = "From: $root_email";
               }#end if type of update eq map info
             if ($type_of_update == 'marker_info')
               {
                 if ($_POST['old_marker_num_in_map'] != $marker_num_in_map)
                   {
                     $update_field_array[] = 'marker_number_in_map';
                     $update_value_array[] = $marker_num_in_map;
                   }#end if marker number in map changed
                 if ($_POST['old_distance_from_previous_marker'] != $dist_prev_marker)
                   {
                     $update_field_array[] = 'distance_from_previous_marker';
                     $update_value_array[] = $dist_prev_marker;
                   }#end if distance from previous marker changed

                 if (sizeof($update_field_array) > '0')
	           {
		     $ret_val = updateRecord('map_marker_link_table',$map_marker_link_id,$update_field_array,$update_value_array);
		     if ($ret_val != '1')
		       {
                         $date = date('Y-m-d H:i:s');
		         echo "Error #152: $date<br>\n";
		         echo "Error in call to updateRecord from edit_record.php<br>\n";
		         echo "$ret_val<br><br>\n";
		         echo "Please email the above error message using the Comments/Help/Support link \n";
		         echo "on the left navigation bar.\n";
		         echo "</body></html>\n";
                         fclose($log_file_handle);
                         chmod("../data/$tmp_log_file",0777);
                         $command = "rm ../data/$tmp_log_file";
                         exec($command,$output_array,$return_code);
		         $ret_val = disconnect();
		         exit;
		       }#end if error in call to updateRecord
                     $date = date('Y-m-d H:i:s');
                     $log_file_statement = "$date:\t$_SESSION[user_name] Updated Map Marker Link ID $map_marker_link_id in Database ID $database_id ";
		     echo "Marker $marker_name in Map $map_name was successfully updated.  The fields updated were:<br>\n";
		     for ($i=0;$i <sizeof($update_field_array);$i++)
		       {
                         $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		         echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		       }#end for each updated field
                     $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                     $log_file_statement.= ".\n";
                     fwrite($log_file_handle,$log_file_statement);
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                     exec($command,$output_array,$return_code);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
	           }#end if fields to update
	         if (sizeof($update_field_array) == '0')
	           {
		     echo "Marker $marker_name in Map $map_name was not updated because there were no changes to the values for any of \n";
		     echo "the fields in the table.\n";
                     echo "</body></html>\n";
                     fwrite($log_file_handle,$log_file_statement);
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                     exec($command,$output_array,$return_code);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
                     $ret_val = disconnect();
                     exit;
	           }#end if(sizeof(update_field_array) == '0')

                 $subject = "Updated Marker Information for a Map in your Genetic Studies Database";
                 $message = "The Marker $marker_name in Map $map_name was updated in database $database_rec[database_name].  ";
                 $message.= "The new information for this map is:\n";
                 for ($i=0;$i <sizeof($update_field_array);$i++)
	           {
		     $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	           }#end for each updated field
                 $header  = "From: $root_email";
               }#end if type of update eq marker info

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
             if (!is_array($database_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #153: $date<br>\n";
                 echo "Error in call to getDatabase from edit_record.php<br>\n";
                 echo "$database_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getDatabase
             $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #154: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #155: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #156: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #157: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
           }#end if table name eq map table

	 if ($table_name == 'allele_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();
	      
	     if ($_POST['old_allele_size'] != $allele_size)
	       {
		 $update_field_array[] = 'allele_size';
		 $update_value_array[] = $allele_size;
	       }#end if new allele size

	     if ($_POST['old_allele_sequence'] != $allele_seq)
	       {
		 $update_field_array[] = 'allele_sequence';
		 $update_value_array[] = $allele_seq;
	       }#end if new allele seq

	     if ($_POST['old_allele_frequency'] != $allele_freq)
	       {
		 $update_field_array[] = 'allele_frequency';
		 $update_value_array[] = $allele_freq;
	       }#end if new allele freq
	      
	     if ($_POST['old_allele_illumina_code'] != $illumina_code)
	       {
		 $update_field_array[] = 'allele_illumina_code';
		 $update_value_array[] = $illumina_code;
	       }#end if new illumina_code
	      
	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord('allele_table',$allele_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #158: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Allele ID $allele_id in Database ID $database_id ";
		 echo "The Allele Coded $allele_code for Marker Name $marker_name successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Allele Coded $allele_code for Marker Name $marker_name was not updated because there were no changes to the values for any of \n";
		 echo "the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #159: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #160: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Allele Information in your Genetic Studies Database";
             $message = "The Allele which is coded $allele_code for Marker $marker_name was updated in database $database_rec[database_name].  The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #161: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #162: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #163: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq 'allele_table'

	 if ($table_name == 'genotype_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();

	     if ($_POST['old_allele_1_code'] != $allele_1_code)
	       {
		 $field_list_array = array('marker_id','allele_code');
		 $term_array       = array($marker_id,$allele_1_code);
		 $mode_array       = array('equal','equal');
		 $allele1_rec_list = compoundTableQuery('allele_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
		 if (!is_array($allele1_rec_list))
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #164: $date<br>\n";
		     echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		     echo "$allele1_rec_list<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to compoundTableQuery
		 if (sizeof($allele1_rec_list) == '0')
		   {
		     echo "The genotype for Individual ID $individual_id in Pedigree ID $pedigree_id for Marker Name $marker_name \n";
		     echo "was not updated.  The new Allele Code allele_1_code for allele 1 is not associated with an allele record \n";
		     echo "that is already in the database.  Please check that you entered the correct allele code or use the Allele Search \n";
		     echo "tool to assist you.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if not alleles
		 $allele1_rec = $allele1_rec_list[0];
		 $allele_1_id = $allele1_rec['allele_id'];
		 $update_field_array[] = 'allele_1_id';
		 $update_value_array[] = $allele_1_id;
	       }#end if have new allele 1 code

	     if ($_POST['old_allele_2_code'] != $allele_2_code)
	       {
		 $field_list_array = array('marker_id','allele_code');
		 $term_array       = array($marker_id,$allele_2_code);
		 $mode_array       = array('equal','equal');
		 $allele2_rec_list = compoundTableQuery('allele_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
		 if (!is_array($allele2_rec_list))
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #165: $date<br>\n";
		     echo "Error in call to compoundTableQuery from edit_record.php<br>\n";
		     echo "$allele2_rec_list<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to compoundTableQuery
		 if (sizeof($allele2_rec_list) == '0')
		   {
		     echo "The genotype for Individual ID $individual_id in Pedigree ID $pedigree_id for Marker Name $marker_name \n";
		     echo "was not updated.  The new Allele Code allele_2_code for allele 2 is not associated with an allele record \n";
		     echo "that is already in the database.  Please check that you entered the correct allele code or use the Allele Search \n";
		     echo "tool to assist you.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if not alleles
		 $allele2_rec = $allele2_rec_list[0];
		 $allele_2_id = $allele2_rec['allele_id'];
		 $update_field_array[] = 'allele_2_id';
		 $update_value_array[] = $allele_2_id;
	       }#end if have new allele 2 code

	     if ($_POST['old_flagged'] != $flagged)
	       {
		 if (($flagged != '1') and ($flagged != '0'))
		   {
		     echo "The genotype for Individual ID $individual_id in Pedigree ID $pedigree_id for Marker Name $marker_name \n";
		     echo "was not updated.  The flagged field must either be 1 for yes this is a flagged genotype, or 0 for no \n";
		     echo "this is not a flagged genotype.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if incorrect flagged value
		 else
		   {
		     $update_field_array[] = 'flagged';
		     $update_field_array[] = $flagged;
		   }#end else correct flagged value
	       }#end if new flagged value

	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord('genotype_table',$genotype_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #166: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Genotype ID $genotype_id in Database ID $database_id ";
		 echo "The Genotype for Individual ID $individual_id in Pedigree $pedigree_id for Marker Name $marker_name successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Genotype for Individual ID $individual_id in Pedigree $pedigree_id for Marker Name $marker_name was not updated \n";
		 echo "because there were no changes to the values for any of the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #167: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #168: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Genotype Information in your Genetic Studies Database";
             $message = "The Genotype for Individual $individual_id in Pedigree $pedigree_id for Marker $marker_name was updated in database $database_rec[database_name].  ";
             $message.= "The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #169: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #170: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #171: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name == genotype_table

	 if ($table_name == 'phenotype_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();
		 
	     if ($_POST['old_phenotype_description'] != $phenotype_desc)
	       {
		 $update_field_array[] = 'phenotype_description';
		 $update_field_array[] = $phenotype_desc;
	       }#end if new phenotype description

	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord('phenotype_table',$phenotype_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #172: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Phenotype ID $phenotype_id in Database ID $database_id ";
		 echo "The Phenotype Name $phenotype_name successfully updated.  The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Phenotype Name $phenotype_name was not updated \n"; 
		 echo "because there were no changes to the values for any of the fields in the table. \n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #173: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #174: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Phenotype Information in your Genetic Studies Database";
             $message = "The Phenotype $phenotype_name was updated in database $database_rec[database_name].  The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #175: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #176: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #177: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq phenotype_table

	 if ($table_name == 'phenotype_value_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();

             $field_list_array   = array('phenotype_id');
	     $term               = $search_terms[2];
	     $phenotype_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$term,'equal','all');
	     if (!is_array($phenotype_rec_list))
	       {
                 $date = date('Y-m-d H:i:s');
		 echo "Error #178: $date<br>\n";
		 echo "Error in call to tableQuery from edit_record.php<br>\n";
		 echo "$phenotype_rec_list<br><br>\n";
		 echo "Please email the above error message using the Comments/Help/Support link \n";
		 echo "on the left navigation bar.\n";
		 echo "</form>\n";
		 echo "</body></html>\n";
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
		 $ret_val = disconnect();
		 exit;
               }#end if error in call to distinctTableQuery
	     if (sizeof($phenotype_rec_list) == '0')
	       {
                 $date = date('Y-m-d H:i:s');
		 echo "There is no phenotype record in the database associated with Phenotype ID $term .  \n";
		 echo "It appears that the phenotype record was deleted before you submitted your request to update the value \n";
                 echo "information for Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id].  \n";
                 echo "This message was generated at $date.\n";
		 echo "</form>\n";
		 echo "</body></html>\n";
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
		 $ret_val = disconnect();
		 exit;
	       }#end if no phenotypes
	     $phenotype_rec = $phenotype_rec_list[0];
             $phenotype_name  = $phenotype_rec['phenotype_name'];

	     if ($_POST['old_phenotype_value'] != $phenotype_value)
	       {
		 $update_field_array[] = 'phenotype_value';
		 $update_value_array[] = $phenotype_value;
	       }#end if new phenotype_value

	     if (sizeof($update_field_array) > '0')
	       {
		 if ($type_of_phenotype == 'qualitative')
                   {$ret_val = updateRecord('qualitative_phenotype_value_table',$phenotype_value_id,$update_field_array,$update_value_array);}
                 if ($type_of_phenotype == 'quantitative')
                   {$ret_val = updateRecord('quantitative_phenotype_value_table',$phenotype_value_id,$update_field_array,$update_value_array);}
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #179: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated ";
                 if ($type_of_phenotype == 'qualitative'){$log_file_statement.= "Qualitative Phenotype Value ID ";}
                 if ($type_of_phenotype == 'quantitative'){$log_file_statement.= "Quantitative Phenotype Value ID ";}
                 $log_file_statement.= "in Database ID $database_id ";
		 echo "The Phenotype Value Record for Individual ID $indvidual_id in Pedigree ID $pedigree_id for Phenotype Name $phenotype_name successfully updated. \n"; 
		 echo "The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Phenotype Value record for Individual ID $individual_id in Pedigree $pedigree_id for Phenotype Name $phenotype_name was not updated  \n";
		 echo "because there were no changes to the values for any of the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
             if (!is_array($database_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #180: $date<br>\n";
                 echo "Error in call to getDatabase from edit_record.php<br>\n";
                 echo "$database_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getDatabase
             $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #181: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Phenotype Value Information in your Genetic Studies Database";
             $message = "The Phenotype Value for Individual $individual_id in Pedigree $pedigree_id for Phenotype $phenotype_name ";
             $message.= "was updated in database $database_rec[database_name].  ";
             $message.= "The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #182: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #183: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #184: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq phenotype_value_table

	 if ($table_name == 'age_group_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();

	     if ($_POST['old_age_group_min_age'] != $age_group_min_age)
	       {
		 $update_field_array[] = 'age_group_min_age';
		 $update_value_array[] = $age_group_min_age;
	       }
	     if ($_POST['old_age_group_max_age'] != $age_group_max_age)
	       {
		 $update_field_array[] = 'age_group_max_age';
		 $update_value_array[] = $age_group_max_age;
	       }
	     if ($_POST['old_age_group_nationality'] != $age_group_nationality)
	       {
		 $update_field_array[] = 'age_group_nationality';
		 $update_value_array[] = $age_group_nationality;
	       }

	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord($table_name,$age_group_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #185: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Age Group ID $age_group_id in Database ID $database_id ";
		 echo "The Age Group record for Minimum Age $age_group_min_age, Maximum Age $age_group_max_age, and Nationality $age_group_nationality \n";
		 echo "was successfully updated. \n"; 
		 echo "The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Age Group record for Minimum Age $age_group_min_age, Maximum Age $age_group_max_age, and Nationality $age_group_nationality was not updated  \n";
		 echo "because there were no changes to the values for any of the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
            if (!is_array($database_rec_list))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #186: $date<br>\n";
                echo "Error in call to getDatabase from edit_record.php<br>\n";
                echo "$database_rec_list<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
                echo "left navigation bar.\n";
                echo "</body></html>\n";
                $ret_val = disconnect();
                exit;
              }#end error in call to getDatabase
            $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #187: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Age Group Information in your Genetic Studies Database";
             $message = "The Age Group with minimum age $age_group_min_age, maximum age $age_group_max_age, and nationality $age_group_nationality was updated ";
             $message.= "in database $database_rec[database_name].  ";
             $message.= "The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #188: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #189: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #190: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq age_group_table

	 if ($table_name == 'age_group_phenotype_percentile_link_table')
	   {
	     $update_field_array = array();
	     $update_value_array = array();

	     if ($_POST['old_age_group_phenotype_male_10th_percentile_value'] != $age_group_phenotype_male_10th_percentile_value)
	       {
		 $update_field_array[] = 'age_group_phenotype_male_10th_percentile_value';
		 $update_value_array[] = $age_group_phenotype_male_10th_percentile_value;
	       }
	     if ($_POST['old_age_group_phenotype_male_90th_percentile_value'] != $age_group_phenotype_male_90th_percentile_value)
	       {
		 $update_field_array[] = 'age_group_phenotype_male_90th_percentile_value';
		 $update_value_array[] = $age_group_phenotype_male_90th_percentile_value;
	       }
	     if ($_POST['old_age_group_phenotype_female_10th_percentile_value'] != $age_group_phenotype_female_10th_percentile_value)
	       {
		 $update_field_array[] = 'age_group_phenotype_female_10th_percentile_value';
		 $update_value_array[] = $age_group_phenotype_female_10th_percentile_value;
	       }
	     if ($_POST['old_age_group_phenotype_male_90th_percentile_value'] != $age_group_phenotype_female_90th_percentile_value)
	       {
		 $update_field_array[] = 'age_group_phenotype_female_90th_percentile_value';
		 $update_value_array[] = $age_group_phenotype_female_90th_percentile_value;
	       }

	     if (sizeof($update_field_array) > '0')
	       {
		 $ret_val = updateRecord($table_name,$age_group_phenotype_percentile_link_id,$update_field_array,$update_value_array);
		 if ($ret_val != '1')
		   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #191: $date<br>\n";
		     echo "Error in call to updateRecord from edit_record.php<br>\n";
		     echo "$ret_val<br><br>\n";
		     echo "Please email the above error message using the Comments/Help/Support link \n";
		     echo "on the left navigation bar.\n";
		     echo "</body></html>\n";
                     fclose($log_file_handle);
                     chmod("../data/$tmp_log_file",0777);
                     $command = "rm ../data/$tmp_log_file";
                     exec($command,$output_array,$return_code);
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to updateRecord
                 $date = date('Y-m-d H:i:s');
                 $log_file_statement = "$date:\t$_SESSION[user_name] Updated Age Group-Phenotype Percentile Link ID ";
                 $log_file_statement.= "$age_group_phenotype_percentile_link_id in Database ID $database_id ";
		 echo "The Age Group-Phenotype Precentile record for Minimum Age $age_group_min_age, Maximum Age $age_group_max_age, ";
                 echo "Nationality $age_group_nationality, \n";
		 echo "and Phenotype Name $phenotype_name was successfully updated. \n"; 
		 echo "The fields updated were:<br>\n";
		 for ($i=0;$i <sizeof($update_field_array);$i++)
		   {
                     $log_file_statement.= "set $update_field_array[$i] to $update_value_array[$i],";
		     echo "Field $update_field_array[$i] was updated with the value $update_value_array[$i]<br>\n";
		   }#end for each updated field
                 $log_file_statement = preg_replace('/,$/','',$log_file_statement);
                 $log_file_statement.= ".\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
	       }#end if fields to update
	     if (sizeof($update_field_array) == '0')
	       {
		 echo "The Age Group-Phenotype Percentile record for Minimum Age $age_group_min_age, Maximum Age $age_group_max_age, Nationality $age_group_nationality, \n";
		 echo "and Phenotype Name $was not updated  \n";
		 echo "because there were no changes to the values for any of the fields in the table.\n";
                 echo "</body></html>\n";
                 fwrite($log_file_handle,$log_file_statement);
                 fclose($log_file_handle);
                 chmod("../data/$tmp_log_file",0777);
                 $command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
                 exec($command,$output_array,$return_code);
                 $command = "rm ../data/$tmp_log_file";
                 exec($command,$output_array,$return_code);
                 $ret_val = disconnect();
                 exit;
	       }#end if(sizeof(update_field_array) == '0')

             echo "Now emailing all the users of the database to inform them of the new information in the database.<br>\n";

             $database_rec_list = getDatabase($database_id);
             if (!is_array($database_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #192: $date<br>\n";
                 echo "Error in call to getDatabase from edit_record.php<br>\n";
                 echo "$database_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getDatabase
             $database_rec = $database_rec_list[0];

             $user_rec_list = getAllUsers();
             if (!is_array($user_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo "Error #193: $date<br>\n";
                 echo "Error in call to getAllUsers from edit_record.php<br>\n";
                 echo "$user_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to getAllUsers
	     foreach ($user_rec_list as $user_rec)
               {
                 if ($user_rec['user_name'] == 'root') {$root_email = $user_rec['user_email'];}
               }#end foreach user

             $subject = "Updated Age Group Phenotype Percentile Information in your Genetic Studies Database";
             $message = "The Age Group Phenotype Percentile record for Age Group with minimum ag $age_group_min_age, ";
             $message.= "maximum age $age_group_max_age, and \n";
             $message.= "nationality $age_group_nationality for Phenotype $phenotype_name was updated in ";
             $message.= "database $database_rec[database_name].  The new information is:\n";
             for ($i=0;$i <sizeof($update_field_array);$i++)
	       {
		 $message.= "Field $update_field_array[$i] was updated with the value $update_value_array[$i]\n";
	       }#end for each updated field
             $header  = "From: $root_email";


             $field_list = array('user_database_link_id');
             $user_database_link_rec_list = tableQuery('user_database_link_table',$database_id,$field_list,'_','wildcard','all');
             if (!is_array($user_database_link_rec_list))
               {
                 $date = date('Y-m-d H:i:s');
                 echo"Error #194: $date<br>\n";
                 echo "Error in call to tableQuery from edit_record.php<br>\n";
                 echo "$user_database_link_rec_list<br><br>\n";
                 echo "Please email the above error using the Comments/Help/Support link on the \n";
                 echo "left navigation bar.\n";
                 echo "</body></html>\n";
                 $ret_val = disconnect();
                 exit;
               }#end error in call to tableQuery
	     if (sizeof($user_database_link_rec_list) > '0')
               {
                 foreach ($user_database_link_rec_list as $user_database_link_rec)
                   {
                     $user_id = $user_database_link_rec['user_id'];
                     $field_list = array('user_id');
                     $user_rec_list = getUser($user_id);
                     if (!is_array($user_rec_list))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #195: $date<br>\n";
                         echo "Error in call to getUser from edit_record.php<br>\n";
                         echo "$user_rec_list<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to getUser
		     if (sizeof($user_rec_list) == '0') {continue;}
                     elseif (sizeof($user_rec_list) == '1') {$user_rec = $user_rec_list[0];}
                     else
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #196: $date<br>\n";
                         echo "Tried to send an update email to user id $user_id, but when queried the user table \n";
                         echo "with that id multiple records were returned.<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in data integrity
		     $user_email_address = $user_rec['user_email'];

                     $ret_val = mail($user_email_address,$subject,$message,$header);
                     #if (!$ret_val) {echo "Unable to send an update email to user $user_rec[user_name]<br>\n";}
                     #else           {echo "Sent an update email to user $user_name<br>\n";}
                   }#end foreach user associated with database
	       }#end if have users associated with database
	     echo "Finished sending update emails to all the users<br>\n";
	   }#end if table_name eq age_group_phenotype_percentile_link_table

         echo "<br><br>\n";
         $ret_val = printLogOutButton('edit_record.php');
       }#end if have table_name and submit eq Update Record
   }#end if auth_user == '1'
$ret_val = disconnect();
echo "</body></html>\n";
?>
Return current item: Generic Genetic Studies Database