Location: PHPKode > projects > Enzyme: PHP profile/object community mgr > Enzyme-0.6.3/main/edit/register2.php3
<?page_open( array("sess" => "Poe_Session", "auth" => "Poe_Challenge_Auth", "perm" => "Cat_Perm", "user" => "Poe_User"));
$perm->check( "temp" );

//print( "admin_mode: $admin_mode<br>\n" );
// if the person already has student permissions, they have already completed registration. 
// Send 'em to the profile editor.
if( $perm->have_perm( "student" ) )
{
  header("Location: index.php3");
  exit;
}

// Values from the referrer table for these three referrers, who have to be dealt with specially.
define( "CAMPUS_ORG_REF_ID", 999 ); 
define( "INDIVIDUAL_REF_ID", 6 ); 
define( "CAMPUS_REP_REF_ID", 999  );

$PAGE_TITLE = "Registration Step 2";
$no_menubar = 1;
$no_suggest = 1;
include "cat_header_code.inc";

// needed to send the various emails later in the script
require( "EmailTemplate.inc" );

// set up the FORM objects

include( "setup_personal.inc" );

// the 'true' argument indicates this is the registration page, and not the personal page
$f = setup_personal( true, $admin_mode );

$error = $f->validate();
// BEGIN special error checking
if( $password1 != $password2 ) 
{
  $error = "Passwords do not match.";
  $pwd_err = $error;
  // need a special variable here because the message 
  //doesn't get displayed by the standard ooh forms validation stuff.
}
if( $student_referrer_referrerid == INDIVIDUAL_REF_ID ) {
  if( empty( $unamebox ) ) 
    {
      $error = "You must supply the Catalyst username of the person who referred you.";
    }
  else 
    {
      $db = new DB_Readonly;
      $query = "
SELECT * FROM
user
WHERE 
name = \"$unamebox\";";

      $db->query( $query );
      // make sure the user exists and that it's not the person him or herself
      if( $db->nf() == 0 or 
	  $unamebox == $auth->auth["uname"] )
	$uref_err = $error = "We don't have anyone registered with this username. Please make sure you've typed it correctly.";
      else 
	{
	  // send an email to the lucky person, letting them know
	  // that they are very close to winning a free CD

	  $db->next_record();
	  $ue = new Email;
	  //global $ref_count, $ref_firstname, $ref_lastname, $ref_email;
	  $ref_count = $db->nf();
	  $ref_firstname = $db->f("firstname");
	  $ref_lastname = $db->f("lastname");
	  $ref_email = $db->f("email");
	  $ref_username = $db->f("name");
 
	  $globals = "\$ref_count, \$ref_firstname, \$ref_lastname, \$ref_email, \$user_email, \$ref_username";
	  $ue->load( "referral_email.txt", $globals );
	  
	  // don't send the email if there is an error!
	  if( empty( $error ) )
	    {
	      $ue->send();
	      //$ue->report();
	    }
	}
    }
  //$uref_err = $error;
}
else if( $student_referrer_referrerid == CAMPUS_ORG_REF_ID and $known_schoolid <= 0 ) {
  $error = "You must specify the school of the Campus Organization.";
  $orgref_err = $error;
}
// END special error checking

// BEGIN BIG INSERTION IF STATEMENT
if( isset( $submit_new ) && !$error ) 
{
  include( "UpdateOrInsert.inc" );
  $HTTP_POST_VARS["contact_info_firstname"] = $user_firstname;
  $HTTP_POST_VARS["contact_info_lastname"] = $user_lastname;
  $HTTP_POST_VARS["contact_info_email"] = $user_email;
  // if we get here, passwords should match.
  $HTTP_POST_VARS["user_password"] = $password1;
  $contactid = UpdateOrInsert( "contact_info", 0, array( "contact_infoid" ) );
  if( $user_wantsmail ) {
    $HTTP_POST_VARS["student_setting_settingid"] = 1;
    $HTTP_POST_VARS["student_setting_level"] = 1;
  }
  else {
    $HTTP_POST_VARS["student_setting_settingid"] = 1;
    $HTTP_POST_VARS["student_setting_level"] = 0;
  }
  $HTTP_POST_VARS["user_contact_infoid"] = $contactid;
  $HTTP_POST_VARS["user_contact_infoid_2"] = $contactid2;
  $HTTP_POST_VARS["user_name"] = $user_name = $auth->auth["uname"];
  $userid = UpdateOrInsert( "user", 0, array( "name" ) );
  $HTTP_POST_VARS["student_userid"] = $userid;
  $stid = UpdateOrInsert( "student", 0, array( "userid" ) ); 
  
  $db = new DB_Poe;
  
  // if we know their school, let's give them a student_school record for free. 
  // Worst comes to worst, they can always delete it...
  if( $known_schoolid <= 0 && $REMOTE_ADDR ) 
    {
      $domain = gethostbyaddr( $REMOTE_ADDR );
      $arr = explode( ".", $domain );
      for( $i = 0; $i < sizeof($arr); $i++ ) {
	if( strtolower( $arr[$i] ) == "edu" )
	  $schoolname = $arr[$i-1];
      }
      if( $schoolname ) 
	{
	  $query = sprintf( "SELECT schoolid FROM school WHERE (LCASE(abbr) = '%s');", 
			    strtolower($schoolname) );
	  $db->query( $query );
	  $db->next_record();
	  if( $db->nf() == 1 )
	    $known_schoolid = $db->f( "schoolid" );
	}
    }
  
  if( $known_schoolid > 0 ) 
    {
      $query = sprintf( "INSERT INTO student_school ( studentid, schoolid ) VALUES ( %d, %d );",
			$stid,
			$known_schoolid
			);
      $db->query( $query );
    }
  
  $query = sprintf( 
		   "UPDATE auth_user SET userid = %d, perms='student', password = '%s' WHERE ( uid = '%s' );",
		   $userid,
		   $password1,
		   $auth->auth['uid']
		   );
  $db->query( $query );

  //   UpdateOrInsert( "student_stat", 0, array( "student_statid" ) );
  $query = "INSERT INTO student_stat( studentid ) values ( $stid );";
  $db->query( $query );

  //Here we set up the email to be sent- it is actually sent when we check for $success later.

  $e = new Email;
  $globals = "\$password1, \$user_email, \$user_firstname, \$user_lastname, \$user_name";
  $e->load( "register2_email.txt", $globals );
  
  switch( $student_referrer_referrerid ) 
    {
    case CAMPUS_ORG_REF_ID:
      $special_ref = "campus_org";
      break;
      //case CAMPUS_REP_REF_ID:
      //$special_ref = "campus_rep";
      //break;
    default:
      //if( $student_referrer_referrerid != CAMPUS_ORG_REF_ID ) { //and $student_referrer_referrerid != CAMPUS_REP_REF_ID ) { 
      //for campus org and campus rep, we need to do a separate page.
      //Do the update here.
      $HTTP_POST_VARS["student_referrer_studentid"] = getStudentid();
      $HTTP_POST_VARS["student_referrer_http_refererid"] = $referer_array['id'];

      // signifies Individual Catalyst User, in which case, we need to take from the box.
      if( $student_referrer_referrerid == INDIVIDUAL_REF_ID ) 
	{ 
	  $unamebox = trim( $unamebox );

	  if( $HTTP_POST_VARS["student_referrer_user_ref"] = $unamebox )
	    {	  
	      
	      // do nothing right now...
	    }
	}

      if( $referer_array['host'] )
	{
	  $HTTP_POST_VARS['student_referrer_http_host_ref'] = $referer_array['host'];
	  $sess->unregister( "referer_array" );
	}

      $key = array( "studentid" ); // each student can have only one referrer!
      UpdateOrInsert( "student_referrer", 0, $key );
      break;
    }

  $auth->auth["perm"] = "student";
  $success = TRUE;
} 
// END OF BIG INSERTION IF STATEMENT

if( $success and !$special_ref ) {
  if( !$admin_mode )
    $e->send();
  page_close();
  header( "Location: index.php3" );
}
// we have a special referrer (ie campus org) so go to referrer.php3
else if( $success ) {
  if( !$admin_mode )
    $e->send();
  page_close();
  header( "Location: referrer.php3?known_schoolid=$known_schoolid&special_ref=$special_ref" );
}

//Load up the person's first, last, email, which we know from Register 1.
$db = new DB_Poe;
$query = sprintf( 
    "SELECT * FROM auth_user NATURAL LEFT JOIN user WHERE ( uid = '%s' );",
    $auth->auth['uid']
    );
$db->query( $query );
$db->next_record();

$user_firstname = $db->f("firstname");
$user_email = $db->f("email");
$user_lastname = $db->f("lastname");

//if we have a referring username registered in the session from register.php3, load it up now.
if( $sess_refname ) {
  // make sure the user exists before we do all this fancy stuff
  $db->query( "SELECT * FROM user WHERE name = \"$sess_refname\"" );
  if( $db->nf() != 0 ) {
    $db->next_record();
    $refrealname = $db->f( "firstname" ) . " " . $db->f( "lastname" );
    $unamebox = $sess_refname;
    $student_referrer_referrerid = INDIVIDUAL_REF_ID;
    $sess->unregister( "sess_refname" );
    $f->freeze( array( "unamebox", "student_referrer_referrerid" ) );
  }
}


include( "cat_header_layout.inc" );
?>
<?
$f->no_javascript = true;

$f->start();
$f->show_element( $sess->classname );
?>
<? 
$f->load_defaults();
?>
<table border="0" cellpadding="2" cellspacing="2" width="100%">
	<tr height="6">
		<td height="6" colspan="4">
<H2>Registration: Step 2</H2>
<H3>On this page, we ask you for a little bit more information in order to complete the Catalyst registration process.
The fields marked with asterisks are required.</H3>
<? if( $error ): ?>
<font color="red"><H3>An error occurred. Please see below.</H3></font>
<? endif; ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">First Name *</font></td>
		<td height="18" >
<? $f->show_element( 'user_firstname' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Last Name *
			</font></td>
		<td height="18" >
<? $f->show_element( 'user_lastname' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">E-mail *</font></td>
		<td height="18" >
<? $f->show_element( 'user_email' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" colspan="4">
		Please choose a new password for your account. It should be something easy for you to remember, but hard
		for someone else to guess. It must be at least 6 characters long.
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">New password *</font></td>
		<td height="18" >
<font color="red" size="2"><i><? echo $pwd_err; ?></i></font>
<? $f->show_element( 'password1' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">Retype new password *</font></td>
		<td height="18" >
<? $f->show_element( 'password2' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Gender *
			</font>
		</td>
		<td height="18" >
<? $f->show_element( 'student_gender' ); ?>
		</td>
	</tr>
	<tr height="18">
		<td height="18" width="125">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Ethnicity *
			</font>
		</td>
		<td height="18" >
		        <? $f->show_element( 'student_ethnicityid' ); ?>
		</td>
	</tr>
<? /*************
	<tr>
		<td width="125" height="20">
			<font color="<< echo $cat_textOnLightBKG; >>">
			Personal Homepage
			</font>
		</td>
		<td  height="20">
                << $f->show_element( 'student_url' ); >>
		</td>
	</tr>
   ******************************/ ?>
	<tr>
		<td colspan="2">
			<hr>
			<b>Current address</b>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>"><br>
			Street address line 1 *
			</font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_street1' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Street address line 2
			</font>
		</td>
		<td  height="14" align="left">
		<? $f->show_element( 'contact_info_street2' ); ?>
		</td>  
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			City *
 			</font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_city' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			State *</font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_stateid' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Province (non-USA)</font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_otherstate' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Zip/Postal Code *</font>
  		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_zip' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Country *
			</font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_countryid' ); ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			 Daytime Phone *
			 </font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_phone' ); ?>
&nbsp;&nbsp;
<font color="<? echo $cat_textOnLightBKG; ?>">
Ext
</font>
&nbsp;&nbsp;
<? $f->show_element( 'contact_info_extension' ); ?>
		</td>
 	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
          Evening Phone
          </font>
		</td>
		<td  height="14" align="left">
<? $f->show_element( 'contact_info_phone2' ); ?>
&nbsp;&nbsp;
<font color="<? echo $cat_textOnLightBKG; ?>">
Ext
</font>
&nbsp;&nbsp;
<? $f->show_element( 'contact_info_extension2' ); ?>
		</td>
	</tr>

<? /******************************************************************************
	<tr>
		<td colspan="2">
			<hr>
			<b>Permanent address (optional)</b>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14" valign="middle">
			<font color="<< echo $cat_textOnLightBKG; >>"><br>
			Street
			</font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_street1_1' ); >>
<br>
<< $f->show_element( 'contact_info_street2_1' ); >>
		</td>  
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			City
 			</font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_city_1' ); >>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			State</font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_stateid_1' ); >>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			Province (non-USA)</font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_otherstate_1' ); >>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			Zip/Postal Code</font>
  		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_zip_1' ); >>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			Country
			</font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_countryid_1' ); >>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<< echo $cat_textOnLightBKG; >>">
			 Daytime Phone
			 </font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_phone_1' ); >>
		</td>
 	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
          Evening Phone
          </font>
		</td>
		<td  height="14" align="left">
<< $f->show_element( 'contact_info_phone2_1' ); >>
		</td>
	</tr>
******************************************************************************/ ?>
	<tr>
		<td colspan="2">
			<hr>
			<b>How did you hear about Catalyst? (required)</b>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
			<font color="<? echo $cat_textOnLightBKG; ?>">
			Source *</font>
		</td>
		<td  height="14" align="left">
		<? // GENERIC REFERRERS
		$f->show_element( "student_referrer_referrerid" ); 
?>
		</td>
	</tr>
		<tr>
		<td width=125>
		<font color="<? echo $cat_textOnLightBKG; ?>">
		Please specify (e.g., name of site):
		</td>
		<td>
		<? $f->show_element( "student_referrer_other_ref" ); ?>
		</td>
		</tr>
	<tr height="14">
		<td width="125" height="14">
        

<!--		Referrer username (if applicable): -->
		If you were referred by another Catalyst user, please list their username here:
		</font>
		</td>
		<td height="14">
		<? print( "<font size=\"2\" color=\"red\"><i>$uref_err</i></font>" ); ?><br>
		<? print( $refrealname ? "$refrealname<BR>" : "" ); ?>
		<?
		$f->show_element( "unamebox" );
                ?>
		</td>
	</tr>
	<tr height="14">
		<td width="125" height="14">
		<font color="<? echo $cat_textOnLightBKG; ?>">
		Campus where you heard about Catalyst (if applicable):
		</font>
		</td>
		<td  height="14" align="left">
		<? print( "<font size=\"2\" color=\"red\"><i>$orgref_err</i></font>" ); ?><br>
		<? $f->show_element( "known_schoolid" ); //SCHOOL SELECT ?>
		</td>
	</tr>
	<tr height="5">
		<td height="5" colspan="2">
		</td>
	</tr>
		<tr>
		<td allign="left">
		<font size="2" color="<? echo $cat_textOnLightBKG; ?>">
		* required fields
		</font>
		</td>
	</tr>
<tr>
		<td colspan="2">
		<hr size="1">
		</td>
		</tr>
		<tr>
		<td height="14" allign="left" colspan="2">
		<blockquote>
		<? $f->show_element( "user_wantsmail" ); ?>
		<font color="<? echo $cat_textOnLightBKG; ?>">
		I'd like to hear from Catalyst from time to time about special job opportunities, career news and advice, and deals from our partners.

		</font>
		</blockquote>
		</td>	       
		</tr>

       	<tr>
		<td colspan="2">

<? $f->show_element( 'submit_new', 'Begin editing your profile' ); ?>

		</td>
<!--<td>to  				
begin editing your online profile. You will be asked to log in with your username and password one last time.
</td>-->
	</tr>
<? $f->finish(); ?>
</table>
<!-- BEGIN CAT_FOOTER.INC -->
<? include( "cat_footer.inc" ); ?>
<? page_close(); ?>
Return current item: Enzyme: PHP profile/object community mgr