Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2005, 7:09 AM   #1
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
Exclamation I need (URGENT) help, please!

Heeeey!

I'm building (along with some other guys) a new website for our fire department, since it's a volunteer fire department, it's the firefighters that got stuck with building the site...

Anyway, the old site was kinda cool but sucked programming-wise, so now we're using a pre-built engine. Xoops, to be exact...

Everything is running smoothly, but we need to add custom fields (like firehouse and rank and such). So after some looooong search I finaly found a tutorial on how to add those fields, but I must have missed something, 'cause now the registration page ain't working!

I'm using a tutorial I found on the Xoops forums.

The code I'm working on is:

<?php
$xoopsOption['pagetype'] = 'user';

include 'mainfile.php';
$myts =& MyTextSanitizer::getInstance();

$config_handler =& xoops_gethandler('config');
$xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER);

if (empty($xoopsConfigUser['allow_register'])) {
	redirect_header('index.php', 6, _US_NOREGISTER);
	exit();
}

function userCheck($uname, $email, $pass, $vpass)
{
	global $xoopsConfigUser;
	$xoopsDB =& Database::getInstance();
	$myts =& MyTextSanitizer::getInstance();
	$stop = '';
	if ( !checkEmail($email) ) {
		$stop .= _US_INVALIDMAIL.'<br />';
	}
	foreach ($xoopsConfigUser['bad_emails'] as $be) {
		if ( !empty($be) && preg_match("/".$be."/i", $email) ) {
			$stop .= _US_INVALIDMAIL.'<br />';
			break;
		}
	}
	if ( strrpos($email,' ') > 0 ) {
		$stop .= _US_EMAILNOSPACES.'<br />';
	}
	$uname = xoops_trim($myts->oopsStripSlashesGPC($uname));
	switch ( $xoopsConfigUser['uname_test_level'] ) {
	case 0:
		// strict
		$restriction = '/[^a-zA-Z0-9\_\-]/';
		break;
	case 1:
		// medium
		$restriction = '/[^a-zA-Z0-9\_\-\<\>\,\.\$\%\#\@\!\\\'\"]/';
		break;
	case 2:
		// loose
		$restriction = '/[\000-\040]/';
		break;
	}
	if (empty($uname) || preg_match($restriction, $uname)) {
		$stop .= _US_INVALIDNICKNAME."<br />";
	}
	if ( strlen($uname) > $xoopsConfigUser['maxuname'] ) {
		$stop .= sprintf(_US_NICKNAMETOOLONG, $xoopsConfigUser['maxuname'])."<br />";
	}
	if ( strlen($uname) < $xoopsConfigUser['minuname'] ) {
		$stop .= sprintf(_US_NICKNAMETOOSHORT, $xoopsConfigUser['minuname'])."<br />";
	}
	foreach ($xoopsConfigUser['bad_unames'] as $bu) {
		if ( !empty($bu) && preg_match("/".$bu."/i", $uname) ) {
			$stop .= _US_NAMERESERVED."<br />";
			break;
		}
	}
	if ( strrpos($uname,' ') > 0 ) {
		$stop .= _US_NICKNAMENOSPACES."<br />";
	}
	$sql = "SELECT COUNT(*) FROM ".$xoopsDB->prefix('users')." WHERE uname='".addslashes($uname)."'";
	$result = $xoopsDB->query($sql);
	list($count) = $xoopsDB->fetchRow($result);
	if ( $count > 0 ) {
		$stop .= _US_NICKNAMETAKEN."<br />";
	}
	$count = 0;
	if ( $email ) {
		$sql = "SELECT COUNT(*) FROM ".$xoopsDB->prefix('users')." where email='".$myts->makeTboxData4Save($email)."'";
		$result = $xoopsDB->query($sql);
		list($count) = $xoopsDB->fetchRow($result);
		if ( $count > 0 ) {
			$stop .= _US_EMAILTAKEN."<br />";
		}
	}
	if ( !isset($pass) || $pass == '' || !isset($vpass) || $vpass == '' ) {
		$stop .= _US_ENTERPWD.'<br />';
	}
	if ( (isset($pass)) && ($pass != $vpass) ) {
		$stop .= _US_PASSNOTSAME.'<br />';
	} elseif ( ($pass != '') && (strlen($pass) < $xoopsConfigUser['minpass']) ) {
		$stop .= sprintf(_US_PWDTOOSHORT,$xoopsConfigUser['minpass'])."<br />";
	}
	return $stop;
}

$op = 'register';
foreach ( $_POST as $k => $v ) {
	$$k = $v;
}
switch ( $op ) {
case 'newuser':
	include 'header.php';
	if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') {
		if (empty($agree_disc)) {
			redirect_header('register.php', 5, _US_UNEEDAGREE);
			exit();
		}
	}
	$uname = trim($uname);
	$email = trim($email);
	$pass = trim($pass);
	$vpass = trim($vpass);
	$stop = userCheck($uname, $email, $pass, $vpass);
	if ( empty($stop) ) {
//		OpenTable();
		echo _US_USERNAME.": ".$myts->makeTboxData4Preview($uname)."<br />";
		echo _US_EMAIL.": ".$myts->makeTboxData4Preview($email)."<br />";
		//if ( $user_avatar != '' ) {
		//	echo _US_AVATAR.": <img src='uploads/".$user_avatar."' alt='' /><br />";
		//}
		if ( isset($url) && $url != '' ) {
			$url = formatURL($myts->makeTboxData4Preview($url));
			echo _US_WEBSITE.": $url<br />";
		}
		$f_timezone = ($timezone_offset < 0) ? 'GMT '.$timezone_offset : 'GMT +'.$timezone_offset;
		echo _US_TIMEZONE.": $f_timezone<br />";
		echo "<form action='register.php' method='post'>
		<input type='hidden' name='uname' value='".$myts->makeTboxData4PreviewInForm($uname)."' />;
		<input type='hidden' name='name' value='".$myts->makeTboxData4PreviewInForm($name)."' / > ";
		echo "<input type='hidden' name='firehouse' value='".$myts->makeTboxData4PreviewInForm($firehouse)."' / > ";
		echo "<input type='hidden' name='location' value='".$myts->makeTboxData4PreviewInForm($location)."' / > ";
		//echo "<input type='hidden' name='user_avatar' value='".$myts->makeTboxData4PreviewInForm($user_avatar)."' />";
		$user_viewemail = isset($user_viewemail) ? intval($user_viewemail) : 0;
		echo "<input type='hidden' name='user_viewemail' value='".$user_viewemail."' />
		<input type='hidden' name='timezone_offset' value='".(float)$timezone_offset."' />
		<input type='hidden' name='url' value='".$myts->makeTboxData4PreviewInForm($url)."' />
		<input type='hidden' name='pass' value='".$myts->makeTboxData4PreviewInForm($pass)."' />
		<input type='hidden' name='vpass' value='".$myts->makeTboxData4PreviewInForm($vpass)."' />
		<input type='hidden' name='user_mailok' value='".intval($user_mailok)."' />
		<br /><br /><input type='hidden' name='op' value='finish' /><input type='submit' value='". _US_FINISH ."' /></form>";
//		CloseTable();
	} else {
		echo "<span style='color:#ff0000;'>$stop</span>";
		include 'include/registerform.php';
		$reg_form->display();
	}
	include 'footer.php';
	break;
case 'finish':
	include 'header.php';
	$uname = trim($uname);
	$email = trim($email);
	$pass = trim($pass);
	$vpass = trim($vpass);
	$stop = userCheck($uname, $email, $pass, $vpass);
	if ( empty($stop) ) {
		$member_handler =& xoops_gethandler('member');
		$newuser =& $member_handler->createUser();
		if ( isset($user_viewemail) ) {
			$newuser->setVar('user_viewemail',$user_viewemail);
		}
		if ( isset($attachsig) ) {
			$newuser->setVar('attachsig',$attachsig);
		}
		$name = isset($name) ? $name : '';
		$newuser->setVar('uname', $uname);
		$newuser->setVar('name', $name);
		$newuser->setVar('firehouse', $firehouse);
		$newuser->setVar('location', $location);
		$newuser->setVar('email', $email);
		if ( isset($url) && $url!='' ) {
			$newuser->setVar('url', formatURL($url));
		}

		$newuser->setVar('user_avatar','blank.gif');
		$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
		$newuser->setVar('actkey',$actkey);
		$newuser->setVar('pass', md5($pass));
		$newuser->setVar('timezone_offset', $timezone_offset);
		$newuser->setVar('user_regdate', time());
		$newuser->setVar('uorder',$xoopsConfig['com_order']);
		$newuser->setVar('umode',$xoopsConfig['com_mode']);
		$newuser->setVar('user_mailok',$user_mailok);
		if ($xoopsConfigUser['activation_type'] == 1) {
			$newuser->setVar('level', 1);
		}
		if (!$member_handler->insertUser($newuser)) {
			echo _US_REGISTERNG;
			include 'footer.php';
			exit();
		}
		$newid = $newuser->getVar('uid');
		if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) {
			echo _US_REGISTERNG;
			include 'footer.php';
			exit();
		}
		if ($xoopsConfigUser['activation_type'] == 1) {
			redirect_header('index.php', 4, _US_ACTLOGIN);
			exit();
		}
		if ($xoopsConfigUser['activation_type'] == 0) {
			$myts =& MyTextSanitizer::getInstance();
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$xoopsMailer->setTemplate('register.tpl');
			$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
			$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
			$xoopsMailer->assign('SITEURL', XOOPS_URL."/");
			$xoopsMailer->setToUsers(new XoopsUser($newid));
			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
			$xoopsMailer->setFromName($xoopsConfig['sitename']);
			$xoopsMailer->setSubject(sprintf(_US_USERKEYFOR,$myts->oopsStripSlashesGPC($uname)));
//			OpenTable();
			if ( !$xoopsMailer->send() ) {
				echo _US_YOURREGMAILNG;
			} else {
				echo _US_YOURREGISTERED;
			}
//			CloseTable();
		} elseif ($xoopsConfigUser['activation_type'] == 2) {
			$myts =& MyTextSanitizer::getInstance();
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$xoopsMailer->setTemplate('adminactivate.tpl');
			$xoopsMailer->assign('USERNAME', $myts->oopsStripSlashesGPC($uname));
			$xoopsMailer->assign('USEREMAIL', $myts->oopsStripSlashesGPC($email));
			$xoopsMailer->assign('USERACTLINK', XOOPS_URL.'/user.php?op=actv&id='.$newid.'&actkey='.$actkey);
			$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
			$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
			$xoopsMailer->assign('SITEURL', XOOPS_URL."/");
			$member_handler =& xoops_gethandler('member');
			$xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['activation_group']));
			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
			$xoopsMailer->setFromName($xoopsConfig['sitename']);
			$xoopsMailer->setSubject(sprintf(_US_USERKEYFOR,$myts->oopsStripSlashesGPC($uname)));
//			OpenTable();
			if ( !$xoopsMailer->send() ) {
				echo _US_YOURREGMAILNG;
			} else {
				echo _US_YOURREGISTERED2;
			}
//			CloseTable();
		}
		if ($xoopsConfigUser['new_user_notify'] == 1 && !empty($xoopsConfigUser['new_user_notify_group'])) {
			$myts =& MyTextSanitizer::getInstance();
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$member_handler =& xoops_gethandler('member');
			$xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['new_user_notify_group']));
			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
			$xoopsMailer->setFromName($xoopsConfig['sitename']);
			$xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT,$xoopsConfig['sitename']));
			$xoopsMailer->setBody(sprintf(_US_HASJUSTREG,$myts->oopsStripSlashesGPC($uname)));
			$xoopsMailer->send();
		}
	} else {
		echo "<span style='color:#ff0000; font-weight:bold;'>$stop</span>";
		include 'include/registerform.php';
		$reg_form->display();
	}
	include 'footer.php';
	break;
case 'register':
default:
	include 'header.php';
	//OpenTable();
	include 'include/registerform.php';
	$reg_form->display();
	//CloseTable();
	include 'footer.php';
	break;
}
?>

I got a couple of sintax errors that I think are now fixed!

So far I've added these lines:
		<input type='hidden' name='name' value='".$myts->makeTboxData4PreviewInForm($name)."' / > ";
                echo "<input type='hidden' name='firehouse' value='".$myts->makeTboxData4PreviewInForm($firehouse)."' / > ";
		echo "<input type='hidden' name='location' value='".$myts->makeTboxData4PreviewInForm($location)."' / > ";

and

		$newuser->setVar('name', $name);
		$newuser->setVar('firehouse', $firehouse);
		$newuser->setVar('location', $location);
´

But when I try to register a test user I get a blank screen (nothing loads)... Before I got errors that I could work with but I only get a white screen now!


I really need urgent help, please!

EDIT: If I try echo "<input type='hidden' name='name' value='".$myts->makeTboxData4PreviewInForm($name)."' / > "; instead of <input type='hidden' name='name' value='".$myts->makeTboxData4PreviewInForm($name)."' / > "; I get the following error:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/bvportue/public_html/register.php on line 151

Just thought you should know...

EDIT 2 - The return of EDIT: AAAAAARGH!!!! The whole site seems not to work now! And no, it ain't a server problem...

Anyway, if you're really a neat guy that is into helping people out, take a nice good look at the files that I modified:

- Register Form
- English Language File
- Kernel User File
- Register File (Although the code is posted above you might want to take a look at it).

If you need any info, ask away as I'll be glad to answer...
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA

Last edited by Broax; Feb 1st, 2005 at 7:59 AM.
Broax is offline   Reply With Quote
Old Feb 2nd, 2005, 8:20 PM   #2
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
If you use a form to pass values, you use one of two methods post or get... I think you are using post... if that is the case i think you need to use this variables...
		$newuser->setVar('name', $_POST['name']);
		$newuser->setVar('firehouse', $_POST['firehouse']);
		$newuser->setVar('location', $_POST['location']);
hope this is the problem...
take care
-codetaino
__________________
"God bless u all" :)
codetaino is offline   Reply With Quote
Old Feb 2nd, 2005, 8:53 PM   #3
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
$_REQUEST is a super global that holds the values from $_POST, $_GET, $SESSION and $_COOKIE. If you are ever coding, and aren't sure if it's $_POST or $_GET use $_REQUEST... Thus:

                $newuser->setVar('name', $_REQUEST['name']);
                $newuser->setVar('firehouse', $_REQUEST['firehouse']);
                $newuser->setVar('location', $_REQUEST['location']);

Hope this helps
__________________

tempest is offline   Reply With Quote
Old Feb 3rd, 2005, 1:25 PM   #4
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
thanks for the the suggestions and I'll try everything later today..
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
Broax is offline   Reply With Quote
Old Feb 4th, 2005, 10:24 PM   #5
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
I was re-reading your code and i notice something... there is a foreach that convert all the $_POST vars to variables ... so yeah the variables you are using are correct... but also i notice that you assing 'register' to the variable $op .... does your code take you always to the registration form? also i notice that there are some functions inside your hidden data in your form? (wondering why are hidden, maybe is a preview of the data so the user could review it and need the info hidden to resend it to the next page) and also what does the function $myts->makeTboxData4PreviewInForm do?...

- codetaino
__________________
"God bless u all" :)

Last edited by codetaino; Feb 4th, 2005 at 10:29 PM.
codetaino is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC