<?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';
$access_type_required = 'search';
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>View Affection Statuses</title>\n";
echo " </head>\n";
echo "<body bgcolor=\"white\">\n";
echo "<center><h3>View Affection Statuses</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo "<br>\n";
$ret_val = connect();
if ($ret_val != '1')
{
$date = date('Y-m-d H:i:s');
echo "Error #1: $date<br>\n";
echo "Error in call to connect from affection_status_view.php<br>\n";
echo "$ret_val<br><br>\n";
echo "Please email the above error using the Comments/Help/Support link \n";
echo "in the left navigation bar.<br>\n";
echo "</body></html>\n";
exit;
}
#1 Authenticate User
if (isset($_POST['end_session']))#if want to end session
{
#if (key_exists('files_on_server',$_SESSION))
# {
# $files_to_delete_array = $_SESSION['files_on_server'];
# $ret_val = deleteFiles($files_to_delete_array);
# if ($ret_val != '1')
# {
# $date = date('Y-m-d H:i:s');
# echo "Error #2: $date<br>\n";
# echo "Error in call to deleteFiles from affection_status_view.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 affection_status_view.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('affection_status_view.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 affection_status_view.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 affection_status_view.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 affection_status_view.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 affection_status_view.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('affection_status_view.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 affection_status_view.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('affection_status_view.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 affection_status_view.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 affection_status_view.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'];
echo "The following are all the Affection Status records that have been defined in the database. \n";
echo "If you would like to add more Affection Statuses use the Define Affection Statuses utility on the left \n";
echo "navigation bar. If you would like to change or edit any of the records use the Edit/Update Record \n";
echo "utility on the left navigation bar.<br><br>\n";
echo "<center><b>Defined Affection Statuses</b></center><br><br>\n";
$ret_val = printStatusViewTable($database_id);
if ($ret_val == '0')
{
echo "Error in call to printStatusViewTable from affection_status_view.php<br>\n";
echo "See the above error message from printStatusViewTable for an explanation of the error<br><br>\n";
echo "Please email the above error message using the Comments/Help/Suggestions link \n";
echo "on the left navigation bar.\n";
echo "</body></html>\n";
$ret_val = disconnect();
exit;
}
echo "<br><br>\n";
$ret_val = printLogOutButton('affection_status_view.php');
}#end if auth_user
$ret_val = disconnect();
echo "</body></html>\n";
?>