Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/members/saaceadmin/
Upload File :
Current File : /var/www/cesa.co.za/members/saaceadmin/register.php

<html>
<head>
<title>SAACE Site Admin</title>
</head>
<body>
<h3>SAACE site Administration</h3>
<?php
if ($id) {
	include('../inc/conf.inc');
	include('../inc/db.inc');
	
	$sql = "SELECT id FROM user_login WHERE contact_id = $id";
	//echo $sql;
	$result = mysql_query($sql);
	$result_rows = mysql_num_rows($result);
	if ($result_rows > 0){
		echo "This user is currently registered";
	} else {
	
	switch ($action) {
		case 1 :
			if (strlen($username) < 5 OR eregi(" ",$username))
			{
				echo "<br><h4>Error:</h4>";
				echo "<p>The username must be at least 5 characters long or you used spaces. Please go <a href=\"";
				echo $PHP_SELF;
				echo "\">back</a> and choose another username.</p><br>";
				break;
			}
			//session_register("username");
			
			$query="SELECT id FROM user_login WHERE username = '$username'";
			$result = mysql_query($query) or die('Unable to query database');
			if (mysql_num_rows($result) > 0)
			{
				echo "<br><h4>Error:</h4>";
				echo "<p>The username has already been taken. Please go ";
				echo "back and choose another username.</p><br>";
				break;
			}
			else
			{
				$sql = "SELECT PreferredEmail, ContactSurname, ContactInitials, ContactFirstName, ContactDesignation AS email FROM Contacts WHERE ContactsID = $id";
				//echo $sql;
				$result = mysql_query($sql);
				$row=mysql_fetch_array($result);
				$email = $row["PreferredEmail"];
				$sn=$row["ContactSurname"];
				$ini=$row["ContactInitials"];
				$fn=$row["ContactFirstName"];
				$dg=$row["ContactDesignation"];
				$str = md5($email + time());
				$pass = substr($str,0,7);
				$lastlogin=gmdate("Y-m-d H:i:s",time()+7200);
				$lastupdate=gmdate("Y-m-d H:i:s",time()+7200);
				$logincount=0;
				
				$str = substr(md5($email + time()),0,8);
					
				$salt = substr(ereg_replace("[^A-Za-z0-9]", "", crypt(time()+2700)) .
	                         	ereg_replace("[^A-Za-z0-9]", "", crypt(time())) .
	                         	ereg_replace("[^A-Za-z0-9]", "", crypt(time())),
	                     		0, 20);
	                     	
	                     	$pass = crypt($str, $salt);
				
				$query2 = "INSERT INTO user_login (contact_id, username, password,salt, accesslevel, lastlogin, lastupdate, logincount)
				VALUES ($id, '$username', '$pass', '$salt', 1, '$lastlogin', '$lastupdate', $logincount)";
				$result = mysql_query($query2) or die('Unable to query database');
				$query3 = "SELECT id FROM user_login WHERE contact_id = $id AND username='$username'";
				$result = mysql_query($query3) or die('Unable to query database');
                $rs = mysql_fetch_array($result);
				$theid = $rs[0];
				if (mysql_num_rows($result) != 1) {
					echo "Something crapped out";
				}
				else {
					$query4 = "INSERT INTO prefs (userid, calendar, docs, work, press) VALUES ($theid, 'y', 'n', -1,-1)";
					$result = mysql_query($query4) or die('Unable to query database');
					$subject="Account Activation: $dg $fn $ini $sn ";
					$msg="This email is to confirm the activation of the SAACE member website subscription for $dg $fn $ini $sn .\nThis process was activated by an authorised SAACE staff member.\nIf you have any questions, please contact SAACE at +27 (011) 463 2022.\n\nYour username is ".$username.".\n
					Your password: ".$str."\n\nTo visit the site, please go to http://www.saace.co.za/members in your browser and login using the username you created and the password from this email\n\nThank you\n\nMembership Services\nSAACE";
					//echo $msg;
                                        //mail($email,$subject,$msg,"From: \"SAACE Member Services\"<memberservices@saace.co.za>");
                                        echo $subject;
                                        echo $msg;
                                        echo "<p><b>Please note the member has not been mailed.</b>";
					//echo "The user has been registered and emailed his/her username and password";
					echo "<p>Back to <a href=\"/members/saaceadmin/\">saaceadmin</a></p>";
				}
			}
			break;
		default :
	?>
	<table width="100%" cellpadding="0" cellspacing="10" border="0">
		<tr><td>
		<h4>Select a username:</h4>
		<p class="hint">
		Please type a username into the the field below. Some rules/tips for usernames:
		<ul class="hint">
		<li>The username must be <b class="hint">at least 5 characters long</b>
		<li>No spaces are allowed, i.e no sentences
		<li>Choose one only you would know
		</ul>
		</p>
		<p align="center">
		<form method="get" action="<?php echo $PHPSELF; ?>">
		<input type="text" name="username">
		<input type="hidden" name="action" value="1">
		<input type="hidden" name="id" value="<?php echo $id; ?>">
		<input type="submit" value="submit">
		</form>
		</p>
		</td></tr>
	</table>
	<?php
			break;
	} //end switch
	} //end if
} elseif (!isset($id)) {
	echo "<b>ERROR</b> - No record specified.";
}
?>
</body>
</html>