<?php
#Copyright 2008 Aaron Day-Williams <hide@address.com>
#
#This file is part of Generic Genetic Studies Database (GGSD).
#
#GGSD is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#GGSD is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with GGSD. If not, see <http://www.gnu.org/licenses/>.
header('Content-type: text/html');
session_cache_limiter('private');
session_start();
require 'sql_lib.inc';
require 'html_lib.inc';
require 'file_system_lib.inc';
#NAME define_affection_status.php
#TYPE PHP
#USES sql_lib.inc (authenticate alterTable)
#PURPOSE To allow the user to dynamically define affection status
# categories
#USAGE define_affection_status.php
#PARAMETERS
# authorized user auth_user int optional
# affection_status_name affection_status_name string optional
#RETURNS
# success message string if success
# error message string if error
#DATASTRUCTURES No special datastructures
#FUNCTIONAL DESCRIPTION The script will authorized the user, then give a form to define
# an affections status.
#ASSUMPTIONS
#LIMITATIONS
#COMMENTS
#PRELIMINARY DESIGN
# 1 Get Args
# 2 Authorize User
# 3 Get Status Name
# 4 Get Allele Frequencies
# 5 Insert Status
echo "<html>\n";
echo " <head>\n";
if (isset($_POST['end_session'])){echo " <META HTTP-EQUIV=Refresh CONTENT=\"$logout_refresh_time;URL=../right.html\">\n";}
else {echo " <META HTTP-EQUIV=Refresh CONTENT=\"$normal_refresh_time; URL=$_SERVER[SCRIPT_NAME]\">\n";}
echo " <title>Define Affection Statuses</title>\n";
echo " </head>\n";
echo "<body bgcolor=\"white\">\n";
echo "<center><h3>Define Affection Status</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo"<br>\n";
#1 Get Args
$access_type_required = 'administrative';
$affection_status_name = $_POST['affection_status_name'];
$number_of_alleles = $_POST['number_of_alleles'];
$allele_frequencies = $_POST['allele_frequency'];
$affection_status_desc = $_POST['affection_status_desc'];
$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 define_affection_status.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 Authorize 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 define_affection_status.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 define_affection_status.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('define_affection_status.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 define_affection_status.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 define_affection_status.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 define_affection_status.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 define_affection_status.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('define_affection_status.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 define_affection_status.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('define_affection_status.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 define_affection_status.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 define_affection_status.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 Get Status Name
if ((!preg_match('/\w+/',$affection_status_name)) and
(!preg_match('/\d+/',$number_of_alleles)) and
(sizeof($allele_frequencies) == 0) and
(!preg_match('/\w+/',$affection_status_desc))
)
{
echo "<form action=\"define_affection_status.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
echo "Please provide the Affection Category details below that are to be inserted into the database below:<br><br>\n";
echo "<table>\n";
echo "<tr><td>Affection Status Name:</td><td><input type=\"textbox\" name=\"affection_status_name\" size=\"15\" maxlength=\"25\"> (i.e. Diabetes, FCHL)</td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td>Number of Alleles:</td><td><input type=\"textbox\" name=\"number_of_alleles\" size =\"15\" maxlength=\"2\"></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td>Affection Status Description:</td><td><textarea name=\"affection_status_desc\" cols=\"75\" rows=\"20\" wrap=\"virtual\"></textarea></td></tr>\n";
echo "</table>\n";
echo "<br><br>\n";
echo "<center>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Insert Affection Status\">\n";
echo "<input type=\"reset\" name=\"reset\" value=\"Reset Affection Name\">\n";
echo "</form>\n";
echo "</center>\n";
echo "<br><br>\n";
$ret_val = printLogOutButton('define_affection_status.php');
echo "\n\n";
echo "<script>\n";
echo "function Validate(form)\n";
echo "{\n";
echo " var exp = /^\d+$/;\n";
echo " if (form.affection_status_name.value == \"\"){\n";
echo " alert(\"You must enter an Affection Status Name\");\n";
echo " return(false);}\n";
echo "\n";
echo " if (form.number_of_alleles.value == \"\"){\n";
echo " alert(\"You must enter the Number of Alleles\");\n";
echo " return(false);}\n";
echo "\n";
echo " if (!exp.test(form.number_of_alleles.value)){\n";
echo " alert(\"The Number of Alleles value must be an integer\");\n";
echo " return(false);}\n";
echo "\n";
echo " if (form.affection_status_desc.value == \"\"){\n";
echo " alert(\"You must enter a description for this affection status\");\n";
echo " return(false);}\n";
echo "\n";
echo " return(true);\n";
echo "}\n";
echo "</script>\n";
}#end if no affection_status_name
#4 Get Allele Frequencies
if ((preg_match('/\w+/',$affection_status_name)) and
(preg_match('/\d+/',$number_of_alleles)) and
(sizeof($allele_frequencies) == 0) and
(preg_match('/\w+/',$affection_status_desc))
)
{
echo "<form action=\"define_affection_status.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
echo "Please Enter the Allele Frequency for each Allele of Affetion Status $affection_status_name<br><br>\n";
echo "<table>\n";
for ($i = 1; $i <= $number_of_alleles; $i++)
{
echo "<tr><td>Alelle $i Frequency:</td><td><input type=\"textbox\" name=\"allele_frequency[]\" size=\"15\" maxlength=\"7\"></td></tr>\n";
}
echo "</table>\n";
echo "<br><br>\n";
echo "<input type=\"hidden\" name=\"affection_status_name\" value=\"$affection_status_name\">\n";
echo "<input type=\"hidden\" name=\"number_of_alleles\" value=\"$number_of_alleles\">\n";
echo "<input type=\"hidden\" name=\"affection_status_desc\" value=\"$affection_status_desc\">\n";
echo "<table align=\"center\">\n";
echo "<tr>\n";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Insert Affection Status\"></td>\n";
echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Allele Frequencies\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>\n\n";
printLogOutButton('define_affection_status.php');
echo "\n\n";
echo "<script>\n";
echo "function Validate(form)\n";
echo "{\n";
echo " var exp = /^\d+\.\d+$/;\n";
echo " var j = 0;\n";
echo " for (var i=0; i<form.elements['allele_frequency[]'].length; i++){\n";
echo " if (!exp.test(form.elements['allele_frequency[]'][i].value)){\n";
echo " j = $i + 1;\n";
echo " alert(\"The Allele Frequency for Allele \"+j+\" must be of format #.#####\");\n";
echo " return(false);}}\n";
echo " return true;\n";
echo "}\n";
echo "</script>\n";
}#end if don't have allele frequencies
#5 Insert Status Name
if ((preg_match('/\w+/',$affection_status_name)) and
(preg_match('/\d+/',$number_of_alleles)) and
(sizeof($allele_frequencies) > 0) and
(preg_match('/\w+/',$affection_status_desc))
)
{
$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 define_affection_status.php<br>\n";
echo "Unable to open log file to keep track of when, what, and by whom data is altered in the database<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}#end error in call to fopen
$status_name = strtolower($affection_status_name);
$field_array = array('affection_status_name');
$value_array = array($status_name);
$existsAffection = existsValue('affection_status_table',$field_array,$value_array,$database_id);
if (!preg_match('/^\d+$/',$existsAffection))
{
$date = date('Y-m-d H:i:s');
echo "Error #12: $date<br>\n";
echo "Error in call to existsValue from define_affection_status.php<br>\n";
echo "$existsAffection<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
echo "</body></html>\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end error in call to existsValue
if ($existsAffection > 0)
{
$date = date('Y-m-d H:i:s');
echo "There is already and Affection Status in the database named $affection_status_name.<br>\n";
echo "This message was generated at $date.<br><br>\n";
echo "</body></html>\n";
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end if affection status already exists
$ret_val = insertAffectionStatus($database_id,$status_name,$number_of_alleles,$affection_status_desc);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #13: $date<br>\n";
echo "Error in call to insertAffectionStatus from define_affection_status.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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 insertAffectionStatus
$field_list_array = array('affection_status_name');
$affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,$status_name,'equal','all');
if (!is_array($affection_status_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #14: $date<br>\n";
echo "Error in call to tableQuery from define_affection_status.php<br>\n";
echo "$affection_status_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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($affection_status_rec_list) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #15: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "Inserted affection status name $status_name for database id $database_id into the affection status table ";
echo "with the function insertAffectionStatus, and it returned success. ";
echo "But when query the affection status table with affection status name $status_name and database_id $database_id \n";
echo "no records are returned. Something wrong with the database.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end if no record in the database
elseif (sizeof($affection_status_rec_list) == '1')
{
$affection_status_rec = $affection_status_rec_list[0];
$affection_status_id = $affection_status_rec['affection_status_id'];
$date = date('Y-m-d H:i:s');
$log_file_statement = "$date:\t$_SESSION[user_name] Inserted new Affection Status into Database ID $database_id, ";
$log_file_statement.= "Affection Status Name $stauts_name and assigned Affection Status ID $affection_status_id.\n";
fwrite($log_file_handle,$log_file_statement);
}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #16: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "There is more than one record in the affection status table with affection_status_name $status_name and database id $database_id.<br>\n";
echo "The affection status ids that are returned when the affection status table is queried with name ";
echo "$status_name and database id $database_id are:<br>\n";
foreach ($affection_status_rec_list as $affection_status_rec) {echo "$affection_status_rec[affection_status_id]<br>\n";}
echo "<br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}
if (is_array($allele_frequencies))
{
for ($i = 1; $i <= $number_of_alleles; $i++)
{
$allele_freq = $allele_frequencies[$i-1];
$ret_val = insertAffectionStatusAllele($database_id,$affection_status_id,$i,$allele_freq);
if ($ret_val != 1)
{
$date = date('Y-m-d H:i:s');
echo "Error #17: $date<br>\n";
echo "Error in call to insertAffectionStatusAllele from define_affection_status.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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 insertAffectionStatus
$field_list = array('affection_status_id','allele_code');
$term_array = array($affection_status_id,$i);
$mode_array = array('equal','equal');
$affect_status_allele_rec_list = compoundTableQuery('affection_status_allele_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
if (!is_array($affect_status_allele_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #18: $date<br>\n";
echo "Error in call to compoundTableQuery from define_affection_status.php<br>\n";
echo "$affect_status_allele_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end error in call to compoundTableQuery
if (sizeof($affect_status_allele_rec_list) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #19: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "Inserted affection status allele record for Affection Status ID $affection_status_id ";
echo "and Allele Code $i for database id $database_id into the affection status allele table ";
echo "with the function insertAffectionStatusAllele, and it returned success. ";
echo "But when query the affection status allele table with that information \n";
echo "no records are returned. Something wrong with the database.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end if no record in the database
elseif (sizeof($affect_status_allele_rec_list) == '1')
{
$affect_status_allele_rec = $affect_status_allele_rec_list[0];
$affect_status_allele_id = $affect_status_allele_rec['affection_status_allele_id'];
$date = date('Y-m-d H:i:s');
$log_file_statement = "$date:\t$_SESSION[user_name] Inserted new Affection Status Allele into Database ID $database_id, ";
$log_file_statement.= "for Affection Status ID $affection_status_id and Allele Code $i and assigned ";
$log_file_statement.= "Affection Status Allele ID $affect_status_allele_id.\n";
fwrite($log_file_handle,$log_file_statement);
}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #20: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "There is more than one record in the affection status allele table with \n";
echo "affection_status_id $affection_status_id and allele_code $i and database id $database_id.<br>\n";
echo "The affection status allele ids that are returned when the affection status allele table is queried with ";
echo "the above information are:<br>\n";
foreach ($affec_status_allele_rec_list as $affect_status_allele_rec)
{echo "$affect_status_allele_rec[affection_status_allele_id]<br>\n";}
echo "<br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end else error in data integrity
}#end for each allele for affection status
}#end if allele_frequencies is an array
else #not an array of allele frequencies
{
if ($number_of_alleles != 1)
{
$date = date('Y-m-d H:i:s');
echo "Error #21: $date<br>\n";
echo "Error in the processing of define_affection_status.php<br>\n";
echo "User specified that there are $number_of_alleles Alleles for Affection Status $status_name and ID $affection_status_id, \n";
echo "but there is only a single allele frequency supplied. The number of allele frequencies MUST ";
echo "match the number of alleles.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
echo "</body></html>\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end if error in data processing
$ret_val = insertAffectionStatusAllele($database_id,$affection_status_id,1,$allele_frequencies);
if ($ret_val != 1)
{
$date = date('Y-m-d H:i:s');
echo "Error #22: $date<br>\n";
echo "Error in call to insertAffectionStatusAllele from define_affection_status.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
echo "</body></html>\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end error in call to insertAffectionStatus
$field_list = array('affection_status_id','allele_code');
$term_array = array($affection_status_id,$i);
$mode_array = array('equal','equal');
$affect_status_allele_rec_list = compoundTableQuery('affection_status_allele_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
if (!is_array($affect_status_allele_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #23: $date<br>\n";
echo "Error in call to compoundTableQuery from define_affection_status.php<br>\n";
echo "$affect_status_allele_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end error in call to compoundTableQuery
if (sizeof($affect_status_allele_rec_list) == '0')
{
$date = date('Y-m-d H:i:s');
echo "Error #24: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "Inserted affection status allele record for Affection Status ID $affection_status_id ";
echo "and Allele Code $i for database id $database_id into the affection status allele table ";
echo "with the function insertAffectionStatusAllele, and it returned success. ";
echo "But when query the affection status allele table with that information \n";
echo "no records are returned. Something wrong with the database.<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end if no record in the database
elseif (sizeof($affect_status_allele_rec_list) == '1')
{
$affect_status_allele_rec = $affect_status_allele_rec_list[0];
$affect_status_allele_id = $affect_status_allele_rec['affection_status_allele_id'];
$date = date('Y-m-d H:i:s');
$log_file_statement = "$date:\t$_SESSION[user_name] Inserted new Affection Status Allele into Database ID $database_id, ";
$log_file_statement.= "for Affection Status ID $affection_status_id and Allele Code $i and assigned ";
$log_file_statement.= "Affection Status Allele ID $affect_status_allele_id.\n";
fwrite($log_file_handle,$log_file_statement);
}
else
{
$date = date('Y-m-d H:i:s');
echo "Error #25: $date<br>\n";
echo "!!!Stop Using Data in Database!!!<br>\n";
echo "Do Not Use the data until Database Administrator tells you it is Okay to use again.<br>\n";
echo "There is more than one record in the affection status allele table with \n";
echo "affection_status_id $affection_status_id and allele_code $i and database id $database_id.<br>\n";
echo "The affection status allele ids that are returned when the affection status allele table is queried with ";
echo "the above information are:<br>\n";
foreach ($affec_status_allele_rec_list as $affect_status_allele_rec)
{echo "$affect_status_allele_rec[affection_status_allele_id]<br>\n";}
echo "<br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end else error in data integrity
}#end else not an array of allele frequencies
$field_list_array = array('individual_table_id');
$individual_rec_list = tableQuery('individual_table',$database_id,$field_list_array,'_','wildcard','all');
if (!is_array($individual_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #26: $date<br>\n";
echo "Error in call to tableQuery from define_affection_status.php<br>\n";
echo "$individual_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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 ($individual_rec_list as $individual_rec)
{
$ret_val = insertIndividualAffectionStatusLink($database_id,$affection_status_id,$individual_rec['individual_table_id']);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #27: $date<br>\n";
echo "Error in call to insertIndividualAffectionStatusLink from define_affection_status.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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
$date = date('Y-m-d H:i:s');
$log_file_statement = "$date:\t$_SESSION[user_name] Inserted a New Individual-Affection Status Link into Database ID $database_id ";
$log_file_statement.= "for Affection Status ID $affection_status_id and Individual Table ID $individual_rec[individual_table_id].\n";
fwrite($log_file_handle,$log_file_statement);
}#end foreach individual create affection status link
$field_list_array = array('pedigree_table_id');
$pedigree_rec_list = tableQuery('pedigree_table',$database_id,$field_list_array,'_','wildcard','all');
if (!is_array($pedigree_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #28: $date<br>\n";
echo "Error in call to tableQuery from define_affection_status.php<br>\n";
echo "$pedigree_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
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 ($pedigree_rec_list as $pedigree_rec)
{
$ret_val = insertPedigreeAffectionStatusLink($database_id,$affection_status_id,$pedigree_rec['pedigree_table_id']);
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #29: $date<br>\n";
echo "Error in call to insertPedigreeAffectionStatusLink from define_affection_status.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
fclose($log_file_handle);
chmod("../data/$tmp_log_file",0777);
$command = "cat ../data/$tmp_log_file >> ../data/log_file.txt";
exec($command,$output_array,$return_code);
$command = "rm ../data/$tmp_log_file";
exec($command,$output_array,$return_code);
$ret_val = disconnect();
exit;
}#end error in call to insertPedigreeAffectionStatusLink
$date = date('Y-m-d H:i:s');
$log_file_statement = "$date:\t$_SESSION[user_name] Inserted a New Pedigree-Affection Status Link into Database ID $database_id ";
$log_file_statement.= "for Affection Status ID $affection_status_id and Individual Table ID $pedigree_rec[pedigree_table_id].\n";
fwrite($log_file_handle,$log_file_statement);
}#end foreach pedigree create affection status link
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 "Successfully added $affection_status_name as an affection category in the database.<br><br>\n";
echo "The database now is tracking the following affection statuses for individuals:<br><br>\n";
$field_list_array = array('affection_status_id');
$affection_status_rec_list = tableQuery('affection_status_table',$database_id,$field_list_array,'_','wildcard','all');
if (!is_array($affection_status_rec_list))
{
$date = date('Y-m-d H:i:s');
echo "Error #30: $date<br>\n";
echo "Error in call to tableQuery from define_affection_status.php<br>\n";
echo "$affection_status_rec_list<br><br>\n";
echo "Please email the above error message using the Comments/Help/Support link \n";
echo "on the left navigation bar.\n";
$ret_val = disconnect();
exit;
}#end error in call to tableQuery
echo "<table>\n";
foreach ($affection_status_rec_list as $affection_status_rec)
{
echo "<tr><td>$affection_status_rec[affection_status_name]</td></tr>\n";
}
echo "</table>\n";
echo "<br><br>\n";
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 #31: $date<br>\n";
echo "Error in call to getDatabase from define_affection_status.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 #32: $date<br>\n";
echo "Error in call to getAllUsers() from define_affection_status.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 Affection Status Defined in your Genetic Studies Database";
$message = "A new affection status named $affection_status_name is now being tracked in 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 #33: $date<br>\n";
echo "Error in call to tableQuery from define_affection_status.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 #34: $date<br>\n";
echo "Error in call to getUser from define_affection_status.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 #35: $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><br>\n";
printLogOutButton('define_affection_status.php');
}#end if have affection_status_name
}#end if (auth_user == '1')
$ret_val = disconnect();
echo "</body></html>\n";
?>