tiki-user_information.php 8.55 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
rjsmelo's avatar
rjsmelo committed
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9 10
// $Id$

rjsmelo's avatar
rjsmelo committed
11
require_once('tiki-setup.php');
12
$messulib = TikiLib::lib('message');
13

rjsmelo's avatar
rjsmelo committed
14
if ($prefs['feature_unified_user_details'] == 'y') {
15
	include "tiki-user_unified_details.php";
16 17 18
	die;
}

19
$registrationlib = TikiLib::lib('registration');
lphuberdeau's avatar
lphuberdeau committed
20
$trklib = TikiLib::lib('trk');
21 22
if (isset($_REQUEST['userId'])) {
	$userwatch = $tikilib->get_user_login($_REQUEST['userId']);
23
	if ($userwatch === false) {
24
		$smarty->assign('errortype', 'no_redirect_login');
25 26 27 28
		$smarty->assign('msg', tra("Unknown user"));
		$smarty->display("error.tpl");
		die;
	}
29
} elseif (isset($_REQUEST['view_user'])) {
30
	$userwatch = $_REQUEST['view_user'];
rjsmelo's avatar
rjsmelo committed
31
	if (! $userlib->user_exists($userwatch)) {
32
		$smarty->assign('errortype', 'no_redirect_login');
33 34 35 36
		$smarty->assign('msg', tra("Unknown user"));
		$smarty->display("error.tpl");
		die;
	}
37
} else {
38 39
	$access->check_user($user);
	$userwatch = $user;
lrargerich's avatar
lrargerich committed
40
}
41

42
$smarty->assign('userwatch', $userwatch);
43
// Custom fields
rjsmelo's avatar
rjsmelo committed
44
$customfields = [];
michael_davey's avatar
 
michael_davey committed
45
$customfields = $registrationlib->get_customfields($userwatch);
46
$smarty->assign_by_ref('customfields', $customfields);
47
$smarty->assign('infoPublic', 'y');
48 49
if ($tiki_p_admin != 'y') {
	$user_information = $tikilib->get_user_preference($userwatch, 'user_information', 'public');
50 51
	// If the user is trying to pull info on themselves, allow it.
	if ($user_information == 'private' && $userwatch != $user) {
52
		$smarty->assign('infoPublic', 'n');
53
	}
54
}
55 56 57
if ($user) {
	$smarty->assign('sent', 0);
	if (isset($_REQUEST['send'])) {
58
		check_ticket('user-information');
59 60 61 62
		$smarty->assign('sent', 1);
		$message = '';
		if (empty($_REQUEST['subject']) && empty($_REQUEST['body'])) {
			$smarty->assign('message', tra('ERROR: Either the subject or body must be non-empty'));
63
			$smarty->display("tiki.tpl");
64 65
			die;
		}
66
		$sent = $messulib->post_message($userwatch, $user, $_REQUEST['to'], '', $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], '', isset($_REQUEST['replytome']) ? 'y' : '', isset($_REQUEST['bccme']) ? 'y' : '');
67
		if ($sent) {
68
			$message = tra('Message sent to') . ':' . $userlib->clean_user($userwatch) . '<br />';
69 70 71
		} else {
			$message = tra('An error occurred, please check your mail settings and try again');
		}
72 73
		$smarty->assign('message', $message);
	}
74
}
75
if (isset($user) and $user != $userwatch) {
rjsmelo's avatar
rjsmelo committed
76 77 78
	TikiLib::events()->trigger(
		'tiki.user.view',
		[
79 80 81
			'type' => 'user',
			'object' => $userwatch,
			'user' => $user,
rjsmelo's avatar
rjsmelo committed
82
		]
83
	);
84
}
changi67's avatar
changi67 committed
85
$smarty->assign('priority', 3);
86
if ($prefs['allowmsg_is_optional'] == 'y') {
changi67's avatar
changi67 committed
87
	$allowMsgs = $tikilib->get_user_preference($userwatch, 'allowMsgs', 'y');
88 89 90
} else {
	$allowMsgs = 'y';
}
changi67's avatar
changi67 committed
91
$smarty->assign('allowMsgs', $allowMsgs);
92
$smarty->assign_by_ref('user_prefs', $user_preferences[$userwatch]);
93 94 95
if (! empty($prefs['site_style'])) {
	$user_style = $tikilib->get_user_preference($userwatch, 'theme', $prefs['site_style']);
}
changi67's avatar
changi67 committed
96
$smarty->assign_by_ref('user_style', $user_style);
97
$user_language = $tikilib->get_language($userwatch);
98
$langLib = TikiLib::lib('language');
rjsmelo's avatar
rjsmelo committed
99
$user_language_text = $langLib->format_language_list([$user_language]);
100
$smarty->assign_by_ref('user_language', $user_language_text[0]['name']);
changi67's avatar
changi67 committed
101 102 103 104 105 106 107 108 109 110 111
$realName = $tikilib->get_user_preference($userwatch, 'realName', '');
$gender = $tikilib->get_user_preference($userwatch, 'gender', '');
$country = $tikilib->get_user_preference($userwatch, 'country', 'Other');
$smarty->assign('country', $country);
$anonpref = $tikilib->get_preference('userbreadCrumb', 4);
$userbreadCrumb = $tikilib->get_user_preference($userwatch, 'userbreadCrumb', $anonpref);
$smarty->assign_by_ref('realName', $realName);
$smarty->assign_by_ref('gender', $gender);
$smarty->assign_by_ref('userbreadCrumb', $userbreadCrumb);
$homePage = $tikilib->get_user_preference($userwatch, 'homePage', '');
$smarty->assign_by_ref('homePage', $homePage);
lrargerich's avatar
lrargerich committed
112
$avatar = $tikilib->get_user_avatar($userwatch);
113 114 115
$smarty->assign('avatar', $avatar);
$user_information = $tikilib->get_user_preference($userwatch, 'user_information', 'public');
$smarty->assign('user_information', $user_information);
lrargerich's avatar
lrargerich committed
116
$userinfo = $userlib->get_user_info($userwatch);
117
$email_isPublic = $tikilib->get_user_preference($userwatch, 'email is public', 'n');
118
if ($email_isPublic != 'n') {
119
	$smarty->assign('scrambledEmail', TikiMail::scrambleEmail($userinfo['email'], $email_isPublic));
120
}
121
$userinfo['score'] = TikiLib::lib('score')->get_user_score($userwatch);
122
$smarty->assign_by_ref('userinfo', $userinfo);
changi67's avatar
changi67 committed
123 124
$smarty->assign_by_ref('email_isPublic', $email_isPublic);
$userPage = $prefs['feature_wiki_userpage_prefix'] . $userinfo['login'];
125 126
$exist = $tikilib->page_exists($userPage);
$smarty->assign("userPage_exists", $exist);
127
if ($prefs['feature_display_my_to_others'] == 'y') {
128
	if ($prefs['feature_wiki'] == 'y') {
lphuberdeau's avatar
lphuberdeau committed
129
		$wikilib = TikiLib::lib('wiki');
130 131 132 133
		$user_pages = $wikilib->get_user_all_pages($userwatch, 'pageName_asc');
		$smarty->assign_by_ref('user_pages', $user_pages);
	}
	if ($prefs['feature_blogs'] == 'y') {
lphuberdeau's avatar
lphuberdeau committed
134
		$bloglib = TikiLib::lib('blog');
135
		$user_blogs = $bloglib->list_user_blogs($userwatch, false);
136
		$smarty->assign_by_ref('user_blogs', $user_blogs);
137 138
		$user_blog_posts = $bloglib->list_posts(0, -1, 'created_desc', '', -1, $userwatch);
		$smarty->assign_by_ref('user_blog_posts', $user_blog_posts['data']);
139 140 141 142 143 144
	}
	if ($prefs['feature_galleries'] == 'y') {
		$user_galleries = $tikilib->get_user_galleries($userwatch, -1);
		$smarty->assign_by_ref('user_galleries', $user_galleries);
	}
	if ($prefs['feature_trackers'] == 'y') {
145 146
		$trklib = TikiLib::lib('trk');
		$user_items = $trklib->get_user_items($userwatch);
147 148 149
		$smarty->assign_by_ref('user_items', $user_items);
	}
	if ($prefs['feature_articles'] == 'y') {
150
		$artlib = TikiLib::lib('art');
151 152 153 154
		$user_articles = $artlib->get_user_articles($userwatch, -1);
		$smarty->assign_by_ref('user_articles', $user_articles);
	}
	if ($prefs['feature_forums'] == 'y') {
155
		$commentslib = TikiLib::lib('comments');
156 157 158 159 160
		$user_forum_comments = $commentslib->get_user_forum_comments($userwatch, -1);
		$smarty->assign_by_ref('user_forum_comments', $user_forum_comments);
		$user_forum_topics = $commentslib->get_user_forum_comments($userwatch, -1, 'topics');
		$smarty->assign_by_ref('user_forum_topics', $user_forum_topics);
	}
161
	if ($prefs['user_who_viewed_my_stuff'] == 'y') {
rjsmelo's avatar
rjsmelo committed
162
		$mystuff = [];
163 164 165
		if (isset($user_pages)) {
			$stuffType = 'wiki page';
			foreach ($user_pages as $obj) {
rjsmelo's avatar
rjsmelo committed
166
				$mystuff[] = [ 'object' => $obj["pageName"], 'objectType' => $stuffType, 'comment' => '' ];
167 168 169 170 171
			}
		}
		if (isset($user_blogs)) {
			$stuffType = 'blog';
			foreach ($user_blogs as $obj) {
rjsmelo's avatar
rjsmelo committed
172
				$mystuff[] = [ 'object' => $obj["blogId"], 'objectType' => $stuffType, 'comment' => '' ];
173 174 175 176 177
			}
		}
		if (isset($user_articles)) {
			$stuffType = 'article';
			foreach ($user_articles as $obj) {
rjsmelo's avatar
rjsmelo committed
178
				$mystuff[] = [ 'object' => $obj["articleId"], 'objectType' => $stuffType, 'comment' => '' ];
179 180 181 182 183 184
			}
		}
		if (isset($user_forum_topics)) {
			$stuffType = 'forum';
			foreach ($user_forum_topics as $obj) {
				$forum_comment = 'comments_parentId=' . $obj["threadId"];
rjsmelo's avatar
rjsmelo committed
185
				$mystuff[] = [ 'object' => $obj["object"], 'objectType' => $stuffType, 'comment' => $forum_comment ];
186 187
			}
		}
188
		$logslib = TikiLib::lib('logs');
189 190 191
		$whoviewed = $logslib->get_who_viewed($mystuff, false);
		$smarty->assign('whoviewed', $whoviewed);
	}
192
}
changi67's avatar
changi67 committed
193
if ($prefs['user_tracker_infos']) {
194
	// arg passed 11,56,58,68=trackerId,fieldId...
changi67's avatar
changi67 committed
195
	$trackerinfo = explode(',', $prefs['user_tracker_infos']);
196
	$userTrackerId = array_shift($trackerinfo);
rjsmelo's avatar
rjsmelo committed
197 198
	if (! empty($trackerinfo)) {
		$filter = ['fieldId' => $trackerinfo];
199
	} else {
rjsmelo's avatar
rjsmelo committed
200
		$filter = [];
201 202
	}
	$fields = $trklib->list_tracker_fields($userTrackerId, 0, -1, 'position_asc', '', true, $filter);
203
	foreach ($fields['data'] as $field) {
204 205
		$lll[$field['fieldId']] = $field;
	}
206
	$definition = Tracker_Definition::get($userTrackerId);
207 208 209 210
	if ($definition) {
		$items = $trklib->list_items($userTrackerId, 0, 1, '', $lll, $definition->getUserField(), '', '', '', $userwatch);
		$smarty->assign_by_ref('userItem', $items['data'][0]);
	} else {
rjsmelo's avatar
rjsmelo committed
211
		$smarty->assign('userItem', []);
212
	}
213
}
214
ask_ticket('user-information');
215 216
// Get full user picture if it is set
if ($prefs["user_store_file_gallery_picture"] == 'y') {
217
	$userprefslib = TikiLib::lib('userprefs');
rjsmelo's avatar
rjsmelo committed
218
	if ($user_picture_id = $userprefslib->get_user_picture_id($userwatch)) {
219
		$smarty->assign('user_picture_id', $user_picture_id);
rjsmelo's avatar
rjsmelo committed
220
	}
221
}
222 223
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
224
$smarty->assign('mid', 'tiki-user_information.tpl');
225
$smarty->display("tiki.tpl");