punbb/profile.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 7 98bbc533541c
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 //define('PUN_ROOT', './');
       
    27 //require PUN_ROOT.'include/common.php';
       
    28 
       
    29 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    30 
       
    31 $GLOBALS['id'] = 0;
       
    32 $id =& $GLOBALS['id'];
       
    33 
       
    34 $action = isset($_GET['action']) ? $_GET['action'] : null;
       
    35 $section = isset($_GET['section']) ? $_GET['section'] : null;
       
    36 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
       
    37 if ($id < 2)
       
    38 	message($lang_common['Bad request']);
       
    39 
       
    40 if ($pun_user['g_read_board'] == '0' && ($action != 'change_pass' || !isset($_GET['key'])))
       
    41 	message($lang_common['No view']);
       
    42 
       
    43 $GLOBALS['lang_profile'] = array();
       
    44 $lang_profile =& $GLOBALS['lang_profile'];
       
    45 
       
    46 // Load the profile.php/register.php language file
       
    47 require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
       
    48 
       
    49 // Load the profile.php language file
       
    50 require PUN_ROOT.'lang/'.$pun_user['language'].'/profile.php';
       
    51 
       
    52 
       
    53 if ($action == 'change_pass')
       
    54 {
       
    55   // Can't do this, Enano's already got it
       
    56   message($lang_common['No permission'] . ' This is because this function is disabled in the Enano port, and Enano handles sessions and user management for PunBB.');
       
    57   
       
    58 	if (isset($_GET['key']))
       
    59 	{
       
    60 		// If the user is already logged in we shouldn't be here :)
       
    61 		if (!$pun_user['is_guest'])
       
    62 		{
       
    63 			header('Location: index.php');
       
    64 			exit;
       
    65 		}
       
    66 
       
    67 		$key = $_GET['key'];
       
    68 
       
    69 		$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());
       
    70 		list($new_password_hash, $new_password_key) = $pun_db->fetch_row($result);
       
    71 
       
    72 		if ($key == '' || $key != $new_password_key)
       
    73 			message($lang_profile['Pass key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
       
    74 		else
       
    75 		{
       
    76 			$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());
       
    77 
       
    78 			message($lang_profile['Pass updated'], true);
       
    79 		}
       
    80 	}
       
    81 
       
    82 	// Make sure we are allowed to change this users password
       
    83 	if ($pun_user['id'] != $id)
       
    84 	{
       
    85 		if ($pun_user['g_id'] < USER_LEVEL_MOD)	// A regular user trying to change another users password?
       
    86 			message($lang_common['No permission']);
       
    87 		else if ($pun_user['g_id'] == USER_LEVEL_MOD)	// A moderator trying to change a users password?
       
    88 		{
       
    89 			$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());
       
    90 			if (!$pun_db->num_rows($result))
       
    91 				message($lang_common['Bad request']);
       
    92 
       
    93 			if ($pun_config['p_mod_edit_users'] == '0' || $pun_config['p_mod_change_passwords'] == '0' || $pun_db->result($result) < PUN_GUEST)
       
    94 				message($lang_common['No permission']);
       
    95 		}
       
    96 	}
       
    97 
       
    98 	if (isset($_POST['form_sent']))
       
    99 	{
       
   100 		$old_password = isset($_POST['req_old_password']) ? trim($_POST['req_old_password']) : '';
       
   101 		$new_password1 = trim($_POST['req_new_password1']);
       
   102 		$new_password2 = trim($_POST['req_new_password2']);
       
   103 
       
   104 		if ($new_password1 != $new_password2)
       
   105 			message($lang_prof_reg['Pass not match']);
       
   106 		if (strlen($new_password1) < 4)
       
   107 			message($lang_prof_reg['Pass too short']);
       
   108 
       
   109 		$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());
       
   110 		list($db_password_hash, $save_pass) = $pun_db->fetch_row($result);
       
   111 
       
   112 		$authorized = false;
       
   113 
       
   114 		if (!empty($db_password_hash))
       
   115 		{
       
   116 			$sha1_in_db = (strlen($db_password_hash) == 40) ? true : false;
       
   117 			$sha1_available = (function_exists('sha1') || function_exists('mhash')) ? true : false;
       
   118 
       
   119 			$old_password_hash = pun_hash($old_password);	// This could result in either an SHA-1 or an MD5 hash
       
   120 
       
   121 			if (($sha1_in_db && $sha1_available && $db_password_hash == $old_password_hash) ||
       
   122 				(!$sha1_in_db && $db_password_hash == md5($old_password)) ||
       
   123 				$pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
   124 				$authorized = true;
       
   125 		}
       
   126 
       
   127 		if (!$authorized)
       
   128 			message($lang_profile['Wrong pass']);
       
   129 
       
   130 		$new_password_hash = pun_hash($new_password1);
       
   131 
       
   132 		$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());
       
   133 
       
   134 		if ($pun_user['id'] == $id)
       
   135 		{
       
   136 			$expire = ($save_pass == '1') ? time() + 31536000 : 0;
       
   137 			pun_setcookie($pun_user['id'], $new_password_hash, $expire);
       
   138 		}
       
   139 
       
   140 		pun_redirect('profile.php?section=essentials&amp;id='.$id, $lang_profile['Pass updated redirect']);
       
   141 	}
       
   142 
       
   143 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
   144 	$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']);
       
   145 	$focus_element = array('change_pass', (($pun_user['g_id'] < USER_LEVEL_MOD) ? 'req_old_password' : 'req_new_password1'));
       
   146 	require PUN_ROOT.'header.php';
       
   147 
       
   148 ?>
       
   149 <div class="blockform">
       
   150 	<h2><span><?php echo $lang_profile['Change pass'] ?></span></h2>
       
   151 	<div class="box">
       
   152 		<form id="change_pass" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'action=change_pass&id=' . $id . '', true); ?>" onsubmit="return process_form(this)">
       
   153 			<div class="inform">
       
   154 				<input type="hidden" name="form_sent" value="1" />
       
   155 				<fieldset>
       
   156 					<legend><?php echo $lang_profile['Change pass legend'] ?></legend>
       
   157 					<div class="infldset">
       
   158 <?php if ($pun_user['g_id'] < USER_LEVEL_MOD): ?>						<label><strong><?php echo $lang_profile['Old pass'] ?></strong><br />
       
   159 						<input type="password" name="req_old_password" size="16" maxlength="16" /><br /></label>
       
   160 <?php endif; ?>						<label class="conl"><strong><?php echo $lang_profile['New pass'] ?></strong><br />
       
   161 						<input type="password" name="req_new_password1" size="16" maxlength="16" /><br /></label>
       
   162 						<label class="conl"><strong><?php echo $lang_profile['Confirm new pass'] ?></strong><br />
       
   163 						<input type="password" name="req_new_password2" size="16" maxlength="16" /><br /></label>
       
   164 						<div class="clearb"></div>
       
   165 					</div>
       
   166 				</fieldset>
       
   167 			</div>
       
   168 			<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
       
   169 		</form>
       
   170 	</div>
       
   171 </div>
       
   172 <?php
       
   173 
       
   174 	require PUN_ROOT.'footer.php';
       
   175 }
       
   176 
       
   177 
       
   178 else if ($action == 'change_email')
       
   179 {
       
   180 	// Make sure we are allowed to change this users e-mail
       
   181 	if ($pun_user['id'] != $id)
       
   182 	{
       
   183 		if ($pun_user['g_id'] < USER_LEVEL_MOD)	// A regular user trying to change another users e-mail?
       
   184 			message($lang_common['No permission']);
       
   185 		else if ($pun_user['g_id'] == USER_LEVEL_MOD)	// A moderator trying to change a users e-mail?
       
   186 		{
       
   187 			$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());
       
   188 			if (!$pun_db->num_rows($result))
       
   189 				message($lang_common['Bad request']);
       
   190 
       
   191 			if ($pun_config['p_mod_edit_users'] == '0' || $pun_db->result($result) < PUN_GUEST)
       
   192 				message($lang_common['No permission']);
       
   193 		}
       
   194 	}
       
   195 
       
   196 	if (isset($_GET['key']))
       
   197 	{
       
   198 		$key = $_GET['key'];
       
   199 
       
   200 		$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());
       
   201 		list($new_email, $new_email_key) = $pun_db->fetch_row($result);
       
   202 
       
   203 		if ($key == '' || $key != $new_email_key)
       
   204 			message($lang_profile['E-mail key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
       
   205 		else
       
   206 		{
       
   207 			$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());
       
   208 
       
   209 			message($lang_profile['E-mail updated'], true);
       
   210 		}
       
   211 	}
       
   212 	else if (isset($_POST['form_sent']))
       
   213 	{
       
   214 		if (pun_hash($_POST['req_password']) !== $pun_user['password'])
       
   215 			message($lang_profile['Wrong pass']);
       
   216 
       
   217 		require PUN_ROOT.'include/email.php';
       
   218 
       
   219 		// Validate the email-address
       
   220 		$new_email = strtolower(trim($_POST['req_new_email']));
       
   221 		if (!is_valid_email($new_email))
       
   222 			message($lang_common['Invalid e-mail']);
       
   223 
       
   224 		// Check it it's a banned e-mail address
       
   225 		if (is_banned_email($new_email))
       
   226 		{
       
   227 			if ($pun_config['p_allow_banned_email'] == '0')
       
   228 				message($lang_prof_reg['Banned e-mail']);
       
   229 			else if ($pun_config['o_mailing_list'] != '')
       
   230 			{
       
   231 				$mail_subject = 'Alert - Banned e-mail detected';
       
   232 				$mail_message = 'User \''.$pun_user['username'].'\' changed to banned e-mail address: '.$new_email."\n\n".'User profile: '.$pun_config['o_base_url'].'/profile.php?id='.$id."\n\n".'-- '."\n".'Forum Mailer'."\n".'(Do not reply to this message)';
       
   233 
       
   234 				pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
       
   235 			}
       
   236 		}
       
   237 
       
   238 		// Check if someone else already has registered with that e-mail address
       
   239 		$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());
       
   240 		if ($pun_db->num_rows($result))
       
   241 		{
       
   242 			if ($pun_config['p_allow_dupe_email'] == '0')
       
   243 				message($lang_prof_reg['Dupe e-mail']);
       
   244 			else if ($pun_config['o_mailing_list'] != '')
       
   245 			{
       
   246 				while ($cur_dupe = $pun_db->fetch_assoc($result))
       
   247 					$dupe_list[] = $cur_dupe['username'];
       
   248 
       
   249 				$mail_subject = 'Alert - Duplicate e-mail detected';
       
   250 				$mail_message = 'User \''.$pun_user['username'].'\' changed to an e-mail address that also belongs to: '.implode(', ', $dupe_list)."\n\n".'User profile: '.$pun_config['o_base_url'].'/profile.php?id='.$id."\n\n".'-- '."\n".'Forum Mailer'."\n".'(Do not reply to this message)';
       
   251 
       
   252 				pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
       
   253 			}
       
   254 		}
       
   255 
       
   256 
       
   257 		$new_email_key = random_pass(8);
       
   258 
       
   259 		$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());
       
   260 
       
   261 		// Load the "activate e-mail" template
       
   262 		$mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/activate_email.tpl'));
       
   263 
       
   264 		// The first row contains the subject
       
   265 		$first_crlf = strpos($mail_tpl, "\n");
       
   266 		$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
       
   267 		$mail_message = trim(substr($mail_tpl, $first_crlf));
       
   268 
       
   269 		$mail_message = str_replace('<username>', $pun_user['username'], $mail_message);
       
   270 		$mail_message = str_replace('<base_url>', $pun_config['o_base_url'], $mail_message);
       
   271 		$mail_message = str_replace('<activation_url>', $pun_config['o_base_url'].'/profile.php?action=change_email&id='.$id.'&key='.$new_email_key, $mail_message);
       
   272 		$mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
       
   273 
       
   274 		pun_mail($new_email, $mail_subject, $mail_message);
       
   275 
       
   276 		message($lang_profile['Activate e-mail sent'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.', true);
       
   277 	}
       
   278 
       
   279 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
   280 	$required_fields = array('req_new_email' => $lang_profile['New e-mail'], 'req_password' => $lang_common['Password']);
       
   281 	$focus_element = array('change_email', 'req_new_email');
       
   282 	require PUN_ROOT.'header.php';
       
   283 
       
   284 ?>
       
   285 <div class="blockform">
       
   286 	<h2><span><?php echo $lang_profile['Change e-mail'] ?></span></h2>
       
   287 	<div class="box">
       
   288 		<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)">
       
   289 			<div class="inform">
       
   290 				<fieldset>
       
   291 					<legend><?php echo $lang_profile['E-mail legend'] ?></legend>
       
   292 					<div class="infldset">
       
   293 						<input type="hidden" name="form_sent" value="1" />
       
   294 						<label><strong><?php echo $lang_profile['New e-mail'] ?></strong><br /><input type="text" name="req_new_email" size="50" maxlength="50" /><br /></label>
       
   295 						<label><strong><?php echo $lang_common['Password'] ?></strong><br /><input type="password" name="req_password" size="16" maxlength="16" /><br /></label>
       
   296 						<p><?php echo $lang_profile['E-mail instructions'] ?></p>
       
   297 					</div>
       
   298 				</fieldset>
       
   299 			</div>
       
   300 			<p><input type="submit" name="new_email" value="<?php echo $lang_common['Submit'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
       
   301 		</form>
       
   302 	</div>
       
   303 </div>
       
   304 <?php
       
   305 
       
   306 	require PUN_ROOT.'footer.php';
       
   307 }
       
   308 
       
   309 
       
   310 else if ($action == 'upload_avatar' || $action == 'upload_avatar2')
       
   311 {
       
   312 	if ($pun_config['o_avatars'] == '0')
       
   313 		message($lang_profile['Avatars disabled']);
       
   314 
       
   315 	if ($pun_user['id'] != $id && $pun_user['g_id'] < USER_LEVEL_MOD)
       
   316 		message($lang_common['No permission']);
       
   317 
       
   318 	if (isset($_POST['form_sent']))
       
   319 	{
       
   320 		if (!isset($_FILES['req_file']))
       
   321 			message($lang_profile['No file']);
       
   322 			
       
   323 		$uploaded_file = $_FILES['req_file'];
       
   324 
       
   325 		// Make sure the upload went smooth
       
   326 		if (isset($uploaded_file['error']))
       
   327 		{
       
   328 			switch ($uploaded_file['error'])
       
   329 			{
       
   330 				case 1:	// UPLOAD_ERR_INI_SIZE
       
   331 				case 2:	// UPLOAD_ERR_FORM_SIZE
       
   332 					message($lang_profile['Too large ini']);
       
   333 					break;
       
   334 
       
   335 				case 3:	// UPLOAD_ERR_PARTIAL
       
   336 					message($lang_profile['Partial upload']);
       
   337 					break;
       
   338 
       
   339 				case 4:	// UPLOAD_ERR_NO_FILE
       
   340 					message($lang_profile['No file']);
       
   341 					break;
       
   342 
       
   343 				case 6:	// UPLOAD_ERR_NO_TMP_DIR
       
   344 					message($lang_profile['No tmp directory']);
       
   345 					break;
       
   346 
       
   347 				default:
       
   348 					// No error occured, but was something actually uploaded?
       
   349 					if ($uploaded_file['size'] == 0)
       
   350 						message($lang_profile['No file']);
       
   351 					break;
       
   352 			}
       
   353 		}
       
   354 
       
   355 		if (is_uploaded_file($uploaded_file['tmp_name']))
       
   356 		{
       
   357 			$allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
       
   358 			if (!in_array($uploaded_file['type'], $allowed_types))
       
   359 				message($lang_profile['Bad type']);
       
   360 
       
   361 			// Make sure the file isn't too big
       
   362 			if ($uploaded_file['size'] > $pun_config['o_avatars_size'])
       
   363 				message($lang_profile['Too large'].' '.$pun_config['o_avatars_size'].' '.$lang_profile['bytes'].'.');
       
   364 
       
   365 			// Determine type
       
   366 			$extensions = null;
       
   367 			if ($uploaded_file['type'] == 'image/gif')
       
   368 				$extensions = array('.gif', '.jpg', '.png');
       
   369 			else if ($uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg')
       
   370 				$extensions = array('.jpg', '.gif', '.png');
       
   371 			else
       
   372 				$extensions = array('.png', '.gif', '.jpg');
       
   373 
       
   374 			// Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions.
       
   375 			if (!@move_uploaded_file($uploaded_file['tmp_name'], $pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
       
   376 				message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
       
   377 
       
   378 			// Now check the width/height
       
   379 			list($width, $height, $type,) = getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
       
   380 			if (empty($width) || empty($height) || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
       
   381 			{
       
   382 				@unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
       
   383 				message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
       
   384 			}
       
   385 			else if ($type == 1 && $uploaded_file['type'] != 'image/gif')	// Prevent dodgy uploads
       
   386 			{
       
   387 				@unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
       
   388 				message($lang_profile['Bad type']);
       
   389 			}			
       
   390 
       
   391 			// Delete any old avatars and put the new one in place
       
   392 			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
       
   393 			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[1]);
       
   394 			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[2]);
       
   395 			@rename($pun_config['o_avatars_dir'].'/'.$id.'.tmp', $pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
       
   396 			@chmod($pun_config['o_avatars_dir'].'/'.$id.$extensions[0], 0644);
       
   397 		}
       
   398 		else
       
   399 			message($lang_profile['Unknown failure']);
       
   400 
       
   401 		// Enable use_avatar (seems sane since the user just uploaded an avatar)
       
   402 		$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());
       
   403 
       
   404 		pun_redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
       
   405 	}
       
   406 
       
   407 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
   408 	$required_fields = array('req_file' => $lang_profile['File']);
       
   409 	$focus_element = array('upload_avatar', 'req_file');
       
   410 	require PUN_ROOT.'header.php';
       
   411 
       
   412 ?>
       
   413 <div class="blockform">
       
   414 	<h2><span><?php echo $lang_profile['Upload avatar'] ?></span></h2>
       
   415 	<div class="box">
       
   416 		<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)">
       
   417 			<div class="inform">
       
   418 				<fieldset>
       
   419 					<legend><?php echo $lang_profile['Upload avatar legend'] ?></legend>
       
   420 					<div class="infldset">
       
   421 						<input type="hidden" name="form_sent" value="1" />
       
   422 						<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $pun_config['o_avatars_size'] ?>" />
       
   423 						<label><strong><?php echo $lang_profile['File'] ?></strong><br /><input name="req_file" type="file" size="40" /><br /></label>
       
   424 						<p><?php echo $lang_profile['Avatar desc'].' '.$pun_config['o_avatars_width'].' x '.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].' '.$lang_common['and'].' '.$pun_config['o_avatars_size'].' '.$lang_profile['bytes'].' ('.ceil($pun_config['o_avatars_size'] / 1024) ?> KB).</p>
       
   425 					</div>
       
   426 				</fieldset>
       
   427 			</div>
       
   428 			<p><input type="submit" name="upload" value="<?php echo $lang_profile['Upload'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
       
   429 		</form>
       
   430 	</div>
       
   431 </div>
       
   432 <?php
       
   433 
       
   434 	require PUN_ROOT.'footer.php';
       
   435 }
       
   436 
       
   437 
       
   438 else if ($action == 'delete_avatar')
       
   439 {
       
   440 	if ($pun_user['id'] != $id && $pun_user['g_id'] < USER_LEVEL_MOD)
       
   441 		message($lang_common['No permission']);
       
   442 
       
   443 	confirm_referrer('profile.php');
       
   444 
       
   445 	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.jpg');
       
   446 	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.png');
       
   447 	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.gif');
       
   448 
       
   449 	// Disable use_avatar
       
   450 	$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());
       
   451 
       
   452 	pun_redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar deleted redirect']);
       
   453 }
       
   454 
       
   455 
       
   456 else if (isset($_POST['update_group_membership']))
       
   457 {
       
   458 	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
       
   459 		message($lang_common['No permission']);
       
   460 
       
   461 	confirm_referrer('profile.php');
       
   462 
       
   463 	$new_group_id = intval($_POST['group_id']);
       
   464 
       
   465 	$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());
       
   466 
       
   467 	// If the user was a moderator or an administrator, we remove him/her from the moderator list in all forums as well
       
   468 	if ($new_group_id > PUN_MOD)
       
   469 	{
       
   470 		$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
       
   471 
       
   472 		while ($cur_forum = $pun_db->fetch_assoc($result))
       
   473 		{
       
   474 			$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
       
   475 
       
   476 			if (in_array($id, $cur_moderators))
       
   477 			{
       
   478 				$username = array_search($id, $cur_moderators);
       
   479 				unset($cur_moderators[$username]);
       
   480 				$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
       
   481 
       
   482 				$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());
       
   483 			}
       
   484 		}
       
   485 	}
       
   486 
       
   487 	pun_redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Group membership redirect']);
       
   488 }
       
   489 
       
   490 
       
   491 else if (isset($_POST['update_forums']))
       
   492 {
       
   493 	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
       
   494 		message($lang_common['No permission']);
       
   495 
       
   496 	confirm_referrer('profile.php');
       
   497 
       
   498 	// Get the username of the user we are processing
       
   499 	$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());
       
   500 	$username = $pun_db->result($result);
       
   501 
       
   502 	$moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
       
   503 
       
   504 	// Loop through all forums
       
   505 	$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
       
   506 
       
   507 	while ($cur_forum = $pun_db->fetch_assoc($result))
       
   508 	{
       
   509 		$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
       
   510 		// If the user should have moderator access (and he/she doesn't already have it)
       
   511 		if (in_array($cur_forum['id'], $moderator_in) && !in_array($id, $cur_moderators))
       
   512 		{
       
   513 			$cur_moderators[$username] = $id;
       
   514 			ksort($cur_moderators);
       
   515 
       
   516 			$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());
       
   517 		}
       
   518 		// If the user shouldn't have moderator access (and he/she already has it)
       
   519 		else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators))
       
   520 		{
       
   521 			unset($cur_moderators[$username]);
       
   522 			$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
       
   523 
       
   524 			$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());
       
   525 		}
       
   526 	}
       
   527 
       
   528 	pun_redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Update forums redirect']);
       
   529 }
       
   530 
       
   531 
       
   532 else if (isset($_POST['ban']))
       
   533 {
       
   534 	if ($pun_user['g_id'] < USER_LEVEL_MOD || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_ban_users'] == '0'))
       
   535 		message($lang_common['No permission']);
       
   536 
       
   537 	pun_redirect('admin_bans.php?add_ban='.$id, $lang_profile['Ban redirect']);
       
   538 }
       
   539 
       
   540 
       
   541 else if (isset($_POST['delete_user']) || isset($_POST['delete_user_comply']))
       
   542 {
       
   543 	if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
       
   544 		message($lang_common['No permission']);
       
   545 
       
   546 	confirm_referrer('profile.php');
       
   547 
       
   548 	// Get the username and group of the user we are deleting
       
   549 	$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());
       
   550 	list($group_id, $username) = $pun_db->fetch_row($result);
       
   551 
       
   552 	if ($group_id == PUN_ADMIN)
       
   553 		message('Administrators cannot be deleted. In order to delete this user, you must first move him/her to a different user group.');
       
   554 
       
   555 	if (isset($_POST['delete_user_comply']))
       
   556 	{
       
   557 		// If the user is a moderator or an administrator, we remove him/her from the moderator list in all forums as well
       
   558 		if ($group_id < PUN_GUEST)
       
   559 		{
       
   560 			$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
       
   561 
       
   562 			while ($cur_forum = $pun_db->fetch_assoc($result))
       
   563 			{
       
   564 				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
       
   565 
       
   566 				if (in_array($id, $cur_moderators))
       
   567 				{
       
   568 					unset($cur_moderators[$username]);
       
   569 					$cur_moderators = (!empty($cur_moderators)) ? '\''.$pun_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
       
   570 
       
   571 					$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());
       
   572 				}
       
   573 			}
       
   574 		}
       
   575 
       
   576 		// Delete any subscriptions
       
   577 		$pun_db->query('DELETE FROM '.$pun_db->prefix.'subscriptions WHERE user_id='.$id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $pun_db->error());
       
   578 
       
   579 		// Remove him/her from the online list (if they happen to be logged in)
       
   580 		$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());
       
   581 
       
   582 		// Should we delete all posts made by this user?
       
   583 		if (isset($_POST['delete_posts']))
       
   584 		{
       
   585 			require PUN_ROOT.'include/search_idx.php';
       
   586 			@set_time_limit(0);
       
   587 
       
   588 			// Find all posts made by this user
       
   589 			$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());
       
   590 			if ($pun_db->num_rows($result))
       
   591 			{
       
   592 				while ($cur_post = $pun_db->fetch_assoc($result))
       
   593 				{
       
   594 					// Determine whether this post is the "topic post" or not
       
   595 					$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());
       
   596 
       
   597 					if ($pun_db->result($result2) == $cur_post['id'])
       
   598 						delete_topic($cur_post['topic_id']);
       
   599 					else
       
   600 						delete_post($cur_post['id'], $cur_post['topic_id']);
       
   601 
       
   602 					update_forum($cur_post['forum_id']);
       
   603 				}
       
   604 			}
       
   605 		}
       
   606 		else
       
   607 			// Set all his/her posts to guest
       
   608 			$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());
       
   609 
       
   610 		// Delete the user
       
   611 		$pun_db->query('DELETE FROM '.$pun_db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $pun_db->error());
       
   612 
       
   613 		pun_redirect('index.php', $lang_profile['User delete redirect']);
       
   614 	}
       
   615 
       
   616 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
   617 	require PUN_ROOT.'header.php';
       
   618 
       
   619 ?>
       
   620 <div class="blockform">
       
   621 	<h2><span><?php echo $lang_profile['Confirm delete user'] ?></span></h2>
       
   622 	<div class="box">
       
   623 		<form id="confirm_del_user" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'id=' . $id . '', true); ?>">
       
   624 			<div class="inform">
       
   625 				<fieldset>
       
   626 					<legend><?php echo $lang_profile['Confirm delete legend'] ?></legend>
       
   627 					<div class="infldset">
       
   628 						<p><?php echo $lang_profile['Confirmation info'].' '.pun_htmlspecialchars($username).'.' ?></p>
       
   629 						<div class="rbox">
       
   630 							<label><input type="checkbox" name="delete_posts" value="1" checked="checked" /><?php echo $lang_profile['Delete posts'] ?><br /></label>
       
   631 						</div>
       
   632 						<p class="warntext"><strong><?php echo $lang_profile['Delete warning'] ?></strong></p>
       
   633 					</div>
       
   634 				</fieldset>
       
   635 			</div>
       
   636 			<p><input type="submit" name="delete_user_comply" value="<?php echo $lang_profile['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
       
   637 		</form>
       
   638 	</div>
       
   639 </div>
       
   640 <?php
       
   641 
       
   642 	require PUN_ROOT.'footer.php';
       
   643 }
       
   644 
       
   645 
       
   646 else if (isset($_POST['form_sent']))
       
   647 {
       
   648 	// Fetch the user group of the user we are editing
       
   649 	$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());
       
   650 	if (!$pun_db->num_rows($result))
       
   651 		message($lang_common['Bad request']);
       
   652 
       
   653 	$group_id = $pun_db->result($result);
       
   654 
       
   655 	if ($pun_user['id'] != $id &&
       
   656 		($pun_user['g_id'] < USER_LEVEL_MOD ||
       
   657 		($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_edit_users'] == '0') ||
       
   658 		($pun_user['g_id'] == USER_LEVEL_MOD && $group_id < PUN_GUEST)))
       
   659 		message($lang_common['No permission']);
       
   660 
       
   661 	if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
   662 		confirm_referrer('profile.php');
       
   663 
       
   664 	// Extract allowed elements from $_POST['form']
       
   665 	function extract_elements($allowed_elements)
       
   666 	{
       
   667 		$form = array();
       
   668 
       
   669 		while (list($key, $value) = @each($_POST['form']))
       
   670 		{
       
   671 		    if (in_array($key, $allowed_elements))
       
   672 		        $form[$key] = $value;
       
   673 		}
       
   674 
       
   675 		return $form;
       
   676 	}
       
   677 
       
   678 	$username_updated = false;
       
   679 
       
   680 	// Validate input depending on section
       
   681 	switch ($section)
       
   682 	{
       
   683 		case 'essentials':
       
   684 		{
       
   685 			$form = extract_elements(array('timezone', 'language'));
       
   686 
       
   687 			if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
   688 			{
       
   689 				$form['admin_note'] = trim($_POST['admin_note']);
       
   690 
       
   691 				// Are we allowed to change usernames?
       
   692         // In Enano, NO!
       
   693 				if ( false ) // ($pun_user['g_id'] == USER_LEVEL_ADMIN || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_rename_users'] == '1'))
       
   694 				{
       
   695 					$form['username'] = trim($_POST['req_username']);
       
   696 					$old_username = trim($_POST['old_username']);
       
   697 
       
   698 					if (strlen($form['username']) < 2)
       
   699 						message($lang_prof_reg['Username too short']);
       
   700 					else if (pun_strlen($form['username']) > 25)	// This usually doesn't happen since the form element only accepts 25 characters
       
   701 					    message($lang_common['Bad request']);
       
   702 					else if (!strcasecmp($form['username'], 'Guest') || !strcasecmp($form['username'], $lang_common['Guest']))
       
   703 						message($lang_prof_reg['Username guest']);
       
   704 					else if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $form['username']))
       
   705 						message($lang_prof_reg['Username IP']);
       
   706 					else if (preg_match('#\[b\]|\[/b\]|\[u\]|\[/u\]|\[i\]|\[/i\]|\[color|\[/color\]|\[quote\]|\[quote=|\[/quote\]|\[code\]|\[/code\]|\[img\]|\[/img\]|\[url|\[/url\]|\[email|\[/email\]#i', $form['username']))
       
   707 						message($lang_prof_reg['Username BBCode']);
       
   708 
       
   709 					// Check that the username is not already registered
       
   710 					$result = $pun_db->query('SELECT 1 FROM '.table_prefix.'users WHERE username=\''.$pun_db->escape($form['username']).'\' AND user_id!='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
       
   711 					if ($pun_db->num_rows($result))
       
   712 						message($lang_profile['Dupe username']);
       
   713 
       
   714 					if ($form['username'] != $old_username)
       
   715 						$username_updated = true;
       
   716 				}
       
   717 
       
   718 				// We only allow administrators to update the post count
       
   719 				if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
       
   720 					$form['num_posts'] = intval($_POST['num_posts']);
       
   721 			}
       
   722 
       
   723       /*
       
   724       // Don't update e-mail address in Enano
       
   725 			if ($pun_config['o_regs_verify'] == '0' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
   726 			{
       
   727 				require PUN_ROOT.'include/email.php';
       
   728 
       
   729 				// Validate the email-address
       
   730 				$form['email'] = strtolower(trim($_POST['req_email']));
       
   731 				if (!is_valid_email($form['email']))
       
   732 					message($lang_common['Invalid e-mail']);
       
   733 			}
       
   734       */
       
   735 
       
   736 			// Make sure we got a valid language string
       
   737 			if (isset($form['language']))
       
   738 			{
       
   739 				$form['language'] = preg_replace('#[\.\\\/]#', '', $form['language']);
       
   740 				if (!file_exists(PUN_ROOT.'lang/'.$form['language'].'/common.php'))
       
   741 						message($lang_common['Bad request']);
       
   742 			}
       
   743 
       
   744 			break;
       
   745 		}
       
   746 
       
   747 		case 'personal':
       
   748 		{
       
   749 			$form = extract_elements(array('realname', 'url', 'location'));
       
   750 
       
   751 			if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
       
   752 				$form['title'] = trim($_POST['title']);
       
   753 			else if ($pun_user['g_set_title'] == '1')
       
   754 			{
       
   755 				$form['title'] = trim($_POST['title']);
       
   756 
       
   757 				if ($form['title'] != '')
       
   758 				{
       
   759 					// A list of words that the title may not contain
       
   760 					// If the language is English, there will be some duplicates, but it's not the end of the world
       
   761 					$forbidden = array('Member', 'Moderator', 'Administrator', 'Banned', 'Guest', $lang_common['Member'], $lang_common['Moderator'], $lang_common['Administrator'], $lang_common['Banned'], $lang_common['Guest']);
       
   762 
       
   763 					if (in_array($form['title'], $forbidden))
       
   764 						message($lang_profile['Forbidden title']);
       
   765 				}
       
   766 			}
       
   767 
       
   768 			// Add http:// if the URL doesn't contain it already
       
   769 			if ($form['url'] != '' && strpos(strtolower($form['url']), 'http://') !== 0)
       
   770 				$form['url'] = 'http://'.$form['url'];
       
   771 
       
   772 			break;
       
   773 		}
       
   774 
       
   775 		case 'messaging':
       
   776 		{
       
   777 			$form = extract_elements(array('jabber', 'icq', 'msn', 'aim', 'yahoo'));
       
   778 
       
   779 			// If the ICQ UIN contains anything other than digits it's invalid
       
   780 			if ($form['icq'] != '' && @preg_match('/[^0-9]/', $form['icq']))
       
   781 				message($lang_prof_reg['Bad ICQ']);
       
   782 
       
   783 			break;
       
   784 		}
       
   785 
       
   786 		case 'personality':
       
   787 		{
       
   788 			$form = extract_elements(array('use_avatar'));
       
   789 
       
   790 			// Clean up signature from POST
       
   791 			$form['signature'] = pun_linebreaks(trim($_POST['signature']));
       
   792 
       
   793 			// Validate signature
       
   794 			if (pun_strlen($form['signature']) > $pun_config['p_sig_length'])
       
   795 				message($lang_prof_reg['Sig too long'].' '.$pun_config['p_sig_length'].' '.$lang_prof_reg['characters'].'.');
       
   796 			else if (substr_count($form['signature'], "\n") > ($pun_config['p_sig_lines']-1))
       
   797 				message($lang_prof_reg['Sig too many lines'].' '.$pun_config['p_sig_lines'].' '.$lang_prof_reg['lines'].'.');
       
   798 			else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && strtoupper($form['signature']) == $form['signature'] && $pun_user['g_id'] < USER_LEVEL_MOD)
       
   799 				$form['signature'] = ucwords(strtolower($form['signature']));
       
   800 
       
   801 			// Validate BBCode syntax
       
   802 			if ($pun_config['p_sig_bbcode'] == '1' && strpos($form['signature'], '[') !== false && strpos($form['signature'], ']') !== false)
       
   803 			{
       
   804 				require PUN_ROOT.'include/parser.php';
       
   805 				$form['signature'] = preparse_bbcode($form['signature'], $foo, true);
       
   806 			}
       
   807 
       
   808 			if (!isset($form['use_avatar']) || $form['use_avatar'] != '1') $form['use_avatar'] = '0';
       
   809 
       
   810 			break;
       
   811 		}
       
   812 
       
   813 		case 'display':
       
   814 		{
       
   815 			$form = extract_elements(array('disp_topics', 'disp_posts', 'show_smilies', 'show_img', 'show_img_sig', 'show_avatars', 'show_sig', 'style'));
       
   816 
       
   817 			if ($form['disp_topics'] != '' && intval($form['disp_topics']) < 3) $form['disp_topics'] = 3;
       
   818 			if ($form['disp_topics'] != '' && intval($form['disp_topics']) > 75) $form['disp_topics'] = 75;
       
   819 			if ($form['disp_posts'] != '' && intval($form['disp_posts']) < 3) $form['disp_posts'] = 3;
       
   820 			if ($form['disp_posts'] != '' && intval($form['disp_posts']) > 75) $form['disp_posts'] = 75;
       
   821 
       
   822 			if (!isset($form['show_smilies']) || $form['show_smilies'] != '1') $form['show_smilies'] = '0';
       
   823 			if (!isset($form['show_img']) || $form['show_img'] != '1') $form['show_img'] = '0';
       
   824 			if (!isset($form['show_img_sig']) || $form['show_img_sig'] != '1') $form['show_img_sig'] = '0';
       
   825 			if (!isset($form['show_avatars']) || $form['show_avatars'] != '1') $form['show_avatars'] = '0';
       
   826 			if (!isset($form['show_sig']) || $form['show_sig'] != '1') $form['show_sig'] = '0';
       
   827 
       
   828 			break;
       
   829 		}
       
   830 
       
   831 		case 'privacy':
       
   832 		{
       
   833 			$form = extract_elements(array('email_setting', 'save_pass', 'notify_with_post'));
       
   834 
       
   835 			$form['email_setting'] = intval($form['email_setting']);
       
   836 			if ($form['email_setting'] < 0 && $form['email_setting'] > 2) $form['email_setting'] = 1;
       
   837 
       
   838 			if (!isset($form['save_pass']) || $form['save_pass'] != '1') $form['save_pass'] = '0';
       
   839 			if (!isset($form['notify_with_post']) || $form['notify_with_post'] != '1') $form['notify_with_post'] = '0';
       
   840 
       
   841 			// If the save_pass setting has changed, we need to set a new cookie with the appropriate expire date
       
   842 			if ($pun_user['id'] == $id && $form['save_pass'] != $pun_user['save_pass'])
       
   843 			{
       
   844 				$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());
       
   845 				pun_setcookie($id, $pun_db->result($result), ($form['save_pass'] == '1') ? time() + 31536000 : 0);
       
   846 			}
       
   847 
       
   848 			break;
       
   849 		}
       
   850 
       
   851 		default:
       
   852 			message($lang_common['Bad request']);
       
   853 	}
       
   854 
       
   855 
       
   856 	// Singlequotes around non-empty values and NULL for empty values
       
   857 	$temp = array();
       
   858 	while (list($key, $input) = @each($form))
       
   859 	{
       
   860 		$value = ($input !== '') ? '\''.$pun_db->escape($input).'\'' : 'NULL';
       
   861 
       
   862 		$temp[] = $key.'='.$value;
       
   863 	}
       
   864 
       
   865 	if (empty($temp))
       
   866 		message($lang_common['Bad request']);
       
   867 
       
   868 
       
   869 	$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());
       
   870 
       
   871 	// If we changed the username we have to update some stuff
       
   872 	if ($username_updated)
       
   873 	{
       
   874 		$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());
       
   875 		$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());
       
   876 		$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());
       
   877 		$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());
       
   878 		$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());
       
   879 
       
   880 		// If the user is a moderator or an administrator we have to update the moderator lists
       
   881 		$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());
       
   882 		$group_id = $pun_db->result($result);
       
   883 
       
   884 		if ($group_id < PUN_GUEST)
       
   885 		{
       
   886 			$result = $pun_db->query('SELECT id, moderators FROM '.$pun_db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
       
   887 
       
   888 			while ($cur_forum = $pun_db->fetch_assoc($result))
       
   889 			{
       
   890 				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
       
   891 
       
   892 				if (in_array($id, $cur_moderators))
       
   893 				{
       
   894 					unset($cur_moderators[$old_username]);
       
   895 					$cur_moderators[$form['username']] = $id;
       
   896 					ksort($cur_moderators);
       
   897 
       
   898 					$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());
       
   899 				}
       
   900 			}
       
   901 		}
       
   902 	}
       
   903 
       
   904 	pun_redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);
       
   905 }
       
   906 
       
   907 
       
   908 $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());
       
   909 if (!$pun_db->num_rows($result))
       
   910 	message($lang_common['Bad request']);
       
   911 
       
   912 $user = $pun_db->fetch_assoc($result);
       
   913 
       
   914 $last_post = format_time($user['last_post']);
       
   915 
       
   916 if ($user['signature'] != '')
       
   917 {
       
   918 	require PUN_ROOT.'include/parser.php';
       
   919 	$parsed_signature = parse_signature($user['signature']);
       
   920 }
       
   921 
       
   922 
       
   923 // View or edit?
       
   924 if ($pun_user['id'] != $id &&
       
   925 	($pun_user['g_id'] > USER_LEVEL_MOD ||
       
   926 	($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_edit_users'] == '0') ||
       
   927 	($pun_user['g_id'] == USER_LEVEL_MOD && $user['g_id'] < PUN_GUEST)))
       
   928 {
       
   929 	if ($user['email_setting'] == '0' && !$pun_user['is_guest'])
       
   930 		$email_field = '<a href="mailto:'.$user['email'].'">'.$user['email'].'</a>';
       
   931 	else if ($user['email_setting'] == '1' && !$pun_user['is_guest'])
       
   932 		$email_field = '<a href="misc.php?email='.$id.'">'.$lang_common['Send e-mail'].'</a>';
       
   933 	else
       
   934 		$email_field = $lang_profile['Private'];
       
   935 
       
   936 	$user_title_field = get_title($user);
       
   937 
       
   938 	if ($user['url'] != '')
       
   939 	{
       
   940 		$user['url'] = pun_htmlspecialchars($user['url']);
       
   941 
       
   942 		if ($pun_config['o_censoring'] == '1')
       
   943 			$user['url'] = censor_words($user['url']);
       
   944 
       
   945 		$url = '<a href="'.$user['url'].'">'.$user['url'].'</a>';
       
   946 	}
       
   947 	else
       
   948 		$url = $lang_profile['Unknown'];
       
   949 
       
   950 	if ($pun_config['o_avatars'] == '1')
       
   951 	{
       
   952 		if ($user['use_avatar'] == '1')
       
   953 		{
       
   954 			if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.gif'))
       
   955 				$avatar_field = '<img src="'.$pun_config['o_avatars_dir'].'/'.$id.'.gif" '.$img_size[3].' alt="" />';
       
   956 			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.jpg'))
       
   957 				$avatar_field = '<img src="'.$pun_config['o_avatars_dir'].'/'.$id.'.jpg" '.$img_size[3].' alt="" />';
       
   958 			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.png'))
       
   959 				$avatar_field = '<img src="'.$pun_config['o_avatars_dir'].'/'.$id.'.png" '.$img_size[3].' alt="" />';
       
   960 			else
       
   961 				$avatar_field = $lang_profile['No avatar'];
       
   962 		}
       
   963 		else
       
   964 			$avatar_field = $lang_profile['No avatar'];
       
   965 	}
       
   966 
       
   967 	$posts_field = '';
       
   968 	if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
   969 		$posts_field = $user['num_posts'];
       
   970 	if ($pun_user['g_search'] == '1')
       
   971 		$posts_field .= (($posts_field != '') ? ' - ' : '').'<a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a>';
       
   972 
       
   973 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
   974 	define('PUN_ALLOW_INDEX', 1);
       
   975 	require PUN_ROOT.'header.php';
       
   976 
       
   977 ?>
       
   978 <div id="viewprofile" class="block">
       
   979 	<h2><span><?php echo $lang_common['Profile'] ?></span></h2>
       
   980 	<div class="box">
       
   981 		<div class="fakeform">
       
   982 			<div class="inform">
       
   983 				<fieldset>
       
   984 				<legend><?php echo $lang_profile['Section personal'] ?></legend>
       
   985 					<div class="infldset">
       
   986 						<dl>
       
   987 							<dt><?php echo $lang_common['Username'] ?>: </dt>
       
   988 							<dd><?php echo pun_htmlspecialchars($user['username']) ?></dd>
       
   989 							<dt><?php echo $lang_common['Title'] ?>: </dt>
       
   990 							<dd><?php echo ($pun_config['o_censoring'] == '1') ? censor_words($user_title_field) : $user_title_field; ?></dd>
       
   991 							<dt><?php echo $lang_profile['Realname'] ?>: </dt>
       
   992 							<dd><?php echo ($user['realname'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['realname']) : $user['realname']) : $lang_profile['Unknown']; ?></dd>
       
   993 							<dt><?php echo $lang_profile['Location'] ?>: </dt>
       
   994 							<dd><?php echo ($user['location'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['location']) : $user['location']) : $lang_profile['Unknown']; ?></dd>
       
   995 							<dt><?php echo $lang_profile['Website'] ?>: </dt>
       
   996 							<dd><?php echo $url ?>&nbsp;</dd>
       
   997 							<dt><?php echo $lang_common['E-mail'] ?>: </dt>
       
   998 							<dd><?php echo $email_field ?></dd>
       
   999 						</dl>
       
  1000 						<div class="clearer"></div>
       
  1001 					</div>
       
  1002 				</fieldset>
       
  1003 			</div>
       
  1004 			<div class="inform">
       
  1005 				<fieldset>
       
  1006 				<legend><?php echo $lang_profile['Section messaging'] ?></legend>
       
  1007 					<div class="infldset">
       
  1008 						<dl>
       
  1009 							<dt><?php echo $lang_profile['Jabber'] ?>: </dt>
       
  1010 							<dd><?php echo ($user['jabber'] !='') ? pun_htmlspecialchars($user['jabber']) : $lang_profile['Unknown']; ?></dd>
       
  1011 							<dt><?php echo $lang_profile['ICQ'] ?>: </dt>
       
  1012 							<dd><?php echo ($user['icq'] !='') ? $user['icq'] : $lang_profile['Unknown']; ?></dd>
       
  1013 							<dt><?php echo $lang_profile['MSN'] ?>: </dt>
       
  1014 							<dd><?php echo ($user['msn'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['msn']) : $user['msn']) : $lang_profile['Unknown']; ?></dd>
       
  1015 							<dt><?php echo $lang_profile['AOL IM'] ?>: </dt>
       
  1016 							<dd><?php echo ($user['aim'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['aim']) : $user['aim']) : $lang_profile['Unknown']; ?></dd>
       
  1017 							<dt><?php echo $lang_profile['Yahoo'] ?>: </dt>
       
  1018 							<dd><?php echo ($user['yahoo'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['yahoo']) : $user['yahoo']) : $lang_profile['Unknown']; ?></dd>
       
  1019 						</dl>
       
  1020 						<div class="clearer"></div>
       
  1021 					</div>
       
  1022 				</fieldset>
       
  1023 			</div>
       
  1024 			<div class="inform">
       
  1025 				<fieldset>
       
  1026 				<legend><?php echo $lang_profile['Section personality'] ?></legend>
       
  1027 					<div class="infldset">
       
  1028 						<dl>
       
  1029 <?php if ($pun_config['o_avatars'] == '1'): ?>							<dt><?php echo $lang_profile['Avatar'] ?>: </dt>
       
  1030 							<dd><?php echo $avatar_field ?></dd>
       
  1031 <?php endif; ?>							<dt><?php echo $lang_profile['Signature'] ?>: </dt>
       
  1032 							<dd><div><?php echo isset($parsed_signature) ? $parsed_signature : $lang_profile['No sig']; ?></div></dd>
       
  1033 						</dl>
       
  1034 						<div class="clearer"></div>
       
  1035 					</div>
       
  1036 				</fieldset>
       
  1037 			</div>
       
  1038 			<div class="inform">
       
  1039 				<fieldset>
       
  1040 				<legend><?php echo $lang_profile['User activity'] ?></legend>
       
  1041 					<div class="infldset">
       
  1042 						<dl>
       
  1043 <?php if ($posts_field != ''): ?>							<dt><?php echo $lang_common['Posts'] ?>: </dt>
       
  1044 							<dd><?php echo $posts_field ?></dd>
       
  1045 <?php endif; ?>							<dt><?php echo $lang_common['Last post'] ?>: </dt>
       
  1046 							<dd><?php echo $last_post ?></dd>
       
  1047 							<dt><?php echo $lang_common['Registered'] ?>: </dt>
       
  1048 							<dd><?php echo format_time($user['registered'], true) ?></dd>
       
  1049 						</dl>
       
  1050 						<div class="clearer"></div>
       
  1051 					</div>
       
  1052 				</fieldset>
       
  1053 			</div>
       
  1054 		</div>
       
  1055 	</div>
       
  1056 </div>
       
  1057 
       
  1058 <?php
       
  1059 
       
  1060 	require PUN_ROOT.'footer.php';
       
  1061 }
       
  1062 else
       
  1063 {
       
  1064 	if (!$section || $section == 'essentials')
       
  1065 	{
       
  1066 		if ($pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
  1067 		{
       
  1068 			if ( false ) // NO RENAMING IN ENANO // ($pun_user['g_id'] == USER_LEVEL_ADMIN || $pun_config['p_mod_rename_users'] == '1')
       
  1069 				$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";
       
  1070 			else
       
  1071 				$username_field = '<p>'.$lang_common['Username'].': '.pun_htmlspecialchars($user['username']).'</p>'."\n";
       
  1072 
       
  1073 			$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><p><a href="misc.php?email='.$id.'">'.$lang_common['Send e-mail'].'</a></p>'."\n";
       
  1074 		}
       
  1075 		else
       
  1076 		{
       
  1077 			$username_field = '<p>'.$lang_common['Username'].': '.pun_htmlspecialchars($user['username']).'</p>'."\n";
       
  1078 
       
  1079 			if ($pun_config['o_regs_verify'] == '1')
       
  1080 				$email_field = '<p>'.$lang_common['E-mail'].': '.$user['email'].'&nbsp;-&nbsp;<a href="profile.php?action=change_email&amp;id='.$id.'">'.$lang_profile['Change e-mail'].'</a></p>'."\n";
       
  1081 			else
       
  1082 				$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";
       
  1083 		}
       
  1084 
       
  1085 		if ($pun_user['g_id'] == USER_LEVEL_ADMIN)
       
  1086     {
       
  1087 			$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";
       
  1088     }
       
  1089 		else if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] >= USER_LEVEL_MEMBER)
       
  1090     {
       
  1091 			$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";
       
  1092     }
       
  1093 		else
       
  1094     {
       
  1095 			$posts_field = '<p><a href="search.php?action=show_user&amp;user_id='.$id.'">'.$lang_profile['Show posts'].'</a></p>'."\n";
       
  1096     }
       
  1097 
       
  1098 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1099 		$GLOBALS['required_fields'] = array('req_username' => $lang_common['Username']);
       
  1100 		require PUN_ROOT.'header.php';
       
  1101 
       
  1102 		generate_profile_menu('essentials');
       
  1103 
       
  1104 ?>
       
  1105 	<div class="blockform">
       
  1106 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section essentials'] ?></span></h2>
       
  1107 		<div class="box">
       
  1108 			<form id="profile1" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=essentials&id=' . $id . '', true); ?>" onsubmit="return process_form(this)">
       
  1109 				<div class="inform">
       
  1110 					<fieldset>
       
  1111 						<legend><?php echo $lang_profile['Username and pass legend'] ?></legend>
       
  1112 						<div class="infldset">
       
  1113 							<input type="hidden" name="form_sent" value="1" />
       
  1114 							<?php echo $username_field ?>
       
  1115 <?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>
       
  1116 <?php endif;  */?>					</div>
       
  1117 					</fieldset>
       
  1118 				</div>
       
  1119 				<div class="inform">
       
  1120 					<fieldset>
       
  1121 						<legend><?php echo $lang_prof_reg['Localisation legend'] ?></legend>
       
  1122 						<div class="infldset">
       
  1123 							<label><?php echo $lang_prof_reg['Timezone'] ?>: <?php echo $lang_prof_reg['Timezone info'] ?>
       
  1124 							<br /><select name="form[timezone]">
       
  1125 								<option value="-12"<?php if ($user['timezone'] == -12) echo ' selected="selected"' ?>>-12</option>
       
  1126 								<option value="-11"<?php if ($user['timezone'] == -11) echo ' selected="selected"' ?>>-11</option>
       
  1127 								<option value="-10"<?php if ($user['timezone'] == -10) echo ' selected="selected"' ?>>-10</option>
       
  1128 								<option value="-9.5"<?php if ($user['timezone'] == -9.5) echo ' selected="selected"' ?>>-09.5</option>
       
  1129 								<option value="-9"<?php if ($user['timezone'] == -9) echo ' selected="selected"' ?>>-09</option>
       
  1130 								<option value="-8.5"<?php if ($user['timezone'] == -8.5) echo ' selected="selected"' ?>>-08.5</option>
       
  1131 								<option value="-8"<?php if ($user['timezone'] == -8) echo ' selected="selected"' ?>>-08 PST</option>
       
  1132 								<option value="-7"<?php if ($user['timezone'] == -7) echo ' selected="selected"' ?>>-07 MST</option>
       
  1133 								<option value="-6"<?php if ($user['timezone'] == -6) echo ' selected="selected"' ?>>-06 CST</option>
       
  1134 								<option value="-5"<?php if ($user['timezone'] == -5) echo ' selected="selected"' ?>>-05 EST</option>
       
  1135 								<option value="-4"<?php if ($user['timezone'] == -4) echo ' selected="selected"' ?>>-04 AST</option>
       
  1136 								<option value="-3.5"<?php if ($user['timezone'] == -3.5) echo ' selected="selected"' ?>>-03.5</option>
       
  1137 								<option value="-3"<?php if ($user['timezone'] == -3) echo ' selected="selected"' ?>>-03 ADT</option>
       
  1138 								<option value="-2"<?php if ($user['timezone'] == -2) echo ' selected="selected"' ?>>-02</option>
       
  1139 								<option value="-1"<?php if ($user['timezone'] == -1) echo ' selected="selected"' ?>>-01</option>
       
  1140 								<option value="0"<?php if ($user['timezone'] == 0) echo ' selected="selected"' ?>>00 GMT</option>
       
  1141 								<option value="1"<?php if ($user['timezone'] == 1) echo ' selected="selected"' ?>>+01 CET</option>
       
  1142 								<option value="2"<?php if ($user['timezone'] == 2) echo ' selected="selected"' ?>>+02</option>
       
  1143 								<option value="3"<?php if ($user['timezone'] == 3) echo ' selected="selected"' ?>>+03</option>
       
  1144 								<option value="3.5"<?php if ($user['timezone'] == 3.5) echo ' selected="selected"' ?>>+03.5</option>
       
  1145 								<option value="4"<?php if ($user['timezone'] == 4) echo ' selected="selected"' ?>>+04</option>
       
  1146 								<option value="4.5"<?php if ($user['timezone'] == 4.5) echo ' selected="selected"' ?>>+04.5</option>
       
  1147 								<option value="5"<?php if ($user['timezone'] == 5) echo ' selected="selected"' ?>>+05</option>
       
  1148 								<option value="5.5"<?php if ($user['timezone'] == 5.5) echo ' selected="selected"' ?>>+05.5</option>
       
  1149 								<option value="6"<?php if ($user['timezone'] == 6) echo ' selected="selected"' ?>>+06</option>
       
  1150 								<option value="6.5"<?php if ($user['timezone'] == 6.5) echo ' selected="selected"' ?>>+06.5</option>
       
  1151 								<option value="7"<?php if ($user['timezone'] == 7) echo ' selected="selected"' ?>>+07</option>
       
  1152 								<option value="8"<?php if ($user['timezone'] == 8) echo ' selected="selected"' ?>>+08</option>
       
  1153 								<option value="9"<?php if ($user['timezone'] == 9) echo ' selected="selected"' ?>>+09</option>
       
  1154 								<option value="9.5"<?php if ($user['timezone'] == 9.5) echo ' selected="selected"' ?>>+09.5</option>
       
  1155 								<option value="10"<?php if ($user['timezone'] == 10) echo ' selected="selected"' ?>>+10</option>
       
  1156 								<option value="10.5"<?php if ($user['timezone'] == 10.5) echo ' selected="selected"' ?>>+10.5</option>
       
  1157 								<option value="11"<?php if ($user['timezone'] == 11) echo ' selected="selected"' ?>>+11</option>
       
  1158 								<option value="11.5"<?php if ($user['timezone'] == 11.5) echo ' selected="selected"' ?>>+11.5</option>
       
  1159 								<option value="12"<?php if ($user['timezone'] == 12) echo ' selected="selected"' ?>>+12</option>
       
  1160 								<option value="13"<?php if ($user['timezone'] == 13) echo ' selected="selected"' ?>>+13</option>
       
  1161 								<option value="14"<?php if ($user['timezone'] == 14) echo ' selected="selected"' ?>>+14</option>
       
  1162 							</select>
       
  1163 							<br /></label>
       
  1164 <?php
       
  1165 
       
  1166 		$languages = array();
       
  1167 		$d = dir(PUN_ROOT.'lang');
       
  1168 		while (($entry = $d->read()) !== false)
       
  1169 		{
       
  1170 			if ($entry != '.' && $entry != '..' && is_dir(PUN_ROOT.'lang/'.$entry) && file_exists(PUN_ROOT.'lang/'.$entry.'/common.php'))
       
  1171 				$languages[] = $entry;
       
  1172 		}
       
  1173 		$d->close();
       
  1174 
       
  1175 		// Only display the language selection box if there's more than one language available
       
  1176 		if (count($languages) > 1)
       
  1177 		{
       
  1178 			natsort($languages);
       
  1179 
       
  1180 ?>
       
  1181 							<label><?php echo $lang_prof_reg['Language'] ?>: <?php echo $lang_prof_reg['Language info'] ?>
       
  1182 							<br /><select name="form[language]">
       
  1183 <?php
       
  1184 
       
  1185 			while (list(, $temp) = @each($languages))
       
  1186 			{
       
  1187 				if ($user['language'] == $temp)
       
  1188 					echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$temp.'</option>'."\n";
       
  1189 				else
       
  1190 					echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$temp.'</option>'."\n";
       
  1191 			}
       
  1192 
       
  1193 ?>
       
  1194 							</select>
       
  1195 							<br /></label>
       
  1196 <?php
       
  1197 
       
  1198 		}
       
  1199 
       
  1200 ?>
       
  1201 						</div>
       
  1202 					</fieldset>
       
  1203 				</div>
       
  1204 				<div class="inform">
       
  1205 					<fieldset>
       
  1206 						<legend><?php echo $lang_profile['User activity'] ?></legend>
       
  1207 						<div class="infldset">
       
  1208 							<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>
       
  1209 							<p><?php echo $lang_common['Last post'] ?>: <?php echo $last_post ?></p>
       
  1210 								<?php echo $posts_field ?>
       
  1211 <?php if ($pun_user['g_id'] >= USER_LEVEL_MEMBER): ?>							<label><?php echo $lang_profile['Admin note'] ?><br />
       
  1212 							<input id="admin_note" type="text" name="admin_note" value="<?php echo pun_htmlspecialchars($user['admin_note']) ?>" size="30" maxlength="30" /><br /></label>
       
  1213 						</div>
       
  1214 <?php endif; ?>					</fieldset>
       
  1215 				</div>
       
  1216 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
       
  1217 			</form>
       
  1218 		</div>
       
  1219 	</div>
       
  1220 <?php
       
  1221 
       
  1222 	}
       
  1223 	else if ($section == 'personal')
       
  1224 	{
       
  1225 		if ($pun_user['g_set_title'] == '1')
       
  1226 			$title_field = '<label>'.$lang_common['Title'].'&nbsp;&nbsp;(<em>'.$lang_profile['Leave blank'].'</em>)<br /><input type="text" name="title" value="'.pun_htmlspecialchars($user['title']).'" size="30" maxlength="50" /><br /></label>'."\n";
       
  1227 
       
  1228 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1229 		require PUN_ROOT.'header.php';
       
  1230 
       
  1231 		generate_profile_menu('personal');
       
  1232 
       
  1233 ?>
       
  1234 	<div class="blockform">
       
  1235 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section personal'] ?></span></h2>
       
  1236 		<div class="box">
       
  1237 			<form id="profile2" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=personal&id=' . $id . '', true); ?>">
       
  1238 				<div class="inform">
       
  1239 					<fieldset>
       
  1240 						<legend><?php echo $lang_profile['Personal details legend'] ?></legend>
       
  1241 						<div class="infldset">
       
  1242 							<input type="hidden" name="form_sent" value="1" />
       
  1243 							<label><?php echo $lang_profile['Realname'] ?><br /><input type="text" name="form[realname]" value="<?php echo pun_htmlspecialchars($user['realname']) ?>" size="40" maxlength="40" /><br /></label>
       
  1244 <?php if (isset($title_field)): ?>					<?php echo $title_field ?>
       
  1245 <?php endif; ?>							<label><?php echo $lang_profile['Location'] ?><br /><input type="text" name="form[location]" value="<?php echo pun_htmlspecialchars($user['location']) ?>" size="30" maxlength="30" /><br /></label>
       
  1246 							<label><?php echo $lang_profile['Website'] ?><br /><input type="text" name="form[url]" value="<?php echo pun_htmlspecialchars($user['url']) ?>" size="50" maxlength="80" /><br /></label>
       
  1247 						</div>
       
  1248 					</fieldset>
       
  1249 				</div>
       
  1250 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
       
  1251 			</form>
       
  1252 		</div>
       
  1253 	</div>
       
  1254 <?php
       
  1255 
       
  1256 	}
       
  1257 	else if ($section == 'messaging')
       
  1258 	{
       
  1259 
       
  1260 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1261 		require PUN_ROOT.'header.php';
       
  1262 
       
  1263 		generate_profile_menu('messaging');
       
  1264 
       
  1265 ?>
       
  1266 	<div class="blockform">
       
  1267 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section messaging'] ?></span></h2>
       
  1268 		<div class="box">
       
  1269 			<form id="profile3" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=messaging&id=' . $id . '', true); ?>">
       
  1270 				<div class="inform">
       
  1271 					<fieldset>
       
  1272 						<legend><?php echo $lang_profile['Contact details legend'] ?></legend>
       
  1273 						<div class="infldset">
       
  1274 							<input type="hidden" name="form_sent" value="1" />
       
  1275 							<label><?php echo $lang_profile['Jabber'] ?><br /><input id="jabber" type="text" name="form[jabber]" value="<?php echo pun_htmlspecialchars($user['jabber']) ?>" size="40" maxlength="75" /><br /></label>
       
  1276 							<label><?php echo $lang_profile['ICQ'] ?><br /><input id="icq" type="text" name="form[icq]" value="<?php echo $user['icq'] ?>" size="12" maxlength="12" /><br /></label>
       
  1277 							<label><?php echo $lang_profile['MSN'] ?><br /><input id="msn" type="text" name="form[msn]" value="<?php echo pun_htmlspecialchars($user['msn']) ?>" size="40" maxlength="50" /><br /></label>
       
  1278 							<label><?php echo $lang_profile['AOL IM'] ?><br /><input id="aim" type="text" name="form[aim]" value="<?php echo pun_htmlspecialchars($user['aim']) ?>" size="20" maxlength="30" /><br /></label>
       
  1279 							<label><?php echo $lang_profile['Yahoo'] ?><br /><input id="yahoo" type="text" name="form[yahoo]" value="<?php echo pun_htmlspecialchars($user['yahoo']) ?>" size="20" maxlength="30" /><br /></label>
       
  1280 						</div>
       
  1281 					</fieldset>
       
  1282 				</div>
       
  1283 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
       
  1284 			</form>
       
  1285 		</div>
       
  1286 	</div>
       
  1287 <?php
       
  1288 
       
  1289 	}
       
  1290 	else if ($section == 'personality')
       
  1291 	{
       
  1292 		$avatar_field = '<a href="profile.php?action=upload_avatar&amp;id='.$id.'">'.$lang_profile['Change avatar'].'</a>';
       
  1293 		if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.gif'))
       
  1294 			$avatar_format = 'gif';
       
  1295 		else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.jpg'))
       
  1296 			$avatar_format = 'jpg';
       
  1297 		else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.png'))
       
  1298 			$avatar_format = 'png';
       
  1299 		else
       
  1300 			$avatar_field = '<a href="profile.php?action=upload_avatar&amp;id='.$id.'">'.$lang_profile['Upload avatar'].'</a>';
       
  1301 
       
  1302 		// Display the delete avatar link?
       
  1303 		if ($img_size)
       
  1304 			$avatar_field .= '&nbsp;&nbsp;&nbsp;<a href="profile.php?action=delete_avatar&amp;id='.$id.'">'.$lang_profile['Delete avatar'].'</a>';
       
  1305 
       
  1306 		if ($user['signature'] != '')
       
  1307 			$signature_preview = '<p>'.$lang_profile['Sig preview'].'</p>'."\n\t\t\t\t\t".'<div class="postsignature">'."\n\t\t\t\t\t\t".'<hr />'."\n\t\t\t\t\t\t".$parsed_signature."\n\t\t\t\t\t".'</div>'."\n";
       
  1308 		else
       
  1309 			$signature_preview = '<p>'.$lang_profile['No sig'].'</p>'."\n";
       
  1310 
       
  1311 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1312 		require PUN_ROOT.'header.php';
       
  1313 
       
  1314 		generate_profile_menu('personality');
       
  1315 
       
  1316 
       
  1317 ?>
       
  1318 	<div class="blockform">
       
  1319 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section personality'] ?></span></h2>
       
  1320 		<div class="box">
       
  1321 			<form id="profile4" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=personality&id=' . $id . '', true); ?>">
       
  1322 				<div><input type="hidden" name="form_sent" value="1" /></div>
       
  1323 <?php if ($pun_config['o_avatars'] == '1'): ?>				<div class="inform">
       
  1324 					<fieldset id="profileavatar">
       
  1325 						<legend><?php echo $lang_profile['Avatar legend'] ?></legend>
       
  1326 						<div class="infldset">
       
  1327 <?php if (isset($avatar_format)): ?>					<img src="<?php echo $pun_config['o_avatars_dir'].'/'.$id.'.'.$avatar_format ?>" <?php echo $img_size[3] ?> alt="" />
       
  1328 <?php endif; ?>					<p><?php echo $lang_profile['Avatar info'] ?></p>
       
  1329 							<div class="rbox">
       
  1330 								<label><input type="checkbox" name="form[use_avatar]" value="1"<?php if ($user['use_avatar'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Use avatar'] ?><br /></label>
       
  1331 							</div>
       
  1332 							<p class="clearb"><?php echo $avatar_field ?></p>
       
  1333 						</div>
       
  1334 					</fieldset>
       
  1335 				</div>
       
  1336 <?php endif; ?>				<div class="inform">
       
  1337 					<fieldset>
       
  1338 						<legend><?php echo $lang_profile['Signature legend'] ?></legend>
       
  1339 						<div class="infldset">
       
  1340 							<p><?php echo $lang_profile['Signature info'] ?></p>
       
  1341 							<div class="txtarea">
       
  1342 								<label><?php echo $lang_profile['Sig max length'] ?>: <?php echo $pun_config['p_sig_length'] ?> / <?php echo $lang_profile['Sig max lines'] ?>: <?php echo $pun_config['p_sig_lines'] ?><br />
       
  1343 								<textarea name="signature" rows="4" cols="65"><?php echo pun_htmlspecialchars($user['signature']) ?></textarea><br /></label>
       
  1344 							</div>
       
  1345 							<ul class="bblinks">
       
  1346 								<li><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a>: <?php echo ($pun_config['p_sig_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
       
  1347 								<li><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a>: <?php echo ($pun_config['p_sig_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
       
  1348 								<li><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a>: <?php echo ($pun_config['o_smilies_sig'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
       
  1349 							</ul>
       
  1350 							<?php echo $signature_preview ?>
       
  1351 						</div>
       
  1352 					</fieldset>
       
  1353 				</div>
       
  1354 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
       
  1355 			</form>
       
  1356 		</div>
       
  1357 	</div>
       
  1358 <?php
       
  1359 
       
  1360 	}
       
  1361 	else if ($section == 'display')
       
  1362 	{
       
  1363 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1364 		require PUN_ROOT.'header.php';
       
  1365 
       
  1366 		generate_profile_menu('display');
       
  1367 
       
  1368 ?>
       
  1369 	<div class="blockform">
       
  1370 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section display'] ?></span></h2>
       
  1371 		<div class="box">
       
  1372 			<form id="profile5" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=display&id=' . $id . '', true); ?>">
       
  1373 				<div><input type="hidden" name="form_sent" value="1" /></div>
       
  1374 <?php
       
  1375 
       
  1376 		$styles = array();
       
  1377 		$d = dir(PUN_ROOT.'style');
       
  1378 		while (($entry = $d->read()) !== false)
       
  1379 		{
       
  1380 			if (substr($entry, strlen($entry)-4) == '.css')
       
  1381 				$styles[] = substr($entry, 0, strlen($entry)-4);
       
  1382 		}
       
  1383 		$d->close();
       
  1384 
       
  1385 		// Only display the style selection box if there's more than one style available
       
  1386 		if (count($styles) == 1)
       
  1387 			echo "\t\t\t".'<div><input type="hidden" name="form[style]" value="'.$styles[0].'" /></div>'."\n";
       
  1388 		else if (count($styles) > 1)
       
  1389 		{
       
  1390 			natsort($styles);
       
  1391 
       
  1392 ?>
       
  1393 				<div class="inform">
       
  1394 					<fieldset>
       
  1395 						<legend><?php echo $lang_profile['Style legend'] ?></legend>
       
  1396 						<div class="infldset">
       
  1397 							<label><?php echo $lang_profile['Style info'] ?><br />
       
  1398 
       
  1399 							<select name="form[style]">
       
  1400 <?php
       
  1401 
       
  1402 			while (list(, $temp) = @each($styles))
       
  1403 			{
       
  1404 				if ($user['style'] == $temp)
       
  1405 					echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
       
  1406 				else
       
  1407 					echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
       
  1408 			}
       
  1409 
       
  1410 ?>
       
  1411 							</select>
       
  1412 							<br /></label>
       
  1413 						</div>
       
  1414 					</fieldset>
       
  1415 				</div>
       
  1416 <?php
       
  1417 
       
  1418 		}
       
  1419 
       
  1420 ?>
       
  1421 				<div class="inform">
       
  1422 					<fieldset>
       
  1423 						<legend><?php echo $lang_profile['Post display legend'] ?></legend>
       
  1424 						<div class="infldset">
       
  1425 							<p><?php echo $lang_profile['Post display info'] ?></p>
       
  1426 							<div class="rbox">
       
  1427 								<label><input type="checkbox" name="form[show_smilies]" value="1"<?php if ($user['show_smilies'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Show smilies'] ?><br /></label>
       
  1428 								<label><input type="checkbox" name="form[show_sig]" value="1"<?php if ($user['show_sig'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Show sigs'] ?><br /></label>
       
  1429 <?php if ($pun_config['o_avatars'] == '1'): ?>							<label><input type="checkbox" name="form[show_avatars]" value="1"<?php if ($user['show_avatars'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Show avatars'] ?><br /></label>
       
  1430 <?php endif; ?>								<label><input type="checkbox" name="form[show_img]" value="1"<?php if ($user['show_img'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Show images'] ?><br /></label>
       
  1431 								<label><input type="checkbox" name="form[show_img_sig]" value="1"<?php if ($user['show_img_sig'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Show images sigs'] ?><br /></label>
       
  1432 							</div>
       
  1433 						</div>
       
  1434 					</fieldset>
       
  1435 				</div>
       
  1436 				<div class="inform">
       
  1437 					<fieldset>
       
  1438 						<legend><?php echo $lang_profile['Pagination legend'] ?></legend>
       
  1439 						<div class="infldset">
       
  1440 							<label class="conl"><?php echo $lang_profile['Topics per page'] ?><br /><input type="text" name="form[disp_topics]" value="<?php echo $user['disp_topics'] ?>" size="6" maxlength="3" /><br /></label>
       
  1441 							<label class="conl"><?php echo $lang_profile['Posts per page'] ?><br /><input type="text" name="form[disp_posts]" value="<?php echo $user['disp_posts'] ?>" size="6" maxlength="3" /><br /></label>
       
  1442 							<p class="clearb"><?php echo $lang_profile['Paginate info'] ?> <?php echo $lang_profile['Leave blank'] ?></p>
       
  1443 						</div>
       
  1444 					</fieldset>
       
  1445 				</div>
       
  1446 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" />  <?php echo $lang_profile['Instructions'] ?></p>
       
  1447 			</form>
       
  1448 		</div>
       
  1449 	</div>
       
  1450 <?php
       
  1451 
       
  1452 	}
       
  1453 	else if ($section == 'privacy')
       
  1454 	{
       
  1455 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1456 		require PUN_ROOT.'header.php';
       
  1457 
       
  1458 		generate_profile_menu('privacy');
       
  1459 
       
  1460 ?>
       
  1461 	<div class="blockform">
       
  1462 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section privacy'] ?></span></h2>
       
  1463 		<div class="box">
       
  1464 			<form id="profile6" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=privacy&id=' . $id . '', true); ?>">
       
  1465 				<div class="inform">
       
  1466 					<fieldset>
       
  1467 						<legend><?php echo $lang_prof_reg['Privacy options legend'] ?></legend>
       
  1468 						<div class="infldset">
       
  1469 							<input type="hidden" name="form_sent" value="1" />
       
  1470 							<p><?php echo $lang_prof_reg['E-mail setting info'] ?></p>
       
  1471 							<div class="rbox">
       
  1472 								<label><input type="radio" name="form[email_setting]" value="0"<?php if ($user['email_setting'] == '0') echo ' checked="checked"' ?> /><?php echo $lang_prof_reg['E-mail setting 1'] ?><br /></label>
       
  1473 								<label><input type="radio" name="form[email_setting]" value="1"<?php if ($user['email_setting'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_prof_reg['E-mail setting 2'] ?><br /></label>
       
  1474 								<label><input type="radio" name="form[email_setting]" value="2"<?php if ($user['email_setting'] == '2') echo ' checked="checked"' ?> /><?php echo $lang_prof_reg['E-mail setting 3'] ?><br /></label>
       
  1475 							</div>
       
  1476 							<p><?php echo $lang_prof_reg['Save user/pass info'] ?></p>
       
  1477 							<div class="rbox">
       
  1478 								<label><input type="checkbox" name="form[save_pass]" value="1"<?php if ($user['save_pass'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_prof_reg['Save user/pass'] ?><br /></label>
       
  1479 							</div>
       
  1480 							<p><?php echo $lang_profile['Notify full info'] ?></p>
       
  1481 							<div class="rbox">
       
  1482 								<label><input type="checkbox" name="form[notify_with_post]" value="1"<?php if ($user['notify_with_post'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['Notify full'] ?><br /></label>
       
  1483 							</div>
       
  1484 						</div>
       
  1485 					</fieldset>
       
  1486 				</div>
       
  1487 				<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
       
  1488 			</form>
       
  1489 		</div>
       
  1490 	</div>
       
  1491 <?php
       
  1492 
       
  1493 	}
       
  1494 	else if ($section == 'admin')
       
  1495 	{
       
  1496 		if ($pun_user['g_id'] < USER_LEVEL_MOD || ($pun_user['g_id'] == USER_LEVEL_MOD && $pun_config['p_mod_ban_users'] == '0'))
       
  1497 			message($lang_common['Bad request']);
       
  1498 
       
  1499 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
       
  1500 		require PUN_ROOT.'header.php';
       
  1501 
       
  1502 		generate_profile_menu('admin');
       
  1503 
       
  1504 ?>
       
  1505 	<div class="blockform">
       
  1506 		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section admin'] ?></span></h2>
       
  1507 		<div class="box">
       
  1508 			<form id="profile7" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Profile', 'section=admin&id=' . $id . '&action=foo', true); ?>">
       
  1509 				<div class="inform">
       
  1510 				<input type="hidden" name="form_sent" value="1" />
       
  1511 					<fieldset>
       
  1512 <?php
       
  1513 
       
  1514 		if ($pun_user['g_id'] == USER_LEVEL_MOD)
       
  1515 		{
       
  1516 
       
  1517 ?>
       
  1518 						<legend><?php echo $lang_profile['Delete ban legend'] ?></legend>
       
  1519 						<div class="infldset">
       
  1520 							<p><input type="submit" name="ban" value="<?php echo $lang_profile['Ban user'] ?>" /></p>
       
  1521 						</div>
       
  1522 					</fieldset>
       
  1523 				</div>
       
  1524 <?php
       
  1525 
       
  1526 		}
       
  1527 		else
       
  1528 		{
       
  1529 			if ($pun_user['id'] != $id)
       
  1530 			{
       
  1531 
       
  1532 ?>
       
  1533 						<legend><?php echo $lang_profile['Group membership legend'] ?></legend>
       
  1534 						<div class="infldset">
       
  1535 							<select id="group_id" name="group_id">
       
  1536 <?php
       
  1537 
       
  1538 				$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());
       
  1539 
       
  1540 				while ($cur_group = $pun_db->fetch_assoc($result))
       
  1541 				{
       
  1542 					if ($cur_group['g_id'] == $user['g_id'] || ($cur_group['g_id'] == $pun_config['o_default_user_group'] && $user['g_id'] == ''))
       
  1543 						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";
       
  1544 					else
       
  1545 						echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
       
  1546 				}
       
  1547 
       
  1548 ?>
       
  1549 							</select>
       
  1550 							<input type="submit" name="update_group_membership" value="<?php echo $lang_profile['Save'] ?>" />
       
  1551 						</div>
       
  1552 					</fieldset>
       
  1553 				</div>
       
  1554 				<div class="inform">
       
  1555 					<fieldset>
       
  1556 <?php
       
  1557 
       
  1558 			}
       
  1559 
       
  1560 ?>
       
  1561 						<legend><?php echo $lang_profile['Delete ban legend'] ?></legend>
       
  1562 						<div class="infldset">
       
  1563 							<input type="submit" name="delete_user" value="<?php echo $lang_profile['Delete user'] ?>" />&nbsp;&nbsp;<input type="submit" name="ban" value="<?php echo $lang_profile['Ban user'] ?>" />
       
  1564 						</div>
       
  1565 					</fieldset>
       
  1566 				</div>
       
  1567 <?php
       
  1568 
       
  1569 			if ($user['g_id'] == PUN_MOD || $user['g_id'] == PUN_ADMIN)
       
  1570 			{
       
  1571 
       
  1572 ?>
       
  1573 				<div class="inform">
       
  1574 					<fieldset>
       
  1575 						<legend><?php echo $lang_profile['Set mods legend'] ?></legend>
       
  1576 						<div class="infldset">
       
  1577 							<p><?php echo $lang_profile['Moderator in info'] ?></p>
       
  1578 <?php
       
  1579 
       
  1580 				$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());
       
  1581 
       
  1582 				$cur_category = 0;
       
  1583 				while ($cur_forum = $pun_db->fetch_assoc($result))
       
  1584 				{
       
  1585 					if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
       
  1586 					{
       
  1587 						if ($cur_category)
       
  1588 							echo "\n\t\t\t\t\t\t\t\t".'</div>';
       
  1589 
       
  1590 						if ($cur_category != 0)
       
  1591 							echo "\n\t\t\t\t\t\t\t".'</div>'."\n";
       
  1592 
       
  1593 						echo "\t\t\t\t\t\t\t".'<div class="conl">'."\n\t\t\t\t\t\t\t\t".'<p><strong>'.$cur_forum['cat_name'].'</strong></p>'."\n\t\t\t\t\t\t\t\t".'<div class="rbox">';
       
  1594 						$cur_category = $cur_forum['cid'];
       
  1595 					}
       
  1596 
       
  1597 					$moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
       
  1598 
       
  1599 					echo "\n\t\t\t\t\t\t\t\t\t".'<label><input type="checkbox" name="moderator_in['.$cur_forum['fid'].']" value="1"'.((in_array($id, $moderators)) ? ' checked="checked"' : '').' />'.pun_htmlspecialchars($cur_forum['forum_name']).'<br /></label>'."\n";
       
  1600 				}
       
  1601 
       
  1602 ?>
       
  1603 								</div>
       
  1604 							</div>
       
  1605 							<br class="clearb" /><input type="submit" name="update_forums" value="<?php echo $lang_profile['Update forums'] ?>" />
       
  1606 						</div>
       
  1607 					</fieldset>
       
  1608 				</div>
       
  1609 <?php
       
  1610 
       
  1611 			}
       
  1612 		}
       
  1613 
       
  1614 ?>
       
  1615 			</form>
       
  1616 		</div>
       
  1617 	</div>
       
  1618 <?php
       
  1619 
       
  1620 	}
       
  1621 
       
  1622 ?>
       
  1623 	<div class="clearer"></div>
       
  1624 </div>
       
  1625 <?php
       
  1626 
       
  1627 	require PUN_ROOT.'footer.php';
       
  1628 }