<?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 'html_lib.inc';
require 'sql_lib.inc';
require 'file_system_lib.inc';
#NAME insert_individuals.php
#TYPE PHP
#USES html_lib.inc(??)
# sql_lib.inc(authenticate insertPedigree insertIndividual existsPedigree existsIndividual)
#PURPOSE To get individual data from the user to insert into the database
#USAGE insert_individuals.php
#PARAMETERS
# authorized user auth_user int optional
# insert_from_file insert_from_file int optional
# file on server file_on_server string optional
# nationality nationality int optional
# pedigree id ped_id int optional
# individual id indiv_id int optional
# father id father_id int optional
# mother id mother_id int optional
# sex sex int optional
#RETURNS
# nothing
#DATASTRUCTURES No special datastructures
#FUNCTIONAL DESCRIPTION The script will authenticate the user. Then determine
# whether they want to insert from a file or from the web
# site. If from a file, parse the file and insert individuals.
# If from website, give them a form to fill out and insert the
# values they supply.
#ASSUMPTIONS
#LIMITATIONS
#COMMENTS
#PRELIMINARY DESIGN
# 1 Get Args
# 2 Authenticate User
# 3 Determine Whether they want to upload file
# 4 If from Website give form
# 5 Insert Individual from webform
# 6 Get File
# 7 Parse File and Insert
echo "<html>\n";
echo " <head>\n";
echo " <title>Insert Individuals</title>\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 "<body bgcolor = \"white\">\n";
echo "<center><h3>Insert Individuals</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo "<br>\n";
#1 Get Args
$access_type_required = 'administrative';
$DEBUG = '0';
$start_time = date('Y-m-d H:i:s');
$insert_from_file = $_POST['insert_from_file'];
$upload_file = $_POST['upload_file'];
$file_on_server = $_POST['file_name'];
$nationality = $_POST['nationality'];
$ped_id = $_POST['pedigree_id'];
$indiv_id = $_POST['individual_id'];
$father_id = $_POST['father_id'];
$mother_id = $_POST['mother_id'];
$sex = $_POST['sex'];
if ($DEBUG)
{
echo "auth_user = $auth_user<br>\n";
echo "insert_from_file = $insert_from_file<br>\n";
echo "nationality = $nationality<br>\n";
echo "ped_id = $ped_id<br>\n";
echo "indiv_id = $indiv_id<br>\n";
echo "father_id = $father_id<br>\n";
echo "mother_id = $mother_id<br>\n";
echo "sex = $sex<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 insert_individuals.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;
}
#2 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 insert_individuals.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 insert_individuals.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('insert_individuals.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 insert_individuals.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 insert_individuals.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 insert_individuals.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 insert_individuals.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('insert_individuals.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 insert_individuals.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('insert_individuals.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 insert_individuals.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 insert_individuals.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
if ($auth_user == '1')
{
$database_id = $_SESSION['database_id'];
#3 Determine Whether Insert from File or Web
if (!preg_match('/\d+/',$insert_from_file))
{
echo "<form action=\"insert_individuals.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
echo "This form allows you to insert new individuals into the database. There are two options \n";
echo "for the way to do this. If you have multiple individuals to insert you can store their \n";
echo "information in a comma-separated file, or if you only have \n";
echo "one or two individuals you can use a web form to insert their data. Please choose the method \n";
echo "you would like to choose below.<br><br>\n";
echo "<table>\n";
echo "<tr><td><input type=\"radio\" name=\"insert_from_file\" value=\"0\"></td><td>Insert Individuals Using a Web Form</td></tr>\n";
echo "<tr><td><input type=\"radio\" name=\"insert_from_file\" value=\"1\" checked></td><td>Insert Individuals Stored in a File</td></tr>\n";
echo "</table>\n";
echo "<br>\n";
echo "<table align=\"center\">\n";
echo "<tr>\n";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Insert New Individuals\"></td>\n";
echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Selection\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br><br>\n";
$ret_val = printLogOutButton('insert_individuals.php');
}#end if (!preg_match('/\d+/',insert_from_file))
#4 If Insert from Web form
if (($insert_from_file == '0') and
(!preg_match('/\w+/',$nationality)) and
(!preg_match('/\d+/',$ped_id)) and
(!preg_match('/\d+/',$indiv_id)) and
(!preg_match('/\d+/',$father_id)) and
(!preg_match('/\d+/',$mother_id)) and
(!preg_match('/\d+/',$sex))
)
{
echo "<form action=\"insert_individuals.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
echo "Please fill in the information below and then press the submit button. The \n";
echo "information will then be entered into the database.<br><br>\n";
echo "<table>\n";
echo "<tr><td align=\"right\"><b>Nationality</b></td><td> <input type=\"text\" name=\"nationality\" max_length=\"50\" size=\"15\"> (i.e. Finnish,Dutch,Mexican)</td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td align=\"right\"><b>Pedigree ID</b></td><td> <input type=\"text\" name=\"pedigree_id\" max_length=\"50\" size=\"15\"></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td align=\"right\"><b>Individual ID</b></td><td> <input type=\"text\" name=\"individual_id\" max_length=\"50\" size=\"15\"></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td align=\"right\"><b>Father ID</b></td><td> <input type=\"text\" name=\"father_id\" max_length=\"50\" size=\"15\"> (If unknown enter 0)</td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td align=\"right\"><b>Mother ID</b></td><td> <input type=\"text\" name=\"mother_id\" max_length=\"50\" size=\"15\"> (If unknown enter 0)</td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td align=\"right\"><b>Gender</b> </td><td> <input type=\"radio\" name=\"sex\" value=\"1\">Male<br> <input type=\"radio\" name=\"sex\" value=\"2\">Female</td></tr>\n";
echo "</table>\n";
echo "<br><br>\n";
echo "<input type=\"hidden\" name=\"insert_from_file\" value=\"0\">\n";
echo "<center>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Insert Individual into Database\">\n";
echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
echo "</form>\n";
echo "</center>\n";
echo "<br><br>\n";
$ret_val = printLogOutButton('insert_individuals.php');
echo "\n\n";
echo "<script>\n";
echo "function Validate(form)\n";
echo "{
if (form.ped_id.value==\"\") {
alert(\"You must enter a Pedigree ID\");
form.ped_id.focus();
return false;}
if (form.indiv_id.value==\"\"){
alert(\"You must enter an Individual ID\");
form.indiv_id.focus();
return false;}
if (form.father_id.value==\"\"){
alert(\"You must enter a Father ID\");
form.father_id.focus();
return false;}
if (form.mother_id.value==\"\"){
alert(\"You must enter a Mother ID\");
form.mother_id.focus();
return false;}
var rv=false;
for(var i=0; i<form.sex.length; i++){
if (form.sex[i].checked){rv=true}}
if(!rv){
alert(\"You must select a Sex\");
return false;}
return true;
}\n";
echo "</script>\n";
}#end if from web but no values
#5 Insert values from Web form
if (($insert_from_file == '0') and
(preg_match('/\w+/',$nationality)) and
(preg_match('/\d+/',$ped_id)) and
(preg_match('/\d+/',$indiv_id)) and
(preg_match('/\d+/',$father_id)) and
(preg_match('/\d+/',$mother_id)) and
(preg_match('/\d+/',$sex))
)
{
echo "Inserting the Individual into the database:<br>\n";
echo " <form action=\"insert_individuals.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
$inserted_individuals = array();
$inserted_pedigrees = array();
$inserted_ped_affect_links = array();
$inserted_indiv_affect_links = array();
$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 #11: $date<br>\n";
echo "Error in call to fopen from insert_individuals.php<br>\n";
echo "Unable to open the log file to keep track of what, when, and by whom data is altered in the database.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}
$log_file_statement = "";
$pedigree_field_array = array('pedigree_id');
$pedigree_value_array = array($ped_id);
$exists_pedigree = existsValue('pedigree_table',$pedigree_field_array,$pedigree_value_array,$database_id);
if (!preg_match('/\d+/',$exists_pedigree))
{
$date = date('Y-m-d H:i:s');
echo "Error #12: $date<br>\n";
echo "Error in call to existsValue from insert_individuals.php<br>\n";
echo "$exists_pedigree<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 existsValue
if ($exists_pedigree == '0')
{
echo "Pedigree ID $ped_id is not already a pedigree in the database. It will now be inserted into the database.<br>\n";
$ret_val = insertPedigree($database_id,$ped_id,$nationality);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #13: $date<br>\n";
echo "Error in call to insertPedigree from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 insertPedigree
$field_list = array('pedigree_id');
$ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list,$ped_id,'equal','all');
if (!is_array($ped_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #14: $date<br><br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$ped_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 error in call to tableQuery
if (sizeof($ped_rec_list) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #15: $date<br>\n";
echo "Error in data integrity. Inserted pedigree $ped_id into database with database id $database_id and \n";
echo "insertPedigree returned success, but when query the pedigree table with that information no records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 error in data integrity
elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #16: $date<br>\n";
echo "Error in data integrity. Inserted pedigree $ped_id into database with database id $database_id and \n";
echo "insertPedigree returned success, but when query the pedigree 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 \n";
echo "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 error in data integrity
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] Inserted Pedigree ID $ped_rec[pedigree_id] into the Pedigree Table ";
$log_file_statement.= "for Database ID $database_id, and was assigned pedigree_table_id $ped_rec[pedigree_table_id]\n";
$inserted_pedigrees[] = $ped_rec['pedigree_table_id'];
$field_list = array('affection_status_id');
$affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list,'_','wildcard','all');
if (!is_array($affection_status_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #17: $date<br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$affection_status_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #18: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
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 error in call to tableQuery
foreach ($affection_status_rec_list as $affection_status_rec)
{
$affection_status_id = $affection_status_rec['affection_status_id'];
$ret_val = insertPedigreeAffectionStatusLink($database_id,$affection_status_id,$ped_rec['pedigree_table_id']);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #19: $date<br>\n";
echo "Error in call to insertPedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #20: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #21: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 error in call to insertPedigreeAffectionStatusLink
$field_list_array = array('pedigree_table_id','affection_status_id');
$term_array = array($ped_rec['pedigree_table_id'],$affection_status_rec['affection_status_id']);
$mode_array = array('equal','equal');
$ped_affect_link_id_array = distinctCompoundTableQuery('pedigree_affection_status_link_id','pedigree_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
if (!is_array($ped_affect_link_id_array))
{
$date = date('Y-m-d H:i:s');
echo "Error #22: $date<br><br>\n";
echo "Error in call to distinctCompoundTableQuery from insert_individuals.php<br>\n";
echo "$ped_affect_link_id_array<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #23: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #24: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 distinctCompoundTableQuery
if (sizeof($ped_affect_link_id_array) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #25: $date<br>\n";
echo "Error in data integrity. Inserted Pedigree-Affection Status link for Pedigree Table ID \n";
echo "$ped_rec[pedigree_table_id] and Affection Status ID $affection_status_rec[affection_status_id] \n";
echo "into database with database id $database_id and \n";
echo "insertPedigreeAffectionStatusLink returned success, but when query the pedigree_affection_status_link_table \n";
echo "with that information no records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #26: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #27: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 integrity
elseif (sizeof($ped_affect_link_id_array) == '1') {$ped_affect_link_id = $ped_affect_link_id_array[0];}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #28: $date<br>\n";
echo "Error in data integrity. Inserted Pedigree-Affection Status link for Pedigree Table ID \n";
echo "$ped_rec[pedigree_table_id] and Affection Status ID $affection_status_rec[affection_status_id] \n";
echo "into database with database id $database_id and \n";
echo "insertPedigreeAffectionStatusLink returned success, but when query the pedigree_affection_status_link_table \n";
echo "with that information multiple records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #29: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #30: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 integrity
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] Inserted a link into pedigree_affection_status_link_table ";
$log_file_statement.= "between pedigree_table_id $ped_rec[pedigree_table_id] and ";
$log_file_statement.= "affection_status_id $affection_status_rec[affection_status_id], it was assigned ";
$log_file_statement.= "pedigree_affection_status_link_id $ped_affect_link_id\n";
$inserted_ped_affect_links[] = $ped_affect_link_id;
}#end foreach affection status
echo "Pedigree ID $ped_id successfully inserted into the database.<br>\n";
}#end if pedigree not already in the database
else #pedigree already in the database
{
$field_list = array('pedigree_id');
$ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list,$ped_id,'equal','all');
if (!is_array($ped_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #31: $date<br><br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$ped_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 error in call to tableQuery
if (sizeof($ped_rec_list) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #32: $date<br>\n";
echo "Error in data integrity. Function existsValue returned TRUE for pedigree $ped_id in Database ID $database_id\n";
echo ", but when query the pedigree table with that information no records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "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 error in data integrity
elseif (sizeof($ped_rec_list) == '1') {$ped_rec = $ped_rec_list[0];}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #33: $date<br>\n";
echo "Error in data integrity. Function existsValue returned TRUE for pedigree $ped_id in Database ID $database_id\n";
echo ", but when query the pedigree 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 \n";
echo "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 error in data integrity
}#end else pedigree already in the database
$individual_field_array = array('pedigree_table_id','pedigree_id','individual_id');
$individual_value_array = array($ped_rec['pedigree_table_id'],$ped_id,$indiv_id);
$exists_individual = existsValue('individual_table',$individual_field_array,$individual_value_array,$database_id);
if (!preg_match('/\d+/',$exists_individual))
{
$date = date('Y-m-d H:i:s');
echo "Error #34: $date<br>\n";
echo "Error in call to existsValue from insert_individuals.php<br>\n";
echo "$exists_individual<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #35: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #36: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 existsValue
if ($exsists_individual == '1')
{
echo "Individual $indiv_id in Pedigree $ped_id is already in the database<br>\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;
}
else #individual doesn't exist
{
$ret_val = insertIndividual($database_id,$ped_rec['pedigree_table_id'],$ped_id,$indiv_id,$father_id,$mother_id,$sex);
if ($ret_val != '1')
{
echo "Individual $indiv_id in Pedigree $ped_id was NOT inserted into the database.<br>\n";
echo "See error message below for an explanation.<br>\n";
$date = date('Y-m-d H:i:s');
echo "Error #37: $date<br>\n";
echo "Error in call to insertIndividual from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #38: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #39: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 (ret_val != '1')
$field_list = array('individual_id','pedigree_id','pedigree_table_id');
$term_array = array($indiv_id,$ped_id,$ped_rec['pedigree_table_id']);
$mode_array = array('equal','equal','equal');
$indiv_rec_list = compoundTableQuery('individual_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
if (!is_array($indiv_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #40: $date<br><br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$indiv_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #41: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #42: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 "Error #43: $date<br>\n";
echo "Error in data integrity. Inserted individual $indiv_id in pedigree $ped_id into database with database id $database_id and \n";
echo "insertIndividual returned success, but when query the pedigree table with that information no records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #44: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #45: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 integrity
elseif (sizeof($indiv_rec_list) == '1') {$indiv_rec = $indiv_rec_list[0];}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #46: $date<br>\n";
echo "Error in data integrity. Inserted individual $indiv_id in pedigree $ped_id into database with database id $database_id and \n";
echo "insertIndividual returned success, but when query the individual 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 \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #47: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #48: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
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 integrity
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] Inserted Individual $indiv_rec[individual_id] in Pedigree $indiv_rec[pedigree_id] ";
$log_file_statement.= "in Database ID $database_id, and individual_table_id $indiv_rec[individual_table_id] was returned.\n";
$inserted_individuals[] = $indiv_rec['individual_table_id'];
$field_list = array('affection_status_id');
$affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list,'_','wildcard','all');
if (!is_array($affection_status_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #49: $date<br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$affection_status_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #50: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #51: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #52: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted individual table id
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 error in call to tableQuery
foreach ($affection_status_rec_list as $affection_status_rec)
{
$affection_status_id = $affection_status_rec['affection_status_id'];
$ret_val = insertIndividualAffectionStatusLink($database_id,$affection_status_id,$indiv_rec['individual_table_id']);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #53: $date<br>\n";
echo "Error in call to insertIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #54: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #55: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #56: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted individual table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #57: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to insertIndividualAffectionStatusLink
$field_list_array = array('individual_table_id','affection_status_id');
$term_array = array($indiv_rec['individual_table_id'],$affection_status_id);
$mode_array = array('equal','equal');
$indiv_affect_link_id_array = distinctCompoundTableQuery('individual_affection_status_link_id','individual_affection_status_link_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
if (!is_array($indiv_affect_link_id_array))
{
$date = date('Y-m-d H:i:s');
echo "Error #58: $date<br>\n";
echo "Error in call to distinctCompoundTableQuery from insert_individuals.php<br>\n";
echo "$ped_affect_link_id_array<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #59: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #60: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #61: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted individual table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #62: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 distinctCompoundTableQuery
if (sizeof($indiv_affect_link_id_array) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #63: $date<br>\n";
echo "Error in data integrity. Inserted Individual-Affection Status link for Individual Table ID \n";
echo "$indiv_rec[individual_table_id] and Affection Status ID $affection_status_rec[affection_status_id] \n";
echo "into database with database id $database_id and \n";
echo "insertIndividualAffectionStatusLink returned success, but when query the individual_affection_status_link_table \n";
echo "with that information no records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #64: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #65: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #66: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted individual table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #67: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 integrity
elseif (sizeof($indiv_affect_link_id_array) == '1') {$indiv_affect_link_id = $indiv_affect_link_id_array[0];}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #68: $date<br>\n";
echo "Error in data integrity. Inserted Individual-Affection Status link for Individual Table ID \n";
echo "$indiv_rec[individual_table_id] and Affection Status ID $affection_status_rec[affection_status_id] \n";
echo "into database with database id $database_id and \n";
echo "insertIndividualAffectionStatusLink returned success, but when query the individual_affection_status_link_table \n";
echo "with that information multiple records are returned.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #69: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #70: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #71: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #72: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 integrity
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] Inserted a link into the individual_affection_status_link_table ";
$log_file_statement.= "for Database ID $database_id linking individual_table_id $indiv_rec[individual_table_id] and ";
$log_file_statement.= "affection_status_id $affection_status_id, assigned individual_affection_status_link_id $indiv_affect_link_id.\n";
$inserted_indiv_affect_links[] = $indiv_affect_link_id;
}#end foreach affection status
echo "Individual $indiv_id in Pedigree $ped_id was successfully inserted into the database.<br><br>\n";
}#end if individual doesn't already exist
echo "Updating the Pedigree Table with the new Individual information<br>\n";
$num_in_ped = $ped_rec['number_in_pedigree'];
$field_array = array('pedigree_table_id');
$update_indiv_rec_list = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_array,$ped_rec['pedigree_table_id'],'equal','all');
if (!is_array($update_indiv_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #73: $date<br>\n";
echo "Error in call to distinctTableQuery from insert_individuals.php<br>\n";
echo "$indiv_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #74: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #75: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #76: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #77: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 not array
$update_indiv_table_id_term = join($update_indiv_rec_list,',');
$new_num_in_ped = sizeof($update_indiv_rec_list);
unset($update_indiv_rec_list);
$update_field_array = array();
$update_value_array = array();
if ($new_num_in_ped != $num_in_ped)
{
$update_field_array[]= 'number_in_pedigree';
$update_value_array[]= $new_num_in_ped;
}
if (sizeof($update_field_array) > '0')
{
$ret_val = updateRecord('pedigree_table',$ped_rec['pedigree_table_id'],$update_field_array,$update_value_array);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #78: $date<br>\n";
echo "Error in call to updateRecord from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #79: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #80: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #81: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #82: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to updateRecord
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] updated field number_in_pedigree for Pedigree Table ID $ped_rec[pedigree_table_id] ";
$log_file_statement.= "in Database ID $database_id, updated to $new_num_in_ped from $num_in_ped.\n";
}#end if fields to update
$field_list = array('affection_status_id');
$affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list,'_','wildcard','all');
if (!is_array($affection_status_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #83: $date<br>\n";
echo "Error in call to tableQuery from insert_individuals.php<br>\n";
echo "$affection_status_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #84: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #85: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #86: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #87: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to tableQuery
foreach ($affection_status_rec_list as $affection_status_rec)
{
$affection_status_id = $affection_status_rec['affection_status_id'];
$field_list = array('affection_status_id','individual_table_id','individual_affection_status');
$term_array = array($affection_status_id,$update_indiv_table_id_term,'2');
$mode_array = array('equal','in','equal');
$indiv_affect_link_rec_list = compoundTableQuery('individual_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
if (!is_array($indiv_affect_link_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #88: $date<br>\n";
echo "Error in call to compoundTableQuery from insert_individuals.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 on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #89: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #90: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #91: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #92: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to compoundTableQuery
$new_num_affected = sizeof($indiv_affect_link_rec_list);
unset($indiv_affect_link_rec_list);
$field_list = array('affection_status_id','pedigree_table_id');
$term_array = array($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,$term_array,$mode_array,'and','all');
if (!is_array($ped_affect_link_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #93: $date<br>\n";
echo "Error in call to compoundTableQuery from insert_individuals.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 on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #94: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #95: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #96: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #97: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to compoundTableQuery
$ped_affect_link_rec = $ped_affect_link_rec_list[0];
$num_affected = $ped_affect_link_rec['number_affected_in_pedigree'];
if ($new_num_affected != $num_affected)
{
$update_field_array = array('number_affected_in_pedigree');
$update_value_array = array($new_num_affected);
$ret_val = updateRecord('pedigree_affection_status_link_table',$ped_affect_link_rec['pedigree_affection_status_link_id'],$update_field_array,$update_value_array);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #98: $date <br>\n";
echo "Error in call to updateRecord from insert_individuals.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</form>\n";
echo "<br><br>\n";
echo "Encountered a problem while trying to insert the data.<br>\n";
echo "Tool will now assume that there is something wrong with the data and delete all data that has ";
echo "been inserted into the database.<br>\n";
foreach ($inserted_pedigrees as $inserted_pedigree)
{
$ret_val = deletePedigree($inserted_pedigree);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #99: $date<br>\n";
echo "Error in call to deletePedigree from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigree
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Table ID $inserted_pedigree from Database ID $database_id.";
}#end foreach inserted pedigree table id
if (sizeof($inserted_ped_affect_links) > '0')
{
foreach ($inserted_ped_affect_links as $inserted_ped_affect_link)
{
$ret_val = deletePedigreeAffectionStatusLink($inserted_ped_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #100: $date<br>\n";
echo "Error in call to deletePedigreeAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deletePedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Pedigree Affection Status Link ID $inserted_ped_affect_link from Database ID $database_id.";
}#end foreach inserted pedigree-affection status link
}#end if have pedigree affections status links
foreach ($inserted_individuals as $inserted_individual)
{
$ret_val = deleteIndividual($inserted_individual);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #101: $date<br>\n";
echo "Error in call to deleteIndividual from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividual
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Table ID $inserted_individual from Database ID $database_id.";
}#end foreach inserted indiv table id
if (sizeof($inserted_indiv_affect_links) > '0')
{
foreach ($inserted_indiv_affect_links as $inserted_indiv_affect_link)
{
$ret_val = deleteIndividualAffectionStatusLink($inserted_indiv_affect_link);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #102: $date<br>\n";
echo "Error in call to deleteIndividualAffectionStatusLink from insert_individuals.php<br>\n";
echo "$ret_val<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";
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 error in call to deleteIndividualAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement.= "date:\tUser $_SESSION[user_name] Deleted Individual Affection Status Link ID $inserted_indiv_affect_link from Database ID $database_id.";
}#end foreach inserted individual-affection status link
}#end if have individual affections status links
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 error in call to updateRecord
$date = date('Y-m-d H:i:s');
$log_file_statement.= "$date:\tUser $_SESSION[user_name] updated field number_affected_in_pedigree in table ";
$log_file_statement.= "pedigree_affection_status_link_table for pedigree_affection_status_link_id ";
$log_file_statement.= "$ped_affect_link_rec[pedigree_affection_status_link_id] in Database ID $database_id, updated value to ";
$log_file_statement.= "$new_num_affected from $num_affected.\n";
}#end if new number affected
}#end foreach affection status
echo "Updated the pedigree information for Pedigree $ped_id<br><br>\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);
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 insert_individuals.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 insert_individuals.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 = "New Individual in your Genetic Studies Database";
$message = "The Individual $indiv_id in Pedigree $ped_id was inserted into the database $database_rec[database_name].";
$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 insert_individuals.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 insert_individuals.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";
echo " If you would like to insert more individuals please click the button below.<br><br>\n";
echo "<center>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Insert More Individuals\">\n";
echo "</center>\n";
echo "</form>\n";
echo "<br><br>\n";
$ret_val = printLogOutButton('insert_individuals.php');
}#end if insert from web and have values
#6 Determine whether to Get File from Users Computer or on server
if (($insert_from_file == '1') and
(!preg_match('/^\d$/',$upload_file)) and
((!preg_match('/\w+/',$file_on_server)) and (!is_uploaded_file($_FILES['indiv_file']['tmp_name'])))
)
{
echo "Please select whether you would like to upload a file from your computer, or \n";
echo "select a file that is already in your 'Uploaded Data' directory on the server.<br><br>\n";
echo "<form action=\"insert_individuals.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
echo "<input type=\"hidden\" name=\"insert_from_file\" value=\"$insert_from_file\">\n";
echo "<table align=\"center\">\n";
echo "<tr><td><input type=\"radio\" name=\"upload_file\" value=\"0\" checked></td><td>Select File in 'Uploaded Data' directory</td></tr>\n";
echo "<tr><td><input type=\"radio\" name=\"upload_file\" value=\"1\"></td><td>Upload File from Your Computer</td></tr>\n";
echo "</table>\n";
echo "<br>\n";
echo "<table align=\"center\">\n";
echo "<tr>\n";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Select File to Insert From\"></td>\n";
echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Method to Select File\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>\n";
printLogOutButton('insert_individuals.php');
}#end determine whether to get file from users computer or server
if (($insert_from_file == '1') and
(preg_match('/^\d$/',$upload_file)) and
((!preg_match('/\w+/',$file_on_server)) and (!is_uploaded_file($_FILES['indiv_file']['tmp_name'])))
)
{
echo "This form will allow you to upload a file you have stored on the server that contains the individuals \n";
echo "you would like to insert into the database.<br> \n";
echo "The file must be in a specific format for the insertion to be done properly. The file must contain <b>6</b> \n";
echo "columns, and they must be in this order:<br> \n";
echo "<table>\n";
echo "<tr><td> </td><td><b>Column 1:</b> Nationality</td></tr>\n";
echo "<tr><td> </td><td><b>Column 2:</b> Pedigree ID</td></tr>\n";
echo "<tr><td> </td><td><b>Column 3:</b> Individual ID</td></tr>\n";
echo "<tr><td> </td><td><b>Column 4:</b> Father ID</td></tr>\n";
echo "<tr><td> </td><td><b>Column 5:</b> Mother ID</td></tr>\n";
echo "<tr><td> </td><td><b>Column 6:</b> Sex</td></tr>\n";
echo "<tr><td> </td><td>(Click <a href=\"../data/test_data/insert_individual_demo_file.csv\" target=\"_blank\">here</a> for an example file.)</td></tr>\n";
echo "</table>\n";
echo "<br>\n";
echo "The columns must be comma-delimited, and every column must contain data. Each individual must be on its own line, and \n";
echo "<b>cannot</b> have any missing values. If an Individual has unknown parents, enter a zero (0) in the Father and Mother ID columns. Males are designated by a 1 in the sex column, and females \n";
echo "are designated by a 2 in the sex column.<br><br>\n";
if ($upload_file == 1)
{echo "<form action=\"insert_individuals.php\" enctype=\"multipart/form-data\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";}
else
{echo "<form action=\"insert_individuals.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";}
echo "<input type=\"hidden\" name=\"insert_from_file\" value=\"$insert_from_file\">\n";
echo "<input type=\"hidden\" name=\"upload_file\" value=\"$upload_file\">\n";
echo "<table align=\"center\">\n";
if ($upload_file == 1)
{
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000000\">\n";
echo "<tr><td>File Name:</td><td><input type=\"file\" name=\"indiv_file\" size=\"20\" maxlength=\"250\"></td></tr>\n";
}
else #file on server
{
echo "<tr>\n";
echo "<td>File Name:</td><td>\n";
$jscript = printFileSelectList($_SESSION['user_name'],$database_id,'upload');
if ($jscript == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #108: $date<br>\n";
echo "Error in call to printFileSelectList from insert_individuals.php<br>\n";
echo "Please see the error from printFileSelectList above for an explanation.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end error in call to printFileSelectList
if ($jscript == '1')
{
$date = date('Y-m-d H:i:s');
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br><br>\n";
echo "<center>\n";
echo "There are no files stored for user $_SESSION[user_name] in their uploaded_data directory.<br>\n";
echo "This means either you have not transfered the file to the server, or the file has expired and has been \n";
echo "deleted from the server.<br> So you need to either transfer the file you are looking for to the server and put it \n";
echo "in your uploaded_data directory, or upload the file directly from your computer in order to insert the data.<br><br>\n";
echo "</center>\n\n";
$ret_val = printLogOutButton('insert_individuals.php');
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if no files in uploaded_data directory for user
echo "</td>\n";
echo "</tr>\n";
}#end else file on server
echo "</table>\n";
echo "<br>\n";
echo "<table align=\"center\">\n";
echo "<tr>\n";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Insert From File\"></td>\n";
echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Selected File\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br><br>\n";
$ret_val = printLogOutButton('insert_individuals.php');
echo "\n\n";
echo "<script>\n";
echo "function Validate(form)\n";
if ($upload_file == 1)
{
echo "{\n";
echo " if (form.indiv_file.value == \"\"){\n";
echo " alert(\"You must select a File to upload\");\n";
echo " form.indiv_file.focus();\n";
echo " return(false);}\n";
echo " return(true);\n";
echo "}\n";
}#end if file uploaded
else {echo "$jscript\n";}
echo "</script>\n";
}#end get file
#7 Parse File and Insert
if ((
($insert_from_file == '1') and
($upload_file == '1') and
(is_uploaded_file($_FILES['indiv_file']['tmp_name']))
) or
(
($insert_from_file == '1') and
($upload_file == '0') and
(preg_match('/\w+/',$file_on_server)))
)
{
if ($upload_file == '1')
{
$rand_num = rand();
$file_name = "indiv_data_upload_".$rand_num.".txt";
$ret_val = move_uploaded_file($_FILES['indiv_file']['tmp_name'],"../data/uploaded_data/$_SESSION[user_name]/$file_name");
if (!$ret_val)
{
$date = date('Y-m-d H:i:s');
echo "Error #109: $date<br>\n";
echo "Error in call to insert_individuals.php<br>\n";
echo "Unable to move uploaded file inorder to read it.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link on \n";
echo "the left navigation bar\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if (!ret_val)
$uploaded_file_name = "../../data/uploaded_data/$_SESSION[user_name]/$file_name";
$uploaded_file_size = @filesize("../data/uploaded_data/$_SESSION[user_name]/$file_name");
if (!$uploaded_file_size)
{
$command = "stat -c %s ../data/uploaded_data/$_SESSION[user_name]/$file_name";
exec($command,$output_array);
$uploaded_file_size = $output_array[0];
}#end if file too big for php
}#end if file from users computer
else
{
$uploaded_file_name = "../"."$file_on_server";
$uploaded_file_size = @filesize("$file_on_server");
if (!$uploaded_file_size)
{
$command = "stat -c %s $file_on_server";
exec($command,$output_array);
$uploaded_file_size = $output_array[0];
}#end if file too big for php
}#end if file from server
$ret_val = chdir("../bin/database_query_scripts/");
if (!$ret_val)
{
$date = date('Y-m-d H:i:s');
echo "Error #110: $date<br>\n";
echo "Error in call to chdir from insert_individuals.php<br>\n";
echo "Unable to change directory to database query scripts directory<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";
$ret_val = disconnect();
exit;
}#end error in call to chdir
if ($uploaded_file_size > $max_file_size_to_wait_to_run)
{
$background_flag = 1;
if ($uploaded_file_size >= $max_file_size_not_to_split)
{
$found = preg_match('/^(.+\/)([^\/]+)$/',$uploaded_file_name,$captured);
$path = $captured[1];
$file_name = $captured[2];
$sub_file_name = "sub_"."$file_name";
$prefix = "$path"."$sub_file_name";
$prefix = preg_replace('/\.\w+$/','_',$prefix);
$command = "split -a5 --lines=$num_lines_to_split_files $uploaded_file_name $prefix";
if (sizeof($output_array) > '0'){$output_array = array();}
exec($command,$output_array,$return_code);
if ($return_code)
{
$err_msg = implode("\n",$output_array);
$date = date('Y-m-d H:i:s');
echo "Error #111: $date<br>\n";
echo "Error in call to exec to split file from insert_individuals.php<br>\n";
echo "$err_msg<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link on the \n";
echo "left navigation bar.\n";
echo "</form>\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if error in exec call to split file
$file_array = glob("$prefix*");
$num_files_split = sizeof($file_array);
sort($file_array);
foreach ($file_array as $key=>$file)
{
$command = "./insert_data_into_database.php '$file' '$database_id' 'Insert Individuals' '$_SESSION[user_name]' ";
$command.= "'$background_flag' >> dummy_insert_data_background_output.txt &";
$last_line = system($command,$sys_ret_val);
if ($sys_ret_val != '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #112: $date<br>\n";
echo "Error in system call to insert_data_into_database.php from insert_individuals.php<br>\n";
echo "The return value of the sytem call was $sys_ret_val<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link on the \n";
echo "left navigation bar.\n";
echo "</form>\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if error in system call
}#end foreach sub file
}#end if file too big for php
else #don't need to split file
{
$command = "./insert_data_into_database.php '$uploaded_file_name' '$database_id' 'Insert Individuals' '$_SESSION[user_name]' ";
$command.= "'$background_flag' >> dummy_insert_data_background_output.txt &";
$last_line = system($command,$sys_ret_val);
if ($sys_ret_val != '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #113: $date<br>\n";
echo "Error in system call to insert_data_into_database.php from insert_individuals.php<br>\n";
echo "The return value of the sytem call was $sys_ret_val<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link on the \n";
echo "left navigation bar.\n";
echo "</form>\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if error in system call
}#end else don't need to split file
}#end if run in background
else #run in foreground
{
$background_flag = 0;
$command = "./insert_data_into_database.php '$uploaded_file_name' '$database_id' 'Insert Individuals' '$_SESSION[user_name]' '$background_flag' ";
passthru($command,$sys_ret_val);
if ($sys_ret_val != '0')
{
echo "<br><br>\n";
$date = date('Y-m-d H:i:s');
echo "Error #114: $date<br>\n";
echo "Error in system call to insert_data_into_database.php from insert_individuals.php<br>\n";
echo "See the error message above for an explanation of the error<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link on the \n";
echo "left navigation bar.\n";
echo "</form>\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if error in system call
}#end else run in foreground
$ret_val = chdir("../../cgi-bin/");
if (!$ret_val)
{
$date = date('Y-m-d H:i:s');
echo "Error #115: $date<br>\n";
echo "Error in call to chdir from insert_individuals.php<br>\n";
echo "Unable to change directory to cgi-bin directory<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";
$ret_val = disconnect();
exit;
}#end error in call to chdir
if ($background_flag)
{
echo "<center>\n";
echo "<b>The data you uploaded is being inserted into the database.<br>\n";
if ($uploaded_file_size >= $max_file_size_not_to_split)
{
echo "The file was too large to handle, so it was split into $num_files_split sub files, and each \n";
echo "sub file is being processed separately. So you will recieve an email when the data in each sub file \n";
echo "has been inserted into the database \n";
}#end if split file
else {echo "You will receive an email when all the data has been inserted into the database \n";}
echo "detailing the results of the file upload and any errors.</b><br><br>\n";
echo "</center>\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end if running in background
if (!$background_flag){echo "Finished sending update emails to all the users<br>\n";}
}#end parse file and insert
}#end if (auth_user == '1')
$ret_val = disconnect();
echo "</body></html>\n";
?>