PageRenderTime 241ms CodeModel.GetById 198ms app.highlight 6ms RepoModel.GetById 29ms app.codeStats 0ms

/other/punbb-modified-forum/profile.php

https://bitbucket.org/Balancer/projects-balancer
PHP | 1629 lines | 1334 code | 212 blank | 83 comment | 419 complexity | 91b60f5e856ba7ef09b55eee0e6e9696 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2//if(1 || !empty($_POST['form'])) { echo "<xmp>"; print_r($_POST); print_r($_GET); print_r($_FILES); echo "</xmp>"; exit(); }
   3/***********************************************************************
   4
   5  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
   6
   7  This file is part of PunBB.
   8
   9  PunBB is free software; you can redistribute it and/or modify it
  10  under the terms of the GNU General Public License as published
  11  by the Free Software Foundation; either version 2 of the License,
  12  or (at your option) any later version.
  13
  14  PunBB is distributed in the hope that it will be useful, but
  15  WITHOUT ANY WARRANTY; without even the implied warranty of
  16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  GNU General Public License for more details.
  18
  19  You should have received a copy of the GNU General Public License
  20  along with this program; if not, write to the Free Software
  21  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22  MA  02111-1307  USA
  23
  24************************************************************************/
  25
  26define('PUN_ROOT', dirname(__FILE__).'/');
  27require PUN_ROOT.'include/common.php';
  28
  29if($_SERVER['HTTP_HOST'] != 'www.balancer.ru' || !preg_match('!^/forum/punbb/!', $_SERVER['REQUEST_URI']))
  30{
  31	include_once('inc/navigation.php');
  32	go("http://www.balancer.ru/forum/punbb/profile.php" . (empty($_SERVER['QUERY_STRING']) ? "" : "?".$_SERVER['QUERY_STRING']), true);
  33	exit("Redirected");
  34}
  35
  36$action = isset($_GET['action']) ? $_GET['action'] : null;
  37$section = isset($_GET['section']) ? $_GET['section'] : null;
  38$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  39if ($id < 2)
  40	message($lang_common['Bad request']);
  41
  42if ($pun_user['g_read_board'] == '0' && ($action != 'change_pass' || !isset($_GET['key'])))
  43	message($lang_common['No view']);
  44
  45// Load the profile.php/register.php language file
  46require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
  47
  48// Load the profile.php language file
  49require PUN_ROOT.'lang/'.$pun_user['language'].'/profile.php';
  50
  51if ($action == 'change_pass')
  52{
  53	if (isset($_GET['key']))
  54	{
  55		// If the user is already logged in we shouldn't be here :)
  56		if (!$pun_user['is_guest'])
  57		{
  58			header('Location: index.php');
  59			exit;
  60		}
  61
  62		$key = $_GET['key'];
  63
  64		$user = bors_find_first('airbase_user', array('activate_key' => $key));
  65
  66		if(!$key || !$user)
  67			message($lang_profile['Pass key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
  68
  69		$user->set_password_hash_new($user->activate_string());
  70
  71		message($lang_profile['Pass updated'], true);
  72	}
  73
  74	// Make sure we are allowed to change this users password
  75	if ($pun_user['id'] != $id)
  76	{
  77		if ($pun_user['g_id'] > PUN_MOD)	// A regular user trying to change another users password?
  78			message($lang_common['No permission']);
  79		else if ($pun_user['g_id'] == PUN_MOD)	// A moderator trying to change a users password?
  80		{
  81			$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  82			if (!$db->num_rows($result))
  83				message($lang_common['Bad request']);
  84
  85			if ($pun_config['p_mod_edit_users'] == '0' || $pun_config['p_mod_change_passwords'] == '0' || $db->result($result) < PUN_GUEST)
  86				message($lang_common['No permission']);
  87		}
  88	}
  89
  90	if (isset($_POST['form_sent']))
  91	{
  92		$old_password = isset($_POST['req_old_password']) ? trim($_POST['req_old_password']) : '';
  93		$new_password1 = trim($_POST['req_new_password1']);
  94		$new_password2 = trim($_POST['req_new_password2']);
  95
  96		$user = bors_load('airbase_user', $id);
  97		if(!$user)
  98			message(ec('Не могу найти пользователя с ID=').$id);
  99
 100		$is_admin = $pun_user['g_id'] == PUN_ADMIN;
 101
 102		if(!$is_admin && !$user->check_password($old_password, false))
 103		{
 104//			debug_hidden_log('_pass_ch_err', "old=$old_password, new={$_POST['req_new_password1']}");
 105			message($lang_profile['Wrong pass'].' [1]');
 106		}
 107//		else
 108//			debug_hidden_log('_pass_ch_ok', "old=$old_password, new={$_POST['req_new_password1']}");
 109
 110		if($new_password1 != $new_password2)
 111			message($lang_prof_reg['Pass not match']);
 112
 113		if(strlen($new_password1) < 4)
 114			message($lang_prof_reg['Pass too short']);
 115
 116		$user->change_password($new_password1);
 117		$user->cookie_hash_update($save_pass ? -1 : 0);
 118
 119		redirect('profile.php?section=essentials&amp;id='.$id, $lang_profile['Pass updated redirect']);
 120	}
 121
 122	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 123	$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']);
 124	$focus_element = array('change_pass', (($pun_user['g_id'] > PUN_MOD) ? 'req_old_password' : 'req_new_password1'));
 125
 126	require PUN_ROOT.'header.php';
 127
 128?>
 129<div class="blockform">
 130	<h2><span><?php echo $lang_profile['Change pass'] ?></span></h2>
 131	<div class="box">
 132		<form id="change_pass" method="post" action="profile.php?action=change_pass&amp;id=<?php echo $id;/*"*/?>" onsubmit="return process_form(this)">
 133			<div class="inform">
 134				<input type="hidden" name="form_sent" value="1" />
 135				<fieldset>
 136					<legend><?php echo $lang_profile['Change pass legend'] ?></legend>
 137					<div class="infldset">
 138<?php if ($pun_user['g_id'] > PUN_MOD): ?>						<label><strong><?php echo $lang_profile['Old pass'] ?></strong><br />
 139						<input type="password" name="req_old_password" size="16" maxlength="16" /><br /></label>
 140<?php endif; ?>						<label class="conl"><strong><?php echo $lang_profile['New pass'] ?></strong><br />
 141						<input type="password" name="req_new_password1" size="16" maxlength="16" /><br /></label>
 142						<label class="conl"><strong><?php echo $lang_profile['Confirm new pass'] ?></strong><br />
 143						<input type="password" name="req_new_password2" size="16" maxlength="16" /><br /></label>
 144						<div class="clearb"></div>
 145					</div>
 146				</fieldset>
 147			</div>
 148			<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>
 149		</form>
 150	</div>
 151</div>
 152<?php
 153
 154	require PUN_ROOT.'footer.php';
 155}
 156
 157
 158else if ($action == 'change_email')
 159{
 160	// Make sure we are allowed to change this users e-mail
 161	if ($pun_user['id'] != $id)
 162	{
 163		if ($pun_user['g_id'] > PUN_MOD)	// A regular user trying to change another users e-mail?
 164			message($lang_common['No permission']);
 165		else if ($pun_user['g_id'] == PUN_MOD)	// A moderator trying to change a users e-mail?
 166		{
 167			$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 168			if (!$db->num_rows($result))
 169				message($lang_common['Bad request']);
 170
 171			if ($pun_config['p_mod_edit_users'] == '0' || $db->result($result) < PUN_GUEST)
 172				message($lang_common['No permission']);
 173		}
 174	}
 175
 176	if (isset($_GET['key']))
 177	{
 178		$key = $_GET['key'];
 179
 180		$result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch activation data', __FILE__, __LINE__, $db->error());
 181		list($new_email, $new_email_key) = $db->fetch_row($result);
 182
 183		if ($key != $new_email_key)
 184			message($lang_profile['E-mail key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
 185		else
 186		{
 187			$db->query('UPDATE '.$db->prefix.'users SET email=activate_string, activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update e-mail address', __FILE__, __LINE__, $db->error());
 188
 189			message($lang_profile['E-mail updated'], true);
 190		}
 191	}
 192	else if (isset($_POST['form_sent']))
 193	{
 194		if (pun_hash($_POST['req_password'], $pun_user['username']) !== $pun_user['password'])
 195			message($lang_profile['Wrong pass'].'[2]');
 196
 197		require PUN_ROOT.'include/email.php';
 198
 199		// Validate the email-address
 200		$new_email = strtolower(trim($_POST['req_new_email']));
 201		if (!is_valid_email($new_email))
 202			message($lang_common['Invalid e-mail']);
 203
 204		// Check it it's a banned e-mail address
 205		if (is_banned_email($new_email))
 206		{
 207			if ($pun_config['p_allow_banned_email'] == '0')
 208				message($lang_prof_reg['Banned e-mail']);
 209			else if ($pun_config['o_mailing_list'] != '')
 210			{
 211				$mail_subject = 'Alert - Banned e-mail detected';
 212				$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)';
 213
 214				pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
 215			}
 216		}
 217
 218		// Check if someone else already has registered with that e-mail address
 219		$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE email=\''.$db->escape($new_email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 220		if ($db->num_rows($result))
 221		{
 222			if ($pun_config['p_allow_dupe_email'] == '0')
 223				message($lang_prof_reg['Dupe e-mail']);
 224			else if ($pun_config['o_mailing_list'] != '')
 225			{
 226				while ($cur_dupe = $db->fetch_assoc($result))
 227					$dupe_list[] = $cur_dupe['username'];
 228
 229				$mail_subject = 'Alert - Duplicate e-mail detected';
 230				$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)';
 231
 232				pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
 233			}
 234		}
 235
 236
 237		$new_email_key = random_pass(8);
 238
 239		$db->query('UPDATE '.$db->prefix.'users SET activate_string=\''.$db->escape($new_email).'\', activate_key=\''.$new_email_key.'\' WHERE id='.$id) or error('Unable to update activation data', __FILE__, __LINE__, $db->error());
 240
 241		// Load the "activate e-mail" template
 242		$mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/activate_email.tpl'));
 243
 244		// The first row contains the subject
 245		$first_crlf = strpos($mail_tpl, "\n");
 246		$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
 247		$mail_message = trim(substr($mail_tpl, $first_crlf));
 248
 249		$mail_message = str_replace('<username>', $pun_user['username'], $mail_message);
 250		$mail_message = str_replace('<base_url>', $pun_config['o_base_url'], $mail_message);
 251		$mail_message = str_replace('<activation_url>', $pun_config['o_base_url'].'/profile.php?action=change_email&id='.$id.'&key='.$new_email_key, $mail_message);
 252		$mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
 253
 254		pun_mail($new_email, $mail_subject, $mail_message);
 255
 256		message($lang_profile['Activate e-mail sent'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.', true);
 257	}
 258
 259	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 260	$required_fields = array('req_new_email' => $lang_profile['New e-mail'], 'req_password' => $lang_common['Password']);
 261	$focus_element = array('change_email', 'req_new_email');
 262	require PUN_ROOT.'header.php';
 263
 264?>
 265<div class="blockform">
 266	<h2><span><?php echo $lang_profile['Change e-mail'] ?></span></h2>
 267	<div class="box">
 268		<form id="change_email" method="post" action="profile.php?action=change_email&amp;id=<?php echo $id; /*"*/?>" id="change_email" onsubmit="return process_form(this)">
 269			<div class="inform">
 270				<fieldset>
 271					<legend><?php echo $lang_profile['E-mail legend'] ?></legend>
 272					<div class="infldset">
 273						<input type="hidden" name="form_sent" value="1" />
 274						<label><strong><?php echo $lang_profile['New e-mail'] ?></strong><br /><input type="text" name="req_new_email" size="50" maxlength="50" /><br /></label>
 275						<label><strong><?php echo $lang_common['Password'] ?></strong><br /><input type="password" name="req_password" size="16" maxlength="16" /><br /></label>
 276						<p><?php echo $lang_profile['E-mail instructions'] ?></p>
 277					</div>
 278				</fieldset>
 279			</div>
 280			<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>
 281		</form>
 282	</div>
 283</div>
 284<?php
 285
 286	require PUN_ROOT.'footer.php';
 287}
 288
 289
 290else if ($action == 'upload_avatar' || $action == 'upload_avatar2')
 291{
 292	if ($pun_config['o_avatars'] == '0')
 293		message($lang_profile['Avatars disabled']);
 294
 295	if ($pun_user['id'] != $id && $pun_user['g_id'] > PUN_MOD)
 296		message($lang_common['No permission']);
 297
 298	if (isset($_POST['form_sent']))
 299	{
 300		if (!isset($_FILES['req_file']))
 301			message($lang_profile['No file']);
 302			
 303		$uploaded_file = $_FILES['req_file'];
 304
 305		// Make sure the upload went smooth
 306		if (isset($uploaded_file['error']))
 307		{
 308			switch ($uploaded_file['error'])
 309			{
 310				case 1:	// UPLOAD_ERR_INI_SIZE
 311				case 2:	// UPLOAD_ERR_FORM_SIZE
 312					message($lang_profile['Too large ini']);
 313					break;
 314
 315				case 3:	// UPLOAD_ERR_PARTIAL
 316					message($lang_profile['Partial upload']);
 317					break;
 318
 319				case 4:	// UPLOAD_ERR_NO_FILE
 320					message($lang_profile['No file']);
 321					break;
 322
 323				case 6:	// UPLOAD_ERR_NO_TMP_DIR
 324					message($lang_profile['No tmp directory']);
 325					break;
 326
 327				default:
 328					// No error occured, but was something actually uploaded?
 329					if ($uploaded_file['size'] == 0)
 330						message($lang_profile['No file']);
 331					break;
 332			}
 333		}
 334
 335		if (is_uploaded_file($uploaded_file['tmp_name']))
 336		{
 337			$allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
 338			if (!in_array($uploaded_file['type'], $allowed_types))
 339				message($lang_profile['Bad type']);
 340
 341			// Make sure the file isn't too big
 342			if ($uploaded_file['size'] > $pun_config['o_avatars_size'])
 343				message($lang_profile['Too large'].' '.$pun_config['o_avatars_size'].' '.$lang_profile['bytes'].'.');
 344
 345			// Determine type
 346			$extensions = null;
 347			if ($uploaded_file['type'] == 'image/gif')
 348				$extensions = array('.gif', '.jpg', '.png');
 349			else if ($uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg')
 350				$extensions = array('.jpg', '.gif', '.png');
 351			else
 352				$extensions = array('.png', '.gif', '.jpg');
 353
 354			// Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions.
 355			if (!@move_uploaded_file($uploaded_file['tmp_name'], $pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
 356				message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
 357
 358			// Now check the width/height
 359			list($width, $height, $type,) = getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
 360			if (empty($width) || empty($height) || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
 361			{
 362				@unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
 363				message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
 364			}
 365			else if ($type == 1 && $uploaded_file['type'] != 'image/gif')	// Prevent dodgy uploads
 366			{
 367				@unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
 368				message($lang_profile['Bad type']);
 369			}			
 370
 371			// Delete any old avatars and put the new one in place
 372			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
 373			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[1]);
 374			@unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[2]);
 375			@rename($pun_config['o_avatars_dir'].'/'.$id.'.tmp', $pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
 376			@chmod($pun_config['o_avatars_dir'].'/'.$id.$extensions[0], 0666);
 377		}
 378		else
 379			message($lang_profile['Unknown failure']);
 380
 381		$avatars_dir = '/var/www/balancer.ru/htdocs/forum/punbb/img/avatars';
 382		
 383		$user_avatar = "";
 384		
 385		if($img_size = @getimagesize("$avatars_dir/$id.gif"))
 386			$user_avatar = "$id.gif";
 387		elseif($img_size = @getimagesize("$avatars_dir/$id.png"))
 388			$user_avatar = "$id.png";
 389		elseif($img_size = @getimagesize("$avatars_dir/$id.jpg"))
 390			$user_avatar = "$id.jpg";
 391
 392		bors()->changed_save(); // Сохраняем всё. А то, вдруг, там где-то старые параметры аватара.
 393
 394		// Enable use_avatar (seems sane since the user just uploaded an avatar)
 395		$db->query("UPDATE {$db->prefix}users SET use_avatar='".addslashes($user_avatar)."', avatar_width={$img_size[0]}, avatar_height={$img_size[0]} WHERE id=$id")
 396			or error('Unable to update avatar state', __FILE__, __LINE__, $db->error());
 397
 398		redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
 399	}
 400
 401	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 402	$required_fields = array('req_file' => $lang_profile['File']);
 403	$focus_element = array('upload_avatar', 'req_file');
 404	require PUN_ROOT.'header.php';
 405
 406?>
 407<div class="blockform">
 408	<h2><span><?php echo $lang_profile['Upload avatar'] ?></span></h2>
 409	<div class="box">
 410		<form id="upload_avatar" method="post" enctype="multipart/form-data" action="profile.php?action=upload_avatar2&amp;id=<?php echo $id; /*"*/ ?>" onsubmit="return process_form(this)">
 411			<div class="inform">
 412				<fieldset>
 413					<legend><?php echo $lang_profile['Upload avatar legend'] ?></legend>
 414					<div class="infldset">
 415						<input type="hidden" name="form_sent" value="1" />
 416						<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $pun_config['o_avatars_size'];/*"*/ ?>" />
 417						<label><strong><?php echo $lang_profile['File'] ?></strong><br /><input name="req_file" type="file" size="40" /><br /></label>
 418						<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>
 419					</div>
 420				</fieldset>
 421			</div>
 422			<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>
 423		</form>
 424	</div>
 425</div>
 426<?php
 427
 428	require PUN_ROOT.'footer.php';
 429}
 430
 431
 432else if ($action == 'delete_avatar')
 433{
 434	if ($pun_user['id'] != $id && $pun_user['g_id'] > PUN_MOD)
 435		message($lang_common['No permission']);
 436
 437	confirm_referrer('profile.php');
 438
 439	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.jpg');
 440	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.png');
 441	@unlink($pun_config['o_avatars_dir'].'/'.$id.'.gif');
 442
 443	// Disable use_avatar
 444	$db->query("UPDATE {$db->prefix}users SET use_avatar='' WHERE id=$id")
 445		or error('Unable to update avatar state', __FILE__, __LINE__, $db->error());
 446
 447	redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar deleted redirect']);
 448}
 449
 450
 451else if (isset($_POST['update_group_membership']))
 452{
 453	if ($pun_user['g_id'] > PUN_ADMIN)
 454		message($lang_common['No permission']);
 455
 456	confirm_referrer('profile.php');
 457
 458	$new_group_id = intval($_POST['group_id']);
 459
 460	$db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
 461
 462	// If the user was a moderator or an administrator, we remove him/her from the moderator list in all forums as well
 463	if ($new_group_id > PUN_MOD)
 464	{
 465		$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
 466
 467		while ($cur_forum = $db->fetch_assoc($result))
 468		{
 469			$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 470
 471			if (in_array($id, $cur_moderators))
 472			{
 473				$username = array_search($id, $cur_moderators);
 474				unset($cur_moderators[$username]);
 475				$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 476
 477				$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 478			}
 479		}
 480	}
 481
 482	redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Group membership redirect']);
 483}
 484
 485
 486else if (isset($_POST['update_forums']))
 487{
 488	if ($pun_user['g_id'] > PUN_ADMIN)
 489		message($lang_common['No permission']);
 490
 491	confirm_referrer('profile.php');
 492
 493	// Get the username of the user we are processing
 494	$result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 495	$username = $db->result($result);
 496
 497	$moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
 498
 499	// Loop through all forums
 500	$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
 501
 502	while ($cur_forum = $db->fetch_assoc($result))
 503	{
 504		$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 505		// If the user should have moderator access (and he/she doesn't already have it)
 506		if (in_array($cur_forum['id'], $moderator_in) && !in_array($id, $cur_moderators))
 507		{
 508			$cur_moderators[$username] = $id;
 509			ksort($cur_moderators);
 510
 511			$db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 512		}
 513		// If the user shouldn't have moderator access (and he/she already has it)
 514		else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators))
 515		{
 516			unset($cur_moderators[$username]);
 517			$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 518
 519			$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 520		}
 521	}
 522
 523	redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Update forums redirect']);
 524}
 525
 526
 527else if (isset($_POST['ban']))
 528{
 529	if ($pun_user['g_id'] > PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
 530		message($lang_common['No permission']);
 531
 532	redirect('admin_bans.php?add_ban='.$id, $lang_profile['Ban redirect']);
 533}
 534
 535
 536else if (isset($_POST['delete_user']) || isset($_POST['delete_user_comply']))
 537{
 538	if ($pun_user['g_id'] > PUN_ADMIN)
 539		message($lang_common['No permission']);
 540
 541	confirm_referrer('profile.php');
 542
 543	// Get the username and group of the user we are deleting
 544	$result = $db->query('SELECT group_id, username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 545	list($group_id, $username) = $db->fetch_row($result);
 546
 547	if ($group_id == PUN_ADMIN)
 548		message('Administrators cannot be deleted. In order to delete this user, you must first move him/her to a different user group.');
 549
 550	if (isset($_POST['delete_user_comply']))
 551	{
 552		// If the user is a moderator or an administrator, we remove him/her from the moderator list in all forums as well
 553		if ($group_id < PUN_GUEST)
 554		{
 555			$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
 556
 557			while ($cur_forum = $db->fetch_assoc($result))
 558			{
 559				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 560
 561				if (in_array($id, $cur_moderators))
 562				{
 563					unset($cur_moderators[$username]);
 564					$cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
 565
 566					$db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 567				}
 568			}
 569		}
 570
 571		// Delete any subscriptions
 572		$db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE user_id='.$id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
 573
 574		// Remove him/her from the online list (if they happen to be logged in)
 575		$db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$id) or error('Unable to remove user from online list', __FILE__, __LINE__, $db->error());
 576
 577		// Should we delete all posts made by this user?
 578		if (isset($_POST['delete_posts']))
 579		{
 580			require PUN_ROOT.'include/search_idx.php';
 581			@set_time_limit(0);
 582
 583			// Find all posts made by this user
 584			$result = $db->query('SELECT p.id, p.topic_id, t.forum_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.poster_id='.$id) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
 585			if ($db->num_rows($result))
 586			{
 587				while ($cur_post = $db->fetch_assoc($result))
 588				{
 589					// Determine whether this post is the "topic post" or not
 590					$result2 = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['topic_id'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
 591
 592					if ($db->result($result2) == $cur_post['id'])
 593						delete_topic($cur_post['topic_id']);
 594					else
 595						delete_post($cur_post['id'], $cur_post['topic_id']);
 596
 597					update_forum($cur_post['forum_id']);
 598				}
 599			}
 600		}
 601		else
 602			// Set all his/her posts to guest
 603			$db->query('UPDATE '.$db->prefix.'posts SET poster_id=1 WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
 604
 605		// Delete the user
 606		$db->query('DELETE FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $db->error());
 607
 608		redirect('index.php', $lang_profile['User delete redirect']);
 609	}
 610
 611	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 612	require PUN_ROOT.'header.php';
 613
 614?>
 615<div class="blockform">
 616	<h2><span><?php echo $lang_profile['Confirm delete user'] ?></span></h2>
 617	<div class="box">
 618		<form id="confirm_del_user" method="post" action="profile.php?id=<?php echo $id /*"*/?>">
 619			<div class="inform">
 620				<fieldset>
 621					<legend><?php echo $lang_profile['Confirm delete legend'] ?></legend>
 622					<div class="infldset">
 623						<p><?php echo $lang_profile['Confirmation info'].' '.pun_htmlspecialchars($username).'.' ?></p>
 624						<div class="rbox">
 625							<label><input type="checkbox" name="delete_posts" value="1" checked="checked" /><?php echo $lang_profile['Delete posts'] ?><br /></label>
 626						</div>
 627						<p class="warntext"><strong><?php echo $lang_profile['Delete warning'] ?></strong></p>
 628					</div>
 629				</fieldset>
 630			</div>
 631			<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>
 632		</form>
 633	</div>
 634</div>
 635<?php
 636
 637	require PUN_ROOT.'footer.php';
 638}
 639
 640
 641else if (isset($_POST['form_sent']))
 642{
 643	// Fetch the user group of the user we are editing
 644	$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 645	if (!$db->num_rows($result))
 646		message($lang_common['Bad request']);
 647
 648	$group_id = $db->result($result);
 649
 650	if ($pun_user['id'] != $id &&
 651		($pun_user['g_id'] > PUN_MOD ||
 652		($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_edit_users'] == '0') ||
 653		($pun_user['g_id'] == PUN_MOD && $group_id < PUN_GUEST)))
 654		message($lang_common['No permission']);
 655
 656	if ($pun_user['g_id'] < PUN_GUEST)
 657		confirm_referrer('profile.php');
 658
 659	// Extract allowed elements from $_POST['form']
 660	function extract_elements($allowed_elements)
 661	{
 662		$form = array();
 663
 664		while (list($key, $value) = @each($_POST['form']))
 665		{
 666		    if (in_array($key, $allowed_elements))
 667		        $form[$key] = $value;
 668		}
 669
 670		return $form;
 671	}
 672
 673	$username_updated = false;
 674
 675	// Validate input depending on section
 676	switch ($section)
 677	{
 678		case 'essentials':
 679		{
 680			$form = extract_elements(array('timezone', 'language'));
 681
 682			if ($pun_user['g_id'] < PUN_GUEST)
 683			{
 684				$form['admin_note'] = trim($_POST['admin_note']);
 685
 686				// Are we allowed to change usernames?
 687				if ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_rename_users'] == '1'))
 688				{
 689					$form['username'] = trim($_POST['req_username']);
 690					$old_username = trim($_POST['old_username']);
 691
 692					if (strlen($form['username']) < 2)
 693						message($lang_prof_reg['Username too short']);
 694					else if (pun_strlen($form['username']) > 25)	// This usually doesn't happen since the form element only accepts 25 characters
 695						message($lang_prof_reg['Username too long']." (".strlen($form['username']).")");
 696					else if (!strcasecmp($form['username'], 'Guest') || !strcasecmp($form['username'], $lang_common['Guest']))
 697						message($lang_prof_reg['Username guest']);
 698					else if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $form['username']))
 699						message($lang_prof_reg['Username IP']);
 700					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']))
 701						message($lang_prof_reg['Username BBCode']);
 702
 703					// Check that the username is not already registered
 704					$result = $db->query('SELECT 1 FROM '.$db->prefix.'users WHERE username=\''.$db->escape($form['username']).'\' AND id!='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 705					if ($db->num_rows($result))
 706						message($lang_profile['Dupe username']);
 707
 708					if ($form['username'] != $old_username)
 709						$username_updated = true;
 710				}
 711
 712				// We only allow administrators to update the post count
 713				if ($pun_user['g_id'] == PUN_ADMIN)
 714					$form['num_posts'] = intval($_POST['num_posts']);
 715			}
 716
 717			if ($pun_config['o_regs_verify'] == '0' || $pun_user['g_id'] < PUN_GUEST)
 718			{
 719				require PUN_ROOT.'include/email.php';
 720
 721				// Validate the email-address
 722				$form['email'] = strtolower(trim($_POST['req_email']));
 723				if (!is_valid_email($form['email']))
 724					message($lang_common['Invalid e-mail']);
 725			}
 726
 727			// Make sure we got a valid language string
 728			if (isset($form['language']))
 729			{
 730				$form['language'] = preg_replace('#[\.\\\/]#', '', $form['language']);
 731				if (!file_exists(PUN_ROOT.'lang/'.$form['language'].'/common.php'))
 732						message($lang_common['Bad request']);
 733			}
 734
 735			break;
 736		}
 737
 738		case 'personal':
 739		{
 740			$form = extract_elements(array('realname', 'user_nick', 'url', 'location'));
 741
 742			if ($pun_user['g_id'] == PUN_ADMIN)
 743				$form['title'] = trim($_POST['title']);
 744			else if ($pun_user['g_set_title'] == '1')
 745			{
 746				$form['title'] = trim($_POST['title']);
 747
 748				if ($form['title'] != '')
 749				{
 750					// A list of words that the title may not contain
 751					// If the language is English, there will be some duplicates, but it's not the end of the world
 752					$forbidden = array('Member', 'Moderator', 'Administrator', 'Banned', 'Guest', $lang_common['Member'], $lang_common['Moderator'], $lang_common['Administrator'], $lang_common['Banned'], $lang_common['Guest']);
 753
 754					if (in_array($form['title'], $forbidden))
 755						message($lang_profile['Forbidden title']);
 756				}
 757			}
 758
 759			// Add http:// if the URL doesn't contain it already
 760			if ($form['url'] != '' && !stristr($form['url'], 'http://'))
 761				$form['url'] = 'http://'.$form['url'];
 762
 763			break;
 764		}
 765
 766		case 'messaging':
 767		{
 768			$form = extract_elements(array('jabber', 'icq', 'msn', 'aim', 'yahoo'));
 769
 770			// If the ICQ UIN contains anything other than digits it's invalid
 771			if ($form['icq'] != '' && preg_match('/[^0-9]/', $form['icq']))
 772				message($lang_prof_reg['Bad ICQ']);
 773
 774			break;
 775		}
 776
 777		case 'personality':
 778		{
 779			$form = extract_elements(array('use_avatar'));
 780
 781			// Clean up signature from POST
 782			$form['signature'] = pun_linebreaks(trim($_POST['signature']));
 783
 784			// Validate signature
 785			if (pun_strlen($form['signature']) > $pun_config['p_sig_length'])
 786				message($lang_prof_reg['Sig too long'].' '.$pun_config['p_sig_length'].' '.$lang_prof_reg['characters'].'.');
 787			else if (substr_count($form['signature'], "\n") > ($pun_config['p_sig_lines']-1))
 788				message($lang_prof_reg['Sig too many lines'].' '.$pun_config['p_sig_lines'].' '.$lang_prof_reg['lines'].'.');
 789			else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && strtoupper($form['signature']) == $form['signature'] && $pun_user['g_id'] > PUN_MOD)
 790				$form['signature'] = ucwords(strtolower($form['signature']));
 791
 792			// Validate BBCode syntax
 793			if ($pun_config['p_sig_bbcode'] == '1' && strpos($form['signature'], '[') !== false && strpos($form['signature'], ']') !== false)
 794			{
 795				require PUN_ROOT.'include/parser.php';
 796				$form['signature'] = preparse_bbcode($form['signature'], $foo, true);
 797			}
 798
 799			if (!isset($form['use_avatar']) || !$form['use_avatar']) $form['use_avatar'] = '';
 800
 801			break;
 802		}
 803
 804		case 'display':
 805		{
 806			$form = extract_elements(array('disp_topics', 'disp_posts', 'show_smilies', 'show_img', 'show_img_sig', 'show_avatars', 'show_sig', 'style'));
 807
 808			if ($form['disp_topics'] != '' && intval($form['disp_topics']) < 3) $form['disp_topics'] = 3;
 809			if ($form['disp_topics'] != '' && intval($form['disp_topics']) > 75) $form['disp_topics'] = 75;
 810			if ($form['disp_posts'] != '' && intval($form['disp_posts']) < 3) $form['disp_posts'] = 3;
 811			if ($form['disp_posts'] != '' && intval($form['disp_posts']) > 75) $form['disp_posts'] = 75;
 812
 813			if (!isset($form['show_smilies']) || $form['show_smilies'] != '1') $form['show_smilies'] = '0';
 814			if (!isset($form['show_img']) || $form['show_img'] != '1') $form['show_img'] = '0';
 815			if (!isset($form['show_img_sig']) || $form['show_img_sig'] != '1') $form['show_img_sig'] = '0';
 816			if (!isset($form['show_avatars']) || $form['show_avatars'] != '1') $form['show_avatars'] = '0';
 817			if (!isset($form['show_sig']) || $form['show_sig'] != '1') $form['show_sig'] = '0';
 818
 819			break;
 820		}
 821
 822		case 'privacy':
 823		{
 824			$form = extract_elements(array('email_setting', 'save_pass', 'notify_with_post'));
 825
 826			$form['email_setting'] = intval($form['email_setting']);
 827			if ($form['email_setting'] < 0 && $form['email_setting'] > 2) $form['email_setting'] = 1;
 828
 829			if (!isset($form['save_pass']) || $form['save_pass'] != '1') $form['save_pass'] = '0';
 830			if (!isset($form['notify_with_post']) || $form['notify_with_post'] != '1') $form['notify_with_post'] = '0';
 831
 832			// If the save_pass setting has changed, we need to set a new cookie with the appropriate expire date
 833			if ($pun_user['id'] == $id && $form['save_pass'] != $pun_user['save_pass'])
 834			{
 835				$me = new User($id);
 836				$me->cookie_hash_update();
 837			}
 838
 839			break;
 840		}
 841
 842		default:
 843			message($lang_common['Bad request']);
 844	}
 845
 846//	set_loglevel(10,0);
 847	$user = object_load('forum_user', $id, array('no_load_cache' => true));
 848	$user->set_signature($form['signature'], true);
 849	$user->set_signature_html(NULL, true);
 850	$user->set_use_avatar($form['use_avatar'], true);
 851
 852	foreach(array(
 853		'url' => 'www', 
 854		'title' => 'user_title',
 855		'username' => 'title',
 856	) as $from => $to)
 857	{
 858		if(isset($form[$from]))
 859			$form[$to] = $form[$from];
 860		unset($form[$from]);
 861	}
 862
 863	foreach($form as $key => $val)
 864		$user->set($key, $val, true);
 865
 866	$user->store();
 867//	print_d($form);
 868//	bors_exit();
 869
 870//	$db->query('UPDATE '.$db->prefix.'users SET '.implode(',', $temp).' WHERE id='.$id) or error('Unable to update profile', __FILE__, __LINE__, $db->error());
 871
 872	// If we changed the username we have to update some stuff
 873	if ($username_updated)
 874	{
 875		$db->query('UPDATE '.$db->prefix.'posts SET poster=\''.$db->escape($form['username']).'\' WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
 876		$db->query('UPDATE '.$db->prefix.'topics SET poster=\''.$db->escape($form['username']).'\' WHERE poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
 877		$db->query('UPDATE '.$db->prefix.'topics SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
 878		$db->query('UPDATE '.$db->prefix.'forums SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update forums', __FILE__, __LINE__, $db->error());
 879		$db->query('UPDATE '.$db->prefix.'online SET ident=\''.$db->escape($form['username']).'\' WHERE ident=\''.$db->escape($old_username).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error());
 880
 881		// If the user is a moderator or an administrator we have to update the moderator lists
 882		$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 883		$group_id = $db->result($result);
 884
 885		if ($group_id < PUN_GUEST)
 886		{
 887			$result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
 888
 889			while ($cur_forum = $db->fetch_assoc($result))
 890			{
 891				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
 892
 893				if (in_array($id, $cur_moderators))
 894				{
 895					unset($cur_moderators[$old_username]);
 896					$cur_moderators[$form['username']] = $id;
 897					ksort($cur_moderators);
 898
 899					$db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 900				}
 901			}
 902		}
 903	}
 904
 905	redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);
 906}
 907
 908
 909$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.user_nick, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.use_avatar, u.avatar_height, u.avatar_width, 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.last_visit, u.registered, u.registration_ip, u.admin_note, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 910if (!$db->num_rows($result))
 911	message($lang_common['Bad request']);
 912
 913$user = $db->fetch_assoc($result);
 914
 915$last_post = format_time($user['last_post']);
 916$last_visit = format_time($user['last_visit']);
 917
 918if ($user['signature'] != '')
 919{
 920	require PUN_ROOT.'include/parser.php';
 921	$parsed_signature = parse_signature($user['signature']);
 922}
 923
 924
 925// View or edit?
 926if ($pun_user['id'] != $id &&
 927	($pun_user['g_id'] > PUN_MOD ||
 928	($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_edit_users'] == '0') ||
 929	($pun_user['g_id'] == PUN_MOD && $user['g_id'] < PUN_GUEST)))
 930{
 931	if ($user['email_setting'] == '0' && !$pun_user['is_guest'])
 932		$email_field = '<a href="mailto:'.$user['email'].'">'.$user['email'].'</a>';
 933	else if ($user['email_setting'] == '1' && !$pun_user['is_guest'])
 934		$email_field = "<a href=\"{$pun_config['root_uri']}/misc.php?email=$id\">".$lang_common['Send e-mail'].'</a>';
 935	else
 936		$email_field = $lang_profile['Private'];
 937
 938	$user_title_field = get_title($user);
 939
 940	if ($user['url'] != '')
 941	{
 942		$user['url'] = pun_htmlspecialchars($user['url']);
 943
 944		if ($pun_config['o_censoring'] == '1')
 945			$user['url'] = censor_words($user['url']);
 946
 947		$url = '<a href="'.$user['url'].'">'.$user['url'].'</a>';
 948	}
 949	else
 950		$url = $lang_profile['Unknown'];
 951
 952	if ($pun_config['o_avatars'] == '1')
 953	{
 954		if ($user['use_avatar'])
 955			$avatar_field = "<img src=\"{$pun_config['root_uri']}/{$pun_config['o_avatars_dir']}/{$user['use_avatar']}\" width=\"{$user['avatar_width']}\" height=\"{$user['avatar_height']}\" alt=\"\" />";
 956		else
 957			$avatar_field = $lang_profile['No avatar'];
 958	}
 959
 960	$posts_field = '';
 961	if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST)
 962		$posts_field = $user['num_posts'];
 963	if ($pun_user['g_search'] == '1')
 964		$posts_field .= (($posts_field != '') ? ' - ' : '')."<a href=\"{$pun_config['root_uri']}/search.php?action=show_user&amp;user_id=$id\">".$lang_profile['Show posts'].'</a>';
 965
 966	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
 967	define('PUN_ALLOW_INDEX', 1);
 968	require PUN_ROOT.'header.php';
 969
 970?>
 971<div id="viewprofile" class="block">
 972	<h2><span><?php echo $lang_common['Profile'] ?></span></h2>
 973	<div class="box">
 974		<div class="fakeform">
 975			<div class="inform">
 976				<fieldset>
 977				<legend><?php echo $lang_profile['Section personal'] ?></legend>
 978					<div class="infldset">
 979						<dl>
 980							<dt>Новый профиль:</dt>
 981							<dd><a href="http://www.balancer.ru/user/<?php echo $id?>/">http://www.balancer.ru/user/<?php echo $id?>/</a></dd>
 982							<dt><?php echo $lang_common['Username'] ?>: </dt>
 983							<dd><?php echo pun_htmlspecialchars($user['username']) ?></dd>
 984							<dt><?php echo $lang_common['Title'] ?>: </dt>
 985							<dd><?php echo ($pun_config['o_censoring'] == '1') ? censor_words($user_title_field) : $user_title_field; ?></dd>
 986							<dt><?php echo $lang_profile['Realname'] ?>: </dt>
 987							<dd><?php echo ($user['realname'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['realname']) : $user['realname']) : $lang_profile['Unknown']; ?></dd>
 988							<dt><?php echo 'Ник (отображаемое имя)' ?>: </dt>
 989							<dd><?php echo ($user['user_nick'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['user_nick']) : $user['user_nick']) : $lang_profile['Unknown']; ?></dd>
 990							<dt><?php echo $lang_profile['Location'] ?>: </dt>
 991							<dd><?php echo ($user['location'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['location']) : $user['location']) : $lang_profile['Unknown']; ?></dd>
 992							<dt><?php echo $lang_profile['Website'] ?>: </dt>
 993							<dd><?php echo $url ?>&nbsp;</dd>
 994							<dt><?php echo $lang_common['E-mail'] ?>: </dt>
 995							<dd><?php echo $email_field ?></dd>
 996						</dl>
 997						<div class="clearer"></div>
 998					</div>
 999				</fieldset>
1000			</div>
1001			<div class="inform">
1002				<fieldset>
1003				<legend><?php echo $lang_profile['Section messaging'] ?></legend>
1004					<div class="infldset">
1005						<dl>
1006							<dt><?php echo $lang_profile['Jabber'] ?>: </dt>
1007							<dd><?php echo ($user['jabber'] !='') ? pun_htmlspecialchars($user['jabber']) : $lang_profile['Unknown']; ?></dd>
1008							<dt><?php echo $lang_profile['ICQ'] ?>: </dt>
1009							<dd><?php echo ($user['icq'] !='') ? $user['icq'] : $lang_profile['Unknown']; ?></dd>
1010							<dt><?php echo $lang_profile['MSN'] ?>: </dt>
1011							<dd><?php echo ($user['msn'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['msn']) : $user['msn']) : $lang_profile['Unknown']; ?></dd>
1012							<dt><?php echo $lang_profile['AOL IM'] ?>: </dt>
1013							<dd><?php echo ($user['aim'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['aim']) : $user['aim']) : $lang_profile['Unknown']; ?></dd>
1014							<dt><?php echo $lang_profile['Yahoo'] ?>: </dt>
1015							<dd><?php echo ($user['yahoo'] !='') ? pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['yahoo']) : $user['yahoo']) : $lang_profile['Unknown']; ?></dd>
1016						</dl>
1017						<div class="clearer"></div>
1018					</div>
1019				</fieldset>
1020			</div>
1021			<div class="inform">
1022				<fieldset>
1023				<legend><?php echo $lang_profile['Section personality'] ?></legend>
1024					<div class="infldset">
1025						<dl>
1026<?php if ($pun_config['o_avatars'] == '1'): ?>							<dt><?php echo $lang_profile['Avatar'] ?>: </dt>
1027							<dd><?php echo $avatar_field ?></dd>
1028<?php endif; ?>							<dt><?php echo $lang_profile['Signature'] ?>: </dt>
1029							<dd><div><?php echo isset($parsed_signature) ? $parsed_signature : $lang_profile['No sig']; ?></div></dd>
1030						</dl>
1031						<div class="clearer"></div>
1032					</div>
1033				</fieldset>
1034			</div>
1035			<div class="inform">
1036				<fieldset>
1037				<legend><?php echo $lang_profile['User activity'] ?></legend>
1038					<div class="infldset">
1039						<dl>
1040<?php if ($posts_field != ''): ?>							<dt><?php echo $lang_common['Posts'] ?>: </dt>
1041							<dd><?php echo $posts_field ?></dd>
1042<?php endif; ?>							<dt><?php echo $lang_common['Last post'] ?>: </dt>
1043							<dd><?php echo $last_post ?></dd>
1044							<dt><?php echo $lang_common['Registered'] ?>: </dt>
1045							<dd><?php echo format_time($user['registered'], true) ?></dd>
1046						</dl>
1047						<div class="clearer"></div>
1048					</div>
1049				</fieldset>
1050			</div>
1051		</div>
1052	</div>
1053</div>
1054
1055<?php
1056
1057	require PUN_ROOT.'footer.php';
1058}
1059else
1060{
1061	if (!$section || $section == 'essentials')
1062	{
1063		if ($pun_user['g_id'] < PUN_GUEST)
1064		{
1065			if ($pun_user['g_id'] == PUN_ADMIN || $pun_config['p_mod_rename_users'] == '1')
1066				$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";
1067			else
1068				$username_field = '<p>'.$lang_common['Username'].': '.pun_htmlspecialchars($user['username']).'</p>'."\n";
1069
1070			$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";
1071		}
1072		else
1073		{
1074			$username_field = '<p>'.$lang_common['Username'].': '.pun_htmlspecialchars($user['username']).'</p>'."\n";
1075
1076			if ($pun_config['o_regs_verify'] == '1')
1077				$email_field = '<p>'.$lang_common['E-mail'].': '.$user['email']."&nbsp;-&nbsp;<a href=\"{$pun_config['root_uri']}/profile.php?action=change_email&amp;id=$id\">".$lang_profile['Change e-mail'].'</a></p>'."\n";
1078			else
1079				$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";
1080		}
1081
1082		if ($pun_user['g_id'] == PUN_ADMIN)
1083			$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";
1084		else if ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST)
1085			$posts_field = "<p>{$lang_common['Posts']}: {$user['num_posts']} - <a href=\"{$pun_config['root_uri']}/search.php?action=show_user&amp;user_id=$id\">{$lang_profile['Show posts']}</a></p>\n";
1086		else
1087			$posts_field = "<p><a href=\"{$pun_config['root_uri']}/search.php?action=show_user&amp;user_id=$id\">{$lang_profile['Show posts']}</a></p>\n";
1088
1089		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
1090		$required_fields = array('req_username' => $lang_common['Username'], 'req_email' => $lang_common['E-mail']);
1091		require PUN_ROOT.'header.php';
1092
1093		generate_profile_menu('essentials');
1094
1095?>
1096	<div class="blockform">
1097		<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section essentials'] ?></span></h2>
1098		<div class="box">
1099			<form id="profile1" method="post" action="profile.php?section=essentials&amp;id=<?php echo $id;/*"*/?>" onsubmit="return process_form(this)">
1100				<div class="inform">
1101					<fieldset>
1102						<legend><?php echo $lang_profile['Username and pass legend'] ?></legend>
1103						<div class="infldset">
1104							<input type="hidden" name="form_sent" value="1" />
1105							<?php echo $username_field ?>
1106<?php if ($pun_user['id'] == $id || $pun_user['g_id'] == PUN_ADMIN || ($user['g_id'] > PUN_MOD && $pun_config['p_mod_change_passwords'] == '1')): ?><p><a href="<?php echo $pun_config['root_uri'];?>/profile.php?action=change_pass&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Change pass'];/*"*/?></a></p>
1107<?php endif; ?>					</div>
1108					</fieldset>
1109				</div>
1110				<div class="inform">
1111					<fieldset>
1112						<legend><?php echo $lang_prof_reg['E-mail legend'] ?></legend>
1113						<div class="infldset">
1114							<?php echo $email_field ?>
1115						</div>
1116					</fieldset>
1117				</div>
1118				<div class="inform">
1119					<fieldset>
1120						<legend><?php echo $lang_prof_reg['Localisation legend'] ?></legend>
1121						<div class="infldset">
1122							<label><?php echo $lang_prof_reg['Timezone'] ?>: <?php echo $lang_prof_reg['Timezone info'] ?>
1123							<br /><select name="form[timezone]">
1124								<option value="-12"<?php if ($user['timezone'] == -12) echo ' selected="selected"' ?>>-12</option>
1125								<option value="-11"<?php if ($user['timezone'] == -11) echo ' selected="selected"' ?>>-11</option>
1126								<option value="-10"<?php if ($user['timezone'] == -10) echo ' selected="selected"' ?>>-10</option>
1127								<option value="-9.5"<?php if ($user['timezone'] == -9.5) echo ' selected="selected"' ?>>-09.5</option>
1128								<option value="-9"<?php if ($user['timezone'] == -9) echo ' selected="selected"' ?>>-09</option>
1129								<option value="-8.5"<?php if ($user['timezone'] == -8.5) echo ' selected="selected"' ?>>-08.5</option>
1130								<option value="-8"<?php if ($user['timezone'] == -8) echo ' selected="selected"' ?>>-08 PST</option>
1131								<option value="-7"<?php if ($user['timezone'] == -7) echo ' selected="selected"' ?>>-07 MST</option>
1132								<option value="-6"<?php if ($user['timezone'] == -6) echo ' selected="selected"' ?>>-06 CST</option>
1133								<option value="-5"<?php if ($user['timezone'] == -5) echo ' selected="selected"' ?>>-0…

Large files files are truncated, but you can click here to view the full file