<?php
/**
 * User information page
 *
 * Copyright 1999-2001 (c) VA Linux Systems
 * Copyright 2002-2004 (c) GForge Team
 * Copyright 2010-2011, Franck Villaume - Capgemini
 * http://fusionforge.org/
 *
 * This file is part of FusionForge. FusionForge 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 Licence, or (at your option)
 * any later version.
 *
 * FusionForge 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

require_once 'env.inc.php';
require_once $gfcommon.'include/pre.php';
require_once $gfcommon.'include/User.class.php';

$normalized_urlprefix = normalized_urlprefix();
$pathinfo = substr_replace(getStringFromServer('REQUEST_URI'), '', 0, strlen($normalized_urlprefix)-1);
$expl_pathinfo = explode('/', $pathinfo);

if (!$expl_pathinfo[2]) {
	exit_error(_('No User Name Provided'));
}

$default_content_type = 'text/html';
$script='user_home';
$content_type = util_negociate_alternate_content_types($script, $default_content_type);

$username = urldecode($expl_pathinfo[2]);

// If restricted mode, display only people who are sharing a project with the current user.
if (forge_get_config('restrict_users_visibility')) {
	if (!session_loggedin()) {
		exit_permission_denied();
	}

	$s  = session_get_user();
	$u1 = $s->getID();

	$user = user_get_object_by_name($username);
	if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {
		exit_permission_denied();
	}
	$u2 = $user->getID();

	$u2gl = $user->getGroups();
	$seen = false;
	foreach ($u2gl as $u2g) {
		if (forge_check_perm('project_read', $u2g->getID())) {
			$seen = true;
			break;
		}
	}
	if ($seen == false) {
		exit_permission_denied();
	}
}

//get the user object based on the user_name in the URL
$user = user_get_object_by_name($username);

if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {

	exit_error(_('That user does not exist.'));

} else {
	// if a custom content-type is selected, then redirect to plugin's rendering
	if($content_type != $default_content_type) {
		$hook_params = array();
		$hook_params['username'] = $username;
		$hook_params['accept'] = $content_type;
		$hook_params['return'] = '';
		plugin_hook_by_reference('content_negociated_user_home', $hook_params);
		if($hook_params['content_type'] != ''){
				header('Content-type: '. $hook_params['content_type']);
				echo $hook_params['content'];
		}
		else {
				header('HTTP/1.1 406 Not Acceptable',true,406);
				exit(0);
		}
	} else { // default HTML view
		$user_id = $user->getID();

		//now show the user page
		include $gfwww.'include/user_home.php';
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:

?>
