Location: PHPKode > projects > Enzyme: PHP profile/object community mgr > Enzyme-0.6.3/main/edit/tests.php3
<?
page_open(array("sess" => "Poe_Session", "auth" => "Poe_Challenge_Auth", "perm" => "Cat_Perm", "user" => "Poe_User"));
$perm->check( "student" );
?>
<? 
$PAGE_TITLE = "Catalyst Recruiting";
include "cat_header_code.inc"; 
include( "date.inc" );
include( "UpdateOrInsert.inc" );
?>
<? 
function doInsertTest( $testid, $score )
{
  global $HTTP_POST_VARS;

  $HTTP_POST_VARS[ "student_test_testid" ] = $testid;
  $HTTP_POST_VARS[ "student_test_score" ] = $score;
  $HTTP_POST_VARS[ "student_test_studentid" ] = getStudentid();
  addDateToPost( "student_test_testdate" );
  if( $score > 0 ) // this is a TEMPORARY fix for SQL errors on attempts to 'save' empty forms.
    UpdateOrInsert( "student_test", 0, array( "studentid", "testid" ) );
  else if( empty( $score ) )
    deleteEntry( "student_test", array( "testid", "studentid" ), array( $testid, getStudentid() ) ); 
}

$db = new DB_Poe;

if( !isset( $which ) )
     $which = "testsat";

include( "setup_tests.inc" );
$input_form = setup_tests( $which );


$error = $input_form->validate();

if( !$error && (isset( $submit_item ) or isset( $Next ) ))
{     
  switch( $which )
    {
    case "testsat":
	// need to do three update/inserts
	// first is SAT Verbal
	doInsertTest( $SATV_id, $SATV_score );
	// next is SAT Math
	doInsertTest( $SATM_id, $SATM_score );
	// next is the whole SAT
	doInsertTest( $SAT_id, $SATM_score + $SATV_score );
	if( isset( $Next ) )
	  header( "Location: tests.php3?which=testgre" );
	break;
	
    case "testmcat":
      doInsertTest( $MCATP_id, $MCATP_score );
      doInsertTest( $MCATB_id, $MCATB_score );
      doInsertTest( $MCATV_id, $MCATV_score );
      doInsertTest( $MCATE_id, $MCATE_score );
      if( isset( $Next ) )
	header( "Location: tests.php3?which=testlsat" );
      break;
    case "testlsat":
      doInsertTest( $LSAT_id, $LSAT_score );
      if( isset( $Next ) )
	header( "Location: samples.php3?which=samplesWriting" );
      break;
    case "testgre":
      doInsertTest( $GREV_id, $GREV_score );
      doInsertTest( $GREQ_id, $GREQ_score );
      doInsertTest( $GREA_id, $GREA_score );
      if( isset( $Next ) )
	header( "Location: tests.php3?which=testmcat" );
      break;
   }

} elseif( !$error ) {

  $stid = getStudentid();
  $query = sprintf( "SELECT * FROM test NATURAL LEFT JOIN student_test WHERE( studentid = %d );", $stid );
  $db->query( $query );

  while( $db->next_record() )
    {
      $testabbr = $db->f( 'abbr' );
      ${ $testabbr . '_score' } = $db->f( 'score' );
      ${ $testabbr . '_date' } = $db->f( 'testdate' );
      //$student_test_testdate = $db->f( 'testdate' );
    }
}

if( $which == "testsat" )
     $student_test_testdate = $SAT_date;
else if( $which == "testgre" )
     $student_test_testdate = $GREV_date;
else if( $which == "testmcat" )
     $student_test_testdate = $MCATE_date;
else if( $which == "testlsat" )
     $student_test_testdate = $LSAT_date;
//if there's nothing entered, make day = 1 so load_defaults won't wipe it out.
if( !$student_test_testdate )
     $student_test_testdateDay = 1;

?>
<?
$cat_body = "#ffffff";
include( "cat_header_layout.inc" );

$input_form->load_defaults();

$inc = $which . ".inc";

if( empty( $which ) || !file_exists( $inc ) ) {
  $which = "testsat";
  $inc = "testsat.inc";
}

?>
<? //-- header/tab stuff for tests pages. Will need to be cleaned up later. ?>
<!--<br>-->
<table border="0" cellpadding="3" cellspacing="0" frame width="100%">
	<tr>
		<td width="112" bgcolor="#3130CE" colspan="2">
			<img src="headerImages/testHeader.gif">

		</td>
	</tr>
</table>
<?
$help = "tests";
$form_action = "$PHP_SELF?which=$which";
include( "navBarTop.inc" );
$query = "SELECT * FROM test;";
$db->query($query);
while( $db->next_record() )
{
  $testabbr = $db->f( 'abbr' );
  printf( "<INPUT TYPE=hidden NAME='%s' VALUE='%d'>\n", $testabbr."_id", $db->f('testid') );
}

?>
<INPUT type="hidden" name="which" value="<? echo $which ?>">
<INPUT type="hidden" name="<? echo $sess->classname ?>" value="<? echo $sess->id ?>" >

<center>
<p>
<table border="0" cellpadding="0" cellspacing="0" width="460">
	<tr valign="bottom" bgcolor="#ffffcc">
		<th height="12">
			<center>
                        <? if( $which == "testsat" ): ?>
			<img src="tabs/testSatOn.gif"></font>
			<? else: ?>
			<a href="<? $sess->purl( 'tests.php3?which=testsat' ); ?>">
			<img src="tabs/testSat.gif" border="0" alt="SAT"></a>
			<? endif; ?>
			</center>
		</th>
		<th height="12">
			<center>
                        <? if( $which == "testgre" ): ?>
			<img src="tabs/testGreOn.gif"></font>
			<? else: ?>
			<a href="<? $sess->purl( 'tests.php3?which=testgre' ); ?>">
			<img src="tabs/testGre.gif" border="0" alt="GRE"></a>
			<? endif; ?>
			</center>
		</th>
		<th height="12">
			<center>
                        <? if( $which == "testmcat" ): ?>
			<img src="tabs/testMcatOn.gif"></font>
			<? else: ?>
			<a href="<? $sess->purl( 'tests.php3?which=testmcat' ); ?>">
			<img src="tabs/testMcat.gif" border="0" alt="MCAT"></a>
			<? endif; ?>
			</center>
		</th>
		<th height="12">
			<center>
                        <? if( $which == "testlsat" ): ?>
			<img src="tabs/testLsatOn.gif"></font>
			<? else: ?>
			<a href="<? $sess->purl( 'tests.php3?which=testlsat' ); ?>">
			<img src="tabs/testLsat.gif" border="0" alt="LSAT"></a>
			<? endif; ?>
			</center>
		</th>
	</tr>
<!-- END TABS -->

<?
   include( $inc );  
//   $input_form->finish();
?>

<!-- BEGIN CAT_FOOTER.INC -->
<? //all this is commented because the navbar is in the main body. I don't
   //who put this here, but it's wrong. --Clark ?>
<!table border="0" cellspacing="0" cellpadding="0" width="100%" height="220">
<!tr>
<!td valign="bottom">
<? //include( "navBarBottom.inc" ); ?>
<!/td>
<!/tr>
<!/table>
<? include( "cat_footer.inc" ); ?>
Return current item: Enzyme: PHP profile/object community mgr