here is the monster code so far
THE THREE FILES ARE AVAILABLE AT
http://www.qnctv.com/testbed/firstphp/science/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
DESCRIPTION OF PAGE
PAGE NAME: upload_check_insert_page.php
WHAT THIS PAGE DOES:
This page UPLOADS three files.
places their info into arrays
queries the database with this info
This information is displayed in a form
Editing is allowed
Final version is placed into database
-->
<!-- connect to database and generate page title -->
<?php
// set parameters
$dbhost = '******';
$dbuser = '********';
$dbpass = '*********';
$dbname = 'qncqnc_lodscore';
// different tables may be queried. but this is the table to insert final information.
$insert_dbtabl = 'raw_allele';
// fields are:
// ui (primary, auto incre)
// fam_ui (key that links to fam data table and is basically the first two in the ped file)
// marker_name (which comes from the dat file) ,
// alleles1 and alleles 2 (both from ped file)
// and original file (which comes from smp file)
// Connect to the database server
$dbcon = mysql_connect($dbhost, $dbuser, $dbpass) OR die('could not connect to MySQL: ' . mysql_error());
// Select the database
mysql_select_db ($dbname) OR die('could not connect to database: ' . mysql_error());
// PAGE TITELS
// information about family and markers or just display "upload page"
if(!isset($_POST['submit']))
{
$page_title='upload_page';
}
else
{
$page_title="info for $no_markers markers ending in $matches[n] for $fam_items[0] family";
}
echo "<title> $page_title </title>";
//for pretty html code
echo "\n"; //end
?>
<!-- link JavaScript and css elements and close head -->
<script src="../page_elements/form_go_on_select.js"></script>
<link rel="stylesheet" type="text/css" href="../page_elements/qnctv_css_style_sheet.css" />
<!-- end head -->
</head>
<!-- link body tag -->
<?php
include('../page_elements/body.htm'); //end
//for pretty html code
echo "\n"; //end
?>
<!--
UPLOAD FORM
Aim of form: to browse for files on computer viewing page.
upload the file to $pedlines, $datlines and $smplines
-->
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
print_r($_POST);
if( !isset($_POST['submit'])) { ?>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Ped file: <input name="pedfile" type="file" /><br />
Dat file: <input name="datfile" type="file" /><br />
Smp file: <input name="smpfile" type="file" /><br />
<input type="submit" name="submit" value="Upload Files" />
</form>
<?php }
else {
$uploaddir = './'; // same folder as this file set permission to 0777
$pedupload = $uploaddir . basename($_FILES['pedfile']['name']);
$datupload = $uploaddir . basename($_FILES['datfile']['name']);
$smpupload = $uploaddir . basename($_FILES['smpfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['pedfile']['tmp_name'], $pedupload) &&
substr($_FILES['pedfile']['name'],-4) == ".ped") {
echo "Ped file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
if (move_uploaded_file($_FILES['datfile']['tmp_name'], $datupload)&&
substr($_FILES['datfile']['name'],-4) == ".dat") {
echo "Dat file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
if (move_uploaded_file($_FILES['smpfile']['tmp_name'], $smpupload)&&
substr($_FILES['smpfile']['name'],-4) == ".smp") {
echo "Smp file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
$pedlines = file($pedupload);
$datlines = file($datupload);
$smplines = file($smpupload);
// unlink files after info loaded into array
// ? will it upset the !isset protocol ?
@unlink($_FILES['pedfile']['tmp_name']);
@unlink($_FILES['datfile']['tmp_name']);
@unlink($_FILES['smpfile']['tmp_name']);
// check data in files WILL BE REMOVED IN FINAL VERSION!!
$pedlines_implode = implode(" " , $pedlines);
$datlines_implode = implode(" " , $datlines);
$smplines_implode = implode(" " , $smplines);
echo "<br /><br /><br /><br />";
echo "ped file contains <br /><br /> $pedlines_implode <br /><br /><br />";
echo "dat file contains <br /><br /> $datlines_implode <br /><br /><br />";
echo "smp file contains <br /><br /> $smplines_implode <br /><br /><br />";
}
?>
<!--
NOW WE START THE MAIN DATA GATHERING AND EDIT FORM PREPERATION:
Aim: is to
gather marker name information USING preg and foreach as suggested by IBBO @ webmaster-talk.com/
gather family and individual details
query fam_data table to get fam_ui for individual
query raw_allele data with fam_ui and marker data to see if record has been entered
if yes then as if replacement or insert
if insert then add "duplicate and $entry_date" to form
all other cases leave comments blank
insert form into database
-->
<?php
echo "preg_match_all and for each<br />";
// convert $datlines array to string using implode
$datlines_implode = implode(" " , $datlines);
// specify regular expression
$regex = '/(\w[0-9]+s[0-9]+)/';
// find expression in $datlines and pass to $matched array
preg_match_all($regex , $datlines_implode , $matched);
// take matched array and push values into match array
$match = Array();
foreach($matched[0] as $key=>$value){
array_push($match,$value);
}
$arr=array();
// for each marker look at each line of ped file and match the alleles and family data
foreach ($match as $value)
{
foreach($pedlines as $key_fam => $value_fam)
{
$arr[]=explode(" ",$value_fam);
// using $fam items = no result???
// this only gives the first and second letter ???
echo $arr[0]." ". $arr[1]." ". $value."<br />";
// WE WILL HAVE TO ADD THE DATA FROM THE SMP FILES AS WELL ALLELES
// add $fam_items[$match+6]." "$fam_items[$match+7].
}
}
// check if numbers are is correct
$no_markers = count($matched[0]);
$no_alleles = $no_markers*2;
echo "<br />$no_markers = number of markers<br />";
echo "$no_alleles = number of alleles<br />";
?>
<!--
THE FOLLOWING IS STILL TO BE WORKED OUT!!
TO BE INTERGRAGTED IN THE SECTION ABOVE
// query databse with $fam_i and $in_i
$sql = "SELECT fam_ui FROM fam_data WHERE fam_i = '".$fam_i."' AND in_i = '".$in_i."'";
$fam_ui_result = mysql_query($sql) or die ('Failed to execute ' . $sql . ' due to ' . mysql_error());
// get the actual $fam_ui number
$fam_ui_number = mysql_result($fam_ui_result,0,'fam_ui');
echo "$fam_ui_number = family number";
// if no $fam_ui_number number, then eneter into database as new entry
// and output subsequent $fam_ui_number number
//query raw_allele to see if person and marker have been entered before
$sql2="SELECT ui FROM raw_allele WHERE fam_ui++d_no == $fam_ui_result ++ $matches";
$duplicate_entry_result = mysql_query($sql2) or die ('Failed to execute ' . $sql2 . ' due to ' . mysql_error());
// make form with prefilled in $raw_allele_line
// IF REPLACE THEN JUST REPLACE
// IF INSERT THEN ADD DATE SO SUBSEQUENT SERACHES CAN BE DISTINGUSIHED
// inserts final file into database
// insert into database as REPLACE or INSERT.
// echo out success
-->
<!-- finish upload_page.php page -->
</body>
</html>