Source code for:
dvalidate.php
<HTML>
<HEAD>
<TITLE>Q7310 Validation ROUTINE </TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY bgcolor="#000000" text="white" link="#FFCC00" vlink="#FFCC00" alink="#00FF00">
<A name="print_sub"></A>
<?php
/*
====================================================================
prtBR = Function to print a line of text and move to a NEW line
prtBR ("the arguement is in double quotes for variable \$text");
======================================================================
*/
FUNCTION prtBR($text){
PRINT ("$text <br> \n");
}
// prtBR("This is printing routine.");
?>
<A name="print_tiger"></A>
<?php
/*
====================================================================
prtTiger = Function is to print the name of the sport
====================================================================
*/
FUNCTION prtTiger($text){
PRINT ("<hr> <FONT color='gold'>");
PRINT ("<h1> <center> MU $text Rules! </center> </h1> </FONT> \n");
}
// $sport="volleyball";
// prtTiger("$sport");
?>
<?php
FUNCTION prtData($where) {
SETTYPE($formdata, 'array');
$max=40;
PRINT ("DEBUG Printing $where \n");
FOR ($counter=0; $counter<=$max; $counter++) {
PRINT("$counter: $formdata[$counter]");
}
}
?>
<TABLE width="90%" border="1" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD>
<CENTER>
<IMG src="../images/MissouriM_SM.gif" width="83" height="84">
</CENTER>
</TD>
</TR>
<TR>
<TD bgcolor="black">
<FONT color='yellow'>
<P align="center">
<H3> A moment, please!</H3>
<!--
==========================================================
INITIALIZE VARIABLES
==========================================================
==========================================================
MOVE DATA TO A TEMPORARY DATA ARRAY, $formdata
==========================================================
-->
<?
PRINT(" <h3> Checking your submission for errors . . ");
$max=10;
FOR ($counter=0; $counter<=$max; $counter++){
PRINT (" . ");
}
prtBR("</h3> <hr>");
SETTYPE($formdata, 'array');
$formdata[1]= $Level;
$formdata[2]= $OtherLevel2;
$formdata[3]= $Eligibility;
$formdata[4]= $Sport;
$formdata[5]= $GPA;
$formdata[6]= $APD;
$formdata[7]= $Transfer;
$formdata[8]= $Scholarship;
$formdata[9]= $Unit;
$formdata[10]= $study;
$formdata[11]= $Mentor;
$formdata[12]= $Mentor2;
$formdata[13]= $Tutor;
$formdata[14]= $Tutor2;
$formdata[15]= $SHall;
$formdata[16]= $SHall2;
$formdata[17]= $TGroup;
$formdata[18]= $TGroup2;
$formdata[19]= $t1;
$formdata[20]= $t2;
$formdata[21]= $t3;
$formdata[22]= $t4;
$formdata[23]= $t5;
$formdata[24]= $t6;
$formdata[25]= $t7;
$formdata[26]= $t8;
$formdata[27]= $t9;
$formdata[28]= $t10;
$formdata[29]= $t11;
$formdata[30]= $t12;
$formdata[31]= $t13;
$formdata[32]= $t14;
$formdata[33]= $Pro;
$formdata[34]= $Scareer;
$formdata[35]= $good;
$formdata[36]= $change;
$formdata[37]= $comment;
$today = date("Y-m-d");
$formdata[39]= $today;
$timestamp = date("H:i:s");
$formdata[38]= $timestamp;
//prtBR("$today $timestamp");
$errflag=0;
$max=34;
FOR ($counter=0; $counter<=$max; $counter++){
// prtBR ("$counter: $formdata[$counter]");
// Check for Errors in the For Loop
SWITCH ($counter){
CASE "1":
IF ($formdata[$counter] == NULL){
$errflag=1;
// prtBR ("Error Flag =$errflag");
prtBR ("Please select a year in school& Resubmit ");
}
BREAK;
CASE "2":
BREAK;//
CASE "3":
IF ($formdata[$counter] == NULL) {
$errflag=1;
prtBR ("Please select an eligibility status & Resubmit ");
}
BREAK;
CASE "4":
IF ($formdata[$counter] == NULL) {
$errflag=1;
prtBR ("Please select the primary sport you participate in & Resubmit");
}
BREAK;
CASE "5":
BREAK;
CASE "6":
IF ($formdata[$counter] == NULL){
$errflag=1;
prtBR ("Please answer the NCAA Academic Progress Question & Resubmit");
}
BREAK;
CASE "33":
IF ($formdata[$counter] == NULL){
$errflag=1;
prtBR ("Please answer the Professional Sports Question & Resubmit");
}
BREAK;
CASE "34":
IF ($formdata[$counter] == NULL){
$errflag=1;
prtBR ("Please answer the Sports Related Question & Resubmit");
}
BREAK;
DEFAULT:
// prtBR ("$counter <h1> $errflag </h1>");
}
}
// ======= MAXIMUM OF FOUR SELECTED IDEAS =============
$max=32;
$tcount=0;
FOR ($counter=19; $counter<=$max; $counter++) {
IF ($formdata[$counter] != NULL) {
$tcount++;
// prtBR("$tcount: $formdata[$counter]$tcount");
}
}
IF ($tcount > 4) {
$terror= $tcount - 4;
prtBR("You have selected <FONT color='red'> <b> $terror </b> </FONT> too many ideas; you will need to limit your TPP selections to four choices");
$errflag=1;
}
SWITCH ($errflag) {
CASE "0":
prtBR("Thank you for participating in this survey.");
prtTiger("$Sport");
BREAK;
CASE "1":
INCLUDE ("backmsg.php");
BREAK;
DEFAULT:
prtBR ("<h2> Survey Processing Error - Contact ryh352@mizzou.edu </h2>");
}
// ========================================================
?>
<?php
/*
================= ========================================
OPEN & WRITE RAW TEXT DATA FILE
==========================================================
*/
$filename = "iac_rawdata.txt";
IF (FILE_EXISTS ($filename)) {
// prtBR ("The file <b> $filename </b> exist.");
prtBR ("<center> * * * </center>");
} ELSE {
prtBR ("<FONT color='red'> $filename does not exist, please contact Web Developer </FONT>");
}
$fp = FOPEN( $filename, 'a' ) or DIE("Couldn't open $filename");
// prtBR ("$filename is open");
?>
<?php
$browser= GETENV("HTTP_USER_AGENT"); //DEBUG prtBR ("$browser");
FWRITE ($fp,"\n $browser ,$errflag , ");
$max=40;
FOR ($counter=0; $counter<=$t; $counter++) {
FWRITE($fp, "$formdata[$counter] , ");
}
FCLOSE($fp);
?>
</FONT>
<?php
SWITCH ($errflag) {
CASE "0":
/*
====================================================
SAVE VALID RECORD TO DATABASE
====================================================
*/
$user = "flatfilsoc";
$pass = "q7310";
$db = "iac_survey";
$table = "iac_test";
// CONNECT TO SERVER =================================
$link = mysql_connect("mysql", $user, $pass)OR DIE ( "Could not connect to MySQL" );
// PRINT "Successfully <b> connected </b> to server<P>";
// SELECT DATABASE =========================================
mysql_select_db($db) OR DIE ( "Couldn't open $db: ".mysql_error() );
// PRINT "Successfully selected database <b> \"$db\" </b><P>";
// SELECT TABLE ===============================================
$query = "SELECT * FROM $table";
$result = mysql_query($query);
// PRINT "Successfully selected table <b> \"$table\" </b> <P>";
/*
========================================================
INSERT NEW RECORD
========================================================
*/
$max=40;
FOR ($counter=0; $counter<=$max; $counter++){
// prtBR ("$counter: insert $formdata[$counter]");
}
$sql = "INSERT INTO $table(record,Level, OtherLevel2, Eligibility, Sport, GPA, APD, Transfer, Scholarship,
Unit, study, Mentor, Mentor2, Tutor,Tutor2, SHall, SHall2, TGroup, TGroup2, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
t11, t12, t13, t14,Pro, Scareer, good, Bcomment, Ocomment, time1, date1)
VALUES (NULL, '$Level', '$OtherLevel2','$Eligibility', '$Sport', '$GPA', '$APD','$Transfer','$Scholarship', '$Unit',
'$study','$Mentor', '$Mentor2', '$Tutor', '$Tutor2','$SHall', '$SHall2', '$TGroup', '$TGroup2', '$t1', '$t2', '$t3','$t4', '$t5', '$t6', '$t7', '$t8', '$t9',
'$t10', '$t11', '$t12','$t13', '$t14', '$Pro', '$Scareer', '$formdata[35]',
'$formdata[36]', '$formdata[37]','$timestamp', '$today')";
/*
=====================================================
=====================================================
DISPLAY LAST INSERTED RECORD
=====================================================
=====================================================
*/
$select=mysql_query("SELECT * FROM $table") OR DIE (mysql_error());
$num_rows = mysql_num_rows($select);
$lastrecord=($num_rows + 100) - 1;
$query ="SELECT * FROM $table WHERE record = $lastrecord";
$select = mysql_query($query);
$prt_row= mysql_fetch_array($select);
PRINT "<table width='75%' border='2'align='center'>";
$max=40;
PRINT " <tr> <td width='20%'> <FONT color='gold'>Item No. </FONT></td> <td align='center'> <h3> ";
PRINT "<FONT color='gold'>Your Survey Responses </h3> </FONT></td>";
PRINT "<tr>";
FOR ($counter=0; $counter<$max; $counter++){
$line=($counter +1);
IF ($prt_row[$counter] != NULL) {
PRINT " <td width='20%'>$line</td><td>$prt_row[$counter]</td> </tr>";
}
}
PRINT "<tr></td>.</td>";
PRINT "</tr> </table>";
$result = @mysql_query($sql, $link) OR DIE (mysql_error());
prtBR ("<FONT color='gold'> <center> Your survey was successfully saved to <b> \"$table\" </b> </center> </FONT>");
prtBR ("<center> Currently $num_rows survey records submitted; ID: $lastrecord </center>");
/*
=============================================
CLOSE SERVER
=============================================
*/
mysql_close($link);
// PRINT "Successfully <b> disconnected</b> from server<P>";
BREAK;
CASE "1":
PRINT "<center> Return to Survey </center>";
BREAK;
DEFAULT:
prtBR ("<h2> Database Insertion Error - Contact ryh352@mizzou.edu </h2>");
}
?>
</TD>
</TR> </TABLE>
<HR>
Last Updated <I>:
<!-- #BeginDate format:fcAm1m -->Tuesday, November 23, 2004 18:31<!-- #EndDate -->
</I>
<P>
<FONT face="Arial, Helvetica, sans-serif" size="1">
(c) 2004 Robin Y. Mabry Hubbard <A href="mailto:4ascii@marz.com">4ascii@marz.com</A>
</FONT>
</P>
</BODY>
</HTML>
|