qa-page-user-profile.php 34.8 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3 4 5 6 7
/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10
	File: qa-include/qa-page-user-profile.php
	Version: See define()s at top of qa-include/qa-base.php
Gideon Greenspan committed
11
	Description: Controller for user profile page, including wall
Gideon Greenspan committed
12 13 14 15 16 17


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';
	require_once QA_INCLUDE_DIR.'qa-app-limits.php';
	require_once QA_INCLUDE_DIR.'qa-app-updates.php';
Scott Vivian committed
36

Gideon Greenspan committed
37 38 39 40

//	$handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration


Gideon Greenspan committed
41 42 43 44
//	Redirect to 'My Account' page if button clicked

	if (qa_clicked('doaccount'))
		qa_redirect('account');
Scott Vivian committed
45

Gideon Greenspan committed
46

Gideon Greenspan committed
47
//	Find the user profile and questions and answers for this handle
Scott Vivian committed
48

Gideon Greenspan committed
49 50 51 52 53 54 55 56
	$loginuserid=qa_get_logged_in_userid();
	$identifier=QA_FINAL_EXTERNAL_USERS ? $userid : $handle;

	list($useraccount, $userprofile, $userfields, $usermessages, $userpoints, $userlevels, $navcategories, $userrank)=
		qa_db_select_with_pending(
			QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
			QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_profile_selectspec($handle, false),
			QA_FINAL_EXTERNAL_USERS ? null : qa_db_userfields_selectspec(),
Gideon Greenspan committed
57
			QA_FINAL_EXTERNAL_USERS ? null : qa_db_recent_messages_selectspec(null, null, $handle, false, qa_opt_if_loaded('page_size_wall')),
Gideon Greenspan committed
58 59 60 61 62
			qa_db_user_points_selectspec($identifier),
			qa_db_user_levels_selectspec($identifier, QA_FINAL_EXTERNAL_USERS, true),
			qa_db_category_nav_selectspec(null, true),
			qa_db_user_rank_selectspec($identifier)
		);
Scott Vivian committed
63

Gideon Greenspan committed
64 65 66 67
	if (!QA_FINAL_EXTERNAL_USERS)
		foreach ($userfields as $index => $userfield)
			if ( isset($userfield['permit']) && qa_permit_value_error($userfield['permit'], $loginuserid, qa_get_logged_in_level(), qa_get_logged_in_flags()) )
				unset($userfields[$index]); // don't pay attention to user fields we're not allowed to view
Scott Vivian committed
68

Gideon Greenspan committed
69 70

//	Check the user exists and work out what can and can't be set (if not using single sign-on)
Scott Vivian committed
71

Gideon Greenspan committed
72
	$errors=array();
Scott Vivian committed
73

Gideon Greenspan committed
74 75 76 77
	$loginlevel=qa_get_logged_in_level();

	if (!QA_FINAL_EXTERNAL_USERS) { // if we're using integrated user management, we can know and show more
		require_once QA_INCLUDE_DIR.'qa-app-messages.php';
Scott Vivian committed
78

Gideon Greenspan committed
79 80
		if ((!is_array($userpoints)) && !is_array($useraccount))
			return include QA_INCLUDE_DIR.'qa-page-not-found.php';
Scott Vivian committed
81

Gideon Greenspan committed
82 83 84
		$userid=$useraccount['userid'];
		$fieldseditable=false;
		$maxlevelassign=null;
Scott Vivian committed
85

Gideon Greenspan committed
86 87 88
		$maxuserlevel=$useraccount['level'];
		foreach ($userlevels as $userlevel)
			$maxuserlevel=max($maxuserlevel, $userlevel['level']);
Scott Vivian committed
89

Gideon Greenspan committed
90 91 92 93 94 95
		if (
			isset($loginuserid) &&
			($loginuserid!=$userid) &&
			(($loginlevel>=QA_USER_LEVEL_SUPER) || ($loginlevel>$maxuserlevel)) &&
			(!qa_user_permit_error())
		) { // can't change self - or someone on your level (or higher, obviously) unless you're a super admin
Scott Vivian committed
96

Gideon Greenspan committed
97 98 99 100 101 102 103 104
			if ($loginlevel>=QA_USER_LEVEL_SUPER)
				$maxlevelassign=QA_USER_LEVEL_SUPER;

			elseif ($loginlevel>=QA_USER_LEVEL_ADMIN)
				$maxlevelassign=QA_USER_LEVEL_MODERATOR;

			elseif ($loginlevel>=QA_USER_LEVEL_MODERATOR)
				$maxlevelassign=QA_USER_LEVEL_EXPERT;
Scott Vivian committed
105

Gideon Greenspan committed
106 107
			if ($loginlevel>=QA_USER_LEVEL_ADMIN)
				$fieldseditable=true;
Scott Vivian committed
108

Gideon Greenspan committed
109 110 111
			if (isset($maxlevelassign) && ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED))
				$maxlevelassign=min($maxlevelassign, QA_USER_LEVEL_EDITOR); // if blocked, can't promote too high
		}
Scott Vivian committed
112

Gideon Greenspan committed
113 114 115
		$approvebutton=isset($maxlevelassign) && ($useraccount['level']<QA_USER_LEVEL_APPROVED) && ($maxlevelassign>=QA_USER_LEVEL_APPROVED) && (!($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED)) && qa_opt('moderate_users');
		$usereditbutton=$fieldseditable || isset($maxlevelassign);
		$userediting=$usereditbutton && (qa_get_state()=='edit');
Scott Vivian committed
116

Gideon Greenspan committed
117
		$wallposterrorhtml=qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
Scott Vivian committed
118

Gideon Greenspan committed
119
	//	This code is similar but not identical to that in to qq-page-user-wall.php
Scott Vivian committed
120

Gideon Greenspan committed
121
		$usermessages=array_slice($usermessages, 0, qa_opt('page_size_wall'));
Gideon Greenspan committed
122
		$usermessages=qa_wall_posts_add_rules($usermessages, 0);
Scott Vivian committed
123

Gideon Greenspan committed
124 125 126 127
		foreach ($usermessages as $message)
			if ($message['deleteable'] && qa_clicked('m'.$message['messageid'].'_dodelete')) {
				if (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
					$errors['page']=qa_lang_html('misc/form_security_again');
Scott Vivian committed
128

Gideon Greenspan committed
129 130 131 132 133 134 135 136 137 138 139 140
				else {
					qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
					qa_redirect(qa_request(), null, null, null, 'wall');
				}
			}
	}


//	Process edit or save button for user, and other actions

	if (!QA_FINAL_EXTERNAL_USERS) {
		$reloaduser=false;
Scott Vivian committed
141

Gideon Greenspan committed
142 143 144
		if ($usereditbutton) {
			if (qa_clicked('docancel'))
				qa_redirect(qa_request());
Scott Vivian committed
145

Gideon Greenspan committed
146 147
			elseif (qa_clicked('doedit'))
				qa_redirect(qa_request(), array('state' => 'edit'));
Scott Vivian committed
148

Gideon Greenspan committed
149 150 151
			elseif (qa_clicked('dosave')) {
				require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
				require_once QA_INCLUDE_DIR.'qa-db-users.php';
Scott Vivian committed
152

Gideon Greenspan committed
153
				$inemail=qa_post_text('email');
Scott Vivian committed
154

Gideon Greenspan committed
155 156 157
				$inprofile=array();
				foreach ($userfields as $userfield)
					$inprofile[$userfield['fieldid']]=qa_post_text('field_'.$userfield['fieldid']);
Scott Vivian committed
158

Gideon Greenspan committed
159 160 161
				if (!qa_check_form_security_code('user-edit-'.$handle, qa_post_text('code'))) {
					$errors['page']=qa_lang_html('misc/form_security_again');
					$userediting=true;
Scott Vivian committed
162

Gideon Greenspan committed
163 164 165 166
				} else {
					if (qa_post_text('removeavatar')) {
						qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_AVATAR, false);
						qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_GRAVATAR, false);
Scott Vivian committed
167

Gideon Greenspan committed
168 169
						if (isset($useraccount['avatarblobid'])) {
							require_once QA_INCLUDE_DIR.'qa-app-blobs.php';
Scott Vivian committed
170

Gideon Greenspan committed
171 172 173 174 175 176
							qa_db_user_set($userid, 'avatarblobid', null);
							qa_db_user_set($userid, 'avatarwidth', null);
							qa_db_user_set($userid, 'avatarheight', null);
							qa_delete_blob($useraccount['avatarblobid']);
						}
					}
Scott Vivian committed
177

Gideon Greenspan committed
178 179 180 181
					if ($fieldseditable) {
						$filterhandle=$handle; // we're not filtering the handle...
						$errors=qa_handle_email_filter($filterhandle, $inemail, $useraccount);
						unset($errors['handle']); // ...and we don't care about any errors in it
Scott Vivian committed
182

Gideon Greenspan committed
183 184 185 186 187
						if (!isset($errors['email']))
							if ($inemail != $useraccount['email']) {
								qa_db_user_set($userid, 'email', $inemail);
								qa_db_user_set_flag($userid, QA_USER_FLAGS_EMAIL_CONFIRMED, false);
							}
Scott Vivian committed
188

Gideon Greenspan committed
189 190 191 192 193
						if (count($inprofile)) {
							$filtermodules=qa_load_modules_with('filter', 'filter_profile');
							foreach ($filtermodules as $filtermodule)
								$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
						}
Scott Vivian committed
194

Gideon Greenspan committed
195 196 197
						foreach ($userfields as $userfield)
							if (!isset($errors[$userfield['fieldid']]))
								qa_db_user_profile_set($userid, $userfield['title'], $inprofile[$userfield['fieldid']]);
Scott Vivian committed
198

Gideon Greenspan committed
199 200
						if (count($errors))
							$userediting=true;
Scott Vivian committed
201

Gideon Greenspan committed
202 203 204 205 206
						qa_report_event('u_edit', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array(
							'userid' => $userid,
							'handle' => $useraccount['handle'],
						));
					}
Scott Vivian committed
207

Gideon Greenspan committed
208 209
					if (isset($maxlevelassign)) {
						$inlevel=min($maxlevelassign, (int)qa_post_text('level')); // constrain based on maximum permitted to prevent simple browser-based attack
Gideon Greenspan committed
210 211
						if ($inlevel!=$useraccount['level'])
							qa_set_user_level($userid, $useraccount['handle'], $inlevel, $useraccount['level']);
Scott Vivian committed
212

Gideon Greenspan committed
213 214
						if (qa_using_categories()) {
							$inuserlevels=array();
Scott Vivian committed
215

Gideon Greenspan committed
216 217 218 219
							for ($index=1; $index<=999; $index++) {
								$inlevel=qa_post_text('uc_'.$index.'_level');
								if (!isset($inlevel))
									break;
Scott Vivian committed
220

Gideon Greenspan committed
221
								$categoryid=qa_get_category_field_value('uc_'.$index.'_cat');
Scott Vivian committed
222

Gideon Greenspan committed
223 224 225 226 227 228 229
								if (strlen($categoryid) && strlen($inlevel))
									$inuserlevels[]=array(
										'entitytype' => QA_ENTITY_CATEGORY,
										'entityid' => $categoryid,
										'level' => min($maxlevelassign, (int)$inlevel),
									);
							}
Scott Vivian committed
230

Gideon Greenspan committed
231 232 233
							qa_db_user_levels_set($userid, $inuserlevels);
						}
					}
Scott Vivian committed
234

Gideon Greenspan committed
235 236
					if (empty($errors))
						qa_redirect(qa_request());
Scott Vivian committed
237

Gideon Greenspan committed
238
					list($useraccount, $userprofile, $userlevels)=qa_db_select_with_pending(
Gideon Greenspan committed
239
						qa_db_user_account_selectspec($userid, true),
Gideon Greenspan committed
240
						qa_db_user_profile_selectspec($userid, true),
Scott Vivian committed
241
						qa_db_user_levels_selectspec($userid, true, true)
Gideon Greenspan committed
242 243 244 245
					);
				}
			}
		}
Scott Vivian committed
246

Gideon Greenspan committed
247 248 249
		if (qa_clicked('doapprove') || qa_clicked('doblock') || qa_clicked('dounblock') || qa_clicked('dohideall') || qa_clicked('dodelete')) {
			if (!qa_check_form_security_code('user-'.$handle, qa_post_text('code')))
				$errors['page']=qa_lang_html('misc/form_security_again');
Scott Vivian committed
250

Gideon Greenspan committed
251 252 253 254 255 256
			else {
				if ($approvebutton && qa_clicked('doapprove')) {
					require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
					qa_set_user_level($userid, $useraccount['handle'], QA_USER_LEVEL_APPROVED, $useraccount['level']);
					qa_redirect(qa_request());
				}
Scott Vivian committed
257

Gideon Greenspan committed
258 259 260
				if (isset($maxlevelassign) && ($maxuserlevel<QA_USER_LEVEL_MODERATOR)) {
					if (qa_clicked('doblock')) {
						require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
Scott Vivian committed
261

Gideon Greenspan committed
262 263 264
						qa_set_user_blocked($userid, $useraccount['handle'], true);
						qa_redirect(qa_request());
					}
Scott Vivian committed
265

Gideon Greenspan committed
266 267 268 269 270 271
					if (qa_clicked('dounblock')) {
						require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';

						qa_set_user_blocked($userid, $useraccount['handle'], false);
						qa_redirect(qa_request());
					}
Scott Vivian committed
272

Gideon Greenspan committed
273 274 275
					if (qa_clicked('dohideall') && !qa_user_permit_error('permit_hide_show')) {
						require_once QA_INCLUDE_DIR.'qa-db-admin.php';
						require_once QA_INCLUDE_DIR.'qa-app-posts.php';
Scott Vivian committed
276

Gideon Greenspan committed
277
						$postids=qa_db_get_user_visible_postids($userid);
Scott Vivian committed
278

Gideon Greenspan committed
279 280
						foreach ($postids as $postid)
							qa_post_set_hidden($postid, true, $loginuserid);
Scott Vivian committed
281

Gideon Greenspan committed
282 283
						qa_redirect(qa_request());
					}
Scott Vivian committed
284

Gideon Greenspan committed
285 286
					if (qa_clicked('dodelete') && ($loginlevel>=QA_USER_LEVEL_ADMIN)) {
						require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
Scott Vivian committed
287

Gideon Greenspan committed
288
						qa_delete_user($userid);
Scott Vivian committed
289

Gideon Greenspan committed
290 291 292 293
						qa_report_event('u_delete', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array(
							'userid' => $userid,
							'handle' => $useraccount['handle'],
						));
Scott Vivian committed
294

Gideon Greenspan committed
295 296 297 298 299
						qa_redirect('users');
					}
				}
			}
		}
Scott Vivian committed
300 301


Gideon Greenspan committed
302 303
		if (qa_clicked('dowallpost')) {
			$inmessage=qa_post_text('message');
Scott Vivian committed
304

Gideon Greenspan committed
305 306
			if (!strlen($inmessage))
				$errors['message']=qa_lang('profile/post_wall_empty');
Scott Vivian committed
307

Gideon Greenspan committed
308 309
			elseif (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
				$errors['message']=qa_lang_html('misc/form_security_again');
Scott Vivian committed
310

Gideon Greenspan committed
311 312 313 314 315 316 317 318 319 320 321 322
			elseif (!$wallposterrorhtml) {
				qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $userid, $useraccount['handle'], $inmessage, '');
				qa_redirect(qa_request(), null, null, null, 'wall');
			}
		}
	}


//	Process bonus setting button

	if ( ($loginlevel>=QA_USER_LEVEL_ADMIN) && qa_clicked('dosetbonus') ) {
		require_once QA_INCLUDE_DIR.'qa-db-points.php';
Scott Vivian committed
323

Gideon Greenspan committed
324
		$inbonus=(int)qa_post_text('bonus');
Scott Vivian committed
325

Gideon Greenspan committed
326 327
		if (!qa_check_form_security_code('user-activity-'.$handle, qa_post_text('code')))
			$errors['page']=qa_lang_html('misc/form_security_again');
Scott Vivian committed
328

Gideon Greenspan committed
329 330 331 332 333 334
		else {
			qa_db_points_set_bonus($userid, $inbonus);
			qa_db_points_update_ifuser($userid, null);
			qa_redirect(qa_request(), null, null, null, 'activity');
		}
	}
Scott Vivian committed
335

Gideon Greenspan committed
336 337

//	Prepare content for theme
Scott Vivian committed
338

Gideon Greenspan committed
339
	$qa_content=qa_content_prepare();
Scott Vivian committed
340

Gideon Greenspan committed
341 342 343 344 345 346
	$qa_content['title']=qa_lang_html_sub('profile/user_x', $userhtml);
	$qa_content['error']=@$errors['page'];

	if (isset($loginuserid) && !QA_FINAL_EXTERNAL_USERS) {
		$favoritemap=qa_get_favorite_non_qs_map();
		$favorite=@$favoritemap['user'][$useraccount['userid']];
Scott Vivian committed
347

Gideon Greenspan committed
348 349 350 351 352 353 354 355
		$qa_content['favorite']=qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite,
			qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'users/add_user_x_favorites', $handle));
	}

	$qa_content['script_rel'][]='qa-content/qa-user.js?'.QA_VERSION;


//	General information about the user, only available if we're using internal user management
Scott Vivian committed
356

Gideon Greenspan committed
357
	if (!QA_FINAL_EXTERNAL_USERS) {
358 359 360
		$membertime = qa_time_to_string(qa_opt('db_time')-$useraccount['created']);
		$joindate = qa_when_to_html($useraccount['created'], 0);

Gideon Greenspan committed
361
		$qa_content['form_profile']=array(
Gideon Greenspan committed
362
			'tags' => 'method="post" action="'.qa_self_html().'"',
Scott Vivian committed
363

Gideon Greenspan committed
364
			'style' => 'wide',
Scott Vivian committed
365

Gideon Greenspan committed
366 367 368 369 370 371 372 373 374
			'fields' => array(
				'avatar' => array(
					'type' => 'image',
					'style' => 'tall',
					'label' => '',
					'html' => qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'],
						$useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size')),
					'id' => 'avatar',
				),
Scott Vivian committed
375

Gideon Greenspan committed
376
				'removeavatar' => null,
Scott Vivian committed
377

Gideon Greenspan committed
378 379 380
				'duration' => array(
					'type' => 'static',
					'label' => qa_lang_html('users/member_for'),
381
					'value' => qa_html( $membertime . ' (' . qa_lang_sub('main/since_x', $joindate['data']) . ')' ),
Gideon Greenspan committed
382 383
					'id' => 'duration',
				),
Scott Vivian committed
384

Gideon Greenspan committed
385 386 387
				'level' => array(
					'type' => 'static',
					'label' => qa_lang_html('users/member_type'),
Gideon Greenspan committed
388
					'tags' => 'name="level"',
Gideon Greenspan committed
389 390 391 392 393 394
					'value' => qa_html(qa_user_level_string($useraccount['level'])),
					'note' => (($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED) && isset($maxlevelassign)) ? qa_lang_html('users/user_blocked') : '',
					'id' => 'level',
				),
			),
		);
Scott Vivian committed
395

Gideon Greenspan committed
396 397
		if (empty($qa_content['form_profile']['fields']['avatar']['html']))
			unset($qa_content['form_profile']['fields']['avatar']);
Scott Vivian committed
398 399


Gideon Greenspan committed
400
	//	Private message link
Scott Vivian committed
401

Gideon Greenspan committed
402 403
		if ( qa_opt('allow_private_messages') && isset($loginuserid) && ($loginuserid!=$userid) && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) && !$userediting )
			$qa_content['form_profile']['fields']['level']['value'].=strtr(qa_lang_html('profile/send_private_message'), array(
Gideon Greenspan committed
404 405
				'^1' => '<a href="'.qa_path_html('message/'.$handle).'">',
				'^2' => '</a>',
Gideon Greenspan committed
406
			));
Scott Vivian committed
407 408


Gideon Greenspan committed
409
	//	Levels editing or viewing (add category-specific levels)
Scott Vivian committed
410

Gideon Greenspan committed
411 412 413 414
		if ($userediting) {

			if (isset($maxlevelassign)) {
				$qa_content['form_profile']['fields']['level']['type']='select';
Scott Vivian committed
415

Gideon Greenspan committed
416 417 418
				$showlevels=array(QA_USER_LEVEL_BASIC);
				if (qa_opt('moderate_users'))
					$showlevels[]=QA_USER_LEVEL_APPROVED;
Scott Vivian committed
419

Gideon Greenspan committed
420
				array_push($showlevels, QA_USER_LEVEL_EXPERT, QA_USER_LEVEL_EDITOR, QA_USER_LEVEL_MODERATOR, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_SUPER);
Scott Vivian committed
421

Gideon Greenspan committed
422
				$leveloptions=array();
Gideon Greenspan committed
423
				$catleveloptions=array('' => qa_lang_html('users/category_level_none'));
Gideon Greenspan committed
424 425 426 427 428 429 430

				foreach ($showlevels as $showlevel)
					if ($showlevel<=$maxlevelassign) {
						$leveloptions[$showlevel]=qa_html(qa_user_level_string($showlevel));
						if ($showlevel>QA_USER_LEVEL_BASIC)
							$catleveloptions[$showlevel]=$leveloptions[$showlevel];
					}
Scott Vivian committed
431

Gideon Greenspan committed
432 433
				$qa_content['form_profile']['fields']['level']['options']=$leveloptions;

Scott Vivian committed
434

Gideon Greenspan committed
435
			//	Category-specific levels
Scott Vivian committed
436

Gideon Greenspan committed
437
				if (qa_using_categories()) {
Gideon Greenspan committed
438
					$catleveladd=qa_get('catleveladd') ? true : false;
Scott Vivian committed
439

Gideon Greenspan committed
440 441
					if ((!$catleveladd) && !count($userlevels))
						$qa_content['form_profile']['fields']['level']['suffix']=strtr(qa_lang_html('users/category_level_add'), array(
Gideon Greenspan committed
442 443
							'^1' => '<a href="'.qa_path_html(qa_request(), array('state' => 'edit', 'catleveladd' => 1)).'">',
							'^2' => '</a>',
Gideon Greenspan committed
444 445 446
						));
					else
						$qa_content['form_profile']['fields']['level']['suffix']=qa_lang_html('users/level_in_general');
Scott Vivian committed
447

Gideon Greenspan committed
448 449
					if ($catleveladd || count($userlevels))
						$userlevels[]=array('entitytype' => QA_ENTITY_CATEGORY);
Scott Vivian committed
450

Gideon Greenspan committed
451 452 453 454
					$index=0;
					foreach ($userlevels as $userlevel)
						if ($userlevel['entitytype']==QA_ENTITY_CATEGORY) {
							$index++;
Gideon Greenspan committed
455
							$id='ls_'.+$index;
Scott Vivian committed
456

Gideon Greenspan committed
457 458 459
							$qa_content['form_profile']['fields']['uc_'.$index.'_level']=array(
								'label' => qa_lang_html('users/category_level_label'),
								'type' => 'select',
Gideon Greenspan committed
460
								'tags' => 'name="uc_'.$index.'_level" id="'.qa_html($id).'" onchange="this.qa_prev=this.options[this.selectedIndex].value;"',
Gideon Greenspan committed
461 462 463 464
								'options' => $catleveloptions,
								'value' => isset($userlevel['level']) ? qa_html(qa_user_level_string($userlevel['level'])) : '',
								'suffix' => qa_lang_html('users/category_level_in'),
							);
Scott Vivian committed
465

Gideon Greenspan committed
466
							$qa_content['form_profile']['fields']['uc_'.$index.'_cat']=array();
Scott Vivian committed
467

Gideon Greenspan committed
468 469 470 471
							if (isset($userlevel['entityid']))
								$fieldnavcategories=qa_db_select_with_pending(qa_db_category_nav_selectspec($userlevel['entityid'], true));
							else
								$fieldnavcategories=$navcategories;
Scott Vivian committed
472

Gideon Greenspan committed
473 474
							qa_set_up_category_field($qa_content, $qa_content['form_profile']['fields']['uc_'.$index.'_cat'],
								'uc_'.$index.'_cat', $fieldnavcategories, @$userlevel['entityid'], true, true);
Scott Vivian committed
475

Gideon Greenspan committed
476 477
							unset($qa_content['form_profile']['fields']['uc_'.$index.'_cat']['note']);
						}
Gideon Greenspan committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

					$qa_content['script_lines'][]=array(
						"function qa_update_category_levels()",
						"{",
						"\tglob=document.getElementById('level_select');",
						"\tif (!glob)",
						"\t\treturn;",
						"\tvar opts=glob.options;",
						"\tvar lev=parseInt(opts[glob.selectedIndex].value);",
						"\tfor (var i=1; i<9999; i++) {",
						"\t\tvar sel=document.getElementById('ls_'+i);",
						"\t\tif (!sel)",
						"\t\t\tbreak;",
						"\t\tsel.qa_prev=sel.qa_prev || sel.options[sel.selectedIndex].value;",
						"\t\tsel.options.length=1;", // just leaves "no upgrade" element
						"\t\tfor (var j=0; j<opts.length; j++)",
						"\t\t\tif (parseInt(opts[j].value)>lev)",
						"\t\t\t\tsel.options[sel.options.length]=new Option(opts[j].text, opts[j].value, false, (opts[j].value==sel.qa_prev));",
						"\t}",
						"}",
					);
Scott Vivian committed
499

Gideon Greenspan committed
500 501 502
					$qa_content['script_onloads'][]=array(
						"qa_update_category_levels();",
					);
Scott Vivian committed
503

Gideon Greenspan committed
504
					$qa_content['form_profile']['fields']['level']['tags'].=' id="level_select" onchange="qa_update_category_levels();"';
Scott Vivian committed
505

Gideon Greenspan committed
506 507
				}
			}
Scott Vivian committed
508

Gideon Greenspan committed
509 510 511
		} else {
			foreach ($userlevels as $userlevel)
				if ( ($userlevel['entitytype']==QA_ENTITY_CATEGORY) && ($userlevel['level']>$useraccount['level']) )
Gideon Greenspan committed
512
					$qa_content['form_profile']['fields']['level']['value'].='<br/>'.
Gideon Greenspan committed
513 514
						strtr(qa_lang_html('users/level_for_category'), array(
							'^1' => qa_html(qa_user_level_string($userlevel['level'])),
Gideon Greenspan committed
515
							'^2' => '<a href="'.qa_path_html(implode('/', array_reverse(explode('/', $userlevel['backpath'])))).'">'.qa_html($userlevel['title']).'</a>',
Gideon Greenspan committed
516 517 518
						));
		}

Scott Vivian committed
519

Gideon Greenspan committed
520
	//	Show any extra privileges due to user's level or their points
Scott Vivian committed
521

Gideon Greenspan committed
522 523
		$showpermits=array();
		$permitoptions=qa_get_permit_options();
Scott Vivian committed
524

Gideon Greenspan committed
525 526 527 528 529 530 531 532 533 534
		foreach ($permitoptions as $permitoption)
			if ( // if not available to approved and email confirmed users with no points, but yes available to the user, it's something special
				qa_permit_error($permitoption, $userid, QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_EMAIL_CONFIRMED, 0) &&
				!qa_permit_error($permitoption, $userid, $useraccount['level'], $useraccount['flags'], $userpoints['points'])
			) {
				if ($permitoption=='permit_retag_cat')
					$showpermits[]=qa_lang(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
				else
					$showpermits[]=qa_lang('profile/'.$permitoption); // then show it as an extra priviliege
			}
Scott Vivian committed
535

Gideon Greenspan committed
536 537 538 539 540 541 542 543
		if (count($showpermits))
			$qa_content['form_profile']['fields']['permits']=array(
				'type' => 'static',
				'label' => qa_lang_html('profile/extra_privileges'),
				'value' => qa_html(implode("\n", $showpermits), true),
				'rows' => count($showpermits),
				'id' => 'permits',
			);
Scott Vivian committed
544 545


Gideon Greenspan committed
546
	//	Show email address only if we're an administrator
Scott Vivian committed
547

Gideon Greenspan committed
548 549 550 551
		if (($loginlevel>=QA_USER_LEVEL_ADMIN) && !qa_user_permit_error()) {
			$doconfirms=qa_opt('confirm_user_emails') && ($useraccount['level']<QA_USER_LEVEL_EXPERT);
			$isconfirmed=($useraccount['flags'] & QA_USER_FLAGS_EMAIL_CONFIRMED) ? true : false;
			$htmlemail=qa_html(isset($inemail) ? $inemail : $useraccount['email']);
Scott Vivian committed
552

Gideon Greenspan committed
553 554 555
			$qa_content['form_profile']['fields']['email']=array(
				'type' => $userediting ? 'text' : 'static',
				'label' => qa_lang_html('users/email_label'),
Gideon Greenspan committed
556 557
				'tags' => 'name="email"',
				'value' => $userediting ? $htmlemail : ('<a href="mailto:'.$htmlemail.'">'.$htmlemail.'</a>'),
Gideon Greenspan committed
558 559 560 561 562 563 564
				'error' => qa_html(@$errors['email']),
				'note' => ($doconfirms ? (qa_lang_html($isconfirmed ? 'users/email_confirmed' : 'users/email_not_confirmed').' ') : '').
					($userediting ? '' : qa_lang_html('users/only_shown_admins')),
				'id' => 'email',
			);

		}
Scott Vivian committed
565 566


Gideon Greenspan committed
567
	//	Show IP addresses and times for last login or write - only if we're a moderator or higher
Scott Vivian committed
568

Gideon Greenspan committed
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
		if (($loginlevel>=QA_USER_LEVEL_MODERATOR) && !qa_user_permit_error()) {
			$qa_content['form_profile']['fields']['lastlogin']=array(
				'type' => 'static',
				'label' => qa_lang_html('users/last_login_label'),
				'value' =>
					strtr(qa_lang_html('users/x_ago_from_y'), array(
						'^1' => qa_time_to_string(qa_opt('db_time')-$useraccount['loggedin']),
						'^2' => qa_ip_anchor_html($useraccount['loginip']),
					)),
				'note' => $userediting ? null : qa_lang_html('users/only_shown_moderators'),
				'id' => 'lastlogin',
			);

			if (isset($useraccount['written']))
				$qa_content['form_profile']['fields']['lastwrite']=array(
					'type' => 'static',
					'label' => qa_lang_html('users/last_write_label'),
					'value' =>
						strtr(qa_lang_html('users/x_ago_from_y'), array(
							'^1' => qa_time_to_string(qa_opt('db_time')-$useraccount['written']),
							'^2' => qa_ip_anchor_html($useraccount['writeip']),
						)),
					'note' => $userediting ? null : qa_lang_html('users/only_shown_moderators'),
					'id' => 'lastwrite',
				);
			else
				unset($qa_content['form_profile']['fields']['lastwrite']);

		}
Scott Vivian committed
598

Gideon Greenspan committed
599 600 601 602

	//	Show other profile fields

		$fieldsediting=$fieldseditable && $userediting;
Scott Vivian committed
603 604

		foreach ($userfields as $userfield) {
Gideon Greenspan committed
605 606 607 608 609 610 611 612 613 614
			if (($userfield['flags'] & QA_FIELD_FLAGS_LINK_URL) && !$fieldsediting)
				$valuehtml=qa_url_to_html_link(@$userprofile[$userfield['title']], qa_opt('links_in_new_window'));

			else {
				$value=@$inprofile[$userfield['fieldid']];
				if (!isset($value))
					$value=@$userprofile[$userfield['title']];

				$valuehtml=qa_html($value, (($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) && !$fieldsediting) ? true : false);
			}
Scott Vivian committed
615

Gideon Greenspan committed
616 617 618
			$label=trim(qa_user_userfield_label($userfield), ':');
			if (strlen($label))
				$label.=':';
Scott Vivian committed
619

Gideon Greenspan committed
620 621 622 623 624 625 626 627 628 629 630
			$notehtml=null;
			if (isset($userfield['permit']) && !$userediting) {
				if ($userfield['permit']<=QA_PERMIT_ADMINS)
					$notehtml=qa_lang_html('users/only_shown_admins');
				elseif ($userfield['permit']<=QA_PERMIT_MODERATORS)
					$notehtml=qa_lang_html('users/only_shown_moderators');
				elseif ($userfield['permit']<=QA_PERMIT_EDITORS)
					$notehtml=qa_lang_html('users/only_shown_editors');
				elseif ($userfield['permit']<=QA_PERMIT_EXPERTS)
					$notehtml=qa_lang_html('users/only_shown_experts');
			}
Scott Vivian committed
631

Gideon Greenspan committed
632 633 634
			$qa_content['form_profile']['fields'][$userfield['title']]=array(
				'type' => $fieldsediting ? 'text' : 'static',
				'label' => qa_html($label),
Gideon Greenspan committed
635
				'tags' => 'name="field_'.$userfield['fieldid'].'"',
Gideon Greenspan committed
636 637 638 639 640 641 642
				'value' => $valuehtml,
				'error' => qa_html(@$errors[$userfield['fieldid']]),
				'note' => $notehtml,
				'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
				'id' => 'userfield-'.$userfield['fieldid'],
			);
		}
Scott Vivian committed
643

Gideon Greenspan committed
644 645

	//	Edit form or button, if appropriate
Scott Vivian committed
646

Gideon Greenspan committed
647 648 649 650 651 652 653 654 655
		if ($userediting) {

			if (
				(qa_opt('avatar_allow_gravatar') && ($useraccount['flags'] & QA_USER_FLAGS_SHOW_GRAVATAR)) ||
				(qa_opt('avatar_allow_upload') && (($useraccount['flags'] & QA_USER_FLAGS_SHOW_AVATAR)) && isset($useraccount['avatarblobid']))
			) {
				$qa_content['form_profile']['fields']['removeavatar']=array(
					'type' => 'checkbox',
					'label' => qa_lang_html('users/remove_avatar'),
Gideon Greenspan committed
656
					'tags' => 'name="removeavatar"',
Gideon Greenspan committed
657 658
				);
			}
Scott Vivian committed
659

Gideon Greenspan committed
660 661
			$qa_content['form_profile']['buttons']=array(
				'save' => array(
Gideon Greenspan committed
662
					'tags' => 'onclick="qa_show_waiting_after(this, false);"',
Gideon Greenspan committed
663 664
					'label' => qa_lang_html('users/save_user'),
				),
Scott Vivian committed
665

Gideon Greenspan committed
666
				'cancel' => array(
Gideon Greenspan committed
667
					'tags' => 'name="docancel"',
Gideon Greenspan committed
668 669 670
					'label' => qa_lang_html('main/cancel_button'),
				),
			);
Scott Vivian committed
671

Gideon Greenspan committed
672 673 674 675 676 677 678
			$qa_content['form_profile']['hidden']=array(
				'dosave' => '1',
				'code' => qa_get_form_security_code('user-edit-'.$handle),
			);

		} elseif ($usereditbutton) {
			$qa_content['form_profile']['buttons']=array();
Scott Vivian committed
679

Gideon Greenspan committed
680 681
			if ($approvebutton)
				$qa_content['form_profile']['buttons']['approve']=array(
Gideon Greenspan committed
682
					'tags' => 'name="doapprove"',
Gideon Greenspan committed
683 684
					'label' => qa_lang_html('users/approve_user_button'),
				);
Scott Vivian committed
685

Gideon Greenspan committed
686
			$qa_content['form_profile']['buttons']['edit']=array(
Gideon Greenspan committed
687
				'tags' => 'name="doedit"',
Gideon Greenspan committed
688 689
				'label' => qa_lang_html('users/edit_user_button'),
			);
Scott Vivian committed
690

Gideon Greenspan committed
691 692 693
			if (isset($maxlevelassign) && ($useraccount['level']<QA_USER_LEVEL_MODERATOR)) {
				if ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED) {
					$qa_content['form_profile']['buttons']['unblock']=array(
Gideon Greenspan committed
694
						'tags' => 'name="dounblock"',
Gideon Greenspan committed
695 696
						'label' => qa_lang_html('users/unblock_user_button'),
					);
Scott Vivian committed
697

Gideon Greenspan committed
698 699
					if (!qa_user_permit_error('permit_hide_show'))
						$qa_content['form_profile']['buttons']['hideall']=array(
Gideon Greenspan committed
700
							'tags' => 'name="dohideall" onclick="qa_show_waiting_after(this, false);"',
Gideon Greenspan committed
701 702
							'label' => qa_lang_html('users/hide_all_user_button'),
						);
Scott Vivian committed
703

Gideon Greenspan committed
704 705
					if ($loginlevel>=QA_USER_LEVEL_ADMIN)
						$qa_content['form_profile']['buttons']['delete']=array(
Gideon Greenspan committed
706
							'tags' => 'name="dodelete" onclick="qa_show_waiting_after(this, false);"',
Gideon Greenspan committed
707 708
							'label' => qa_lang_html('users/delete_user_button'),
						);
Scott Vivian committed
709

Gideon Greenspan committed
710 711
				} else
					$qa_content['form_profile']['buttons']['block']=array(
Gideon Greenspan committed
712
						'tags' => 'name="doblock"',
Gideon Greenspan committed
713 714
						'label' => qa_lang_html('users/block_user_button'),
					);
Scott Vivian committed
715

Gideon Greenspan committed
716 717 718 719
				$qa_content['form_profile']['hidden']=array(
					'code' => qa_get_form_security_code('user-'.$handle),
				);
			}
Gideon Greenspan committed
720 721 722 723 724 725 726 727

		} elseif (isset($loginuserid) && ($loginuserid==$userid))
			$qa_content['form_profile']['buttons']=array(
				'account' => array(
					'tags' => 'name="doaccount"',
					'label' => qa_lang_html('users/edit_profile'),
				),
			);
Scott Vivian committed
728 729


Gideon Greenspan committed
730 731
		if (!is_array($qa_content['form_profile']['fields']['removeavatar']))
			unset($qa_content['form_profile']['fields']['removeavatar']);
Scott Vivian committed
732

Gideon Greenspan committed
733 734 735
		$qa_content['raw']['account']=$useraccount; // for plugin layers to access
		$qa_content['raw']['profile']=$userprofile;
	}
Scott Vivian committed
736

Gideon Greenspan committed
737 738 739 740

//	Information about user activity, available also with single sign-on integration

	$qa_content['form_activity']=array(
Gideon Greenspan committed
741
		'title' => '<a name="activity">'.qa_lang_html_sub('profile/activity_by_x', $userhtml).'</a>',
Scott Vivian committed
742

Gideon Greenspan committed
743
		'style' => 'wide',
Scott Vivian committed
744

Gideon Greenspan committed
745 746 747
		'fields' => array(
			'bonus' => array(
				'label' => qa_lang_html('profile/bonus_points'),
Gideon Greenspan committed
748
				'tags' => 'name="bonus"',
Gideon Greenspan committed
749 750 751 752 753
				'value' => qa_html(isset($inbonus) ? $inbonus : $userpoints['bonus']),
				'type' => 'number',
				'note' => qa_lang_html('users/only_shown_admins'),
				'id' => 'bonus',
			),
Scott Vivian committed
754

Gideon Greenspan committed
755 756 757 758
			'points' => array(
				'type' => 'static',
				'label' => qa_lang_html('profile/score'),
				'value' => (@$userpoints['points']==1)
Gideon Greenspan committed
759 760
					? qa_lang_html_sub('main/1_point', '<span class="qa-uf-user-points">1</span>', '1')
					: qa_lang_html_sub('main/x_points', '<span class="qa-uf-user-points">'.qa_html(number_format(@$userpoints['points'])).'</span>'),
Gideon Greenspan committed
761 762
				'id' => 'points',
			),
Scott Vivian committed
763

Gideon Greenspan committed
764 765 766 767 768 769
			'title' => array(
				'type' => 'static',
				'label' => qa_lang_html('profile/title'),
				'value' => qa_get_points_title_html(@$userpoints['points'], qa_get_points_to_titles()),
				'id' => 'title',
			),
Scott Vivian committed
770

Gideon Greenspan committed
771 772 773
			'questions' => array(
				'type' => 'static',
				'label' => qa_lang_html('profile/questions'),
Gideon Greenspan committed
774
				'value' => '<span class="qa-uf-user-q-posts">'.qa_html(number_format(@$userpoints['qposts'])).'</span>',
Gideon Greenspan committed
775 776
				'id' => 'questions',
			),
Scott Vivian committed
777

Gideon Greenspan committed
778 779 780
			'answers' => array(
				'type' => 'static',
				'label' => qa_lang_html('profile/answers'),
Gideon Greenspan committed
781
				'value' => '<span class="qa-uf-user-a-posts">'.qa_html(number_format(@$userpoints['aposts'])).'</span>',
Gideon Greenspan committed
782 783 784 785
				'id' => 'answers',
			),
		),
	);
Scott Vivian committed
786

Gideon Greenspan committed
787
	if ($loginlevel>=QA_USER_LEVEL_ADMIN) {
Gideon Greenspan committed
788
		$qa_content['form_activity']['tags']='method="post" action="'.qa_self_html().'"';
Scott Vivian committed
789

Gideon Greenspan committed
790 791
		$qa_content['form_activity']['buttons']=array(
			'setbonus' => array(
Gideon Greenspan committed
792
				'tags' => 'name="dosetbonus"',
Gideon Greenspan committed
793 794 795
				'label' => qa_lang_html('profile/set_bonus_button'),
			),
		);
Scott Vivian committed
796

Gideon Greenspan committed
797 798 799
		$qa_content['form_activity']['hidden']=array(
			'code' => qa_get_form_security_code('user-activity-'.$handle),
		);
Scott Vivian committed
800

Gideon Greenspan committed
801 802
	} else
		unset($qa_content['form_activity']['fields']['bonus']);
Scott Vivian committed
803

Gideon Greenspan committed
804 805
	if (!isset($qa_content['form_activity']['fields']['title']['value']))
		unset($qa_content['form_activity']['fields']['title']);
Scott Vivian committed
806

Gideon Greenspan committed
807 808 809 810
	if (qa_opt('comment_on_qs') || qa_opt('comment_on_as')) { // only show comment count if comments are enabled
		$qa_content['form_activity']['fields']['comments']=array(
			'type' => 'static',
			'label' => qa_lang_html('profile/comments'),
Gideon Greenspan committed
811
			'value' => '<span class="qa-uf-user-c-posts">'.qa_html(number_format(@$userpoints['cposts'])).'</span>',
Gideon Greenspan committed
812 813 814
			'id' => 'comments',
		);
	}
Scott Vivian committed
815

Gideon Greenspan committed
816 817
	if (qa_opt('voting_on_qs') || qa_opt('voting_on_as')) { // only show vote record if voting is enabled
		$votedonvalue='';
Scott Vivian committed
818

Gideon Greenspan committed
819 820 821
		if (qa_opt('voting_on_qs')) {
			$qvotes=@$userpoints['qupvotes']+@$userpoints['qdownvotes'];

Gideon Greenspan committed
822
			$innervalue='<span class="qa-uf-user-q-votes">'.number_format($qvotes).'</span>';
Gideon Greenspan committed
823 824
			$votedonvalue.=($qvotes==1) ? qa_lang_html_sub('main/1_question', $innervalue, '1')
				: qa_lang_html_sub('main/x_questions', $innervalue);
Scott Vivian committed
825

Gideon Greenspan committed
826 827 828
			if (qa_opt('voting_on_as'))
				$votedonvalue.=', ';
		}
Scott Vivian committed
829

Gideon Greenspan committed
830 831
		if (qa_opt('voting_on_as')) {
			$avotes=@$userpoints['aupvotes']+@$userpoints['adownvotes'];
Scott Vivian committed
832

Gideon Greenspan committed
833
			$innervalue='<span class="qa-uf-user-a-votes">'.number_format($avotes).'</span>';
Gideon Greenspan committed
834 835 836
			$votedonvalue.=($avotes==1) ? qa_lang_html_sub('main/1_answer', $innervalue, '1')
				: qa_lang_html_sub('main/x_answers', $innervalue);
		}
Scott Vivian committed
837

Gideon Greenspan committed
838 839 840 841 842 843
		$qa_content['form_activity']['fields']['votedon']=array(
			'type' => 'static',
			'label' => qa_lang_html('profile/voted_on'),
			'value' => $votedonvalue,
			'id' => 'votedon',
		);
Scott Vivian committed
844

Gideon Greenspan committed
845
		$upvotes=@$userpoints['qupvotes']+@$userpoints['aupvotes'];
Gideon Greenspan committed
846
		$innervalue='<span class="qa-uf-user-upvotes">'.number_format($upvotes).'</span>';
Gideon Greenspan committed
847
		$votegavevalue=(($upvotes==1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_up_votes', $innervalue)).', ';
Scott Vivian committed
848

Gideon Greenspan committed
849
		$downvotes=@$userpoints['qdownvotes']+@$userpoints['adownvotes'];
Gideon Greenspan committed
850
		$innervalue='<span class="qa-uf-user-downvotes">'.number_format($downvotes).'</span>';
Gideon Greenspan committed
851
		$votegavevalue.=($downvotes==1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_down_votes', $innervalue);
Scott Vivian committed
852

Gideon Greenspan committed
853 854 855 856 857 858 859
		$qa_content['form_activity']['fields']['votegave']=array(
			'type' => 'static',
			'label' => qa_lang_html('profile/gave_out'),
			'value' => $votegavevalue,
			'id' => 'votegave',
		);

Gideon Greenspan committed
860
		$innervalue='<span class="qa-uf-user-upvoteds">'.number_format(@$userpoints['upvoteds']).'</span>';
Gideon Greenspan committed
861 862
		$votegotvalue=((@$userpoints['upvoteds']==1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1')
			: qa_lang_html_sub('profile/x_up_votes', $innervalue)).', ';
Scott Vivian committed
863

Gideon Greenspan committed
864
		$innervalue='<span class="qa-uf-user-downvoteds">'.number_format(@$userpoints['downvoteds']).'</span>';
Gideon Greenspan committed
865 866 867 868 869 870 871 872 873 874
		$votegotvalue.=(@$userpoints['downvoteds']==1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1')
			: qa_lang_html_sub('profile/x_down_votes', $innervalue);

		$qa_content['form_activity']['fields']['votegot']=array(
			'type' => 'static',
			'label' => qa_lang_html('profile/received'),
			'value' => $votegotvalue,
			'id' => 'votegot',
		);
	}
Scott Vivian committed
875

Gideon Greenspan committed
876 877
	if (@$userpoints['points'])
		$qa_content['form_activity']['fields']['points']['value'].=
Gideon Greenspan committed
878
			qa_lang_html_sub('profile/ranked_x', '<span class="qa-uf-user-rank">'.number_format($userrank).'</span>');
Scott Vivian committed
879

Gideon Greenspan committed
880 881
	if (@$userpoints['aselects'])
		$qa_content['form_activity']['fields']['questions']['value'].=($userpoints['aselects']==1)
Gideon Greenspan committed
882 883
			? qa_lang_html_sub('profile/1_with_best_chosen', '<span class="qa-uf-user-q-selects">1</span>', '1')
			: qa_lang_html_sub('profile/x_with_best_chosen', '<span class="qa-uf-user-q-selects">'.number_format($userpoints['aselects']).'</span>');
Scott Vivian committed
884

Gideon Greenspan committed
885 886
	if (@$userpoints['aselecteds'])
		$qa_content['form_activity']['fields']['answers']['value'].=($userpoints['aselecteds']==1)
Gideon Greenspan committed
887 888
			? qa_lang_html_sub('profile/1_chosen_as_best', '<span class="qa-uf-user-a-selecteds">1</span>', '1')
			: qa_lang_html_sub('profile/x_chosen_as_best', '<span class="qa-uf-user-a-selecteds">'.number_format($userpoints['aselecteds']).'</span>');
Gideon Greenspan committed
889 890


Scott Vivian committed
891

Gideon Greenspan committed
892 893 894 895 896 897 898 899 900 901 902
//	For plugin layers to access

	$qa_content['raw']['userid']=$userid;
	$qa_content['raw']['points']=$userpoints;
	$qa_content['raw']['rank']=$userrank;


//	Wall posts

	if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('allow_user_walls')) {
		$qa_content['message_list']=array(
Gideon Greenspan committed
903
			'title' => '<a name="wall">'.qa_lang_html_sub('profile/wall_for_x', $userhtml).'</a>',
Scott Vivian committed
904

Gideon Greenspan committed
905
			'tags' => 'id="wallmessages"',
Scott Vivian committed
906

Gideon Greenspan committed
907
			'form' => array(
Gideon Greenspan committed
908
				'tags' => 'name="wallpost" method="post" action="'.qa_self_html().'#wall"',
Gideon Greenspan committed
909 910 911
				'style' => 'tall',
				'hidden' => array(
					'qa_click' => '', // for simulating clicks in Javascript
Gideon Greenspan committed
912 913 914
					'handle' => qa_html($useraccount['handle']),
					'start' => 0,
					'code' => qa_get_form_security_code('wall-'.$useraccount['handle']),
Gideon Greenspan committed
915 916
				),
			),
Scott Vivian committed
917

Gideon Greenspan committed
918 919
			'messages' => array(),
		);
Scott Vivian committed
920

Gideon Greenspan committed
921 922
		if ($wallposterrorhtml)
			$qa_content['message_list']['error']=$wallposterrorhtml; // an error that means we are not allowed to post
Scott Vivian committed
923

Gideon Greenspan committed
924 925 926
		else {
			$qa_content['message_list']['form']['fields']=array(
				'message' => array(
Gideon Greenspan committed
927
					'tags' => 'name="message" id="message"',
Gideon Greenspan committed
928 929 930 931 932
					'value' => qa_html(@$inmessage, false),
					'rows' => 2,
					'error' => qa_html(@$errors['message']),
				),
			);
Scott Vivian committed
933

Gideon Greenspan committed
934 935
			$qa_content['message_list']['form']['buttons']=array(
				'post' => array(
Gideon Greenspan committed
936
					'tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, true);"',
Gideon Greenspan committed
937 938 939 940
					'label' => qa_lang_html('profile/post_wall_button'),
				),
			);
		}
Gideon Greenspan committed
941 942 943

		foreach ($usermessages as $message)
			$qa_content['message_list']['messages'][]=qa_wall_post_view($message);
Scott Vivian committed
944

Gideon Greenspan committed
945 946
		if ($useraccount['wallposts']>count($usermessages))
			$qa_content['message_list']['messages'][]=qa_wall_view_more_link($handle, count($usermessages));
Gideon Greenspan committed
947
	}
Scott Vivian committed
948 949


Gideon Greenspan committed
950 951
//	Sub menu for navigation in user pages

Gideon Greenspan committed
952 953
	$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'profile',
		isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
Gideon Greenspan committed
954 955 956 957 958 959 960 961


	return $qa_content;


/*
	Omit PHP closing tag to help avoid accidental output
*/