@@ -1,42 +1,30 @@
<?php
require_once (dirname (__FILE__).'/db.php' );
require_once (dirname (__FILE__).'/gen_user_id.php' );
require_once ("$dir/gen_user_id.php" );
if (! isset ($ _REQUEST ['user_name' ]))
$ nextPage = 'survey' ;
try
{
if (! isset ($ _REQUEST ['user_email ' ]))
if (! isset ($ _REQUEST ['user_name ' ]))
{
$ missing_arg = "either user_name or user_email" ;
throw new Exception ( 'Invoked without user_name in \$_REQUEST' , 404 ) ;
}
else
if (! isset ( $ _REQUEST [ 'user_email' ]))
{
$ mssing_arg = "user_name" ;
throw new Exception ( 'Invoked without user_email in \$_REQUEST' , 404 ) ;
}
}
else if (! isset ($ _REQUEST ['user_name' ]))
{
$ mssing_arg = "user_email" ;
}
if ( isset ($ missing_arg ) )
{
error_log (__FILE__.":: Invoked without $mssing_arg in \$_REQUEST" );
require (dirname (__FILE__).'/404.php' );
return ;
}
$ name = $ _REQUEST ['user_name' ];
$ email = $ _REQUEST ['user_email' ];
$ name = $ _REQUEST ['user_name' ];
$ email = $ _REQUEST ['user_email' ];
$ name = preg_replace ('/^\s+/' ,'' ,$ name );
$ name = preg_replace ('/\s+$/' ,'' ,$ name );
$ name = preg_replace ('/\s+/' ,' ' ,$ name );
if ( ! preg_match ('/[a-z][a-z.]+(\s[a-z][a-z.]+)+$/i' , $ name ) )
{
error_log (__FILE__ .":: Invalid user_name provided ($name)" );
if ( $ tt_nojs )
$ name = preg_replace ('/^\s+/' ,'' ,$ name );
$ name = preg_replace ('/\s+$/' ,'' ,$ name );
$ name = preg_replace ('/\s+/' ,' ' ,$ name );
if ( ! preg_match ('/[a-z][a-z.]+(\s[a-z][a-z.]+)+$/i' , $ name ) )
{
error_log (__FILE__ .":: Invalid user_name provided ($name)" );
if ( strlen ($ name ) > 0 )
{
$ tt_error = "You must provide both first and last name" ;
@@ -45,107 +33,70 @@
{
$ tt_error = "You must provide your name" ;
}
require (dirname (__FILE__).'/user_id_prompt.php' );
return ;
throw new Exception ('user_id_prompt' ,0 );
}
else
{
require (dirname (__FILE__).'/500.php' );
return ;
}
}
$ email = preg_replace ('/^\s+/' ,'' ,$ email );
$ email = preg_replace ('/\s+$/' ,'' ,$ email );
if ( ! preg_match ('/^([^\s@]+@[^\s@]+.[^\s@]+)?$/' , $ email ) )
{
error_log (__FILE__ .":: Invalid user_email provided ($email)" );
if ( $ tt_nojs )
$ email = preg_replace ('/^\s+/' ,'' ,$ email );
$ email = preg_replace ('/\s+$/' ,'' ,$ email );
if ( ! preg_match ('/^([^\s@]+@[^\s@]+.[^\s@]+)?$/' , $ email ) )
{
error_log (__FILE__ .":: Invalid user_email provided ($email)" );
$ tt_error = "Invalid Email ('$email') entered" ;
require (dirname (__FILE__).'/user_id_prompt.php' );
return ;
}
else
{
require (dirname (__FILE__).'/500.php' );
return ;
throw new Exception ('user_id_prompt' ,0 );
}
}
$ attempts = 0 ;
$ user_id = strtoupper ( gen_user_id ( $ tt_max_gen_id_attempts )) ;
$ db = db_connect ();
if ( ! $ db )
{
error_log (__FILE__.":: Failed to connect to database" );
require (dirname (__FILE__).'/500.php' );
return ;
}
error_log ("New User ID Generated: $user_id for: $name" );
$ found_id = false ;
for( $ i =0 ; $ found_id == false && $ i <$ tt_max_gen_id_attempts ; ++$ i )
{
$ user_id = gen_user_id ();
$ db = db_connect ();
try
{
$ sql = "insert into user_ids values ('$user_id')" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
throw new Exception ("Invalid SQL: $sql" ,500 );
}
error_log ("candidate ID: $user_id" );
$ sql = "insert into participants values ('$user_id','$name','$email')" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
throw new Exception ("Invalid SQL: $sql" ,500 );
}
$ sql = "select user_id from user_ids where user_id='$user_id'" ;
$ sql = "insert into participation_history values ('$user_id',$tt_year,0)" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
throw new Exception ("Invalid SQL: $sql" ,500 );
}
$ result = $ db ->query ($ sql );
if ( ! $ result )
$ _SESSION ['USER_ID' ] = $ user_id ;
setcookie ('USER_ID' , $ _SESSION ['USER_ID' ], time ()+30 *86400 );
}
finally
{
$ db ->close ();
error_log (__FILE__.":: Invalid SQL at line " .__LINE__.": $sql" );
require (dirname (__FILE__).'/500.php' );
return ;
}
else if ( $ result ->num_rows == 0 )
{
$ found_id = true ;
}
}
if ( $ found_id == false )
catch ( Exception $ e )
{
$ db ->close ();
error_log (__FILE__.":: Failed to generate a unique ID in $tt_max_gen_id_attempts attempts" );
require (dirname (__FILE__).'/500.php' );
return ;
}
$ code = $ e ->getCode ();
error_log ("New User ID Generated: $user_id for: $name" );
$ sql = "insert into user_ids values ('$user_id')" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
error_log (__FILE__.":: Invalid SQL at line " .__LINE__.": $sql" );
require (dirname (__FILE__).'/500.php' );
return ;
}
$ sql = "insert into participants values ('$user_id','$name','$email')" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
error_log (__FILE__.":: Invalid SQL at line " .__LINE__.": $sql" );
require (dirname (__FILE__).'/500.php' );
return ;
}
$ sql = "insert into participation_history values ('$user_id',$tt_year,0)" ;
$ result = $ db ->query ($ sql );
if ( ! $ result )
{
error_log (__FILE__.":: Invalid SQL at line " .__LINE__.": $sql" );
require (dirname (__FILE__).'/500.php' );
return ;
if ( $ code == 0 )
{
$ nextPage = $ e ->getMessage ();
}
else
{
throw $ e ;
}
}
$ _SESSION ['user_id' ] = $ user_id ;
setcookie ('USER_ID' , $ _SESSION ['user_id' ], time ()+30 *86400 );
require (dirname (__FILE__).'/survey.php' );
require ("$dir/$nextPage.php" );
?>