Просмотр файла phpmytourney/p_signup.php

Размер файла: 7.92Kb
<?php
//* note, this file is a modified version for the phpmytourney package.
/*********************************************************************
*	This file is part of the phpmyleague freeware package.
*	PhpMyLeague 
*	By : Jйrфme Poulin
*	Website : http://phpmyleague.tuxfamily.org
*	Email : [email protected] (DO NOT USE THIS FOR SUPPORT)
*	Support : http://phpmyleague.tuxfamily.org/forums/
*********************************************************************/
/*********************************************************************
*	Filename : p_signup.php
*	Created by : Jйrфme Poulin 
*	Last modification : 25-10-2001@Jйrфme Poulin
*
*	Modif @ 25-10-2001 @ Jйrфme Poulin 
*		==> Final Modification Before version 1.0.0a release
*
*
*********************************************************************/
/*********************************************************************
*  You can modify this file at your ease, but don't remove any 
*  copyright information !!!  In exchange for this entirely free 
*  scripts, all i'm asking is that you give me credit for it...
*
*  If you are interested in working on phpmyleague to make it even
*  better, i strongly encourage you to join my team.  Of course, i
*  w'ont pay you any money for your work, since i'm not making any 
*  from mine, but everything you do will be credited.
*********************************************************************/
/**************************************
 Includes et Database Connection
**************************************/
include('config.inc');
include($header_file);
include($path_includes . 'email_body.inc');

// HARDCODED MESSAGE VARIABLE FOR PHPMYTOURNEY COMPATIBILITY. 
$msg_nickname = "Nickname";
$msg_password = "Password";
$msg_retype_password = "Re-Type Password";
$msg_email = "Email";
$msg_signup = "Create Login";
$msgerr_name_exist = "Nickname allready in use";
$msgerr_retypedpasswd = "Re-typed password does not match";
$msgerr_no_email = "You have to provide a valid Email";
$msgerr_sql_insert = "An error occured while database update, retry or contact webmaster";
$msg_activation_key = "Activation Key";
$msg_activate = "Activate";
$msg_activation_key_sent = "Activation Key Sent";
$msgerr_nick_nf = "Nickname Not found";
$msgerr_allready_active = "Nickname Allready Active";
$msgerr_wrong_key = "Wrong Key";
$msgsucc_signup = "Your login was created successfully";

$use_type = 0; // TYPE ADDON DISEABLED FOR TOURNEY SIGN UP...
$msgerr_notype = "Please select a type"; //should not be used.

/****************************************************************
*	FUNCTIONS USED ONLY BY THIS SCRIPT...			*
*****************************************************************/
/********************************
Print player's sign up form...
input : table name used to fill
	combo box
*********************************/
function print_p_signup_form(){
	global 	$msg_nickname,
		$msg_password, 
		$msg_retype_password,
		$msg_email,
		$hmsg_type_question,
		$msg_signup,
		$nick,
		$use_type,
		$hmsg_name_type_1,
		$hmsg_name_type_2,
		$email;

		print_top_form($msg_signup);
		print_textbox($msg_nickname,"nick");
		print_password($msg_password,"passwd",12,12);
		print_password($msg_retype_password,"passwdchek",12,12);
		print_textbox($msg_email,"email",25,50);
		if($use_type){
			$array[] = $hmsg_type_1;
			$array[] = $hmsg_type_2;
			print_select_2dim_array($hmsg_type_question,"type",$array);   //change me, var $type 
		}
		
		echo("<input type=\"HIDDEN\" name=\"action\" value=\"addperson\">");
		echo("<input type=\"HIDDEN\" name=\"form\" value=\"step2\">");
		print_submit($msg_signup);

}
/***************************
	Activation form
***************************/
function print_activation_form(){
	global 	$msg_nickname,
		$msg_password, 
		$msg_activation_key,
		$msg_activate;
	
		print_top_form($msg_activate);
		print_textbox($msg_nickname,"nick");
		print_password($msg_password,"passwd",12,12);
		print_textbox($msg_activation_key,"activation_key",5,10);
		echo("<input type=\"HIDDEN\" name=\"form\" value=\"step3\">");
		print_submit($msg_activate);
	
}
/****************************************
*  	Validate sign up data		*
*					*
* no error: return true			*
* error: return false			*
*****************************************/
function validate_p_signup_data($nick, $passwd, $passwdchek, $email, $type){
	//used msg
	global 	$use_type,
		$msgerr_name_exist,
		$msgerr_retypedpasswd,
		$msgerr_notype,
		$msgerr_no_email,
		$msgerr_sql_insert,
		$use_activation_key;
	
	global $REMOTE_ADDR;
	//variables
	$error = 1;
	$error1 = 1;

	// Check if name allready exist
	$sql[0] = "SELECT id FROM ALLTOURNEY_players WHERE name = '$nick'"; 
	$result = mysql_query($sql[0]); 
	$num_rows = mysql_num_rows($result); 
	if($num_rows != 0){
		print_error($nick . " " . $msgerr_name_exist . "<br>");
		$error = 0;
	}

	// Check if password match retyped password
	
	if($passwd != $passwdchek){
		print_error($msgerr_retypedpasswd . "<br>");
		$error = 0;
	}
	
	//CHECK IF SELECTED A TYPE
	if ($use_type){
		$error1 = got_type($type);
	}
	
	//Check if provided email address..
	if (trim($email) == ""){
		print_error($msgerr_no_email);	
		$error = 0;
	}
	
	if($use_activation_key)
		$active = 'N';
	else
		$active = 'Y';
	//INSERT PLAYER IN NOT ACTIVATED YET TABLE
	if ($error && $error1){
		$cur_date = get_cur_date();
		
		//temporary way to fix restricted caracter.
		$name 	= addslashes($name);
		$passwd = addslashes($passwd);
		$email 	= addslashes($email);
		
		$sql[1] = "INSERT INTO ALLTOURNEY_players
	  		 SET	name = '$nick', 
				passwd = '$passwd', 
	       			email = '$email', 
				type = '$type', 
	    			j_date = '$cur_date',
	    			active = '$active', 
	    			ip = '$REMOTE_ADDR'";
		$error = mysql_query($sql[1]);
		if ($error)
			print_error($msgerr_sql_db . "<br>");
		else
			$error=1;
	}

return $error && $error1;
}


/******************************
SEND ACTIVATION KEY TO EMAIL...
******************************/
function send_mail($nick, $passwd, $email){
 	global 	$msg_activation_key,
		$msg_activation_key_sent;
 
 	$key = get_key($nick);
 	$body = generate_email_body_signup($nick,$passwd,$key);
 	
 	//send mail...
	mail($email,$msg_activation_key,$body);

	echo($msg_activation_key_sent . " " . $email);
	
	return 1;
}

/*****************************************************************
*	This fonction Activate an account after validating
*	all is submited data...
*
*  no error : return true
*  error: return false
*
* COMPLETLY REWROTE THAT FUNCTION FOR PHPMYTOURNEY, god the phpmyleague 
* version was so old and shitty. (HINT: the old one took 50 lines.)
*****************************************************************/
function activate_player($nick, $passwd, $key){
	
	//"USED" error msg
	global  $use_type,
		$msgerr_nick_nf,
		$msgerr_allready_active,
		$msgerr_wrong_key;
	$error = 1;
	$flag = 1;
	
	$pid = login_name($nick,$passwd,"N");
	if($pid){
		if($pid == $key)
			return set_active_player($pid);
		else
			print_error($msgerr_wrong_key);
	}
	return 0;
}
function set_active_player($pid){
	$sql = "UPDATE ALLTOURNEY_players SET active='Y' where id = '$pid'";	
	return execute_query($sql);
}
/********************************************
		SIGN UP !!!
*********************************************/
$msg_combo_box = $hmsg_type_question;
//bleh... This shit is old as hell.  I'll add the activation key bypass by adding a if
//statement `: it will be even messyer haha.  I shall recode all this file
//when ill have the interrest of doin it.

if(!isset($form))
	print_p_signup_form();
else if ($form == "step2") {
	if(validate_p_signup_data($nick, $passwd, $passwdchek, $email, $type)){
		if($use_activation_key){
			send_mail($nick, $passwd,$email);
			print_activation_form();
		}
		else
			echo($msgsucc_signup);			
	}
	else 
		print_p_signup_form();
}
else if ($form == "step3") {
	
	if (activate_player($nick, $passwd, $activation_key))
		echo($msgsucc_signup);
	else	
		print_activation_form();
}
else if ($form == "activate")
	print_activation_form();


/** END OF MAIN... **/

	do_not_remove_please();

	include($footer_file);
?>