punbb/profile.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
--- a/punbb/profile.php	Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/profile.php	Thu Jul 12 01:04:01 2007 -0400
@@ -23,9 +23,13 @@
 ************************************************************************/
 
 
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
 
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
+$GLOBALS['id'] = 0;
+$id =& $GLOBALS['id'];
 
 $action = isset($_GET['action']) ? $_GET['action'] : null;
 $section = isset($_GET['section']) ? $_GET['section'] : null;
@@ -36,6 +40,9 @@
 if ($pun_user['g_read_board'] == '0' && ($action != 'change_pass' || !isset($_GET['key'])))
 	message($lang_common['No view']);
 
+$GLOBALS['lang_profile'] = array();
+$lang_profile =& $GLOBALS['lang_profile'];
+
 // Load the profile.php/register.php language file
 require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
 
@@ -56,14 +63,14 @@
 
 		$key = $_GET['key'];
 
-		$result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $db->error());
-		list($new_password_hash, $new_password_key) = $db->fetch_row($result);
+		$result = $pun_db->query('SELECT activate_string, activate_key FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $pun_db->error());
+		list($new_password_hash, $new_password_key) = $pun_db->fetch_row($result);
 
 		if ($key == '' || $key != $new_password_key)
 			message($lang_profile['Pass key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
 		else
 		{
-			$db->query('UPDATE '.$db->prefix.'users SET password=\''.$new_password_hash.'\', activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
+			$pun_db->query('UPDATE '.$pun_db->prefix.'users SET password=\''.$new_password_hash.'\', activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $pun_db->error());
 
 			message($lang_profile['Pass updated'], true);
 		}
@@ -72,15 +79,15 @@
 	// Make sure we are allowed to change this users password
 	if ($pun_user['id'] != $id)
 	{
-		if ($pun_user['g_id'] > PUN_MOD)	// A regular user trying to change another users password?
+		if ($pun_user['g_id'] < USER_LEVEL_MOD)	// A regular user trying to change another users password?
 			message($lang_common['No permission']);
-		else if ($pun_user['g_id'] == PUN_MOD)	// A moderator trying to change a users password?
+		else if ($pun_user['g_id'] == USER_LEVEL_MOD)	// A moderator trying to change a users password?
 		{
-			$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-			if (!$db->num_rows($result))
+			$result = $pun_db->query('SELECT group_id FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+			if (!$pun_db->num_rows($result))
 				message($lang_common['Bad request']);
 
-			if ($pun_config['p_mod_edit_users'] == '0' || $pun_config['p_mod_change_passwords'] == '0' || $db->result($result) < PUN_GUEST)
+			if ($pun_config['p_mod_edit_users'] == '0' || $pun_config['p_mod_change_passwords'] == '0' || $pun_db->result($result) < PUN_GUEST)
 				message($lang_common['No permission']);
 		}
 	}
@@ -96,8 +103,8 @@
 		if (strlen($new_password1) < 4)
 			message($lang_prof_reg['Pass too short']);
 
-		$result = $db->query('SELECT password, save_pass FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch password', __FILE__, __LINE__, $db->error());
-		list($db_password_hash, $save_pass) = $db->fetch_row($result);
+		$result = $pun_db->query('SELECT password, save_pass FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch password', __FILE__, __LINE__, $pun_db->error());
+		list($db_password_hash, $save_pass) = $pun_db->fetch_row($result);
 
 		$authorized = false;
 
@@ -110,7 +117,7 @@
 
 			if (($sha1_in_db && $sha1_available && $db_password_hash == $old_password_hash) ||
 				(!$sha1_in_db && $db_password_hash == md5($old_password)) ||
-				$pun_user['g_id'] < PUN_GUEST)
+				$pun_user['g_id'] >= USER_LEVEL_MEMBER)
 				$authorized = true;
 		}
 
@@ -119,7 +126,7 @@
 
 		$new_password_hash = pun_hash($new_password1);
 
-		$db->query('UPDATE '.$db->prefix.'users SET password=\''.$new_password_hash.'\' WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'users SET password=\''.$new_password_hash.'\' WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $pun_db->error());
 
 		if ($pun_user['id'] == $id)
 		{
@@ -127,25 +134,25 @@
 			pun_setcookie($pun_user['id'], $new_password_hash, $expire);
 		}
 
-		redirect('profile.php?section=essentials&amp;id='.$id, $lang_profile['Pass updated redirect']);
+		pun_redirect('profile.php?section=essentials&amp;id='.$id, $lang_profile['Pass updated redirect']);
 	}
 
 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 	$required_fields = array('req_old_password' => $lang_profile['Old pass'], 'req_new_password1' => $lang_profile['New pass'], 'req_new_password2' => $lang_profile['Confirm new pass']);
-	$focus_element = array('change_pass', (($pun_user['g_id'] > PUN_MOD) ? 'req_old_password' : 'req_new_password1'));
+	$focus_element = array('change_pass', (($pun_user['g_id'] < USER_LEVEL_MOD) ? 'req_old_password' : 'req_new_password1'));
 	require PUN_ROOT.'header.php';
 
 ?>
 <div class="blockform">
 	<h2><span><?php echo $lang_profile['Change pass'] ?></span></h2>
 	<div class="box">
-		<form id="change_pass" method="post" action="profile.php?action=change_pass&amp;id=<?php echo $id ?>" onsubmit="return process_form(this)">
+		<form id="change_pass" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'action=change_pass&id=' . $id . '', true); ?>" onsubmit="return process_form(this)">
 			<div class="inform">
 				<input type="hidden" name="form_sent" value="1" />
 				<fieldset>
 					<legend><?php echo $lang_profile['Change pass legend'] ?></legend>
 					<div class="infldset">
-<?php if ($pun_user['g_id'] > PUN_MOD): ?>						<label><strong><?php echo $lang_profile['Old pass'] ?></strong><br />
+<?php if ($pun_user['g_id'] < USER_LEVEL_MOD): ?>						<label><strong><?php echo $lang_profile['Old pass'] ?></strong><br />
 						<input type="password" name="req_old_password" size="16" maxlength="16" /><br /></label>
 <?php endif; ?>						<label class="conl"><strong><?php echo $lang_profile['New pass'] ?></strong><br />
 						<input type="password" name="req_new_password1" size="16" maxlength="16" /><br /></label>
@@ -170,15 +177,15 @@
 	// Make sure we are allowed to change this users e-mail
 	if ($pun_user['id'] != $id)
 	{
-		if ($pun_user['g_id'] > PUN_MOD)	// A regular user trying to change another users e-mail?
+		if ($pun_user['g_id'] < USER_LEVEL_MOD)	// A regular user trying to change another users e-mail?
 			message($lang_common['No permission']);
-		else if ($pun_user['g_id'] == PUN_MOD)	// A moderator trying to change a users e-mail?
+		else if ($pun_user['g_id'] == USER_LEVEL_MOD)	// A moderator trying to change a users e-mail?
 		{
-			$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-			if (!$db->num_rows($result))
+			$result = $pun_db->query('SELECT group_id FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+			if (!$pun_db->num_rows($result))
 				message($lang_common['Bad request']);
 
-			if ($pun_config['p_mod_edit_users'] == '0' || $db->result($result) < PUN_GUEST)
+			if ($pun_config['p_mod_edit_users'] == '0' || $pun_db->result($result) < PUN_GUEST)
 				message($lang_common['No permission']);
 		}
 	}
@@ -187,14 +194,14 @@
 	{
 		$key = $_GET['key'];
 
-		$result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch activation data', __FILE__, __LINE__, $db->error());
-		list($new_email, $new_email_key) = $db->fetch_row($result);
+		$result = $pun_db->query('SELECT activate_string, activate_key FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch activation data', __FILE__, __LINE__, $pun_db->error());
+		list($new_email, $new_email_key) = $pun_db->fetch_row($result);
 
 		if ($key == '' || $key != $new_email_key)
 			message($lang_profile['E-mail key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
 		else
 		{
-			$db->query('UPDATE '.$db->prefix.'users SET email=activate_string, activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update e-mail address', __FILE__, __LINE__, $db->error());
+			$pun_db->query('UPDATE '.$pun_db->prefix.'users SET email=activate_string, activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update e-mail address', __FILE__, __LINE__, $pun_db->error());
 
 			message($lang_profile['E-mail updated'], true);
 		}
@@ -226,14 +233,14 @@
 		}
 
 		// Check if someone else already has registered with that e-mail address
-		$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE email=\''.$db->escape($new_email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-		if ($db->num_rows($result))
+		$result = $pun_db->query('SELECT id, username FROM '.$pun_db->prefix.'users WHERE email=\''.$pun_db->escape($new_email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+		if ($pun_db->num_rows($result))
 		{
 			if ($pun_config['p_allow_dupe_email'] == '0')
 				message($lang_prof_reg['Dupe e-mail']);
 			else if ($pun_config['o_mailing_list'] != '')
 			{
-				while ($cur_dupe = $db->fetch_assoc($result))
+				while ($cur_dupe = $pun_db->fetch_assoc($result))
 					$dupe_list[] = $cur_dupe['username'];
 
 				$mail_subject = 'Alert - Duplicate e-mail detected';
@@ -246,7 +253,7 @@
 
 		$new_email_key = random_pass(8);
 
-		$db->query('UPDATE '.$db->prefix.'users SET activate_string=\''.$db->escape($new_email).'\', activate_key=\''.$new_email_key.'\' WHERE id='.$id) or error('Unable to update activation data', __FILE__, __LINE__, $db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'users SET activate_string=\''.$pun_db->escape($new_email).'\', activate_key=\''.$new_email_key.'\' WHERE id='.$id) or error('Unable to update activation data', __FILE__, __LINE__, $pun_db->error());
 
 		// Load the "activate e-mail" template
 		$mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/activate_email.tpl'));
@@ -275,7 +282,7 @@
 <div class="blockform">
 	<h2><span><?php echo $lang_profile['Change e-mail'] ?></span></h2>
 	<div class="box">
-		<form id="change_email" method="post" action="profile.php?action=change_email&amp;id=<?php echo $id ?>" id="change_email" onsubmit="return process_form(this)">
+		<form id="change_email" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'action=change_email&id=' . $id . '', true); ?>" id="change_email" onsubmit="return process_form(this)">
 			<div class="inform">
 				<fieldset>
 					<legend><?php echo $lang_profile['E-mail legend'] ?></legend>
@@ -302,7 +309,7 @@
 	if ($pun_config['o_avatars'] == '0')
 		message($lang_profile['Avatars disabled']);
 
-	if ($pun_user['id'] != $id && $pun_user['g_id'] > PUN_MOD)
+	if ($pun_user['id'] != $id && $pun_user['g_id'] < USER_LEVEL_MOD)
 		message($lang_common['No permission']);
 
 	if (isset($_POST['form_sent']))
@@ -389,9 +396,9 @@
 			message($lang_profile['Unknown failure']);
 
 		// Enable use_avatar (seems sane since the user just uploaded an avatar)
-		$db->query('UPDATE '.$db->prefix.'users SET use_avatar=1 WHERE id='.$id) or error('Unable to update avatar state', __FILE__, __LINE__, $db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'users SET use_avatar=1 WHERE id='.$id) or error('Unable to update avatar state', __FILE__, __LINE__, $pun_db->error());
 
-		redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
+		pun_redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
 	}
 
 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
@@ -403,7 +410,7 @@
 <div class="blockform">
 	<h2><span><?php echo $lang_profile['Upload avatar'] ?></span></h2>
 	<div class="box">
-		<form id="upload_avatar" method="post" enctype="multipart/form-data" action="profile.php?action=upload_avatar2&amp;id=<?php echo $id ?>" onsubmit="return process_form(this)">
+		<form id="upload_avatar" method="post" enctype="multipart/form-data" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'action=upload_avatar2&id=' . $id . '', true); ?>" onsubmit="return process_form(this)">
 			<div class="inform">
 				<fieldset>
 					<legend><?php echo $lang_profile['Upload avatar legend'] ?></legend>
@@ -427,7 +434,7 @@
 
 else if ($action == 'delete_avatar')
 {
-	if ($pun_user['id'] != $id && $pun_user['g_id'] > PUN_MOD)
+	if ($pun_user['id'] != $id && $pun_user['g_id'] < USER_LEVEL_MOD)
 		message($lang_common['No permission']);
 
 	confirm_referrer('profile.php');
@@ -437,29 +444,29 @@
 	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.gif');
 
 	// Disable use_avatar
-	$db->query('UPDATE '.$db->prefix.'users SET use_avatar=0 WHERE id='.$id) or error('Unable to update avatar state', __FILE__, __LINE__, $db->error());
+	$pun_db->query('UPDATE '.$pun_db->prefix.'users SET use_avatar=0 WHERE id='.$id) or error('Unable to update avatar state', __FILE__, __LINE__, $pun_db->error());
 
-	redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar deleted redirect']);
+	pun_redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar deleted redirect']);
 }
 
 
 else if (isset($_POST['update_group_membership']))
 {
-	if ($pun_user['g_id'] > PUN_ADMIN)
+	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
 		message($lang_common['No permission']);
 
 	confirm_referrer('profile.php');
 
 	$new_group_id = intval($_POST['group_id']);
 
-	$db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
+	$pun_db->query('UPDATE '.$pun_db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $pun_db->error());
 
 	// If the user was a moderator or an administrator, we remove him/her from the moderator list in all forums as well
 	if ($new_group_id > PUN_MOD)
 	{
-		$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
+		$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
 
-		while ($cur_forum = $db->fetch_assoc($result))
+		while ($cur_forum = $pun_db->fetch_assoc($result))
 		{
 			$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 
@@ -467,34 +474,34 @@
 			{
 				$username = array_search($id, $cur_moderators);
 				unset($cur_moderators[$username]);
-				$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
+				$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 
-				$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+				$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
 			}
 		}
 	}
 
-	redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Group membership redirect']);
+	pun_redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Group membership redirect']);
 }
 
 
 else if (isset($_POST['update_forums']))
 {
-	if ($pun_user['g_id'] > PUN_ADMIN)
+	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
 		message($lang_common['No permission']);
 
 	confirm_referrer('profile.php');
 
 	// Get the username of the user we are processing
-	$result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-	$username = $db->result($result);
+	$result = $pun_db->query('SELECT eu.username FROM '.$pun_db->prefix.'users AS u LEFT JOIN '.table_prefix.'users AS eu ON eu.user_id=u.id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+	$username = $pun_db->result($result);
 
 	$moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
 
 	// Loop through all forums
-	$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
+	$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
 
-	while ($cur_forum = $db->fetch_assoc($result))
+	while ($cur_forum = $pun_db->fetch_assoc($result))
 	{
 		$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 		// If the user should have moderator access (and he/she doesn't already have it)
@@ -503,41 +510,41 @@
 			$cur_moderators[$username] = $id;
 			ksort($cur_moderators);
 
-			$db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+			$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET moderators=\''.$pun_db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
 		}
 		// If the user shouldn't have moderator access (and he/she already has it)
 		else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators))
 		{
 			unset($cur_moderators[$username]);
-			$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
+			$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 
-			$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+			$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
 		}
 	}
 
-	redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Update forums redirect']);
+	pun_redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Update forums redirect']);
 }
 
 
 else if (isset($_POST['ban']))
 {
-	if ($pun_user['g_id'] > PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
+	if ($pun_user['g_id'] < USER_LEVEL_MOD || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_ban_users'] == '0'))
 		message($lang_common['No permission']);
 
-	redirect('admin_bans.php?add_ban='.$id, $lang_profile['Ban redirect']);
+	pun_redirect('admin_bans.php?add_ban='.$id, $lang_profile['Ban redirect']);
 }
 
 
 else if (isset($_POST['delete_user']) || isset($_POST['delete_user_comply']))
 {
-	if ($pun_user['g_id'] > PUN_ADMIN)
+	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
 		message($lang_common['No permission']);
 
 	confirm_referrer('profile.php');
 
 	// Get the username and group of the user we are deleting
-	$result = $db->query('SELECT group_id, username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-	list($group_id, $username) = $db->fetch_row($result);
+	$result = $pun_db->query('SELECT group_id, username FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+	list($group_id, $username) = $pun_db->fetch_row($result);
 
 	if ($group_id == PUN_ADMIN)
 		message('Administrators cannot be deleted. In order to delete this user, you must first move him/her to a different user group.');
@@ -547,27 +554,27 @@
 		// If the user is a moderator or an administrator, we remove him/her from the moderator list in all forums as well
 		if ($group_id < PUN_GUEST)
 		{
-			$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
+			$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
 
-			while ($cur_forum = $db->fetch_assoc($result))
+			while ($cur_forum = $pun_db->fetch_assoc($result))
 			{
 				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 
 				if (in_array($id, $cur_moderators))
 				{
 					unset($cur_moderators[$username]);
-					$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
+					$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 
-					$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+					$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
 				}
 			}
 		}
 
 		// Delete any subscriptions
-		$db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE user_id='.$id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
+		$pun_db->query('DELETE FROM '.$pun_db->prefix.'subscriptions WHERE user_id='.$id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $pun_db->error());
 
 		// Remove him/her from the online list (if they happen to be logged in)
-		$db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$id) or error('Unable to remove user from online list', __FILE__, __LINE__, $db->error());
+		$pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE user_id='.$id) or error('Unable to remove user from online list', __FILE__, __LINE__, $pun_db->error());
 
 		// Should we delete all posts made by this user?
 		if (isset($_POST['delete_posts']))
@@ -576,15 +583,15 @@
 			@set_time_limit(0);
 
 			// Find all posts made by this user
-			$result = $db->query('SELECT p.id, p.topic_id, t.forum_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.poster_id='.$id) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
-			if ($db->num_rows($result))
+			$result = $pun_db->query('SELECT p.id, p.topic_id, t.forum_id FROM '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$pun_db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.poster_id='.$id) or error('Unable to fetch posts', __FILE__, __LINE__, $pun_db->error());
+			if ($pun_db->num_rows($result))
 			{
-				while ($cur_post = $db->fetch_assoc($result))
+				while ($cur_post = $pun_db->fetch_assoc($result))
 				{
 					// Determine whether this post is the "topic post" or not
-					$result2 = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['topic_id'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
+					$result2 = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id='.$cur_post['topic_id'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
 
-					if ($db->result($result2) == $cur_post['id'])
+					if ($pun_db->result($result2) == $cur_post['id'])
 						delete_topic($cur_post['topic_id']);
 					else
 						delete_post($cur_post['id'], $cur_post['topic_id']);
@@ -595,12 +602,12 @@
 		}
 		else
 			// Set all his/her posts to guest
-			$db->query('UPDATE '.$db->prefix.'posts SET poster_id=1 WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
+			$pun_db->query('UPDATE '.$pun_db->prefix.'posts SET poster_id=1 WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $pun_db->error());
 
 		// Delete the user
-		$db->query('DELETE FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $db->error());
+		$pun_db->query('DELETE FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $pun_db->error());
 
-		redirect('index.php', $lang_profile['User delete redirect']);
+		pun_redirect('index.php', $lang_profile['User delete redirect']);
 	}
 
 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
@@ -610,7 +617,7 @@
 <div class="blockform">
 	<h2><span><?php echo $lang_profile['Confirm delete user'] ?></span></h2>
 	<div class="box">
-		<form id="confirm_del_user" method="post" action="profile.php?id=<?php echo $id ?>">
+		<form id="confirm_del_user" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'id=' . $id . '', true); ?>">
 			<div class="inform">
 				<fieldset>
 					<legend><?php echo $lang_profile['Confirm delete legend'] ?></legend>
@@ -636,19 +643,19 @@
 else if (isset($_POST['form_sent']))
 {
 	// Fetch the user group of the user we are editing
-	$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-	if (!$db->num_rows($result))
+	$result = $pun_db->query('SELECT group_id FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+	if (!$pun_db->num_rows($result))
 		message($lang_common['Bad request']);
 
-	$group_id = $db->result($result);
+	$group_id = $pun_db->result($result);
 
 	if ($pun_user['id'] != $id &&
-		($pun_user['g_id'] > PUN_MOD ||
-		($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_edit_users'] == '0') ||
-		($pun_user['g_id'] == PUN_MOD && $group_id < PUN_GUEST)))
+		($pun_user['g_id'] < USER_LEVEL_MOD ||
+		($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_edit_users'] == '0') ||
+		($pun_user['g_id'] == USER_LEVEL_MOD && $group_id < PUN_GUEST)))
 		message($lang_common['No permission']);
 
-	if ($pun_user['g_id'] < PUN_GUEST)
+	if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
 		confirm_referrer('profile.php');
 
 	// Extract allowed elements from $_POST['form']
@@ -674,12 +681,12 @@
 		{
 			$form = extract_elements(array('timezone', 'language'));
 
-			if ($pun_user['g_id'] < PUN_GUEST)
+			if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
 			{
 				$form['admin_note'] = trim($_POST['admin_note']);
 
 				// Are we allowed to change usernames?
-				if ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_rename_users'] == '1'))
+				if ($pun_user['g_id'] == USER_LEVEL_ADMIN || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_rename_users'] == '1'))
 				{
 					$form['username'] = trim($_POST['req_username']);
 					$old_username = trim($_POST['old_username']);
@@ -696,8 +703,8 @@
 						message($lang_prof_reg['Username BBCode']);
 
 					// Check that the username is not already registered
-					$result = $db->query('SELECT 1 FROM '.$db->prefix.'users WHERE username=\''.$db->escape($form['username']).'\' AND id!='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-					if ($db->num_rows($result))
+					$result = $pun_db->query('SELECT 1 FROM '.$pun_db->prefix.'users WHERE username=\''.$pun_db->escape($form['username']).'\' AND id!='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+					if ($pun_db->num_rows($result))
 						message($lang_profile['Dupe username']);
 
 					if ($form['username'] != $old_username)
@@ -705,11 +712,13 @@
 				}
 
 				// We only allow administrators to update the post count
-				if ($pun_user['g_id'] == PUN_ADMIN)
+				if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
 					$form['num_posts'] = intval($_POST['num_posts']);
 			}
 
-			if ($pun_config['o_regs_verify'] == '0' || $pun_user['g_id'] < PUN_GUEST)
+      /*
+      // Don't update e-mail address in Enano
+			if ($pun_config['o_regs_verify'] == '0' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
 			{
 				require PUN_ROOT.'include/email.php';
 
@@ -718,6 +727,7 @@
 				if (!is_valid_email($form['email']))
 					message($lang_common['Invalid e-mail']);
 			}
+      */
 
 			// Make sure we got a valid language string
 			if (isset($form['language']))
@@ -734,7 +744,7 @@
 		{
 			$form = extract_elements(array('realname', 'url', 'location'));
 
-			if ($pun_user['g_id'] == PUN_ADMIN)
+			if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
 				$form['title'] = trim($_POST['title']);
 			else if ($pun_user['g_set_title'] == '1')
 			{
@@ -781,7 +791,7 @@
 				message($lang_prof_reg['Sig too long'].' '.$pun_config['p_sig_length'].' '.$lang_prof_reg['characters'].'.');
 			else if (substr_count($form['signature'], "\n") > ($pun_config['p_sig_lines']-1))
 				message($lang_prof_reg['Sig too many lines'].' '.$pun_config['p_sig_lines'].' '.$lang_prof_reg['lines'].'.');
-			else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && strtoupper($form['signature']) == $form['signature'] && $pun_user['g_id'] > PUN_MOD)
+			else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && strtoupper($form['signature']) == $form['signature'] && $pun_user['g_id'] < USER_LEVEL_MOD)
 				$form['signature'] = ucwords(strtolower($form['signature']));
 
 			// Validate BBCode syntax
@@ -827,8 +837,8 @@
 			// If the save_pass setting has changed, we need to set a new cookie with the appropriate expire date
 			if ($pun_user['id'] == $id && $form['save_pass'] != $pun_user['save_pass'])
 			{
-				$result = $db->query('SELECT password FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user password hash', __FILE__, __LINE__, $db->error());
-				pun_setcookie($id, $db->result($result), ($form['save_pass'] == '1') ? time() + 31536000 : 0);
+				$result = $pun_db->query('SELECT password FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user password hash', __FILE__, __LINE__, $pun_db->error());
+				pun_setcookie($id, $pun_db->result($result), ($form['save_pass'] == '1') ? time() + 31536000 : 0);
 			}
 
 			break;
@@ -843,7 +853,7 @@
 	$temp = array();
 	while (list($key, $input) = @each($form))
 	{
-		$value = ($input !== '') ? '\''.$db->escape($input).'\'' : 'NULL';
+		$value = ($input !== '') ? '\''.$pun_db->escape($input).'\'' : 'NULL';
 
 		$temp[] = $key.'='.$value;
 	}
@@ -852,26 +862,26 @@
 		message($lang_common['Bad request']);
 
 
-	$db->query('UPDATE '.$db->prefix.'users SET '.implode(',', $temp).' WHERE id='.$id) or error('Unable to update profile', __FILE__, __LINE__, $db->error());
+	$pun_db->query('UPDATE '.$pun_db->prefix.'users SET '.implode(',', $temp).' WHERE id='.$id) or error('Unable to update profile', __FILE__, __LINE__, $pun_db->error());
 
 	// If we changed the username we have to update some stuff
 	if ($username_updated)
 	{
-		$db->query('UPDATE '.$db->prefix.'posts SET poster=\''.$db->escape($form['username']).'\' WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
-		$db->query('UPDATE '.$db->prefix.'topics SET poster=\''.$db->escape($form['username']).'\' WHERE poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
-		$db->query('UPDATE '.$db->prefix.'topics SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
-		$db->query('UPDATE '.$db->prefix.'forums SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update forums', __FILE__, __LINE__, $db->error());
-		$db->query('UPDATE '.$db->prefix.'online SET ident=\''.$db->escape($form['username']).'\' WHERE ident=\''.$db->escape($old_username).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'posts SET poster=\''.$pun_db->escape($form['username']).'\' WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $pun_db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET poster=\''.$pun_db->escape($form['username']).'\' WHERE poster=\''.$pun_db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $pun_db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET last_poster=\''.$pun_db->escape($form['username']).'\' WHERE last_poster=\''.$pun_db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $pun_db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET last_poster=\''.$pun_db->escape($form['username']).'\' WHERE last_poster=\''.$pun_db->escape($old_username).'\'') or error('Unable to update forums', __FILE__, __LINE__, $pun_db->error());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'online SET ident=\''.$pun_db->escape($form['username']).'\' WHERE ident=\''.$pun_db->escape($old_username).'\'') or error('Unable to update online list', __FILE__, __LINE__, $pun_db->error());
 
 		// If the user is a moderator or an administrator we have to update the moderator lists
-		$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-		$group_id = $db->result($result);
+		$result = $pun_db->query('SELECT group_id FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+		$group_id = $pun_db->result($result);
 
 		if ($group_id < PUN_GUEST)
 		{
-			$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
+			$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
 
-			while ($cur_forum = $db->fetch_assoc($result))
+			while ($cur_forum = $pun_db->fetch_assoc($result))
 			{
 				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 
@@ -881,21 +891,21 @@
 					$cur_moderators[$form['username']] = $id;
 					ksort($cur_moderators);
 
-					$db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+					$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET moderators=\''.$pun_db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
 				}
 			}
 		}
 	}
 
-	redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);
+	pun_redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);
 }
 
 
-$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.save_pass, u.notify_with_post, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
-if (!$db->num_rows($result))
+$result = $pun_db->query('SELECT eu.username, eu.email, u.title, eu.real_name AS realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.use_avatar, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.save_pass, u.notify_with_post, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, g.g_id, g.g_user_title FROM '.$pun_db->prefix.'users AS u LEFT JOIN '.table_prefix.'users AS eu ON eu.user_id=u.id LEFT JOIN '.$pun_db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+if (!$pun_db->num_rows($result))
 	message($lang_common['Bad request']);
 
-$user = $db->fetch_assoc($result);
+$user = $pun_db->fetch_assoc($result);
 
 $last_post = format_time($user['last_post']);
 
@@ -908,9 +918,9 @@
 
 // View or edit?
 if ($pun_user['id'] != $id &&
-	($pun_user['g_id'] > PUN_MOD ||
-	($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_edit_users'] == '0') ||
-	($pun_user['g_id'] == PUN_MOD && $user['g_id'] < PUN_GUEST)))
+	($pun_user['g_id'] > USER_LEVEL_MOD ||
+	($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_edit_users'] == '0') ||
+	($pun_user['g_id'] == USER_LEVEL_MOD && $user['g_id'] < PUN_GUEST)))
 {
 	if ($user['email_setting'] == '0' && !$pun_user['is_guest'])
 		$email_field = '<a href="mailto:'.$user['email'].'">'.$user['email'].'</a>';
@@ -951,7 +961,7 @@
 	}
 
 	$posts_field = '';
-	if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST)
+	if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
 		$posts_field = $user['num_posts'];
 	if ($pun_user['g_search'] == '1')
 		$posts_field .= (($posts_field != '') ? ' - ' : '').'<a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a>';
@@ -1049,9 +1059,9 @@
 {
 	if (!$section || $section == 'essentials')
 	{
-		if ($pun_user['g_id'] < PUN_GUEST)
+		if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
 		{
-			if ($pun_user['g_id'] == PUN_ADMIN || $pun_config['p_mod_rename_users'] == '1')
+			if ($pun_user['g_id'] == USER_LEVEL_ADMIN || $pun_config['p_mod_rename_users'] == '1')
 				$username_field = '<input type="hidden" name="old_username" value="'.pun_htmlspecialchars($user['username']).'" /><label><strong>'.$lang_common['Username'].'</strong><br /><input type="text" name="req_username" value="'.pun_htmlspecialchars($user['username']).'" size="25" maxlength="25" /><br /></label>'."\n";
 			else
 				$username_field = '<p>'.$lang_common['Username'].': '.pun_htmlspecialchars($user['username']).'</p>'."\n";
@@ -1068,12 +1078,18 @@
 				$email_field = '<label><strong>'.$lang_common['E-mail'].'</strong><br /><input type="text" name="req_email" value="'.$user['email'].'" size="40" maxlength="50" /><br /></label>'."\n";
 		}
 
-		if ($pun_user['g_id'] == PUN_ADMIN)
+		if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
+    {
 			$posts_field = '<label>'.$lang_common['Posts'].'<br /><input type="text" name="num_posts" value="'.$user['num_posts'].'" size="8" maxlength="8" /><br /></label><p><a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a></p>'."\n";
-		else if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST)
+    }
+		else if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
+    {
 			$posts_field = '<p>'.$lang_common['Posts'].': '.$user['num_posts'].' - <a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a></p>'."\n";
+    }
 		else
+    {
 			$posts_field = '<p><a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a></p>'."\n";
+    }
 
 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 		$required_fields = array('req_username' => $lang_common['Username'], 'req_email' => $lang_common['E-mail']);
@@ -1085,27 +1101,19 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section essentials'] ?></span></h2>
 		<div class="box">
-			<form id="profile1" method="post" action="profile.php?section=essentials&amp;id=<?php echo $id ?>" onsubmit="return process_form(this)">
+			<form id="profile1" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=essentials&id=' . $id . '', true); ?>" onsubmit="return process_form(this)">
 				<div class="inform">
 					<fieldset>
 						<legend><?php echo $lang_profile['Username and pass legend'] ?></legend>
 						<div class="infldset">
 							<input type="hidden" name="form_sent" value="1" />
 							<?php echo $username_field ?>
-<?php if ($pun_user['id'] == $id || $pun_user['g_id'] == PUN_ADMIN || ($user['g_id'] > PUN_MOD && $pun_config['p_mod_change_passwords'] == '1')): ?><p><a href="profile.php?action=change_pass&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Change pass'] ?></a></p>
+<?php if ($pun_user['id'] == $id || $pun_user['g_id'] == USER_LEVEL_ADMIN || ($user['g_id'] > PUN_MOD && $pun_config['p_mod_change_passwords'] == '1')): ?><p><a href="profile.php?action=change_pass&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Change pass'] ?></a></p>
 <?php endif; ?>					</div>
 					</fieldset>
 				</div>
 				<div class="inform">
 					<fieldset>
-						<legend><?php echo $lang_prof_reg['E-mail legend'] ?></legend>
-						<div class="infldset">
-							<?php echo $email_field ?>
-						</div>
-					</fieldset>
-				</div>
-				<div class="inform">
-					<fieldset>
 						<legend><?php echo $lang_prof_reg['Localisation legend'] ?></legend>
 						<div class="infldset">
 							<label><?php echo $lang_prof_reg['Timezone'] ?>: <?php echo $lang_prof_reg['Timezone info'] ?>
@@ -1193,10 +1201,10 @@
 					<fieldset>
 						<legend><?php echo $lang_profile['User activity'] ?></legend>
 						<div class="infldset">
-							<p><?php echo $lang_common['Registered'] ?>: <?php echo format_time($user['registered'], true); if ($pun_user['g_id'] < PUN_GUEST) echo ' (<a href="moderate.php?get_host='.pun_htmlspecialchars($user['registration_ip']).'">'.pun_htmlspecialchars($user['registration_ip']).'</a>)'; ?></p>
+							<p><?php echo $lang_common['Registered'] ?>: <?php echo format_time($user['registered'], true); if ($pun_user['g_id'] >= USER_LEVEL_MEMBER) echo ' (<a href="moderate.php?get_host='.pun_htmlspecialchars($user['registration_ip']).'">'.pun_htmlspecialchars($user['registration_ip']).'</a>)'; ?></p>
 							<p><?php echo $lang_common['Last post'] ?>: <?php echo $last_post ?></p>
 								<?php echo $posts_field ?>
-<?php if ($pun_user['g_id'] < PUN_GUEST): ?>							<label><?php echo $lang_profile['Admin note'] ?><br />
+<?php if ($pun_user['g_id'] >= USER_LEVEL_MEMBER): ?>							<label><?php echo $lang_profile['Admin note'] ?><br />
 							<input id="admin_note" type="text" name="admin_note" value="<?php echo pun_htmlspecialchars($user['admin_note']) ?>" size="30" maxlength="30" /><br /></label>
 						</div>
 <?php endif; ?>					</fieldset>
@@ -1222,7 +1230,7 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section personal'] ?></span></h2>
 		<div class="box">
-			<form id="profile2" method="post" action="profile.php?section=personal&amp;id=<?php echo $id ?>">
+			<form id="profile2" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=personal&id=' . $id . '', true); ?>">
 				<div class="inform">
 					<fieldset>
 						<legend><?php echo $lang_profile['Personal details legend'] ?></legend>
@@ -1254,7 +1262,7 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section messaging'] ?></span></h2>
 		<div class="box">
-			<form id="profile3" method="post" action="profile.php?section=messaging&amp;id=<?php echo $id ?>">
+			<form id="profile3" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=messaging&id=' . $id . '', true); ?>">
 				<div class="inform">
 					<fieldset>
 						<legend><?php echo $lang_profile['Contact details legend'] ?></legend>
@@ -1306,7 +1314,7 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section personality'] ?></span></h2>
 		<div class="box">
-			<form id="profile4" method="post" action="profile.php?section=personality&amp;id=<?php echo $id ?>">
+			<form id="profile4" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=personality&id=' . $id . '', true); ?>">
 				<div><input type="hidden" name="form_sent" value="1" /></div>
 <?php if ($pun_config['o_avatars'] == '1'): ?>				<div class="inform">
 					<fieldset id="profileavatar">
@@ -1357,7 +1365,7 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section display'] ?></span></h2>
 		<div class="box">
-			<form id="profile5" method="post" action="profile.php?section=display&amp;id=<?php echo $id ?>">
+			<form id="profile5" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=display&id=' . $id . '', true); ?>">
 				<div><input type="hidden" name="form_sent" value="1" /></div>
 <?php
 
@@ -1449,7 +1457,7 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section privacy'] ?></span></h2>
 		<div class="box">
-			<form id="profile6" method="post" action="profile.php?section=privacy&amp;id=<?php echo $id ?>">
+			<form id="profile6" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=privacy&id=' . $id . '', true); ?>">
 				<div class="inform">
 					<fieldset>
 						<legend><?php echo $lang_prof_reg['Privacy options legend'] ?></legend>
@@ -1481,7 +1489,7 @@
 	}
 	else if ($section == 'admin')
 	{
-		if ($pun_user['g_id'] > PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
+		if ($pun_user['g_id'] < USER_LEVEL_MOD || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_ban_users'] == '0'))
 			message($lang_common['Bad request']);
 
 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
@@ -1493,13 +1501,13 @@
 	<div class="blockform">
 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section admin'] ?></span></h2>
 		<div class="box">
-			<form id="profile7" method="post" action="profile.php?section=admin&amp;id=<?php echo $id ?>&amp;action=foo">
+			<form id="profile7" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=admin&id=' . $id . '&action=foo', true); ?>">
 				<div class="inform">
 				<input type="hidden" name="form_sent" value="1" />
 					<fieldset>
 <?php
 
-		if ($pun_user['g_id'] == PUN_MOD)
+		if ($pun_user['g_id'] == USER_LEVEL_MOD)
 		{
 
 ?>
@@ -1523,9 +1531,9 @@
 							<select id="group_id" name="group_id">
 <?php
 
-				$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
+				$result = $pun_db->query('SELECT g_id, g_title FROM '.$pun_db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $pun_db->error());
 
-				while ($cur_group = $db->fetch_assoc($result))
+				while ($cur_group = $pun_db->fetch_assoc($result))
 				{
 					if ($cur_group['g_id'] == $user['g_id'] || ($cur_group['g_id'] == $pun_config['o_default_user_group'] && $user['g_id'] == ''))
 						echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
@@ -1565,10 +1573,10 @@
 							<p><?php echo $lang_profile['Moderator in info'] ?></p>
 <?php
 
-				$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.moderators FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
+				$result = $pun_db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.moderators FROM '.$pun_db->prefix.'categories AS c INNER JOIN '.$pun_db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $pun_db->error());
 
 				$cur_category = 0;
-				while ($cur_forum = $db->fetch_assoc($result))
+				while ($cur_forum = $pun_db->fetch_assoc($result))
 				{
 					if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
 					{